//===========================================================================//
// File:	MWPlayer.hpp																	     //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 09/09/98  JSE  Inital base class based off of Shadowrun/Adept                                //
//---------------------------------------------------------------------------//
// Copyright (C) 1998, Fasa Interactive										 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#pragma once

#include "MW4.hpp"

#include <Adept\Player.hpp>
#pragma warning (push)
#include <vector>
#pragma warning (pop)
#include "obstacle.hpp"
#include "playerai.hpp"
#include "AI_LancemateCommands.hpp"
#include <Adept\GUITextObject.hpp>

namespace MechWarrior4
{

	class Vehicle;
	class VehicleInterface;

	typedef Adept::Player__CreateMessage				MWPlayer__CreateMessage;

	//##########################################################################
	//###########################   MWPlayer    ################################
	//##########################################################################

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

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Inheritance Support
	//
		typedef MWPlayer__CreateMessage					CreateMessage;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Run-time Construction and Destruction Support
	//
	public:
		static MWPlayer*
			Make(
				CreateMessage *message,
				ReplicatorID *base_id
			);

		void
			Respawn(CreateMessage *message);

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

		~MWPlayer();

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Simulation Support
	//
	public:
		void
			PostCollisionExecute(Stuff::Time till);

		void
			PreCollisionExecute(Stuff::Time till);
		void
			ConnectToVehicle();

		static
			ObjectID MWPlayer::FindDropZone(int team);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Inherited Accesor support
	//
		public:
			Vehicle
				*GetVehicle()
					{Check_Object(this); return (Vehicle *)vehicle;}

			VehicleInterface
				*GetInterface()
					{Check_Object(this); return (VehicleInterface *)playerInterface;}

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Shared Data support
	//
	public:
		static ClassData
			*DefaultData;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// LanceMate support
	//
		class LancemateCommandProxy
		{
		  public:
			enum Mode
			{
				LANCEMATE_1,
				LANCEMATE_2,
				LANCEMATE_3,
				LANCEMATE_ALL,
				INVALID
			};

			LancemateCommandProxy();

			Mode GetMode() const { return (m_Mode); }
			bool SetMode(Mode mode);
			bool IssueCommand(Vehicle* v, MW4AI::LancemateCommands::ID command);

		  private:
			Mode m_Mode;
		};

		LancemateCommandProxy m_LancemateCommandProxy;

	protected:
		int m_Team;

	public:
		void
			AddObjectToDestroy(ObjectID who);

	protected:
		stlport::vector<ObjectID> m_ObjectsToDestroy;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Obstacle support
	//

	protected:
			stlport::vector<MW4AI::LockData *> m_PathLock;				// in BLOCK_GRID_RES coordinates
			stlport::vector<MW4AI::Rect4D *> m_LockedRects;

			bool LockSquare (const Point3D& loc,Stuff::Scalar rad);
			bool LockedByMe (const Stuff::Point3D& loc) const
			{
				if (loc.x < MW4AI::MinX)
					return true;
				if (loc.z < MW4AI::MinZ)
					return true;
				if (loc.x >= MW4AI::MaxX)
					return true;
				if (loc.z >= MW4AI::MaxZ)
					return true;
				return (MW4AI::Blocker (loc) == (MWObject *) this);
			}
			bool AddLockCell (const Stuff::Point3D& loc);			// true if can lock cell

		public:
			virtual void ClearPathLock (bool quitting);
			virtual bool PathLock (bool secondpass=false);

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


