#pragma once


#define MWCORPORATION_UNIT_STRENGTH_VALID   0x00000001
#define MWCORPORATION_INFAMY_VALID          0x00000002
#define MWCORPORATION_STEINER_RATING_VALID  0x00000004
#define MWCORPORATION_DAVION_RATING_VALID   0x00000008
#define MWCORPORATION_NOBILITY_VALID        0x00000010

#define MWCORPORATION_GRAPH_DATA_VALID      0x0000001F

#define      NUM_OF_ARENAS                        3 //** should be moved somewhere else
#define      CORPORATION_CYCLE_EXPENSE_FRACTION   (float)0.05 //applied to the sum of all the dragoon values to get the companies maintenance costs for a particular cycle
#define      NUM_OF_DRAGOONS_FOR_UNIT_STRENGTH    8

namespace MechWarrior4
{

	typedef Receiver__ClassData				MWCorporation__ClassData;
	typedef Receiver__Message				MWCorporation__Message;

	class MWCorporation : public Adept::Receiver
	{
	private:
		int   dwFlags; //?
		Stuff::MString  m_szCompanyName; //The name of the mercenary regiment, read by GOS
		int   m_iSponsorRegiment; //The number identifier of the mercenary regiment (see enumerated type) -- associated with a string
		int   m_iSolarisTitle; //The number identifier of the players' current solaris title (ex. Grand Champion, Loser)
		int   m_iCurrentStatus; //Your current status with your sponsor regiment -- accociated with a string
		int   m_iDate; //A cycle counter, each cycle represents 2 weeks after the start-date
		int   m_iMissionVictoryCount; //self-explanatory
		int   m_iMissionDefeatCount; //self-explanatory
		int   m_aiArenaVictoryCount[NUM_OF_ARENAS]; //array of statistics for each of the arenas
		int   m_aiArenaDefeatCount[NUM_OF_ARENAS]; //array of statistics for each of the arenas
		int   m_iPlayerMechKills; //number of mechs you kill
		int   m_iLanceMechKills; //number of mechs your lancemates kill
		//stored for each cycle
		std::vector<int>   m_unitStrength;  //your eight highest dragoon values in your Mech Inventory
		std::vector<int>   m_infamy; //Your standing within your regiment
		std::vector<int>   m_steinerFactionRating; //self-explanatory
		std::vector<int>   m_davionFactionRating; //self-explanatory
		std::vector<int>   m_nobility; //how well you play the game, like a paladin

	public:
		static ClassData 
			*DefaultData;

		typedef MWCorporation__ClassData		ClassData;
		typedef MWCorporation__Message		  	Message;
	/*
		enum {
			RegimentWoDrg = 5100, //corresponds to the scriptstring table and mwconst.abi in the ABL code
			RegimentNoHi,
			RegimentKlHnd,
			RegimentGDLeg
		};
	*/

		enum { //for getting graph data from GOS -- need to be defined in GOS-SCRIPT too
			InfamyTAG = 1,
			UnitStrenthTAG,
			SteinerTAG,
			DavionTAG,
			NobilityTAG
		};

	/*
		enum {
			StatusProbation = 5104, //corresponds to the scriptstring table and mwconst.abi in the ABL code
			StatusRegular,
			StatusFullMember,
			StatusSuspended,
			StatusDisavowed
		};

		enum { //solaris title
			SolTitleOne = 5109,  //corresponds to the scriptstring table and mwconst.abi in the ABL code
			SolTitleTwo,
			SolTitleThree,
			SolTitleFour,
			SolTitleFive,
			SolTitleSix,
			SolTitleSeven,
			SolTitleEight,
			SolTitleNine,
			SolTitleTen
		};
	*/

	public:
		//Contstructor(s)
		MWCorporation (Stuff::MemoryStream *stream);

		//Destructor(s)
		~MWCorporation ();


		//Serialization and Misc.
		static void	InitializeClass();
		static void	TerminateClass();

