global Map =
{
	DispenseAmmoTime = 10,
	DontDispenseAmmo = true,

	//set status' for conditionals
	//FlagStatus = 0, //0 nobody, 1 axis, 2 allies
	DocsGone = false, //may be grabbed, but not out of meeting room
	DocStatus = false, //home
	MainDoorStatus = false, //intact
	TowerDoorStatus = false, //intact

	East_Tower_Door_Destroyed = function( trigger )
	{
		Map.TowerDoorStatus = true;

		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_main_defend_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ATTACK_main_attack_1",
			"ATTACK_main_attack_3",
		});

		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_main_defend_1",
			"DEFEND_doc_defend_.*",
			"DEFEND_doc_panzer_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"CHECKPOINT_beach_flag",
			"FLAG_sec_docs",
		});

		//allies should plant tower first
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Main_.*" );

		SetGoalPriority( "CALL.*", 0.6 );
		SetGoalPriority( "ARTILLLERY.*", 0.6 );

		Util.MapDebugPrint( "East_Tower_Door_Destroyed" );
	},

	East_Tower_Door_Planted = function( trigger )
	{
		//don't bother trying to defuse this
		Util.DisableGoal( "DEFUSE_East_Tower.*" );

		Util.MapDebugPrint( "East_Tower_Door_Planted" );
	},

	Main_Entrance_Destroyed = function( trigger )
	{
		Map.MainDoorStatus = true;

		if ( !Map.DocStatus ) {
			SetAvailableMapGoals( TEAM.ALLIES, false, {
				"ATTACK_main_attack_2",
				"ATTACK_main_attack_4",
			});
		}

		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_main_defend_1" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"ROUTE_main_entrance",
			"ROUTE_docdel2",
			"ROUTE_docdel3",
		});

		SetGoalPriority( "CALL.*", 0.0 );

		WeaponTable.SetWeaponAvailability(CLASS.SOLDIER, WEAPON.FLAMETHROWER, true);

		Util.MapDebugPrint( "Main_Entrance_Destroyed " );
	},

	Main_Entrance_Planted = function( trigger )
	{
		//don't bother trying to defuse this
		Util.DisableGoal( "DEFUSE_Main_Entrance.*" );

		Util.MapDebugPrint( "Main_Entrance_Planted" );
	},

	Decoder_Manual_Taken = function( trigger )
	{
		Map.DocStatus = 1;

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_doc_defend_.*",
			"DEFEND_doc_panzer_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_main_defend_1",
			"DEFEND_main_defend_3",
			"DEFEND_main_defend_4",
			"DEFEND_axis_doc_del_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"ATTACK_main_attack_.*",
			"ATTACK_allies_doc_del_.*",
		});

		// some axis should stay at meeting room until doc carrier is out
		if ( !Map.DocsGone ) {
			SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_rMeeting.*" );
		}

		// Hold the enemy in the bunker/forest respectivly
		SetGoalPriority( "CALL.*", 0.7 );
		SetGoalPriority( "ARTILLLERY.*", 0.7 );

		Util.MapDebugPrint( "Decoder_Manual_Taken" );
	},

	Decoder_Manual_Returned = function( trigger )
	{
		Map.DocStatus = 0;

		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_doc_defend_.*",
			"DEFEND_doc_panzer_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_main_defend_1",
			"DEFEND_main_defend_3",
			"DEFEND_main_defend_4",
			"DEFEND_axis_doc_del_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ATTACK_main_attack_.*",
			"ATTACK_allies_doc_del_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_rMeeting.*" );

		// CEASE FIRE!! Protect docs
		SetGoalPriority( "CALL.*", 0.0 );
		SetGoalPriority( "ARTILLLERY.*", 0.0 );

		Util.MapDebugPrint( "Decoder_Manual_Returned" );
	},

	beach_flag_Axis_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_beach_flag" );

		Util.MapDebugPrint( "beach_flag_Axis_Captured " );
	},

	beach_flag_Allies_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT_beach_flag" );

		// dont call arty as much
		SetGoalPriority( "CALL.*", 0.5 );
		SetGoalPriority( "ARTILLLERY.*", 0.5 );

		Util.MapDebugPrint( "beach_flag_Allies_Captured" );
	},

	FoyerTrigger =
	{
		Name = "FoyerTrigger",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function( ent )
		{
			if ( GetEntTeam( ent ) == TEAM.ALLIES ) {
				if ( GetEntFlags( ent, ENTFLAG.CARRYINGGOAL ) ) {
					//docs are gone
					Map.DocsGone = true;
					SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_rMeeting.*" );
				}
			}
		},
	},
};

