/////////////////////////////////////////////////////////////////////
// initialize the team tables
AxisBots = {};
AlliedBots = {};

/////////////////////////////////////////////////////////////////////
// USER CONFIG STARTS HERE
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
// Register default profiles for the game classes.
foreach (cls in Util.PlayerClassTable)
{
	RegisterDefaultProfile(cls, "def_bot.gm");
}

/////////////////////////////////////////////////////////////////////
// optionally assign a prefix for the bot name. set to "" for no prefix
global BotPrefix = "^7[^2B^3O^1T^7]^7";
global AxisBotPrefix = BotPrefix ;
global AlliedBotPrefix =  BotPrefix ;

/////////////////////////////////////////////////////////////////////
// Axis Bots

// Covert Ops
t = { class=CLASS.COVERTOPS, weapon=0, profile="" };
AxisBots["^6Walter"] = t;
AxisBots["^1Fred"] = t;
AxisBots["^2Morgan"] = t;
AxisBots["^3Lawrence"] = t;
AxisBots["^4Richard"] = t;
AxisBots["^eMichael"] = t;
AxisBots["^xBrad"] = t;

// Engineers
t = { class=CLASS.ENGINEER, weapon=0, profile="" };
AxisBots["^1George"] = t;
AxisBots["^9Anton"] = t;
AxisBots["^2Monty"] = t;
AxisBots["^7Bean"] = t;
AxisBots["^3Sean"] = t;
AxisBots["^6Backfire"] = t;
AxisBots["^uHalfwit"] = t;

// Field Ops
t = { class=CLASS.FIELDOPS, weapon=0, profile="" };
AxisBots["^kHalfbaked"] = t;
AxisBots["^hFullmonty"] = t;
AxisBots["^eNohope"] = t;
AxisBots["^?Hitnrun"] = t;
AxisBots["^aMissnrun"] = t;
AxisBots["^cOysterhead"] = t;
AxisBots["^2Fullthrottle"] = t;

// Medics
t = { class=CLASS.MEDIC, weapon=0, profile="" };
AxisBots["^NoAmmo"] = t;
AxisBots["^xBullseye"] = t;
AxisBots["^1Aimless"] = t;
AxisBots["^6Blackader"] = t;
AxisBots["^4Newbie"] = t;
AxisBots["^2Cledus"] = t;
AxisBots["^9Chimichanga"] = t;

// Soldiers
t = { class=CLASS.SOLDIER, weapon=0, profile="" };
AxisBots["^>Razor"] = t;
AxisBots["^jTanz"] = t;
AxisBots["^fVic"] = t;
AxisBots["^+Malin"] = t;
AxisBots["^-Thor"] = t;
AxisBots["^5Grog"] = t;
AxisBots["^<Drago"] = t;

/////////////////////////////////////////////////////////////////////
// Allied Bots

// Covert Ops
t = { class=CLASS.COVERTOPS, weapon=0, profile="" };
AlliedBots["^1Stinger"] = t;
AlliedBots["^2Tarnok"] = t;
AlliedBots["^3Wens"] = t;
AlliedBots["^4Brohn"] = t;
AlliedBots["^5Ivor"] = t;
AlliedBots["^6Gordac"] = t;
AlliedBots["^eBortack"] = t;

// Engineers
t = { class=CLASS.ENGINEER, weapon=0, profile="" };
AlliedBots["^eMorgriff"] = t;
AlliedBots["^6Kole"] = t;
AlliedBots["^5Garbok"] = t;
AlliedBots["^4Korv"] = t;
AlliedBots["^3Vokur"] = t;
AlliedBots["^2Gali"] = t;
AlliedBots["^1Beelz"] = t;

// Field Ops
t = { class=CLASS.FIELDOPS, weapon=0, profile="" };
AlliedBots["^4CraigChrist"] = t;
AlliedBots["^2WhittlinMan"] = t;
AlliedBots["^eSpecialEd"] = t;
AlliedBots["^3Flint"] = t;
AlliedBots["^5Argo"] = t;
AlliedBots["^6Milius"] = t;
AlliedBots["^1Vera"] = t;

