global Map =
{
	Debug = false,
	lifttop = 1,
	icw_trigger = 0,
	Talk = true,
	DefendingTeam = TEAM.AXIS,

	Switches =
	{
		liftsw =
		{
			Enabled = true,
			Priority = 0.0,
			WaypointName = "liftsw",
			AimPosition = Vec3(2905.383, 2227.875, 2310.797),
			LimitBots = 1,
		}
	},

	Navigation =
	{
		wait =
		{
			navigate = function(_this)
			{
				timeout = 1;
				while ( timeout > 0 ) {
					_this.Goto(_this.Bot.GetPosition());
					sleep(6);
					timeout -= 1;
				}
			},
		},
	},

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

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

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

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

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

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

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

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

	entrance_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( 0, false, {
			"ATTACK_bridge.*",
			"ATTACK_library.*",
			"BUILD.*",
			"CHECKPOINT_f_flag",
			"PLANT.*",
		});
		SetAvailableMapGoals( 0, true, "ATTACK_spike.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "FLAG_spike" );
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"MOUNTMG42_.*",
			"REPAIR.*",
			"PLANT_bridge",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "MOBILEMG42_spike.*" );

		ExecCommand( "kt 1" );
		foreach ( gameId and bot in BotTable )
		{
			if ( bot.GetTeam() == TEAM.ALLIES && bot.DistanceTo( Vec3(2804,2114,2297) ) > 700 )
			{
				bot.ExecCommand( "kill" );
			}
		}
		Util.MapDebugPrint( "entrance_Destroyed" );
		Map.icw_trigger = OnTriggerRegion( AABB(1507.460,2004.384,1017.807,1714.690,2169.217,1178.544), RegionTrigger.IntrusionWarning ); // CHANGE TRIGGER NAME

		sleep(20);
		Wp.SetWaypointFlag( "LiftArea1", "closed", true );
		Wp.SetWaypointFlag( "LiftArea2", "closed", true );
		Wp.SetWaypointFlag( "LiftArea3", "closed", true );
	},

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

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

	spike_Taken = function( trigger )
	{
		SetAvailableMapGoals( 0, false, "ATTACK_spike.*" );
		SetAvailableMapGoals( 0, true, "ATTACK_cappoint.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "MOBILEMG42_spike.*" );
		DeleteTriggerRegion( Map.icw_trigger );
		Util.MapDebugPrint( "spike_Taken" );
	},

	spike_Returned = function( trigger )
	{
		SetAvailableMapGoals( 0, false, "ATTACK_cappoint.*" );
		SetAvailableMapGoals( 0, true, "ATTACK_spike.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "MOBILEMG42_spike.*" );
		Map.icw_trigger = OnTriggerRegion( AABB(1507.460,2004.384,1017.807,1714.690,2169.217,1178.544), RegionTrigger.IntrusionWarning ); // CHANGE TRIGGER NAME
		Util.MapDebugPrint( "spike_Returned" );
	},

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

	f_flag_Axis_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_bridge.*" );
		Util.MapDebugPrint( "f_flag_Axis_Captured" );
	},

	f_flag_Allies_Captured = function( trigger )
	{
		SetAvailableMapGoals( 0, true, "ATTACK_library.*" );
		SetAvailableMapGoals( 0, false, "ATTACK_bridge.*" );
		Util.MapDebugPrint( "f_flag_Allies_Captured" );
	},

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

	lift_moving_down = function( trigger )
	{
		Map.lifttop = 0;
		Wp.SetWaypointFlag( "LiftDoor", "closed", true );
		Map.Switches.liftsw.Enabled = false;
		Util.MapDebugPrint( "lift_moving_down" );
	},

	lift_moving_up = function( trigger )
	{
		sleep(4.5);
		Map.lifttop = 1;
		Map.Switches.liftsw.Enabled = true;
		Wp.SetWaypointFlag( "LiftDoor", "closed", false );
		Util.MapDebugPrint( "lift_moving_up" );
	},
};

