//script created by palota
global Map =
{
	cp = 0,
	flag = 1,

	SetPriorities = function()
	{
		SetAvailableMapGoals(TEAM.AXIS, Map.flag < 2 && Map.cp < 2, "DEFEND_flag.*");
		SetAvailableMapGoals(TEAM.AXIS, Map.flag >= 2 && Map.cp < 2, "DEFEND_cp.*");
		SetAvailableMapGoals(TEAM.AXIS, Map.flag == 3 && Map.cp < 2, ".*MG42.*");
	},

	SetSpawn1 = function(bot)
	{
		//1-train station, 2-allies, 3-axis, 4-command post
		if(bot.GetTeam()==TEAM.ALLIES){
			if(Map.cp==2){
				bot.ChangeSpawnPoint(4);
			}else if(Map.flag==2){
				bot.ChangeSpawnPoint(1);
			}else{
				bot.ChangeSpawnPoint(0);
			}
		}
	},

	SetSpawn = function()
	{
		Map.SetPriorities();
		foreach(bot in BotTable)
		{
			Map.SetSpawn1(bot);
		}
	},

	forward_flag_Axis_Captured = function()
	{
		Map.flag = 1;
		Map.SetSpawn();
		Util.MapDebugPrint("forward_flag_Axis_Captured");
	},

	forward_flag_Allies_Captured = function()
	{
		Map.flag = 2;
		Map.SetSpawn();
		Util.MapDebugPrint("forward_flag_Allies_Captured");
	},

	Command_Post_Axis = function()
	{
		Map.cp = 1;
		Map.SetSpawn();
		Util.MapDebugPrint("Command_Post_Axis");
	},

	Command_Post_Allies = function()
	{
		Map.cp = 2;
		Map.SetSpawn();
		Util.MapDebugPrint("Command_Post_Allies");
	},

	Command_Post_Destroyed = function()
	{
		Map.cp = 0;
		Map.SetSpawn();
		Util.MapDebugPrint("Command_Post_Destroyed");
	},

	Road_Barrier_Destroyed = function()
	{
		Map.flag = 3;
		Map.SetPriorities();
		Util.SetMaxUsersInProgress(2, "BUILD_Neutral_Command_Post");
		Util.EnableGoal("ROUTE_barrier");
		Util.MapDebugPrint("Road_Barrier_Destroyed");
	},

	Sewer_Grate_Destroyed = function()
	{
		Util.EnableGoal("ROUTE_sewer");
		Util.MapDebugPrint("Sewer_Grate_Destroyed");
	},

	North_Depot_Gate_Destroyed = function()
	{
		Util.EnableGoal("ROUTE_north_depot_gate");
		Util.MapDebugPrint("North_Depot_Gate_Destroyed");
	},

	West_Depot_Gate_Destroyed = function()
	{
		Util.EnableGoal("ROUTE_west_depot_gate");
		Util.MapDebugPrint("West_Depot_Gate_Destroyed");
	},

	North_Fueltruck_Destroyed = function()
	{
		Util.DisableGoal(".*n_truck.*");
		Util.MapDebugPrint("North_Fueltruck_Destroyed");
	},

	South_Fueltruck_Destroyed = function()
	{
		Util.DisableGoal(".*s_truck.*");
		Util.MapDebugPrint("South_Fueltruck_Destroyed");
	},
};

