//==========================================================================================
//
//	eaxmas.gm
//
//	Who	When		What
//------------------------------------------------------------------------------------------
//	palota	18 May 2011	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 0,
	gateDestroyed = false,

	Roles =
	{
		ALLIES =
		{
			ATTACKER =
			{
				numbots = 2,
			},
		},
	},

	Church_Gate_Destroyed = function( trigger )
	{
		Map.gateDestroyed = true;
		ClearGoalRole( "FLAG_scr_AXIS_GOLD", ROLE.INFILTRATOR);
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_church.*",
			"TRIPMINE_church.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_gate.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_gate.*" );
		Util.EnableGoal( ".*CAB_.*3");
		Util.MapDebugPrint( "Church_Gate_Destroyed" );
	},

	Game_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_cap.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_cap.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_church.*",
			"DEFEND_axis.*",
		});
		Util.MapDebugPrint( "Game_Taken" );
	},

	Game_Returned = function( trigger )
	{
		if (Map.gateDestroyed){
			SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_church.*" );
		}
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_axis.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_cap.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_cap.*" );
		Util.MapDebugPrint( "Game_Returned" );
	},

	Game_Secured = function( trigger )
	{
		ETUtil.WinningChat( TEAM.ALLIES );
		ETUtil.LosingChat( TEAM.AXIS );
		Util.MapDebugPrint( "Game_Secured" );
	},

	EnableSwitches = function()
	{
		sleep(10);
		SetAvailableMapGoals( TEAM.ALLIES, true, "SWITCH.*" );
		Util.MapDebugPrint( "EnableSwitches" );
	},

	Switch_Pressed = function( trigger )
	{
		Util.DisableGoal("SWITCH.*");
		thread(Map.EnableSwitches);
		Util.MapDebugPrint( "Switch_Pressed" );
	},

	two_minute = function( trigger )
	{
		if (GetGameTimeLeft() > 0)
		{
			SetGoalPriority( "SWITCH.*", 0.5, TEAM.ALLIES);
		}
		Util.MapDebugPrint( "two_minute" );
	},
};

