global Map =
{
	Debug = false,

	Switches =
	{
		TrackSwitch =
		{
			Enabled = false,
			Priority = 0, // leave for paththrough
			WaypointName = "TrackSwitch",
			LimitTeam = 0, // disabled initially.
		},

		RailgunControls =
		{
			Enabled = false,
			Priority = 0, // leave for paththrough
			WaypointName = "Railgun Controls",
			LimitTeam = 0, // disabled initially.
		},
	},

	// a few bots on each team will focus on the flag area while the rest will ignore it
	Roles =
	{
		AXIS =
		{
			DEFENDER3 =
			{
				numbots = 3,
			},
		},

		ALLIES =
		{
			DEFENDER3 =
			{
				numbots = 3,
			},
		},
	},

	Navigation =
	{
		// some quick jumping for rails and gaps
		quickjump =
		{
			navigate = function(_this)
			{
				_this.Bot.PressButton(BTN.JUMP);
				sleep(0.25);
			},
		},
	},

	//flag status
	FlagStatus = 0, //1 axis, 2 allies

	Ammo_Cabinet_t1170 = "AMMOCAB_t1170",
	Health_Cabinet_t1171 = "HEALTHCAB_t1171",
	Checkpoint_depotflag = "CHECKPOINT_depotflag",
	Build_Command_Post = "BUILD_Command_Post",
	Build_Depot_Yard_MG_Nest = "BUILD_Depot_Yard_MG_Nest",
	Build_Rail_Gun_Firing_Controls = "BUILD_Rail_Gun_Firing_Controls",
	Build_Track_Switch_MG_Nest = "BUILD_Track_Switch_MG_Nest",
	Plant_Command_Post = "PLANT_Command_Post",
	Plant_Depot_Yard_MG_Nest = "PLANT_Depot_Yard_MG_Nest",
	Plant_Rail_Gun_Firing_Controls = "PLANT_Rail_Gun_Firing_Controls",
	Plant_Track_Switch_MG_Nest = "PLANT_Track_Switch_MG_Nest",
	Mount_Construction_Site_MG_Nest = "MOUNTMG42_Construction_Site_MG_Nest",
	Mount_Depot_Yard_MG_Nest = "MOUNTMG42_Depot_Yard_MG_Nest",
	Mount_Track_Switch_MG_Nest = "MOUNTMG42_Track_Switch_MG_Nest",
	Mount_mg42_3 = "MOUNTMG42_mg42_3",
	Repair_Construction_Site_MG_Nest = "REPAIRMG42_Construction_Site_MG_Nest",
	Repair_Depot_Yard_MG_Nest = "REPAIRMG42_Depot_Yard_MG_Nest",
	Repair_Track_Switch_MG_Nest = "REPAIRMG42_Track_Switch_MG_Nest",
	Repair_mg42_3 = "REPAIRMG42_mg42_3",
	Mover_train1 = "MOVER_train1",
	Mover_train2 = "MOVER_train2",

	DispenseHealthTime = 15.0,
	DispenseAmmoTime = 15.0,

	// some flags to help with tug position logic
	southcrane = 0,
	southofswitch = 0,
	northofswitch = 0,
	depotyard = 0,
	panel3 = true,
	Railgun_Loaded = false,
	Switch_Raised = false,
	AmmoCrane = false,
	AmmoLoaded = false,

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

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

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

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

	Rail_Gun_Firing_Controls_Built = function( trigger )
	{
		Map.panel3 = true;

		if ( Map.Railgun_Loaded )
		{
			Map.Switches.RailgunControls.LimitTeam = (1<<TEAM.AXIS);
			Util.LimitGoal( TEAM.AXIS, "SWITCH_controls" );
		}

		Util.MapDebugPrint( "Rail_Gun_Firing_Controls_Built" );
	},

	Rail_Gun_Firing_Controls_Destroyed = function( trigger )
	{
		Map.panel3 = false;

		if ( Map.Railgun_Loaded )
		{
			Map.Switches.RailgunControls.LimitTeam = 0;
			Util.DisableGoal( "SWITCH_controls" );
		}

		Util.MapDebugPrint( "Rail_Gun_Firing_Controls_Destroyed" );
	},

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

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

	depotflag_Axis_Captured = function( trigger )
	{
		Map.FlagStatus = 1;

		Util.MapDebugPrint( "depotflag_Axis_Captured" );
	},

	depotflag_Allies_Captured = function( trigger )
	{
		Map.FlagStatus = 2;

		Util.MapDebugPrint( "depotflag_Allies_Captured" );
	},

	Track_Switch_Raised = function( trigger )
	{
		Map.Switch_Raised = true;

		if ( Map.Switches.TrackSwitch.LimitTeam == (1<<TEAM.AXIS) )
			{ Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.ALLIES); }
		else
			{ Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.AXIS); }

		// TODO: need to redo this stuff
		mg = GetGoal("SWITCH_trackswitch");
		if( mg.IsAvailable(TEAM.AXIS) )
		{
			Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
		}
		else
		{
			Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
		}

		if ( !Map.AmmoCrane )
		{
			// cs: don't toggle these now that both teams will chase
			/*if ( !Map.depotyard )
			{
				SetAvailableMapGoals( TEAM.AXIS, true, "RIDE_rtug1" );
				SetAvailableMapGoals( TEAM.ALLIES, true, "RIDE_btug1" );
			}
			else
			{
				SetAvailableMapGoals( TEAM.AXIS, true, "RIDE_rtug1" );
				SetAvailableMapGoals( TEAM.ALLIES, false, "RIDE_btug1" );
			}*/

			if ( !Map.AmmoLoaded )
			{
				if ( Map.southofswitch || Map.southcrane )
				{
					Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
				}
			}
			else
			{
				if ( Map.southofswitch || Map.southcrane )
				{
					Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
				}
			}
		}

		Util.MapDebugPrint( "Track_Switch_Raised" );
	},

	Track_Switch_Lowered = function( trigger )
	{
		Map.Switch_Raised = false;

		if ( Map.Switches.TrackSwitch.LimitTeam == (1<<TEAM.ALLIES) )
			{ Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.AXIS); }
		else
			{ Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.ALLIES); }

		// TODO: need to redo this stuff
		mg = GetGoal("SWITCH_trackswitch");
		if( mg.IsAvailable(TEAM.ALLIES) )
		{
			Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
		}
		else
		{
			Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
		}

		if ( !Map.AmmoCrane )
		{
			if ( !Map.AmmoLoaded )
			{
				if ( Map.southofswitch || Map.southcrane )
				{
					Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
				}
			}
			else
			{
				if ( Map.southofswitch || Map.southcrane )
				{
					Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
				}
			}
		}

		Util.MapDebugPrint( "Track_Switch_Lowered" );
	},

	Axis_Ammo_Tug1 = function( trigger )
	{
		Map.AmmoLoaded = true;

		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Depot_Yard.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Depot_Yard.*" );

		Util.MapDebugPrint( "Axis_Ammo_Tug1" );
	},

	Axis_Ammo_Crane = function( trigger )
	{
		Map.AmmoCrane = true;

		SetAvailableMapGoals( TEAM.AXIS, false, "RIDE_rtug1" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "RIDE_btug1" );
		SetAvailableMapGoals( TEAM.AXIS, true, "RIDE_rtug2" );

		Map.Switches.TrackSwitch.LimitTeam = null;
		Util.DisableGoal("SWITCH_trackswitch");

		// Allied goals
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"DEFEND_Track_Switch_North_.*",
			"PLANTMINE_bTrackswitch.*",
			Map.Mount_Track_Switch_MG_Nest,
			Map.Build_Track_Switch_MG_Nest,
			Map.Repair_Track_Switch_MG_Nest,
			Map.Repair_Depot_Yard_MG_Nest,
			Map.Mount_mg42_3,
			Map.Repair_mg42_3,
			Map.Plant_Command_Post,
			Map.Build_Command_Post,
			Map.Health_Cabinet_t1171,
			Map.Ammo_Cabinet_t1170,
		});

		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Railgun.*" ); //just to make sure
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Crane_Area_.*" );

		// Axis goals
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"ATTACK_Track_Switch_North_.*",
			Map.Mount_Track_Switch_MG_Nest,
			Map.Plant_Track_Switch_MG_Nest,
			Map.Repair_Track_Switch_MG_Nest,
			Map.Repair_Depot_Yard_MG_Nest,
			Map.Repair_mg42_3,
			Map.Plant_Depot_Yard_MG_Nest,
			Map.Plant_Command_Post,
			Map.Mount_mg42_3,
			Map.Build_Command_Post,
			Map.Health_Cabinet_t1171,
			Map.Ammo_Cabinet_t1170,
		});

		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_Railgun.*" );

		Util.MapDebugPrint( "Axis_Ammo_Crane" );
	},

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

	Axis_Loaded_Railgun = function( trigger )
	{
		Map.Railgun_Loaded = true;

		if ( Map.panel3 )
		{
			Map.Switches.RailgunControls.LimitTeam = (1<<TEAM.AXIS);
			Util.LimitGoal( TEAM.AXIS, "SWITCH_controls" );
		}

		SetAvailableMapGoals( TEAM.AXIS, false, "RIDE_rtug2" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "RIDE_btug2" );

		SetAvailableMapGoals( TEAM.AXIS, true, Map.Build_Rail_Gun_Firing_Controls );

		Util.MapDebugPrint( "Axis_Loaded_Railgun" );
	},

	Axis_Fired_Railgun = function( trigger )
	{
		Map.Switches.RailgunControls.LimitTeam = 0;
		Util.DisableGoal( "SWITCH_controls" );

		Util.MapDebugPrint( "Axis_Fired_Railgun" );
	},

	tug_depotyard =
	{
		Name = "tug_depotyard",
		TriggerOnEntity = GetGoal("MOVER_train1").GetEntity(),
		OnEnter = function(ent)
		{
			if ( Map.depotyard != 0 )
			{
				//SetAvailableMapGoals( TEAM.ALLIES, false, "RIDE_btug1");
				Map.depotyard = 0;
			}
			else
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, "RIDE_btug1");
				Map.depotyard = 1;
			}

			//reset the northofswitch flag
			Map.northofswitch = 0;

			//run the logic tests
			Map.tug_logics(1);

			Util.MapDebugPrint( "tug_depotyard" );
		},
	},

	tug_northofswitch =
	{
		Name = "tug_northofswitch",
		TriggerOnEntity = GetGoal("MOVER_train1").GetEntity(),
		OnEnter = function(ent)
		{
			Map.northofswitch = 1;
			Map.southofswitch = 0;
			Map.depotyard = 0;

			//run the logic tests
			Map.tug_logics(2);

			Util.MapDebugPrint( "tug_northofswitch" );
		},
	},

	tug_southofswitch =
	{
		Name = "tug_southofswitch",
		TriggerOnEntity = GetGoal("MOVER_train1").GetEntity(),
		OnEnter = function(ent)
		{
			Map.northofswitch = 0;
			Map.southofswitch = 1;
			Map.southcrane = 0;

			//run the logic tests
			Map.tug_logics(3);

			Util.MapDebugPrint( "tug_southofswitch" );
		},
	},

	tug_southcrane =
	{
		Name = "tug_southcrane",
		TriggerOnEntity = GetGoal("MOVER_train1").GetEntity(),
		OnEnter = function(ent)
		{
			if ( Map.southcrane != 0 )
			{
				Map.southcrane = 0;
			}
			else
			{
				Map.southcrane = 1;
			}

			//reset the southofswitch flag
			Map.southofswitch = 0;

			//run the logic tests
			Map.tug_logics(4);

			Util.MapDebugPrint( "tug_southcrane" );
		},
	},

	tug_logics = function (position)
	{
		Util.MapDebugPrint("tug_logics", true);
		if ( !Map.AmmoLoaded )
		{
			if( position == 1 ) //depotyard
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, {
					"DEFEND_Track_Switch_North_.*",
					"PLANTMINE_bTrackswitch.*",
					"DEFEND_Depot_Yard_.*",
				});
				SetAvailableMapGoals( TEAM.AXIS, false, Map.Mount_mg42_3 );
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Crane_Area_.*" );
			}
			else if( position == 2 ) //northofswitch
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, {
					"DEFEND_Depot_Yard_.*",
					"DEFEND_Track_Switch_North_.*",
					"PLANTMINE_bTrackswitch.*",
				});
				SetAvailableMapGoals( TEAM.AXIS, true, Map.Mount_mg42_3 );


				if ( !Map.Switch_Raised )
				{
					if ( Map.southofswitch != 0 )
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.ALLIES);
						Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
					}
					else
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.AXIS);
						Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
					}
				}
				else
				{
					if ( Map.southofswitch != 0 )
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.AXIS);
						Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
					}
					else
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.ALLIES);
						Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
					}
				}
			}
			else if( position == 3 ) //southofswitch
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Crane_Area_.*" );

				if ( !Map.Switch_Raised )
				{
					if ( Map.norththofswitch != 0 )
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.AXIS);
						Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
					}
					else
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.ALLIES);
						Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
					}
				}
				else
				{
					if ( Map.northofswitch != 0 )
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.ALLIES);
						Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
					}
					else
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.AXIS);
						Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
					}
				}
			}
			else if( position == 4 ) //southcrane
			{
				if ( Map.Switch_Raised )
				{
					Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.ALLIES);
					Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
				}
				else
				{
					Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.AXIS);
					Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
				}
			}
		}
		else
		{
			if( position == 1 )
			{
				//will never get here
			}
			else if( position == 2 )
			{
				if ( !Map.Switch_Raised )
				{
					if ( Map.southofswitch != 0 )
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.AXIS);
						Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
					}
					else
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.ALLIES);
						Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
					}
				}
				else
				{
					if ( Map.southofswitch != 0 )
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.ALLIES);
						Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
					}
					else
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.AXIS);
						Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
					}
				}

				//some allies should start cheating over to railgun here
				SetAvailableMapGoals( TEAM.ALLIES, true, {
					"DEFEND_Railgun_.*",
					"DEFEND_Crane_Area_.*",
				});

				SetAvailableMapGoals( TEAM.ALLIES, false, {
					Map.Checkpoint_depotflag,
					Map.Build_Depot_Yard_MG_Nest,
					Map.Mount_Depot_Yard_MG_Nest,
					Map.Repair_Depot_Yard_MG_Nest,
				});

				SetAvailableMapGoals( TEAM.AXIS, false, {
					Map.Checkpoint_depotflag,
					Map.Build_Depot_Yard_MG_Nest,
					Map.Mount_Depot_Yard_MG_Nest,
					Map.Repair_Depot_Yard_MG_Nest,
				});
			}
			else if( position == 3 )
			{
				if ( !Map.Switch_Raised )
				{
					if ( Map.norththofswitch != 0 )
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.ALLIES);
						Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
					}
					else
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.AXIS);
						Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
					}
				}
				else
				{
					if ( Map.northofswitch != 0 )
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.AXIS);
						Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
					}
					else
					{
						Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.ALLIES);
						Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
					}
				}

				SetAvailableMapGoals( TEAM.ALLIES, false, {
					"DEFEND_Railgun_.*",
					"DEFEND_Crane_Area_.*",
				});

				//SetAvailableMapGoals( TEAM.ALLIES, true, Map.Checkpoint_depotflag );
				SetAvailableMapGoals( TEAM.ALLIES, true, {
					Map.Build_Depot_Yard_MG_Nest,
					Map.Mount_Depot_Yard_MG_Nest,
					Map.Repair_Depot_Yard_MG_Nest,
				});

				//SetAvailableMapGoals( TEAM.AXIS, true, Map.Checkpoint_depotflag );
				SetAvailableMapGoals( TEAM.AXIS, true, {
					Map.Build_Depot_Yard_MG_Nest,
					Map.Mount_Depot_Yard_MG_Nest,
					Map.Repair_Depot_Yard_MG_Nest,
				});
			}
			else if( position == 4 )
			{
				if ( Map.Switch_Raised )
				{
					Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.ALLIES);
					Util.LimitGoal( TEAM.ALLIES, "SWITCH_trackswitch" );
				}
				else
				{
					Map.Switches.TrackSwitch.LimitTeam = (1<<TEAM.AXIS);
					Util.LimitGoal( TEAM.AXIS, "SWITCH_trackswitch" );
				}
			}
		}

		return;
	},
};

