//==========================================================================================
//
//	UJE_city_patrol.gm
//
//	Who		When		What
//------------------------------------------------------------------------------------------
//	palota		13 February 2013
//==========================================================================================
global Map =
{
	MapStart = 1,
	TankAtB1 = 0,
	B1Built = 0,
	TankAtB2 = 0,
	B2Built = 0,
	TankAtB3 = 0,
	B3Built = 0,

	Roles =
	{
		ALLIES =
		{
			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" );
	},

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

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

		Util.MapDebugPrint( "TankBarrier_1_Built" );
	},

	Baricade1_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",
			"PLANT_TankBarrier_2",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANTMINE_yard.*" );

		Util.MapDebugPrint( "Tank_Past_Barrier_1" );
	},

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

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

		Util.MapDebugPrint( "TankBarrier_2_Built" );
	},

	Baricade2_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",
					"ROUTE_Hotel_Back_Path",
				});
				SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_Bar.*" );
			}

		Util.MapDebugPrint( "Tank_At_Barrier_2" );
	},

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

		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Square.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"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, true, {
			"DEFEND_Yard.*",
			"DEFEND_Arch.*",
			"CALLARTILLERY_Arch.*",
			"BUILD_factory_side_door",
			"PLANTMINE_end.*",
		});

		Util.MapDebugPrint( "Forward_spawn_activated" );
	},

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

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

		Util.MapDebugPrint( "Tank_Barrier_3_Built" );
	},

	Baricade3_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" );
	},

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

	factory_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()
{
	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( "^1Barrier ^31 ^7has been constructed.", Map.Baricade1_Built );
	OnTrigger( "^1Barrier ^31 ^7has been destroyed.", Map.Baricade1_Destroyed );
	OnTrigger( "The tank is past the first baricade.", Map.Tank_Past_Barrier_1 );
	OnTrigger( "^1Barrier ^32 ^7has been constructed.", Map.TankBarrier_2_Built );
	OnTrigger( "^1Barrier ^32 ^7has been destroyed.", Map.TankBarrier_2_Destroyed );
	OnTrigger( "The tank is past the second baricade.", Map.Tank_Past_Barrier_2 );
	OnTrigger( "Forward spawns activated", Map.Forward_spawn_activated );
	OnTrigger( "^1Barrier ^33 ^7has been constructed.", Map.Tank_Barrier_3_Built );
	OnTrigger( "^1Barrier ^33 ^7has 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.factory_side_door_Destroyed );
	OnTrigger( "the side door has been contructed", Map.factory_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); //tank at barrier 1
	OnTriggerRegion(AABB(1858.738,548.481,-162.952,2067.330,654.422,-19.251), RegionTrigger.VehicleTrigger); //tank at barrier 2
	OnTriggerRegion(AABB(-672.875,2268.633,105.213,-617.805,2612.659,179.926), RegionTrigger.VehicleTrigger); //tank at barrier 3
	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 );

	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",
		"MOUNT_Tank",
		"ESCORT_Tank",
		"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_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("BUILD_TankBarrier_2", Vec3(2157.849, 1617.439, -54.917) );
	Util.AddUsePoint("PLANT_Tank_Barrier_3", { Vec3(-596.017, 2609.599, 128.298), Vec3(-567.195, 2308.238, 129.367) });

	sleep(0.5); //wait so that the tank can be repaired
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Axis_CP" );

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

global InitializeRoutes = function()
{
	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 = {},
			}
		},
		PLANT_Allied_CP = {
			ROUTE_Forward_Spawn = {
				ROUTE_allied_cp1 = {},
			}
		},
	};
	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);
};