		static MWCorporation *MakeNewCorporation (const ResourceID& corporation_resource_id);
		static MWCorporation *MakeNewCorporation (const char *corporation_name);

		static void ConstructCorporationStream (MemoryStream *stream);
		void Save (MemoryStream *stream);

		void TestInstance();


		//Accessors
		inline Stuff::MString GetCompanyName  (void) 
		{
			char *test;
			test = (char*)m_szCompanyName;
			m_szCompanyName.GetLength();
			return MWCorporation::m_szCompanyName; 
		}
		inline int     GetSolarisTitle        (void) { return MWCorporation::m_iSolarisTitle; }
		int            GetCycleExpenses       (void); //Costs for current cycle -- some percentage of the sum of your dragoon ratings
		inline int     GetSponsorRegimentID   (void) { return MWCorporation::m_iSponsorRegiment; }
		inline int     GetCurrentStatusValue  (void) { return MWCorporation::m_iCurrentStatus; }
		inline int     GetCurrentCycle        (void) { return MWCorporation::m_iDate; } //returns the date
		inline int     GetMissionVictoryCount (void) { return MWCorporation::m_iMissionVictoryCount; }
		inline int     GetMissionDefeatCount  (void) { return MWCorporation::m_iMissionDefeatCount; }
		void           GetArenaRecord (int arenaIndex, int &wins, int &losses)
		{
			wins = m_aiArenaVictoryCount[arenaIndex];
			losses = m_aiArenaDefeatCount[arenaIndex];
			return;
		}
		inline int     GetPlayerMechKills      (void) { return MWCorporation::m_iPlayerMechKills; }
		inline int     GetLanceMateMechKills   (void) { return MWCorporation::m_iLanceMechKills; }

		int            GetCurrentUnitStrength         (void);
		int            GetCurrentInfamy               (void);
		int            GetCurrentSteinerFactionRating (void);
		int            GetCurrentDavionFactionRating  (void);
		int            GetCurrentNobility             (void);

		void           GetGraphData (char type, int **data, int &size);

		void           SetCompanyName           (Stuff::MString name) { MWCorporation::m_szCompanyName = name; }
		inline void    SetSolarisTitle          (int title)       { MWCorporation::m_iSolarisTitle = title; }
		inline void    SetSponsorRegimentID     (int regID)       { MWCorporation::m_iSponsorRegiment = regID; }
		inline void    SetCurrentStatusValue    (int value)       { MWCorporation::m_iCurrentStatus = value; }
		inline void    IncrementCycle           (void)           
		{ 
			++MWCorporation::m_iDate; 
			MWCorporation::dwFlags &= ~MWCORPORATION_GRAPH_DATA_VALID; 
		}
		inline void    AddToMissionVictoryCount (int num = 1)    { MWCorporation::m_iMissionVictoryCount += num; }
		inline void    AddToMissionDefeatCount  (int num = 1)    { MWCorporation::m_iMissionDefeatCount += num; }
		inline void    AddWinToArenaRecord      (int arenaIndex) { ++MWCorporation::m_aiArenaVictoryCount[arenaIndex]; }
		inline void    AddLossToArenaRecord     (int arenaIndex) { ++MWCorporation::m_aiArenaDefeatCount[arenaIndex]; }
		inline void    AddToPlayerMechKills     (void)           { ++MWCorporation::m_iPlayerMechKills; }
		inline void    AddToLanceMateMechKills  (void)           { ++MWCorporation::m_iLanceMechKills; }

		int            UpdateAndSetCurrentUnitStrength (void); //goes and gets the top 8 mechs and adds their dragoon values together -- also returns the value
		int            SetCurrentInfamy                (int value);
		int            SetCurrentSteinerFactionRating  (int value);
		int            SetCurrentDavionFactionRating   (int value);
		int            SetCurrentNobility              (int value);


		static MWCorporation* GetInstance() 
		{
			return reinterpret_cast<MWCorporation *>( GlobalPointers::GetGlobalPointer(MWCorporationGlobalPointerIndex));
		};



	}; //class MWCorporation
}