global OnMapLoad = function()
{
	Util.SetGoalOffset( 0, 25, -10, Map.Build_Rail_Gun_Firing_Controls );
	//~ Util.SetGoalOffset( 50, 0, 0, Map.Build_Depot_Yard_MG_Nest );

	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "The Depot Yard MG Nest has been constructed.", Map.Depot_Yard_MG_Nest_Built );
	OnTrigger( "The Depot Yard MG has been constructed.", Map.Depot_Yard_MG_Nest_Built );
	OnTrigger( "Rail Gun Firing Controls rebuilt!", Map.Rail_Gun_Firing_Controls_Built );
	OnTrigger( "The Track Switch MG Nest has been constructed.", Map.Track_Switch_MG_Nest_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Command_Post_Destroyed );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Command_Post_Destroyed );
	OnTrigger( "The Depot Yard MG has been destroyed.", Map.Depot_Yard_MG_Nest_Destroyed );
	OnTrigger( "Rail Gun Firing Controls destroyed!", Map.Rail_Gun_Firing_Controls_Destroyed );
	OnTrigger( "The Track Switch MG Nest has been destroyed.", Map.Track_Switch_MG_Nest_Destroyed );
	OnTrigger( "Axis captures the Depot Yard!", Map.depotflag_Axis_Captured );
	OnTrigger( "Allies capture the Depot Yard!", Map.depotflag_Allies_Captured );
	OnTrigger( "Track Switch raised!", Map.Track_Switch_Raised );
	OnTrigger( "Track Switch lowered!", Map.Track_Switch_Lowered );
	OnTrigger( "Axis loaded the Rail Gun Ammo onto the First Tug!", Map.Axis_Ammo_Tug1 );
	OnTrigger( "Axis transported the Ammo to the North Crane!", Map.Axis_Ammo_Crane );
	OnTrigger( "Axis transferred the Ammo to the Second Tug!", Map.Axis_Ammo_Tug2 );
	OnTrigger( "Axis team have loaded the Rail Gun!", Map.Axis_Loaded_Railgun );
	OnTrigger( "Axis fired the Rail Gun!", Map.Axis_Fired_Railgun );

	depotyard = OnTriggerRegion(AABB(589.290,4722.105,266.537,668.859,4976.230,347.125), Map.tug_depotyard);
	northofswitch = OnTriggerRegion(AABB(3759.637,4301.975,264.942,4051.185,4411.987,365.170), Map.tug_northofswitch);
	southofswitch = OnTriggerRegion(AABB(3705.093,2385.649,269.221,4299.063,2610.763,393.125), Map.tug_southofswitch);
	southcrane = OnTriggerRegion(AABB(1094.028,955.041,263.132,1464.842,1297.302,345.125), Map.tug_southcrane);

	// disable combat movement and bot pushing in axis spawns
	cm = OnTriggerRegion(AABB(-1526.600,4775.126,289.125,-1119.990,5261.116,424.964),RegionTrigger.DisableBotPush);
	tower = OnTriggerRegion(AABB(1832.000,4915.000,561.000,2263.000,5339.000,714.000),RegionTrigger.DisableBotPush);

	// Max users per goal
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "ATTACK_Depot_Yard.*" );
	Util.SetMaxUsers( 2, Map.Checkpoint_depotflag );
	Util.SetMaxUsers( 1, "SWITCH_.*" );

	Util.SetMaxUsersInUse( 1, "RIDE_.*" );
	Util.SetMaxUsersInProgress( 3, "RIDE_.*" );

	SetMapGoalProperties( "ATTACK_.*", {MinCampTime=10, MaxCampTime=30});
	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=15, MaxCampTime=30});
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=45, MaxCampTime=90});
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=120, MaxCampTime=120});
	SetMapGoalProperties( "SNIPE_.*", {MinCampTime=120, MaxCampTime=120});

	ETUtil.SetCabinets();

	SetGoalPriority( "MOUNTMG42_.*", 0.0, 0, CLASS.MEDIC );
	SetGoalPriority( "MOUNTMG42_.*", 0.0, 0, CLASS.ENGINEER );
	SetGoalPriority( Map.Plant_Command_Post, 0.0, 0, CLASS.ENGINEER );
	SetGoalPriority( Map.Plant_Depot_Yard_MG_Nest, 0.0, 0, CLASS.ENGINEER );
	SetGoalPriority( "SWITCH.*", 0.8 );

	// these goals in the flag area are limited by role. we want some bots to focus on them
	// so increase priority
	SetGoalPriority( ".*Depot_Yard.*", 0.81 ); // camps and all mg42 related goals
	SetGoalPriority( "CHECKPOINT_.*", 0.82 );

	// Allied goals
	SetGoalPriority( Map.Plant_Depot_Yard_MG_Nest, 0.81, TEAM.ALLIES, CLASS.COVERTOPS );

	// Axis goals
	SetGoalPriority( Map.Plant_Track_Switch_MG_Nest, 0.0, TEAM.AXIS, CLASS.ENGINEER );
	SetGoalPriority( Map.Plant_Depot_Yard_MG_Nest, 0.81, TEAM.AXIS, CLASS.COVERTOPS );
	SetGoalPriority( Map.Plant_Track_Switch_MG_Nest, 0.82, TEAM.AXIS, CLASS.COVERTOPS );

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

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"REPAIRMG42_Track_Switch_MG_Nest",
		"HEALTHCAB_t1171",
		"AMMOCAB_t1170",
		"BUILD_Command_Post",
		"BUILD_Track_Switch_MG_Nest",
		"PLANT_Rail_Gun_Firing_Controls",
		"PLANT_Command_Post",
		"PLANT_Depot_Yard_MG_Nest",
		"MOUNTMG42_Track_Switch_MG_Nest",
		"CHECKPOINT_depotflag",
		"DEFEND_Crane_Area_.*",
		"DEFEND_Depot_Yard_.*",
		"PLANTMINE_bTrackswitch.*",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"REPAIRMG42_mg42_3",
		"REPAIRMG42_Track_Switch_MG_Nest",
		"HEALTHCAB_t1171",
		"AMMOCAB_t1170",
		"BUILD_Command_Post",
		"PLANT_Track_Switch_MG_Nest",
		"RIDE_rtug1",
		"PLANT_Command_Post",
		"PLANT_Depot_Yard_MG_Nest",
		"MOUNTMG42_Track_Switch_MG_Nest",
		"CHECKPOINT_depotflag",
		"ATTACK_Depot_Yard_.*",
		"ATTACK_Track_Switch_North_.*",
	});
	Util.EnableGroup( "tsarty", TEAM.AXIS );

	Util.UpdateSwitchData();

	if(ToInt(GetGoal("MOVER_train1").GetPosition().x) == -316){
		//old mods return wrong mover position
		SetMapGoalProperties("RIDE_[br]tug1", {
			BoardPositions = { Vec3(-128,64,0), Vec3(128,64,0) },
			Seats = { Vec3(1,64,26) },
		});
		SetMapGoalProperties("RIDE_[br]tug2", {
			BoardPositions = { Vec3(-128,-64,0), Vec3(128,-64,0) },
			Seats = { Vec3(1,-64,24) },
		});
	}
	Util.MapDebugPrint( "OnMapLoad" );
};

