//==========================================================================================
//
//	ship.gm
//
//	Who	When		What
//------------------------------------------------------------------------------------------
//	palota	14 January 2011	Initial Script
//	palota	11 May 2011	role, routes to DEFEND_east2 and DEFEND_doc5, max users for FLAG_Top_secret_document
//	palota	18 May 2011	boat paththrough navigation, WinningChat
//
//==========================================================================================
//

global Map =
{
	objTaken = 0,
	objSecured = 0,
	enigmaTaken = false,
	docTaken = false,

	Roles =
	{
		AXIS =
		{
			DEFENDER2 =
			{
				numbots = 4,
			},
		},
	},

	Navigation =
	{
		l1 = { navigate = function(_this) {
			_this.AddAimRequest(Priority.High, "facing", Vector3(0.3,0,0.9));
			_this.Bot.HoldButton(BTN.WALK, 3);
			sleep(0.3);
			_this.Bot.HoldButton(BTN.BACKWARD, 2);
			sleep(2);
			_this.AddAimRequest(Priority.High, "facing", Vector3(0.3,0,-0.9));
			_this.Bot.HoldButton(BTN.FORWARD, 2.5);
			sleep(2.5);
		}},
		l2 = { navigate = function(_this) {
			_this.AddAimRequest(Priority.High, "facing", Vector3(0,-0.3,-0.9));
			_this.Bot.HoldButton(BTN.WALK, 3);
			sleep(0.3);
			_this.Bot.HoldButton(BTN.FORWARD, 6);
			sleep(6);
		}},
		boat = { navigate = function(_this) {
			_this.AddAimRequest(Priority.High, "facing", Vector3(0,0.3,0.9));
			yield();
			_this.Bot.HoldButton(BTN.FORWARD, 2);
			sleep(2.5);
		}},
	},

	East_rader_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_east_radar.*" );
		Util.MapDebugPrint( "East_rader_Destroyed" );
	},

	West_rader_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_west_radar.*" );
		Util.MapDebugPrint( "West_rader_Destroyed" );
	},

	Wall_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_wall.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_wall.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_enigma.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "FLAG_Enigma_box" );
		Util.MapDebugPrint( "Wall_Destroyed" );
	},

	SetDoc = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, !Map.docTaken, "DEFEND_doc.*" );
		SetAvailableMapGoals( TEAM.AXIS, Map.objTaken > 0, "DEFEND_boat.*" );
		SetAvailableMapGoals( TEAM.AXIS, !Map.enigmaTaken, {
			"SNIPE_w.*",
			"MOBILEMG42.*2",
		});
	},

	Enigma_box_Taken = function()
	{
		if (!Map.enigmaTaken){
			Map.enigmaTaken = true;
			Map.objTaken += 1;
		}
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_enigma.*" );
		Map.SetDoc();
		Util.MapDebugPrint( "Enigma_box_Taken" );
	},

	Enigma_box_Returned = function()
	{
		Map.enigmaTaken = false;
		Map.objTaken -= 1;
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_enigma.*" );
		Map.SetDoc();
		Util.MapDebugPrint( "Enigma_box_Returned" );
	},

	Top_secret_document_Taken = function()
	{
		if (!Map.docTaken){
			Map.docTaken = true;
			Map.objTaken += 1;
			Util.SetMaxUsers( 5, "FLAG_Top_secret_document" );
		}
		Map.SetDoc();
		Util.MapDebugPrint( "Top_secret_document_Taken" );
	},

	Top_secret_document_Returned = function()
	{
		Map.docTaken = false;
		Map.objTaken -= 1;
		Map.SetDoc();
		if (Map.objSecured == 0){
			Util.SetMaxUsers( 2, "FLAG_Top_secret_document" );
		}
		Util.MapDebugPrint( "Top_secret_document_Returned" );
	},

	Objective_Secured = function()
	{
		Map.objTaken -= 1;
		Map.objSecured += 1;
		Map.SetDoc();
		Util.SetMaxUsers( 2, "ATTACK_.*" );
		Util.SetMaxUsers( 4, "FLAG_Top_secret_document" );
		ClearGoalRole("DEFEND_wall.*", ROLE.DEFENDER2);
		ClearGoalRole("DEFEND_west_radar.*", ROLE.DEFENDER2);
		ClearGoalRole("DEFEND_enigma.*", ROLE.DEFENDER2);
		Util.MapDebugPrint( "Objective_Secured" );
		if (Map.objSecured==2){
			ETUtil.WinningChat( TEAM.ALLIES );
			ETUtil.LosingChat( TEAM.AXIS );
			Util.MapDebugPrint( "Allies win" );
		}
	},

	Round_End = function()
	{
		if (Map.objSecured<2){
			ETUtil.WinningChat( TEAM.AXIS );
			ETUtil.LosingChat( TEAM.ALLIES );
			Util.MapDebugPrint( "Axis win" );
		}
	},
};