global OnMapLoad = function()
{
	OnTrigger("Axis have reclaimed the Trainstation", Map.forward_flag_Axis_Captured);
	OnTrigger("Allies have captured the Trainstation!", Map.forward_flag_Allies_Captured);
	OnTrigger("Axis Command Post constructed. Charge speed increased! Spawnpoint gaine"/*d!*/, Map.Command_Post_Axis);
	OnTrigger("Allied Command Post constructed. Charge speed increased! Spawnpoint gai"/*ned!*/, Map.Command_Post_Allies);
	OnTrigger("Axis team has destroyed the Allied Command Post! Charge speed restored!"/* Spawnpoint lost!*/, Map.Command_Post_Destroyed);
	OnTrigger("Allied team has destroyed the Axis Command Post! Charge speed restored!"/* Spawnpoint lost!*/, Map.Command_Post_Destroyed);
	OnTrigger("Allies have destroyed the Road Barrier!", Map.Road_Barrier_Destroyed);
	OnTrigger("Allies have breached the Sewer Grate!", Map.Sewer_Grate_Destroyed);
	OnTrigger("Allies have destroyed the North Depot Gates!", Map.North_Depot_Gate_Destroyed);
	OnTrigger("Allies have destroyed the West Depot Gates!", Map.West_Depot_Gate_Destroyed);
	OnTrigger("Allies have destroyed the North Fueltruck!", Map.North_Fueltruck_Destroyed);
	OnTrigger("Allies have destroyed the South Fueltruck!", Map.South_Fueltruck_Destroyed);

	Util.DisableGoal(".*_Tug_.*");
	SetAvailableMapGoals(TEAM.AXIS, false, "ATTACK.*");
	SetAvailableMapGoals(TEAM.ALLIES, false, "DEFEND.*");
	Util.DisableGoal(".*MG42.*");
	Util.DisableGoal("ROUTE_barrier");
	Util.DisableGoal("ROUTE_sewer");
	Util.DisableGoal("ROUTE_north_depot_gate");
	Util.DisableGoal("ROUTE_west_depot_gate");

	SetGoalPriority("DEFEND_flag.*", 0.51, TEAM.AXIS);
	SetGoalPriority("PLANT_Road_Barrier", 0.81, TEAM.ALLIES);
	Map.SetPriorities();

	Util.SetMaxUsersInProgress(1, ".*MG42.*");
	Util.SetMaxUsersInProgress(1, "BUILD_Neutral_Command_Post");

	SetMapGoalProperties("DEFEND_.*", {mincamptime=70, maxcamptime=300} );
	SetMapGoalProperties("MOUNTMG42.*", {mincamptime=70, maxcamptime=300} );
	SetMapGoalProperties("SNIPE_.*", {mincamptime=60, maxcamptime=250} );

	MapRoutes =
	{
		CHECKPOINT_forward_flag = {
			ROUTE_allies_spawn = {
				ROUTE_allies1 = {},
				ROUTE_allies2 = {},
				ROUTE_allies3 = {},
				ROUTE_allies4 = {},
				ROUTE_allies5 = {},
				ROUTE_allies6 = {},
			},
			ROUTE_cp_spawn = {
				ROUTE_axis_north = { Weight = 2 },
				ROUTE_barrier = {},
				ROUTE_train_west = {},
				ROUTE_train_east = {},
			},
		},
		PLANT_North_Fueltruck = {
			ROUTE_flag_spawn = {
				ROUTE_train_west = {},
				ROUTE_train_east = {},
				ROUTE_barrier = { Weight = 2,
					ROUTE_mg = {},
					ROUTE_mg2 = {},
				},
			},
			ROUTE_cp_spawn = {
				ROUTE_sewer = { Weight=2 },
				ROUTE_north_depot_gate = {},
				ROUTE_west_depot_gate = {},
			},
		},
		PLANT_South_Fueltruck = {
			ROUTE_flag_spawn = {
				ROUTE_train_west = {},
				ROUTE_train_east = {},
				ROUTE_barrier = { Weight = 3,
					ROUTE_mg = {},
					ROUTE_mg2 = {},
				},
			},
			ROUTE_cp_spawn = {
				ROUTE_north_depot_gate = {},
				ROUTE_center = {
					ROUTE_south_ladder = {},
					ROUTE_west_depot_gate = {},
				},
				ROUTE_south_west = {
					ROUTE_south_ladder = {},
					ROUTE_west_depot_gate = {},
				},
			},
		},
	};
	MapRoutes.ATTACK_n_truck1 = MapRoutes.PLANT_North_Fueltruck;
	MapRoutes.ATTACK_n_truck2 = MapRoutes.ATTACK_n_truck1;
	MapRoutes.ATTACK_s_truck1 = MapRoutes.PLANT_South_Fueltruck;
	MapRoutes.ATTACK_s_truck2 = MapRoutes.ATTACK_s_truck1;
	Util.Routes(MapRoutes);
};

global OnBotJoin = function( bot )
{
	Map.SetSpawn1(bot);
};
