global Map =
{
	Talk = true,

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

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

	construction_script_Built = function( trigger )
	{
		Wp.SetWaypointFlag("Ladder2","closed",false);
		Util.MapDebugPrint( "construction_script_Built" );
	},

	construction_script_Destroyed = function( trigger )
	{
		Wp.SetWaypointFlag("Ladder2","closed",true);
		Util.MapDebugPrint( "construction_script_Destroyed" );
	},

	storagewall_Destroyed = function( trigger )
	{
		Map.WallDestroyed = true;
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"FLAG_War_Documents",
			"ATTACK_documents.*",
		});

		Util.MapDebugPrint( "storagewall_Destroyed" );
	},

	basewall_Dyno_Planted = function( trigger )
	{
		if ( Map.Talk && MAP_TALK )
		{
			wppos = Util.GetWpNamePosition( "start4" );
			foreach ( id and bot in BotTable )
			{
				if ( bot.GetTeam() == TEAM.AXIS && bot.GetClass() != CLASS.ENGINEER && GetGameTimeLeft()>120 )
				{
					ran = RandRange(0,10);
					if( ran<3 && bot.DistanceTo(wppos)<800 && !bot.GetNearestAlly(CAT.PLAYER,CLASS.ENGINEER) )
					{
						sleep(ran);
						bot.SayVoice(VOICE.NEED_ENGINEER);
					}
					else if( ran>9 )
					{
						sleep(ran-8);
						bot.SayVoice(VOICE.DISARM_DYNAMITE);
					}
				}
			}
		}

		Util.MapDebugPrint( "basewall_Dyno_Planted" );
	},

	basewall_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Allied_Command_Post",
			"ATTACK_sidewall",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, "SNIPE_start.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "SNIPE_allied_commandpost" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "SNIPE_allied_commandpost" );
		SetAvailableMapGoals( TEAM.AXIS, true, "SNIPE_documents.*" );

		if ( Map.Talk && MAP_TALK )
		{
			rand = ETUtil.CountTeam(TEAM.AXIS) * 2;
			rand2 = ETUtil.CountTeam(TEAM.ALLIES) * 2;
			foreach ( gameId and bot in BotTable )
			{
				if (bot.GetTeam() == TEAM.AXIS && RandInt(0,rand) < 2 && GetGameTimeLeft()>120)
				{
					sleep(RandRange(1,2.5));
					bot.SayVoice(VOICE.DEFEND_OBJECTIVE);
				}
				else if (bot.GetTeam() == TEAM.AXIS && RandInt(0,rand) < 2 && GetGameTimeLeft()>120)
				{
					sleep(RandRange(1,2.0));
					bot.ExecCommand("vsay_team FTFallBack");
				}
				else if (bot.GetTeam() == TEAM.AXIS && RandInt(0,rand) < 2 && GetGameTimeLeft()>120)
				{
					sleep(RandRange(1,2.0));
					bot.SayVoice(VOICE.REINFORCE_DEF);
				}
				if (bot.GetTeam() == TEAM.ALLIES && RandInt(0,rand2) < 2 && GetGameTimeLeft()>120)
				{
					sleep(RandRange(1,2.8));
					bot.SayVoice(VOICE.REINFORCE_OFF);
				}
				else if (bot.GetTeam() == TEAM.ALLIES && RandInt(1,rand2) < 2 && GetGameTimeLeft()>300)
				{
					sleep(1.5);
					bot.SayVoice(VOICE.G_CHEER);
				}
				else if (bot.GetTeam() == TEAM.ALLIES && RandInt(1,rand2) < 2 && GetGameTimeLeft()>120)
				{
					sleep(1.5);
					bot.ExecCommand("vsay_team FTAttack");
				}
			}
		}
		Util.MapDebugPrint( "basewall_Destroyed" );
	},

	Allies_Capture_Flag = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT_forwardspawn1_flag" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"REPAIRMG42_Spawn_MG42",
			"MOUNTMG42_Spawn_MG42",
			"BUILD_Field_MG42",
			"BUILD_Spawn_MG42",
			"BUILD_Fortress_Ladder",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"PLANT_Spawn_MG42",
			"PLANT_Field_MG42",
			"PLANT_Fortress_Ladder",
			"DEFEND_start.*",
		});
		Util.MapDebugPrint( "Allies_Capture_Flag" );
	},

	Axis_Capture_Flag = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Spawn_MG42",
			"BUILD_Field_MG42",
			"BUILD_Fortress_Ladder",
		});
		if (!Map.WallDestroyed)
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, "REPAIRMG42_Spawn_MG42" );
			SetAvailableMapGoals( TEAM.AXIS, true, "MOUNTMG42_almg3" );
			SetAvailableMapGoals( TEAM.ALLIES, true, "MOUNTMG42_Spawn_MG42" );
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"PLANT_Field_MG42",
				"PLANT_Spawn_MG42",
				"PLANT_Fortress_Ladder",
			});
		}
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_start.*" );
		Util.MapDebugPrint( "Axis_Capture_Flag" );
	},

	Docs_Stolen = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "SNIPE_allied_commandpost" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "SNIPE_allied_commandpost" );
		SetAvailableMapGoals( TEAM.AXIS, true, "SNIPE_drop_point.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"PLANT_Allied_Command_Post",
			"DEFEND_documents.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_drop_point.*",
			"DEFEND_sidewall",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_drop_point.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_documents.*" );

		if (Map.Talk)
		{
			// find the bot who just got the docs:
			foreach ( gameId and bot in BotTable )
			{
				if( GetEntFlags(bot.GetGameEntity(), ENTFLAG.CARRYINGGOAL) && RandInt(1,2)==1 )
				{
					bot.SayVoice(VOICE.G_CHEER);
					// perhaps do something more useful here
				}
			}
		}
		Util.MapDebugPrint( "Docs Stolen" );
	},

	Docs_Returned = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "SNIPE_allied_commandpost" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "SNIPE_allied_commandpost" );
		SetAvailableMapGoals( TEAM.AXIS, false, "SNIPE_drop_point.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Allied_Command_Post" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_drop_point.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_documents.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_sidewall" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_drop_point.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_documents.*" );
		Util.MapDebugPrint( "Docs Returned" );
	},
};

