//==========================================================================================
//
//	uje_convoy.gm
//
//	Who		When		What
//------------------------------------------------------------------------------------------
//	MickyP		14 April 2011	Initial Script
//	palota		28 July 2012	routes, roles, use points, ESCORT_Tank, DEFEND_End_Above, PLANTMINE, CALLARTILLERY, BUILD_Tank offsets, HEALTHCAB range, detonate spots
//==========================================================================================
//
// To Do
// Defence Mount goals
//
global Map =
{
	MapStart = 1,
	TankAtB1 = 0,
	B1Built = 0,
	TankAtB2 = 0,
	B2Built = 0,
	TankAtB3 = 0,
	B3Built = 0,

	Roles =
	{
		ALLIES =
		{
			DEFENDER1 = {
				numbots = 3,
			},
			DEFENDER2 = {
				numbots = 3,
			},
		},
	},

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

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

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

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

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

	Tank_Destroyed = function()
	{
		if ( Map.MapStart == 1 )
			{
				Map.MapStart = 0;
				return;
			}

		Util.MapDebugPrint( "Tank_Destroyed" );
	},

	TankBarrier_1_Built = function()
	{
		Map.B1Built = 1;

		if ( Map.TankAtB1 == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Tank" );
			}

		Util.MapDebugPrint( "TankBarrier_1_Built" );
	},

	TankBarrier_1_Destroyed = function()
	{
		Map.B1Built = 0;

		if ( Map.TankAtB1 == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Tank" );
			}

		Util.MapDebugPrint( "TankBarrier_1_Destroyed" );
	},

	Tank_At_Barrier_1 = function()
	{
		Map.TankAtB1 = 1;

		if ( Map.B1Built == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, false, {
					"BUILD_Tank",
					"ESCORT_Tank",
				});
			}

		Util.MapDebugPrint( "Tank_At_Barrier_1" );
	},

	Tank_Past_Barrier_1 = function()
	{
		Map.TankAtB1 = 0;

		SetAvailableMapGoals( TEAM.AXIS, true, "ESCORT_Tank" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANTMINE_yard.*" );

		Util.MapDebugPrint( "Tank_Past_Barrier_1" );
	},

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

	TankBarrier_2_Built = function()
	{
		Map.B2Built = 1;

		if ( Map.TankAtB2 == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Tank" );
			}

		Util.MapDebugPrint( "TankBarrier_2_Built" );
	},

	TankBarrier_2_Destroyed = function()
	{
		Map.B2Built = 0;

		if ( Map.TankAtB2 == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Tank" );
			}

		Util.MapDebugPrint( "TankBarrier_2_Destroyed" );
	},

	Tank_At_Barrier_2 = function()
	{
		Map.TankAtB2 = 1;

		if ( Map.B2Built == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, false, {
					"BUILD_Tank",
					"ESCORT_Tank",
				});
			}

		Util.MapDebugPrint( "Tank_At_Barrier_2" );
	},

	Tank_Past_Barrier_2 = function()
	{
		Map.TankAtB2 = 0;

		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Square.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"ATTACK_Bar.*",
			"PLANT_Tank_Barrier_3",
			"ESCORT_Tank",
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Square.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"DEFEND_Bar.*",
			"BUILD_Tank_Barrier_3",
		});

		Util.MapDebugPrint( "Tank_Past_Barrier_2" );
	},

	Forward_spawn_activated = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Bar.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_Yard.*" );

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"DEFEND_Bar.*",
			"PLANTMINE_yard.*",
		});
		//SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Axis_CP" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"DEFEND_Yard.*",
			"DEFEND_Arch.*",
			"CALLARTILLERY_Arch.*",
			"BUILD_factory_side_door",
			"PLANTMINE_end.*",
		});

		Util.MapDebugPrint( "Forward_spawn_activated" );
	},

	Tank_Barrier_3_Built = function()
	{
		Map.B3Built = 1;

		if ( Map.TankAtB3 == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Tank" );
			}

		Util.MapDebugPrint( "Tank_Barrier_3_Built" );
	},

	Tank_Barrier_3_Destroyed = function()
	{
		Map.B3Built = 0;

		if ( Map.TankAtB3 == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Tank" );
			}

		Util.MapDebugPrint( "Tank_Barrier_3_Destroyed" );
	},

	Tank_At_Barrier_3 = function()
	{
		Map.TankAtB3 = 1;

		if ( Map.B3Built == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, false, {
					"BUILD_Tank",
					"ESCORT_Tank",
				});
			}

		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Yard.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"ATTACK_End.*",
			"PLANT_factory_side_door",
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Yard.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_End.*" );

		Util.MapDebugPrint( "Tank_At_Barrier_3" );
	},

	Tank_Past_Barrier_3 = function()
	{
		Map.TankAtB3 = 0;
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANTMINE_end.*" );

		Util.MapDebugPrint( "Tank_Past_Barrier_3" );
	},

	Side_Door_Destroyed = function()
	{
		Util.EnableGoal( "ROUTE_Side_Door" );
		Util.MapDebugPrint( "Side_Door_Destroyed" );
	},

	Side_Door_Built = function()
	{
		Util.DisableGoal( "ROUTE_Side_Door" );
		Util.MapDebugPrint( "Side_Door_Built" );
	},

	vehicle_at_location = function()
	{
		switch(Map.VehicleLocation)
		{
			case 1:
			{
				Map.Tank_At_Barrier_1();
			}
			case 2:
			{
				Map.Tank_At_Barrier_2();
			}
			case 3:
			{
				Map.Tank_At_Barrier_3();
			}
		}
		Util.MapDebugPrint("vehicle at location " + Map.VehicleLocation, true);
	},

	TwoMinute = function()
	{
		if (GetGameTimeLeft() > 0)
		{
			SetAvailableMapGoals( TEAM.ALLIES, false, "ARTILLERY_S_Bar.*" );
			Util.MapDebugPrint( "TwoMinute" );
		}
	},
};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Allied_CP_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Allied_CP_Destroyed );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Axis_CP_Built );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Axis_CP_Destroyed );
	OnTrigger( "^5The tank has been damaged", Map.Tank_Destroyed );
	OnTrigger( "The Tank has been repaired", Map.Tank_Built );
	OnTrigger( "Barrier 1 has been constructed.", Map.TankBarrier_1_Built );
	OnTrigger( "Barrier 1 has been destroyed.", Map.TankBarrier_1_Destroyed );
	OnTrigger( "The tank is past the first barrier.", Map.Tank_Past_Barrier_1 );
	OnTrigger( "House spawn activated", Map.House_spawn_activated );
	OnTrigger( "Barrier 2 has been constructed.", Map.TankBarrier_2_Built );
	OnTrigger( "Barrier 2 has been destroyed.", Map.TankBarrier_2_Destroyed );
	OnTrigger( "The tank is past the second barrier.", Map.Tank_Past_Barrier_2 );
	OnTrigger( "Forward spawns activated", Map.Forward_spawn_activated );
	OnTrigger( "Barrier 3 has been constructed.", Map.Tank_Barrier_3_Built );
	OnTrigger( "Barrier 3 has been destroyed.", Map.Tank_Barrier_3_Destroyed );
	OnTrigger( "The tank is past the last barrier.", Map.Tank_Past_Barrier_3 );
	OnTrigger( "the side door has been destroyed", Map.Side_Door_Destroyed );
	OnTrigger( "the side door has been contructed", Map.Side_Door_Built );
	OnTrigger( "tank at location", Map.vehicle_at_location );
	OnTrigger("two minute warning.", Map.TwoMinute);

	OnTriggerRegion(AABB(704.498,-53.113,-210.875,913.125,16.611,-101.875), RegionTrigger.VehicleTrigger);
	OnTriggerRegion(AABB(1479.614,-435.076,-210.875,1708.975,-385.460,-136.875),  RegionTrigger.VehicleTrigger);
	OnTriggerRegion(AABB(-672.875,2268.633,105.213,-617.805,2612.659,179.926), RegionTrigger.VehicleTrigger);
	OnTriggerRegion(AABB(-2603.167,2591.125,401.125,-2077.153,2768.855,517.723), RegionTrigger.DisableBotPush); //north allied window at end
	OnTriggerRegion(AABB(-2596.628,1273.762,401.125,-2104.030,1434.406,513.777), RegionTrigger.DisableBotPush); //south allied window at end
	OnTriggerRegion(AABB(-863.675,2236.922,105.125,-566.459,2627.361,180.988),RegionTrigger.DisableCombatMovement); //tank barrier 3

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

	Util.EnableGoal( "AMMOCAB.*" );
	Util.EnableGoal( "HEALTHCAB.*" );

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"BUILD_TankBarrier_1",
		"BUILD_TankBarrier_2",
		"BUILD_Allied_CP",
		"PLANT_Axis_CP",
		"DEFEND_Square.*",
		"ARTILLERY_S_Bar.*",
	});


	SetAvailableMapGoals( TEAM.AXIS, true, {
		"BUILD_Tank",
		"PLANT_TankBarrier_1",
		"PLANT_TankBarrier_2",
		"MOUNT_Tank",
		"ESCORT_Tank",
		"BUILD_Axis_CP",
		"PLANT_Allied_CP",
		"ATTACK_Square.*",
	});

	SetGoalPriority( "PLANT_TankBarrier_1", 0.82, TEAM.AXIS );
	SetGoalPriority( "BUILD_TankBarrier_1", 0.91, TEAM.ALLIES );
	SetGoalPriority( "BUILD_factory_side_door", 0.79, TEAM.ALLIES );
	SetGoalPriority( "BUILD_Allied_CP", 0.79, TEAM.ALLIES );
	SetGoalPriority( "PLANT_Allied_CP", 0.80, TEAM.AXIS, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_factory_side_door", 0.80, TEAM.AXIS, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_Axis_CP", 0.80, TEAM.AXIS );
	SetGoalPriority( "PLANT_Axis_CP", 0.5, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "PLANTMINE_.*", 0.75);
	SetGoalPriority( "DEFUSE_Allied_CP.*", 0.79, TEAM.ALLIES, CLASS.ENGINEER, true );

	SetGoalRole("DEFEND_End_Above.*", ROLE.DEFENDER1 );
	SetGoalRole("DEFEND_Arch.*", ROLE.DEFENDER2 );

	// Max users per goal
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "BUILD_Allied_CP" );
	Util.SetMaxUsers( 1, "PLANT_Allied_CP" );
	Util.SetMaxUsers( 1, "BUILD_Axis_CP" );
	Util.SetMaxUsers( 1, "PLANT_Axis_CP" );
	Util.SetMaxUsers( 1, "ESCORT_Tank" );
	Util.SetMaxUsers( 1, "BUILD_factory_side_door" );


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

	Util.AddUsePoint("PLANT_factory_side_door", { Vec3(-1423.993, 2751.172, 208.125), Vec3(-1421.508, 2823.145, 208.363) });
	Util.AddUsePoint("BUILD_TankBarrier_1", Vec3(1175.005, -31.508, -187.875) );
	Util.AddUsePoint("PLANT_Tank_Barrier_3", { Vec3(-596.017, 2609.599, 128.298), Vec3(-567.195, 2308.238, 129.367) });


	MapRoutes =
	{
		BUILD_TankBarrier_1 = {
			ROUTE_allied_spawn = {
				ROUTE_City_Left = {},
				ROUTE_City_Right = {},
				ROUTE_city_east1 = {},
			}
		},
		PLANT_Axis_CP = {
			ROUTE_allied_spawn = {
				ROUTE_city_east1 = {},
			},
		},
		PLANT_TankBarrier_1 = {
			ROUTE_Axis_1st_Spawn = {
				ROUTE_Hotel_Front = {},
				ROUTE_Hotel_Main = {},
				ROUTE_Hotel_Back_Path = { Weight=0.5 },
			},
		},
		PLANT_TankBarrier_2 = {
			ROUTE_Axis_1st_Spawn = {
				ROUTE_Hotel_Front = {},
				ROUTE_red_lion_bar = {},
			},
		},
		PLANT_factory_side_door = {
			ROUTE_Forward_Spawn = {
				ROUTE_Side_Door2 = {},
			}
		},
	};
	MapRoutes["ATTACK_Square_.*"] = {
			ROUTE_Axis_1st_Spawn = {
				ROUTE_Hotel_Front = {},
				ROUTE_Hotel_Main = {},
				ROUTE_Hotel_Back_Path = { Weight=3 },
				ROUTE_red_lion_bar = { Weight=2 },
			},
	};
	MapRoutes["DEFEND_Square_.*"] = {
			ROUTE_allied_spawn = {
				ROUTE_City_Left = {},
				ROUTE_City_Right = {},
				ROUTE_city_south = { Weight=2 },
				ROUTE_city_east1 = {},
				ROUTE_city_east2 = {},
			}
	};
	MapRoutes["ATTACK_End.*"] = {
			ROUTE_Forward_Spawn = {
				ROUTE_allied_cp1 = {},
				ROUTE_allied_cp2 = {},
				ROUTE_barrier3_1 = { Weight=0.5 },
				ROUTE_yard_right = { ROUTE_barrier3_2 = {}},
				ROUTE_Side_Door = { Weight=3 },
			}
	};

	MapRoutes.BUILD_TankBarrier_2 = MapRoutes.PLANT_Axis_CP;
	MapRoutes["PLANTMINE_yard.*"] = MapRoutes.PLANT_Axis_CP;

	Util.Routes(MapRoutes);

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