global Map =
{
	Quiet = true,
	FocusPrimary = false,
	DispenseAmmoTime = 15,

	Ammo_Cabinet_south_ammocabinet = "AMMOCAB_south_ammocabinet",
	Ammo_Cabinet_south_ammocabinet_1 = "AMMOCAB_south_ammocabinet_1",
	Health_Cabinet_south_healthcabinet = "HEALTHCAB_south_healthcabinet",
	Health_Cabinet_south_healthcabinet_1 = "HEALTHCAB_south_healthcabinet_1",
	Call_Artillery_bCemetary_1 = "CALLARTILLERY_bCemetary_1",
	Call_Artillery_rCemetary_1 = "CALLARTILLERY_rCemetary_1",
	Call_Artillery_rCemetary_2 = "CALLARTILLERY_rCemetary_2",
	Artillery_S_bCemetary_1 = "ARTILLERY_S_bCemetary_1",
	Artillery_S_rCemetary_1 = "ARTILLERY_S_rCemetary_1",
	Checkpoint_northflag = "CHECKPOINT_northflag",
	Flag_obj_item01 = "FLAG_obj_item01",
	Cappoint_truck = "CAPPOINT_truck",
	Build_Command_Post = "BUILD_Command_Post",
	Plant_Command_Post = "PLANT_Command_Post",
	Plant_Gold_Storage_Crypt = "PLANT_Gold_Storage_Crypt",
	Mount_cemetary_mg = "MOUNTMG42_cemetary_mg",
	Mount_central_cyd_mg = "MOUNTMG42_central_cyd_mg",
	Mount_cottage_mg = "MOUNTMG42_cottage_mg",
	Mount_west_cyd_mg = "MOUNTMG42_west_cyd_mg",
	Repair_cemetary_mg = "REPAIRMG42_cemetary_mg",
	Repair_central_cyd_mg = "REPAIRMG42_central_cyd_mg",
	Repair_cottage_mg = "REPAIRMG42_cottage_mg",
	Repair_west_cyd_mg = "REPAIRMG42_west_cyd_mg",

	CryptStatus = false, //intact
	CryptDyno = 0, //counter
	GoldStatus = false, //home
	AlliesNearCrypt = false,

	RoundStart = true,
	IncomingCalled = false,

	FriendlyFire,

	Navigation =
	{
		// cs: from ledge by destroyed cottage to boxes
		tjump =
		{
			navigate = function(_this)
			{
				sleep(0.25);
				_this.Bot.HoldButton(BTN.JUMP, 0.5);
				_this.Bot.HoldButton(BTN.SPRINT, 3);
				sleep(0.25);
				_this.Bot.HoldButton(BTN.STRAFE_R, 0.5);
				sleep(0.51);
				_this.Bot.HoldButton(BTN.JUMP, 2);
				_this.Bot.HoldButton(BTN.FORWARD, 1);
				sleep(3);
			},
		},
	},

	Airstrike =
	{
		sladder =
		{
			Enabled = true,
			Team = (1<<TEAM.ALLIES), // or (1<<TEAM.AXIS) or (1<<TEAM.ALLIES)
			Facing = Vector3(0.683,-0.132,0.718), // use this if no goto waypoint. /bot mypos shows facing
			NoPause = true, // optional: set this if you want them throw while running
		},
		bridge =
		{
			Enabled = true,
			Team = (1<<TEAM.AXIS), // or (1<<TEAM.AXIS) or (1<<TEAM.ALLIES)
			Waypoint = "bridge_as", // optional: defining this will have them go to given waypoint and then throw a/s
		},
	},

	CryptTrigger =
	{
		Name = "StairsTrigger",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			if( !Map.AlliesNearCrypt && GetEntTeam(ent) == TEAM.ALLIES && !Map.CryptStatus )
			{
				if ( GetEntClass(ent) == CLASS.ENGINEER )
				{
					Map.AlliesNearCrypt = true;
					Util.LimitToClass("CHECKPOINT.*", TEAM.AXIS, CLASS.SOLDIER);
					SetAvailableMapGoals( TEAM.AXIS, false, {
						"DEFEND_.*",
						"CAMP_rCottage.*",
						"AIRSTRIKE_rTavernAS_1",
					});
					SetAvailableMapGoals( TEAM.AXIS, true, {
						"DEFEND_rCrypt.*",
						"CAMP_rCellar.*",
					});
					SetAvailableMapGoals( TEAM.AXIS, false, {
						"DEFEND_rFlag.*",
						"CAMP_cd.*",
					});
					Util.OneBotVSayTeam(TEAM.AXIS, VOICE.DEFEND_OBJECTIVE);
					SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Command_Post" );
				}
				else if ( Map.RoundStart )
				{
					SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_rFlag.*" );

					if ( !Map.IncomingCalled ) // heard you the first time noob
					{
						Map.IncomingCalled = true;
						Util.OneBotVSayTeam(TEAM.AXIS, VOICE.INCOMING);
					}
				}
			}
		},
	},

	Defend =
	{
		MaxBots = 1,
		Users = {},
	},

	Gold_Storage_Crypt_Destroyed= function( trigger )
	{
		Map.CryptStatus = true;
		Map.CryptDyno = 0;

		SetAvailableMapGoals( TEAM.ALLIES, true, Map.Flag_obj_item01 );
		SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT.*" );

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ARTILLERY_S.*",
			"CALLARTILLERY.*",
		});
	},

	Gold_Storage_Crypt_Planted = function( trigger )
	{
		Map.CryptDyno += 1;
	},

	Gold_Storage_Crypt_Defused = function( trigger )
	{
		Map.CryptDyno -= 1;
	},

	obj_item01_Taken = function( trigger )
	{
		Map.GoldStatus = true;

		Util.SetMaxUsersInProgress( 1, "CHECKPOINT.*" );	//Martin - Ok Ken, at least let only 1 axis go for it instead of all the soldiers.

		//spawn back
		Util.ChangeSpawn( TEAM.ALLIES, 1);

		// axis soldier will grab flag if a minimum of 5 axis are alive
		if ( !ETUtil.IsTeamDead( TEAM.AXIS, 5 ) )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT.*" );
		}
		else
		{
			Util.DisableGoal("CHECKPOINT.*", true);
		}

		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_bDeliver.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ATTACK_bCemetary.*",
			"MOUNTMG42_cemetary_mg",
		});

		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_rDeliver.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_rCrypt.*",
			"CAMP_rCellar.*",
			"ARTILLERY_S.*",
			"CALLARTILLERY.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"AIRSTRIKE_rTruckAS.*",
			"ARTILLERY_S_rDeliverArt.*",
		});
		Util.DisableGoal("PLANT_Command_Post");

		Map.Airstrike.sladder.Enabled = false;
	},

	obj_item01_Returned = function ( trigger )
	{
		Map.GoldStatus = false;

		Util.SetMaxUsersInProgress( 64, "CHECKPOINT.*" );	//Martin - Anyone can go for it now...

		//spawn default
		Util.ChangeSpawn( TEAM.ALLIES, 0);

		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_bDeliver.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"ATTACK_bCemetary.*",
			"MOUNTMG42_cemetary_mg",
			"CHECKPOINT.*",
		});

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"CHECKPOINT.*",
			"DEFEND_rDeliver.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_rCrypt.*",
			"CAMP_rCellar.*",
			"ARTILLERY_S_rCemetary_.*",
			"CALLARTILLERY_rCemetary_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"ARTILLERY_S_rDeliverArt.*",
			"AIRSTRIKE_rTruckAS.*",
		});
		Util.EnableGoal("PLANT_Command_Post");

		if ( Map.FriendlyFire < 1 )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, "ARTILLERY_S_rCrypt_.*" );
		}

		Map.Airstrike.sladder.Enabled = true;
	},

	truck_Captured = function( trigger )
	{
	},

	allied_flag01_Axis_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ARTILLERY_S.*",
			"CALLARTILLERY.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"ARTILLERY_S.*",
			"CALLARTILLERY.*",
		});
	},

	allied_flag01_Allies_Captured = function( trigger )
	{
		Map.RoundStart = false;

		if ( !Map.CryptStatus && !Map.GoldStatus)
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, Map.Plant_Crypt );
			SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT.*" );
		}

		if ( !Map.GoldStatus )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"DEFEND_rCrypt.*",
				"CAMP_rCellar.*",
			});
			SetAvailableMapGoals( TEAM.AXIS, false, {
				"DEFEND_rTavern.*",
				"CAMP_rCottage.*",
				"AIRSTRIKE_rTavernAS_1",
			});

			SetAvailableMapGoals( TEAM.ALLIES, true, {
				"ATTACK_bCemetary.*",
				"CAMP_bSpawnCamp.*",
				"MOUNTMG42_cemetary_mg",
				"ARTILLERY_S_bCemetary_.*",
				"CALLARTILLERY_bCemetary_.*",
			});
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"ARTILLERY_S_rCemetary_.*",
				"CALLARTILLERY_rCemetary_.*",
			});
			SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Command_Post" );
			Util.EnableGoal("PLANT_Command_Post");
			SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Command_Post" );

			if ( Map.FriendlyFire < 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, true, "ARTILLERY_S_rCrypt_.*" );
			}
		}

		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Gold_Storage_Crypt" );
		Map.Airstrike.bridge.Enabled = false;
	},

	two_minute = function( trigger )
	{
		//time is low, so start focusing on main obj
		Map.FocusPrimary = true;

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

		if ( !Map.CryptStatus )
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, {
				Map.Plant_Crypt,
				"ATTACK_bCemetary.*",
				"MOUNTMG42_cemetary_mg",
				"CAMP_bSpawnCamp.*",
			});
		}
	},

	spawnkill = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_.*",
			"CAMP_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_rSpawnkill.*" );
		//SetAvailableMapGoals( TEAM.AXIS, true, "CAMP_rSpawnkill.*" );

		//Map.AxisASTable = {"rSpawnkill_1",};
	},
};

