//==========================================================================================
//
//	le_lac.gm
//
//	Who	When		What
//------------------------------------------------------------------------------------------
//	palota	5 may 2010	Initial Script
//	palota	22 October 2010	BUILD_allies_assault_boat paththrough
//	palota	27 November 2011	parachute paththrough navigation (very buggy), ATTACK MaxUsers
//==========================================================================================
//
global Map =
{
	Debug = 0,
	phase = 0,
	gunDamaged = false,
	shipDamaged = false,
	backDestroyed = false,
	sideDestroyed = false,
	elevator_pos = "start",

	Movers = { "MOVER_ship", "MOVER_boat_sm" },

	BUILD_Canal_Boat_Stuffs_Construction = "BUILD_Canal_Boat_Stuffs_Construction",
	EXPLODE_Canal_Boat_Stuffs_Construction = "EXPLODE_Canal_Boat_Stuffs_Construction",
	BUILD_Anti_Ship_Gun = "BUILD_Anti_Ship_Gun",
	PLANT_Missile_Prototype = "PLANT_Missile_Prototype",
	BUILD_Command_Post = "BUILD_Command_Post",
	PLANT_Command_Post = "PLANT_Command_Post",
	BUILD_Axis_South_East_MG_nest = "BUILD_Axis_South_East_MG_nest",
	PLANT_Axis_South_East_MG_nest = "PLANT_Axis_South_East_MG_nest",
	BUILD_Allied_Islands_MG42 = "BUILD_Allied_Islands_MG42",
	MOUNTMG42_Allied_Islands_MG42 = "MOUNTMG42_Allied_Islands_MG42",
	REPAIRMG42_Allied_Islands_MG42 = "REPAIRMG42_Allied_Islands_MG42",
	PLANT_Allied_Islands_MG42 = "PLANT_Allied_Islands_MG42",
	BUILD_Axis_MG42_Beach = "BUILD_Axis_MG42_Beach",
	MOUNTMG42_Axis_MG42_Beach = "MOUNTMG42_Axis_MG42_Beach",
	REPAIRMG42_Axis_MG42_Beach = "REPAIRMG42_Axis_MG42_Beach",
	PLANT_Axis_MG42_Beach = "PLANT_Axis_MG42_Beach",
	PLANT_Sewer_Grate = "PLANT_Sewer_Grate",
	PLANT_Side_Door = "PLANT_Side_Door",
	PLANT_Back_Door = "PLANT_Back_Door",

	Switches =
	{
		AS_Gun =
		{
			Priority = 0.8,
			WaypointName = "as_gun",
			LimitTeam = (1<<TEAM.AXIS),
			LimitClass = (1<<CLASS.SOLDIER),
		},
		Helicopter_Gun1 =
		{
			Priority = 0.8,
			WaypointName = "heli1",
			LimitTeam = (1<<TEAM.ALLIES),
			LimitBots = 1,
			LimitDistance = 500,
			AimPosition = Vector3(-6086.3, 2167.9, -450),
			ExitConditions =
			{
				someFunc = function(bot){ sleep(3); return true; }
			},
		},
		Helicopter_Gun2 =
		{
			Priority = 0.8,
			WaypointName = "heli2",
			LimitTeam = (1<<TEAM.ALLIES),
			LimitBots = 1,
			LimitDistance = 500,
			AimPosition = Vector3(-5941.9, 2167.9, -450),
			ExitConditions =
			{
				someFunc = function(bot){ sleep(3); return true; }
			},
		},
		asgun_hatch =
		{
			Enabled = true,
			Priority = 0,
			WaypointName = "ASgun_hatch",
		},
		elevator_up_call =
		{
			Enabled = true,
			Priority = 0,
			WaypointName = "elevator_up_call",
			Timeout = 8000,
			ExitConditions =
			{
				f = function(bot){
					return Map.elevator_pos == "moving_up";
				}
			},
			Wait = function()
			{
				return Map.elevator_pos == "top";
			}
		},
		elevator_up_in =
		{
			Enabled = false,
			Priority = 0,
			WaypointName = "elevator_up_in",
			Wait = function()
			{
				return Map.elevator_pos != "moving_down";
			},
		},
		elevator_down_call =
		{
			Enabled = true,
			Priority = 0,
			WaypointName = "elevator_down_call",
			Timeout = 8000,
			ExitConditions =
			{
				f = function(bot){
					return Map.elevator_pos == "moving_down";
				}
			},
			Wait = function()
			{
				return Map.elevator_pos == "bottom";
			}
		},
		elevator_down_in =
		{
			Enabled = false,
			Priority = 0,
			WaypointName = "elevator_down_in",
			Wait = function()
			{
				return Map.elevator_pos != "moving_up";
			},
		},
	},

	Elevator_Up = function(trigger)
	{
		vel = ToVector(trigger.Action);
		if(vel.y < 0){
			Util.MapDebugPrint("elevator is up", true);
			sleep(1);
			if(Map.elevator_pos == "moving_up"){
				Map.elevator_pos = "stopped_top";
				sleep(2);
				if(Map.elevator_pos == "stopped_top"){
					Map.elevator_pos = "top";
					Map.Switches.elevator_up_call.Enabled = false;
					Map.Switches.elevator_up_in.Enabled = true;
				}
			}
		}
		else if(vel.y > 0){
			Util.MapDebugPrint("elevator is moving down", true);
			Map.elevator_pos = "moving_down";
			Map.Switches.elevator_up_call.Enabled = true;
			Map.Switches.elevator_up_in.Enabled = false;
		}
	},

	Elevator_Down = function(trigger)
	{
		vel = ToVector(trigger.Action);
		if(vel.y < 0){
			Util.MapDebugPrint("elevator is down", true);
			sleep(1);
			if(Map.elevator_pos == "moving_down"){
				Map.elevator_pos = "stopped_bottom";
				sleep(2);
				if(Map.elevator_pos == "stopped_bottom"){
					Map.elevator_pos = "bottom";
					Map.Switches.elevator_down_call.Enabled = false;
					Map.Switches.elevator_down_in.Enabled = true;
				}
			}
		}
		else if(vel.y > 0){
			Util.MapDebugPrint("elevator is moving up", true);
			Map.elevator_pos = "moving_up";
			Map.Switches.elevator_down_call.Enabled = true;
			Map.Switches.elevator_down_in.Enabled = false;
		}
		else if(Map.elevator_pos == "start"){
			Map.elevator_pos = "moving_down";
		}
	},

	DestroyBreakable = function(_this, position, facing)
	{
		name = "breakable_" + _this.CurrentNavigation;
		Map[name] = true;
		ent = TraceLine( position, position + 200*facing, 0, TRACE.SHOT, _this.Bot.GetGameId(), false ).entity;
		if(ent)
		{
			id = GetGameIdFromEntity(ent);
			Util.MapDebugPrint("destroying breakable " + id, true);
			_this.Bot.HoldButton(BTN.FORWARD, 6);
			_this.AddAimRequest(Priority.High, "facing", facing);
			_this.AddWeaponRequest(Priority.High, WEAPON.KNIFE);
			_this.BlockForWeaponChange(WEAPON.KNIFE);
			for(j=0; j<30; j+=1) {
				if (!EntityIsValid(id)){ return; }
				_this.Bot.HoldButton(BTN.ATTACK1, 0.5);
				if(facing.z < -0.7){ _this.Bot.HoldButton(BTN.CROUCH, 0.4); }
				sleep(0.5);
			}
			Map[name] = null;
		}
		sleep(3);
	},

	Navigation =
	{
		parachute = {
			navigate = function(_this)
			{
				_this.Goto(_this.Bot.GetPosition());
				_this.AddAimRequest(Priority.Low, "position", Vec3(-3815.434, -1128.956, 1129.706));
				for(i=0; i<200; i+=1)
				{
					pos = _this.Bot.GetPosition();
					if(pos.z>-120){ break; }
					_this.Bot.ResetStuckTime();
					_this.Bot.MoveTowards(pos);
					yield();
				}
				for(i=0; i<400; i+=1)
				{
					pos = _this.Bot.GetPosition();
					if(pos.z<515){ break; }
					_this.Bot.MoveTowards(pos);
					yield();
				}
			}
		},
		dam_door = {
			navigate = function(_this)
			{
				if (_this.Bot.GetVelocity().y < 10)
				{
					_this.AddAimRequest(Priority.High, "facing", Vector3(0,-1,0));
					sleep(1.5);
				}
			}
		},
		sewer_hatch = {
			EvalFunc = function(t){
				return !Map.breakable_sewer_hatch;
			},
			navigate = function(_this)
			{
				Map.DestroyBreakable(_this, Vector3(-2235.844, -1241.875, 807.015), Vector3(0, -0.184, 0.983));
			}
		},
		hatch_fuel1 = {
			EvalFunc = function(t){
				return !Map.breakable_hatch_fuel1;
			},
			navigate = function(_this)
			{
				Map.DestroyBreakable(_this, Vector3(-154.126, 2071.415, 659.089), Vector3(0.214, 0, 0.977));
			}
		},
		hatch_fuel2 = {
			EvalFunc = function(t){
				return !Map.breakable_hatch_fuel2;
			},
			navigate = function(_this)
			{
				Map.DestroyBreakable(_this, Vector3(-160.332, 2882.322, 648.125), Vector3(0.215, 0.015, 0.976));
			}
		},
		hatch_fuel2top = {
			EvalFunc = function(t){
				return !Map.breakable_hatch_fuel2top;
			},
			navigate = function(_this)
			{
				Map.DestroyBreakable(_this, Vector3(-169.874, 2889.875, 764.247), Vector3(-0.029, 0.022, -0.999));
			}
		},
	},

	ASgun_hatch_trigger = function( trigger )
	{
		Map.Switches.asgun_hatch.Enabled =  ToVector(trigger.Action).x > 0;
	},

	SetSpawn1 = function(bot)
	{
		if (Map.phase>=10 && bot.GetTeam()==TEAM.AXIS)
		{
			if (Map.phase<20 || Map.phase<30 && RandInt(0,1)==0)
			{
				bot.ChangeSpawnPoint(4);
			}else{
				bot.ChangeSpawnPoint(2);
			}
		}
	},

	SetSpawn = function()
	{
		foreach(bot in BotTable)
		{
			Map.SetSpawn1(bot);
		}
	},

	Wait_For_Plane = function(trigger)
	{
		SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_ship1");
		SetAvailableMapGoals(TEAM.ALLIES, true, "MOUNT_ship");
		Util.MapDebugPrint("Wait_For_Plane");
	},

	Get_Explosives_To_Ship = function(trigger)
	{
		SetAvailableMapGoals(TEAM.ALLIES, true, {
			"FLAG_box_obj2",
			"CAPPOINT_ship1",
		});
		Util.MapDebugPrint("Get_Explosives_To_Ship");
	},

	SetGun = function()
	{
		if(Map.phase<20)
		{
			Map.Switches.AS_Gun.Enabled = Map.phase>=5 && Map.phase<10 && !Map.gunDamaged && !Map.shipDamaged;
			Map.Switches.Helicopter_Gun1.Enabled = Map.phase<5 || Map.phase<10 && !Map.gunDamaged;
			Map.Switches.Helicopter_Gun2.Enabled = Map.Switches.Helicopter_Gun1.Enabled;
		}
	},

	SetDoor = function(trigger)
	{
		SetAvailableMapGoals(TEAM.AXIS, Map.sideDestroyed && Map.phase>=5 && Map.phase<30, "BUILD_side_door");
		SetAvailableMapGoals(TEAM.AXIS, Map.backDestroyed && Map.phase>=20, "BUILD_back_door");

		b = !Map.sideDestroyed && Map.phase>=10 && Map.phase<20;
		SetAvailableMapGoals(TEAM.ALLIES, b, "ATTACK_side_door_out");
		if(b){ Util.SetPercentInProgress(70, "FLAG_bomb_pickup"); }
		else { Util.SetMaxUsersInProgress(99, "FLAG_bomb_pickup"); }

		b = !Map.backDestroyed && Map.phase>=30;
		SetAvailableMapGoals(TEAM.ALLIES, b, "ATTACK_back_door_out");
		if(b){ Util.SetPercentInProgress(70, "FLAG_gold"); }
		else { Util.SetMaxUsersInProgress(99, "FLAG_gold"); }
	},

	Escort_Ship = function(trigger)
	{
		Map.phase = 5;
		SetAvailableMapGoals(TEAM.ALLIES, false, {
			"FLAG_box_obj2",
			"CAPPOINT_ship1",
		});
		SetAvailableMapGoals(TEAM.ALLIES, true, {
			"AMMOCAB_side1",
			"HEALTHCAB_side2",
		});
		SetAvailableMapGoals(TEAM.AXIS, true, Map.BUILD_Anti_Ship_Gun);
		Map.SetGun();
		Map.SetDoor();
		SetAvailableMapGoals(TEAM.ALLIES, true, "ESCORT_ship");
		Server.MinClassCount[TEAM.AXIS][CLASS.SOLDIER] += 1;
		ETUtil.SetStartIndex("BUILD_allies_assault_boat", 1);
		Util.MapDebugPrint("Escort_Ship");
	},

	Gun_Damaged = function(trigger)
	{
		Map.gunDamaged = true;
		Map.SetGun();
		Util.MapDebugPrint("Gun_Damaged");
	},

	Gun_Repaired = function(trigger)
	{
		Map.gunDamaged = false;
		Map.SetGun();
		Util.MapDebugPrint("Gun_Repaired");
	},

	Ship_Damaged = function(trigger)
	{
		Map.shipDamaged = true;
		Map.SetGun();
		Util.MapDebugPrint("Ship_Damaged");
	},

	Ship_Repaired = function(trigger)
	{
		Map.shipDamaged = false;
		Map.SetGun();
		Util.MapDebugPrint("Ship_Repaired");
	},

	SetFuel = function(b)
	{
		SetAvailableMapGoals(TEAM.ALLIES, b, {
			"FLAG_bomb_pickup",
			"CAPPOINT_port_fuel",
		});
		SetAvailableMapGoals(TEAM.AXIS, b, {
			"DEFEND_fuel.*",
			"TRIPMINE_fuel.*",
		});
	},

	Get_Fuel = function(trigger)
	{
		SetAvailableMapGoals(TEAM.ALLIES, false, "ESCORT_ship");
		Map.SetFuel(true);
		SetAvailableMapGoals(TEAM.ALLIES, false, {
			Map.BUILD_Allied_Islands_MG42,
			Map.REPAIRMG42_Allied_Islands_MG42,
		});
		SetAvailableMapGoals(TEAM.ALLIES, true, Map.PLANT_Sewer_Grate);
		SetAvailableMapGoals(TEAM.ALLIES, true, Map.PLANT_Side_Door); //dynamite
		SetGoalPriority(Map.MOUNTMG42_Allied_Islands_MG42, 0.51, TEAM.ALLIES);
		Wp.SetWaypointFlag("ship2", "closed", false);
		ETUtil.SetStartIndex("BUILD_allies_assault_boat", 0);
		Util.MapDebugPrint("Get_Fuel");
	},

	Sewer_Grate_Destroyed = function(trigger)
	{
		Util.EnableGoal("ROUTE_sewer_grate");
		Util.MapDebugPrint("Sewer_Grate_Destroyed");
	},

	Dam_Lost = function(trigger)
	{
		Map.phase = 10;
		Map.SetGun();
		Map.SetDoor();
		Map.SetSpawn();
		Wp.SetWaypointFlag("gun_in1", "closed", true);
		Wp.SetWaypointFlag("gun_in2", "closed", true);
		Wp.SetWaypointFlag("gun_prone", "closed", false);
		Util.EnableGoal("AMMOCAB_cp1");
		Util.EnableGoal("HEALTHCAB_cp2");
		SetAvailableMapGoals(TEAM.AXIS, true, {
			"AMMOCAB_side1",
			"HEALTHCAB_side2",
		});
		SetAvailableMapGoals(TEAM.AXIS, false, {
			".*MG42_dam_south.*",
			".*MG42_dam_east_mg2",
			Map.BUILD_Anti_Ship_Gun,
			"ATTACK_dam.*",
			"SNIPE_dam.*",
			"AMMOCAB_dam1",
		});
		SetAvailableMapGoals(TEAM.ALLIES, false, "BUILD_allies_assault_boat");
		SetAvailableMapGoals(TEAM.ALLIES, true, ".*MG42_bunker_mg");
		Server.MinClassCount[TEAM.AXIS][CLASS.SOLDIER] -= 1;
		Util.MapDebugPrint("Dam_Lost");
	},

	Side_Door_Destroyed = function(trigger)
	{
		Map.sideDestroyed = true;
		Map.SetDoor();
		Util.EnableGoal("ROUTE_side_door");
		Util.EnableGoal("ROUTE_fuel_door");
		Util.EnableGoal("ROUTE_fuel_shaft");
		SetAvailableMapGoals(TEAM.ALLIES, true, ".*Command_Post");
		Util.MapDebugPrint("Side_Door_Destroyed");
	},

	Side_Door_Built = function(trigger)
	{
		Map.sideDestroyed = false;
		Map.SetDoor();
		Util.DisableGoal("ROUTE_side_door");
		Util.DisableGoal("ROUTE_fuel_door");
		Util.DisableGoal("ROUTE_fuel_shaft");

		goal=GetGoal("PLANT_side_door");
		if(goal.TraceEntity==null){
			goal.TraceEntity = Util.TraceForEntityInfo(goal.TraceInfo.eyePos, goal.TraceInfo.endPos, TRACE.ALL);
		}
		SetAvailableMapGoals(TEAM.ALLIES, true, "PLANT_side_door");
		Util.MapDebugPrint("Side_Door_Built");
	},

	Fuel_Taken = function(trigger)
	{
		SetGoalPriority("DEFEND_fuel9", 0.55, TEAM.AXIS);
		Util.MapDebugPrint("Fuel_Taken");
	},

	Fuel_Returned = function(trigger)
	{
		SetGoalPriority("DEFEND_fuel9", 0.49, TEAM.AXIS);
		Util.MapDebugPrint("Fuel_Returned");
	},

	Fuel_Captured = function(trigger)
	{
		if(trigger.Action=="allied_complete")
		{
			Map.phase=20;
			Map.SetFuel(false);
			Map.SetDoor();
			Map.SetSpawn();
			SetGoalPriority("BUILD_side_door", 0.6, TEAM.AXIS);
			SetAvailableMapGoals(TEAM.AXIS, false, Map.PLANT_Allied_Islands_MG42);
			SetAvailableMapGoals(TEAM.ALLIES, false, Map.MOUNTMG42_Allied_Islands_MG42);
			SetAvailableMapGoals(TEAM.AXIS, true, {
				Map.BUILD_Axis_MG42_Beach,
				Map.REPAIRMG42_Axis_MG42_Beach,
				Map.EXPLODE_Canal_Boat_Stuffs_Construction,
				"ATTACK_boat1.*",
			});
			SetAvailableMapGoals(TEAM.ALLIES, true, {
				Map.BUILD_Canal_Boat_Stuffs_Construction,
				"DEFEND_boat1.*",
			});
			Util.MapDebugPrint("Fuel_Captured");
		}
	},

	Boat_Moving =
	{
		TriggerOnEntity = GetGoal("MOVER_boat_sm").GetEntity(),
		OnEnter = function(ent)
		{
			SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_boat");
			Util.MapDebugPrint("Boat_Moving");
		},
	},

	Boat_Under_Bridge =
	{
		TriggerOnEntity = GetGoal("MOVER_boat_sm").GetEntity(),
		OnEnter = function(ent)
		{
			SetAvailableMapGoals(TEAM.AXIS, true, "ATTACK_boat2.*");
			SetAvailableMapGoals(TEAM.ALLIES, true, "DEFEND_boat2.*");
			Util.MapDebugPrint("Boat_Under_Bridge");
		},
	},

	Boat_Built = function(trigger)
	{
		if(Map.triggerBoat1==null){
			Map.triggerBoat1 = OnTriggerRegion(Util.WpNameInfo("boat1").position, 250, Map.Boat_Moving);
			Map.triggerBoat2 = OnTriggerRegion(Util.WpNameInfo("boat2").position, 200, Map.Boat_Under_Bridge);
		}
		SetAvailableMapGoals(TEAM.AXIS, true, {
			Map.BUILD_Axis_South_East_MG_nest,
			Map.MOUNTMG42_Axis_MG42_Beach,
		});
		SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_boat");
		Util.MapDebugPrint("Boat_Built");
	},

	Boat_Destroyed = function(trigger)
	{
		SetAvailableMapGoals(TEAM.AXIS, false, {
			Map.MOUNTMG42_Axis_MG42_Beach,
			"ATTACK_boat2.*",
		});
		SetAvailableMapGoals(TEAM.ALLIES, false, "DEFEND_boat2.*");
		Util.MapDebugPrint("Boat_Destroyed");
	},

	Get_Explosives_To_Missile = function(trigger)
	{
		Map.phase=30;
		DeleteTriggerRegion(Map.triggerBoat1);
		DeleteTriggerRegion(Map.triggerBoat2);
		//Util.AddInvVehicle("MOVER_boat_sm");
		Map.SetDoor();
		Map.SetSpawn();
		Util.DisableGoal("AMMOCAB_side1");
		Util.DisableGoal("HEALTHCAB_side2");
		Util.EnableGoal("AMMOCAB_missile_ammo");
		Util.EnableGoal("HEALTHCAB_missile_health");
		Util.EnableGoal("AMMOCAB_bunker1");
		Util.EnableGoal("HEALTHCAB_bunker2");
		Util.EnableGoal("AMMOCAB_back1");
		Util.EnableGoal("HEALTHCAB_back2");
		SetAvailableMapGoals(TEAM.AXIS, false, {
			Map.EXPLODE_Canal_Boat_Stuffs_Construction,
			".*MG42_dam_east_mg1",
			"ATTACK_boat.*",
		});
		SetAvailableMapGoals(TEAM.ALLIES, false, {
			"DEFEND_boat.*",
			Map.PLANT_Side_Door,
			"PLANT_side_door",
			"MOUNT_ship",
			Map.BUILD_Canal_Boat_Stuffs_Construction,
			".*MG42_bunker_mg",
		});
		SetAvailableMapGoals(TEAM.AXIS, true, {
			"DEFEND_missile.*",
			"DEFEND_door_back.*",
		});
		SetAvailableMapGoals(TEAM.AXIS, Map.backDestroyed, "DEFEND_back.*");
		SetAvailableMapGoals(TEAM.AXIS, false, Map.MOUNTMG42_Axis_MG42_Beach);
		SetAvailableMapGoals(TEAM.AXIS, true, {
			".*MG42_mg42_2",
			".*MG42_mg42_2_1",
			"TRIPMINE_missile.*",
		});
		SetAvailableMapGoals(TEAM.ALLIES, true, {
			"FLAG_gold",
			"CAPPOINT_missile.*",
			Map.PLANT_Back_Door,
			Map.PLANT_Axis_MG42_Beach,
			Map.PLANT_Axis_South_East_MG_nest,
			"ATTACK_missile.*",
		});
		Util.MapDebugPrint("Get_Explosives_To_Missile");
	},

	Back_Door_Destroyed = function(trigger)
	{
		Map.backDestroyed=true;
		Map.SetDoor();
		Util.EnableGoal("ROUTE_back_door");
		Wp.SetWaypointFlag("back_door_axis", "closed", true);
		SetAvailableMapGoals(TEAM.AXIS, Map.phase>=30, "DEFEND_back.*");
		Util.MapDebugPrint("Back_Door_Destroyed");
	},

	Back_Door_Built = function(trigger)
	{
		Map.backDestroyed=false;
		Map.SetDoor();
		Util.DisableGoal("ROUTE_back_door");
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_back.*");

		goal=GetGoal("PLANT_back_door");
		if(goal.TraceEntity==null){
			goal.TraceEntity = Util.TraceForEntityInfo(goal.TraceInfo.eyePos, goal.TraceInfo.endPos, TRACE.ALL);
		}
		SetAvailableMapGoals(TEAM.ALLIES, true, "PLANT_back_door");
		Util.MapDebugPrint("Back_Door_Built");
	},

	Arm_Bomb = function(trigger)
	{
		SetAvailableMapGoals(TEAM.ALLIES, false, {
			"FLAG_gold",
			"CAPPOINT_missile.*",
		});
		SetAvailableMapGoals(TEAM.ALLIES, true, Map.PLANT_Missile_Prototype);
		Util.MapDebugPrint("Arm_Bomb");
	},
};

