global Map =
{
	//set some vars for the door entities
	frontdoorent,
	leftdoorent,
	rightdoorent,
	hatch = false,

	//status' for conditionals
	beachplanks = false,
	flagstatus = 0, //0 none, 1 axis, 2 allies
	doorcontrols = true, //intact
	frontdoor = false, //closed
	rightdoor = false,
	leftdoor = false,
	CPStatus = 0, // no team owns it

	//dyno counter
	GunDyno = 0,

	DispenseAmmoTime = 15,

	// a couple axis bots will want to mount the south east mg
	Roles =
	{
		AXIS =
		{
			DEFENDER1 =
			{
				numbots = 2,
			},
		},
	},

	Switches =
	{
		FrontDoor =
		{
			Enabled = true,
			Priority = 0, // leave for paththrough
			WaypointName = "Front Door Switch",
			LimitTeam = 0, // disabled initially.
		},

		LeftDoor =
		{
			Enabled = true,
			Priority = 0, // leave for paththrough
			WaypointName = "Left Door Switch",
			LimitTeam = 0, // disabled initially.
		},

		RightDoor =
		{
			Enabled = true,
			Priority = 0, // leave for paththrough
			WaypointName = "Right Door Switch",
			LimitTeam = 0, // disabled initially.
		},

		Hatch =
		{
			Enabled = true,
			Priority = 0, // leave for paththrough
			WaypointName = "Hatch",
			LimitTeam = 0, // disabled initially.
		},
	},

	BaseTriggered = false,
	BaseTrigger =
	{
		Name = "BaseTrigger",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			if ( !Map.BaseTriggered )
			{
				if( GetEntTeam(ent) == TEAM.ALLIES )
				{
					Util.LimitToClass( "CHECKPOINT_westbunker_flag", TEAM.AXIS, CLASS.COVERTOPS );

					Util.ChangeSpawn( TEAM.AXIS, 1 );
					Map.BaseTriggered = true;
					SetAvailableMapGoals( TEAM.AXIS, true, {
						"DEFEND_Gun.*",
						"TRIPMINE_controls.*",
					});
					SetAvailableMapGoals( TEAM.AXIS, false, {
						"MOUNTMG42_Axis_Main_Bunker_MG_nest",
						"DEFEND_Flag_.*",
						"CAMP_cFlag.*",
						"MOUNTMG42_westbunker.*",
						"CALLARTILLERY.*",
						"REPAIRMG42_westbunker_mg42_1",
						"REPAIRMG42_westbunker_mg42_2",
						"CAMP_cFlag.*",
						"PLANT_Allied_Beach_Assault_Ramp",
						"CHECKPOINT_westbunker_flag",
						"MOUNTMG42_Axis_North_W.*MG_nest",
						"REPAIRMG42_Axis_North_W.*MG_nest",
						"BUILD_Axis_North_W.*MG_nest",
						"MOBILEMORTAR_ramp",
					});
					SetAvailableMapGoals( TEAM.ALLIES, false, {
						"MOBILEMORTAR_bUpperBunker1",
						"GRENADE_westbunkermg",
					});

					DeleteTriggerRegion("BaseTrigger");
					Util.MapDebugPrint("BaseTrigger");
				}
			}
		},
	},

	Axis_Conservative = false,
	Axis_Fallback =
	{
		Name = "Axis_Fallback",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			if ( !Map.Axis_Conservative )
			{
				if( GetEntTeam(ent) == TEAM.ALLIES )
				{
					Map.Axis_Conservative = true;
					Util.ChangeSpawn( TEAM.AXIS, 1 );
					Util.OneBotVSayTeam( TEAM.AXIS, VOICE.INCOMING );
					SetAvailableMapGoals( TEAM.AXIS, true, {
						"DEFEND_Gun.*",
						"TRIPMINE_controls.*",
						"MOUNTMG42_Axis_Main_Bunker_MG_nest",
					});
					SetAvailableMapGoals( TEAM.AXIS, false, {
						"DEFEND_Flag_.*",
						"CAMP_cFlag.*",
						"MOUNTMG42_westbunker.*",
						"CALLARTILLERY.*",
						"REPAIRMG42_westbunker_mg42_1",
						"REPAIRMG42_westbunker_mg42_2",
						"CAMP_cFlag.*",
						"PLANT_Allied_Beach_Assault_Ramp",
						"CHECKPOINT_westbunker_flag",
						"MOUNTMG42_Axis_North_W.*MG_nest",
						"REPAIRMG42_Axis_North_W.*MG_nest",
						"BUILD_Axis_North_W.*MG_nest",
						"MOBILEMORTAR_ramp",
					});
					SetAvailableMapGoals( TEAM.ALLIES, false, {
						"MOBILEMORTAR_bUpperBunker1",
						"GRENADE_westbunkermg",
					});

					DeleteTriggerRegion("Axis_Fallback");
					Util.MapDebugPrint("Axis_Fallback");
				}
			}
		},
	},

	Allied_Beach_Assault_Ramp_Built = function()
	{
		Wp.CheckBlockable();
		Map.beachplanks = true;

		// Allied goals
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"SMOKEBOMB_assaultramp",
			"BUILD_Allied_Beach_Assault_Ramp",
			"AIRSTRIKE_bRamp.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"CHECKPOINT_westbunker_flag",
			"PLANT_Gun_Controls",
			"PLANT_Generator",
			"PLANT_Axis_Main_Bunker_MG_nest",
			"PLANT_Axis_South_East_MG_nest",
			"PLANT_Axis_North_W.*MG_nest",
		});

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"MOBILEMORTAR_ramp",
			"DEFEND_Flag.*",
		});

		if ( !Map.BaseTriggered )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, "CAMP_cFlag.*" );
		}

		Util.MapDebugPrint( "Allied_Beach_Assault_Ramp_Built" );
	},


	// TODO: really need to determine which allies are on the beach and which are past the ramp
	// right now, an eng at gun controls could potentially head back to the beach ...
	// dynamically setting roles is one option i guess
	Allied_Beach_Assault_Ramp_Destroyed = function()
	{
		Map.beachplanks = false;

		// Allied goals
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Allied_Beach_Assault_Ramp" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"CHECKPOINT_westbunker_flag",
			"PLANT_Generator",
			"PLANT_Axis_Main_Bunker_MG_nest",
			"PLANT_Axis_South_East_MG_nest",
			"PLANT_Axis_North_W.*MG_nest",
		});

		if ( Map.flagstatus != 2 && !Map.BaseTriggered )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"MOBILEMORTAR_ramp",
				"DEFEND_Flag.*",
			});
			SetAvailableMapGoals( TEAM.AXIS, false, "CAMP_cFlag.*" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Gun_Controls" );
			SetAvailableMapGoals( TEAM.ALLIES, true, "SMOKEBOMB_assaultramp" );
		}

		Util.MapDebugPrint( "Allied_Beach_Assault_Ramp_Destroyed" );
	},

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

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

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

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

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

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

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

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

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

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

	Command_Post_Built_Allied = function()
	{
		Map.CPStatus = 2;

		if ( !Map.doorcontrols ) {
			Util.ChangeSpawn( TEAM.ALLIES, 4, 4 ); // spawn up to 4 at cp
		}

		Util.MapDebugPrint( "Command_Post_Built_Allied" );
	},

	Command_Post_Built_Axis = function()
	{
		Map.CPStatus = 1;

		Util.MapDebugPrint( "Command_Post_Built_Axis" );
	},

	Command_Post_Destroyed_Allied = function()
	{
		Map.CPStatus = 0;

		Util.MapDebugPrint( "Command_Post_Destroyed_Allied" );
	},

	Command_Post_Destroyed_Axis = function()
	{
		Map.CPStatus = 0;
		Util.ChangeSpawn( TEAM.ALLIES, 5 );

		Util.MapDebugPrint( "Command_Post_Destroyed_Axis" );
	},

	Generator_Built = function()
	{
		Map.doorcontrols = true;

		if ( Map.GunDyno < 1 )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_gc_flex.*" );

			if ( Map.frontdoor )
			{
				// Map.Switches.FrontDoor.LimitTeam = (1<<TEAM.AXIS);
				// Util.LimitToTeam( TEAM.AXIS, "SWITCH_frontdoor" );
			}
			else if ( Map.flagstatus == 2 )
			{
				Map.Switches.FrontDoor.LimitTeam = (1<<TEAM.ALLIES);
				Util.LimitToTeam( TEAM.ALLIES, "SWITCH_frontdoor" );
			}
			else
			{
				Map.Switches.FrontDoor.LimitTeam = 0;
				Util.DisableGoal( "SWITCH_frontdoor" );
			}

			if ( Map.rightdoor )
			{
				Map.Switches.RightDoor.LimitTeam = (1<<TEAM.AXIS);
				Util.LimitToTeam( TEAM.AXIS, "SWITCH_rightdoor" );
			}
			else if ( Map.flagstatus == 2 )
			{
				Map.Switches.RightDoor.LimitTeam = (1<<TEAM.ALLIES);
				Util.LimitToTeam( TEAM.ALLIES, "SWITCH_rightdoor" );
			}
			else
			{
				Map.Switches.RightDoor.LimitTeam = 0;
				Util.DisableGoal( "SWITCH_rightdoor" );
			}

			if ( Map.leftdoor )
			{
				Map.Switches.LeftDoor.LimitTeam = (1<<TEAM.AXIS);
				Util.LimitToTeam( TEAM.AXIS, "SWITCH_leftdoor" );
			}
			else if ( Map.flagstatus == 2 )
			{
				Map.Switches.LeftDoor.LimitTeam = (1<<TEAM.ALLIES);
				Util.LimitToTeam( TEAM.ALLIES, "SWITCH_leftdoor" );
			}
			else
			{
				Map.Switches.LeftDoor.LimitTeam = 0;
				Util.DisableGoal( "SWITCH_leftdoor" );
			}
		}

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"MOUNTMG42_Axis_South_East_MG_nest",
			"REPAIRMG42_Axis_South_East_MG_nest",
		});
		Util.ChangeSpawn( TEAM.ALLIES, 5 );

		Util.MapDebugPrint( "Generator_Built" );
	},

	Generator_Destroyed = function()
	{
		Map.doorcontrols = false;
		Map.Switches.FrontDoor.LimitTeam = 0;
		Map.Switches.LeftDoor.LimitTeam = 0;
		Map.Switches.RightDoor.LimitTeam = 0;

		Util.DisableGoal( {
			"SWITCH_frontdoor",
			"SWITCH_leftdoor",
			"SWITCH_rightdoor",
		});

		SetAvailableMapGoals( TEAM.AXIS, true, {
			"MOUNTMG42_Axis_South_East_MG_nest",
			"REPAIRMG42_Axis_South_East_MG_nest",
		});

		if ( Map.CPStatus == 2 ) {
			Util.ChangeSpawn( TEAM.ALLIES, 4, 4 ); // spawn up to 4 at cp
		}
		Util.MapDebugPrint( "Generator_Destroyed" );
	},

	westbunker_flag_Axis_Captured = function()
	{
		Map.flagstatus = 1;

		Util.ChangeSpawn( TEAM.ALLIES, 3 );

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

		if ( Map.GunDyno < 1 && !Map.BaseTriggered )
		{
			// Axis goals
			SetAvailableMapGoals( TEAM.AXIS, false, {
				"DEFEND_Gun_.*",
				"DEFEND_gc_flex.*",
			});
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"MOUNTMG42_westbunker.*",
				"REPAIRMG42_westbunker_mg42_1",
				"REPAIRMG42_westbunker_mg42_2",
				"CALLARTILLERY.*",
			});
		}

		if ( !Map.beachplanks  )
		{
			SetAvailableMapGoals( TEAM.ALLIES, false, {
				"PLANT_Gun_Controls",
				"ATTACK_Gun_.*",
			});
			SetAvailableMapGoals( TEAM.ALLIES, true, {
				"ATTACK_Beach_.*",
				"GRENADE_westbunkermg",
				"GRENADE_westbunkermg1",
				"SMOKEBOMB_westbunkermg",
				"SMOKEBOMB_westbunker",
				"MOBILEMORTAR_bUpperBunker1",
			});
			SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Flag_.*" );
		}
		else
		{
			SetAvailableMapGoals( TEAM.AXIS, true, "CAMP_cFlag.*" );
		}

		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Allied_West_beach_MG_nest",
			"MOUNTMG42_Allied_West_beach_MG_nest",
			"REPAIRMG42_Allied_West_beach_MG_nest",
		});

		if ( Map.frontdoor && Map.GunDyno < 1 && Map.doorcontrols )
		{
			// Map.Switches.FrontDoor.LimitTeam = (1<<TEAM.AXIS);
			// Util.LimitToTeam( TEAM.AXIS, "SWITCH_frontdoor" );
		}
		else
		{
			Map.Switches.FrontDoor.LimitTeam = 0;
			Util.DisableGoal( "SWITCH_frontdoor" );
		}

		if ( Map.leftdoor && Map.doorcontrols )
		{
			Map.Switches.LeftDoor.LimitTeam = (1<<TEAM.AXIS);
			Util.LimitToTeam( TEAM.AXIS, "SWITCH_leftdoor" );
		}
		else
		{
			Map.Switches.LeftDoor.LimitTeam = 0;
			Util.DisableGoal( "SWITCH_leftdoor" );
		}

		if ( Map.rightdoor && Map.doorcontrols )
		{
			Map.Switches.RightDoor.LimitTeam = (1<<TEAM.AXIS);
			Util.LimitToTeam( TEAM.AXIS, "SWITCH_rightdoor" );
		}
		else
		{
			Map.Switches.RightDoor.LimitTeam = 0;
			Util.DisableGoal( "SWITCH_rightdoor" );
		}

		if ( Map.hatch )
		{
			Map.Switches.Hatch.LimitTeam = (1<<TEAM.AXIS);
			Util.LimitToTeam( TEAM.AXIS, "SWITCH_hatch" );
		}
		else
		{
			Map.Switches.Hatch.LimitTeam = 0;
			Util.DisableGoal( "SWITCH_hatch" );
		}

		Util.MapDebugPrint( "westbunker_flag_Axis_Captured" );
	},

	westbunker_flag_Allies_Captured = function()
	{
		Map.flagstatus = 2;

		// Allied goals
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ATTACK_Beach_.*",
			"MOBILEMORTAR_bUpperBunker1",
			"GRENADE_westbunkermg",
			"GRENADE_westbunkermg1",
			"SMOKEBOMB_westbunkermg",
			"SMOKEBOMB_westbunker",
			"BUILD_Allied_West_beach_MG_nest",
			"MOUNTMG42_Allied_West_beach_MG_nest",
			"REPAIRMG42_Allied_West_beach_MG_nest",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"ATTACK_Gun_.*",
			"PLANT_Gun_Controls",
		});

		//make sure they spawn at flag
		Util.ChangeSpawn( TEAM.ALLIES, 5 );

		// Axis goals
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Gun_.*" );

		if ( Map.GunDyno < 1 && !Map.BaseTriggered )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"DEFEND_gc_flex.*",
				"BUILD_Axis_Main_Bunker_MG_nest",
				"MOUNTMG42_Axis_Main_Bunker_MG_nest",
				"TRIPMINE_flex.*",
			});
		}

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_Flag_.*",
			"CAMP_cFlag.*",
			"MOUNTMG42_westbunker.*",
			"CALLARTILLERY.*",
			"REPAIRMG42_westbunker_mg42_1",
			"REPAIRMG42_westbunker_mg42_2",
			"TRIPMINE_bunker1",
		});

		if ( Map.frontdoor && Map.GunDyno < 1 && Map.doorcontrols )
		{
			// Map.Switches.FrontDoor.LimitTeam = (1<<TEAM.AXIS);
			// Util.LimitToTeam( TEAM.AXIS, "SWITCH_frontdoor" );
		}
		else if( !Map.frontdoor && Map.doorcontrols )
		{
			Map.Switches.FrontDoor.LimitTeam = (1<<TEAM.ALLIES);
			Util.LimitToTeam( TEAM.ALLIES, "SWITCH_frontdoor" );
		}
		else
		{
			Map.Switches.FrontDoor.LimitTeam = 0;
			Util.DisableGoal( "SWITCH_frontdoor" );
		}

		if ( Map.leftdoor && Map.doorcontrols )
		{
			Map.Switches.LeftDoor.LimitTeam = (1<<TEAM.AXIS);
			Util.LimitToTeam( TEAM.AXIS, "SWITCH_leftdoor" );
		}
		else if ( !Map.leftdoor && Map.doorcontrols )
		{
			Map.Switches.LeftDoor.LimitTeam = (1<<TEAM.ALLIES);
			Util.LimitToTeam( TEAM.ALLIES, "SWITCH_leftdoor" );
		}
		else
		{
			Map.Switches.LeftDoor.LimitTeam = 0;
			Util.DisableGoal( "SWITCH_leftdoor" );
		}

		if ( Map.rightdoor && Map.doorcontrols )
		{
			Map.Switches.RightDoor.LimitTeam = (1<<TEAM.AXIS);
			Util.LimitToTeam( TEAM.AXIS, "SWITCH_rightdoor" );
		}
		else if ( !Map.rightdoor && Map.doorcontrols )
		{
			Map.Switches.RightDoor.LimitTeam = (1<<TEAM.ALLIES);
			Util.LimitToTeam( TEAM.ALLIES, "SWITCH_rightdoor" );
		}
		else
		{
			Map.Switches.RightDoor.LimitTeam = 0;
			Util.DisableGoal( "SWITCH_rightdoor" );
		}

		if ( !Map.hatch )
		{
			Map.Switches.Hatch.LimitTeam = (1<<TEAM.ALLIES);
			Util.LimitToTeam( TEAM.ALLIES, "SWITCH_hatch" );
		}
		else
		{
			Map.Switches.Hatch.LimitTeam = 0;
			Util.DisableGoal( "SWITCH_hatch" );
		}

		WeaponTable.SetWeaponAvailability(CLASS.COVERTOPS, WEAPON.FG42, false);

		Util.MapDebugPrint( "westbunker_flag_Allies_Captured" );
	},

	Gun_Controls_Destroyed = function()
	{
		Map.GunDyno = 0;

		Util.MapDebugPrint( "Gun_Controls_Destroyed" );
	},

	Controls_Plant = function()
	{
		++Map.GunDyno;

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_gc_flex.*",
			"TRIPMINE_flex.*",
		});
		Map.Switches.FrontDoor.LimitTeam = 0;
		Util.DisableGoal( "SWITCH_frontdoor" );

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"MOUNTMG42_Axis_South_East_MG_nest",
			"REPAIRMG42_Axis_South_East_MG_nest",
			"BUILD_Generator",
		});

		Util.MapDebugPrint( "Controls_Plant" );
	},

	Controls_Defuse = function()
	{
		--Map.GunDyno;

		if ( Map.GunDyno < 1 )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"DEFEND_gc_flex.*",
				"TRIPMINE_flex.*",
				"MOUNTMG42_Axis_South_East_MG_nest",
				"REPAIRMG42_Axis_South_East_MG_nest",
				"BUILD_Generator",
			});

			Map.Axis_Conservative = false;

			if ( Map.frontdoor && Map.doorcontrols )
			{
				// Map.Switches.FrontDoor.LimitTeam = (1<<TEAM.AXIS);
				// Util.LimitToTeam( TEAM.AXIS, "SWITCH_frontdoor" );
			}
			else if ( Map.flagstatus == 2 && Map.doorcontrols )
			{
				Map.Switches.FrontDoor.LimitTeam = (1<<TEAM.ALLIES);
				Util.LimitToTeam( TEAM.ALLIES, "SWITCH_frontdoor" );
			}
			else
			{
				Map.Switches.FrontDoor.LimitTeam = 0;
				Util.DisableGoal( "SWITCH_frontdoor" );
			}
		}

		Util.MapDebugPrint( "Controls_Defuse" );
	},

	front_door_lever = function()
	{
		//as soon as they trigger it, turn it off
		//so they only hit it once.
		Map.Switches.FrontDoor.LimitTeam = 0;
		Util.DisableGoal( "SWITCH_frontdoor" );
		Util.MapDebugPrint( "front_door_lever", true );
	},

	front_door_right = function(trigger)
	{
		vel = ToVector(trigger.Action);

		//set status based on direction
		if ( vel[1] < 0 )
		{
			Map.frontdoor = false;
			Util.DisableGoal("ROUTE_fdoor_route");
			Util.MapDebugPrint("front door closing", true);
		}
		else if ( vel[1] > 0 )
		{
			Map.frontdoor = true;
			Util.EnableGoal("ROUTE_fdoor_route");
			Util.MapDebugPrint("front door opening", true);
		}

		//set availability based on status'
		if ( Map.GunDyno < 1 && Map.doorcontrols && Map.frontdoor )
		{
			// Map.Switches.FrontDoor.LimitTeam = (1<<TEAM.AXIS);
			// Util.LimitToTeam( TEAM.AXIS, "SWITCH_frontdoor" );
		}
		else if ( Map.flagstatus == 2 && !Map.frontdoor )
		{
			Map.Switches.FrontDoor.LimitTeam = (1<<TEAM.ALLIES);
			Util.LimitToTeam( TEAM.ALLIES, "SWITCH_frontdoor" );
		}
		else
		{
			Map.Switches.FrontDoor.LimitTeam = 0;
			Util.DisableGoal( "SWITCH_frontdoor" );
		}

		Util.MapDebugPrint( "front_door_right", true );
	},

	left_door_lever = function()
	{
		Map.Switches.LeftDoor.LimitTeam = 0;
		Util.DisableGoal( "SWITCH_leftdoor" );
		Util.MapDebugPrint( "left_door_lever", true );
	},

	left_door_right = function(trigger)
	{
		vel = ToVector(trigger.Action);

		if ( vel[1] > 0 )
		{
			Map.leftdoor = false;
			Util.MapDebugPrint("left door closing", true);
		}
		else if ( vel[1] < 0 )
		{
			Map.leftdoor = true;
			Util.MapDebugPrint("left door opening", true);
		}

		if ( Map.doorcontrols && Map.leftdoor )
		{
			Map.Switches.LeftDoor.LimitTeam = (1<<TEAM.AXIS);
			Util.LimitToTeam( TEAM.AXIS, "SWITCH_leftdoor" );
		}
		else if ( Map.flagstatus == 2 && !Map.leftdoor )
		{
			Map.Switches.LeftDoor.LimitTeam = (1<<TEAM.ALLIES);
			Util.LimitToTeam( TEAM.ALLIES, "SWITCH_leftdoor" );
		}
		else
		{
			Map.Switches.LeftDoor.LimitTeam = 0;
			Util.DisableGoal( "SWITCH_leftdoor" );
		}

		Util.MapDebugPrint( "left_door_right", true );
	},

	right_door_lever = function()
	{
		Map.Switches.RightDoor.LimitTeam = 0;
		Util.DisableGoal( "SWITCH_rightdoor" );
		Util.MapDebugPrint( "right_door_lever", true );
	},

	right_door_right = function(trigger)
	{
		vel = ToVector(trigger.Action);

		if ( vel[1] < 0 )
		{
			Map.rightdoor = false;
			Util.MapDebugPrint("right door closing", true);
		}
		else if ( vel[1] > 0 )
		{
			Map.rightdoor = true;
			Util.MapDebugPrint("right door opening", true);
		}

		if ( Map.doorcontrols && Map.rightdoor )
		{
			Map.Switches.RightDoor.LimitTeam = (1<<TEAM.AXIS);
			Util.LimitToTeam( TEAM.AXIS, "SWITCH_rightdoor" );
		}
		else if ( Map.flagstatus == 2 && !Map.rightdoor )
		{
			Map.Switches.RightDoor.LimitTeam = (1<<TEAM.ALLIES);
			Util.LimitToTeam( TEAM.ALLIES, "SWITCH_rightdoor" );
		}
		else
		{
			Map.Switches.RightDoor.LimitTeam = 0;
			Util.DisableGoal( "SWITCH_rightdoor" );
		}

		Util.MapDebugPrint( "right_door_right", true );
	},

	hatch_start = function(trigger)
	{
		vel = ToVector(trigger.Action);

		//set status based on direction
		if ( vel[1] < 0 )
		{
			Util.MapDebugPrint("hatch closing", true);
		}
		else if ( vel[1] > 0 )
		{
			Util.MapDebugPrint("hatch opening", true);
		}

		//set availability based on status'
		if ( Map.hatch )
		{
			Map.hatch = false;
			Map.Switches.Hatch.LimitTeam = (1<<TEAM.ALLIES);
			Util.LimitToTeam( TEAM.ALLIES, "SWITCH_hatch" );
			Wp.SetWaypointFlag( "Base Hatch.*", "closed", true );
			DynamicPathsUpdated( TEAM.AXIS, TEAM.ALLIES );
		}
		else
		{
			Map.hatch = true;
			Map.Switches.Hatch.LimitTeam = (1<<TEAM.AXIS);
			Util.LimitToTeam( TEAM.AXIS, "SWITCH_hatch" );
			Wp.SetWaypointFlag( "Base Hatch.*", "closed", false );
			DynamicPathsUpdated( TEAM.AXIS, TEAM.ALLIES );
		}

		Util.MapDebugPrint( "hatch_start", true );
	},
};

