/////////////////////////////////////////////////////////////////////
// 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 = "^o[BOT]^7";
global AxisBotPrefix = BotPrefix;
global AlliedBotPrefix = BotPrefix;

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

// Covert Ops
t = { class=CLASS.COVERTOPS, weapon=0, profile="" };
AxisBots["Walter"] = t;
AxisBots["Fred"] = t;
AxisBots["Morgan"] = t;
AxisBots["Lawrence"] = t;
AxisBots["Richard"] = t;
AxisBots["Michael"] = t;
AxisBots["Brad"] = t;

// Engineers
t = { class=CLASS.ENGINEER, weapon=0, profile="" };
AxisBots["George"] = t;
AxisBots["Anton"] = t;
AxisBots["Monty"] = t;
AxisBots["Bean"] = t;
AxisBots["Sean"] = t;
AxisBots["Backfire"] = t;
AxisBots["Halfwit"] = t;

// Field Ops
t = { class=CLASS.FIELDOPS, weapon=0, profile="" };
AxisBots["Halfbaked"] = t;
AxisBots["Fullmonty"] = t;
AxisBots["Nohope"] = t;
AxisBots["Hitnrun"] = t;
AxisBots["Missnrun"] = t;
AxisBots["Oysterhead"] = t;
AxisBots["Fullthrottle"] = t;

// Medics
t = { class=CLASS.MEDIC, weapon=0, profile="" };
AxisBots["NoAmmo"] = t;
AxisBots["Bullseye"] = t;
AxisBots["Aimless"] = t;
AxisBots["Blackadder"] = t;
AxisBots["Newbie"] = t;
AxisBots["Cledus"] = t;
AxisBots["Chimichanga"] = t;

// Soldiers
t = { class=CLASS.SOLDIER, weapon=0, profile="" };
AxisBots["Razor"] = t;
AxisBots["Tanz"] = t;
AxisBots["Vic"] = t;
AxisBots["Malin"] = t;
AxisBots["Thor"] = t;
AxisBots["Grog"] = t;
AxisBots["Drago"] = t;

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

// Covert Ops
t = { class=CLASS.COVERTOPS, weapon=0, profile="" };
AlliedBots["Stinger"] = t;
AlliedBots["Tarnok"] = t;
AlliedBots["Wens"] = t;
AlliedBots["Brohn"] = t;
AlliedBots["Ivor"] = t;
AlliedBots["Gordac"] = t;
AlliedBots["Bortack"] = t;

// Engineers
t = { class=CLASS.ENGINEER, weapon=0, profile="" };
AlliedBots["Morgriff"] = t;
AlliedBots["Kole"] = t;
AlliedBots["Garbok"] = t;
AlliedBots["Korv"] = t;
AlliedBots["Vokur"] = t;
AlliedBots["Gali"] = t;
AlliedBots["Beelz"] = t;

// Field Ops
t = { class=CLASS.FIELDOPS, weapon=0, profile="" };
AlliedBots["CraigChrist"] = t;
AlliedBots["WhittlinMan"] = t;
AlliedBots["SpecialEd"] = t;
AlliedBots["Flint"] = t;
AlliedBots["Argo"] = t;
AlliedBots["Milius"] = t;
AlliedBots["Vera"] = t;

// Medics
t = { class=CLASS.MEDIC, weapon=0, profile="" };
AlliedBots["Merki"] = t;
AlliedBots["Tarnen"] = t;
AlliedBots["Royen"] = t;
AlliedBots["Kaolin"] = t;
AlliedBots["Nandet"] = t;
AlliedBots["Nundak"] = t;
AlliedBots["Ryver"] = t;

// Soldiers
t = { class=CLASS.SOLDIER, weapon=0, profile="" };
AlliedBots["Mungri"] = t;
AlliedBots["Chan"] = t;
AlliedBots["Amadi"] = t;
AlliedBots["Zarna"] = t;
AlliedBots["PillowPants"] = t;
AlliedBots["ListerFiend"] = 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 };
};