global OnMapLoad = function()
{
	if (GetGoal("BUILD_6The_Command_Post")!=null)
	{
		Map.BUILD_Canal_Boat_Stuffs_Construction = "BUILD_2Canal_Boat_Stuffs_Construction";
		Map.EXPLODE_Canal_Boat_Stuffs_Construction = "EXPLODE_2Canal_Boat_Stuffs_Construction";
		Map.BUILD_Anti_Ship_Gun = "BUILD_2The_Anti_Ship_Gun";
		Map.PLANT_Missile_Prototype = "PLANT_2The_Missile_Prototype";
		Map.BUILD_Command_Post = "BUILD_6The_Command_Post";
		Map.PLANT_Command_Post = "PLANT_6The_Command_Post";
		Map.BUILD_Axis_South_East_MG_nest = "BUILD_2the_Axis_South_East_MG_nest";
		Map.PLANT_Axis_South_East_MG_nest = "PLANT_2the_Axis_South_East_MG_nest";
		Map.BUILD_Allied_Islands_MG42 = "BUILD_2Allied_Islands_MG42";
		Map.MOUNTMG42_Allied_Islands_MG42 = "MOUNTMG42_2Allied_Islands_MG42";
		Map.REPAIRMG42_Allied_Islands_MG42 = "REPAIRMG42_2Allied_Islands_MG42";
		Map.PLANT_Allied_Islands_MG42 = "PLANT_2Allied_Islands_MG42";
		Map.BUILD_Axis_MG42_Beach = "BUILD_2Axis_MG42_Beach";
		Map.MOUNTMG42_Axis_MG42_Beach = "MOUNTMG42_2Axis_MG42_Beach";
		Map.REPAIRMG42_Axis_MG42_Beach = "REPAIRMG42_2Axis_MG42_Beach";
		Map.PLANT_Axis_MG42_Beach = "PLANT_2Axis_MG42_Beach";
		Map.PLANT_Sewer_Grate = "PLANT_2The_Sewer_Grate";
		Map.PLANT_Side_Door = "PLANT_2The_Side_Door";
		Map.PLANT_Back_Door = "PLANT_2The_Back_Door";
	}

	OnTrigger("^6Plane was on his way whit ^3The Explosives", Map.Wait_For_Plane);
	OnTrigger("^3The Explosives ^6landed safely on the Center Island !!!!", Map.Get_Explosives_To_Ship);
	OnTrigger("^3The Anti-Ship Gun ^2has been damaged!", Map.Gun_Damaged);
	OnTrigger("^3The Anti-Ship Gun ^2has been repaired!", Map.Gun_Repaired);
	OnTrigger("^6The 4 Explosives was load onto The Ship!!!!", Map.Escort_Ship);
	OnTrigger("^3The Ship ^2has been damaged", Map.Ship_Damaged);
	OnTrigger("^3The Ship ^2has been repaired", Map.Ship_Repaired);
	OnTrigger("^dAllies have loaded The ^3Explosives ^2onto the ^3Port Station", Map.Get_Fuel);
	OnTrigger("^1Axis Team ^3lost ^6Dam_Spawn.", Map.Dam_Lost);
	//OnTrigger("^3The Explosives ready to load in to the canal boat!!", Map.);
	//OnTrigger("^dThe Explosives was in the Crane and on his way to the Canal Boat (waiting 30sec)", Map.);
	OnTrigger("^3The Sewer Grate has been destroyed!", Map.Sewer_Grate_Destroyed);
	OnTrigger("^dAllies have destroyed ^3The SideDoor", Map.Side_Door_Destroyed);
	OnTrigger("^dAllies have destroyed ^3The SideDoor Barricade", Map.Side_Door_Destroyed);
	OnTrigger("^1Axis have built the ^3SideDoor Barricade", Map.Side_Door_Built);
	OnTrigger("Allies have stolen Fuel Can!", Map.Fuel_Taken);
	OnTrigger("Flag returned bomb_pickup!", Map.Fuel_Returned);
	OnTrigger("bomb_pickup", Map.Fuel_Captured);
	OnTrigger("^dAllies have built The 3Canal Boat!", Map.Boat_Built);
	OnTrigger("^3The Canal Boat ^2has been destroyed!", Map.Boat_Destroyed);
	//OnTrigger("^3... But reach enought to land on the beach!", Map.);
	OnTrigger("^dAllies have escorted ^3The Canal Boat ^2and secured ^3The Explosives "/*"^2onto ^3The Beach ^2carefully!"*/, Map.Get_Explosives_To_Missile);
	OnTrigger("^dAllies have destroyed ^3The BackDoor", Map.Back_Door_Destroyed);
	OnTrigger("Allies have destroyed the BackDoor Barricade", Map.Back_Door_Destroyed);
	OnTrigger("^1Axis have built ^3The BackDoor Barricade", Map.Back_Door_Built);
	OnTrigger("^6The bomb is ready to be armed!!!!", Map.Arm_Bomb);
	//OnTrigger("^3Alert AxisTeam: ^2intruder ^3detected On the ^62nd Floor ^3Missile Basement!", Map.);
	//OnTrigger("^3Alert AxisTeam: ^dintruder ^3detected On the ^61st Floor ^3Missile Basement!", Map.);
	//OnTrigger("^6The first Explosive charge has been placed!!!!", Map.);
	//OnTrigger("^6The 4th Explosive charge has been placed!!!!", Map.);
	OnTrigger("elevatordoor_up_goto", Map.Elevator_Up);
	OnTrigger("elevatordoor_down_goto", Map.Elevator_Down);
	OnTrigger("hatch2_start", Map.ASgun_hatch_trigger);

	OnTriggerRegion( AABB(-6951.792,640.794,618.503,-5462.037,2321.158,1823.906), RegionTrigger.DisableBotPush ); //parachute

	Util.DisableGoal(".*", true);
	Util.DisableGoal("ROUTE_sewer_grate");
	Util.DisableGoal("ROUTE_side_door");
	Util.DisableGoal("ROUTE_fuel_door");
	Util.DisableGoal("ROUTE_fuel_shaft");
	SetAvailableMapGoals(TEAM.ALLIES, false, "ROUTE_back_door");

	SetAvailableMapGoals(TEAM.AXIS, true, {
		".*MG42_dam.*",
		Map.PLANT_Allied_Islands_MG42,
		Map.EXPLODE_Canal_Boat_Stuffs_Construction,
		".*Command_Post",
		"ATTACK_dam.*",
		"SNIPE_dam.*",
		"AMMOCAB_dam1",
	});

	SetAvailableMapGoals(TEAM.ALLIES, true, {
		"ATTACK_ship1",
		Map.BUILD_Allied_Islands_MG42,
		Map.MOUNTMG42_Allied_Islands_MG42,
		Map.REPAIRMG42_Allied_Islands_MG42,
		"BUILD_allies_assault_boat",
	});

	SetGoalPriority(Map.BUILD_Command_Post, 0.85, TEAM.AXIS);
	SetGoalPriority(Map.BUILD_Command_Post, 0.7, TEAM.ALLIES);
	SetGoalPriority(Map.PLANT_Command_Post, 0.555, TEAM.AXIS, CLASS.ENGINEER);
	SetGoalPriority(Map.PLANT_Command_Post, 0.7, TEAM.ALLIES, CLASS.ENGINEER);
	SetGoalPriority(Map.PLANT_Axis_South_East_MG_nest, 0.6, TEAM.ALLIES, CLASS.ENGINEER);
	SetGoalPriority(Map.MOUNTMG42_Allied_Islands_MG42, 0.69, TEAM.ALLIES);
	SetGoalPriority("ESCORT_ship", 0.5, TEAM.ALLIES);
	SetGoalPriority(Map.PLANT_Allied_Islands_MG42, 0.5, TEAM.AXIS, CLASS.ENGINEER);
	SetGoalPriority("CAPPOINT_missile.*", 0.69, TEAM.ALLIES);
	SetGoalPriority("ATTACK_boat", 0.65, TEAM.ALLIES);
	SetGoalPriority(Map.PLANT_Back_Door, 0.85, TEAM.ALLIES);
	SetGoalPriority("PLANT_back_door", 0.85, TEAM.ALLIES);
	SetGoalPriority("REPAIRMG42.*", 0.8);
	SetGoalPriority("FLAG.*", 0.49, TEAM.AXIS, 0, true);
	SetGoalPriority("TRIPMINE.*", 0.8, TEAM.AXIS);

	Map.SetGun();

	foreach (id and goal in { ".*MG42.*", Map.PLANT_Command_Post, Map.BUILD_Command_Post }){
		Util.SetMaxUsersInProgress(1, goal);
	}
	Util.SetMaxUsersInProgress(5, "ATTACK_missile.*");
	Util.SetMaxUsersInProgress(15, "ATTACK_ship1");

	SetMapGoalProperties("DEFEND_.*", {mincamptime=60, maxcamptime=250} );

	Wp.SetWaypointFlag("gun_in1", "closed", false);
	Wp.SetWaypointFlag("gun_in2", "closed", false);
	Wp.SetWaypointFlag("gun_prone", "closed", true);
	Wp.SetWaypointFlag("back_door_axis", "closed", false);
	Wp.SetWaypointFlag("ship2", "closed", true);

	Util.SetGoalOffset(10, -10, 0, Map.BUILD_Axis_MG42_Beach);
	Util.SetGoalOffset(0, -15, 0, "MOUNTMG42_dam_east_mg1");
	Util.SetGoalOffset(15, 0, 0, "MOUNTMG42_dam_east_mg2");
	Util.SetGoalOffset(0, 60, 0, Map.PLANT_Axis_South_East_MG_nest);
	Util.AddUseWp(Map.PLANT_Side_Door, "side_door");
	Util.AddUseWp(Map.PLANT_Side_Door, "side_door_in");
	Util.AddUseWp(Map.PLANT_Back_Door, "back_door");
	Util.AddUseWp(Map.PLANT_Back_Door, "back_door_in");

	ETUtil.SetStartIndex("BUILD_allies_assault_boat", 0);

	GetGoal("BUILD_allies_assault_boat").PaththroughFunction = function(_this)
	{
		bot = _this.Bot;
		if (bot.GetPosition().z < 390){
			ent = GetGoal("MOVER_ship").GetEntity();
			//climb up the ship ladder
			v = GetEntFacing(ent);
			_this.AddAimRequest(Priority.High, "facing", Vector3(-v.y, v.x, 3));
			sleep(0.3);
			bot.HoldButton(BTN.FORWARD, 4);
			pos = GetEntityWorldSpace(ent, Vector3(0,-360,-70));
			for(i=0; i<=40 && bot.DistanceTo(pos) > 110; i+=1)
			{
				sleep(0.1);
			}
			bot.ReleaseButton(BTN.FORWARD);
			//go to the repair point
			bot.MoveTowards(GetEntityWorldSpace(ent, Vector3(0,-221,-70)));
			_this.AddAimRequest(Priority.High, "facing", v);
			sleep(1);
		}
	};

	MapRoutes =
	{
		CAPPOINT_ship1 = {
			ROUTE_explosives_drop = {
				ROUTE_water1 = {},
				ROUTE_water2 = {},
			}
		},
		FLAG_bomb_pickup = {
			ROUTE_port_spawn = {
				ROUTE_side_door = { Weight=9,
					ROUTE_fuel_door = {},
					ROUTE_fuel_shaft = {},
				},
				ROUTE_sewer_grate = {
					ROUTE_bunker_bridge = {
						ROUTE_fuel_stairs = {},
						ROUTE_fuel_up2 = {},
					}
				},
			},
		},
		CAPPOINT_port_fuel = {
			ROUTE_fuel = {
				ROUTE_fuel_door = { Weight=4 },
				ROUTE_fuel_shaft = { Weight=4 },
				ROUTE_fuel_stairs = {},
				ROUTE_fuel_up1 = { ROUTE_command_post = {}},
				ROUTE_fuel_up2 = { ROUTE_command_post = {}},
			},
		},
		CAPPOINT_missile1 = {
			ROUTE_beach_spawn = {
				ROUTE_back_door = { Weight=4,
					ROUTE_back_down = { Weight=3 },
					ROUTE_back_stairs1 = {},
					ROUTE_back_stairs2 = {},
				},
				ROUTE_bunker_stairs1 = {
					ROUTE_missile_east = {},
				},
				ROUTE_bunker_stairs2 = {
					ROUTE_missile_west = {},
				},
				ROUTE_sewer = { Weight=0.5,
					ROUTE_bunker_bridge = { ROUTE_bunker_stairs1 = {}},
				},
			},
		},
		DEFEND_fuel6 = {
			ROUTE_bunker_spawn = {
				ROUTE_fuel_stairs = {},
			},
			ROUTE_command_post = {
				ROUTE_fuel_stairs = {},
			},
		},
		DEFEND_back6 = {
			ROUTE_bunker_spawn = {
				ROUTE_missile_west = {},
			}
		},
	};
	MapRoutes[Map.BUILD_Command_Post] = {
			ROUTE_beach_spawn = {
				ROUTE_sewer = {},
			},
	};

	MapRoutes.CAPPOINT_missile2 = MapRoutes.CAPPOINT_missile1;
	MapRoutes[Map.PLANT_Missile_Prototype] = MapRoutes.CAPPOINT_missile1;
	MapRoutes.ATTACK_missile5 = MapRoutes.CAPPOINT_missile1;
	MapRoutes.ATTACK_missile6 = MapRoutes.CAPPOINT_missile1;
	MapRoutes[Map.PLANT_Command_Post] = MapRoutes[Map.BUILD_Command_Post];
	MapRoutes.DEFEND_fuel7 = MapRoutes.DEFEND_fuel6;
	MapRoutes.DEFEND_fuel8 = MapRoutes.DEFEND_fuel6;
	MapRoutes.DEFEND_back7 = MapRoutes.DEFEND_back6;
	MapRoutes.DEFEND_missile8 = MapRoutes.DEFEND_back6;
	MapRoutes.DEFEND_back4 = MapRoutes.DEFEND_back6;
	MapRoutes.DEFEND_back8 = MapRoutes.DEFEND_back6;

	Util.Routes(MapRoutes);
	Util.UpdateSwitchData();
	Util.MapDebugPrint( "Omni_bot map script for " + GetMapName() + " executed." );
};

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 100.0;
	Map.SetSpawn1(bot);
};