global OnMapLoad = function()
{
	OnTrigger( "^?Allied Command Post constructed. Charge speed increased!", Map.Allied_Command_Post_Built );
	OnTrigger( "^?Axis Command Post constructed. Charge speed increased!", Map.Axis_Command_Post_Built );
	OnTrigger( "^?Bridge constructed!", Map.bridge_Built );
	OnTrigger( "^?Footbridge constructed!", Map.footbridge_Built );
	OnTrigger( "^?Ramp constructed!", Map.ramp_Built );
	OnTrigger( "^?Axis team has destroyed the Allied Command Post!", Map.Allied_Command_Post_Destroyed );
	OnTrigger( "^?Allied team has destroyed the Axis Command Post!", Map.Axis_Command_Post_Destroyed );
	OnTrigger( "^?Bridge destroyed!", Map.bridge_Destroyed );
	OnTrigger( "^?The entrance destroyed!", Map.entrance_Destroyed );
	OnTrigger( "^?Footbridge destroyed!", Map.footbridge_Destroyed );
	OnTrigger( "^?Ramp destroyed!", Map.ramp_Destroyed );
	OnTrigger( "Allies have stolen The spike!", Map.spike_Taken );
	OnTrigger( "Flag returned spike!", Map.spike_Returned );
	OnTrigger( "^?Allies have killed count Dracula!!!", Map.CAPPOINT_Dracula );
	OnTrigger( "^?Axis reclaim the graveyard!", Map.f_flag_Axis_Captured );
	OnTrigger( "^?Allies capture the graveyard!", Map.f_flag_Allies_Captured );
	OnTrigger( "Planted at The main entrance.", Map.plant_main );
	OnTrigger( "^?Elevator goes down in : ^q 3 sec!", Map.lift_moving_down );
	OnTrigger( "^?Elevator goes up in : ^q 1 sec!", Map.lift_moving_up );


	SetAvailableMapGoals( 0, false, {
		"ATTACK_.*",
		"MOBILEMG42_.*",
		"FLAG_spike",
	});
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"ATTACK_library.*",
		"ATTACK_bridge.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_library.*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"MOUNTMG42_.*",
		"REPAIR.*",
	});

	SetGoalPriority( "BUILD_bridge", 0.91 );
	SetGoalPriority( "PLANT_entrance", 0.90 );

	Util.AddUsePoint( "PLANT_entrance", Vec3(2804,2114,2297) );
	Util.AddUsePoint( "BUILD_bridge", Vec3(-165,-2616,534) );

	Wp.SetWaypointFlag( "LiftDoor", "closed", false );
	Wp.SetWaypointFlag( "LiftArea1", "closed", false );
	Wp.SetWaypointFlag( "LiftArea2", "closed", false );
	Wp.SetWaypointFlag( "LiftArea3", "closed", false );

	// Max users per goal
	Util.SetMaxUsers( 1, "ATTACK_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 1, "BUILD_.*" );

	// Camp times
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=15, MaxCampTime=90} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=10, MaxCampTime=60} );

	// No combat movement on bridges
	Trigger1 = OnTriggerRegion( AABB(717.620,2037.613,1606.579,1213.809,2207.578,1719.662), RegionTrigger.DisableCombatMovement );
	Trigger2 = OnTriggerRegion( AABB(-691.387,-2223.629,587.400,-374.894,-1522.393,672.103), RegionTrigger.DisableCombatMovement );

	MapRoutes =
	{
		FLAG_spike =
		{
			ROUTE_door =
			{
				ROUTE_spike1_1 = {},
				ROUTE_spike1_2 = {},
				ROUTE_spike1_3 = {},
			},
			ROUTE_door2 =
			{
				ROUTE_spike1_1 = {},
				ROUTE_spike1_2 = {},
				ROUTE_spike1_3 = {},
			},
			ROUTE_forward_spawn =
			{
				ROUTE_spike1_1 = {},
				ROUTE_spike1_2 = {},
				ROUTE_spike1_3 = {},
			},
			ROUTE_lift =
			{
				ROUTE_spike1_1 = {},
				ROUTE_spike1_2 = {},
				ROUTE_spike1_3 = {},
			}
		},
		CAPPOINT_600 =
		{
			ROUTE_spike =
			{
				ROUTE_cappoint1 = {},
				ROUTE_cappoint2 = {},
				ROUTE_cappoint3 = {},
			}
		},
		CHECKPOINT_f_flag =
		{
			ROUTE_Allies1stSpawn =
			{
				ROUTE_Bridge =
				{
					ROUTE_FootBridge = {},
					ROUTE_MainPath = {},
				},
				ROUTE_Ladder =
				{
					ROUTE_MainPath = {},
				},
			},
		},
	};

	MapRoutes["ATTACK_spike.*"] = MapRoutes.FLAG_spike;
	MapRoutes["ATTACK_cappoint.*"] = MapRoutes.CAPPOINT_600;
	Util.Routes(MapRoutes);
	Util.UpdateSwitchData();

	print( "Omni-bot map script for " + GetMapName() + " executed." );
	Util.MapDebugPrint( "OnMapLoad" );
};

global OnBotJoin = function( bot )
{
};
