//===========================================================================//
// File:	VehicleInterface.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\Interface.hpp>
#include "MWEntityManager.hpp"
#include "Vehicle.hpp"
#include "mwguimanager.hpp"
#include "Blanderizer.hpp"

#pragma warning (push)
#include <stlport\string>
#pragma warning (pop)


namespace Adept
{
	class Effect;
	class GUITextObject;
	class AudioCommand;
}

namespace ElementRenderer
{
	class CameraElement;
}

namespace MechWarrior4
{

	class MWMover;
	class CollisionGroup;
	class Weapon;
	class VehicleInterface;
	class MWPlayer;
	class PlayerAI;	
	class VehicleCommand;
	class LongTomWeaponSubsystem;
	class NavPoint;

	
	void VehicleInterfaceSecurityCheckStart();
	void VehicleInterfaceSecurityCheckStop();	

	//##########################################################################
	//###############    VehicleInterface::ExecutionStateEngine     ############
	//##########################################################################

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

		typedef Adept::Entity__ExecutionStateEngine BaseClass;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Run-time Construction and Destruction Support
	//
	public:
		typedef VehicleInterface__ExecutionStateEngine*
			(*Factory)(
				VehicleInterface *vehicle_interface,
				FactoryRequest *request
			);

		static VehicleInterface__ExecutionStateEngine*
			Make(
				VehicleInterface *vehicle_interface,
				FactoryRequest *request
			);

	protected:
		VehicleInterface__ExecutionStateEngine(
			ClassData *class_data,
			VehicleInterface *vehicle_interface,
			FactoryRequest *request
		);

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

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// State stuff
	//
	public:
		enum {
			FollowingState = Adept::Interface__ExecutionStateEngine::StateCount,
			WatchingDeathState,
			AIRunningState,
			FieldBaseState,
//			AutoPilotState,
			ObservationState,
			StateCount
		};


		int RequestState(int new_state,void* data);

	protected:
		static const StateEntry
			StateEntries[];

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


	//##########################################################################
	//##################    VehicleInterface::CreateMessage    #################
	//##########################################################################

	class VehicleInterface__CreateMessage:
		public Adept::Interface__CreateMessage
	{
	public:
		typedef Adept::Interface__CreateMessage BaseClass;

		Adept::ResourceID
			guiStreamResourceID;

		VehicleInterface__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 &local_to_parent,
			Stuff::Scalar age,
			int execution_state,
			int name_id,
			int entity_alignment,
			Adept::ResourceID gui_id
		):
			Interface__CreateMessage(
				length,
				priority,
				message_flags,
				class_id,
				replicator_flags,
				data_list_id,
				local_to_parent,
				age,
				execution_state,
				name_id,
				entity_alignment
			),
			guiStreamResourceID(gui_id)
				{}