global OnMapLoad = function()
{
	Util.SetGoalOffset( -128, -96, 128, "PLANT_Allied_Beach_Assault_Ramp" );

	OnTrigger( "The Allied Beach Assault Ramp has been constructed.", Map.Allied_Beach_Assault_Ramp_Built );
	OnTrigger( "The Allied East beach MG Nest has been constructed.", Map.Allied_East_beach_MG_nest_Built );
	OnTrigger( "The Allied West beach MG Nest has been constructed.", Map.Allied_West_beach_MG_nest_Built );
	OnTrigger( "The Axis Main Bunker MG Nest has been constructed.", Map.Axis_Main_Bunker_MG_nest_Built );
	OnTrigger( "The Axis North-West MG Nest has been constructed.", Map.Axis_North_West_MG_nest_Built );
	OnTrigger( "The Axis South-East MG Nest has been constructed.", Map.Axis_South_East_MG_nest_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Command_Post_Built_Axis );
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Command_Post_Built_Allied );
	OnTrigger( "Axis have constructed the Door Controls Generator!", Map.Generator_Built );
	OnTrigger( "Axis have destroyed the Allied Beach Assault Ramp.", Map.Allied_Beach_Assault_Ramp_Destroyed );
	OnTrigger( "The Allied East beach MG Nest has been destroyed.", Map.Allied_East_beach_MG_nest_Destroyed );
	OnTrigger( "The Allied West beach MG Nest has been destroyed.", Map.Allied_West_beach_MG_nest_Destroyed );
	OnTrigger( "The Axis Main Bunker MG Nest has been destroyed.", Map.Axis_Main_Bunker_MG_nest_Destroyed );
	OnTrigger( "The Axis North-West MG Nest has been destroyed.", Map.Axis_North_West_MG_nest_Destroyed );
	OnTrigger( "The Axis South-East MG Nest has been destroyed.", Map.Axis_South_East_MG_nest_Destroyed );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Command_Post_Destroyed_Axis );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Command_Post_Destroyed_Allied );
	OnTrigger( "Allied team has destroyed the Door Controls Generator!", Map.Generator_Destroyed );
	OnTrigger( "Allies have destroyed the gun tracking", Map.Gun_Controls_Destroyed );
	OnTrigger( "Axis capture the West Bunker!", Map.westbunker_flag_Axis_Captured );
	OnTrigger( "Allies capture the Forward Bunker!", Map.westbunker_flag_Allies_Captured );
	OnTrigger( "Planted at the Gun Controls.", Map.Controls_Plant );
	OnTrigger( "Defused at the Gun Controls.", Map.Controls_Defuse );
	OnTrigger( "frontdoor_right_goto", Map.front_door_right );
	OnTrigger( "leftdoor_right_goto", Map.left_door_right );
	OnTrigger( "rightdoor_right_goto", Map.right_door_right );
	OnTrigger( "frontdoor_lever1_goto", Map.front_door_lever );
	OnTrigger( "leftdoor_lever1_goto", Map.left_door_lever );
	OnTrigger( "rightdoor_lever1_goto", Map.right_door_lever );
	OnTrigger( "hatch_start", Map.hatch_start );

	// detect if the back door can be planted
	//bd = Util.GoalTable("PLANT_Back_Door");
	//if ( tableCount(bd) > 0 )
	//{
		//OnTrigger( "^1Note: ^3Allies have destroyed the Backdoor - Axis need to rebuild it.", Map.Back_Door_Destroyed ); // NoQuarter colored notes
		//OnTrigger( "Allies have destroyed the Backdoor.", Map.Back_Door_Destroyed ); // default
	//}

	// etpro script detection
	Map.EastBunkerMgs = tableCount(Util.GoalTable("MOUNTMG42_eastbunker_mg42.*"));

	OnTriggerRegion(Vector3(2336,-4161,920), 200, Map.BaseTrigger);
	OnTriggerRegion(AABB(3638.603,-4191.351,1151.125,3776.875,-4079.821,1225.125), Map.Axis_Fallback);
	OnTriggerRegion(AABB(3014.064,-3574.636,895.125,3170.968,-3466.865,969.125), Map.Axis_Fallback);
	OnTriggerRegion(AABB(3584.027,-3782.805,895.125,3662.790,-3651.899,969.125), Map.Axis_Fallback);

	// Max users per goal
	Util.SetMaxUsers( 1, {"DEFEND.*", "SWITCH.*", "GRENADE.*", "MOUNT.*", "BUILD_Axis_North_W.*MG_nest", "BUILD_Axis_South_East_MG_nest", "BUILD_Generator"} );
	Util.SetMaxUsersInProgress( 15, "CHECKPOINT.*" );

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

	SetGoalPriority( "SWITCH_.*", 0.65 );
	SetGoalPriority( "DEFEND_gc_flex.*", 0.49, TEAM.AXIS );
	SetGoalPriority( "PLANT_Gun_Controls", 0.85, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_Allied_West_beach_MG_nest", 0.93, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_Allied_Beach_Assault_Ramp", 0.92, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_Allied_East_beach_MG_nest", 0.91, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Generator", 0, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Axis_North_W.*MG_nest", 0, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Axis_Main_Bunker_MG_nest", 0, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Axis_South_East_MG_nest", 0, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Generator", 0.83, TEAM.ALLIES, CLASS.COVERTOPS );
	SetGoalPriority( "PLANT_Axis_North_W.*MG_nest", 0.82, TEAM.ALLIES, CLASS.COVERTOPS );
	SetGoalPriority( "PLANT_Axis_Main_Bunker_MG_nest", 0.81, TEAM.ALLIES, CLASS.COVERTOPS );
	SetGoalPriority( "BUILD_Generator", 0.93, TEAM.AXIS, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_Axis_North_W.*MG_nest", 0.92, TEAM.AXIS, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_Axis_Main_Bunker_MG_nest", 0.91, TEAM.AXIS, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Allied_Beach_Assault_Ramp", 0, TEAM.AXIS, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Allied_Beach_Assault_Ramp", 0.81, TEAM.AXIS, CLASS.COVERTOPS );
	SetGoalPriority( "DEFUSE_Axis_South_East_MG_nest.*", 0, TEAM.AXIS, CLASS.ENGINEER, true );
	SetGoalPriority( "DEFUSE_Command_Post.*", 0, TEAM.AXIS, CLASS.ENGINEER, true );

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

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"ATTACK_Beach_.*",
		"GRENADE_westbunkermg",
		"GRENADE_westbunkermg1",
		"SMOKEBOMB_westbunkermg",
		"SMOKEBOMB_westbunker",
		"SMOKEBOMB_assaultramp",
		"AIRSTRIKE_bRamp.*",
		"BUILD_Allied_Beach_Assault_Ramp",
		"MOBILEMORTAR_bUpperBunker1",
		"BUILD_Allied_West_beach_MG_nest",
		"MOUNTMG42_Allied_West_beach_MG_nest",
		"REPAIRMG42_Allied_West_beach_MG_nest",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_Flag_.*",
		"PLANT_Allied_Beach_Assault_Ramp",
		"CALLARTILLERY_ramparty1",
		"CALLARTILLERY_ramparty2",
		"ARTILLERY_S_573",
		"CHECKPOINT_westbunker_flag",
		"MOUNTMG42_westbunker_mg42_1",
		"MOUNTMG42_westbunker_mg42_2",
		"MOUNTMG42_Axis_North_W.*MG_nest",
		"REPAIRMG42_westbunker_mg42_1",
		"REPAIRMG42_westbunker_mg42_2",
		"REPAIRMG42_Axis_North_W.*MG_nest",
		"BUILD_Axis_North_W.*MG_nest", // overlooks ramp
		"BUILD_Axis_Main_Bunker_MG_nest",
		"BUILD_Axis_South_East_MG_nest",
		"BUILD_Generator",
		"MOBILEMORTAR_ramp",
		"TRIPMINE_bunker1",
	});

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

