//==========================================================================================
//
//	op_lucky_a2.gm
//
//	Who	When		What
//------------------------------------------------------------------------------------------
//	palota	22 September 2012	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 0,
	Movers = { "MOVER_truck" },
	barrierDestroyed = true,
	truckAtBarrier = false,

	warehouse_Entrance_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_radar.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_warehouse.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "FLAG_gold_crate" ); //gold crates are radar parts
		SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_truck" );
		SetGoalPriority("PLANTMINE_truck.*", 0.81);
		Util.MapDebugPrint( "warehouse_Entrance_Destroyed" );
	},

	radar1_Secured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Truck" );
		Util.MapDebugPrint( "radar1_Secured" );
	},

	radar2_Secured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_radar.*",
			"PLANTMINE_truck.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "FLAG_gold_crate" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"ATTACK_barrier.*",
			"ESCORT_truck",
			"PLANT_Truck_Barrier",
		});
		Util.OnTriggerPosition("MOVER_truck", "barrier1", 320.0, Map.Truck_At_Barrier);
		ETUtil.SetStartIndex("BUILD_Truck", -1);
		Util.MapDebugPrint( "radar2_Secured" );
	},

	Truck_Barrier_Built = function( trigger )
	{
		Map.barrierDestroyed = false;
		if(Map.truckAtBarrier){
			SetAvailableMapGoals(TEAM.ALLIES, false, "ESCORT_truck");
		}
		Util.MapDebugPrint( "Truck_Barrier_Built" );
	},

	Truck_Barrier_Destroyed = function( trigger )
	{
		Map.barrierDestroyed = true;
		if(Map.truckAtBarrier){
			SetAvailableMapGoals(TEAM.ALLIES, true, "ESCORT_truck");
		}
		Util.MapDebugPrint( "Truck_Barrier_Destroyed" );
	},

	Truck_At_Barrier = function( trigger )
	{
		Map.truckAtBarrier = true;
		if(!Map.barrierDestroyed){
			SetGoalPriority("PLANT_Truck_Barrier", 0.9);
			SetGoalPriority("BUILD_Truck", 0.85);
			SetAvailableMapGoals(TEAM.ALLIES, false, "ESCORT_truck");
		}
		Util.OnTriggerPosition("MOVER_truck", "barrier2", 200.0, Map.Truck_Past_Barrier);
		Util.MapDebugPrint( "Truck_At_Barrier" );
	},

	Truck_Past_Barrier = function( trigger )
	{
		Map.truckAtBarrier = false;
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"MOBILEMG42_radar.*",
			"BUILD_Truck_Barrier",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_barrier.*" );
		SetGoalPriority("BUILD_Truck", 0.9);
		Util.OnTriggerPosition("MOVER_truck", "center", 300.0, Map.Truck_Center);
		Util.MapDebugPrint( "Truck_Past_Barrier" );
	},

	Truck_Center = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_end.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "MOBILEMG42_checkpoint.*" );
		Util.MapDebugPrint( "Truck_Center" );
	},

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

global OnMapLoad = function()
{
	OnTrigger( "Allies have destroyed the warehouse Entrance", Map.warehouse_Entrance_Destroyed );
	OnTrigger( "Allied team has secured the second Radar Part!", Map.radar1_Secured );
	OnTrigger( "Allied team is escaping with the Radar Parts!", Map.radar2_Secured );
	OnTrigger( "Truck Barrier #1 has been constructed.", Map.Truck_Barrier_Built );
	OnTrigger( "Truck Barrier #1 has been destroyed.", Map.Truck_Barrier_Destroyed );
	OnTrigger( "Allied team escaped with the Radar parts!", Map.Allies_Escaped );

	Util.DisableGoal( ".*", true );
	Util.EnableGoal( ".*_Command_Post" );
	Util.EnableGoal( "CHECKPOINT_bunker_flag" );

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"BUILD_Truck_Barrier",
		"DEFEND_checkpoint.*",
		"PLANTMINE_truck.*",
		"MOBILEMG42_.*",
	});

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"PLANT_warehouse_Entrance",
		"ATTACK_warehouse.*",
	});

	SetGoalPriority("PLANT_warehouse_Entrance", 0.9);
	SetGoalPriority("FLAG_gold_crate", 0.7);
	SetGoalPriority("CHECKPOINT_bunker_flag", 0.7);
	SetGoalPriority("DEFEND_radar.*", 0.7);
	SetGoalPriority("DEFEND_end.*", 0.7);

	SetMapGoalProperties( "DEFEND_checkpoint.*", {MinCampTime=10, MaxCampTime=60} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=15, MaxCampTime=60} );

	ETUtil.SetStartIndex("BUILD_Truck", 0);
	Util.AddUsePoint( "PLANT_Truck_Barrier", {Vec3(-385.183, 2026.751, -341.875), Vec3(-407.505, 1847.170, -346.875), Vec3(-398.646, 1677.157, -336.875), Vec3(-593.615, 2033.068, -341.875) });

	Util.FixMoverPos("truck", Vec3(512.000, 1361.500, -301.500), Vec3(513.000, 1216.000, -358.000));

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

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