global OnMapLoad = function()
{
	OnTrigger( "Allies have Destroyed the Church Gate !", Map.Church_Gate_Destroyed );
	OnTrigger( "The Allied have stolen the Game!", Map.Game_Taken );
	OnTrigger( "Flag returned scr_AXIS_GOLD!", Map.Game_Returned );
	OnTrigger( "Allies are Playing Enemy Territory!", Map.Game_Secured );
	OnTrigger( "Allies are Playing Enemy Territory!", Map.Game_Secured );
	OnTrigger( "t81 activated", Map.Switch_Pressed );
	OnTrigger( "t82 activated", Map.Switch_Pressed );
	OnTrigger( "t83 activated", Map.Switch_Pressed );
	OnTrigger( "t84 activated", Map.Switch_Pressed );
	OnTrigger( "t85 activated", Map.Switch_Pressed );
	OnTrigger( "t86 activated", Map.Switch_Pressed );
	OnTrigger( "t766 activated", Map.Switch_Pressed );
	OnTrigger( "t767 activated", Map.Switch_Pressed );
	OnTrigger( "t768 activated", Map.Switch_Pressed );
	OnTrigger( "t769 activated", Map.Switch_Pressed );
	OnTrigger( "two minute warning.", Map.two_minute );

	Util.DisableGoal("ATTACK.*");
	Util.DisableGoal("DEFEND.*");
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_gate.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_gate.*" );
	Util.LimitToTeam( TEAM.AXIS, ".*_axis.*");
	Util.LimitToTeam( TEAM.ALLIES, ".*_allied.*");
	Util.LimitToTeam( TEAM.ALLIES, "FLAG_scr_AXIS_GOLD" );
	Util.DisableGoal( ".*CAB_.*3"); //church cabinets

	SetGoalRole( "FLAG_scr_AXIS_GOLD", ROLE.INFILTRATOR);
	SetGoalRole( "SWITCH.*", ROLE.ATTACKER);

	SetGoalPriority( "FLAG_scr_AXIS_GOLD", 0.6, TEAM.ALLIES);
	SetGoalPriority( "PLANT_Neutral_Command_Post", 0.8, TEAM.AXIS);

	// Max users per goal
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "PLANT_Neutral_Command_Post" );

	// Camp times
	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=10, MaxCampTime=40} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=20, MaxCampTime=60} );

	MapRoutes =
	{
		FLAG_scr_AXIS_GOLD = {
			ROUTE_allied_spawn = {
				ROUTE_S1 = {},
				ROUTE_S2 = {},
				ROUTE_S3 = {},
				ROUTE_A3 = { ROUTE_S4 = {}},
				ROUTE_A4 = { ROUTE_S5 = {}},
				ROUTE_S6 = {},
			}
		},
		CAPPOINT_DropOff = {
			ROUTE_obj = {
				ROUTE_church_gate = {
					ROUTE_S3 = {
						ROUTE_A2 = {},
						ROUTE_A1 = {},
					},
					ROUTE_S4 = { ROUTE_A3 = {}},
					ROUTE_S5 = { ROUTE_A4 = {}},
					ROUTE_S6 = {},
					ROUTE_S7 = {},
				},
				ROUTE_church_tower = {},
			}
		},
		DEFEND_church1 = {
			ROUTE_axis_spawn = {
				ROUTE_X3 = {},
			}
		},
		DEFEND_axis1 = {
			ROUTE_axis_spawn = {
				ROUTE_N2 = {},
			}
		},
		DEFEND_axis3 = {
			ROUTE_axis_spawn = {
				ROUTE_N1 = {},
			}
		},
		ATTACK_cap1 = {
			ROUTE_axis_spawn = {
				ROUTE_X2 = {},
			}
		},
		PLANT_Neutral_Command_Post = {
			ROUTE_axis_spawn = {
				ROUTE_E1 = {},
				ROUTE_E2 = {},
				ROUTE_E3 = {},
			}
		},
	};
	MapRoutes.PLANT_Church_Gate = MapRoutes.FLAG_scr_AXIS_GOLD;
	MapRoutes.ATTACK_gate1 = MapRoutes.FLAG_scr_AXIS_GOLD;
	MapRoutes.ATTACK_gate2 = MapRoutes.FLAG_scr_AXIS_GOLD;
	MapRoutes.ATTACK_gate3 = MapRoutes.FLAG_scr_AXIS_GOLD;
	MapRoutes.ATTACK_gate4 = MapRoutes.FLAG_scr_AXIS_GOLD;
	MapRoutes.ATTACK_gate5 = MapRoutes.FLAG_scr_AXIS_GOLD;
	MapRoutes.ATTACK_gate6 = MapRoutes.FLAG_scr_AXIS_GOLD;
	MapRoutes.CAPPOINT_DropOff.ROUTE_obj.ROUTE_church_tower = MapRoutes.CAPPOINT_DropOff.ROUTE_obj.ROUTE_church_gate;
	MapRoutes.DEFEND_church3 = MapRoutes.DEFEND_church1;
	MapRoutes.DEFEND_church5 = MapRoutes.DEFEND_church1;
	MapRoutes.DEFEND_gate1 = MapRoutes.DEFEND_church1;
	MapRoutes.DEFEND_gate2 = MapRoutes.DEFEND_church1;
	MapRoutes.DEFEND_gate3 = MapRoutes.DEFEND_church1;
	MapRoutes.DEFEND_axis4 = MapRoutes.PLANT_Neutral_Command_Post;
	MapRoutes.DEFEND_axis7 = MapRoutes.PLANT_Neutral_Command_Post;
	MapRoutes.ATTACK_cap2 = MapRoutes.ATTACK_cap1;
	MapRoutes.ATTACK_cap3 = MapRoutes.ATTACK_cap1;
	MapRoutes.DEFEND_axis5 = MapRoutes.DEFEND_axis1;
	MapRoutes.DEFEND_axis8 = MapRoutes.DEFEND_axis3;
	Util.Routes(MapRoutes);

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

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 80.0;
};
