// cs: possibly remove fake switch hack ...

/*******************************************************************************
Filename: escape2.gm

Created by Advieszeur in 2008

Updated for 0.8 by d00d
Last Updated: Sun, June 20 2010

Change log:
- major comment cleanup (d00d)
- use points for some plant goals (d00d)
- changed priority of BUILD_assault_ramp to 0.8 (d00d)
- added AimPosition to switch (d00d)
- added MAP_TALK checks (d00d)
- removed plant goal hacks, added user-defined plant goals (d00d)
- fixed MG42 repair/mount goals (d00d)
- script formatting (d00d)
- removed WatchForWaypoint stuff (d00d)
- Tweaking (Advieszeur)

--------------------------------------------------------------------------------
Map description:

Allied pow's has to make an escape attempt. To do that they must either:

- Get access to the central area
1. Construct an assault ramp, to gain access to the axis lookout passageway
2. Break 1 or more of the 3 fences
3. Get to the maingate, and blow that up, this will make the lookout spawn permanent.

- Get access to the main entrance
1. Steal the big shell from the ammo bunker, take it to the gun and fire it to blow the wall.
2. Blow the ammo cache on the third floor in the ammobunker to get access to the tunnel or roof route

- Escape with the codebook
1. steal the codebook
2. repairing the gate control for opening the gate
3. escape with the book to truck outside the main entrance.

--------------------------------------------------------------------------------

*** MAP GOALS ***

	//MG objects
	MOUNTMG42_141           //MG Outside Lookout
	MOUNTMG42_189           //MG INSIDE Lookout
	MOUNTMG42_187           //MG2 INSIDE Lookout
	MOUNTMG42_802           //MG1 Fallback
	MOUNTMG42_799           //MG2 Fallback

	REPAIRMG42_799          //MG2 Fallback
	REPAIRMG42_802          //MG1 Fallback
	REPAIRMG42_141          //MG Outside Lookout
	REPAIRMG42_189          //MG INSIDE Lookout
	REPAIRMG42_187          //MG2 INSIDE Lookout

	CHECKPOINT_forward_spawn      //CTF

	/// ALLIES MAP GOALS ///

	FLAG_ctf2_script             //Object codebook
	FLAG_ctf1_script             //Object Shell for gun

	CAPPOINT_BigGun              //return shell object to Gun
	CAPPOINT_Exit                //return codebook to Exit home
	CAPPOINT_cp_control
	CAPPOINT_cp_health
	CAPPOINT_cp_dinner

	SNIPE_lookout_allies         //Sniperspot Allies (lookout)

	BUILD_pile_of_crates
	BUILD_Command_Post           //Command Post
	BUILD_assault_ramp           //Assault Ramp
	BUILD_gate_control           //Gate Control

	PLANT_east_fence
	PLANT_west_fence
	PLANT_Wooden_barrier         //Wooden barrier
	PLANT_Command_Post           //Command Post Axis destroy

	/// AXIS MAP GOALS ///

	BUILD_Command_Post           //Command Post Axis
	BUILD_Wooden_barrier         //Wooden barrier
	BUILD_Command_Post           //Command Post

	PLANT_pile_of_crates         //Pile of Crates
	PLANT_gate_control           //Gate Control
	PLANT_assault_ramp           //Assault Ramp

*******************************************************************************/

