// Load any other scripts that we will need.
ExecScript("et_utilities.gm");
ExecScript( "difficulty.gm" );	

// Register default profiles for the game classes.
RegisterDefaultProfile(CLASS.SOLDIER, "def_bot.gm");
RegisterDefaultProfile(CLASS.MEDIC, "def_bot.gm");
RegisterDefaultProfile(CLASS.ENGINEER, "def_bot.gm");
RegisterDefaultProfile(CLASS.FIELDOPS, "def_bot.gm");
RegisterDefaultProfile(CLASS.COVERTOPS, "def_bot.gm");

// Set up a list of Names, optionally associated with a script.
Names["[BOT]Walter"] = "";
Names["[BOT]Fred"] = "";
Names["[BOT]Morgan"] = "";
Names["[BOT]Lawrence"] = "";
Names["[BOT]Richard"] = "";
Names["[BOT]Michael"] = "";
Names["[BOT]Brad"] = "";
Names["[BOT]George"] = "";
Names["[BOT]Anton"] = "";
Names["[BOT]Monty"] = "";
Names["[BOT]Bean"] = "";
Names["[BOT]Sean"] = "";
Names["[BOT]Backfire"] = "";
Names["[BOT]Halfwit"] = "";
Names["[BOT]Halfbaked"] = "";
Names["[BOT]Fullmonty"] = "";
Names["[BOT]Nohope"] = "";
Names["[BOT]Hitnrun"] = "";
Names["[BOT]Missnrun"] = "";
Names["[BOT]Oysterhead"] = "";
Names["[BOT]Fullthrottle"] = "";
Names["[BOT]Noammo"] = "";
Names["[BOT]Bullseye"] = "";
Names["[BOT]Aimless"] = "";
Names["[BOT]Blackadder"] = "";

// Register a bot with a script. Uncomment this line to try the sample bot.
//Names["samplebot"] = "sample.gm";

// Set minbots/maxbots on map start
//MinBots(2);
//MaxBots(12);

// This is optional for ET. By default breakable objects won't be targeted, because this 
// distance defaults to 0. Set this to some low value to allow bots to target breakable objects.
// This number is the distance that bots are allowed to target breakable entities at.
// It must be a global variable.
// global TargetBreakableDist = 10.0;

print("ET Script Executed");

// Uncomment this line to dump a list of all global function Names and constants
// to a file called globals.txt in the game directory
//DumpGlobals("globals.txt");

// This function runs an infinite loop of adding and kicking bots. It is used to illustrate
// how custom script functions can be run continuously to provide custom control over
// things like the number of bots. Additional behaviors like forcing bots to 1 team can be 
// implemented by starting a similar function to this from a custom command.
global stresstest = function()
{
	sleep(10.0);
	dowhile(1)
	{
		//DumpGlobals("globals.txt");
   
		ran = UnitRandom();
		if(ran > 0.98)
		{
			//KickAll();
		}
		else if(ran < 0.5)
		{
			AddBot();
		}
		else
		{
			foreach ( gameId and bot in BotTable )
			{
				if(bot)
				{
					print(bot);
					KickBot(bot.Name);
					break;
				}                     
			}      
		}      
	      // Pause for 10 seconds between loop iterations.
	      sleep(RandRange(0.0, 3.0));      
	}
};

// This is a Game Monkey Script function that creates a thread using the function we defined above.
// Uncomment the following line if you want to run the function above.
//thread(stresstest); 

// It is also possible to register custom commands, that will be called in a similar way to the other bot commands,
// such as /bot waypoint. These command functions will recieve a table that is filled with all the additional options 
// that were part of the command.
// For example, if the user typed the following command into the games console
//		testme hi how are you
//	This testcommand function would be called, and the params variable would be a table that contains 4 items
//	These items can be referenced by a number, such as params[0], params[1], etc...
// Script commands are an easy way to bind complex script functions to a command that can be executed from
// the games console.
Commands["testme"] = function(_params)
{
	print("Test Command");
	foreach ( name and val in _params )
        {
		print( val );
        }
};

Commands["showweapons"] = function(_params)
{
	print("Printing Weapon List");
	foreach ( name and Id in WEAPON )
        {
		print("Weapon " + name +" : id " + Id);
        } 
};

Commands["showevents"] = function(_params)
{
	print("Printing Event List");
	foreach ( name and Id in EVENT )
        {
		print("Event " + name +" : id " + Id);
        } 
};

Commands["dumpglobals"] = function(_params)
{
	dumpGlobals("globals_functions.gm", DUMP.FUNCTIONS);
	dumpGlobals("globals_references.gm", DUMP.REFERENCES);
	dumpGlobals("globals_typefunctions.gm", DUMP.TYPEFUNCTIONS);
	dumpGlobals("globals_all.gm", DUMP.ALL);
	dumpGlobals("globals_all2.gm");
};

Commands["showscriptgoals"] = function(_params)
{
	print("Printing Bot Script Goals");
	foreach ( gameId and bot in BotTable )
        {
		print(bot, bot.scriptgoal);
        } 
};

Commands["mywpmode"] = function(_params)
{
	ExecCommand("waypoint_view 1");
	Util.EnableWaypointAutoSave( true, 20 );
};

Commands["numthreads"] = function(_params)
{
	allThreads = threadAllIds();
	print("Number of threads", tableCount(allThreads));
};

Commands["goal_exp"] = function(_params)
{
	goallist = table();
	
	GetGoals(goallist, 0, _params[0]);
	print("goal_exp");
	foreach ( index and goal  in goallist )
        {
		print(index, goal, goal.GetName());
        } 
};