global OnMapLoad = function()
{
	OnTrigger( "Allied team has constructed the Spawn MG42!", Map.allied_mg1_Built );
	OnTrigger( "The Field MG42 has been constructed.", Map.allied_mg2_Built );
	OnTrigger( "The fortress Ladder has been constructed.", Map.construction_script_Built );
	OnTrigger( "The fortress Ladder has been destroyed.", Map.construction_script_Destroyed );
	OnTrigger( "Allies have destroyed the Storage Wall!", Map.storagewall_Destroyed );
	OnTrigger( "Planted at the Base Wall.", Map.basewall_Dyno_Planted );
	OnTrigger( "Allies have destroyed the Base Wall!", Map.basewall_Destroyed );
	OnTrigger( "Allies capture the Tower Spawn!", Map.Allies_Capture_Flag );
	OnTrigger( "Axis capture the Tower Spawn!", Map.Axis_Capture_Flag );
	OnTrigger( "Allies have stolen the War Documents!", Map.Docs_Stolen );
	OnTrigger( "Flag returned War Documents!", Map.Docs_Returned);

	SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_.*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"ATTACK_.*",
		"PLANTMINE_.*",
		"DEFEND_.*",
	});
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_.*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "SNIPE_.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"SNIPE_.*",
		"CHECKPOINT_forwardspawn1_flag",
		"REPAIRMG42_Spawn_MG42",
		"REPAIRMG42_Field_MG42",
		"MOUNTMG42_Spawn_MG42",
		"MOUNTMG42_Field_MG42",
	});
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"BUILD_Allied_Command_Post",
		"MOBILEMG42_.*",
	});
	SetAvailableMapGoals( TEAM.AXIS, false, "MOBILEMG42_.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, "MOBILEMG42_docs.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"MOBILEMG42_docs4",
		"MOBILEMG42_docs5",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_documents.*",
		"DEFEND_start.*",
		"SNIPE_start.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_documents.*" );

	// Set Map Goal Properties
	SetMapGoalProperties( "ATTACK_.*", {MinCampTime=2, MaxCampTime=10} );
	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=3, MaxCampTime=40} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=10, MaxCampTime=60} );

	Util.SetMaxUsersInProgress( 3, "FLAG_War_Documents" );
	Util.SetMaxUsersInProgress( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsersInProgress( 1, "CHECKPOINT_forwardspawn1_flag" );
	Util.SetMaxUsersInUse( 1, "CHECKPOINT_forwardspawn1_flag" );
	Util.SetMaxUsersInProgress( 1, "DEFEND_start.*" );
	Util.SetMaxUsersInProgress( 1, "DEFEND_documents.*" );

	SetGoalPriority("PLANT_Base_Wall", 0.9, TEAM.ALLIES, CLASS.ENGINEER);

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"FLAG_War_Documents",
		"CAPPOINT_Transmitter",
	});

	Util.SetGoalPosition( -243.496, -63.046, 56.125, "PLANT_Base_Wall" );
	Wp.SetWaypointFlag("Ladder2","closed",true);

	// *** Routing ***
	MapRoutes =
	{
		ATTACK_documents17 =
		{
			ROUTE_allied_spawn =
			{
				ROUTE_tunnel1 = {},
				ROUTE_main_gate =
				{
					ROUTE_tunnel1 = {},
				},
			},
			ROUTE_tower_spawn =
			{
				ROUTE_tunnel1 = {},
			},
		},
		FLAG_War_Documents =
		{
			ROUTE_tower_spawn =
			{
				ROUTE_tunnel1 = {},
				ROUTE_documents_24 = {},
			},
			ROUTE_allied_spawn =
			{
				ROUTE_main_gate =
				{
					ROUTE_tunnel1 =
					{
						ROUTE_documents17 = {},
					},
				},
				ROUTE_ladder_route1 =
				{
					ROUTE_ladder_route2 = {},
				},
				ROUTE_tunnel1 =
				{
					ROUTE_documents17 = {},
				},
			},
		}
	};

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

global OnBotJoin = function( bot )
{
};
