From 6f864b055da4ed7fdc751048b1b7c7f049b1db79 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 12 Aug 2018 21:30:41 +0100 Subject: [PATCH] Remove IPreventsTeleport interface. MadTank is changed to use conditions instead. This has a side-benefit of disabling the move cursor while deployed. --- OpenRA.Mods.Cnc/Activities/Teleport.cs | 6 ------ OpenRA.Mods.Cnc/Traits/MadTank.cs | 15 ++++++++++++++- .../Traits/SupportPowers/ChronoshiftPower.cs | 3 +-- mods/ra/rules/vehicles.yaml | 4 ++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/OpenRA.Mods.Cnc/Activities/Teleport.cs b/OpenRA.Mods.Cnc/Activities/Teleport.cs index 91399fa355..d7b10254cc 100644 --- a/OpenRA.Mods.Cnc/Activities/Teleport.cs +++ b/OpenRA.Mods.Cnc/Activities/Teleport.cs @@ -19,8 +19,6 @@ using OpenRA.Traits; namespace OpenRA.Mods.Cnc.Activities { - public interface IPreventsTeleport { bool PreventsTeleport(Actor self); } - public class Teleport : Activity { readonly Actor teleporter; @@ -50,10 +48,6 @@ namespace OpenRA.Mods.Cnc.Activities if (teleporter == self && pc != null && !pc.CanTeleport) return NextActivity; - foreach (var condition in self.TraitsImplementing()) - if (condition.PreventsTeleport(self)) - return NextActivity; - var bestCell = ChooseBestDestinationCell(self, destination); if (bestCell == null) return NextActivity; diff --git a/OpenRA.Mods.Cnc/Traits/MadTank.cs b/OpenRA.Mods.Cnc/Traits/MadTank.cs index a8707f9089..be12bf5f21 100644 --- a/OpenRA.Mods.Cnc/Traits/MadTank.cs +++ b/OpenRA.Mods.Cnc/Traits/MadTank.cs @@ -50,6 +50,10 @@ namespace OpenRA.Mods.Cnc.Traits [VoiceReference] public readonly string Voice = "Action"; + [GrantedConditionReference] + [Desc("The condition to grant to self while deployed.")] + public readonly string DeployedCondition = null; + public WeaponInfo ThumpDamageWeaponInfo { get; private set; } public WeaponInfo DetonationWeaponInfo { get; private set; } @@ -75,12 +79,13 @@ namespace OpenRA.Mods.Cnc.Traits } } - class MadTank : IIssueOrder, IResolveOrder, IOrderVoice, ITick, IPreventsTeleport, IIssueDeployOrder + class MadTank : INotifyCreated, IIssueOrder, IResolveOrder, IOrderVoice, ITick, IIssueDeployOrder { readonly Actor self; readonly MadTankInfo info; readonly WithFacingSpriteBody wfsb; readonly ScreenShaker screenShaker; + ConditionManager conditionManager; bool deployed; int tick; @@ -92,6 +97,11 @@ namespace OpenRA.Mods.Cnc.Traits screenShaker = self.World.WorldActor.Trait(); } + void INotifyCreated.Created(Actor self) + { + conditionManager = self.TraitOrDefault(); + } + void ITick.Tick(Actor self) { if (!deployed) @@ -172,6 +182,9 @@ namespace OpenRA.Mods.Cnc.Traits if (deployed) return; + if (conditionManager != null && !string.IsNullOrEmpty(info.DeployedCondition)) + conditionManager.GrantCondition(self, info.DeployedCondition); + self.World.AddFrameEndTask(w => EjectDriver()); if (info.ThumpSequence != null) wfsb.PlayCustomAnimationRepeating(self, info.ThumpSequence); diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs index 8b7bb37690..4e789a72d4 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs @@ -87,8 +87,7 @@ namespace OpenRA.Mods.Cnc.Traits foreach (var t in tiles) units.UnionWith(Self.World.ActorMap.GetActorsAt(t)); - return units.Where(a => a.TraitsImplementing().Any(cs => !cs.IsTraitDisabled) && - !a.TraitsImplementing().Any(condition => condition.PreventsTeleport(a))); + return units.Where(a => a.TraitsImplementing().Any(cs => !cs.IsTraitDisabled)); } public bool SimilarTerrain(CPos xy, CPos sourceLocation) diff --git a/mods/ra/rules/vehicles.yaml b/mods/ra/rules/vehicles.yaml index fd36c09569..40094b8253 100644 --- a/mods/ra/rules/vehicles.yaml +++ b/mods/ra/rules/vehicles.yaml @@ -769,7 +769,10 @@ QTNK: Armor: Type: Heavy Mobile: + RequiresCondition: !deployed Speed: 56 + Chronoshiftable: + RequiresCondition: !deployed RevealsShroud: Range: 6c0 RevealGeneratedShroud: False @@ -777,6 +780,7 @@ QTNK: Range: 4c0 SelectionDecorations: MadTank: + DeployedCondition: deployed Targetable: TargetTypes: Ground, MADTank, Repair, Vehicle Selectable: