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

global Map =
{
	Debug = 0, // please set to zero before distributing your script

	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:

	Navigation =
	{
		wait =
		{
			navigate = function(_this)
			{
				_this.Bot.HoldButton(BTN.BACKWARD, 0.5);
				sleep(1);
			},
		},
	},

	// /bot waypoint_setproperty paththrough Navigation_PT:wait

	Roles =
	{
		AXIS = // Team
		{
			AllBots = false, // each bot is considered for a role
			DEFENDER = // the DEFENDER role
			{
				spawnpt = 1,			// users of this role will choose spawnpt 1
				numbots = 5,			// maximum of 5 bots
			},
		},
		ALLIES =
		{
			AllBots = false, // default: every other bot
			ATTACKER =
			{
				spawnpt = 3,
				numbots = 4,
				crucialClass = CLASS.ENGINEER,	// first bot
			},
		},
	},

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

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

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

	Allied_Command_Post_Destroyed = function( trigger )
	{

		Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
	},

	Axis_Command_Post_Built = function( trigger )
	{

		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Command_Post" );
		Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},

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

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

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

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

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


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

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

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

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

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

		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

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

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

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

		Util.MapDebugPrint( "Side_Entrance_Destroyed" );
	},

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

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

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

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

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

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

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

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

	AlliedWin = function( trigger )
	{
//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.*",
		"AMMOCAB.*",
		"HEALTHCAB.*",
	});
	//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",
		"AMMOCAB.*",
		"HEALTHCAB.*",
		"CHECKPOINT.*",
	});

	//~SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_.*" );

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

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

	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;
};