global OnBotJoin = function( bot )
{
	// default spawn
	if ( bot.GetTeam() == TEAM.ALLIES ) {
		if ( Map.flagstatus == 2 ) {
			bot.ChangeSpawnPoint(5);
		}
		else {
			bot.ChangeSpawnPoint(3);
		}
	}
	else {
		if ( Map.flagstatus != 2 ) {
			bot.ChangeSpawnPoint(5);
		}
		else {
			bot.ChangeSpawnPoint(1);
		}
	}
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		PLANT_Gun_Controls =
		{
			ROUTE_FlagSpawn =
			{
				ROUTE_fdoor_route =
				{
					ROUTE_hatchroute =
					{
						ROUTE_hatchroute2 =
						{
							ROUTE_eastdoor = {},
							ROUTE_westdoor = {},
							ROUTE_weststairs =
							{
								ROUTE_westladder = {},
								ROUTE_eastladder = {},
							},
						},
					},
					ROUTE_southstairs =
					{
						ROUTE_guntop =
						{
							ROUTE_westladder = {},
							ROUTE_eastladder = {},
						},
					},
				},
				ROUTE_radar_route =
				{
					ROUTE_hatchroute = {},
					ROUTE_southstairs = {},
				},
			},
		},
	};
	MapRoutes["DEFEND_Gun_.*"] =
	{
		ROUTE_AxisSpawn =
		{
			ROUTE_hatchroute =
			{
				ROUTE_hatchroute2 =
				{
					ROUTE_eastdoor = {},
					ROUTE_westdoor = {},
					ROUTE_weststairs =
					{
						ROUTE_westladder = {},
						ROUTE_eastladder = {},
					},
				},
			},
			ROUTE_southstairs =
			{
				Weight = 2,
				ROUTE_southstairs2 = { Weight = 2, },
				ROUTE_guntop = {},
			},
		},
	};
	MapRoutes["DEFEND_Flag_.*"] =
	{
		ROUTE_AxisSpawn =
		{
			ROUTE_flagroute = { Weight = 3 },
			ROUTE_gunpatrol = {},
			ROUTE_southstairs =
			{
				ROUTE_guntop = { ROUTE_guntop = {}, },
			},
		},
	};

	//copy some routes
	MapRoutes["ATTACK_Gun.*"] = MapRoutes.PLANT_Gun_Controls;

	r =
	{
		ROUTE_AxisSpawn =
		{
			ROUTE_westladder = { ROUTE_gunpatrol2 = {}, },
			ROUTE_eastladder = { ROUTE_gunpatrol = {}, },
		},
	};
	MapRoutes["MOUNTMG42_west.*"] = r;
	MapRoutes["MOUNTMG42_Axis.*"] = r;
	MapRoutes["REPAIRMG42_west.*"] = r;
	MapRoutes["REPAIRMG42_Axis.*"] = r;
	MapRoutes.BUILD_Generator = r;
	MapRoutes["BUILD_Axis.*"] = r;

	if ( Map.EastBunkerMgs )
	{
		MapRoutes["MOUNTMG42_east.*"] = r;
		MapRoutes["REPAIRMG42_east.*"] = r;
	}

	Util.Routes(MapRoutes);
};