global OnMapLoad = function()
{
	OnTrigger( "East Tower Door Destroyed.", Map.East_Tower_Door_Destroyed );
	OnTrigger( "Planted at East Tower Door.", Map.East_Tower_Door_Planted );
	OnTrigger( "The Main Entrance Destroyed.", Map.Main_Entrance_Destroyed );
	OnTrigger( "The Main Complex Door has been breeched!", Map.Main_Entrance_Destroyed );
	OnTrigger( "Planted at The Main Entrance.", Map.Main_Entrance_Planted );
	OnTrigger( "Allies have stolen The Decoder Manual!", Map.Decoder_Manual_Taken );
	OnTrigger( "Flag returned Decoder Manual!", Map.Decoder_Manual_Returned );
	OnTrigger( "Axis reclaims the Forward Bunker!", Map.beach_flag_Axis_Captured );
	OnTrigger( "Allies capture the Forward Bunker!", Map.beach_flag_Allies_Captured );

	tOne = OnTriggerRegion( AABB( 528,-2458,739, 636, -1832, 814 ), Map.FoyerTrigger );

	SetMapGoalProperties( "ATTACK_.*", {mincamptime = 15, maxcamptime = 30} );
	SetMapGoalProperties( "DEFEND_.*", {mincamptime = 15, maxcamptime = 30} );
	SetMapGoalProperties( "SNIPE_.*", {mincamptime = 35, maxcamptime = 60} );

	//disable all goals at start
	Util.DisableGoal( ".*", true ); //all but routes

	Util.EnableGoal( "CAPPOINT_.*" );

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

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"ATTACK_main_attack_.*",
		"PLANT_East_Tower_Door",
	});
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"ROUTE_main_entrance",
		"ROUTE_docdel2",
		"ROUTE_docdel3",
	});

	// Arty
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"CALLARTILLERY_spot_allied",
		"ARTILLERY_S_axis_tower",
		"ARTILLERY_S_axis_bunker",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, "ARTILLERY_S_forest_[1234]" );

	SetGoalPriority( "CALL.*", 1.5 );
	SetGoalPriority( "ARTILLLERY.*", 1.5 );
	SetGoalPriority( "DEFEND_rMeeting.*", 0.6 );
	SetGoalPriority( "DEFEND_axis_doc_del_.*", 0.7 );

	Util.SetMaxUsers( 1, "DEFEND.*" );

	// Default Status'
	//Map.FlagStatus = 0; //nobody owns it
	Map.DocStatus = false; //at home
	Map.MainDoorStatus = false; //intact
	Map.SideWallStatus = false; //intact

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

	Maproutes =
	{
		FLAG_sec_docs =
		{
			ROUTE_allies_spawn =
			{
				ROUTE_forward_spawn =
				{
					ROUTE_main_hall = {},
					ROUTE_vents = {},
				},
				ROUTE_main_entrance =
				{
					ROUTE_storage_tunnel = {},
					ROUTE_meeting_room = {},
				},
			},
			ROUTE_forward_spawn =
			{
				ROUTE_main_entrance =
				{
					ROUTE_storage_tunnel = {},
					ROUTE_meeting_room = {}
				},
				ROUTE_main_hall =
				{
					ROUTE_vents = {},
					ROUTE_meeting_room = {},
				},
			},
		},
		CAPPOINT_74 =
		{
			ROUTE_docgrab =
			{
				Weight = 2,
				ROUTE_docdel1 = {},
				ROUTE_docdel2 = {},
				ROUTE_docdel3 = {},
			},
		},
	};

	Util.Routes( Maproutes );
	Util.MapDebugPrint( "OnMapLoad" );
};

global OnBotJoin = function( bot )
{
	bot.MaxViewDistance = 2000.0;
};