global OnMapLoad = function()
{
	OnTrigger( "East rader destroyed", Map.East_rader_Destroyed );
	OnTrigger( "West rader destroyed", Map.West_rader_Destroyed );
	OnTrigger( "Cracked destroyed", Map.Wall_Destroyed );
	OnTrigger( "Allies have stolen Enigma box!", Map.Enigma_box_Taken );
	OnTrigger( "Allies have stolen Top secret document!", Map.Top_secret_document_Taken );
	OnTrigger( "Flag returned Enigma box!", Map.Enigma_box_Returned );
	OnTrigger( "Flag returned Top secret document!", Map.Top_secret_document_Returned );
	OnTrigger( "Allies captured capture2", Map.Objective_Secured ); //enigma box or top secret documents 208
	OnTrigger( "Round End.", Map.Round_End );

	OnTriggerRegion(AABB(5904.419,-882.750,-1790.874,6606.933,-474.715,-1500.0), RegionTrigger.KillTrigger); //under the cappoint boat
	OnTriggerRegion(AABB(5600.0,-1200.0,-1333.801,6816.366,-525.900,-1015.714), RegionTrigger.DisableCombatMovement); //cappoint boat
	Util.LimitToTeam( TEAM.AXIS, "DEFEND_.*" );
	Util.LimitToTeam( TEAM.AXIS, "SNIPE_.*" );
	Util.LimitToTeam( TEAM.AXIS, "MOBILEMG42_.*" );
	Util.LimitToTeam( TEAM.AXIS, "TRIPMINE_.*" );
	Util.LimitToTeam( TEAM.ALLIES, "ATTACK_.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"DEFEND_boat.*",
		"DEFEND_enigma.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, false, "FLAG_Enigma_box" );

	SetGoalPriority( "DEFEND_boat.*", 0.51, TEAM.AXIS);
	SetGoalPriority( "DEFEND_boat1.*", 0.52, TEAM.AXIS);

	SetGoalRole("DEFEND_wall.*", ROLE.DEFENDER2);
	SetGoalRole("DEFEND_west_radar.*", ROLE.DEFENDER2);
	SetGoalRole("DEFEND_enigma.*", ROLE.DEFENDER2);

	Util.SetMaxUsers( 1, "FLAG_Top_secret_document" );
	Util.SetMaxUsers( 1, "DEFEND_.*" );

	Util.AddUsePoint("PLANT_East_rader", Vector3(1529.661, -122.528, 72.125));
	Util.AddUsePoint("PLANT_West_rader", Vector3(-2934.373, 31.209, -167.875));

	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=20, MaxCampTime=50} );
	SetMapGoalProperties( "SNIPE_.*", {MinCampTime=30, MaxCampTime=120} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=50, MaxCampTime=120} );

	MapRoutes =
	{
		FLAG_Top_secret_document = {
			ROUTE_allied_spawn = {
				ROUTE_door_eastN = {},
				ROUTE_door_eastS = {},
				ROUTE_door_north = {},
				ROUTE_door_south = {},
				ROUTE_allied_gun = {},
			},
		},
		PLANT_East_rader = {
			ROUTE_allied_spawn = {
				ROUTE_EN2 = {},
				ROUTE_ES2 = {},
				ROUTE_allied_gun = {},
			}
		},
		PLANT_West_rader = {
			ROUTE_allied_spawn = {
				ROUTE_WN1 = {},
				ROUTE_EN1 = { ROUTE_WN4 = { ROUTE_WNradar = {}}},
				ROUTE_WS1 = {},
				ROUTE_ES1 = { ROUTE_WS4 = { ROUTE_WSradar = {}}},
			}
		},
		FLAG_Enigma_box = {
			ROUTE_allied_spawn = {
				ROUTE_WN1 = { ROUTE_enigma1 = {}},
				ROUTE_WN2 = { ROUTE_enigma2 = {}},
				ROUTE_WN3 = { ROUTE_enigma1 = {}},
				ROUTE_WS1 = { ROUTE_enigma2 = {}},
				ROUTE_WS2 = { ROUTE_enigma1 = {}},
				ROUTE_WS3 = { ROUTE_enigma2 = {}},
			}
		},
		PLANT_Cracked_wall = {
			ROUTE_allied_spawn = {
				ROUTE_WN1 = {},
				ROUTE_WN2 = {},
				ROUTE_WN3 = {},
				ROUTE_WS1 = {},
				ROUTE_WS2 = {},
				ROUTE_WS3 = {},
			}
		},
		DEFEND_enigma1 = {
			ROUTE_axis_spawn = {
				ROUTE_WN1 = {},
				ROUTE_WN2 = {},
				ROUTE_WS1 = {},
				ROUTE_WS2 = {},
			}
		},
		DEFEND_boat1 = {
			ROUTE_axis_spawn = {
				ROUTE_waterS1 = {},
			}
		},
		CAPPOINT_boat = {
			ROUTE_doc = {
				ROUTE_door_east = {},
				ROUTE_door_south = {},
				ROUTE_EN3 = { ROUTE_waterN2 = { ROUTE_waterN1 = {}}},
			},
			ROUTE_enigma = {
				ROUTE_WN1 = { Weight=2, ROUTE_waterN2 = { ROUTE_waterN1 = {}}},
				ROUTE_WN2 = {},
				ROUTE_WS1 = { Weight=2 },
				ROUTE_WS2 = {},
			},
		},
		DEFEND_east2 = {
			ROUTE_axis_spawn = { ROUTE_ES2 = {} }
		},
		DEFEND_doc5 = {
			ROUTE_axis_spawn = { ROUTE_EN3 = {} }
		},
	};
	MapRoutes.ATTACK_wall1 = MapRoutes.PLANT_Cracked_wall;
	MapRoutes.ATTACK_wall2 = MapRoutes.ATTACK_wall1;
	MapRoutes.DEFEND_enigma2 = MapRoutes.DEFEND_enigma1;
	MapRoutes.DEFEND_enigma3 = MapRoutes.DEFEND_enigma1;
	MapRoutes.DEFEND_enigma5 = MapRoutes.DEFEND_enigma1;
	MapRoutes.DEFEND_enigma6 = MapRoutes.DEFEND_enigma1;
	MapRoutes.DEFEND_boat12 = MapRoutes.DEFEND_boat1;
	MapRoutes.DEFEND_east_radar1 = MapRoutes.DEFEND_east2;
	MapRoutes.DEFEND_east_radar3 = MapRoutes.DEFEND_east2;
	MapRoutes.DEFEND_east3 = MapRoutes.DEFEND_doc5;
	MapRoutes.DEFEND_doc6 = MapRoutes.DEFEND_doc5;
	MapRoutes.DEFEND_doc7 = MapRoutes.DEFEND_doc5;
	Util.Routes(MapRoutes);

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