//===========================================================================//
// File:	mechai.hpp																	     //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
//	01/14/2000  AHF	Created File                  //
//---------------------------------------------------------------------------//
// Copyright (C) 1999, Microsoft										 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#pragma once

#include "mech_AI.hpp"
#include "mech.hpp"

namespace MechWarrior4
{
	class NavPoint;
}
namespace MechWarrior4
{

	class PlayerAI;
	//##########################################################################
	//###############    PlayerAI::ExecutionStateEngine    #####################
	//##########################################################################

	class PlayerAI__ExecutionStateEngine:
		public Entity__ExecutionStateEngine
	{
	public:
		static void InitializeClass();
		static void TerminateClass();

		typedef Entity__ExecutionStateEngine BaseClass;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Run-time Construction and Destruction Support
	//
	public:
		typedef PlayerAI__ExecutionStateEngine* (*Factory)(PlayerAI *entity,FactoryRequest *request);

		static PlayerAI__ExecutionStateEngine* Make(PlayerAI *mover,FactoryRequest *request);

	protected:
		PlayerAI__ExecutionStateEngine(ClassData *class_data,PlayerAI *mover,FactoryRequest *request);

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

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// State stuff
	//
	public:
		enum {
			AutoPilotState = Entity::ExecutionStateEngine::StateCount,
			CinemaState,
			FieldBaseState,
			StateCount
		};

//	int RequestState(int new_state,void* data = NULL);

	protected:
		static const StateEntry StateEntries[];

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


	typedef MechAI__CreateMessage				PlayerAI__CreateMessage;

	//##########################################################################
	//###########################   MechAI    ##################################
	//##########################################################################

	class PlayerAI
		: public MechAI
	{
		typedef MechAI inherited;
	public:
		static void	InitializeClass();
		static void	TerminateClass();

		static ClassData *DefaultData;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Inheritance Support
	//
	public:
		typedef PlayerAI__CreateMessage					CreateMessage;
		typedef PlayerAI__ExecutionStateEngine		ExecutionStateEngine;


	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Run-time Construction and Destruction Support
	//
	public:
		virtual void Save (MemoryStream *stream) {MechAI::Save(stream);}
		virtual void Load (MemoryStream *stream) {MechAI::Load(stream);}
		static PlayerAI* Make(CreateMessage *message,ReplicatorID *base_id);

	protected:
		PlayerAI(
			ClassData *class_data,
			CreateMessage *message,
			ReplicatorID *base_id,
			ElementRenderer::Element *element
		);
	public:
		virtual ~PlayerAI();

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Message Support
	//
	public:

		enum {
			DebugTextMessageID = MechWarrior4::MechAI::NextMessageID,
			NextMessageID
		};

		void DebugTextMessageHandler(Adept::ReceiverDataMessageOf<int> *message);

		void NotifyHeatShutdownImminent();
		bool RequestHeatShutdown() const;

		protected:

			static const MessageEntry	MessageEntries[];

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Execution Support
	//
	protected:
		MechWarrior4::NavPoint *m_AutoPilotDest;
		bool m_AutoPilot;
		Stuff::Scalar m_AutoPilotSpeed;

	public:
		virtual void PreCollisionExecute(Stuff::Time till);

		void StartCinema (void);
		void StartFieldBase (void);
		void StopExecuting (void);
		virtual bool ShouldRunScript();
		
		virtual void AddTowardGunnery (int value) {}			// player version of these cannot increase
		virtual void AddTowardPilot (int value) {}
		virtual void AddTowardElite (int value) {}
		virtual void FinishFieldBase (void);

//		virtual bool PilotSkillCheck (Stuff::Scalar damage_amount,bool jump)
//		{ return true; }

		virtual void TurnOn (void);
		virtual void TurnOff (void);
		void AutoPilot (bool value);
		void NavPoint (MechWarrior4::NavPoint *pt);
		void ChangeAutoPilotSpeed (Stuff::Scalar newspeed);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Test Support
	//
	public:
		void TestInstance() const;
	};
	
	inline PlayerAI__ExecutionStateEngine::PlayerAI__ExecutionStateEngine( ClassData *class_data, PlayerAI *mover, FactoryRequest *request ):
		BaseClass(class_data, mover, request)
			{}

}