global InitializeRoutes = function()
{
	MapRoutes =
	{
		FLAG_gold_crate = {
			ROUTE_allied_spawn = {
				ROUTE_allied_west = {
					ROUTE_south_west = { Weight=2 },
					ROUTE_south_east1 = {},
				},
				ROUTE_allied_stairs = {
					ROUTE_south_east1 = {},
					ROUTE_south_east2 = { Weight=2 },
				},
			},
			ROUTE_command_post = {
				ROUTE_truck1 = {},
				ROUTE_truck2 = {},
				ROUTE_truck3 = {},
			},
			ROUTE_flag_spawn = {
				ROUTE_flag_north = {},
				ROUTE_truck_south = {
					ROUTE_truck1 = {},
					ROUTE_truck2 = {},
					ROUTE_truck3 = {},
				},
			},
		},
		CAPPOINT_truck =
		{
			 ROUTE_radar = {
				 ROUTE_truck1 = {},
				 ROUTE_truck2 = {},
			 }
		},
		PLANT_Truck_Barrier =
		{
			ROUTE_allied_spawn = {
				ROUTE_allied_west = {
					ROUTE_south_west = { Weight=2 },
					ROUTE_south_east1 = {},
				},
				ROUTE_allied_stairs = {
					ROUTE_command_post = { Weight=3 },
					ROUTE_truck1 = {},
					ROUTE_truck2 = {},
					ROUTE_truck3 = {},
				},
			},
			ROUTE_command_post = {
				ROUTE_west1 = {},
				ROUTE_truck_south = {},
			},
		},
		CHECKPOINT_bunker_flag =
		{
			ROUTE_axis_spawn = {
				ROUTE_axis2 = { Weight=2,
					ROUTE_barrier1 = {},
					ROUTE_west1 = {}
				},
				ROUTE_north = {},
				ROUTE_north_east = {
					ROUTE_truck1 = { ROUTE_truck_south = {}},
					ROUTE_truck2 = { ROUTE_truck_south = {}},
				},
			},
			ROUTE_allied_spawn = {
				ROUTE_allied_west = {
					ROUTE_south_west = { Weight=2 },
					ROUTE_south_east1 = {},
				},
				ROUTE_allied_stairs = {
					ROUTE_south_east1 = {},
					ROUTE_south_east2 = { Weight=2 },
				},
			},
		},
	};
	MapRoutes["DEFEND_radar.*"] = {
		 ROUTE_axis_spawn = {
			ROUTE_north = { ROUTE_north2 = {}},
			ROUTE_north_east = {},
		 }
	};
	MapRoutes.BUILD_Command_Post = MapRoutes.CHECKPOINT_bunker_flag;
	MapRoutes.PLANT_Command_Post = MapRoutes.BUILD_Command_Post;
	MapRoutes.PLANT_warehouse_Entrance = MapRoutes.FLAG_gold_crate;
	MapRoutes["ATTACK_warehouse.*"] = MapRoutes.FLAG_gold_crate;
	MapRoutes["ATTACK_barrier.*"] = MapRoutes.PLANT_Truck_Barrier;
	Util.Routes(MapRoutes);
};