global Map =
{

	//set status for conditionals
	PlantMines = false,
	Ammo_Destroyed = 0,
	assault_ramp_status = 0,        // not built
	Gun_Fired = 0,
	CheckPoint_Ignore = 0,
	Allies_Lowspawn = 0,            // 0=start, 1=westfence, 2=lookout, 3=maingate
	GamePhase = 0,                  // 0=Start, 1=middle, 2=end
	MainGate_down = 0,
	Main_Dyno = 0,                  // Dyno counts
	Say_Allies = 0,                 // Says count
	Say_Axis = 0,                   // Says count
	Gate_Exit = 0,                  // 0 = open, 1 = close
	Book_Stolen = 0,                // 1 = book is stolen
	Cappoint_switch = 0,            // set when first time is switched
	New_cp = 0,

	// increase TargetBreakableDist in this trigger region
	increasebreakabledist =
	{
		Name = "increasebreakabledist",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			b = Util.IsBot(ent);
			if (b && b.GetTeam() == TEAM.ALLIES)
			{
				b.TargetBreakableDist = 200.0;
			}
			Util.MapDebugPrint( GetEntName(ent) + " entering." );
		},
		OnExit = function(ent)
		{
			b = Util.IsBot(ent);
			if (b)
			{
				b.TargetBreakableDist = 80.0;
			}
			Util.MapDebugPrint( GetEntName(ent) + " exiting." );
		},
	},

	barrier_build_assist =
	{
		Name = "barrier_build_assist",
		TriggerOnClass = CLASS.ENGINEER,
		OnEnter = function(ent)
		{
			team = GetEntTeam(ent);
			name = GetEntName(ent);
			bot = Util.GetBotByName(name);
			if ( team == TEAM.ALLIES && Map.assault_ramp_status == 0 && Map.GamePhase < 1 )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, {
					"DEFEND_build_ramp_assist.*",
					"SMOKEBOMB_east_fence.*",
				});
				if ( bot && MAP_TALK )
				{
					if (RandInt(0,1) == 0)
						{ bot.SayVoice(VOICE.CONST_COMMENCING); }
					else if (RandInt(0,1) == 0)
						{ bot.SayVoice(VOICE.COVER_ME); }
				}
			}
			Util.MapDebugPrint( name + " entering.", true );
			sleep( 10 );
			SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_build_ramp_assist.*" );
			Util.MapDebugPrint( "Disabling DEFEND_build_ramp_assist.* goals." );
		},
		OnExit = function(ent)
		{
			Util.MapDebugPrint( GetEntName(ent) + " exiting.", true );
		},
	},

	barrier_build_assist2 =
	{
		Name = "barrier_build_assist2",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			team = GetEntTeam(ent);
			name = GetEntName(ent);
			bot = Util.GetBotByName(name);
			if ( team == TEAM.ALLIES && Map.assault_ramp_status == 0 && Map.GamePhase < 1 )
			{
				if ( bot && MAP_TALK )
				{
					if ( RandRange(0,1) < 0.2 )
						{ bot.SayVoice(VOICE.ALL_CLEAR); }
					else if ( RandRange(0,1) < 0.7 )
						{ bot.SayVoice(VOICE.ON_DEFENSE); }
				}
			}
		},
	},

	Switches =
	{
		FireGun =
		{
			Enabled = true,
			WaypointName = "GunSwitch",
			AimPosition = Vec3( 1823, 850, -293 ),
			LimitTeam = 0,          //Only available on trigger
			LimitClass = (1<<CLASS.MEDIC) | (1<<CLASS.FIELDOPS) | (1<<CLASS.SOLDIER) | (1<<CLASS.COVERTOPS) | (1<<CLASS.ENGINEER),
			LimitBots = 2,
		},

		FakeSwitch =
		{
			Enabled = true,
			WaypointName = "Engi_Magnet",
			LimitTeam = 0,
			LimitClass = (1<<CLASS.ENGINEER),
			//LimitDistance = 1000,
			PressOnce = true,        //once per spawn

			ExitConditions =
			{
				someFunc = function(bot)
				{
					return true; //as soon as they hit switch, return true
				},
			},
		},

		FakeSwitch2 =
		{
			Enabled = true,
			WaypointName = "Flag_Back",
			LimitTeam = 0,
			LimitClass = (1<<CLASS.MEDIC) | (1<<CLASS.COVERTOPS) | (1<<CLASS.ENGINEER),
			//LimitDistance = 1000,
			PressOnce = true,       //once per spawn
			LimitBots = 2,          //only two bots at a time

			ExitConditions =
			{
				someFunc = function(bot)
				{
					return true;
				},
			},
		},

		ExitCover =
		{
			Enabled = true,
			WaypointName = "cover_exit",
			LimitTeam = 0,
			LimitClass = (1<<CLASS.MEDIC) | (1<<CLASS.FIELDOPS) | (1<<CLASS.SOLDIER) | (1<<CLASS.COVERTOPS) | (1<<CLASS.ENGINEER),
			//LimitDistance = 1000,
			PressOnce = true,        //once per spawn

			ExitConditions =
			{
				someFunc = function(bot)
				{
					return true;
				},
			},
		},
	},

	//====  TRIGGERS BUILD

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

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

	//Assault Ramp build
	con2_script_Built = function( trigger )
	{
		Map.Allies_Lowspawn = 2;        //Fallbackspawn Allies
		Map.assault_ramp_status = 1;

		//ALLIES
		SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_Assault_Ram"); //Attack Assault
		SetAvailableMapGoals(TEAM.ALLIES, true, "PLANT_ammo_cache");    //Dyno objects
		SetAvailableMapGoals(TEAM.ALLIES, true, "PLANT_cellar_crate");  //Dyno objects

		// AXIS GOALS CHANGE
		SetAvailableMapGoals(TEAM.AXIS, false, "MOUNTMG42_141");        //MG Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_Lookout");       //Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_Lookout2");      //Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_Lookout3");      //Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_Lookout3");      //Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, true, "MOUNTMG42_189");         //MG inside Lookout
		SetAvailableMapGoals(TEAM.AXIS, true, "REPAIRMG42_189");        //MG inside Lookout
		SetAvailableMapGoals(TEAM.AXIS, true, "DEFEND_WoodBarrier");    //Defend Wooden Barrier

		Util.MapDebugPrint( "con2_script_Built (Assault ramp)" );
	},

	// Wooden Barrier build
	con1_script_Built = function( trigger )
	{
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_GunSide3");
		Map.Switches.FakeSwitch2.LimitTeam = 0;                  //For backdoor path flag where route failed

		Util.MapDebugPrint( "con1_script_Built (Wooden barrier)" );
	},

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

	//Pile of Crates build
	con3_script_Built = function( trigger )
	{
		if ( Map.GamePhase < 2 )
		{
			Map.GamePhase = 1;      // 0=Start, 1=middle, 2=end
			SetAvailableMapGoals(TEAM.AXIS, true, "DEFEND_AmmoBunker1");   //Bunker upstairs ammocache
		}

		Util.MapDebugPrint( "con3_script_Built (Pile of Crates)" );
	},

	fake_Built = function( trigger )
	{
		Map.Gate_Exit = 1;

		SetAvailableMapGoals(TEAM.ALLIES, false, {
			"CAPPOINT_cp_.*",
			"DEFEND_df_health",
			"DEFEND_df_dinner",
		});
		SetAvailableMapGoals(TEAM.ALLIES, true, "CAPPOINT_exit");

		//Disable fake switch
		Map.Switches.FakeSwitch.LimitTeam = 0;    //Magnet for Engi

		if ( Map.Book_stolen == 1 )
		{
			//Enable cover for codebook
			SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_at_exit");  //Gate exit
			Map.Switches.ExitCover.LimitTeam = (1<<TEAM.ALLIES);         //Cover magnet
		}

		Util.MapDebugPrint( "fake_Built (Exit gate control)" );
	},

	allied_compost_built_Built = function( trigger )
	{
		Map.CheckPoint_Ignore = 1;
		Map.Allies_Lowspawn = 3; // 0 = start, 1=westfence, 2=lookout, 3=maingate

		if ( Map.GamePhase == 0 )
		{
			Map.GamePhase = 1;
			SetAvailableMapGoals(TEAM.AXIS, true, {
				"DEFEND_GunSide.*",
				"DEFEND_AmmoBunker2",
			});
		}

		if ( Map.ammo_Destroyed == 0 ) //Spawn at bunker
		{
			SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_Ammo1");
		}

		//Maingate spawn available for Allies
		SetAvailableMapGoals(TEAM.ALLIES, false, {
			"SNIPE_lookout_allies",
			"DEFEND_Dyno_maingate",
			"ATTACK_Assault_Ram",
			"ARTILLERY_S_Main.*",
			"CALLARTILLERY_ElectricSpot.*",
			"BUILD_assault_ramp",
		});

		Map.Switches.FakeSwitch2.LimitTeam = 0; //For backdoor path flag where route failed

		//AXIS CHANGE GOALS (to position Ammo Bunker)
		SetAvailableMapGoals(TEAM.AXIS, false, "MOUNTMG42_141");         //MG Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "MOUNTMG42_189");         //MG inside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_Lookout.*");      //Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_WoodBarrier.*");  //Wooden barrier

		SetAvailableMapGoals(TEAM.AXIS, false, {
			"BUILD_Command_Post",
			"PLANT_assault_ramp",
			"PLANT_pile_of_crates",
			"BUILD_eastfence",
			"BUILD_westfence",
			"SNIPE_SnipeMain",
			"DEFEND_Main.*",
		});
		SetAvailableMapGoals(TEAM.AXIS, false, "CHECKPOINT_forward_spawn");     //no need for Checkpoint (Allies have Maingate spawn)

		Util.MapDebugPrint( "allied_compost_built_Built" );
	},

	//===== TRIGGERS DESTROYED

	westfence_Destroyed = function( trigger )
	{
		SetAvailableMapGoals(TEAM.ALLIES, true, "PLANT_main_gate");

		Util.MapDebugPrint( "westfence_Destroyed" );
	},

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

	electricfence_Destroyed = function( trigger )
	{
		SetAvailableMapGoals(TEAM.ALLIES, true, {
			"PLANT_main_gate",
			"ATTACK_Ammo1",
			"DEFEND_Dyno_maingate",
		});
		SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_Assault_Ram");

		Util.MapDebugPrint( "Electric fence_Destroyed" );
	},

	electricfence_planted = function( trigger )
	{
		Util.MapDebugPrint( "Electric fence_Planted" );
	},

	fan_Destroyed = function( trigger )
	{
		Wp.SetWaypointFlag("fan1", "closed", false);
		Wp.SetWaypointFlag("fan2", "closed", false);
		Util.MapDebugPrint( "fan_Destroyed" );
	},

	con2_script_Destroyed = function( trigger )
	{
		Map.assault_ramp_status = 0;
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_build_ramp_assist.*" );
		Util.MapDebugPrint( "con2_script_Destroyed (Assault ramp)" );
	},

	maingate_Planted = function( trigger )
	{
		SetAvailableMapGoals(TEAM.ALLIES, true, "DEFEND_Dyno_maingate");    //Defend Dyno

		Util.MapDebugPrint( "Defend Dyno Enabled" );
	},

	maingate_Disarmed = function( trigger )
	{
		SetAvailableMapGoals(TEAM.ALLIES, false, "DEFEND_Dyno_maingate");    //Defend Dyno

		Util.MapDebugPrint( "Defend Dyno disabled" );
	},

	maingate_Destroyed = function( trigger )
	{
		Map.MainGate_down = 1;

		if ( Map.Allies_Lowspawn < 2 )
		{
			Map.Allies_Lowspawn = 2;    // 0=start, 1=westfence, 2=lookout, 3=maingate
		}

		Wp.SetWaypointFlag("c_lookout","closed",false); //escape for Axis

		if ( Map.ammo_Destroyed == 1 )
			{ SetAvailableMapGoals(TEAM.ALLIES, false, "PLANT_west_fence"); }

		SetAvailableMapGoals(TEAM.ALLIES, false, {
			"SMOKEBOMB_.*_fence.*",
			"DEFEND_Dyno_maingate",
			"SNIPE_lookout_allies",
			"DEFEND_Dyno_maingate",
			"ATTACK_Assault_Ram",
			"ARTILLERY_S_Main.*",
			"CALLARTILLERY_ElectricSpot.*",
			"GRENADE_lookout_mg",
		});
		SetAvailableMapGoals(TEAM.ALLIES, true, {
			"PLANT_ammo_cache",
			"PLANT_cellar_crate",
		});

		//AXIS CHANGE GOALS (to position Ammo Bunker)
		SetAvailableMapGoals(TEAM.AXIS, false, {
			"MOUNTMG42_141",
			"MOUNTMG42_189",
			"DEFEND_Lookout.*",
			"DEFEND_WoodBarrier.*",
			"PLANT_assault_ramp",
			"BUILD_eastfence",
			"BUILD_westfence",
			"SNIPE_SnipeMain",
			"DEFEND_Main.*",
		});

		SetAvailableMapGoals(TEAM.AXIS, true, "DEFEND_BigWall_Top");

		if ( Map.GamePhase < 2 )
		{
			Map.GamePhase = 1;
			Map.Say_Allies= 0;

			SetAvailableMapGoals(TEAM.AXIS, true, {
				"DEFEND_GunSide.*",
				"DEFEND_AmmoBunker2",
			});

			SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_Ammo1");     //Ammo in Bunker

			//Splitting spawn Axis
			foreach ( id and bot in BotTable )
			{
				if ( bot.GetTeam() == TEAM.AXIS )
				{
					//Axis uses the attack as defend (workaround for botgoals)
					if ( RandInt(0,1) < 1)
					{
						bot.ChangeSpawnPoint( 4 ); // Bunker
						Util.MapDebugPrint( "axisbot spawn 4", true );
					}
					else
					{
						bot.ChangeSpawnPoint( 2 ); // forward spawn
						Util.MapDebugPrint( "axisbot spawn 2", true );
					}
				}
				if ( bot.GetTeam() == TEAM.ALLIES )
				{
					//Be happy
					if ( Map.Say_Allies == 0 && MAP_TALK )
					{
						sleep(2.0);
						Map.Say_Allies += 1;
						bot.SayVoice(VOICE.G_AFFIRMATIVE);
					}

					if ( Map.Say_Allies == 1 && MAP_TALK )
					{
						sleep(2.0);
						Map.Say_Allies += 1;
						bot.SayVoice(VOICE.G_ENEMY_WEAK);
					}
				}
			}
		}

		Util.MapDebugPrint( "maingate_Destroyed" );
	},

	//Wooden Barrier destroyed
	con1_script_Destroyed = function( trigger )
	{
		SetAvailableMapGoals(TEAM.ALLIES, false, "ARTILLERY_S_Main.*"); //Arty targets Maingate
		SetAvailableMapGoals(TEAM.ALLIES, false, "CALLARTILLERY_ElectricSpot.*"); //Arty spot

		SetAvailableMapGoals(TEAM.AXIS, false, "MOUNTMG42_189");        //MG inside Lookout
		SetAvailableMapGoals(TEAM.AXIS, true, "DEFEND_GunSide3");

		Map.Switches.FakeSwitch2.LimitTeam = (1<<TEAM.ALLIES); //For backdoor path flag where route failed

		Util.MapDebugPrint( "con1_script_Destroyed (Wooden barrier)" );
	},

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

	axis_compost_built_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "allied_compost_built_Destroyed" );
	},

	con3_script_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "con3_script_Destroyed (Pile of Crates)" );
	},

	cache_planted = function( trigger )
	{
		SetAvailableMapGoals(TEAM.ALLIES, true, "DEFEND_Dyno_cache");

		Util.MapDebugPrint( "Chache planted" );
	},

	cache_Destroyed = function( trigger )
	{
		Map.CheckPoint_Ignore = 1;
		Map.ammo_Destroyed = 1;
		Map.GamePhase = 2;

		//ALLIES (Ammo Goal disable)
		SetAvailableMapGoals(TEAM.ALLIES, false, {
			"PLANT_west_fence",
			"PLANT_east_fence",
			"PLANT_electric_fence",
			"ATTACK_Ammo1",
			"DEFEND_Dyno_maingate",
			"SNIPE_lookout_allies",
			"ATTACK_Assault_Ram",
			"ARTILLERY_S_Main.*",
			"CALLARTILLERY_ElectricSpot.*",
			"DEFEND_Dyno_cache",
			"BUILD_assault_ramp",
			"PLANT_fan",
		});

		//Routes to use
		SetAvailableMapGoals(TEAM.ALLIES, true, "ROUTE_Codebook_esc");          //CAN USE ROUTES

		Map.Switches.FakeSwitch2.LimitTeam = 0; //For backdoor path flag where route failed

		if ( Map.Gun_Fired == 1 ) //Spawn at bunker
		{
			SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_at_fake");          //Backside Fake Attack
			SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_at_control");       //Gate control inside
			SetAvailableMapGoals(TEAM.ALLIES, true, "SNIPE_s_FallBack");        //Sniperspot allies on MG Fallback
			SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_a_fallback_top");               //Attack on top of Fallback spawn
			SetAvailableMapGoals(TEAM.ALLIES, true, "DEFEND_d_dinner");                     //defend (dinnerroom window)
			SetAvailableMapGoals(TEAM.ALLIES, true, "DEFEND_d_fallback_topdoor");           //Top of Fallback
			SetAvailableMapGoals(TEAM.ALLIES, true, "FLAG_ctf2_script");  //Codebook

			SetAvailableMapGoals(TEAM.ALLIES, true, {
				"BUILD_gate_control",
				"DEFEND_fake",
				"DEFEND_cp_Control",
			});

			//MG for Allies too
			SetAvailableMapGoals(TEAM.ALLIES, true, "MOUNTMG42_802");               //MG1 Fallback
			SetAvailableMapGoals(TEAM.ALLIES, true, "MOUNTMG42_799");               //MG2 Fallback

			SetAvailableMapGoals(TEAM.ALLIES, false, "CHECKPOINT_forward_spawn");   //CTF - Flag is permanent now
			SetAvailableMapGoals(TEAM.ALLIES, false, "BUILD_con3_script");          //Pile of Crates

			//Make fakeswitch active only for Allies Engi's replacing the failing route to the backdoor
			Map.Switches.FakeSwitch.LimitTeam = (1<<TEAM.ALLIES);      //Magnet for Engi

			// Routes active
			SetAvailableMapGoals(TEAM.ALLIES, true, "ROUTE_.*");       //CAN USE ROUTES
		}

		//AXIS CHANGE GOALS (to Position Fallback)

		SetAvailableMapGoals(TEAM.AXIS, false, "CHECKPOINT_forward_spawn"); //no need for Checkpoint

		SetAvailableMapGoals(TEAM.AXIS, false, "MOUNTMG42_141");        //MG Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "MOUNTMG42_189");        //MG inside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_Lookout.*");     //Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_WoodBarrier.*"); //Wooden barrier
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_Main.*");        //On Maingate / roof
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_AmmoBunker.*");  //Ammo Bunker
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_GunSide.*");             //Ammo Bunker

		SetAvailableMapGoals(TEAM.AXIS, false, {
			"PLANT_assault_ramp",
			"BUILD_eastfence",
			"BUILD_westfence",
		});
		SetAvailableMapGoals(TEAM.AXIS, false, "SNIPE_SnipeMain");      //Sniperspot above maingate spawn allies

		SetAvailableMapGoals(TEAM.AXIS, false, {
			"BUILD_Command_Post",
			"Checkpoint_forward_spawn",
		});

		SetAvailableMapGoals(TEAM.AXIS, true, {
			"DEFEND_FallBack1",
			"DEFEND_FallBack2",
			"DEFEND_Fake",
			"DEFEND_Fake2",
			"DEFEND_BigWall_Top",
		});
		SetAvailableMapGoals(TEAM.AXIS, true, "MOUNTMG42_802");  //MG1 Fallback
		SetAvailableMapGoals(TEAM.AXIS, true, "MOUNTMG42_799");  //MG2 Fallback
		SetAvailableMapGoals(TEAM.AXIS, true, "REPAIRMG42_802"); //MG1 Fallback
		SetAvailableMapGoals(TEAM.AXIS, true, "REPAIRMG42_799"); //MG2 Fallback

		SetAvailableMapGoals(TEAM.AXIS, false, "PLANTMINE_.*");          //Mine placing
		SetAvailableMapGoals(TEAM.AXIS, true, "PLANTMINE_m_exit.*");     //Mine placing
		SetAvailableMapGoals(TEAM.AXIS, true, "PLANTMINE_m_codebook.*"); //Mine placing

		SetAvailableMapGoals(TEAM.AXIS, true, "PLANT_gate_control");     //Destroy control panel

		Util.SetMaxUsersInProgress( 1, "MOUNTMG42.*" );

		//Game Phase 2 - need more Coverts for destroying fake, and change spawn
		Covert_count = 2;
		if ( ETUtil.CountTeam(TEAM.AXIS) < 4 )
			{ Covert_count = 1; }
		Server.MinClassCount[TEAM.AXIS][CLASS.COVERTOPS] = Covert_count;

		foreach ( id and bot in BotTable )
		{
			if ( bot.GetTeam() == TEAM.AXIS )
			{
				//70% change spawnpoint to Fallback
				if ( RandInt(0,9) > 2)   // 70% Fallback 30% Bunker
				{
					bot.ChangeSpawnPoint( 3 );              // fallback
				}
				if ( Map.Gun_Fired == 1 ) // 100% Spawn at bunker
				{
					bot.ChangeSpawnPoint( 3 );              // fallback
					if ( MAP_TALK && RandInt(1,10) < 3 )
					{
						bot.ExecCommand("vsay_team FTFallBack");
					}
				}
			}
			else if ( bot.GetTeam() == TEAM.ALLIES && MAP_TALK )
			{
				if ( RandInt(0,9) < 2)
				{
					bot.SayVoice(VOICE.COMMAND_COMPLETED);
				}
			}
		}

		Util.MapDebugPrint( "cache_Destroyed, Hill Path and Cellar path opened" );
	},

	Wall_Destroyed = function( trigger )
	{
		Map.Gun_Fired = 1;
		Map.CheckPoint_Ignore = 1;
		Map.GamePhase = 2;
		Map.Say_Allies = 0;
		Map.Say_Axis == 0;

		//Disable Attackpoint Gun
		Map.Switches.FireGun.LimitTeam = 0 ;     //Disable Gun Switch
		Map.Switches.FakeSwitch2.LimitTeam = 0;  //For backdoor path flag where route failed

		SetAvailableMapGoals(TEAM.ALLIES, false, {
			"PLANT_fan",
			"PLANT_west_fence",
			"PLANT_east_fence",
			"SNIPE_lookout_allies",
			"PLANT_Wooden_barrier",
			"DEFEND_Dyno_maingate",
			"BUILD_assault_ramp",
			"ATTACK_Ammo1",
			"ATTACK_Assault_Ram",
			"ARTILLERY_S_Main.*",
			"CALLARTILLERY_ElectricSpot.*",
		});

		SetAvailableMapGoals(TEAM.ALLIES, true, "BUILD_gate_control");
		SetAvailableMapGoals(TEAM.ALLIES, true, "FLAG_ctf2_script");  //Codebook
		SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_at_fake");    //Backside Fake Attack
		SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_at_control"); //Gate control inside

		if ( Map.ammo_Destroyed == 1 ) //Spawn at bunker
		{
			SetAvailableMapGoals(TEAM.ALLIES, false, "BUILD_con3_script");          //Pile of Crates
			SetAvailableMapGoals(TEAM.ALLIES, false, "CHECKPOINT_forward_spawn");   //CTF - Flag is permanent now
			//SetAvailableMapGoals(TEAM.ALLIES, false, "BUILD_Command_Post");       //Command Post
			SetAvailableMapGoals(TEAM.ALLIES, true, {
				"DEFEND_fake",
				"DEFEND_cp_Control",
			});

			SetAvailableMapGoals(TEAM.ALLIES, true, "SNIPE_s_FallBack");    //Sniperspot allies on MG Fallback
			SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_a_fallback_top");      //Attack on top of Fallback spawn
			SetAvailableMapGoals(TEAM.ALLIES, true, "DEFEND_d_dinner");            //defend (dinnerroom window)
			SetAvailableMapGoals(TEAM.ALLIES, true, "DEFEND_d_fallback_topdoor");  //Top of Fallback

			//MG for Allies too
			SetAvailableMapGoals(TEAM.ALLIES, true, "MOUNTMG42_802");   //MG1 Fallback
			SetAvailableMapGoals(TEAM.ALLIES, true, "MOUNTMG42_799");   //MG2 Fallback

			//Make fakeswitch active only for Allies Engi's replacing the failing route to the backdoor
			Map.Switches.FakeSwitch.LimitTeam = (1<<TEAM.ALLIES);    //Magnet for Engi

			// Routes active
			SetAvailableMapGoals(TEAM.ALLIES, true, "ROUTE_.*");     //CAN USE ROUTES
		}

		//AXIS CHANGE GOALS (to Position Fallback)

		SetAvailableMapGoals(TEAM.AXIS, false, "CHECKPOINT_forward_spawn"); //no need for Checkpoint

		SetAvailableMapGoals(TEAM.AXIS, false, "MOUNTMG42_141");        //MG Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "MOUNTMG42_189");        //MG inside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_Lookout.*");     //Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_WoodBarrier.*"); //Wooden barrier
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_Main.*");        //On Maingate / roof
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_AmmoBunker.*");  //Ammo Bunker
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_GunSide.*");     //Gun

		SetAvailableMapGoals(TEAM.AXIS, false, {
			"PLANT_assault_ramp",
			"BUILD_east_fence",
			"BUILD_west_fence",
			"SNIPE_SnipeMain",
			"DEFEND_MainGate",
			"BUILD_Command_Post",
		});

		SetAvailableMapGoals(TEAM.AXIS, true, {
			"DEFEND_FallBack1",
			"DEFEND_FallBack2",
			"DEFEND_Fake",
			"DEFEND_Fake2",
			"DEFEND_BigWall_Top",
			"DEFEND_d_dinner",
			"DEFEND_d_barrak",
			"DEFEND_d_exit",
			"ATTACK_a_codebook_outside",
			"ATTACK_a_codebook_inside",
			"DEFEND_BigWall_Top",
		});
		SetAvailableMapGoals(TEAM.AXIS, true, "MOUNTMG42_802");  //MG1 Fallback
		SetAvailableMapGoals(TEAM.AXIS, true, "MOUNTMG42_799");  //MG2 Fallback
		SetAvailableMapGoals(TEAM.AXIS, true, "REPAIRMG42_802"); //MG1 Fallback
		SetAvailableMapGoals(TEAM.AXIS, true, "REPAIRMG42_799"); //MG2 Fallback
		SetAvailableMapGoals(TEAM.AXIS, true, "PLANT_gate_control");

		SetAvailableMapGoals(TEAM.AXIS, false, "PLANTMINE.*");
		SetAvailableMapGoals(TEAM.AXIS, true, {
			"PLANTMINE_m_exit.*",
			"PLANTMINE_m_codebook.*",
		});

		Util.SetMaxUsersInProgress( 1, "MOUNTMG42.*" );

		SetGoalPriority( "MOUNTMG42_.*", 1.0, TEAM.ALLIES, CLASS.SOLDIER );
		SetGoalPriority( "MOUNTMG42_.*", 1.0, TEAM.ALLIES, CLASS.FIELDOPS );

		//Game Phase 2 - need more Coverts for destroying fake, and change spawn
		Covert_count = 2;
		if ( ETUtil.CountTeam(TEAM.AXIS) < 4 )
			{ Covert_count = 1; }
		Server.MinClassCount[TEAM.AXIS][CLASS.COVERTOPS] = Covert_count;

		foreach ( id and bot in BotTable )
		{
			team = bot.GetTeam();

			// AXIS BOT
			if ( team == TEAM.AXIS )
			{
				bot.ChangeSpawnPoint( 3 ); // fallback

				//Negative
				if ( Map.Say_Axis == 0 && MAP_TALK )
				{
					sleep(2.0);
					Map.Say_Axis += 1;
					bot.SayVoice(VOICE.NEGATIVE);
				}
			}

			// ALLIES BOT
			if ( team == TEAM.ALLIES )
			{
				// TODO - jaskot: Need a way to set MinCampTime = 30 and
				// MaxCampTime = 60 for MOUNTMG42 per team

				//Be happy
				if ( Map.Say_Allies == 1 && MAP_TALK )
					{ bot.SayVoice(VOICE.G_ENEMY_WEAK); }

				if ( Map.Say_Allies < 2 && MAP_TALK )
				{
					bot.SayVoice(VOICE.G_CHEER);
					sleep(2.0);
					Map.Say_Allies += 1;
					bot.SayVoice(VOICE.G_CHEER);
				}
			}
		}

		Util.MapDebugPrint( "Wall destroyed" );
	},

	fake_Destroyed = function( trigger )
	{
		Map.Gate_Exit = 0;
		Map.Cappoint_switch = 1;         //Switch is made

		if ( Map.Gun_Fired == 1 && Map.ammo_Destroyed == 1 ) //Fake is goal for Engi's
		{
			//Make fakeswitch active only for Allies Engi's replacing the failing route to the backdoor
			Map.Switches.FakeSwitch.LimitTeam = (1<<TEAM.ALLIES);     //Magnet for Engi
		}

		//Disable cover for codebook
		SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_at_exit");     //Gate exit
		Map.Switches.ExitCover.LimitTeam = 0;                           //Cover magnet (1<<TEAM.ALLIES)

		if ( Map.Book_stolen == 1 )
		{
			sleep(3);       //Wait, codebook may be near to the exit

			SetAvailableMapGoals(TEAM.AXIS, false, "CAPPOINT_exit");

			//Change to cappoint to hide with the codebook
			Map.New_cp = RandInt(0,2);

			if ( Map.New_cp == 0)
				{ SetAvailableMapGoals(TEAM.ALLIES, true, "CAPPOINT_cp_control"); }
			if ( Map.New_cp == 1)
			{
				SetAvailableMapGoals(TEAM.ALLIES, true, {
					"CAPPOINT_cp_health",
					"DEFEND_df_health",
				});
			}
			if ( Map.New_cp == 2)
			{
				SetAvailableMapGoals(TEAM.ALLIES, true, {
					"CAPPOINT_cp_dinner",
					"DEFEND_df_dinner",
				});
			}

			Util.MapDebugPrint( "Hide with codebook " + Map.New_CP, true );
		}

		Util.MapDebugPrint( "fake_Destroyed (Exit gate control)" );
	},

	cellar_Destroyed = function( trigger )
	{
		SetAvailableMapGoals(TEAM.ALLIES, true, "FLAG_ctf2_script");  //Codebook
		SetAvailableMapGoals(TEAM.ALLIES, true, "BUILD_gate_control");

		Util.MapDebugPrint( "cellar crate destroyed" );
	},

	//===== TRIGGERS STEAL - RETURN

	shell_Stolen = function( trigger )
	{
		if ( Map.GamePhase < 2 )
		{
			SetAvailableMapGoals(TEAM.AXIS, true, {
				"DEFEND_GunSide.*",
				"DEFEND_AmmoBunker2",
				"DEFEND_BigWall_Top",
			});
		}

		Util.MapDebugPrint( "Shell_Stolen" );
	},

	shell_Returned = function( trigger )
	{
		Util.MapDebugPrint( "Shell_Returned" );
	},

	shell_Loaded = function( trigger )
	{
		if ( Map.GamePhase < 2 )
		{

			Map.GamePhase = 1;

			//AXIS CHANGE GOALS (to position Ammo Bunker)
			SetAvailableMapGoals(TEAM.AXIS, false, "MOUNTMG42_141");        //MG Outside Lookout
			SetAvailableMapGoals(TEAM.AXIS, false, "MOUNTMG42_189");        //MG inside Lookout
			SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_Lookout.*");     //Outside Lookout
			SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_WoodBarrier.*"); //Wooden barrier
			SetAvailableMapGoals(TEAM.AXIS, false, {
				"PLANT_assault_ramp",
				"BUILD_Wooden_barrier",
				"BUILD_eastfence",
				"BUILD_westfence",
				"SNIPE_SnipeMain",
				"DEFEND_Main.*",
			});

			SetAvailableMapGoals(TEAM.AXIS, true, "DEFEND_GunSide.*");
			SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_AmmoBunker2");
			SetAvailableMapGoals(TEAM.AXIS, true, {
				"DEFEND_AmmoBunker1",
				"DEFEND_BigWall_Top",
			});
		}

		//ALLIES GOALS
		SetAvailableMapGoals(TEAM.ALLIES, true, "CAPPOINT_Exit");    //Cappoint codebook
		SetAvailableMapGoals(TEAM.ALLIES, false, "CAPPOINT_BigGun"); //Cappoint gun

		SetAvailableMapGoals(TEAM.ALLIES, false, "DEFEND_Dyno_maingate");

		//Make Switch active
		Map.Switches.FireGun.LimitTeam = (1<<TEAM.ALLIES); //Gun Switch

		Util.MapDebugPrint( "shell_Loaded, Fire the Gun" );
	},

	Codebook_Stolen = function( trigger )
	{
		Map.Book_Stolen = 1;

		SetAvailableMapGoals(TEAM.ALLIES, true, "SMOKEBOMB_fallback_.*");
		SetAvailableMapGoals(TEAM.ALLIES, true, "CAPPOINT_exit");          //Default Cappoint
		SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_at_exit");         //Gate exit

		if ( Map.Gate_Exit == 0 )               //Gate is closed
		{
			SetAvailableMapGoals(TEAM.ALLIES, false, "CAPPOINT_exit");
			SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_at_exit");  //Gate exit escort

			Map.Cappoint_switch = 1;         //Switch is made

			//Change to cappoint to hide with the codebook
			Map.New_cp = RandInt(0,2);

			if ( Map.New_cp == 0)
				{ SetAvailableMapGoals(TEAM.ALLIES, true, "CAPPOINT_cp_control"); }
			if ( Map.New_cp == 1)
			{
				SetAvailableMapGoals(TEAM.ALLIES, true, {
					"CAPPOINT_cp_health",
					"DEFEND_df_health",
				});
			}
			if ( Map.New_cp == 2)
			{
				SetAvailableMapGoals(TEAM.ALLIES, true, {
					"CAPPOINT_cp_dinner",
					"DEFEND_df_dinner",
				});
			}

			Util.MapDebugPrint( "Hide with codebook ", Map.New_cp );
		}
		else                            //Gate is open
		{
			Map.Switches.ExitCover.LimitTeam = (1<<TEAM.ALLIES);    //Cover magnet
		}

		Util.MapDebugPrint( "Codebook_Stolen" );
	},

	Codebook_Returned = function( trigger )
	{
		SetAvailableMapGoals(TEAM.ALLIES, false, {
			"SMOKEBOMB_fallback_2",
			"SMOKEBOMB_fallback_3",
			"SMOKEBOMB_fallback_4",
			"DEFEND_df_dinner",
			"DEFEND_df_health",
			"CAPPOINT_cp_health",
			"CAPPOINT_cp_dinner",
		});

		//Disable cover for the book
		SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_at_exit");  //Gate exit
		Map.Switches.ExitCover.LimitTeam = 0;                        //Cover magnet

		Map.Book_Stolen = 0;

		Util.MapDebugPrint( "Codebook_Returned" );
	},

	//Allies escaped with the book - WIN!!!!
	Codebook_escape = function( trigger )
	{
		ETUtil.WinningChat( TEAM.ALLIES );
		ETUtil.LosingChat( TEAM.AXIS );
		Util.MapDebugPrint( "Codebook_Escaped" );
	},

	//=== TRIGGERS FLAG CAPTURE

	Allies_Capture_Flag = function( trigger )
	{
		Map.Switches.FakeSwitch2.LimitTeam = 0;  //For backdoor path flag where route failed

		//AXIS CHANGE GOALS
		SetAvailableMapGoals(TEAM.AXIS, false, "MOUNTMG42_141");   //MG Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, "REPAIRMG42_141");  //MG Outside Lookout
		SetAvailableMapGoals(TEAM.AXIS, false, {
			"DEFEND_Lookout.*",
			"PLANT_assault_ramp",
			"BUILD_eastfence",
			"BUILD_westfence",
		});
		SetAvailableMapGoals(TEAM.AXIS, true, "DEFEND_GunSide3");

		if ( Map.CheckPoint_Ignore == 0 )
		{
			SetAvailableMapGoals(TEAM.AXIS, true, "CHECKPOINT_forward_spawn"); //Checkpoint
		}

		Util.MapDebugPrint( "Allies_Capture_Flag" );
	},

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

