diff --git a/OpenRA.Mods.RA/Missions/Allies01Script.cs b/OpenRA.Mods.RA/Missions/Allies01Script.cs index 1b8d5a8b61..488a556ce6 100644 --- a/OpenRA.Mods.RA/Missions/Allies01Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies01Script.cs @@ -145,7 +145,13 @@ namespace OpenRA.Mods.RA.Missions } if (currentAttackWave == EinsteinChinookAttackWave) { - FlyEinsteinFromExtractionLZ(); + einsteinChinook = MissionUtils.ExtractUnitWithChinook( + world, + allies, + einstein, + extractionLZEntryPoint.Location, + extractionLZ.Location, + chinookExitPoint.Location); } } if (einsteinChinook != null) @@ -211,15 +217,9 @@ namespace OpenRA.Mods.RA.Missions } } - IEnumerable UnitsNearActor(Actor actor, int range) - { - return world.FindUnitsInCircle(actor.CenterLocation, Game.CellSize * range) - .Where(a => a.IsInWorld && a != world.WorldActor && !a.Destroyed && a.HasTrait() && !a.Owner.NonCombatant); - } - bool AlliesControlLab() { - var units = UnitsNearActor(lab, LabClearRange); + var units = world.ForcesNearLocation(lab.CenterLocation, LabClearRange); return units.Any() && units.All(a => a.Owner == allies); } @@ -239,32 +239,20 @@ namespace OpenRA.Mods.RA.Missions } } - void FlyEinsteinFromExtractionLZ() - { - einsteinChinook = world.CreateActor(ChinookName, new TypeDictionary { new OwnerInit(allies), new LocationInit(extractionLZEntryPoint.Location) }); - einsteinChinook.QueueActivity(new HeliFly(extractionLZ.CenterLocation)); - einsteinChinook.QueueActivity(new Turn(0)); - einsteinChinook.QueueActivity(new HeliLand(true, 0)); - einsteinChinook.QueueActivity(new WaitFor(() => einsteinChinook.Trait().Passengers.Contains(einstein))); - einsteinChinook.QueueActivity(new Wait(150)); - einsteinChinook.QueueActivity(new HeliFly(chinookExitPoint.CenterLocation)); - einsteinChinook.QueueActivity(new RemoveSelf()); - } - void FlyTanyaToInsertionLZ() { - tanya = world.CreateActor(false, TanyaName, new TypeDictionary { new OwnerInit(allies) }); - var chinook = world.CreateActor(ChinookName, new TypeDictionary { new OwnerInit(allies), new LocationInit(insertionLZEntryPoint.Location) }); - chinook.Trait().Load(chinook, tanya); - chinook.QueueActivity(new HeliFly(insertionLZ.CenterLocation)); - chinook.QueueActivity(new Turn(0)); - chinook.QueueActivity(new HeliLand(true, 0)); - chinook.QueueActivity(new UnloadCargo(true)); - chinook.QueueActivity(new CallFunc(() => Sound.Play("laugh1.aud"))); - chinook.QueueActivity(new CallFunc(() => tanya.QueueActivity(new Move.Move(insertionLZ.Location - new CVec(1, 0))))); - chinook.QueueActivity(new Wait(150)); - chinook.QueueActivity(new HeliFly(chinookExitPoint.CenterLocation)); - chinook.QueueActivity(new RemoveSelf()); + tanya = MissionUtils.InsertUnitWithChinook( + world, + allies, + TanyaName, + insertionLZEntryPoint.Location, + insertionLZ.Location, + chinookExitPoint.Location, + unit => + { + Sound.Play("laugh1.aud"); + unit.QueueActivity(new Move.Move(insertionLZ.Location - new CVec(1, 0))); + }); } void SetAlliedUnitsToDefensiveStance() diff --git a/OpenRA.Mods.RA/Missions/Allies02Script.cs b/OpenRA.Mods.RA/Missions/Allies02Script.cs index be373ee438..c8280276d8 100644 --- a/OpenRA.Mods.RA/Missions/Allies02Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies02Script.cs @@ -238,7 +238,7 @@ namespace OpenRA.Mods.RA.Missions void ManageSovietUnits() { - var idleSovietUnitsAtRP = ForcesNearLocation(sovietRallyPoint.CenterLocation, 3).Where(a => a.Owner == soviets && a.IsIdle && a.HasTrait()); + var idleSovietUnitsAtRP = world.ForcesNearLocation(sovietRallyPoint.CenterLocation, 3).Where(a => a.Owner == soviets && a.IsIdle && a.HasTrait()); if (idleSovietUnitsAtRP.Count() >= SovietGroupSize) { var firstUnit = idleSovietUnitsAtRP.FirstOrDefault(); @@ -255,7 +255,7 @@ namespace OpenRA.Mods.RA.Missions } } } - var idleSovietUnits = ForcesNearLocation(allies2BasePoint.CenterLocation, 20).Where(a => a.Owner == soviets && a.IsIdle); + var idleSovietUnits = world.ForcesNearLocation(allies2BasePoint.CenterLocation, 20).Where(a => a.Owner == soviets && a.IsIdle); foreach (var unit in idleSovietUnits) { var closestAlliedBuilding = ClosestAlliedBuilding(unit, 40); @@ -268,7 +268,7 @@ namespace OpenRA.Mods.RA.Missions Actor ClosestAlliedBuilding(Actor actor, int range) { - return BuildingsNearLocation(actor.CenterLocation, range) + return world.BuildingsNearLocation(actor.CenterLocation, range) .Where(a => a.Owner == allies2) .OrderBy(a => (actor.Location - a.Location).LengthSquared) .FirstOrDefault(); @@ -387,29 +387,13 @@ namespace OpenRA.Mods.RA.Missions einsteinChinook.QueueActivity(new RemoveSelf()); } - IEnumerable UnitsNearLocation(PPos location, int range) - { - return world.FindUnitsInCircle(location, Game.CellSize * range) - .Where(a => a.IsInWorld && a != world.WorldActor && !a.Destroyed && !a.Owner.NonCombatant); - } - - IEnumerable BuildingsNearLocation(PPos location, int range) - { - return UnitsNearLocation(location, range).Where(a => a.HasTrait() && !a.HasTrait()); - } - - IEnumerable ForcesNearLocation(PPos location, int range) - { - return UnitsNearLocation(location, range).Where(a => a.HasTrait()); - } - bool EngineerSafe() { if (engineer.Destroyed) { return false; } - var units = ForcesNearLocation(engineer.CenterLocation, EngineerSafeRange); + var units = world.ForcesNearLocation(engineer.CenterLocation, EngineerSafeRange); return units.Any() && units.All(a => a.Owner == allies1); } diff --git a/OpenRA.Mods.RA/Missions/MissionUtils.cs b/OpenRA.Mods.RA/Missions/MissionUtils.cs new file mode 100644 index 0000000000..4fbd7ccc0f --- /dev/null +++ b/OpenRA.Mods.RA/Missions/MissionUtils.cs @@ -0,0 +1,69 @@ +#region Copyright & License Information +/* + * Copyright 2007-2012 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; +using OpenRA.FileFormats; +using OpenRA.Mods.RA.Activities; +using OpenRA.Mods.RA.Air; +using OpenRA.Mods.RA.Buildings; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA.Missions +{ + public static class MissionUtils + { + public static IEnumerable UnitsNearLocation(this World world, PPos location, int range) + { + return world.FindUnitsInCircle(location, Game.CellSize * range) + .Where(a => a.IsInWorld && a != world.WorldActor && !a.Destroyed && !a.Owner.NonCombatant); + } + + public static IEnumerable BuildingsNearLocation(this World world, PPos location, int range) + { + return UnitsNearLocation(world, location, range).Where(a => a.HasTrait() && !a.HasTrait()); + } + + public static IEnumerable ForcesNearLocation(this World world, PPos location, int range) + { + return UnitsNearLocation(world, location, range).Where(a => a.HasTrait()); + } + + public static Actor ExtractUnitWithChinook(World world, Player owner, Actor unit, CPos entry, CPos lz, CPos exit) + { + var chinook = world.CreateActor("tran", new TypeDictionary { new OwnerInit(owner), new LocationInit(entry) }); + chinook.QueueActivity(new HeliFly(Util.CenterOfCell(lz))); + chinook.QueueActivity(new Turn(0)); + chinook.QueueActivity(new HeliLand(true, 0)); + chinook.QueueActivity(new WaitFor(() => chinook.Trait().Passengers.Contains(unit))); + chinook.QueueActivity(new Wait(150)); + chinook.QueueActivity(new HeliFly(Util.CenterOfCell(exit))); + chinook.QueueActivity(new RemoveSelf()); + return chinook; + } + + public static Actor InsertUnitWithChinook(World world, Player owner, string unitName, CPos entry, CPos lz, CPos exit, Action afterUnload) + { + var unit = world.CreateActor(false, unitName, new TypeDictionary { new OwnerInit(owner) }); + var chinook = world.CreateActor("tran", new TypeDictionary { new OwnerInit(owner), new LocationInit(entry) }); + chinook.Trait().Load(chinook, unit); + chinook.QueueActivity(new HeliFly(Util.CenterOfCell(lz))); + chinook.QueueActivity(new Turn(0)); + chinook.QueueActivity(new HeliLand(true, 0)); + chinook.QueueActivity(new UnloadCargo(true)); + chinook.QueueActivity(new CallFunc(() => afterUnload(unit))); + chinook.QueueActivity(new Wait(150)); + chinook.QueueActivity(new HeliFly(Util.CenterOfCell(exit))); + chinook.QueueActivity(new RemoveSelf()); + return unit; + } + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index cabb716c63..386850be70 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -241,6 +241,7 @@ +