//==========================================================================================
//
//	pirates_b2.gm
//
//	Who  	When		What
//------------------------------------------------------------------------------------------
//	^4Tardis	24 May 2011	Initial Script
//
//==========================================================================================
//

global Map =
{
	Main_Entrance_Dyno = 0,
	Side_Entrance_Dyno = 0,
	Axis_Command_Post_Dyno = 0,
	Allied_Command_Post_Dyno = 0,

	Talk = true, //set Talk to false if you don't want the bots to cheer after winning game:

	Allied_Command_Post_Built = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Command_Post" );
		Util.MapDebugPrint( "Allied_Command_Post_Built" );
	},

	Allied_Command_Post_Planted = function()
	{
		Map.Allied_Command_Post_Dyno += 1;
		Util.MapDebugPrint( "Allied_Command_Post_Planted" );
	},

	Allied_Command_Post_Defused = function()
	{
		Map.Allied_Command_Post_Dyno -= 1;
		Util.MapDebugPrint( "Allied_Command_Post_Defused" );
	},

	Allied_Command_Post_Destroyed = function()
	{

		Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
	},

	Axis_Command_Post_Built = function()
	{

		Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},

	Axis_Command_Post_Planted = function()
	{
		Map.Axis_Command_Post_Dyno += 1;
		Util.MapDebugPrint( "Axis_Command_Post_Planted" );
	},

	Axis_Command_Post_Defused = function()
	{
		Map.Axis_Command_Post_Dyno -= 1;
		Util.MapDebugPrint( "Axis_Command_Post_Defused" );
	},

	Axis_Command_Post_Destroyed = function()
	{
		Util.MapDebugPrint( "Axis_Command_Post_Destroyed" );
	},

	Main_Entrance_Planted = function()
	{
		Map.Main_Entrance_Dyno += 1;
		Util.MapDebugPrint( "Main_Entrance_Planted" );
	},

	Side_Entrance_Planted = function()
	{
		Map.Side_Entrance_Dyno += 1;
		Util.MapDebugPrint( "Side_Entrance_Planted" );
	},


	Main_Entrance_Defused = function()
	{
		Map.Main_Entrance_Dyno -= 1;
		Util.MapDebugPrint( "Main_Entrance_Defused" );
	},

	Side_Entrance_Defused = function()
	{
		Map.Side_Entrance_Dyno -= 1;
		Util.MapDebugPrint( "Side_Entrance_Defused" );
	},

	Main_Entrance_Destroyed = function()
	{
		Map.Main_Entrance_Dyno = 0;

	SetAvailableMapGoals( TEAM.AXIS, false, {
		"CHECKPOINT.*",
		"DEFEND_main.*",
		"DEFEND_side.*",
		"MOUNTMG42.*",
		"REPAIRMG42.*",
		"PLANTMINE_.*",
	});
	SetGoalPriority( "DEFUSE_Side_Entrance.*", 0.0, TEAM.AXIS, CLASS.ENGINEER, true);
	SetGoalPriority( "DEFUSE_Main_Entrance.*", 0.0, TEAM.AXIS, CLASS.ENGINEER, true);
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"GRENADE_main",
		"CHECKPOINT.*",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_gold.*",
		"FLAG.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"FLAG.*",
		"CAPPOINT_gold",
		"BUILD_Command_Post",
	});
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Command_Post" );

		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

	Side_Entrance_Destroyed = function()
	{
		Map.Side_Entrance_Dyno = 0;

	SetAvailableMapGoals( TEAM.AXIS, false, {
		"CHECKPOINT.*",
		"DEFEND_main.*",
		"DEFEND_side.*",
		"MOUNTMG42.*",
		"REPAIRMG42.*",
		"PLANTMINE_.*",
	});
	SetGoalPriority( "DEFUSE_Main_Entrance.*", 0.0, TEAM.AXIS, CLASS.ENGINEER, true);
	SetGoalPriority( "DEFUSE_Side_Entrance.*", 0.0, TEAM.AXIS, CLASS.ENGINEER, true);
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"GRENADE_main",
		"CHECKPOINT.*",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_gold.*",
		"FLAG.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"FLAG.*",
		"CAPPOINT_gold",
		"BUILD_Command_Post",
	});
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Command_Post" );

		Util.MapDebugPrint( "Side_Entrance_Destroyed" );
	},

	goldcrate1_Taken = function()
	{
		//Switch Defend Spot
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_drop.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_.*" );

		Util.MapDebugPrint( "goldcrate1_Taken" );
	},

	goldcrate2_Taken = function()
	{

		//Switch Defend Spot
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_drop.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_.*" );

		Util.MapDebugPrint( "goldcrate2_Taken" );
	},

	goldcrate1_Returned = function()
	{

		//Switch Defend Spot
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_drop.*" );

		Util.MapDebugPrint( "goldcrate1_Returned" );
	},

	goldcrate2_Returned = function()
	{

		//Switch Defend Spot
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_drop.*" );

		Util.MapDebugPrint( "goldcrate2_Returned" );
	},

	goldcrate1_Secured = function()
	{
		//Switch Defend Spot Perm
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_drop.*",
			"MOBILEMG42_drop",
		});

		Util.MapDebugPrint( "goldcrate1_Secured" );
	},

	goldcrate2_Secured = function()
	{
		//Switch Defend Spot Perm
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_drop.*",
			"MOBILEMG42_drop",
		});

		Util.MapDebugPrint( "goldcrate2_Secured" );
	},

	flag_Axis_Captured = function()
	{
		Util.MapDebugPrint( "flag_Axis_Captured" );
	},

	flag_Allies_Captured = function()
	{
		Util.MapDebugPrint( "flag_Allies_Captured" );
	},

	AlliedWin = function()
	{
//Game Over
		if ( Map.Talk && MAP_TALK )
		{
			ETUtil.WinningChat( TEAM.ALLIES );
			ETUtil.LosingChat( TEAM.AXIS );
		}

		Util.MapDebugPrint( "Allies have Won!" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Planted at the Main Entrance.", Map.Main_Entrance_Planted );
	OnTrigger( "Planted at the Side Entrance.", Map.Side_Entrance_Planted );
	OnTrigger( "Defused at the Main Entrance.", Map.Main_Entrance_Defused );
	OnTrigger( "Defused at the Side Entrance.", Map.Side_Entrance_Defused );
	OnTrigger( "Allies have breached the Main Entrance and secured the Old City!", Map.Main_Entrance_Destroyed );
	OnTrigger( "Allies have breached the Side Entrance and secured the Old City!", Map.Side_Entrance_Destroyed );
	OnTrigger( "Allies have stolen The Gold Crate!", Map.goldcrate1_Taken );
	OnTrigger( "Allies have stolen The Gold Crate!", Map.goldcrate2_Taken );
	OnTrigger( "Axis have returned The Gold Crate!", Map.goldcrate1_Returned );
	OnTrigger( "Axis have returned The Gold Crate!", Map.goldcrate2_Returned );
	OnTrigger( "Allied team has secured the first Gold Crate!", Map.goldcrate1_Secured );
	OnTrigger( "Allied team has secured the second Gold Crate!", Map.goldcrate2_Secured );
	OnTrigger( "Axis reclaim the Old City!", Map.flag_Axis_Captured );
	OnTrigger( "Allies capture the Old City!", Map.flag_Allies_Captured );
	OnTrigger( "Allied team secured both Gold Crates!", Map.AlliedWin );

	Util.DisableGoal( ".*", true ); // all but routes

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_main.*",
		"DEFEND_side.*",
		"PLANTMINE_.*",
	});
	//SetAvailableMapGoals( TEAM.AXIS, true, "MOUNTMG42.*" );
	//SetAvailableMapGoals( TEAM.AXIS, true, "REPAIRMG42.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"GRENADE_main",
		"PLANT_Main_Entrance",
		"PLANT_Side_Entrance",
		"CHECKPOINT.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, false, "PLANTMINE_.*" );

	// Max users per goal
	Util.SetMaxUsers( 2, "ATTACK_.*" );
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "GRENADE_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 2, "CHECKPOINT.*" );
	Util.SetMaxUsers( 1, "PLANT_.*" );
	Util.SetMaxUsers( 1, "BUILD_.*" );

	// Camp times
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=15, MaxCampTime=90} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=60, MaxCampTime=120} );

	Util.AddUseWp("PLANT_Main_Entrance", "main1");
	Util.AddUseWp("PLANT_Main_Entrance", "main2");
	Util.AddUseWp("PLANT_Main_Entrance", "main3");
	Util.AddUseWp("PLANT_Side_Entrance", "side");
	Util.AddUseWp("PLANT_Side_Entrance", "side1");
	Util.AddUseWp("PLANT_Side_Entrance", "side2");

	Util.MapDebugPrint( "Omni-bot map script for " + GetMapName() + " executed." );
};

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 90.0;
	bot.MaxViewDistance = 2400;
};
