//===========================================================================//
// File:	bridge.hpp													
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 01/12/2000  AHF  Inital base class
//===========================================================================//

#pragma once

#include "MW4.hpp"
#include "building.hpp"

namespace MechWarrior4
{

	class LancematePlug:
		public Stuff::Plug
	{
		friend class AI;
	public:
		LancematePlug(Stuff::MemoryStream *stream);
		~LancematePlug();

		static void
			ConstructStream(MemoryStream *stream,Stuff::Page *page);
		void
			WriteToText(Stuff::NotationFile& file);
		void
			Save(MemoryStream *stream);

		Stuff::MString
			m_lancemateName;
		Adept::ResourceID
			m_lanceDataListID;
		Stuff::MString
			m_TalkerSuffix;
		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Personality Support
		//
	public:
		enum LANCEMATE_STATE
		{
			OK,
			INJURED,
			MIA,
			KIA
		};

		bool
			Joined (void) const
				{Check_Object(this); return m_Joined;}
		void 
			Joined (bool value)
				{ Check_Object (this); m_Joined = value; }
		LANCEMATE_STATE
			State (void) const
				{Check_Object(this); return m_CurrentState;}
		bool
			MustSurvive() const
				{Check_Object(this); return (m_MustSurvive);}
		int
			GetLanceIDBasedOnSuffix();
		void
			State(LANCEMATE_STATE new_state)
				{Check_Object(this); m_CurrentState = new_state;}

	protected:
		bool
			m_MustSurvive;
		LANCEMATE_STATE
			m_CurrentState;	
		bool
			m_Joined;									// whether the lancemate has been found by the player


		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Skill Support
		//

	protected:
		int m_GunnerySkill;
		int m_PilotSkill;
		int m_EliteSkill;
		int m_MinHeatSkill;
		int m_MaxHeatSkill;
		int m_SensorSkill;
		int m_BlindFightingSkill;
		int m_LongRangeGunnerySkill;
		int m_ShortRangeGunnerySkill;

		int m_TowardsPilotSkill;
		int m_TowardsGunnerySkill;
		int m_TowardsEliteSkill;
		int m_StartGunnerySkill;
		int m_StartPilotSkill;
		int m_StartEliteSkill;

	public:
		void CopyToAI (AI *target);
		void CopyFromAI (AI *src);

		int GetStartGunnerySkill (void) const
		{ return m_StartGunnerySkill; }
		int GetStartPilotSkill (void) const
		{ return m_StartPilotSkill; }

		int RootGunnerySkill (void) const
		{ return m_GunnerySkill; }
		int RootPilotSkill (void) const
		{ return m_PilotSkill; }
		int RootSensorSkill (void) const
		{ return m_SensorSkill; }
		int RootBlindFightingSkill (void) const
		{ return m_BlindFightingSkill; }
		int RootLongRangeGunnerySkill (void) const
		{ return m_LongRangeGunnerySkill; }
		int RootShortRangeGunnerySkill (void) const
		{ return m_ShortRangeGunnerySkill; }
		int RootEliteSkill (void) const
		{ return m_EliteSkill; }
		int RootMinHeatSkill (void) const
		{ return m_MinHeatSkill; }
		int RootMaxHeatSkill (void) const
		{ return m_MaxHeatSkill; }

		int GunnerySkill (void) const;
		int PilotSkill (void) const;
		int SensorSkill (void) const;
		int BlindFightingSkill (void) const;
		int LongRangeGunnerySkill (void) const;
		int ShortRangeGunnerySkill (void) const;
		int EliteSkill (void) const;
		int MinHeatSkill (void) const;
		int MaxHeatSkill (void) const;
		void GunnerySkill (int newvalue)
		{
			m_GunnerySkill = newvalue;
			m_StartGunnerySkill = newvalue;
		}

		void PilotSkill (int newvalue)
		{
			m_PilotSkill = newvalue;
			m_StartPilotSkill = newvalue;
		}

		void SensorSkill (int newvalue)
		{ m_SensorSkill = newvalue; }
		
		void BlindFightingSkill (int newvalue)
		{ m_BlindFightingSkill = newvalue; }
		
		void LongRangeGunnerySkill (int newvalue)
		{ m_LongRangeGunnerySkill = newvalue; }
		
		void ShortRangeGunnerySkill (int newvalue)
		{ m_ShortRangeGunnerySkill = newvalue; }

		void EliteSkill (int newvalue)
		{
			m_EliteSkill = newvalue;
			m_StartEliteSkill = newvalue;
		}
																									
		void MinHeatSkill (int newvalue)
		{ m_MinHeatSkill = newvalue; }

		void MaxHeatSkill (int newvalue)
		{ m_MaxHeatSkill = newvalue; }

		bool ShouldEjectSafely();
	};

	typedef Receiver__ClassData			LancemateManager__ClassData;
	typedef Receiver__Message				LancemateManager__Message;

	class LancemateManager : 		public Receiver
	{
	public:
		static void InitializeClass();
		static void TerminateClass();

		//##########################################################################
		// Inheritance support
		//
	public:
		typedef LancemateManager__ClassData              ClassData;
		typedef LancemateManager__Message                Message;


		static void ConstructLancemateStream(Stuff::MemoryStream *stream,NotationFile *notation_file);

		static LancemateManager* MakeNewLancemateManager(const char *lancematemanager_name);
		static LancemateManager* MakeNewLancemateManager(Adept::ResourceID lancemate_id);

		void Save(MemoryStream *stream);
		void WriteToText(const char *file_name);

		LancemateManager(Stuff::MemoryStream *stream);

		~LancemateManager();

		Stuff::ChainOf<LancematePlug*> m_lancemates;

		static LancemateManager *Instance;

		LancematePlug
			*FindLancemate(MString lance_name,bool case_sensitive = true);

		void RevealLancemate (char *name);
		void HideLancemate (char *name);

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

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