global OnBotJoin = function( bot )
{
	bot.MaxViewDistance = 2500;
	// default spawn
	bot.ChangeSpawnPoint(0);
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		DEFEND_Depot_Yard_6 =
		{
			ROUTE_AllySpawn =
			{
				ROUTE_tsStairsJump = {},
				ROUTE_as_left = { Weight = 3, },
			},
		},
		DEFEND_Railgun_6 =
		{
			ROUTE_AllySpawn =
			{
				ROUTE_as_mid = {},
				ROUTE_as_right = {},
			},
			ROUTE_FlagSpawn =
			{
				ROUTE_east_hill = { Weight = 3 },
				ROUTE_west_hill = {},
			},
		},
		DEFEND_Track_Switch_North_6 =
		{
			ROUTE_AllySpawn =
			{
				ROUTE_tsStairs = { Weight = 4, },
				ROUTE_as_mid = { Weight = 2, },
				ROUTE_as_right = {},
			},
			ROUTE_FlagSpawn =
			{
				ROUTE_west_hill = { ROUTE_bunker_north = {}, },
				ROUTE_bunker_sw =
				{
					Weight = 2,
					ROUTE_bunker_mid = {},
					ROUTE_bunker_east = {},
				},
			},
		},
		ATTACK_Depot_Yard_1 =
		{
			ROUTE_AxisSpawn =
			{
				ROUTE_east_hill = {},
				ROUTE_west_hill = {},
			},
		},
		ATTACK_Railgun_1 =
		{
			ROUTE_AxisSpawn =
			{
				ROUTE_track1 = {},
				ROUTE_track2 = {},
			},
			ROUTE_FlagSpawn =
			{
				ROUTE_east_hill = { Weight = 3 },
				ROUTE_west_hill = {},
			},
		},
		CHECKPOINT_depotflag =
		{
			ROUTE_AxisSpawn =
			{
				ROUTE_east_hill = {},
				ROUTE_west_hill = {},
			},
			ROUTE_AllySpawn =
			{
				ROUTE_tsStairsJump = {},
				ROUTE_as_left = { Weight = 3, },
			},
		},
		ATTACK_Track_Switch_North_1 =
		{
			ROUTE_FlagSpawn =
			{
				ROUTE_west_hill = { ROUTE_bunker_north = {}, },
				ROUTE_bunker_sw =
				{
					Weight = 2,
					ROUTE_bunker_mid = {},
					ROUTE_bunker_east = {},
				},
			},
			ROUTE_AxisSpawn =
			{
				ROUTE_track1 =
				{
					Weight = 3,
					ROUTE_bunker_north = { Weight = 2, },
					ROUTE_bunker_mid = { ROUTE_bunker_east = {}, },
				},
				ROUTE_track2 =
				{
					ROUTE_bunker_north = { Weight = 2, },
					ROUTE_bunker_mid = { ROUTE_bunker_east = {}, },
				},
			},
		},
	};

	//copy some routes
	MapRoutes.DEFEND_Depot_Yard_7 = MapRoutes.DEFEND_Depot_Yard_6;
	MapRoutes.DEFEND_Depot_Yard_8 = MapRoutes.DEFEND_Depot_Yard_6;
	MapRoutes.DEFEND_Depot_Yard_9 = MapRoutes.DEFEND_Depot_Yard_6;
	MapRoutes.DEFEND_Depot_Yard_10 = MapRoutes.DEFEND_Depot_Yard_6;
	MapRoutes.DEFEND_Railgun_7 = MapRoutes.DEFEND_Railgun_6;
	MapRoutes.DEFEND_Railgun_8 = MapRoutes.DEFEND_Railgun_6;
	MapRoutes.DEFEND_Railgun_9 = MapRoutes.DEFEND_Railgun_6;
	MapRoutes.DEFEND_Railgun_10 = MapRoutes.DEFEND_Railgun_6;
	MapRoutes.PLANT_Rail_Gun_Firing_Controls = MapRoutes.DEFEND_Railgun_6;
	MapRoutes.DEFEND_Track_Switch_North_7 = MapRoutes.DEFEND_Track_Switch_North_6;
	MapRoutes.DEFEND_Track_Switch_North_8 = MapRoutes.DEFEND_Track_Switch_North_6;
	MapRoutes.DEFEND_Track_Switch_North_9 = MapRoutes.DEFEND_Track_Switch_North_6;
	MapRoutes.DEFEND_Track_Switch_North_10 = MapRoutes.DEFEND_Track_Switch_North_6;
	MapRoutes.PLANTMINE_bTrackswitch1 = MapRoutes.DEFEND_Track_Switch_North_6;
	MapRoutes.PLANTMINE_bTrackswitch2 = MapRoutes.DEFEND_Track_Switch_North_6;
	MapRoutes.PLANTMINE_bTrackswitch3 = MapRoutes.DEFEND_Track_Switch_North_6;
	MapRoutes.PLANTMINE_bTrackswitch4 = MapRoutes.DEFEND_Track_Switch_North_6;
	MapRoutes.ATTACK_Depot_Yard_2 = MapRoutes.ATTACK_Depot_Yard_1;
	MapRoutes.ATTACK_Depot_Yard_3 = MapRoutes.ATTACK_Depot_Yard_1;
	MapRoutes.ATTACK_Depot_Yard_4 = MapRoutes.ATTACK_Depot_Yard_1;
	MapRoutes.ATTACK_Depot_Yard_5 = MapRoutes.ATTACK_Depot_Yard_1;
	MapRoutes.ATTACK_Railgun_2 = MapRoutes.ATTACK_Railgun_1;
	MapRoutes.ATTACK_Railgun_3 = MapRoutes.ATTACK_Railgun_1;
	MapRoutes.ATTACK_Railgun_4 = MapRoutes.ATTACK_Railgun_1;
	MapRoutes.ATTACK_Railgun_5 = MapRoutes.ATTACK_Railgun_1;
	MapRoutes.BUILD_Rail_Gun_Firing_Controls = MapRoutes.ATTACK_Railgun_1;
	MapRoutes.ATTACK_Track_Switch_North_2 = MapRoutes.ATTACK_Track_Switch_North_1;
	MapRoutes.ATTACK_Track_Switch_North_3 = MapRoutes.ATTACK_Track_Switch_North_1;
	MapRoutes.ATTACK_Track_Switch_North_4 = MapRoutes.ATTACK_Track_Switch_North_1;
	MapRoutes.ATTACK_Track_Switch_North_5 = MapRoutes.ATTACK_Track_Switch_North_1;
	MapRoutes.SWITCH_trackswitch = MapRoutes.ATTACK_Track_Switch_North_1;

	Util.Routes(MapRoutes);
};
