//==========================================================================================
//
//	mp_theriver_2nd.gm
//
//	Who      	When			What
//------------------------------------------------------------------------------------------
//	Qiki		25 November 2012	Initial Script
//	Native12	27.01.2013		Ready to test
//				04.02.2013		Added "OnTriggers" for Nitmod, correction in way.....
//
//	Associated files:	mp_theriver_2nd.way			05.02.2013	160 kB (163 840 b)
//						mp_theriver_2nd_goals.gm	05.02.2013	52 kB (53 248 b)
//
//==========================================================================================
//
//The strategy:
//at first - take over the station
//then - attack the castle and flag documents
//
//you can change it - right from the start attack the station
//and at the same time attack the castle and flag documents

global Map =
{
	Talk = true,
	talk = 1,
	DefendingTeam = TEAM.AXIS,
	AttackingTeam = TEAM.ALLIES,

	Bridge_Controls_Dyno = 0,
	Command_Post_Dyno = 0,
	Front_Wall_Dyno = 0,
	Tram_Engine_Panel_Dyno = 0,
	Allies_Inside = 0,
	AxisTruckSpawn = 0,

	First_Wall_exploded = false,
	Second_Wall_exploded = false,
	StationIsAllied = false,
	CastleFlagIsAllied = false,
	Document_taken = false,
	FrontWallDestroyed = false,
	BridgeControlsDestroyed = false,
	LiftIsUp = false,
	LiftIsUp1 = false,
	LiftIsDown = true,
	LiftGoesDown = false,
	LiftGoesUp = false,
	KT_Lift = 0,
	SecretDocumentsSecured = false,
	TramGoesToTheCastle = false,
	TramIsInTheCastle = false,
	TramIsInTheCastle1 = false,
	TramGoesToTheStation = false,
	TramIsInTheStation = true,
	EnginePanelBuilt = false,
	KT_tram = 0,
	Bots_inTram = 0,
	Bots_inLift = 0,
	Kill_BotsInTram = 0,
	Trigger_NearLowerSwitch2 = 0,
	Trigger_NearLowerSwitchIn2 = 0,

	Movers =
	{
		"MOVER_tram",
		"MOVER_lift",
	},

	Roles =
	{
		AXIS = // Team
		{
			AllBots = true,
			DEFENDER =
			{
				voice = "defend",
				spawnpt = 4,
				numbots = 1,
				crucialClass = CLASS.SOLDIER,	// first bot
				//MinBotsForRole = 4,             // only assign this role if there are already 4 bots in game
			},
			DEFENDER1 =
			{
				voice = "defend",
				spawnpt = 4,
				numbots = 1,
				crucialClass = CLASS.COVERTOPS,	// first bot
				//MinBotsForRole = 4,             // only assign this role if there are already 4 bots in game
			},
			DEFENDER2 =
			{
				voice = "defend",
				spawnpt = 4,
				numbots = 1,
				crucialClass = CLASS.MEDIC,	// first bot
				//MinBotsForRole = 4,             // only assign this role if there are already 4 bots in game
			},
		},
	},

	Navigation =
	{
		//  	/bot waypoint_setproperty paththrough Navigation_PT:wall1
		wall1 =
		{
			EvalFunc = function() // if this function returns false, navigation will not run
			{
				return !Map.First_Wall_exploded;
			},

			navigate = function(_this)
			{
				if ( Map.First_Wall_exploded )
				{
					yield();
					return;
				}

				_this.AddWeaponRequest(WEAPON.KNIFE);
				_this.AddAimRequest(Priority.High, "facing", Vector3(0.997480, -0.035686, -0.061321));

				while( !Map.First_Wall_exploded )
				{
					_this.Bot.HoldButton(BTN.ATTACK1, 1);
					yield();
				}

				_this.ReleaseAimRequest();
				_this.ReleaseWeaponRequest();
			},
		},

		//  	/bot waypoint_setproperty paththrough Navigation_PT:wall2
		wall2 =
		{
			gotowp = "waypointforgrenadewall2", // waypoint for the bot to go to before doing anything else
			EvalFunc = function() // if this function returns false, navigation will not run
			{
				return !Map.Second_Wall_exploded;
			},

			navigate = function(_this)
			{
				if ( Map.Second_Wall_exploded )
				{
					yield();
					return;
				}
				if ( _this.Bot.HasWeapon ( WEAPON.COLT ) )
				{
					_this.AddWeaponRequest(WEAPON.COLT);
				}
				else if ( _this.Bot.HasWeapon ( WEAPON.COLT_AKIMBO ) )
				{
					_this.AddWeaponRequest(WEAPON.COLT_AKIMBO);
				}
				else if ( _this.Bot.HasWeapon ( WEAPON.COLT_AKIMBO_SILENCED ) )
				{
					_this.AddWeaponRequest(WEAPON.COLT_AKIMBO_SILENCED);
				}
				else if ( _this.Bot.HasWeapon ( WEAPON.COLT_SILENCED ) )
				{
					_this.AddWeaponRequest(WEAPON.COLT_SILENCED);
				}

				_this.AddAimRequest(Priority.High, "facing", Vector3(0.524755,-0.846889,0.086084));

				Wp.SetWaypointFlag( "Cave", "closed", true );
				Wp.SetWaypointFlag( "Cave2", "closed", true );
				Wp.SetWaypointFlag( "Cave3", "closed", true );
				DynamicPathsUpdated();

				while( !Map.Second_Wall_exploded )
				{
					while ( _this.Bot.HasAmmo( ) and !Map.Second_Wall_exploded )
					{
						_this.Bot.HoldButton(BTN.ATTACK1, 1);
						yield();
					}
				}

				Wp.SetWaypointFlag( "Cave", "closed", false );
				Wp.SetWaypointFlag( "Cave2", "closed", false );
				Wp.SetWaypointFlag( "Cave3", "closed", false );
				DynamicPathsUpdated();
				_this.ReleaseAimRequest();
				_this.ReleaseWeaponRequest();
				sleep(0.5);
			},
		},

		//  	/bot waypoint_setproperty paththrough Navigation_PT:ladder
		ladder =
		{
			navigate = function(_this)
			{
				wpTable = {};
				Wp.GetWaypointByName("Ladder", wpTable);
				if ( _this.Goto(wpTable.position) == EVENT.PATH_SUCCESS )
				{
					_this.AddAimRequest(Priority.VeryHigh, "facing", wpTable.facing);
					sleep(0.5);
					_this.Bot.HoldButton(BTN.BACKWARD, 0.95);
					_this.Bot.HoldButton(BTN.CROUCH, 0.95);
					sleep(0.95);
					_this.AddAimRequest(Priority.VeryHigh, "facing", Vector3(-0.003247,0.364170,-0.931327));
					_this.Bot.HoldButton(BTN.CROUCH, 1);
					sleep(0.3);
					_this.Bot.HoldButton(BTN.FORWARD, 2.5);
					sleep(2.5);
				}
			},
		},

		//  	/bot waypoint_setproperty paththrough Navigation_PT:ladder_1
		ladder_1 =
		{
			navigate = function(_this)
			{
				wpTable = {};
				Wp.GetWaypointByName("Ladder_1", wpTable);
				if ( _this.Goto(wpTable.position) == EVENT.PATH_SUCCESS )
				{
					_this.AddAimRequest(Priority.VeryHigh, "facing", wpTable.facing);
					sleep(0.35);
					_this.Bot.HoldButton(BTN.FORWARD, 2.8);
					sleep(2.8);
				}
			},
		},

		//  	/bot waypoint_setproperty paththrough Navigation_PT:shelf_jump
		shelf_jump =
		{
			navigate = function(_this)
			{
				wpTable = {};
				Wp.GetWaypointByName("Shelf_jump", wpTable);
				if ( _this.Goto(wpTable.position) == EVENT.PATH_SUCCESS )
				{
					_this.AddAimRequest(Priority.VeryHigh, "facing", wpTable.facing);
					sleep(0.4);
					_this.Bot.HoldButton(BTN.FORWARD, 0.5);
					_this.Bot.HoldButton(BTN.JUMP, 0.5);
					sleep(0.5);
				}
			},
		},

		//  	/bot waypoint_setproperty paththrough Navigation_PT:wait_for_tram
		wait_for_tram =
		{
			gotowp = "wait_tram", // waypoint for the bot to go to before doing anything else
			EvalFunc = function() // if this function returns false, navigation will not run
			{
				if ( Map.TramIsInTheStation )
				{
					//print("^8navigate wait for tram - EVAL tram is in the station");
					return !Map.TramIsInTheStation;
				}
				else if ( Map.TramIsInTheCastle1 )
				{
					//print("^8navigate wait for tram - EVAL tram is in the castle");
					return !Map.TramIsInTheCastle1;
				}
				else
				{
					//print("^8navigate wait for tram - EVAL tram is moving");
					return true;
				}
			},

			navigate = function(_this)
			{
				if ( Map.TramGoesToTheCastle )
				{
					//print("^8navigate _this - TramGoesToTheCastle - bot is on waypoint wait_tram");
					while ( Map.TramGoesToTheCastle )
					{
						yield();
					}
					_this.AddAimRequest(Priority.High, "facing", Vector3(0.398204,-0.917259,0.008341));
					_this.Bot.HoldButton(BTN.FORWARD, 0.3);
					sleep(0.3);
					_this.ReleaseAimRequest();
				}
				if ( Map.TramGoesToTheStation )
				{
					//print("^8navigate _this - TramGoesToTheStation - bot is on waypoint wait_tram");
					while( Map.TramGoesToTheStation )
					{
						yield();
					}
					_this.AddAimRequest(Priority.High, "facing", Vector3(0.398204,-0.917259,0.008341));
					_this.Bot.HoldButton(BTN.FORWARD, 0.3);
					sleep(0.3);
					_this.ReleaseAimRequest();
				}

			},
		},

		//  	/bot waypoint_setproperty paththrough Navigation_PT:wait_way_to_castle
		wait_way_to_castle =
		{
			gotowp = "wait_way", // waypoint for the bot to go to before doing anything else
			navigate = function(_this)
			{
				//print("^8bot is going thru waypoint wait way");
				if ( Map.Bots_inTram > 1 )
				{
					//print("^8run second tram navigate");
					_this.AddAimRequest(Priority.High, "facing", Vector3(0.276696,-0.959989,-0.043130));
					_this.Bot.HoldButton(BTN.WALK, 0.7);
					_this.Bot.HoldButton(BTN.FORWARD, 0.7);

					yield();

					_this.Bot.HoldButton(BTN.WALK, 24);
					_this.Bot.HoldButton(BTN.FORWARD, 25);

					sleep(25);
				}
				else if ( Map.Bots_inTram == 1 )
				{
					//print("^8run first tram navigate");
				}
				else if ( Map.Bots_inTram == 0 )
				{
					//print("^8bad tram navigate");
				}
			},
		},

		//  	/bot waypoint_setproperty paththrough Navigation_PT:wait_for_lift
		wait_for_lift =
		{
			gotowp = "wait", // waypoint for the bot to go to before doing anything else
			EvalFunc = function() // if this function returns false, navigation will not run
			{
				if ( Map.LiftIsDown )
				{
					//print("^8navigate wait for lift - EVAL lift is down");
					return !Map.LiftIsDown;
				}
				else if ( Map.LiftIsUp1 )
				{
					//print("^8navigate wait for lift - EVAL lift is up");
					return !Map.LiftIsUp1;
				}
				else
				{
					//print("^8navigate wait for lift - EVAL lift is moving");
					return true;
				}
			},

			navigate = function(_this)
			{
				if ( Map.LiftGoesUp )
				{
					//print("^8navigate _this - LiftGoesUp - bot is on waypoint wait");
					while ( Map.LiftGoesUp )
					{
						yield();
					}
					yield();
					_this.AddAimRequest(Priority.High, "facing", Vector3(-0.244867,-0.958821,0.143885));
					_this.Bot.HoldButton(BTN.WALK, 0.3);
					_this.Bot.HoldButton(BTN.FORWARD, 0.3);
					sleep(0.3);
					_this.ReleaseAimRequest();
				}
				if ( Map.LiftGoesDown )
				{
					//print("^8navigate _this - LiftGoesDown - bot is on waypoint wait");
					while( Map.LiftGoesDown )
					{
						yield();
					}
					yield();
					_this.AddAimRequest(Priority.High, "facing", Vector3(-0.244867,-0.958821,0.143885));
					_this.Bot.HoldButton(BTN.WALK, 0.3);
					_this.Bot.HoldButton(BTN.FORWARD, 0.3);
					sleep(0.3);
					_this.ReleaseAimRequest();
				}

			},
		},

		//  	/bot waypoint_setproperty paththrough Navigation_PT:wait_waypoint_lift
		wait_waypoint_lift =
		{
			gotowp = "waitwaypointlift", // waypoint for the bot to go to before doing anything else
			navigate = function(_this)
			{
				//print("^8bot is going thru waypoint waitwaypointlift");
				if ( Map.Bots_inLift > 1 )
				{
					//print("^8run second lift navigate");
					_this.AddAimRequest(Priority.High, "facing", Vector3(-0.158195,-0.983781,0.084555));
					_this.Bot.HoldButton(BTN.WALK, 5);
					_this.Bot.HoldButton(BTN.FORWARD, 5);
					sleep(5);
				}
				else if ( Map.Bots_inLift == 1 )
				{
					//print("^8run first lift navigate");
				}
				else if ( Map.Bots_inLift == 0 )
				{
					//print("^8bad navigate");
				}
			},
		},
	},

	Lift_Down_bb =
	{
		Name = "Lift_Down_bb",
		TriggerOnEntity = GetGoal("MOVER_lift").GetEntity(),
		OnEnter = function(ent)
		{
			Map.LiftIsDown = true;
			Map.LiftGoesDown = false;
			DynamicPathsUpdated();

			BotsInLift = OnTriggerRegion(AABB(1125.911,-4664.875,1105.125,1185.875,-4525,1115.125), Map.Bots_In_Lift );
			BotsInLift1 = OnTriggerRegion(AABB(1186,-4664.875,1105.125,1268.875,-4563.141,1115.125), Map.Bots_In_Lift );

			DeleteTriggerRegion( Map.Trigger_NearLowerSwitch2 );

			Map.Switches.nearlowerswitch_inside.Enabled = true;

			Util.MapDebugPrint( "^8Lift is down" );

			sleep(0.1);
			DeleteTriggerRegion( Map.KT_Lift );
			Map.Bots_inLift = 0;

			Map.Trigger_NearLowerSwitchIn2 = OnTriggerRegion(AABB(1220,-4520.875,1105.125,1268.875,-4448.725,1463.890), RegionTrigger.DisableBotPush );

			Util.MapDebugPrint( "^8Kill trigger deleted" );
		},
		OnExit = function(ent)
		{
			Map.LiftIsDown = false;
			Map.LiftGoesUp = true;
			DynamicPathsUpdated();

			Map.Switches.nearlowerswitch_inside.Enabled = false;

			Util.MapDebugPrint( "^8Lift goes up" );

			sleep(1.5);

			DeleteTriggerRegion( "Bots_In_Lift" );

			if ( Map.Bots_inLift > 0 )
			{
				Map.Bots_inLift = 0;

				//print("^8Bots in lift = 0");
			}

			sleep(1);

			Map.KT_Lift = OnTriggerRegion(AABB(1119.125,-4664.875,1089.125,1272.875,-4559.222,1131.125), RegionTrigger.KillTrigger );

			Util.MapDebugPrint( "^8Kill trigger created" );
		},
	},

	Lift_Up_bb =
	{
		Name = "Lift_Up_bb",
		TriggerOnEntity = GetGoal("MOVER_lift").GetEntity(),
		OnEnter = function(ent)
		{
			Map.LiftIsUp = true;
			DynamicPathsUpdated();

			Util.MapDebugPrint( "^8Lift is up" );

			DeleteTriggerRegion( Map.Trigger_NearLowerSwitchIn2 );

			Map.Trigger_NearLowerSwitch2 = OnTriggerRegion(AABB(1132.558,-4447.840,1105.125,1268.875,-4355.785,1140.125), RegionTrigger.DisableBotPush );

			sleep(2);	//waiting for leaving lift

			Map.LiftIsUp1 = true;
			Map.LiftGoesUp = false;

			Map.Switches.nearlowerswitch.Enabled = true;
		},
		OnExit = function(ent)
		{
			Map.LiftIsUp = false;
			Map.LiftIsUp1 = false;
			Map.LiftGoesDown = true;
			DynamicPathsUpdated();

			Util.MapDebugPrint( "^8Lift goes down" );

			Map.Switches.nearlowerswitch.Enabled = false;
		},

	},

	Bots_In_Lift =
	{
		Name = "Bots_In_Lift",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			Map.Bots_inLift += 1;

			//print("^8Bot entered the lift");

			sleep(4);

			if ( !Map.LiftGoesUp and Map.Bots_inLift > 0 )
			{
				Map.Bots_inLift = 0;

				//print("^8Bots in lift = 0 by trigger");
			}
		},
	},

	Switches =
	{
		//////////////////////
		//Lift switches

		//  	/bot waypoint_setproperty paththrough UseSwitch_PT:nearlowerswitch
		nearlowerswitch =
		{
			WaypointName = "lower_switch_out",
			Enabled = false,	//on the start of map is disabled
			LimitBots = 1,
			//	/bot aim_pos
			AimPosition = Vec3(1267.875, -4423.012, 1165.720),
			Priority = 0,

			ExitConditions =
			{
				f = function(bot)
				{
					return Map.LiftGoesDown;
				}
			},
			Wait = function()
			{
				return Map.LiftIsDown;
			},

		},

		//  	/bot waypoint_setproperty paththrough UseSwitch_PT:nearlowerswitch_inside
		nearlowerswitch_inside =
		{
			WaypointName = "lower_switch_in",
			Enabled = true,	//on the start of map is enabled
			LimitBots = 1,
			//	/bot aim_pos
			AimPosition = Vec3(1267.875, -4425.615, 1166.230),
			Priority = 0,

			ExitConditions =
			{
				f = function(bot)
				{
					return LiftGoesUp;
				}
			},
			Wait = function()
			{
				return Map.LiftIsUp;
			},

		},

		//////////////////////
		//Tram switches

		//  	/bot waypoint_setproperty paththrough UseSwitch_PT:call_tram_to_station
		call_tram_to_station =
		{
			WaypointName = "station_call_tram_out",
			Enabled = false,	//on the start of map is disabled
			LimitBots = 1,
			//	/bot aim_pos
			AimPosition = Vec3(-280.148, 1448.125, 1396.310),
			Priority = 0,

			ExitConditions =
			{
				f = function(bot)
				{
					return Map.TramGoesToTheStation;
				}
			},
			Wait = function()
			{
				return Map.TramIsInTheStation;
			},

		},

		//  	/bot waypoint_setproperty paththrough UseSwitch_PT:call_tram_out_of_station
		call_tram_out_of_station =
		{
			WaypointName = "station_call_tram_in",
			Enabled = false,	//on the start of map is disabled
			LimitBots = 1,
			//	/bot aim_pos
			AimPosition = Vec3(-263.875, 1447.230, 1398.920),
			Priority = 0,

			ExitConditions =
			{
				f = function(bot)
				{
					return Map.TramGoesToTheCastle;
				}
			},

			Wait = function()
			{
				return Map.TramIsInTheCastle;
			},

		},
	},

	Axis_TruckSpawn =
	{
		Name = "Axis_TruckSpawn",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			if( GetEntTeam(ent) == TEAM.AXIS )
			{
				if( GetEntClass(ent) == CLASS.FIELDOPS )
				{
					Map.AxisTruckSpawn += 1;

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

					SetAvailableMapGoals( TEAM.AXIS, true, "CALLARTILLERY_Axis_Start_01" );
				}
			}
		},
		OnExit = function(ent)
		{
			if( GetEntTeam(ent) == TEAM.AXIS )
			{
				if( GetEntClass(ent) == CLASS.FIELDOPS )
				{
					Map.AxisTruckSpawn -= 1;

					if ( Map.AxisTruckSpawn == 0 )
					{
						SetAvailableMapGoals( TEAM.AXIS, false, "CALLARTILLERY_Axis_Start_01" );

						if ( !Map.StationIsAllied and !Map.CastleFlagIsAllied )
						{
							SetAvailableMapGoals( TEAM.AXIS, true, "CALLARTILLERY_Axis_Station_13" );
						}
					}
				}
			}
		},
	},

	Wall_1_exploded = function( trigger )
	{

		Map.First_Wall_exploded = true;

		if ( !Map.CastleFlagIsAllied and !Map.StationIsAllied )
		{
			SetGoalPriority( "DEFEND_Axis_Station_03", 0.52, TEAM.AXIS, 0 );
			SetGoalPriority( "DEFEND_Axis_Station_04", 0.52, TEAM.AXIS, 0 );
			SetGoalPriority( "DEFEND_Axis_Station_09", 0.53, TEAM.AXIS, 0 );
			SetGoalPriority( "DEFEND_Axis_Station_12", 0.53, TEAM.AXIS, 0 );
			SetGoalPriority( "DEFEND_Axis_Station_16", 0.53, TEAM.AXIS, 0 );
		}

		Util.MapDebugPrint( "^8Wall_1_exploded" );
	},

	Wall_2_exploded = function( trigger )
	{

		Map.Second_Wall_exploded = true;

		Wp.SetWaypointFlag( "waypointforgrenadewall2", "closed", true );
		DynamicPathsUpdated();

		Util.MapDebugPrint( "^8Wall_2_exploded" );
	},

	Wooden_Door_Exploded = function( trigger )
	{

		if ( !Map.CastleFlagIsAllied and !Map.StationIsAllied )
		{
			SetGoalPriority( "DEFEND_Axis_Station_03", 0.52, TEAM.AXIS, 0 );
			SetGoalPriority( "DEFEND_Axis_Station_04", 0.52, TEAM.AXIS, 0 );
			SetGoalPriority( "DEFEND_Axis_Station_09", 0.53, TEAM.AXIS, 0 );
			SetGoalPriority( "DEFEND_Axis_Station_12", 0.53, TEAM.AXIS, 0 );
			SetGoalPriority( "DEFEND_Axis_Station_16", 0.53, TEAM.AXIS, 0 );
		}

		Util.MapDebugPrint( "^8Wooden_Door_Exploded" );
	},

	Tram_Engine_Panel_Built = function( trigger )
	{

		Map.StationIsAllied = true;
		Map.EnginePanelBuilt = true;

		ClearGoalRole( "MOBILEMG42_Axis_Documents_01", ROLE.DEFENDER);
		ClearGoalRole( "DEFEND_Axis_Documents_02", ROLE.DEFENDER1);
		ClearGoalRole( "DEFEND_Axis_Documents_03", ROLE.DEFENDER2);

		SetGoalPriority( "DEFEND_Axis_Documents_02", 0.51, TEAM.AXIS, CLASS.COVERTOPS );
		SetGoalPriority( "DEFEND_Axis_Documents_03", 0.51, TEAM.AXIS, CLASS.MEDIC );

		SetGoalPriority( "BUILD_Tram_Engine_Panel", 0.8, TEAM.ALLIES, 0 );	//one of routes, but not so important

		SetAvailableMapGoals( TEAM.AXIS, false, {
			".*_Axis_Start_.*",
			".*_Axis_Station_.*",
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"BUILD_Tram_Engine_Panel",
			".*_Allies_Station_.*",
		});

		if ( Map.TramIsInTheCastle1 )
		{
			Map.Switches.call_tram_to_station.Enabled = true;
		}

		if ( Map.TramIsInTheStation )
		{
			Map.Switches.call_tram_out_of_station.Enabled = true;
		}

		if ( !Map.Document_taken )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"AMMOCAB_cabinet_ammo_model",
				"AMMOCAB_cabinet_ammo_model2",
				"HEALTHCAB_cabinet_health_model",
				".*_Axis_Documents_.*",
				"DEFEND_Axis_Castle_.*",
				"BUILD_Command_Post",
				"PLANT_Tram_Engine_Panel",
			});

			SetAvailableMapGoals( TEAM.ALLIES, true, {
				"AMMOCAB_cabinet_ammo_model",
				"AMMOCAB_cabinet_ammo_model2",
				"HEALTHCAB_cabinet_health_model",
				"BUILD_Command_Post",
				"FLAG_Secret_Documents",
			});
		}

		if ( !Map.CastleFlagIsAllied )
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_spawnbridge_flag" );
		}

		if ( !Map.BridgeControlsDestroyed )
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Bridge_Controls" );
		}

		Util.MapDebugPrint( "^8Tram_Engine_Panel_Built" );

		sleep(3);

		Wp.SetWaypointFlag( "wait_tram", "closed", false );
		DynamicPathsUpdated();

		Util.EnableGoal ("ROUTE_Tram1");
		Util.EnableGoal ("ROUTE_Tram2");

		sleep(7);

		Wp.SetWaypointFlag( "waypointforgrenadewall2", "closed", true );
		Wp.SetWaypointFlag( "aa", "closed", true );
		Wp.SetWaypointFlag( "b", "closed", true );
		Wp.SetWaypointFlag( "c", "closed", true );
		Wp.SetWaypointFlag( "d", "closed", true );
		DynamicPathsUpdated();

		RegionTrigger.Create(AABB(-573.127,2480.719,1037.125,379.374,2882.623,1272.769), "KillTrigger", "Bad_place_for_bots");
	},

	Tram_Engine_Panel_Planted = function( trigger )
	{

		Map.Tram_Engine_Panel_Dyno += 1;

		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFUSE_Tram_Engine_Panel_.*" );

		Util.MapDebugPrint( "^8Tram_Engine_Panel_Planted" );
	},

	Tram_Engine_Panel_Defused = function( trigger )
	{

		Map.Tram_Engine_Panel_Dyno -= 1;

		Util.MapDebugPrint( "^8Tram_Engine_Panel_Defused" );
	},

	Tram_Engine_Panel_Destroyed = function( trigger )
	{

		Map.Tram_Engine_Panel_Dyno = 0;
		Map.EnginePanelBuilt = false;

		Map.Switches.call_tram_to_station.Enabled = false;
		Map.Switches.call_tram_out_of_station.Enabled = false;

		Util.DisableGoal ("ROUTE_Tram1");
		Util.DisableGoal ("ROUTE_Tram2");

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

		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tram_Engine_Panel" );

		Util.MapDebugPrint( "^8Tram_Engine_Panel_Destroyed" );
	},

	TramSwitchT_goto = function( trigger )
	{

		vel = ToVector(trigger.Action);

		if ( vel[ 0 ] < 0 )
		{
			Map.Switches.call_tram_out_of_station.Enabled = false;

			Map.TramIsInTheStation = false;
			Map.TramGoesToTheCastle = true;

			Util.MapDebugPrint( "^8Tram goes to the Castle" );

			sleep(4);

			if ( Map.Bots_inTram > 0 )
			{
				Map.Bots_inTram = 0;

				//print("^8Bots in tram = 0");
			}
		}

		if ( vel[ 0 ] > 0 )
		{
			Map.TramGoesToTheStation = false;
			Map.TramIsInTheStation = true;

			if ( Map.EnginePanelBuilt )
			{
				Map.Switches.call_tram_out_of_station.Enabled = true;
			}

			Util.MapDebugPrint( "^8Tram is in the Station" );

			DeleteTriggerRegion( Map.KT_tram );

			Util.MapDebugPrint( "^8Delete killtrigger under tram" );
		}
	},

	TramSwitchC_goto = function( trigger )
	{

		vel = ToVector(trigger.Action);

		if ( vel[ 0 ] == 0 )
		{
			Map.TramIsInTheCastle = true;

			Util.MapDebugPrint( "^8Tram is in the Castle" );

			sleep(3);	//waiting for leaving tram

			Map.TramGoesToTheCastle = false;
			Map.TramIsInTheCastle1 = true;

			if ( Map.EnginePanelBuilt )
			{
				Map.Switches.call_tram_to_station.Enabled = true;
			}
		}

		if ( vel[ 0 ] < -14.90 )
		{
			Map.TramIsInTheCastle = true;

			Util.MapDebugPrint( "^8Tram is in the Castle" );

			sleep(3);	//waiting for leaving tram

			Map.TramGoesToTheCastle = false;
			Map.TramIsInTheCastle1 = true;

			if ( Map.EnginePanelBuilt )
			{
				Map.Switches.call_tram_to_station.Enabled = true;
			}
		}

		if ( vel[ 0 ] > 0 )
		{
			Map.Switches.call_tram_to_station.Enabled = false;

			Map.TramIsInTheCastle = false;
			Map.TramIsInTheCastle1 = false;
			Map.TramGoesToTheStation = true;

			Util.MapDebugPrint( "^8Tram goes to the Station" );
		}
	},

	Tram_goto = function( trigger )
	{

		vel = ToVector(trigger.Action);

		if ( vel[ 1 ] == -250 )
		{
			Map.KT_tram = OnTriggerRegion(AABB(-245.239,1476.343,1129.125,-86.909,1681.402,1326.997), RegionTrigger.KillTrigger );

			Util.MapDebugPrint( "^8Create killtrigger under tram" );
		}
	},

	TramIn_Station =
	{
		Name = "TramIn_Station",
		TriggerOnEntity = GetGoal("MOVER_tram").GetEntity(),
		OnEnter = function(ent)
		{
			BotsInTram = OnTriggerRegion(AABB(-156,1420.395,1345.125,-71.296,1656.152,1419.125), Map.Bots_In_Tram );
			Util.MapDebugPrint( "^8Create trigger BotsInTram" );
			Map.Kill_BotsInTram = OnTriggerRegion(AABB(-168.556,1420.395,1345.125,-71.296,1656.152,1419.125), RegionTrigger.KillTrigger );
			Util.MapDebugPrint( "^8Create killtrigger Kill_BotsInTram" );
			sleep(0.2);
			Map.Bots_inTram = 0;
			DeleteTriggerRegion( Map.Kill_BotsInTram );
			Util.MapDebugPrint( "^8Delete killtrigger Kill_BotsInTram" );
		},
		OnExit = function(ent)
		{
			DeleteTriggerRegion( "Bots_In_Tram" );
			sleep(2);
			if ( Map.Bots_inTram > 0 )
			{
				Map.Bots_inTram = 0;
				//print("^8Bots in tram = 0 by tram entity");
			}
		},

	},

	Bots_In_Tram =
	{
		Name = "Bots_In_Tram",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			Map.Bots_inTram += 1;

			//print("^8Bot entered the tram");

			if ( Map.Bots_inTram == 1 )
			{
				sleep(4);

				if ( !Map.TramGoesToTheCastle and Map.Bots_inTram > 0 )
				{
					Map.Kill_BotsInTram = OnTriggerRegion(AABB(-168.556,1420.395,1345.125,-71.296,1656.152,1419.125), RegionTrigger.KillTrigger );
					sleep(0.5);
					Map.Bots_inTram = 0;

					//print("^8Bots in tram = 0 by trigger");
				}
				yield();

				DeleteTriggerRegion( Map.Kill_BotsInTram );
			}
		},
		OnExit = function(ent)
		{
			//Map.Bots_inTram -= 1;

			//print("^8Decrease number of bots in trigger");
		},
	},

	Front_Wall_Planted = function( trigger )
	{

		Map.Front_Wall_Dyno += 1;

		if ( Map.Document_taken )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFUSE_Front_Wall_.*" );
		}

		Util.MapDebugPrint( "^8Front_Wall_Planted" );
	},

	Front_Wall_Defused = function( trigger )
	{

		Map.Front_Wall_Dyno -= 1;

		Util.MapDebugPrint( "^8Front_Wall_Defused" );
	},

	Front_Wall_Destroyed = function( trigger )
	{

		Util.EnableGoal ("ROUTE_Front_Wall");
		Util.EnableGoal ("ROUTE_Near_Boxes");

		if ( Map.Front_Wall_Dyno > 0 )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFUSE_Front_Wall_.*" );
		}

		Map.Front_Wall_Dyno = 0;
		Map.FrontWallDestroyed = true;

		Wp.SetWaypointFlag( "Front_Wall", "jump", true );

		Util.MapDebugPrint( "^8Front_Wall_Destroyed" );
	},

	spawnbridge_flag_Allies_Captured = function( trigger )
	{

		Map.CastleFlagIsAllied = true;

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

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

		if ( !Map.StationIsAllied )
		{
			Util.ChangeSpawn( TEAM.AXIS, 4 );

			SetAvailableMapGoals( TEAM.AXIS, false, {
				".*_Axis_Start_.*",
				".*_Axis_Station_.*",
			});

			//SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tram_Engine_Panel" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_Allies_Station_.*" );

			if ( !Map.Document_taken )
			{
				SetAvailableMapGoals( TEAM.AXIS, true, {
					"AMMOCAB_cabinet_ammo_model",
					"AMMOCAB_cabinet_ammo_model2",
					"HEALTHCAB_cabinet_health_model",
					".*_Axis_Documents_.*",
					"DEFEND_Axis_Castle_.*",
				});

				SetAvailableMapGoals( TEAM.ALLIES, true, {
					"AMMOCAB_cabinet_ammo_model",
					"AMMOCAB_cabinet_ammo_model2",
					"HEALTHCAB_cabinet_health_model",
					"FLAG_Secret_Documents",
				});

				if ( !Map.BridgeControlsDestroyed )
				{
					SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Bridge_Controls" );
				}
			}
		}

		Util.MapDebugPrint( "^8spawnbridge_flag_Allies_Captured" );
	},

	spawnbridge_flag_Axis_Captured = function( trigger )
	{

		Map.CastleFlagIsAllied = false;

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

		if ( !Map.StationIsAllied )
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tram_Engine_Panel" );

			if ( Map.Allies_Inside == 0 )
			{
				if ( !Map.Document_taken )
				{
					SetAvailableMapGoals( TEAM.ALLIES, false, "FLAG_Secret_Documents" );
				}

				Util.ChangeSpawn( TEAM.AXIS, 0 );

				SetAvailableMapGoals( TEAM.AXIS, false, {
					"AMMOCAB_cabinet_ammo_model",
					"AMMOCAB_cabinet_ammo_model2",
					"HEALTHCAB_cabinet_health_model",
					".*_Axis_Documents_.*",
					"DEFEND_Axis_Castle_.*",
				});

				SetAvailableMapGoals( TEAM.ALLIES, false, {
					"AMMOCAB_cabinet_ammo_model",
					"AMMOCAB_cabinet_ammo_model2",
					"HEALTHCAB_cabinet_health_model",
				});

				if ( !Map.BridgeControlsDestroyed )
				{
					SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Bridge_Controls" );
				}

				SetAvailableMapGoals( TEAM.AXIS, true, {
					"ARTILLERY_S_Axis_Start_02",
					"DEFEND_Axis_Station_.*",
					"MOBILEMG42_Axis_Station_.*",
				});

				SetAvailableMapGoals( TEAM.ALLIES, true, {
					"BUILD_Tram_Engine_Panel",
					"ATTACK_Allies_Station_.*",
				});
			}
			else
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_spawnbridge_flag" );
			}
		}
		else
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_spawnbridge_flag" );
		}

		Util.MapDebugPrint( "^8spawnbridge_flag_Axis_Captured" );
	},

	Bridge_Controls_Planted = function( trigger )
	{

		Map.Bridge_Controls_Dyno += 1;

		if ( Map.Document_taken )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFUSE_Bridge_Controls_.*" );
		}

		Util.MapDebugPrint( "^8Bridge_Controls_Planted" );
	},

	Bridge_Controls_Defused = function( trigger )
	{

		Map.Bridge_Controls_Dyno -= 1;

		Util.MapDebugPrint( "^8Bridge_Controls_Defused" );
	},

	Bridge_Controls_Destroyed = function( trigger )
	{

		Util.EnableGoal ("ROUTE_Past_WoodenBridge");

		if ( Map.Bridge_Controls_Dyno > 0 )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFUSE_Bridge_Controls_.*" );
		}

		Map.Bridge_Controls_Dyno = 0;
		Map.BridgeControlsDestroyed = true;

		Util.MapDebugPrint( "^8Bridge_Controls_Destroyed" );
	},

	Secret_Documents_Taken = function( trigger )
	{

		Map.Document_taken = true;

		SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_Truck" );

		if ( Map.Bridge_Controls_Dyno > 0 and !Map.BridgeControlsDestroyed )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFUSE_Bridge_Controls_.*" );
		}

		if ( Map.Front_Wall_Dyno > 0 and !Map.FrontWallDestroyed )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFUSE_Front_Wall_.*" );
		}

		Util.MapDebugPrint( "^8Secret_Documents_Taken" );

		sleep(2);

		if ( Map.Document_taken )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, ".*_Axis_Documents_.*" );

			SetAvailableMapGoals( TEAM.AXIS, true, {
				"ATTACK_Road_to_Truck_.*",
				"MOUNTMG42_Front",
				"MOUNTMG42_Side",
			});

			SetAvailableMapGoals( TEAM.ALLIES, true, {
				"ATTACK_Road_to_Truck_.*",
				"REPAIRMG42_.*",
				"MOUNTMG42_Front",
				"MOUNTMG42_Side",
			});
		}

		sleep(10);

		if ( Map.Document_taken )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Axis_Castle_.*" );
		}
	},

	Secret_Documents_Returned = function( trigger )
	{

		Map.Document_taken = false;

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"ATTACK_Road_to_Truck_.*",
			"MOUNTMG42_Front",
			"MOUNTMG42_Side",
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"CAPPOINT_Truck",
			"ATTACK_Road_to_Truck_.*",
			"REPAIRMG42_.*",
			"MOUNTMG42_Front",
			"MOUNTMG42_Side",
		});

		if ( Map.Allies_Inside == 0 )
		{
			if ( Map.StationIsAllied or Map.CastleFlagIsAllied )
			{
				SetAvailableMapGoals( TEAM.AXIS, true, {
					".*_Axis_Documents_.*",
					"DEFEND_Axis_Castle_.*",
				});
			}
			else
			{
				SetAvailableMapGoals( TEAM.AXIS, true, {
					".*_Axis_Start_.*",
					"DEFEND_Axis_Station_.*",
					"MOBILEMG42_Axis_Station_.*",
				});

				if ( !Map.FrontWallDestroyed )
				{
					SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Front_Wall" );
				}

				SetAvailableMapGoals( TEAM.ALLIES, true, {
					"BUILD_Tram_Engine_Panel",
					"ATTACK_Allies_Station_.*",
				});
			}
		}
		else
		{
			SetAvailableMapGoals( TEAM.AXIS, true, {
				".*_Axis_Documents_.*",
				"DEFEND_Axis_Castle_.*",
			});
		}

		if ( Map.Bridge_Controls_Dyno > 0 and !Map.BridgeControlsDestroyed )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, "DEFUSE_Bridge_Controls_.*" );
		}

		if ( Map.Front_Wall_Dyno > 0 and !Map.FrontWallDestroyed )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, "DEFUSE_Front_Wall_.*" );
		}

		Util.MapDebugPrint( "^8Secret_Documents_Returned" );
	},

	Secret_Documents_Secured = function( trigger )
	{

		Map.SecretDocumentsSecured = true;

		sleep(1);
		ETUtil.WinningChat( TEAM.ALLIES );
		sleep(1.5);
		ETUtil.LosingChat( TEAM.AXIS );

		Util.MapDebugPrint( "^8Secret_Documents_Secured" );
	},

	Axis_CP_Built = function( trigger )
	{

		Util.DisableGoal( "BUILD_Command_Post" );

		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Command_Post" );

		Util.MapDebugPrint( "^8Axis_CP_Built" );
	},

	Allied_CP_Built = function( trigger )
	{

		Util.DisableGoal( "BUILD_Command_Post" );

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

		Util.MapDebugPrint( "^8Allied_CP_Built" );
	},

	Command_Post_Planted = function( trigger )
	{

		Map.Command_Post_Dyno += 1;

		Util.DisableGoal( "DEFUSE_Command_Post_.*" );

		Util.MapDebugPrint( "^8Command_Post_Planted" );
	},

	Command_Post_Defused = function( trigger )
	{

		Map.Command_Post_Dyno -= 1;

		Util.MapDebugPrint( "^8Command_Post_Defused" );
	},

	Axis_CP_Destroyed = function( trigger )
	{

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

		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Command_Post" );

		Util.MapDebugPrint( "^8Axis_CP_Destroyed" );
	},

	Allied_CP_Destroyed = function( trigger )
	{

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

		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Command_Post" );

		Util.MapDebugPrint( "^8Allied_CP_Destroyed" );
	},

	AlliesInsideCastle =
	{
		Name = "AlliesInsideCastle",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			if( GetEntTeam(ent) == TEAM.ALLIES )
			{
				Map.Allies_Inside += 1;

				if ( Map.Allies_Inside == 1 )
				{
					Util.MapDebugPrint( "^8Allies entered into the Castle" );
				}

				if ( !Map.Document_taken )
				{
					if ( !Map.StationIsAllied )
					{
						if ( !Map.CastleFlagIsAllied )
						{
							if ( Server.Team[ TEAM.AXIS ].NumPlayers < 5 )
							{
								SetAvailableMapGoals( TEAM.AXIS, false, {
									".*_Axis_Start_.*",
									".*_Axis_Station_.*",
								});

								SetAvailableMapGoals( TEAM.AXIS, true, {
									"AMMOCAB_cabinet_ammo_model",
									"AMMOCAB_cabinet_ammo_model2",
									"HEALTHCAB_cabinet_health_model",
									".*_Axis_Documents_.*",
									"DEFEND_Axis_Castle_.*",
								});

								if ( Map.Allies_Inside == 1 )
								{
									ETUtil.SuicideSpawn( TEAM.AXIS, 4, -1, 0 );
								}

								Util.ChangeSpawn( TEAM.AXIS, 4 );
							}
							else
							{
								if ( Map.Allies_Inside < 4 )
								{
									if ( Map.Allies_Inside == 1 )
									{
										SetGoalRole("MOBILEMG42_Axis_Documents_01", ROLE.DEFENDER);
										SetGoalRole("DEFEND_Axis_Documents_02", ROLE.DEFENDER1);
										SetGoalRole("DEFEND_Axis_Documents_03", ROLE.DEFENDER2);

										Util.ChangeSpawnForRole(TEAM.AXIS, ROLE.DEFENDER, 4);
										Util.ChangeSpawnForRole(TEAM.AXIS, ROLE.DEFENDER1, 4);
										Util.ChangeSpawnForRole(TEAM.AXIS, ROLE.DEFENDER2, 4);

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

										SetAvailableMapGoals( TEAM.AXIS, true, {
											"MOBILEMG42_Axis_Documents_01",
											"DEFEND_Axis_Documents_02",
											"DEFEND_Axis_Documents_03",
											"DEFEND_Axis_Documents_04",
										});

										ETUtil.SuicideSpawn( TEAM.AXIS, 4, 1, CLASS.SOLDIER );
										ETUtil.SuicideSpawn( TEAM.AXIS, 4, -1, CLASS.COVERTOPS );
										ETUtil.SuicideSpawn( TEAM.AXIS, 4, 1, CLASS.MEDIC );
									}
								}
								else
								{
									if ( Map.Allies_Inside == 4 )
									{
										ETUtil.SuicideSpawn( TEAM.AXIS, 4, -1, 0 );	//need test it
										//ETUtil.SuicideSpawn( TEAM.AXIS, 4, -1, CLASS.MEDIC );
										//ETUtil.SuicideSpawn( TEAM.AXIS, 4, -1, CLASS.FIELDOPS );
									}

									SetAvailableMapGoals( TEAM.AXIS, false, {
										".*_Axis_Start_.*",
										".*_Axis_Station_.*",
									});

									SetAvailableMapGoals( TEAM.AXIS, true, {
										"AMMOCAB_cabinet_ammo_model",
										"AMMOCAB_cabinet_ammo_model2",
										"HEALTHCAB_cabinet_health_model",
										".*_Axis_Documents_.*",
										"DEFEND_Axis_Castle_.*",
									});

									Util.ChangeSpawn( TEAM.AXIS, 4 );
								}
							}
						}
					}
				}
			}
		},
		OnExit = function(ent)
		{
			if( GetEntTeam(ent) == TEAM.ALLIES )
			{
				Map.Allies_Inside -= 1;

				if ( Map.Allies_Inside == 0 )
				{
					Util.MapDebugPrint( "^8Castle is safe" );

					if ( !Map.StationIsAllied )
					{
						if ( !Map.CastleFlagIsAllied )
						{
							ClearGoalRole( "MOBILEMG42_Axis_Documents_01", ROLE.DEFENDER);
							ClearGoalRole( "DEFEND_Axis_Documents_02", ROLE.DEFENDER1);
							ClearGoalRole( "DEFEND_Axis_Documents_03", ROLE.DEFENDER2);

							Util.ChangeSpawn( TEAM.AXIS, 0 );

							if ( !Map.Document_taken )
							{
								SetAvailableMapGoals( TEAM.ALLIES, false, "FLAG_Secret_Documents" );

								SetAvailableMapGoals( TEAM.AXIS, true, {
									"ARTILLERY_S_Axis_Start_02",
									"DEFEND_Axis_Station_.*",
									"MOBILEMG42_Axis_Station_.*",
								});

								SetAvailableMapGoals( TEAM.ALLIES, true, {
									"BUILD_Tram_Engine_Panel",
									"ATTACK_Allies_Station_.*",
								});
							}

							SetAvailableMapGoals( TEAM.AXIS, false, {
								"AMMOCAB_cabinet_ammo_model",
								"AMMOCAB_cabinet_ammo_model2",
								"HEALTHCAB_cabinet_health_model",
								".*_Axis_Documents_.*",
								"DEFEND_Axis_Castle_.*",
							});

							SetAvailableMapGoals( TEAM.ALLIES, false, {
								"AMMOCAB_cabinet_ammo_model",
								"AMMOCAB_cabinet_ammo_model2",
								"HEALTHCAB_cabinet_health_model",
								"CHECKPOINT_spawnbridge_flag",
							});

							if ( !Map.BridgeControlsDestroyed )
							{
								SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Bridge_Controls" );
							}
						}
					}
				}
			}
		},
	},

	Thirty_second = function( trigger )
	{

		Util.MapDebugPrint( "^5Thirty_second" );

		sleep(30);

		if ( !Map.SecretDocumentsSecured )
		{
			Util.MapDebugPrint( "^5Axis_Win" );

			sleep(1);
			ETUtil.WinningChat( TEAM.AXIS );
			sleep(1.5);
			ETUtil.LosingChat( TEAM.ALLIES );
		}
	},

};

