From 533458992285401601429edac6c6b23814c8fa1d Mon Sep 17 00:00:00 2001 From: ScottNZ Date: Fri, 14 Jun 2013 18:58:39 +1200 Subject: [PATCH] Infiltration code cleanup --- OpenRA.Mods.RA/Activities/Infiltrate.cs | 5 +- OpenRA.Mods.RA/InfiltrateForCash.cs | 2 +- OpenRA.Mods.RA/InfiltrateForExploration.cs | 2 +- OpenRA.Mods.RA/InfiltrateForSupportPower.cs | 2 +- OpenRA.Mods.RA/Infiltrates.cs | 30 +++++------- OpenRA.Mods.RA/Missions/Allies04Script.cs | 53 +++++++++++++-------- OpenRA.Mods.RA/Spy.cs | 3 -- mods/ra/maps/allies-04/map.yaml | 13 +++-- mods/ra/rules/infantry.yaml | 2 +- mods/ra/rules/structures.yaml | 8 ++++ 10 files changed, 65 insertions(+), 55 deletions(-) diff --git a/OpenRA.Mods.RA/Activities/Infiltrate.cs b/OpenRA.Mods.RA/Activities/Infiltrate.cs index fc9c9cdbdd..60f1338442 100644 --- a/OpenRA.Mods.RA/Activities/Infiltrate.cs +++ b/OpenRA.Mods.RA/Activities/Infiltrate.cs @@ -27,10 +27,7 @@ namespace OpenRA.Mods.RA.Activities foreach (var t in target.Actor.TraitsImplementing()) t.OnInfiltrate(target.Actor, self); - if (self.HasTrait()) - self.World.AddFrameEndTask(w => { if (!self.Destroyed) w.Remove(self); }); - else - self.Destroy(); + self.World.AddFrameEndTask(w => { if (!self.Destroyed) w.Remove(self); }); if (target.Actor.HasTrait()) Sound.PlayToPlayer(self.Owner, "bldginf1.aud"); diff --git a/OpenRA.Mods.RA/InfiltrateForCash.cs b/OpenRA.Mods.RA/InfiltrateForCash.cs index 8273e09838..1e7ba1c929 100644 --- a/OpenRA.Mods.RA/InfiltrateForCash.cs +++ b/OpenRA.Mods.RA/InfiltrateForCash.cs @@ -16,7 +16,7 @@ using OpenRA.Mods.RA.Effects; namespace OpenRA.Mods.RA { - class InfiltrateForCashInfo : ITraitInfo + class InfiltrateForCashInfo : ITraitInfo, Requires { public readonly int Percentage = 50; public readonly int Minimum = 500; diff --git a/OpenRA.Mods.RA/InfiltrateForExploration.cs b/OpenRA.Mods.RA/InfiltrateForExploration.cs index 85fc6b93b7..a2b4926188 100644 --- a/OpenRA.Mods.RA/InfiltrateForExploration.cs +++ b/OpenRA.Mods.RA/InfiltrateForExploration.cs @@ -14,7 +14,7 @@ using OpenRA.FileFormats; namespace OpenRA.Mods.RA { - class InfiltrateForExplorationInfo : TraitInfo {} + class InfiltrateForExplorationInfo : TraitInfo, Requires { } class InfiltrateForExploration : IAcceptInfiltrator { diff --git a/OpenRA.Mods.RA/InfiltrateForSupportPower.cs b/OpenRA.Mods.RA/InfiltrateForSupportPower.cs index 8b7fec37bc..5e133e2b05 100644 --- a/OpenRA.Mods.RA/InfiltrateForSupportPower.cs +++ b/OpenRA.Mods.RA/InfiltrateForSupportPower.cs @@ -14,7 +14,7 @@ using OpenRA.FileFormats; namespace OpenRA.Mods.RA { - class InfiltrateForSupportPowerInfo : ITraitInfo + class InfiltrateForSupportPowerInfo : ITraitInfo, Requires { [ActorReference] public readonly string Proxy = null; public object Create(ActorInitializer init) { return new InfiltrateForSupportPower(this); } diff --git a/OpenRA.Mods.RA/Infiltrates.cs b/OpenRA.Mods.RA/Infiltrates.cs index 6fb09f79c4..195b355fde 100644 --- a/OpenRA.Mods.RA/Infiltrates.cs +++ b/OpenRA.Mods.RA/Infiltrates.cs @@ -13,16 +13,22 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using OpenRA.Mods.RA.Activities; -using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Orders; using OpenRA.Traits; -using OpenRA.Mods.RA.Missions; namespace OpenRA.Mods.RA { + class InfiltratableInfo : TraitInfo + { + public string Type = null; + } + + class Infiltratable { } + class InfiltratesInfo : ITraitInfo { - public string[] InfiltrateTypes = {"Cash", "SupportPower", "Exploration"}; + public string[] Types = { "Cash", "SupportPower", "Exploration" }; + public object Create(ActorInitializer init) { return new Infiltrates(this); } } @@ -33,14 +39,13 @@ namespace OpenRA.Mods.RA public Infiltrates(InfiltratesInfo info) { Info = info; - } public IEnumerable Orders { get { - yield return new InfiltratorOrderTargeter(target => CanInfiltrate(target)); + yield return new InfiltratorOrderTargeter(CanInfiltrate); } } @@ -73,19 +78,8 @@ namespace OpenRA.Mods.RA bool CanInfiltrate(Actor target) { - if (Info.InfiltrateTypes.Contains("Cash") && target.HasTrait()) - return true; - - if (Info.InfiltrateTypes.Contains("SupportPower") && target.HasTrait()) - return true; - - if (Info.InfiltrateTypes.Contains("Exploration") && target.HasTrait()) - return true; - - if (Info.InfiltrateTypes.Contains("MissionObjective") && target.HasTrait()) - return true; - - return false; + var infiltratable = target.Info.Traits.GetOrDefault(); + return infiltratable != null && Info.Types.Contains(infiltratable.Type); } class InfiltratorOrderTargeter : UnitOrderTargeter diff --git a/OpenRA.Mods.RA/Missions/Allies04Script.cs b/OpenRA.Mods.RA/Missions/Allies04Script.cs index 08270519d2..a9c32e015a 100644 --- a/OpenRA.Mods.RA/Missions/Allies04Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies04Script.cs @@ -168,27 +168,6 @@ namespace OpenRA.Mods.RA.Missions BaseGuardTick(); - if (allies1Spy.IsDead() || (allies2Spy != null && allies2Spy.IsDead())) - { - infiltrateLab.Status = ObjectiveStatus.Failed; - OnObjectivesUpdated(true); - MissionFailed("{0} spy was killed.".F(allies1 != allies2 ? "A" : "The")); - } - else if (lab.IsDead()) - MissionFailed("The Soviet research laboratory was destroyed."); - else if (!world.Actors.Any(a => (a.Owner == allies1 || a.Owner == allies2) && !a.IsDead() - && (a.HasTrait() && !a.HasTrait()) || a.HasTrait())) - { - destroyBase.Status = ObjectiveStatus.Failed; - OnObjectivesUpdated(true); - MissionFailed("The remaining Allied forces in the area have been wiped out."); - } - else if (SovietBaseDestroyed() && infiltrateLab.Status == ObjectiveStatus.Completed) - { - destroyBase.Status = ObjectiveStatus.Completed; - OnObjectivesUpdated(true); - MissionAccomplished("The Soviet research laboratory has been secured successfully."); - } if (world.FrameNumber == nextCivilianMove) { var civilians = world.Actors.Where(a => !a.IsDead() && a.IsInWorld && a.Owner == creeps && a.HasTrait()); @@ -199,6 +178,38 @@ namespace OpenRA.Mods.RA.Missions nextCivilianMove += world.SharedRandom.Next(1, 75); } } + + world.AddFrameEndTask(w => + { + if ((allies1Spy.IsDead() && !allies1SpyInfiltratedLab) || (allies2Spy != null && allies2Spy.IsDead() && !allies2SpyInfiltratedLab)) + { + infiltrateLab.Status = ObjectiveStatus.Failed; + OnObjectivesUpdated(true); + MissionFailed("{0} spy was killed.".F(allies1 != allies2 ? "A" : "The")); + } + else if (lab.IsDead()) + { + if (infiltrateLab.Status == ObjectiveStatus.InProgress) + infiltrateLab.Status = ObjectiveStatus.Failed; + else if (destroyBase.Status == ObjectiveStatus.InProgress) + destroyBase.Status = ObjectiveStatus.Failed; + OnObjectivesUpdated(true); + MissionFailed("The Soviet research laboratory was destroyed."); + } + else if (!world.Actors.Any(a => (a.Owner == allies1 || a.Owner == allies2) && !a.IsDead() + && (a.HasTrait() && !a.HasTrait()) || a.HasTrait())) + { + destroyBase.Status = ObjectiveStatus.Failed; + OnObjectivesUpdated(true); + MissionFailed("The remaining Allied forces in the area have been wiped out."); + } + else if (SovietBaseDestroyed() && infiltrateLab.Status == ObjectiveStatus.Completed) + { + destroyBase.Status = ObjectiveStatus.Completed; + OnObjectivesUpdated(true); + MissionAccomplished("The Soviet research laboratory has been secured successfully."); + } + }); } bool SovietBaseDestroyed() diff --git a/OpenRA.Mods.RA/Spy.cs b/OpenRA.Mods.RA/Spy.cs index aa3651c59b..883c31c34d 100644 --- a/OpenRA.Mods.RA/Spy.cs +++ b/OpenRA.Mods.RA/Spy.cs @@ -142,7 +142,4 @@ namespace OpenRA.Mods.RA class IgnoresDisguiseInfo : TraitInfo {} class IgnoresDisguise {} - - class DontDestroyWhenInfiltratingInfo : TraitInfo { } - class DontDestroyWhenInfiltrating { } } diff --git a/mods/ra/maps/allies-04/map.yaml b/mods/ra/maps/allies-04/map.yaml index cb801df646..203621ca06 100644 --- a/mods/ra/maps/allies-04/map.yaml +++ b/mods/ra/maps/allies-04/map.yaml @@ -1817,6 +1817,8 @@ Rules: AutoTargetIgnore: Allies04TransformOnLabInfiltrate: ToActor: MISS + Infiltratable: + Type: Lab LST.Unselectable: Inherits: LST Buildable: @@ -1836,23 +1838,22 @@ Rules: Buildable: Owner: None SpyToolTip: - Icon: SPY + Icon: spyicon RenderSpy: Image: SPY Health: HP: 100 - DontDestroyWhenInfiltrating: RevealsShroud: Range: 6 Spy: Infiltrates: - InfiltrateTypes: MissionObjective + Types: Lab, Truck DOG.Patrol: Inherits: DOG Buildable: Owner: None Tooltip: - Icon: DOG + Icon: dogicon Mobile: Speed: 4 RenderInfantry: @@ -1866,6 +1867,8 @@ Rules: MaxWeight: 5 PipCount: 5 AutoTargetIgnore: + Infiltratable: + Type: Truck Allies04Hijackable: Allies04RenderHijacked: Image: TRUK @@ -1875,7 +1878,7 @@ Rules: -RenderUnit: Selectable: Voice: SpyVoice - RevealsShroud: + RevealsShroud: Range: 6 BARL: Allies04TrivialBuilding: diff --git a/mods/ra/rules/infantry.yaml b/mods/ra/rules/infantry.yaml index 416dd638e1..841e38b044 100644 --- a/mods/ra/rules/infantry.yaml +++ b/mods/ra/rules/infantry.yaml @@ -204,7 +204,7 @@ SPY: TakeCover: Spy: Infiltrates: - InfiltrateTypes: Cash, SupportPower, Exploration + Types: Cash, SupportPower, Exploration -AutoTarget: AttackMove: JustMove: true diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index a999914ab7..2312faf03f 100644 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -71,6 +71,8 @@ GAP: SPEN: Inherits: ^Building + Infiltratable: + Type: SupportPower InfiltrateForSupportPower: Proxy: powerproxy.sonarpulse Valued: @@ -126,6 +128,8 @@ SPEN: SYRD: Inherits: ^Building + Infiltratable: + Type: SupportPower InfiltrateForSupportPower: Proxy: powerproxy.sonarpulse Buildable: @@ -369,6 +373,8 @@ DOME: Bib: ProvidesRadar: IronCurtainable: + Infiltratable: + Type: Exploration InfiltrateForExploration: PBOX: @@ -972,6 +978,8 @@ PROC: InitialActivity: FindResources SpawnOffset: 1,2 Facing: 64 + Infiltratable: + Type: Cash InfiltrateForCash: Percentage: 50 Minimum: 500