global OnMapLoad = function()
{
	// close up the 9 waypoints used in checkpoint mode
	for ( i = 1; i < 10; i = i + 1 )
	{
		s = "cpspawn" + i;
		Wp.SetWaypointFlag( s, "closed", true );
	}

	Util.SetGoalPosition( -382, 4726, -19, "PLANT_Gold_Storage_Crypt" );

	Map.FriendlyFire = GetCvar("g_friendlyfire");

	OnTrigger( "Gold Storage Crypt Destroyed.", Map.Gold_Storage_Crypt_Destroyed );
	OnTrigger( "Allies have stolen ^1the Gold!", Map.obj_item01_Taken );
	OnTrigger( "Flag returned obj_item01!", Map.obj_item01_Returned );
	OnTrigger( "^1Axis have reclaimed the Northwest Courtyard!", Map.allied_flag01_Axis_Captured );
	OnTrigger( "^1Allies have captured the Northwest Courtyard!", Map.allied_flag01_Allies_Captured );
	OnTrigger( "Planted at Gold Storage Crypt.", Map.Gold_Storage_Crypt_Planted );
	OnTrigger( "Defused at Gold Storage Crypt.", Map.Gold_Storage_Crypt_Defused );
	OnTrigger( " The Allies have escaped with the Gold!", Map.truck_Captured );
	OnTrigger( "two minute warning.", Map.two_minute );

	//some triggers to help bots know when to aggressively defend crypt
	tOne = OnTriggerRegion(Vector3(67,3056,-110), 200, Map.CryptTrigger);
	tTwo = OnTriggerRegion(Vector3(-1050,3674,-247), 275, Map.CryptTrigger);

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

	Util.DisableGoal(".*", true);
	ETUtil.SetPrimaryGoals(1.0);
	Util.EnableGoal("CAPPOINT.*");

	SetGoalPriority( "DEFEND_rCrypt[1234]", 0.6 );
	SetGoalPriority( "ATTACK_bDeliver7", 0.6 );
	SetGoalPriority( "DEFEND_rDeliver[12]", 0.6 );
	SetGoalPriority( "DEFEND_rFlag.*", 0.6 );
	SetGoalPriority( "GRENADE.*", 0.99 );
	SetGoalPriority( "CAMP_cd.*", 0.85 );
	Util.LimitToClass( "MOUNTMG42.*", TEAM.ALLIES, CLASS.SOLDIER, CLASS.FIELDOPS );
	Util.LimitToClass( "PLANT_Command_Post.*", TEAM.ALLIES, CLASS.COVERTOPS);
	Util.LimitToClass( "PLANT_Command_Post.*", TEAM.AXIS, CLASS.COVERTOPS);

	Util.SetMaxUsers( 1, "MOUNT.*" );
	Util.SetMaxUsers( 1, "CAMP.*" );
	Util.SetMaxUsers( 1, "ATTACK.*" );
	Util.SetMaxUsers( 1, "DEFEND.*" );
	Util.SetMaxUsers( 1, "GRENADE.*" );

	Util.SetRoleForGoals( "CAMP_cd.*", ROLE.DEFENDER );

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

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"CHECKPOINT.*",
		"GRENADE_block[23]",
	});
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_rTavern.*",
		"CAMP_rCottage.*",
		"GRENADE_block1",
		"AIRSTRIKE_rTavernAS_1",
		"BUILD_Command_Post",
		"CAMP_cd.*",
	});

	Map.AxisASTable = Map.AxisASTavern;

	MapRoutes =
	{
		CHECKPOINT_northflag =
		{
			ROUTE_bSpawn =
			{
				ROUTE_tower =
				{
					Weight=2,
					ROUTE_block3 = {},
					ROUTE_bridge2 = {},
				},
				ROUTE_bridge =
				{
					ROUTE_block2 = { ROUTE_cottage = {}, },
					ROUTE_closet = { ROUTE_ccyd = { ROUTE_cottage = {}, }, },
				},
			},
			ROUTE_bSpawn2 =
			{
				ROUTE_tower =
				{
					ROUTE_block3 = {},
					ROUTE_bridge2 = {},

				},
				ROUTE_bridge =
				{
					ROUTE_block2 = { ROUTE_cottage = {}, },
					ROUTE_closet = { ROUTE_ccyd = { ROUTE_cottage = {}, }, },
				},
			},
		},
		FLAG_obj_item01 =
		{
			ROUTE_flagspawn =
			{
				ROUTE_altFlagSpawn1 =
				{
					ROUTE_altFlagSpawn2 =
					{
						ROUTE_nLadder = { Weight = 2, },
						ROUTE_sLadder = {},
					}
				},
				ROUTE_nLadder = { Weight = 2, },
				ROUTE_sLadder = {},
			},
			ROUTE_bSpawn =
			{
				ROUTE_tower =
				{
					ROUTE_block3 = { ROUTE_tavern = {}, },
					ROUTE_bridge2 = { ROUTE_tavern = {}, },

				},
				ROUTE_bridge =
				{
					ROUTE_block2 = { ROUTE_cottage = {}, },
					ROUTE_closet = { ROUTE_ccyd = { ROUTE_cottage = {}, }, },
				},
			},
		},
		CAPPOINT_truck =
		{
			ROUTE_gold =
			{
				ROUTE_nLadder =
				{
					ROUTE_tavern =
					{
						ROUTE_tower =
						{
							ROUTE_truck = {},
							ROUTE_spawn = {},
						},
					},
				},
			},
		},
		DEFEND_rDeliver1 =
		{
			ROUTE_rSpawn1 =
			{
				ROUTE_closet = {},
				ROUTE_block2 = {},
			},
			ROUTE_rSpawn2 =
			{
				ROUTE_closet = {},
				ROUTE_block2 = {},
			},
		},
	};

	MapRoutes.DEFEND_rDeliver2 = MapRoutes.DEFEND_rDeliver1;
	MapRoutes.DEFEND_rDeliver3 = MapRoutes.DEFEND_rDeliver1;
	MapRoutes.DEFEND_rDeliver4 = MapRoutes.DEFEND_rDeliver1;
	MapRoutes.DEFEND_rDeliver5 = MapRoutes.DEFEND_rDeliver1;
	MapRoutes.DEFEND_rDeliver6 = MapRoutes.DEFEND_rDeliver1;
	MapRoutes.AIRSTRIKE_rTruckAS_1 = MapRoutes.DEFEND_rDeliver1;
	MapRoutes.ATTACK_bCemetary1 = MapRoutes.FLAG_obj_item01;
	MapRoutes.ATTACK_bCemetary2 = MapRoutes.FLAG_obj_item01;
	MapRoutes.ATTACK_bCemetary3 = MapRoutes.FLAG_obj_item01;
	MapRoutes.ATTACK_bCemetary4 = MapRoutes.FLAG_obj_item01;
	MapRoutes.ATTACK_bCemetary5 = MapRoutes.FLAG_obj_item01;
	MapRoutes.ATTACK_bCemetary6 = MapRoutes.FLAG_obj_item01;
	MapRoutes.CAMP_bSpawnCamp1 = MapRoutes.FLAG_obj_item01;
	MapRoutes.CAMP_bSpawnCamp2 = MapRoutes.FLAG_obj_item01;
	MapRoutes.CALLARTILLERY_bCemetary_1 = MapRoutes.FLAG_obj_item01;
	MapRoutes.MOUNTMG42_cemetary_mg = MapRoutes.FLAG_obj_item01;
	MapRoutes.PLANT_Gold_Storage_Crypt = MapRoutes.FLAG_obj_item01;

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

global OnBotJoin = function( bot )
{
	if ( bot.GetTeam() == TEAM.AXIS && bot.GetClass() == CLASS.FIELDOPS )
	{
		if ( tableCount(Map.Defend.Users) < Map.Defend.MaxBots )
		{
			Map.Defend.Users[ bot.GetGameId() ] = true;
			bot.SetRoles(ROLE.DEFENDER);
		}
	}
};