//###### GLOBAL MAP LOAD #################

global OnMapLoad = function()
{
	//SET GOALS AVAILABLE
	Util.DisableGoal( ".*", true );                         //disable all but routes

	Wp.SetWaypointFlag("c_lookout", "closed", true);        //escape for Axis
	Wp.SetWaypointFlag("fan1", "closed", true);
	Wp.SetWaypointFlag("fan2", "closed", true);

	Util.AddUsePoint("PLANT_east_fence", { Vector3(3130,-2780,-375), Vector3(3130,-2716,-375) });
	Util.AddUsePoint("PLANT_west_fence", { Vector3(1033,-1264,-350), Vector3(924,-1264,-350) });
	Util.AddUsePoint("PLANT_cellar_crate", { Vector3(-1022,3430,-430), Vector3(-1022,3465,-430) });
	Util.AddUsePoint("PLANT_electric_fence", { Vector3(1908,-2430,-320), Vector3(2000,-2330,-320) });
	Util.AddUsePoint("PLANT_main_gate", { Vector3(2375,-380,-350), Vector3(2375,-270,-350) });
	Util.AddUsePoint("PLANT_Wooden_barrier", { Vector3(3484,700,-350), Vector3(3600,700,-350) });

	//GOAL PROPERTIES
	SetMapGoalProperties( "ATTACK_.*", {MinCampTime=2, MaxCampTime=15} );
	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=10, MaxCampTime=120} );
	SetMapGoalProperties( "DEFEND_build_ramp_assist.*", {MinCampTime=8, MaxCampTime=10} );
	SetMapGoalProperties( "SNIPE_.*", {MinCampTime=60, MaxCampTime=120} );

	SetGoalPriority( "DEFEND_build_ramp_assist.*", 0.8, TEAM.ALLIES );
	SetGoalPriority( "CHECKPOINT_forward_spawn", 0.8, TEAM.ALLIES, CLASS.SOLDIER );
	SetGoalPriority( "CHECKPOINT_forward_spawn", 0.8, TEAM.ALLIES, CLASS.FIELDOPS );
	SetGoalPriority( "CHECKPOINT_forward_spawn", 0.8, TEAM.AXIS, CLASS.SOLDIER );
	SetGoalPriority( "BUILD_assault_ramp", 0.81 );
	SetGoalPriority( "BUILD_pile_of_crates", 0.8 );
	SetGoalPriority( "GRENADE_lookout_mg", 0.7 );
	SetGoalPriority( "BUILD_Command_Post", 0.8 );
	SetGoalPriority( "PLANT_main_gate", 0.81 );
	SetGoalPriority( "PLANT_electric_fence", 0.81 );
	SetGoalPriority( "PLANT_ammo_cache", 0.81 );
	SetGoalPriority( "PLANT_cellar_crate", 0.81, TEAM.ALLIES, CLASS.COVERTOPS );
	SetGoalPriority( "PLANT_east_fence", 0.81, TEAM.ALLIES, CLASS.COVERTOPS );
	SetGoalPriority( "PLANT_west_fence", 0.815, TEAM.ALLIES, CLASS.COVERTOPS );
	SetGoalPriority( "PLANT_Wooden_barrier", 0.81, TEAM.ALLIES, CLASS.COVERTOPS );
	SetGoalPriority( "SMOKEBOMB_.*_fence.*", 0.81, TEAM.ALLIES, CLASS.COVERTOPS );
	SetGoalPriority( "SMOKEBOMB_electric_fence.*", 0.8, TEAM.ALLIES, CLASS.COVERTOPS );
	if ( !Map.PlantMines )
		{ SetGoalPriority( "PLANTMINE_.*", 0.0 ); }

	//ALLIES GOALS
	SetAvailableMapGoals(TEAM.ALLIES, true, {
		"HEALTHCAB_.*",
		"AMMOCAB_.*",
		"PLANT_fan",
		"PLANT_east_fence",
		"PLANT_west_fence",
		"PLANT_electric_fence",
		"PLANT_Wooden_barrier",
	});
	SetAvailableMapGoals(TEAM.ALLIES, true, "BUILD_.*");            //Construct objects
	SetAvailableMapGoals(TEAM.ALLIES, true, {
		"CAPPOINT_BigGun",
		"FLAG_.*",
		"CHECKPOINT_forward_spawn",
		"SNIPE_lookout_allies",
		"DEFEND_Dyno_maingate",
		"ATTACK_Assault_Ram",
		"ARTILLERY.*",
		"CALLARTILLERY_.*",
		"ATTACK_Ammo1",
		"GRENADE_lookout_mg",
		"SMOKEBOMB_east_fence.*",
		"SMOKEBOMB_west_fence.*",
		"SMOKEBOMB_electric_fence.*",
	});

	SetAvailableMapGoals(TEAM.ALLIES, false, {
		"BUILD_gate_control",
		"FLAG_ctf2_script",
		"DEFEND_df_dinner",
		"DEFEND_df_health",
		"HEALTH_Fallback_health",
	});

	//AXIS GOALS
	SetAvailableMapGoals(TEAM.AXIS, true, {
		"HEALTHCAB_.*",
		"AMMOCAB_.*",
	});
	SetAvailableMapGoals(TEAM.AXIS, true, "MOUNTMG42_141"); //MG Outside Lookout
	SetAvailableMapGoals(TEAM.AXIS, true, {
		"DEFEND_Lookout",
		"DEFEND_Lookout2",
		"BUILD_.*",
		"DEFEND_MainGate",
		"DEFEND_MainGate2",
		"SNIPE_SnipeMain",
		"PLANT_pile_of_crates",
		"PLANT_gate_control",
		"PLANT_assault_ramp",
		"PLANTMINE_.*",
	});
	SetAvailableMapGoals(TEAM.AXIS, false, {
		"PLANTMINE_m_exit.*",
		"PLANTMINE_m_codebook.*",
	});

	// Max users per goal
	Util.SetMaxUsersInProgress( 2, "DEFEND_.*" );
	Util.SetMaxUsersInProgress( 2, "FLAG_.*" );
	Util.SetMaxUsersInProgress( 2, "CHECKPOINT_.*" );
	Util.SetMaxUsersInProgress( 1, "DEFEND_Fake.*" );
	Util.SetMaxUsersInProgress( 1, "DEFEND_d_exit" );
	Util.SetMaxUsersInProgress( 1, "ATTACK_a_codebook_outside" );
	Util.SetMaxUsersInProgress( 2, "ATTACK_a_codebook_inside" );
	Util.SetMaxUsersInProgress( 1, "DEFEND_WoodBarrier.*" );
	Util.SetMaxUsersInProgress( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsersInProgress( 1, "PLANT_.*" );
	Util.SetMaxUsersInProgress( 1, "BUILD_.*" );
	Util.SetMaxUsersInProgress( 1, "SMOKEBOMB_.*" );
	Util.SetMaxUsersInProgress( 1, "GRENADE_.*" );

	//************* TRIGGERS ***************************************

	fan_region = OnTriggerRegion( AABB(4340,920,-350, 4700,1090,-150), Map.increasebreakabledist );
	closet_region = OnTriggerRegion( AABB(-930,3030,-14, -527,3233,112), Map.increasebreakabledist );
	assaultramp = OnTriggerRegion( AABB(2485,-3627,-380, 2617,-3507,-230), Map.barrier_build_assist );
	assaultramp2 = OnTriggerRegion( Vector3(2790,-3270,-300), 20, Map.barrier_build_assist2 );;
	assaultramp3 = OnTriggerRegion( Vector3(2768,-3404,-300), 20, Map.barrier_build_assist2 );;
	assaultramp4 = OnTriggerRegion( Vector3(2535,-3374,-300), 20, Map.barrier_build_assist2 );;

	//FENCES
	OnTrigger( "The allies have destroyed the east fence !!!!", Map.eastfence_Destroyed );
	OnTrigger( "The allies have destroyed the west fence !!!!", Map.westfence_Destroyed );
	OnTrigger( "Axis team has rebuilt the west fence !!!!", Map.westfence_Built );
	OnTrigger( "Axis team has rebuilt the east fence !!!!", Map.eastfence_Built );
	OnTrigger( "The allies have destroyed the electric fence!", Map.electricfence_Destroyed );
	OnTrigger( "Planted at the electric fence.", Map.electricfence_planted );

	//ASSAULT RAMP
	OnTrigger( "Allied team has built the assault ramp!", Map.con2_script_Built );
	OnTrigger( "Axis team has destroyed the assault ramp!", Map.con2_script_Destroyed );

	//MAINGATE
	OnTrigger( "Planted at the main gate.", Map.maingate_Planted );
	OnTrigger( "Defused at the main gate.", Map.maingate_Disarmed );
	OnTrigger( "The allies have destroyed the main gate!", Map.maingate_Destroyed );

	//COMPOST
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.axis_compost_built_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.axis_compost_built_Destroyed );
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.allied_compost_built_Built );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.allied_compost_built_Destroyed );

	//WOODEN BARRIER
	OnTrigger( "Axis team has built the wooden barrier!", Map.con1_script_Built );
	OnTrigger( "Allied team has destroyed the wooden barrier!", Map.con1_script_Destroyed );

	//FAN
	OnTrigger( "The allies have destroyed the ventilator!", Map.fan_Destroyed );

	//PILE OF CRATES
	OnTrigger( "Allied team has stacked the pile of crates!", Map.con3_script_Built );
	OnTrigger( "Axis team has destroyed the pile of crates!", Map.con3_script_Destroyed );

	//FLAG CAPTURE
	OnTrigger( "Allies capture the forward spawn!", Map.Allies_Capture_Flag );
	OnTrigger( "Axis capture the forward spawn!", Map.Axis_Capture_Flag );

	//SHELL-GUN-WALL
	OnTrigger( "The allies has stolen the big shell", Map.shell_Stolen );
	OnTrigger( "The big shell has been returned", Map.shell_Returned );
	OnTrigger( "The big shell has been loaded", Map.shell_Loaded );
	OnTrigger( "The allies have blown the wall", Map.Wall_Destroyed );

	//FLOOR - AMMO GRATE
	OnTrigger( "The allies have destroyed the ammo cache!", Map.cache_Destroyed );
	OnTrigger( "The allies have destroyed the cellar grate!", Map.cellar_Destroyed );
	OnTrigger( "Planted at the ammo cache.", Map.cache_planted );

	//EXIT GATE (FAKE)
	OnTrigger( "Allied team has opened the main entrance", Map.fake_Built );
	OnTrigger( "Axis team has closed the main entrance", Map.fake_Destroyed );

	//CODE BOOK
	OnTrigger( "They have stolen codebook", Map.Codebook_Stolen );
	OnTrigger( "The codebook has been returned", Map.Codebook_Returned );

	OnTrigger( "Allies got away with the codebook", Map.Codebook_escape );

	// ********************************************************
	// ***** ROUTES ****************************************
	// ********************************************************
	MapRoutes =
	{
		PLANT_electric_fence =
		{
			ROUTE_allied_spawn =
			{
				ROUTE_irondoor =
				{
					ROUTE_irondoor2 = {},
					ROUTE_ruin_roof = {}
				}
			}
		},
		CHECKPOINT_forward_spawn =
		{
			ROUTE_r_spawn_lookout =
			{
				ROUTE_r_flag_b1 =
				{
					ROUTE_r_flag_b2 = { ROUTE_r_flag_b3 = { }, },
				},
				ROUTE_r_flag_a1 =
				{
					Weight = 3,
					ROUTE_r_flag_b3 = { },
					ROUTE_r_flag_a2 =
					{
						Weight = 3,
						ROUTE_r_flag_a3 =
						{
							ROUTE_r_flag_a4 = { ROUTE_r_flag_a5 = { }, },
						},
					},
				},
			},
		},
		BUILD_gate_control =
		{
			ROUTE_BunkerSpawn =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_Fallback_front =
					{
						ROUTE_Fake_side =
						{
							ROUTE_Fake_behind = { },
						},
					},
					ROUTE_r_wall_ladder =
					{
						Weight = 4,
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge =
							{
								ROUTE_r_fallback_behind =
								{
									Weight = 5,
									ROUTE_Fake_behind = { },
								},
								ROUTE_r_fallback_top1 = { ROUTE_Fake_behind = { }, },
							},
						},
					},
				},
			},
			ROUTE_BunkerSpawn2 =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_Fallback_front =
					{
						ROUTE_Fake_side =
						{
							ROUTE_Fake_behind = { },
						},
					},
					ROUTE_r_wall_ladder =
					{
						Weight = 4,
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge =
							{
								ROUTE_r_fallback_behind =
								{
									Weight = 5,
									ROUTE_Fake_behind = { },
								},
								ROUTE_r_fallback_top1 = { ROUTE_Fake_behind = { }, },
							},
						},
					},
				},
			},
			ROUTE_BunkerSpawn3 =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_Fallback_front =
					{
						ROUTE_Fake_side =
						{
							ROUTE_Fake_behind = { },
						},
					},
					ROUTE_r_wall_ladder =
					{
						Weight = 4,
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge =
							{
								ROUTE_r_fallback_behind =
								{
									Weight = 5,
									ROUTE_Fake_behind = { },
								},
								ROUTE_r_fallback_top1 = { ROUTE_Fake_behind = { }, },
							},
						},
					},
				},
			},
			ROUTE_BunkerSpawn4 =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_Fallback_front =
					{
						ROUTE_Fake_side =
						{
							ROUTE_Fake_behind = { },
						},
					},
					ROUTE_r_wall_ladder =
					{
						Weight = 4,
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge =
							{
								ROUTE_r_fallback_behind =
								{
									Weight = 5,
									ROUTE_Fake_behind = { },
								},
								ROUTE_r_fallback_top1 = { ROUTE_Fake_behind = { }, },
							},
						},
					},
				},
			},
			ROUTE_Bunker_Outside =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_Fallback_front =
					{
						ROUTE_Fake_side =
						{
							ROUTE_Fake_behind = { },
						},
					},
					ROUTE_r_wall_ladder =
					{
						Weight = 4,
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge =
							{
								ROUTE_r_fallback_behind =
								{
									Weight = 5,
									ROUTE_Fake_behind = { },
								},
								ROUTE_r_fallback_top1 = { ROUTE_Fake_behind = { }, },
							},
						},
					},
				},
			},
		},
		CAPPOINT_Exit =
		{
			ROUTE_Codebook_esc =
			{
				ROUTE_Fallback_hide = {},
				ROUTE_Fallback_center =
				{
					ROUTE_Fallback_front =
					{
						ROUTE_Fake_side =
						{
							ROUTE_Fake_behind = { Weight = 8, },
							ROUTE_Fake_front = {},
						},
					},
				},
			},
		},
		FLAG_ctf2_script =
		{
			ROUTE_BunkerSpawn =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_Codebook = {},
				},
				ROUTE_Hill =
				{
					Weight = 3,
					ROUTE_Codebook = {},
				},
				ROUTE_Cellar1 =
				{
					Weight = 3,
					ROUTE_Cellar2 =
					{
						ROUTE_Cellar3 =
						{
							ROUTE_Code2 =
							{
								Weight = 3,
								ROUTE_Codebook = {},
							},
							ROUTE_Code1 =
							{
								ROUTE_Codebook = {},
							},
						},
					},
				},
			},
			ROUTE_BunkerSpawn2 =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_Codebook = {},
				},
				ROUTE_Hill =
				{
					Weight = 3,
					ROUTE_Codebook = {},
				},
				ROUTE_Cellar1 =
				{
					Weight = 3,
					ROUTE_Cellar2 =
					{
						ROUTE_Cellar3 =
						{
							ROUTE_Code2 =
							{
								Weight = 3,
								ROUTE_Codebook = {},
							},
							ROUTE_Code1 =
							{
								ROUTE_Codebook = {},
							},
						},
					},
				},
			},
			ROUTE_BunkerSpawn3 =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_Codebook = {},
				},
				ROUTE_Hill =
				{
					Weight = 3,
					ROUTE_Codebook = {},
				},
				ROUTE_Cellar1 =
				{
					Weight = 3,
					ROUTE_Cellar2 =
					{
						ROUTE_Cellar3 =
						{
							ROUTE_Code2 =
							{
								Weight = 3,
								ROUTE_Codebook = {},
							},
							ROUTE_Code1 =
							{
								ROUTE_Codebook = {},
							},
						},
					},
				},
			},
			ROUTE_BunkerSpawn4 =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_Codebook = {},
				},
				ROUTE_Hill =
				{
					Weight = 3,
					ROUTE_Codebook = {},
				},
				ROUTE_Cellar1 =
				{
					Weight = 3,
					ROUTE_Cellar2 =
					{
						ROUTE_Cellar3 =
						{
							ROUTE_Code2 =
							{
								Weight = 3,
								ROUTE_Codebook = {},
							},
							ROUTE_Code1 =
							{
								ROUTE_Codebook = {},
							},
						},
					},
				},
			},
		},
		ATTACK_a_fallback_top =
		{
			ROUTE_BunkerSpawn =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_r_wall_ladder =
					{
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge =
							{
								ROUTE_r_fallback_behind = { },
								ROUTE_r_fallback_top1 = { },
							},
						},
					},
				},
			},
			ROUTE_BunkerSpawn2 =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_r_wall_ladder =
					{
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge =
							{
								ROUTE_r_fallback_behind = { },
								ROUTE_r_fallback_top1 = { },
							},
						},
					},
				},
			},
			ROUTE_BunkerSpawn3 =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_r_wall_ladder =
					{
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge =
							{
								ROUTE_r_fallback_behind = { },
								ROUTE_r_fallback_top1 = { },
							},
						},
					},
				},
			},
			ROUTE_BunkerSpawn4 =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_r_wall_ladder =
					{
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge =
							{
								ROUTE_r_fallback_behind = { },
								ROUTE_r_fallback_top1 = { },
							},
						},
					},
				},
			},
			ROUTE_Bunker_Outside =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_r_wall_ladder =
					{
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge =
							{
								ROUTE_r_fallback_behind = { },
								ROUTE_r_fallback_top1 = { },
							},
						},
					},
				},
			},
		},
		MOUNTMG42_802 =
		{
			ROUTE_BunkerSpawn =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_r_wall_ladder =
					{
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge = { },
						},
					},
				},
			},
			ROUTE_BunkerSpawn2 =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_r_wall_ladder =
					{
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge = { },
						},
					},
				},
			},
			ROUTE_BunkerSpawn3 =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_r_wall_ladder =
					{
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge = { },
						},
					},
				},
			},
			ROUTE_BunkerSpawn4 =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_r_wall_ladder =
					{
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge = { },
						},
					},
				},
			},
			ROUTE_Bunker_Outside =
			{
				ROUTE_Wall_gap =
				{
					ROUTE_r_wall_ladder =
					{
						ROUTE_r_wall_top =
						{
							ROUTE_r_wall_bridge = { },
						},
					},
				},
			},
		},
		SNIPE_s_FallBack =
		{
			ROUTE_BunkerSpawn =
			{
				ROUTE_Cellar1 =
				{
					ROUTE_Cellar2 = { ROUTE_Cellar3 = { }, },
				},
			},
			ROUTE_BunkerSpawn2 =
			{
				ROUTE_Cellar1 =
				{
					ROUTE_Cellar2 = { ROUTE_Cellar3 = { }, },
				},
			},
			ROUTE_BunkerSpawn3 =
			{
				ROUTE_Cellar1 =
				{
					ROUTE_Cellar2 = { ROUTE_Cellar3 = { }, },
				},
			},
			ROUTE_BunkerSpawn4 =
			{
				ROUTE_Cellar1 =
				{
					ROUTE_Cellar2 = { ROUTE_Cellar3 = { }, },
				},
			},
		},
	};

	// Copy routes
	MapRoutes.PLANT_electric_fence.ROUTE_allied_spawn2 = MapRoutes.PLANT_electric_fence.ROUTE_allied_spawn;
	MapRoutes.PLANT_electric_fence.ROUTE_toilet = MapRoutes.PLANT_electric_fence.ROUTE_allied_spawn;
	MapRoutes.PLANT_east_fence = MapRoutes.PLANT_electric_fence;
	MapRoutes.BUILD_assault_ramp = MapRoutes.PLANT_east_fence;
	MapRoutes.GRENADE_lookout_mg = MapRoutes.PLANT_east_fence;
	MapRoutes.SMOKEBOMB_east_fence = MapRoutes.PLANT_east_fence;
	MapRoutes.SMOKEBOMB_electric_fence = MapRoutes.PLANT_east_fence;
	MapRoutes.BUILD_pile_of_crates = MapRoutes.CHECKPOINT_forward_spawn;
	MapRoutes.DEFEND_Fake = MapRoutes.BUILD_gate_control;
	MapRoutes.DEFEND_cp_control = MapRoutes.BUILD_gate_control;
	MapRoutes.ATTACK_at_fake = MapRoutes.BUILD_gate_control;
	MapRoutes.MOUNTMG42_799 = MapRoutes.MOUNTMG42_802;
	MapRoutes.DEFEND_d_fallback_topdoor = MapRoutes.MOUNTMG42_802;
	MapRoutes.DEFEND_d_fallback_topdoor = MapRoutes.MOUNTMG42_802;
	// *** END ROUTES ******************************************

	Util.UpdateSwitchData();
	Util.Routes(MapRoutes);
	Util.MapDebugPrint( "OnMapLoad" );
};

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 80.0;
	bot.MaxViewDistance = 1800.0;
	team = bot.GetTeam();
	class = bot.GetClass();

	//Change spawn at start
	if ( team == TEAM.AXIS )
	{
		if (Map.GamePhase == 0)
		{
			if ( RandInt(0,4) > 1)   // 60% Bunker, 40% Lookout
			{
				bot.ChangeSpawnPoint( 4 ); // Bunker
				Util.MapDebugPrint( "axisbot spawn 4" );
			}
			else
			{
				bot.ChangeSpawnPoint( 0 ); // forward spawn
				Util.MapDebugPrint( "axisbot spawn 0" );
			}
		}
		if (Map.GamePhase == 2)
		{
			bot.ChangeSpawnPoint( 3 ); // fallback
		}
	}

	//More distanceview for snipers
	yield();yield(); // wait two frames
	if ( bot.CanSnipe() )
	{
		bot.MaxViewDistance = 3000.0;
	}
};