// Medics
t = { class=CLASS.MEDIC, weapon=0, profile="" };
AlliedBots["^k^Merki"] = t;
AlliedBots["^cTarnen"] = t;
AlliedBots["^hRoyen"] = t;
AlliedBots["^aKaolin"] = t;
AlliedBots["^dNandet"] = t;
AlliedBots["^*Nundak"] = t;
AlliedBots["^-Ryver"] = t;

// Soldiers
t = { class=CLASS.SOLDIER, weapon=0, profile="" };
AlliedBots["^jMungri"] = t;
AlliedBots["^uChan"] = t;
AlliedBots["^kAmadi"] = t;
AlliedBots["^iZarna"] = t;
AlliedBots["^+PillowPants"] = t;
AlliedBots["^7ListerFiend"] = t;
AlliedBots["^>Ilikechocmilk"] = t;

/////////////////////////////////////////////////////////////////////
// Overflow bots - used if no bots left for team / class desired
global ExtraBots =
{
	"Himdar",
	"Vedro",
	"Icexo",
	"Tahlkora",
	"Bolund",
	"Ellanil",
	"Galul",
	"Mindelos",
	"Ostmor",
	"Sagel",
	"Thalath",
	"Dharmesh",
	"Aegarond",
	"Havo",
	"Jarno",
	"Leiruth",
	"Edoli",
	"Edwig",
	"Faden",
	"Skorgan"
};

/////////////////////////////////////////////////////////////////////
// END USER CONFIG. DO NOT EDIT BELOW
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
// initialize some global tables for external reference
// the previous tables are set up for user friendliness
global _AxisBots = {};
global _AlliedBots = {};
global _PreferredWeapon = {};
global _OverFlowBotNumber = 0;

/////////////////////////////////////////////////////////////////////
// register the bot names and set up tables for OnBotAutoJoin reference

InitNames = function ( tbl1, tbl2, prefix)
{
	foreach ( botName and loadout in tbl1 ) {
		name = prefix + botName;
		Names[ name ] = loadout.profile;
		if (!tbl2[ loadout.class ]) {
			tbl2[ loadout.class ] = {};
		}
		// add the name to the list
		Util.AddToTable(tbl2[ loadout.class ], name);

		if (loadout.weapon) {
			_PreferredWeapon[ name ] = loadout.weapon;
		}
	}
};

InitNames(AxisBots, _AxisBots, AxisBotPrefix);
InitNames(AlliedBots, _AlliedBots, AlliedBotPrefix);

/////////////////////////////////////////////////////////////////////
// pick a bot to add based on team / class needed
global OnBotAutoJoin = function()
{
	desiredTeam = TEAM.AXIS;
	if ( tableCount(Server.Team)>0 && (Server.Team[TEAM.AXIS].NumPlayers > Server.Team[TEAM.ALLIES].NumPlayers
		|| Server.Team[TEAM.AXIS].NumPlayers == Server.Team[TEAM.ALLIES].NumPlayers && Server.Team[TEAM.AXIS].NumBots > Server.Team[TEAM.ALLIES].NumBots)
		|| GetModName() == "infected") {
		desiredTeam = TEAM.ALLIES;
	}

	desiredClass = ClassManager.EvalClassByTeam(desiredTeam);

	teamTable = _AxisBots;
	if ( desiredTeam == TEAM.ALLIES ) {
		teamTable = _AlliedBots;
	}

	// find a bot for the team and class. sequential lookup for now.
	// cs: note: gm tables are actually randomized, so bots will vary
	// from game to game.
	botName = null;
	if ( teamTable[ desiredClass ] ) {
		foreach ( name in teamTable[ desiredClass ] ) {
			// make sure this name is not already used
			if ( !Util.GetBotByName(name) ) {
				botName = name;
				break;
			}
		}
	}

	if ( !botName && _OverFlowBotNumber < tableCount(ExtraBots) ) {
		botName = ExtraBots[_OverFlowBotNumber];
		global _OverFlowBotNumber = _OverFlowBotNumber + 1;

		if ( desiredTeam == TEAM.ALLIES ) {
			botName = AlliedBotPrefix + botName;
		} else {
			botName = AxisBotPrefix + botName;
		}
	}

	return { class = desiredClass, team = desiredTeam, name = botName };
};
