#ifndef __GAME_SETUP_H__
#define __GAME_SETUP_H__

#include <string>
#include <map>
#include <vector>

#include "SFloat3.h"
#include "GlobalStuff.h"
#include "PlayerBase.h"

class TdfParser;

class CGameSetup
{
public:
	CGameSetup();
	~CGameSetup();
	bool Init(std::string setupFile);
	bool Init(const char* buf, int size);
	void LoadStartPositions();
	
	enum StartPosType
	{
		StartPos_Fixed = 0,
		StartPos_Random = 1,
		StartPos_ChooseInGame = 2,
		StartPos_ChooseBeforeGame = 3,
		StartPos_Last = 3  // last entry in enum (for user input check)
	};

	int myPlayerNum;
	int numPlayers; //the expected amount of players
	int numTeams;
	int numAllyTeams;
	bool fixedAllies;
	std::string mapName;
	std::string baseMod;
	std::string scriptName;
	bool useLuaGaia;
	std::string luaGaiaStr;
	std::string luaRulesStr;
	
	std::string hostip;
	int hostport;
	int sourceport; //the port clients will try to connect from
	int autohostport;
	
	char* gameSetupText;
	int gameSetupTextLength;
	
	StartPosType startPosType;
	
	std::vector<PlayerBase> playerStartingData;
	
	struct TeamData
	{
		unsigned leader;
		unsigned char color[4];
		float handicap;
		std::string side;
		SFloat3 startPos;
		int teamStartNum;
		int teamAllyteam;
		std::string aiDll;
	};
	std::vector<TeamData> teamStartingData;
	
	struct AllyTeamData
	{
		float startRectTop;
		float startRectBottom;
		float startRectLeft;
		float startRectRight;
		bool allies[MAX_TEAMS];
	};
	std::vector<AllyTeamData> allyStartingData;
	
	std::map<std::string, int> restrictedUnits;

	std::map<std::string, std::string> mapOptions;
	std::map<std::string, std::string> modOptions;
	
	int maxUnits;
	
	bool ghostedBuildings;
	bool limitDgun;
	bool diminishingMMs;
	bool disableMapDamage;
	
	float maxSpeed;
	float minSpeed;
	
	bool hostDemo;
	std::string demoName;
	int numDemoPlayers;
	
	std::string saveName;
	
	int startMetal;
	int startEnergy;
	
	int gameMode;
	int noHelperAIs;

private:
	void LoadStartPositionsFromMap();
	void LoadUnitRestrictions(const TdfParser& file);
	void LoadPlayers(const TdfParser& file);
	void LoadTeams(const TdfParser& file);
	void LoadAllyTeams(const TdfParser& file);

	void RemapPlayers();
	void RemapTeams();
	void RemapAllyteams();

	std::map<int, int> playerRemap;
	std::map<int, int> teamRemap;
	std::map<int, int> allyteamRemap;
};

extern const CGameSetup* gameSetup;

#endif // __GAME_SETUP_H__
