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

#pragma once

#include "Adept.hpp"
#include "Driver.hpp"

namespace Adept
{

	class Interface;
	//##########################################################################
	//##################    Player::CreateMessage    ###########################
	//##########################################################################

	class Player__CreateMessage:
		public Driver__CreateMessage
	{
	public:
		ResourceID
			vehicleResourceID;
		ResourceID
			interfaceResourceID;

		int teamNumber;
		
		char skinPrefix;
		int teamDecal;
		int pilotDecal;


		Player__CreateMessage(
			size_t length,
			int priority,
			int message_flags,
			Stuff::RegisteredClass::ClassID class_id,
			int replicator_flags,
			const ResourceID& data_list_id,
			const Stuff::LinearMatrix4D &creation_matrix,
			Stuff::Scalar age,
			int execution_state,
			int name_id,
			int entity_alignment,
			const ResourceID& vehicle_id,
			const ResourceID& interface_id,
			int drop_zone,
			int team_number,
			char skin_prefix,
			int team_decal,
			int pilot_decal
		):
			Driver__CreateMessage(
				length, 
				priority, 
				message_flags, 
				class_id,
				replicator_flags,
				data_list_id,
				creation_matrix,
				age,
				execution_state,
				name_id,
				entity_alignment,
				drop_zone
			),
			vehicleResourceID(vehicle_id),
			interfaceResourceID(interface_id),
			teamNumber(team_number),
			skinPrefix(skin_prefix),
			teamDecal(team_decal),
			pilotDecal(pilot_decal)
				{}

		static void
			ConstructCreateMessage(Script *script);
	};

	//##########################################################################
	//###########################   Player    ##################################
	//##########################################################################

	class Player:
		public Driver
	{
	public:
		static void
			InitializeClass();
		static void
			TerminateClass();

		typedef Driver BaseClass;

		static ClassData
			*DefaultData;

		static Player*
			GetInstance() 
		{
			return reinterpret_cast<Player *>( GlobalPointers::GetGlobalPointer(PlayerGlobalPointerIndex));
		};



	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Inheritance Support
	//
	public:
		typedef Player__CreateMessage				CreateMessage;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Run-time Construction and Destruction Support
	//
	public:
		static Player* 
			Make(
				CreateMessage *message,
				ReplicatorID *base_id
			);
		Replicator::CreateMessage*
			SaveMakeMessage(Stuff::MemoryStream *stream, ResourceFile *res_file);

	protected:
		Player(
			ClassData *class_data,
			CreateMessage *message,
			ReplicatorID *base_id,
			ElementRenderer::Element *element
		);

		~Player();

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Message Support 
	//
	public:
		void
			ReceiveDropZone(const Stuff::LinearMatrix4D& drop_location);
		
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Ownership 
	//
	public:
		Interface
			*playerInterface;

		void
			AddChild(Entity *entity);

	protected:
		void
			ChildPreCollisionChanged(Entity *entity);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Execution Support
	//
	public:
		void
			PreCollisionExecute(Stuff::Time till);

		ResourceID
			interfaceResourceID;
		Stuff::LinearMatrix4D
			oldLocalToWorld;


		virtual void
			ConnectToVehicle();

		Stuff::LinearMatrix4D
			GetEyePoint();
	
		void
			Respawn(CreateMessage *message);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Renderer Support
	//
	public:
		void
			BecomeInteresting(bool render_me);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Test Support
	//
	public:
		void
      	TestInstance();
	};
}