		static void
			ConstructCreateMessage(Script *script);
	};

	//##########################################################################
	//##################     CharacterInterface__GameModel    ##################
	//##########################################################################

	class VehicleInterface__GameModel:
		public Adept::Interface__GameModel
	{
	public:
		typedef Adept::Interface__GameModel BaseClass;

		int
			brbMode;
		

		Stuff::Point3D
			cameraStartOffset;

 		Stuff::Point3D
			cameraExternalTargetStartOffset1;
 		
    Stuff::Point3D
			cameraExternalTargetStartOffset2;

    Stuff::Point3D
			cameraExternalTargetStartOffset3;

		Stuff::UnitQuaternion
			cameraStartAngle;

		Stuff::Scalar
			maxTargetDistance;

		Stuff::Scalar
			turnSpeedZoomModifierTorso;

		Stuff::Scalar
			turnSpeedZoomModifierYaw;

		Stuff::Scalar
			turnSpeedZoomModifierPitch;

		Stuff::Radian
			rotationPerSecond;

		Stuff::Point3D
			translationPerSecond;

		Stuff::Scalar
			deathTimer;

		static void
			GetFogTableEntry(int entry, Stuff::Scalar * pfogNearClip, Stuff::Scalar * pfogFarClip, Stuff::Scalar * pfogDensity);

		Adept::ResourceID	playerAIResource;

		Stuff::Scalar
			delayTorsoCenter,
			maxSpeedAboveMinTransToTorsoCenterKPH;

		enum {
			BRBModeAttributeID = Interface__GameModel::NextAttributeID,
      CameraStartOffsetAttributeID,
      CameraExternalTargetStartOffset1AttributeID,
      CameraExternalTargetStartOffset2AttributeID,
      CameraExternalTargetStartOffset3AttributeID,
			CameraStartAngleAttributeID,
			MaxTargetDistanceAttributeID,
			TurnSpeedZoomModifierTorsoAttributeID,
			TurnSpeedZoomModifierYawAttributeID,
			TurnSpeedZoomModifierPitchAttributeID,
			RotationPerSecondAttributeID,
			TranslationPerSecondAttributeID,
			DeathTimerAttributeID,
			PlayerAIResourceAttributeID,
			DelayTorsoCenterAttributeID,
			MaxSpeedAboveMinTransToTorsoCenterKPHAttributeID,
			NextAttributeID
		};

		static bool
			ReadAndVerify(
				VehicleInterface__GameModel *model,
				ModelAttributeEntry *attribute_entry,
				const char *data,
				char **error,
				int error_buffer = 128
			);

		static void
			ConstructGameModel(Script *script);
	};		



	//##########################################################################
	//########################     AnalogControlSave
	//##########################################################################

	struct AnalogControlSave
	{
	public:
	
		Stuff::Scalar vehicleSpeedDemand;
		Stuff::Scalar vehicleYawDemand;
		Stuff::Scalar torsoPitchDemand;
		Stuff::Scalar torsoYawDemand;
	
		enum {
			LookForward = 0,
			LookLeft,
			LookRight,
			LookBack,  // new angle to take out copters.
			LookDown // new DFA look, with ability to clear clutter from legs as well.
		};

		int lookCommand;

		int commandReady;
		int command;

		AnalogControlSave()
		{
			commandReady = false;
			vehicleSpeedDemand = 0.0f;
			vehicleYawDemand = 0.0f;
			torsoPitchDemand = 0.0f;
			torsoYawDemand = 0.0f;

			lookCommand = LookForward;
		}

	};



	//##########################################################################
	//########################     VehicleInterface    #########################
	//##########################################################################

	class VehicleInterface:
		public Adept::Interface
	{
		friend class Vehicle;
		friend bool __stdcall Check_MouseControl(void);
		friend void __stdcall Activate_MouseControl(void);

	public:
		static void
			InitializeClass();
		static void
			TerminateClass();

		typedef Adept::Interface BaseClass;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Inheritance support
	//
	public:
		typedef VehicleInterface__CreateMessage				CreateMessage;
		typedef VehicleInterface__GameModel					GameModel;
		typedef VehicleInterface__ExecutionStateEngine		ExecutionStateEngine;


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

		void
			Respawn(Adept::Entity::CreateMessage *message);
		void
			CommonCreation(CreateMessage *message);

		void LoadControlStream (const ResourceID& control_stream);

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

		~VehicleInterface();

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

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// AI support
	//
	protected:
		PlayerAI *m_PlayerAI;

	public:
		void ConnectPlayerAI (PlayerAI *p1);
		PlayerAI *getPlayerAI (void)
		{ return m_PlayerAI; }
		void PlayerAIRun (bool value);
		void PlayerAIFieldBase (bool value);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Class Data & Game Model Support
	//
	public:
		typedef VehicleInterface__GameModel
			GameModel;

		const GameModel*
			GetGameModel()
				{return Cast_Pointer(const GameModel*, gameModelResource.GetPointer());}

		static ClassData
			*DefaultData;

		static VehicleInterface*
			GetInstance()
		{
			return reinterpret_cast<VehicleInterface *>( GlobalPointers::GetGlobalPointer(VehicleInterfaceGlobalPointerIndex));
		};

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Interface support
	//
	public:

	//DAVE HUD
	//	GUIInterface *
	//			guiInterface;

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

		void ReadJoystick (Time till);
		void ReadMouse (Time till);
		void HandleKeyboard (Time till);

		void ReadControls(Time till);
    void ModifyControls(Time till); // this is where we do things like tone down control when in zoom
		void ApplyControls(Time till);
//		void CheckEndAutoPilot(Time till);
		void CheckEndFieldBase(Time till);


		AnalogControlSave
			controlPacket;

		ChainOf<VehicleCommand*> quedCommands;
		int commandCount;

		void QueCommand(int command);

		Stuff::Scalar
			longTomAngle;
		Stuff::Scalar
			longTomDistance;
		LongTomWeaponSubsystem
			*longTom;

		BlanderizerOf<Stuff::Point3D>
			jumpHeightAdjustment;

// MSL 5.05 Advance Mode
		int
			m_AdvanceMode;

		int
			m_HeatMode;

		int
			m_AmmoMode;

		Stuff::Scalar FlushTimer;

		void
    		UpdateTargetReticuleCameraPosition(void);

		void
			UpdateViews(void);
		void
			UpdateBRBView(void);
		void
			UpdateTargetReticule(Time till);
		void
			ConnectVehicleToInterface(Vehicle *connecting_vehicle,MWPlayer *player=NULL);
		void
			ResetInterface(int execution_mode);

		inline void
			ShowHUDIfOn(bool fShowHUDIfShould);
		inline void
			ShowStatic(bool fShowBW);

		inline void
			ShowZoomIfOn(bool fShowZoomIfShould);

		Adept::Entity*
			CastCollisionLine();

		void
			SetCameraMode(int camera_mode, const Stuff::Point3D* point = 0);
		void
			SetCameraMode(int camera_mode, const VehicleInterface__GameModel& model);
		void
			SetDeathMode();
		void SetEjectMode();
		void
			CreateWeatherEffect();
		void
			CreateWeatherEffect(const Adept::ResourceID& resource_id);

		Stuff::SlotOf<Adept::Effect *>
			weatherEffect;

		enum {
			NormalFogType = 0,
			UnderwaterFogType,
			SmokeFogType,
			TransitionToSmokeFogType,
			TransitionToNormalFogType
		};

		void SetLightAmpFlareOut(Stuff::Scalar modifier);
		Stuff::Scalar m_CurrentLightAmpMod;

		int
			m_eFogType; // for setting below water fog
		Stuff::Scalar 	
			m_fltFogTransitionEndTime;
		bool
			fNeedSmoke;
		bool
			m_fHudCurrentlyShowing; // used to allow us to continually and cheaply call hide for all views
		bool
			m_fZoomCurrentlyShowing; // used to allow us to continually and cheaply call hide for all views
		bool
			m_fStaticView;
		bool
			m_fHudShouldShow; // current state of the hud

		Stuff::Scalar
			m_maxSpeedTorsoCenterKPH;

		bool
			cameraDirty;
    bool
      isAttachedVehicleAMech; // in order to operate external camera better during jump animation
    int
      vehiclerootJointIndex; // Store this for height info when jumping
		Adept::GUITextObject
			*guiTargetInfo;

    Stuff::Scalar
      addedLengthToTarget; // this is valid when we are using external target reticule

    Stuff::Scalar
			percentage_of_zoom_screen_on_left;
    Stuff::Scalar
			percentage_of_zoom_screen_on_right;
    Stuff::Scalar
			percentage_of_zoom_screen_on_top;
    Stuff::Scalar
			percentage_of_zoom_screen_on_bottom;

		int
			m_currentTargetReticuleCameraPosition;

		void RestorePreferredCameraPosition();
		static void SetPreferredCameraPosition(int newCameraReticuleCameraPosition);

		Stuff::Scalar spinTorsoPitchTimer;
		Stuff::Scalar spinTorsoYawTimer;
		Stuff::Scalar spinMechYawTimer;

		Stuff::Scalar spinTorsoPitchMagnitude;
		Stuff::Scalar spinTorsoYawMagnitude;
		Stuff::Scalar spinMechYawMagnitude;


		void SpinTorsoPitch(Stuff::Scalar magnitude)
		{

			Check_Object(this);

			if (magnitude > 0.0f)
				spinTorsoPitchMagnitude = 1.0f;
			else
				spinTorsoPitchMagnitude = -1.0f;
			
			spinTorsoPitchTimer+=Abs(magnitude);
			Max_Clamp(spinTorsoPitchTimer, 0.5f);
		};

		void SpinTorsoYaw(Stuff::Scalar magnitude)
		{
			Check_Object(this);

			if (magnitude > 0.0f)
				spinTorsoYawMagnitude = 1.0f;
			else
				spinTorsoYawMagnitude = -1.0f;
			
// MSL 5.02 Torso Spin
//			spinTorsoYawMagnitude = 1.0f;
			spinTorsoYawTimer+=Abs(magnitude);
			Max_Clamp(spinTorsoYawTimer, 1.5f);
		};

		void SpinMechYaw(Stuff::Scalar magnitude)
		{
			Check_Object(this);

			if (magnitude > 0.0f)
				spinMechYawMagnitude = 1.0f;
			else
				spinMechYawMagnitude = -1.0f;
			
// MSL 5.02 Mech Spin
//			spinMechYawMagnitude = 1.0f;
			spinMechYawTimer+=Abs(magnitude);
			Max_Clamp(spinMechYawTimer, 1.5f);
		};

		

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Message Support
	//
	public:
		enum {
			ChangeViewMessageID = Adept::Interface::NextMessageID,
			JoyStickButton1MessageID,
			GetUpCommandMessageID,
			ShutDownCommandMessageID,
			CrouchCommandMessageID,
			JumpCommandMessageID,
			AnimDiagTest1MessageID, // anim diag test 1
			AnimDiagTest2MessageID,
			AnimDiagTest3MessageID,
			AnimDiagTest4MessageID,
			AnimDiagTest5MessageID,
			AnimDiagTest6MessageID,
			AnimDiagTest7MessageID,
			AnimDiagTest8MessageID,
			DebugTextMessageID,
			Lancemate1MessageID,
			Lancemate2MessageID,
			Lancemate3MessageID,
			LancemateAllMessageID,
			LancemateAttackMyTargetMessageID,
			LancemateDefendMyTargetMessageID,
			LancemateFormOnMeMessageID,
			LancemateHoldFireMessageID,
			LancemateGoToMyNavPointMessageID,
			LancemateStopMessageID,
			LancemateShutdownMessageID,
			LancemateAttackNearestThreatMessageID,
			LancemateRepairAtNearestRepairBayMessageID,
			LancemateCapturePlayersFlagMessageID,
			ChangeWeaponModeMessageID,
			WeaponGroup1MessageID,
			WeaponGroup2MessageID,
			WeaponGroup3MessageID,
			WeaponGroup4MessageID,
			WeaponGroup5MessageID,
			WeaponGroup6MessageID,
			NextWeaponGroupMessageID,
			PreviousWeaponGroupMessageID,
			NextWeaponMessageID,
			TopDownViewMessageID,
			ToggleInvulnerableMessageID,
			KillCurrentTargetMessageID,
			NextVehicleMessageID,
			ToggleSearchLightMessageID,
			SelfDestructMessageID,
			CoolantMessageID,
			SendChatMessage1MessageID,
			SendChatMessage2MessageID,
			SendChatMessage3MessageID,
			SendChatMessage4MessageID,
			ToggleLightAmpMessageID,
			ToggleHUDMessageID,
			ToggleMultiplayerScoringMessageID,
			NextNavPointMessageID,
			PreviousNavPointMessageID,
			NextEnemyMessageID,
			PreviousEnemyMessageID,
			NearestEnemyMessageID,
			TargetReticuleEnemyMessageID,
			ToggleRadarRangeMessageID,
			ForwardMessageID,
			BackwardMessageID,
			RotateLeftMessageID,
			RotateRightMessageID,
			OriginMessageID,
			TorsoTwistLeftMessageID,
			TorsoTwistRightMessageID,
			PitchUpMessageID,
			PitchDownMessageID,
			ReverseMessageID,
			FireWeaponMessageID,
			LookLeftMessageID,
			LookRightMessageID,
			LookBackMessageID,
			LookDownMessageID,
			CameraDetachMessageID,
			CameraResetMessageID,
			CameraTerrainMessageID,
			CameraTargetReticuleMessageID,
			CameraPitchUpMessageID,
			CameraPitchDownMessageID,
			CameraRollRightMessageID,
			CameraRollLeftMessageID,
			CameraYawLeftMessageID,
			CameraYawRightMessageID,
			CameraPanUpMessageID,
			CameraPanDownMessageID,
			CameraPanLeftMessageID,
			CameraPanRightMessageID,
			CameraZoomInMessageID,
			CameraZoomOutMessageID,
			MFDComm1MessageID,
			MFDComm2MessageID,
			MFDComm3MessageID,
			MFDComm4MessageID,
			MFDComm5MessageID,
			MFDComm6MessageID,
			MFDComm7MessageID,
			MFDComm8MessageID,
			Throttle0MessageID,
			Throttle10MessageID,
			Throttle20MessageID,
			Throttle30MessageID,
			Throttle40MessageID,
			Throttle50MessageID,
			Throttle60MessageID,
			Throttle70MessageID,
			Throttle80MessageID,
			Throttle90MessageID,
			Throttle100MessageID,
			CenterTorsoToLegsMessageID,
			CenterLegsToTorsoMessageID,
			NextFriendlyMessageID,
			PreviousFriendlyMessageID,
			NearestFriendlyMessageID,
			ToggleZoomReticuleMessageID,
			ShowObjectivesMessageID,
// MSL 5.05 Objective Switch
			MuteMessageID,
			MouseTorsoToggleMessageID,
			MouseDeltaToggleMessageID,
//			AutoPilotMessageID,
			EjectMessageID,
			OverrideAutoCenterToTorsoMessageID,
			ToggleRadarPassiveMessageID,
			ShowMapMessageID,
			StartChatMessageID,
			StartTeamChatMessageID,
			OverrideShutdownMessageID,
			LeftMFDMessageID,
			RightMFDMessageID,
			ToggleMouseControlMessageID,
			ToggleLargeChatMessageID,
			ShutDownOnlyCommandMessageID,
			StartUpOnlyCommandMessageID,
			TakeSnapShotMessageID,
			ToggleGroup1MessageID,
			ToggleGroup2MessageID,
			ToggleGroup3MessageID,
			ToggleGroup4MessageID,
			ToggleGroup5MessageID,
			ToggleGroup6MessageID,
			ToggleGroupWeaponModeMessageID

//
// Section for keys we don't want in the release build
//
,
			DebugFastMessageID,
			FreezeGameLogicMessageID,
			ImmediateWeaponLockModeMessageID,
			SucceedMissionMessageID,
			FailMissionMessageID,
			ToggleDebugHudMessageID,

			NextMessageID
		};

		void StartChatMessageHandler (Adept::ReceiverDataMessageOf<int> *message);
		void StartTeamChatMessageHandler (Adept::ReceiverDataMessageOf<int> *message);
		void LeftMFDMessageHandler (Adept::ReceiverDataMessageOf<int> *message);
		void RightMFDMessageHandler (Adept::ReceiverDataMessageOf<int> *message);
		void ToggleRadarPassiveMessageHandler (Adept::ReceiverDataMessageOf<int> *message);
		void
			ChangeViewMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			JoyStickButton1MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			GetUpCommandMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ShutDownCommandMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ShutDownOnlyCommandMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			StartUpOnlyCommandMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CrouchCommandMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			JumpCommandMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			AnimDiagTest1MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			AnimDiagTest2MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			AnimDiagTest3MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			AnimDiagTest4MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			AnimDiagTest5MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			AnimDiagTest6MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			AnimDiagTest7MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			AnimDiagTest8MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			DebugTextMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Lancemate1MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Lancemate2MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Lancemate3MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LancemateAllMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LancemateAttackMyTargetMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LancemateDefendMyTargetMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LancemateFormOnMeMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LancemateHoldFireMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LancemateGoToMyNavPointMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LancemateStopMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LancemateShutdownMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LancemateAttackNearestThreatMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LancemateRepairAtNearestRepairBayMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LancemateCapturePlayersFlagMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ChangeWeaponModeMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			WeaponGroup1MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			WeaponGroup2MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			WeaponGroup3MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			WeaponGroup4MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			WeaponGroup5MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			WeaponGroup6MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleGroup1MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleGroup2MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleGroup3MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleGroup4MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleGroup5MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleGroup6MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			NextWeaponGroupMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			PreviousWeaponGroupMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			NextWeaponMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			TopDownViewMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleInvulnerableMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			KillCurrentTargetMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			NextVehicleMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleSearchLightMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			SelfDestructMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CoolantMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			SendChatMessage1MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			SendChatMessage2MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			SendChatMessage3MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			SendChatMessage4MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleLightAmpMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleHUDMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleMultiplayerScoringMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			NextNavPointMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			PreviousNavPointMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			NextEnemyMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			PreviousEnemyMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			NearestEnemyMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			TargetReticuleEnemyMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleRadarRangeMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ForwardMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			BackwardMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			RotateLeftMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			RotateRightMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			OriginMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			TorsoTwistLeftMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			TorsoTwistRightMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			PitchUpMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			PitchDownMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ReverseMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			FireWeaponMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LookLeftMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LookRightMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LookBackMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			LookDownMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraDetachMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraResetMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraTerrainMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraTargetReticuleMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
    void
      VehicleInterface::CalculatePresetsForExternalTargetReticule(); // helper function for above function
		void
			CameraPitchUpMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraPitchDownMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraRollRightMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraRollLeftMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraYawLeftMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraYawRightMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraPanUpMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraPanDownMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraPanLeftMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraPanRightMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraZoomInMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CameraZoomOutMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			MFDComm1MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			MFDComm2MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			MFDComm3MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			MFDComm4MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			MFDComm5MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			MFDComm6MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			MFDComm7MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			MFDComm8MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Throttle0MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Throttle10MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Throttle20MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Throttle30MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Throttle40MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Throttle50MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Throttle60MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Throttle70MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Throttle80MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Throttle90MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			Throttle100MessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CenterTorsoToLegsMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			CenterLegsToTorsoMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			NextFriendlyMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			PreviousFriendlyMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			NearestFriendlyMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void
			ToggleZoomReticuleMessageHandler(Adept::ReceiverDataMessageOf<int> *message);

// MSL 5.05 Objective Switch
		void ShowObjectivesMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void MuteMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void MouseTorsoToggleMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void MouseDeltaToggleMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
//		void AutoPilotMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void EjectMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void OverrideAutoCenterToTorsoMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void ShowMapMessageHandler (Adept::ReceiverDataMessageOf<int> *message);
		void OverrideShutdownMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void ToggleMouseControlMessageHandler(Adept::ReceiverDataMessageOf <int> *message);
		void ToggleLargeChatMessageHandler(Adept::ReceiverDataMessageOf <int> *message);
		void ToggleGroupWeaponModeMessageHandler(Adept::ReceiverDataMessageOf<int> *message);

//
// Section for keys we don't want in the release build
//

		void DebugFastMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void FreezeGameLogicMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void ImmediateWeaponLockModeMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void TakeSnapShotMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void SucceedMissionMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void FailMissionMessageHandler(Adept::ReceiverDataMessageOf<int> *message);
		void ToggleDebugHudMessageHandler(Adept::ReceiverDataMessageOf<int> *message);


		protected:
			static const MessageEntry
				MessageEntries[];
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Attribute Support
	//
	public:
		enum {
			JoyStickXAxisAttributeID = Interface::NextAttributeID,
			JoyStickYAxisAttributeID,
			JoyStickRudderAttributeID,
			JoyStickThrottleAttributeID,
			JoyStickHatAttributeID,
			MouseWheelAttributeID,
			MousePosXAttributeID,
			MousePosYAttributeID,
			MouseDeltaXAttributeID,
			MouseDeltaYAttributeID
		};

		enum {
			LeftFootForce,
			RightFootForce,
			FireMissleForce,
			FireProjectileForce,
			HitBackForce,
			HitFrontForce,
			HitLeftForce,
			HitRightForce,
			WaterMoveForce,
			FallDownForce,
			maxForces
		};

	public:
		//
		// Attributes
		//
		Vehicle
			*vehicle;

		bool
			animDiagnosticFlag;

		Stuff::Scalar
			joystickXAxis,
			joystickYAxis,
			joystickRudder,
			joystickThrottle,
			joystickHat,
			lastJoystickHat,
			lastJoystickTrottle;

		int
			throttle0Percent,
			throttle10Percent,
			throttle20Percent,
			throttle30Percent,
			throttle40Percent,
			throttle50Percent,
			throttle60Percent,
			throttle70Percent,
			throttle80Percent,
			throttle90Percent,
			throttle100Percent;

		int
			rotateLeftCommand,
			rotateRightCommand,
			forwardCommand,
			backwardCommand,
			originCommand,
			pageUp,
			insert,
			lControl,
			rControl,
			cameraDetachCommand,
			cameraResetCommand,
			cameraTerrainCommand,
			cameraTargetReticuleCommand,
			lookLeft,
			lookRight,
			lookBack,
			lookDown;

		Stuff::Time m_LastForwardCommand,m_LastBackwardCommand;


		bool
			reverseToggle;
#ifdef LAB_ONLY
		bool
			m_fImmediateWeaponLockMode;
#endif
//    int reverseCommand;

		int
			cameraPitchUp,
			cameraPitchDown,
			cameraRollRight,
			cameraRollLeft,
			cameraYawLeft,
			cameraYawRight,
			cameraPanUp,
			cameraPanDown,
			cameraPanLeft,
			cameraPanRight,
			cameraZoomIn,
			cameraZoomOut;


		int
			torsoTwistRight,
			torsoTwistLeft,
			pitchUp,
			pitchDown;

		int
			fireRequest;
		int
			group1FireRequest,
			group2FireRequest,
			group3FireRequest,
			group4FireRequest,
			group5FireRequest,
			group6FireRequest;
		int
			isCooling;
		bool
			needFireRequestReset;

		int netBandwidth;

		int mouseWheel;
		Stuff::Scalar mousePosX,mousePosY;
		Stuff::Scalar mouseDeltaX,mouseDeltaY;
		bool mouseTorsoToggle;
		bool mouseDeltaToggle;
		int m_FrameCount;
		bool preventFireThisFrame; // allows preventing shooting when changing directions of view.
		bool m_MouseEnable;
		int m_TorsoSpaceBarDown;
		static bool m_MouseYEnable;
		static Scalar m_MouseMinChange;
		static Scalar m_MouseMaxChange;
		
		virtual void ForceFeedBack (bool value);
		virtual void MouseAllowed (bool value)
		{
			m_MouseEnable = value;
			Interface::MouseAllowed (value);
		}
		static void LoadMouseYFlag (NotationFile *startup_ini);
		static void LoadMouseMinMax (NotationFile *startup_ini);


		HGOSFORCEEFFECT m_Forces[maxForces];
		HGOSFORCEEFFECT m_HitForce;
		gosJoystick_ForceEffect m_HitForceDetails;

		void PlayForce (int id);
		void StopForce (int id);
		void PlayHitForce (Stuff::Point3D dir,Stuff::Scalar amplitude);

		Stuff::Point3D
			cameraOffset;

		Stuff::YawPitchRoll
			cameraRotation;

    Stuff::Scalar
      externalCameraOffsetStartMinZ;

		Stuff::Point3D
			vehiclePosition;

		int leftFootFlag;
		int rightFootFlag;

		//Stuff::Scalar joystick_throttle_center;
		//Stuff::Scalar joystick_throttle_dead_low;
		//Stuff::Scalar joystick_throttle_dead_high;
		Scalar UseJoystickThrottle (Scalar value);
		bool ThrottleMoved (Scalar newvalue);
		Scalar curMouseX,curMouseY;
		bool m_ChangeMouseTorsoThisFrame;

		// HACK JSE
		Stuff::Scalar
			testAcceleration;
		// HACK JSE


		Stuff::Scalar
			lastSpeedDemand;

		int
			brbMode;

		Stuff::Scalar
			currentDistance;

		enum{
			InMechCameraView = 0,
			ExternalCameraAttachedView,
			ExternalCameraDetachedView,
			ExternalCameraTerrainFollowView,
			ExternalCameraTargetReticule,
			TopDownCameraView,
			NextCameraView,
			EditorCameraView
		};

		int
			cameraView;
		int
			rememberCameraView;

		Stuff::Point3D
			rememberCameraOffset;

		Stuff::YawPitchRoll
			rememberCameraRotation;


		bool reticuleZoomShowing;
		bool userRequestForreticuleZoomChange;
		bool requestedZoomChange;
		void ShowZoom (void);
		void HideZoom (void);

		bool
			cinemaPlaying;

		void SetCinemaPlaying(bool value);
		//This is for the targeting system of the attached vehicle
		MWMover*
			GetEyeSite(Stuff::MString site_name);

		MWMover*
			eyeSitePointer;

	

		// sound tests

		Stuff::Scalar
			twistRightTime,
			twistLeftTime,
			pitchUpTime,
			pitchDownTime,
			rotateRightTime,
			rotateLeftTime;

		Stuff::Scalar
			deathTimer;

	public:

		virtual void EnterChatMode (bool team);
		virtual void LeaveChatMode (void);

		bool
			observerMode;

		SlotOf<Adept::Entity*>
			observingEntity;

		void
			SetObservationMode();

		void
			FindNextMechToFollow();

// [MSR SPECTATOR STUFF] ===================================================
//##########################################################################
//###############    VehicleInterface::Spectator components     ############
//##########################################################################
		
	public:
		// public data
		enum							 // exposed state constants
		{
			STATE_FRONT_SHOT,
			STATE_OVERSHOULDER_SHOT,
			STATE_FIXED_TRACKING_SHOT,
			STATE_SIDE_SHOT,
			STATE_STD_OBSERVERMODE,
            STATE_DEATH_SEQUENCE_START,
            STATE_DEATH_SEQUENCE_TRANS,
            STATE_DEATH_SEQUENCE_SHOT,
		};
        enum
        {
		NO_RANGE = -1,
		CLOSESHOT = 0,
		MEDIUMSHOT = 1,
		LONGSHOT = 2,
        };

		// constants
		enum 
		{
			FROM_NOWHERE, 
			MW4_STD_OBSERVER, 
			MSR_SPECTATOR,
		};


		// camera methods
		void DampedOverShoulderShot
		( 
			LinearMatrix4D parent_local_to_world, 
			Point3D heroPos, 
			Point3D enemyPos, 
			int shotType
		);

		void OverShoulderShot
		( 
			LinearMatrix4D parentLocalToWorld, 
			LinearMatrix4D targetLocalToWorld, 
			int shotType
		);

		void SideShot
		( 
			LinearMatrix4D parentLocalToWorld, 
			LinearMatrix4D targetLocalToWorld
		);

		void FrontShot
		( 
			LinearMatrix4D parentLocalToWorld, 
			LinearMatrix4D targetLocalToWorld, 
			int shotType
		);

		void FixedTracking
		( 
			LinearMatrix4D targetLocalToWorld,
			int shotRangeTypeID
		);

        void HeroDeathToEnemyStart(LinearMatrix4D dyingLocalToWorld);
        void HeroDeathToEnemyTrans(LinearMatrix4D dyingLocalToWorld, float fPer, const LinearMatrix4D& newHeroLocalToWorld = *(const LinearMatrix4D*)NULL);

		void StdObserverMode(Point3D cameraPntLTW);
        void GetObserverPosition(Entity* parent, bool bUseTORSO, bool bUseInterpolation, Stuff::Point3D camOffset, Stuff::YawPitchRoll camRotation, Point3D& ptWorldPos, LinearMatrix4D& camToParent = *(LinearMatrix4D*)NULL); // jcem
		void ClearFixedPoint();


	private:
		int m_curView;             // temporary variable used for debugging cameras
        int m_curRange;            // range of current camera used
        Mech* m_pEnemy;
        Mech* m_pMechDying;
        Stuff::Time m_fTimeStateEnd; // start of time of current camera state 
		Point3D m_fixedPoint;         // fixed camera location for FixedTrack camera
		Point3D m_dyingHeroPoint;     // point where our dying hero is lying
        LinearMatrix4D m_dyingLocalToWorld;
		bool m_fDyingSequenceInited;  // true when enter death sequence
		bool m_fDeathTransDone;       // true when death transition camera sequence is completed
		bool m_fDeathTransInited;     // true when death trans anim delay is done
		Point3D m_heroPos;
		Point3D m_oldHeroPos;
		Point3D m_enemyPos;
		Point3D m_oldEnemyPos;
		Point3D m_tempEnemyPos;       // most immediate last enemy pos for transitioning in overshoulder shots
		bool m_fDampingInited;
		bool m_fDampTransDone;
        Entity* m_pLastParent; // GetObserverPosition to avoid Torso Twitching
        Stuff::Scalar m_fLastTorsoYAW; // GetObserverPosition to avoid Torso Twitching
        Stuff::Time m_fLastTorsoTime;
	public: // restoring scope for existing declarations in file

// END [MSR SPECTATOR STUFF]===============================================


	private:
		void
			IssueLancemateCommand(Adept::ReceiverDataMessageOf<int> *message, int command);

		bool m_Temporary_AddedLancemate;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Debug Speed Display
	public:
		Stuff::Scalar
			currentSpeedMPS,
			currentSpeedKPH,
			speedDemandMPS,
			speedDemandKPH,
			minForwardKPH,
			minReverseKPH,
			minForwardNormal,
			minReverseNormal,
			maxForwardKPH,
			maxReverseKPH;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Target Support
	//
	public:
		void
			SetTargetInfo();
		void
			CalculateInterfaceTargetPosition();
		void
			ExecuteNavSystem();
		void
			UpdateTargetWindow();
//		void UpdateReticuleWindow();
		void
			SetNavPoint(MechWarrior4::NavPoint *nav_point);
		MechWarrior4::NavPoint*
			GetNavPoint();

		Stuff::Time
			targetStartTime;

		Stuff::Time
			targetLossTime;

		Adept::Entity*
			TraceToParent(Adept::Entity *entity);

		SlotOf<Adept::Entity*>
			targetQueryEntity;

		SlotOf<Adept::Entity*>
			lockedTargetEntity;
		SlotOf<Adept::Entity*>
			lockedTargetEntityPart;
		Stuff::Point3D
			pointLockedEntityPartOffset;

		SlotOf<Adept::Entity*>
			targetEntity;
		SlotOf<Adept::Entity*>
			targetLastVehicleEntity;
		SlotOf<Adept::Entity*>
			targetEntityPart;
//		Adept::GUITextObject* m_LockTimeObject;

		Stuff::Scalar
			targetLockTime;
		Stuff::Scalar
			timeEntityHasBeenLocked;

		Stuff::SlotOf<Entity*>
			m_interfaceTarget;		//This is the targeted entity according to the HUD

		Stuff::SlotOf<NavPoint*>
			m_selectedNavPoint;

		ElementRenderer::CameraElement
			*m_targetCamera,
			*m_reticuleCamera;

		bool ShowTargetCamera (void);

		void
			SetGUITarget(Entity* target);
		Entity*
			GetGUITarget();

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//	HUD damage support
		static bool hudDamageMode;
		static bool hudTargetDamageMode;
// MSL 5.02 headshot
		bool hudZoomDestroyed;


	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//	Torso return support

		enum {
			LeaveTorsoAlone,
			CenterTorsoToLegs,
			CenterLegsToTorso,
		};

		static int perminateTorsoMode;
		int temporaryTorsoMode;
		Stuff::Scalar torsoAtRestTimer;

		void
			SetPerminateTorsoMode(int mode)
				{Check_Object(this); perminateTorsoMode = mode;};

		int
			GetPerminateTorsoMode()
				{Check_Object(this); return perminateTorsoMode;};


	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Game Reaction Support
	//
	public:
		// NOTE: the constants here must EXACTLY match those in ABLScripts\MWCONST.ABI!
		enum SOUND_TRIGGER {					// not really, they are events  but I don't want to change the name back
			CRITICAL_HIT_WEAPON	= 0,
			CRITICAL_HIT_GIMP,
			DAMAGE_CRITICAL,
			NO_HEAT,										// must be in order of heat so sounds don't play on the way down.
			LOW_HEAT,
			MED_HEAT,
			HIGH_HEAT,
			MELTDOWN,
			AUTO_SHUTDOWN_OVERRIDE,
			SHUTDOWN,
			POWER_UP,
			MISSILE_LOCKED,
			MISSILE_LOCKLOST,
			MISSILE_LOCKED_ON_ME,
			RADAR_RANGE_CHANGE,
			RADAR_ON,
			RADAR_OFF,
			ZOOM_RETICAL_ENGAGED,
			AMS_ENGAGED,
			LAMS_ENGAGED,
			NARC_SIGNAL_START,
			NARC_HIT,
			NEW_VEHICLE_RADAR_POWER_UP,
			TORSO_TWIST,
			TORSO_TWIST_MAX_REACHED,
			RADAR_JAMMED,
			COOLANT_FLUSH_START,
			COOLANT_FLUSH_STOP,
			OUT_OF_AMMO,
			OBJECT_SCANNED,
			INTERNAL_PPC_WASH,
			HILL_TOO_STEEP,
			TARGET_DESTROYED,
			TERRAIN_BAD,
			NARC_SIGNAL_STOP,
			RECHARGE_BEAM,
			RECHARGE_MISSILE,
			RECHARGE_PROJECTILE,
			RECHARGE_PPC,
			STEP_WATER_START,
			STEP_WATER_STOP,
			ENGINE_WALK,
			ENGINE_RUN,
			ENGINE_STOP,
			ENGINE_REVERSE,
			NAVPOINT_REACHED,
			KILLAWARDED,
			FRIENDLYFIREPENALTY,
			YOUHAVEFLAG,
			YOUINLEAD,
			TEAMMATEDESTROYED,
			FLAGTAKEN,
			FLAGCAPTURED,
			FLAGCAPTUREDHORN,
			FLAGRETURNED,
			HILLCONTESTED,
			HILLCAPTURED,
			REPAIR_START,
			REPAIR_STOP,
			DEFENDEDDESTROYED,
			MECH_DESTROYED,
			ENEMY_DEAD,
			ALLY_DEAD,
			LANCE_DEAD,
			COMM_OFF,
			INIT_REPAIR,
			REPAIR_COMP,
			ENEMY_CAPTURED,
			NAV_ALPHA,
			NAV_BETA,
			NAV_GAMMA,
			NAV_DELTA,
			NAV_EPSL,
			EXTRACT_POINT,
			TEAM_DEAD,
			YOU_WIN,
			YOU_LOSE,
			VICTORY_BABY,
			ALL_HILLS,
			BASE_CAPTURED,
            COLISEUM_AHH,
            COLISEUM_AWW,
            COLISEUM_BOO1,
            COLISEUM_BOO2,
            COLISEUM_BOO3,
            COLISEUM_CHANT1,
            COLISEUM_CHANT3,
            COLISEUM_CHEER1,
            COLISEUM_CHEER2,
            COLISEUM_CHEER3,
            COLISEUM_CHEER4,
            COLISEUM_CHEER5,
            COLISEUM_CHEER8,
            COLISEUM_CHEER9,
            COLISEUM_CROWD1,
            COLISEUM_CROWD2,
            COLISEUM_ENERGYZAP,
            COLISEUM_HORN,
            COLISEUM_JEERS,
            COLISEUM_ROAR,
            COLISEUM_STADAMB,
			COLISEUM_FACTORYHORN,
			COLISEUM_FACTORYBANG,
			COLISEUM_FACTORYBUZZ,
			COLISEUM_FACTORYCLANG,
			COLISEUM_FACTORYDRILL,
			COLISEUM_FACTORYSTEAM,
			COLISEUMAMB,
			COLISEUM_JUNGLEBIRD1,
			COLISEUM_JUNGLEBIRD2,
			COLISEUM_JUNGLEBIRD3,
			COLISEUM_JUNGLEBIRD4,
			COLISEUM_JUNGLEMONKEY1,
			COLISEUM_JUNGLEMONKEY2,
			TARGETATTACKED,
			TARGETDESTROYED,
			COMPONENT_DESTROYED,
			COMPDESTROYED,
			ZOOM_FAIL,
			MECH_AMMOBAY_FIRE,
			RETICULE_WASH,
			WEAPON_DESTROYED,
			AMMO_DUMPED,
			NO_WEAPON,
			FLAGCAPTUREDBUZZER,
			ALARM1,
			ALARM2

		};

		void ReactToEvent (SOUND_TRIGGER event, DWORD dwParam = 0);
		void StartEngineIdle (void);
		void EndEngineIdle (void);

	protected:

		Stuff::SlotOf<Adept::AudioCommand *> m_EngineIdleSound;
		Stuff::SlotOf<Adept::AudioCommand *> m_WaterStepSound;
		Stuff::Time m_LastTorsoTwistSoundTime;
		Stuff::Time m_LastStepWaterSoundTime;
		Stuff::Time m_LastHeatSoundTime;
		Stuff::Time m_NewRadarSoundTime;
		Stuff::Time m_LastEngineSoundTime;
		Stuff::Time m_LastAmmoDepletedSoundTime;
		int m_LastHeatLevel;		// equal to the last heat event
		bool m_PlayedDamageCritical;
		Stuff::SlotOf<Adept::AudioCommand*>
			m_narcSound,
			m_torsoSound,
			m_missileLockSound,
			m_coolantSound,
			m_damageCriticalSound,
			m_heatCriticalSound;

		void ReactToStepWater(bool start);
		void ReactToCriticalWeaponHit();
		void ReactToGimp();
		void ReactToMechShutDownOverride();
		void ReactToMechShutDown();
		void ReactToMechPowerUp();
		void ReactToIncommingMissile();
		void ReactToTargetDestruction();
// MSL 5.03 Ammo Dump
		void ReactToAmmoDump();
		void ReactToOutOfAmmo();

		//SFX Betty Support
		void ReactToHeatMeltdown();
		void ReactToMissileLock(bool lock);
		void ReactToZoom();
		void ReactToAMS();
		void ReactToLAMS();
		void ReactToCoolantFlush(bool start);


	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Network weapon support
	//

	public:
		bool weaponCommandReady;
		bool lockedWeaponCommandReady;

		WeaponUpdate
			weaponCommand;

		WeaponUpdate
			lockedWeaponCommand;

		void SaveTarget();
		

		void MarkWeapon(int weapon)
		{
			weaponCommandReady = true;
			weaponCommand.weaponFired |= (0x1 << weapon);
		}
		
		void MarkLockedWeapon(int weapon)
		{
			lockedWeaponCommandReady = true;
			lockedWeaponCommand.weaponFired |= (0x1 << weapon);
		}

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Weapon Support
	//

	protected:
		Stuff::Time m_LastShootTime;
	public:
		Stuff::Time LastTimeShot (void)
		{
			return m_LastShootTime;
		}

		void FireGroup(Stuff::Time till, int group);
		void GroupFireGroup (Stuff::Time till,Stuff::ChainOf<Weapon *>& group);
		void ChainFireGroup (Stuff::Time till,ChainIteratorOf<Weapon *> *groupWeaponIterator, int nGroupID = 1);

	public:
		void
			FireWeapon(Stuff::Time till);
		void
			FireGroup1(Stuff::Time till);
		void
			FireGroup2(Stuff::Time till);
		void
			FireGroup3(Stuff::Time till);
		void
			FireGroup4(Stuff::Time till);
		void
			FireGroup5(Stuff::Time till);
		void
			FireGroup6(Stuff::Time till);
		bool
			RequestingToFire();
		void
			InitializeWeapons();
		Scalar
			GetLockTimeMultiplier(Vehicle * vehicle, Entity * target);
		Stuff::Scalar
			GetWeaponLockTime();
		Scalar
			GetWeaponLockTime(Weapon *weapon);

// MSL 5.04 Weapon Lock
		float
			GetLockModifier(Vehicle * vehicle, Entity * target);
		bool
			GetLockModifierSTK(Vehicle * vehicle, Entity * target);
		bool
			GetWeaponLock();
		bool
			GetWeaponLockLRM();
		bool
			GetWeaponLockMRM();
		bool
			GetWeaponLockSRM();
		bool
			GetWeaponLockSSRM();
		bool
			GetWeaponLock(Weapon *weapon);

		void
			SetWeaponMode(int weapon_mode);
		void
			ToggleGroupWeaponMode(int group);

// MSL 5.03 Dump Ammo
		void DumpAmmoRound();

		void DumpAmmoMagazine();

		bool SetCameraViewLevel(int level);

		int
			GetCameraViewLevel() const;

		bool IsZoomReticuleAllowed();

		int
			weaponMode;
		int
			selectedWeaponGroup;
		int 
			groupWeaponMode[6];


		bool
			fireBlocked;


		Stuff::Scalar
			weaponFireTime;

		Stuff::ChainOf<Weapon *>
			weaponGroup[6];

		enum{
			ChainFireMode = 0,
			GroupFireMode,
			SingleFireMode
		};

		void
			SetBoundsWarningsEnabled(bool enabled);

		bool
			GetBoundsWarningsEnabled() const;

		Stuff::Scalar
			GetLastTimeFiredWeaponGroup(int weapon_group) const;

		bool
			m_AIControlledHUD;

	protected:

		Stuff::ChainIteratorOf<Weapon *>
			*weaponIterator;
		Stuff::ChainIteratorOf<Weapon *>
			*groupWeaponIterator[6];

		bool
			m_BoundsWarningsEnabled;

		Stuff::Scalar
			m_LastTimeFiredWeaponGroup[6];

	public:
#if 0
		class LancemateCommandDisplay
		{
		  public:
			LancemateCommandDisplay();
			~LancemateCommandDisplay();
			void SetText(const std::string& text, Stuff::Scalar duration);
			void Update();

		  private:
			Stuff::Time m_WhenToStopDisplayingText;
			Adept::GUITextObject* m_Object;
		};

		LancemateCommandDisplay m_LancemateCommandDisplay;
#endif
    public:
        // jcem
        bool SetNewRequestedTarget(Entity* target_entity);
        int IsObserving(bool bIncObserverMode = false) const;
        int GetShutdownState() const;
        int GetJumpJetState() const;
        int GetGUIRadarStates(int state[/*12*/]) const;
        int GetEjectableState() const;
	};

	inline
		VehicleInterface__ExecutionStateEngine::VehicleInterface__ExecutionStateEngine(
			ClassData *class_data,
			VehicleInterface *vehicle_interface,
			FactoryRequest *request
		):
		Adept::Entity__ExecutionStateEngine(class_data, vehicle_interface, request)
	{
	}

    class CamerashipParams
    {
    public:
        bool m_bAllowChatDisplay;
        bool m_bAllowBOTs;
        bool m_bDisplayCameraStates;
        Stuff::Scalar m_fDistGroundLevel;
        Stuff::Scalar m_fDistGroundLevelShift;
        Stuff::Scalar m_fTimeScoringInterval;
        Stuff::Scalar m_fTimeScoringDuration;
        Stuff::Scalar m_fTimeIdleChange;
        Stuff::Scalar m_fTimeStandard;
        Stuff::Scalar m_fDistStandard;
        Stuff::Scalar m_fHeightStandard;
        Stuff::Scalar m_fHeightStandardLookAt;
        Stuff::Scalar m_fTimeDeathWatching;
        Stuff::Scalar m_fOffsDeathWatchingX;
        Stuff::Scalar m_fOffsDeathWatchingY;
        Stuff::Scalar m_fOffsDeathWatchingZ;
        Stuff::Scalar m_fTimeDeathTransition;
        Stuff::Scalar m_fTimeFixedTracking;
        Stuff::Scalar m_fOffsFixedTrackingX;
        Stuff::Scalar m_fOffsFixedTrackingY;
        Stuff::Scalar m_fOffsFixedTrackingZ;
        Stuff::Scalar m_fTimeSideShot;
        Stuff::Scalar m_fDistSideShot;
        Stuff::Scalar m_fOffsSideShotX;
        Stuff::Scalar m_fOffsSideShotY;
        Stuff::Scalar m_fOffsSideShotHeadY;
        Stuff::Scalar m_fTimeFrontShot;
        Stuff::Scalar m_fOffsFrontShotHeadY;
        Stuff::Scalar m_fOffsFrontShotCameraY;
        Stuff::Scalar m_fDistFrontShot;
        Stuff::Scalar m_fTimeOverShoulder;
        Stuff::Scalar m_fOffsOverShoulderHeroX;
        Stuff::Scalar m_fOffsOverShoulderHeroY;
        Stuff::Scalar m_fOffsOverShoulderHeroZ;
        Stuff::Scalar m_fOffsOverShoulderEnemyY;
    public:
        CamerashipParams();
        void LoadOptions(NotationFile& startup_ini);
    };
    extern BOOL g_baChainFireMode[3];
    int GetFiringMode();
}