global OnMapLoad = function()
{

	OnTrigger( "GRENADE_Wall_1 Exploded.", Map.Wall_1_exploded );
	OnTrigger( "GRENADE_Wooden_Door Exploded.", Map.Wooden_Door_Exploded );
	OnTrigger( "GRENADE_Wall_2 Exploded.", Map.Wall_2_exploded );

	OnTrigger( "The Tram Engine Panel has been repaired!", Map.Tram_Engine_Panel_Built );
	OnTrigger( "Planted at the Tram Engine Panel..", Map.Tram_Engine_Panel_Planted );
	OnTrigger( "Planted at Tram Engine Panel..", Map.Tram_Engine_Panel_Planted );	//Nitmod
	OnTrigger( "Defused at the Tram Engine Panel.", Map.Tram_Engine_Panel_Defused );
	OnTrigger( "Defused at Tram Engine Panel.", Map.Tram_Engine_Panel_Defused );	//Nitmod
	OnTrigger( "Axis have destroyed the Tram Engine Panel!", Map.Tram_Engine_Panel_Destroyed );

	OnTrigger( "Planted at the Front Wall.", Map.Front_Wall_Planted );
	OnTrigger( "Planted at Front Wall.", Map.Front_Wall_Planted );	//Nitmod
	OnTrigger( "Defused at the Front Wall.", Map.Front_Wall_Defused );
	OnTrigger( "Defused at Front Wall.", Map.Front_Wall_Defused );	//Nitmod
	OnTrigger( "The Front Wall has been dynamited!", Map.Front_Wall_Destroyed );

	OnTrigger( "Planted at the Bridge Controls.", Map.Bridge_Controls_Planted );
	OnTrigger( "Planted at Bridge Controls.", Map.Bridge_Controls_Planted );	//Nitmod
	OnTrigger( "Defused at the Bridge Controls.", Map.Bridge_Controls_Defused );
	OnTrigger( "Defused at Bridge Controls.", Map.Bridge_Controls_Defused );	//Nitmod
	OnTrigger( "The Bridge Controls have been dynamited: the Bridge is lowered now!", Map.Bridge_Controls_Destroyed );

	OnTrigger( "Planted at the Command Post.", Map.Command_Post_Planted );
	OnTrigger( "Planted at Command Post.", Map.Command_Post_Planted );	//Nitmod
	OnTrigger( "Defused at the Command Post.", Map.Command_Post_Defused );
	OnTrigger( "Defused at Command Post.", Map.Command_Post_Defused );	//Nitmod
	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( "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( "Allies have stolen the Secret Documents!!", Map.Secret_Documents_Taken );
	OnTrigger( "Axis have returned the Secret Documents!!", Map.Secret_Documents_Returned );
	OnTrigger( "Flag returned Secret Documents!", Map.Secret_Documents_Returned );

	OnTrigger( "The Allies escaped with the Treasure Manifest!", Map.Secret_Documents_Secured );

	OnTrigger( "Axis has reclaimed the Castle Flag!", Map.spawnbridge_flag_Axis_Captured );
	OnTrigger( "The Allies have captured the Castle Flag!", Map.spawnbridge_flag_Allies_Captured );

	OnTrigger( "tram_goto", Map.Tram_goto );
	OnTrigger( "tramswitcht_goto", Map.TramSwitchT_goto );
	OnTrigger( "tramswitchc_goto", Map.TramSwitchC_goto );

	OnTrigger( "thirty second warning.", Map.Thirty_second );

	Util.DisableGoal( ".*", true );

	SetAvailableMapGoals( TEAM.AXIS, true, {
		".*_Axis_Start_.*",
		"DEFEND_Axis_Station_.*",
		"MOBILEMG42_Axis_Station_.*",
	});

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"PLANT_Front_Wall",
		"BUILD_Tram_Engine_Panel",
		"ATTACK_Allies_Station_.*",
	});

	Util.AddUseWp( "PLANT_Front_Wall", "Front_Wall_Plant_WP_1" );
	Util.AddUseWp( "PLANT_Front_Wall", "Front_Wall_Plant_WP_2" );
	Util.AddUseWp( "PLANT_Command_Post", "WP_plant_CP" );

	RegionTrigger.Create(AABB(-2417.627,-1805.410,653.125,-1309.552,-710.099,874.797), "DisableCombatMovement", "Left_Bridge");
	RegionTrigger.Create(AABB(-2417.627,-1805.410,653.125,-1309.552,-710.099,874.797), "DisableBotPush", "Left_Bridge");
	RegionTrigger.Create(AABB(756.744,-1879.105,743.125,2011.056,-625.827,1040.430), "DisableCombatMovement", "Right_Bridge");
	RegionTrigger.Create(AABB(756.744,-1879.105,743.125,2011.056,-625.827,1040.430), "DisableBotPush", "Right_Bridge");
	RegionTrigger.Create(AABB(-2015.743,1774.401,1502.847,-1367.808,1943.731,1766.500), "DisableCombatMovement", "Around_Station_02");
	RegionTrigger.Create(AABB(-2015.743,1774.401,1502.847,-1367.808,1943.731,1766.500), "DisableBotPush", "Around_Station_02");
	RegionTrigger.Create(AABB(223.310,2314.211,1285.125,596.875,2400.875,1419.125), "DisableCombatMovement", "Around_Station_15");
	RegionTrigger.Create(AABB(223.310,2314.211,1285.125,596.875,2400.875,1419.125), "DisableBotPush", "Around_Station_15");
	RegionTrigger.Create(AABB(-324.872,2079.125,1481.125,-191.337,2161.066,1555.125), "DisableCombatMovement", "Around_Station_16");
	RegionTrigger.Create(AABB(-324.872,2079.125,1481.125,-191.337,2161.066,1555.125), "DisableBotPush", "Around_Station_16");
	RegionTrigger.Create(AABB(-163.991,-4277.691,1305.125,711.403,-4021.247,1547.125), "DisableCombatMovement", "Jump_from_CP");
	RegionTrigger.Create(AABB(731.759,-3228.163,1153.125,905.027,-3049.970,1268.607), "DisableCombatMovement", "Trigger_Window_CastleSpawn");
	RegionTrigger.Create(AABB(731.759,-3228.163,1153.125,905.027,-3049.970,1268.607), "DisableBotPush", "Trigger_Window_CastleSpawn");
	RegionTrigger.Create(AABB(2957.632,-1410.371,1062.395,3123.994,-1220.583,1202.728), "DisableCombatMovement", "Jump_to_Road");
	RegionTrigger.Create(AABB(2957.632,-1410.371,1062.395,3123.994,-1220.583,1202.728), "DisableBotPush", "Jump_to_Road");
	RegionTrigger.Create(AABB(-352.788,1416.564,1345.125,-82.625,1565.055,1440.296), "DisableCombatMovement", "StationTramSwitch");
	RegionTrigger.Create(AABB(-352.788,1416.564,1345.125,-82.625,1565.055,1440.296), "DisableBotPush", "StationTramSwitch");
	RegionTrigger.Create(AABB(-195.169,-4252.138,1345.125,-71.656,1361.362,1437.156), "DisableCombatMovement", "Route_by_cablecar");
	RegionTrigger.Create(AABB(-195.169,-4252.138,1345.125,-71.656,1361.362,1437.156), "DisableBotPush", "Route_by_cablecar");
	RegionTrigger.Create(AABB(587.229,-4164.875,1182.377,699.439,-3974.503,1355.125), "DisableCombatMovement", "Top_of_Ladder");
	RegionTrigger.Create(AABB(587.229,-4164.875,1182.377,699.439,-3974.503,1355.125), "DisableBotPush", "Top_of_Ladder");
	RegionTrigger.Create(AABB(411.372,752.417,1561.125,786.137,866.144,1663.741), "DisableCombatMovement", "Roof_of_Station");
	RegionTrigger.Create(AABB(411.372,752.417,1561.125,786.137,866.144,1663.741), "DisableBotPush", "Roof_of_Station");
	RegionTrigger.Create(AABB(271.125,2842.875,1037.125,414.879,3056.875,1146.439), "BreakableDistance", "Door1");
	RegionTrigger.Create(AABB(-547.180,1450.791,1345.125,-228.506,1721.458,1419.125), "DisableCombatMovement", "Navigate_near_tram");
	RegionTrigger.Create(AABB(1066.996,-4664.874,1089.125,1272.875,-4201.384,1461.717), "DisableCombatMovement", "Trigger_AroundLift" );
	RegionTrigger.Create(AABB(519.127,-4964.427,1473.125,768.875,-4597.140,1592.015), "DisableCombatMovement", "Trigger_Jump_to_CP" );
	RegionTrigger.Create(AABB(507.127,-3726.384,1281.125,622.941,-3552.414,1393.699), "DisableCombatMovement", "Trigger_Jump_from_window" );

	IW1 = OnTriggerRegion(AABB(-1982.181,-5472.875,801.125,1413.209,-2205.777,1653.020), RegionTrigger.IntrusionWarning );

	Allies_Inside_Castle1 = OnTriggerRegion(AABB(-1982.181,-5472.875,801.125,1413.209,-2205.777,1653.020), Map.AlliesInsideCastle);
	Allies_Inside_Castle2 = OnTriggerRegion(AABB(1378.294,-5248.875,1345.125,2032.873,-4883.125,1580.502), Map.AlliesInsideCastle);
	Allies_Inside_Castle3 = OnTriggerRegion(AABB(-1856.874,-2436.158,1286.335,-1148.828,-2051.125,1407.342), Map.AlliesInsideCastle);
	Allies_Inside_Castle4 = OnTriggerRegion(AABB(-2542.334,-3680.875,737.125,-1951.951,-3487.125,914.747), Map.AlliesInsideCastle);
	//Allies_Inside_Castle5 = OnTriggerRegion(AABB(-3712.875,-4736.875,274.733,-2003.192,-1820.612,1048.491), Map.AlliesInsideCastle);
	Allies_Inside_Castle5 = OnTriggerRegion(AABB(-3712.875,-4736.875,272.185,-1946.988,-1397.661,1321.464), Map.AlliesInsideCastle);
	Allies_Inside_Castle6 = OnTriggerRegion(AABB(1410.762,-4259.398,1089.125,2040.875,-2857.127,1223.703), Map.AlliesInsideCastle);
	Axis_Truck_Spawn = OnTriggerRegion(AABB(2050.711,990.969,1185.125,3433.012,1703.860,1493.005), Map.Axis_TruckSpawn);
	LiftDown_bb = OnTriggerRegion(AABB(1147,-4565,1085,1185,-4527,1090), Map.Lift_Down_bb);
	LiftUp_bb = OnTriggerRegion(AABB(1180,-4589,1345,1218,-4551,1419), Map.Lift_Up_bb);
	TramInStation = OnTriggerRegion(AABB(-195.249,1663.125,1328.449,-149.797,1775.253,1410.287), Map.TramIn_Station);

	Util.LimitToClass("PLANT_Command_Post", 0, CLASS.COVERTOPS);

	Util.LimitToClass("PLANT_Tram_Engine_Panel", TEAM.AXIS, CLASS.ENGINEER);

	Util.DisableGoal ("ROUTE_Front_Wall");
	Util.DisableGoal ("ROUTE_Near_Boxes");
	Util.DisableGoal ("ROUTE_Past_WoodenBridge");
	Util.DisableGoal ("ROUTE_Tram1");
	Util.DisableGoal ("ROUTE_Tram2");

	SetGoalPriority( "BUILD_Command_Post", 0.51, TEAM.AXIS, 0 );	//defence of documents is more important
	SetGoalPriority( "BUILD_Command_Post", 0.79, TEAM.ALLIES, 0 );	//stolen of documents is more important

	SetGoalPriority( "DEFEND_Axis_Station_02", 0.55, TEAM.AXIS, 0 );
	SetGoalPriority( "DEFEND_Axis_Station_03", 0.51, TEAM.AXIS, 0 );
	SetGoalPriority( "DEFEND_Axis_Station_05", 0.55, TEAM.AXIS, 0 );
	SetGoalPriority( "DEFEND_Axis_Station_06", 0.51, TEAM.AXIS, 0 );
	SetGoalPriority( "DEFEND_Axis_Station_07", 0.55, TEAM.AXIS, 0 );
	SetGoalPriority( "DEFEND_Axis_Station_12", 0.55, TEAM.AXIS, 0 );
	SetGoalPriority( "DEFEND_Axis_Station_08", 0.51, TEAM.AXIS, 0 );
	SetGoalPriority( "DEFEND_Axis_Station_14", 0.54, TEAM.AXIS, 0 );
	SetGoalPriority( "DEFEND_Axis_Station_17", 0.53, TEAM.AXIS, 0 );
	SetGoalPriority( "PLANT_Tram_Engine_Panel", 0.5, TEAM.AXIS, CLASS.ENGINEER );	//unimportant
	SetGoalPriority( "DEFEND_Axis_Documents_.*", 0.51, TEAM.AXIS, 0 );
	SetGoalPriority( "DEFEND_Axis_Documents_02", 0.85, TEAM.AXIS, CLASS.COVERTOPS );
	SetGoalPriority( "DEFEND_Axis_Documents_03", 0.85, TEAM.AXIS, CLASS.MEDIC );

	SetGoalPriority( "REPAIRMG42_.*", 0.5, TEAM.AXIS, CLASS.ENGINEER );	//unimportant for axis

	SetGoalPriority( "REPAIRMG42_.*", 0.61, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "ATTACK_Allies_Station_01", 0.51, TEAM.ALLIES, 0 );
	SetGoalPriority( "ATTACK_Allies_Station_02", 0.51, TEAM.ALLIES, 0 );
	SetGoalPriority( "ATTACK_Allies_Station_07", 0.51, TEAM.ALLIES, 0 );
	SetGoalPriority( "ATTACK_Allies_Station_12", 0.51, TEAM.ALLIES, 0 );
	SetGoalPriority( "ATTACK_Allies_Station_06", 0.52, TEAM.ALLIES, 0 );

	SetGoalPriority( "ATTACK_Road_to_Truck_.*", 0.6, 0, 0 );

	SetGoalPriority( "CHECKPOINT_spawnbridge_flag", 0.81, 0, 0 );

	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "GRENADE_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 1, "CHECKPOINT_spawnbridge_flag" );

	Wp.SetWaypointFlag( "waypointforgrenadewall2", "closed", false );
	Wp.SetWaypointFlag( "Cave", "closed", false );
	Wp.SetWaypointFlag( "Cave2", "closed", false );
	Wp.SetWaypointFlag( "Cave3", "closed", false );
	Wp.SetWaypointFlag( "aa", "closed", false );
	Wp.SetWaypointFlag( "b", "closed", false );
	Wp.SetWaypointFlag( "c", "closed", false );
	Wp.SetWaypointFlag( "d", "closed", false );
	Wp.SetWaypointFlag( "wait_tram", "closed", true );
	DynamicPathsUpdated();

	Util.UpdateSwitchData();

	print( "^3Omni-bot map script by ^1Q^2i^3k^4i ^3and ^1n^2a^4t^8i^3v^5e12 ^3for " + GetMapName() + " executed." );
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		BUILD_Tram_Engine_Panel =
		{
			ROUTE_Allied_First_Spawn =
			{
				ROUTE_Building_1 =
				{
					ROUTE_Cave =
					{

					},
					ROUTE_Building_Stairs =
					{

					},
				},
				ROUTE_Tunnel =
				{

				},
			},
		},
		FLAG_Secret_Documents =
		{
			ROUTE_Allied_Station_Spawn =
			{
				ROUTE_Left_jump_to_grass =
				{
					Weight = 2,
					ROUTE_Left_footbridge =
					{
						ROUTE_Front_Wall =
						{
							ROUTE_Near_Boxes =
							{

							},
						},
						ROUTE_Ladder_to_Wooden_Bridge =
						{
							ROUTE_byLift =
							{

							},
							ROUTE_Window =
							{

							},
						},
					},
				},
				ROUTE_Right_jump_to_grass =
				{
					Weight = 2,
					ROUTE_Right_footbridge =
					{
						ROUTE_Cave_stairs =
						{

						},
					},
				},
				ROUTE_Tram1 =
				{
					ROUTE_Tram2 =
					{

					},
				},
			},
			ROUTE_Allied_Castle_Spawn_Right =
			{
				ROUTE_byLift =
				{

				},
				ROUTE_Window =
				{
					ROUTE_Around_Boxes =
					{

					},
				},
			},
			ROUTE_Allied_Castle_Spawn_Left =
			{
				ROUTE_byLift =
				{

				},
				ROUTE_Window =
				{
					ROUTE_Around_Boxes =
					{

					},
				},
			},
		},
		CAPPOINT_Truck =
		{
			ROUTE_FlagDocuments =
			{
				ROUTE_byLift =
				{
					ROUTE_Past_WoodenBridge =
					{

					},
				},
				ROUTE_Near_Boxes_Capp =
				{
					ROUTE_Left_footbridge =
					{

					},
				},
				ROUTE_Cave_stairs =
				{
					ROUTE_Shore =
					{
						ROUTE_Grass_1 =
						{
							ROUTE_Grass_2 =
							{
								ROUTE_Grass_3 =
								{
									ROUTE_Grass_4 =
									{
										ROUTE_Grass_5 =
										{
											ROUTE_Grass_6 =
											{

											},
										},
									},
								},
							},
						},
					},
				},
			},
		},
	};

	MapRoutes["ATTACK_Road_to_Truck_.*"] =
	{
		ROUTE_Defend_Near_Documents =
		{
			ROUTE_byLift =
			{
				ROUTE_Past_WoodenBridge =
				{

				},
			},
			ROUTE_Near_Boxes_Capp =
			{
				ROUTE_Left_footbridge =
				{

				},
			},
		},
		ROUTE_Allied_Castle_Spawn_Left =
		{
			ROUTE_Window =
			{

			},
			ROUTE_Past_WoodenBridge =
			{

			},
		},
		ROUTE_Allied_Castle_Spawn_Right =
		{
			ROUTE_Window =
			{

			},
			ROUTE_Past_WoodenBridge =
			{

			},
		},
		ROUTE_Axis_Castle_Spawn =
		{
			ROUTE_byLift =
			{

			},
			ROUTE_Near_Boxes_Capp_1 =
			{

			},
		},
	};

	MapRoutes["ATTACK_Allies_Station_.*"] = MapRoutes.BUILD_Tram_Engine_Panel;

	Util.Routes(MapRoutes);
};

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 150.0;

	if ( !Map.StationIsAllied )
	{
		if ( Map.Allies_Inside > 0 )
		{
			if ( Server.Team[ TEAM.AXIS ].NumPlayers < 5 )
			{
				Util.ChangeSpawn( TEAM.AXIS, 4 );
			}
			else
			{
				if ( Map.Allies_Inside < 4 )
				{
					ETUtil.SuicideSpawn( TEAM.AXIS, 4, -1, CLASS.SOLDIER );
					ETUtil.SuicideSpawn( TEAM.AXIS, 4, -1, CLASS.COVERTOPS );
				}
				else
				{
					Util.ChangeSpawn( TEAM.AXIS, 4 );
				}
			}
		}
		else
		{
			Util.ChangeSpawn( TEAM.AXIS, 0 );
		}
	}

	WeaponTable.SetWeaponAvailability( CLASS.SOLDIER, WEAPON.FLAMETHROWER, false );
	WeaponTable.SetWeaponAvailability( CLASS.SOLDIER, WEAPON.MORTAR, false );
	WeaponTable.SetWeaponAvailability( CLASS.SOLDIER, WEAPON.MORTAR_SET, false );

	WeaponTable.SetWeaponTeamAvailability ( TEAM.ALLIES, CLASS.SOLDIER, WEAPON.MOBILE_MG42, false );

	if ( ETUtil.CountClass( TEAM.AXIS, CLASS.SOLDIER ) < 2 )
	{
		WeaponTable.SetWeaponTeamAvailability ( TEAM.ALLIES, CLASS.SOLDIER, WEAPON.PANZERFAUST, false );
	}
	else
	{
		WeaponTable.SetWeaponTeamAvailability ( TEAM.ALLIES, CLASS.SOLDIER, WEAPON.PANZERFAUST, true );
	}

	wpn = bot.GetWeapon(WEAPON.MOBILE_MG42);
	if(wpn)
	{
		wpn.PrimaryFire.LowAmmoPriority = 0.8;
	}
};
