//===========================================================================//
// File:	Player_Tool.cpp																	  //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 03/08/99  DPB  Created Files               //
//---------------------------------------------------------------------------//
// Copyright (C) 1998, Fasa Interactive										 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#include "AdeptHeaders.hpp"

#include "Player.hpp"
#include "Tool.hpp"
#include "Interface.hpp"

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	Player__CreateMessage::ConstructCreateMessage(Script *script)
{
	Check_Object(script);
	#if defined(_ARMOR)
		int stack_level = Tool::Instance->GetStackLevel();
	#endif

	//
	//--------------
	// Set up stream
	//--------------
	//
	MemoryStream *message_stream = script->messageStream;
	Check_Object(message_stream);
	message_stream->AllocateBytes(sizeof(Player__CreateMessage));
	Driver::CreateMessage::ConstructCreateMessage(script);
	Verify(stack_level == Tool::Instance->GetStackLevel());
	Player__CreateMessage *message =
		Cast_Pointer(
			Player__CreateMessage*,
			message_stream->GetPointer()
		);
	message->messageLength = sizeof(*message);

	//
	//---------------------------------------------------------------
	// Point at the notation file and make other files relative to it
	//---------------------------------------------------------------
	//
	Page *page = script->instancePage;
	Check_Object(page);

	//
	//-----------------------------------------------------------------
	// Create the map instance and stuff its resource ID in the message
	//-----------------------------------------------------------------
	//
	{
		NotationFile interface_file;
		page->GetEntry("Interface", &interface_file, true);
		Resource interface_instance;
		Check_Object(Tool::Instance);
		ReplicatorID local_base = ReplicatorID::Null;
		Tool::Instance->ConstructCreateMessage(
			&interface_instance,
			&interface_file,
			&local_base
		);
		*script->baseID += local_base;
		message->interfaceResourceID = interface_instance.GetResourceID();
	}

	//
	//-----------------------------------------------------------------
	// Create the map instance and stuff its resource ID in the message
	//-----------------------------------------------------------------
	//
	{
		NotationFile vehicle_file;
		page->GetEntry("Vehicle", &vehicle_file, true);
		Resource vehicle_instance;
		ReplicatorID local_base = ReplicatorID::Null;
		Check_Object(Tool::Instance);
		Tool::Instance->ConstructCreateMessage(
			&vehicle_instance,
			&vehicle_file,
			&local_base
		);
		*script->baseID += local_base;
		message->vehicleResourceID = vehicle_instance.GetResourceID();
	}

	message->dropZone = NameTable::NullObjectID;

	message->teamNumber = 0;
	message->skinPrefix = 0;
	message->teamDecal = 0;
	message->pilotDecal = 0;

	Verify(stack_level == Tool::Instance->GetStackLevel());
}
