From 0fc04b7a4a360cafb43fac4ae12c3dcce15e246c Mon Sep 17 00:00:00 2001 From: atlimit8 Date: Fri, 25 Sep 2015 13:37:50 -0500 Subject: [PATCH] Make Mobile upgradable --- OpenRA.Mods.Common/Activities/Move/Move.cs | 2 +- .../Scripting/Properties/MobileProperties.cs | 3 ++ OpenRA.Mods.Common/Traits/Mobile.cs | 31 ++++++++++--------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index 5c8ea5b1a0..b3e31e93ff 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -155,7 +155,7 @@ namespace OpenRA.Mods.Common.Activities if (IsCanceled) return NextActivity; - if (moveDisablers.Any(d => d.MoveDisabled(self))) + if (mobile.IsTraitDisabled || moveDisablers.Any(d => d.MoveDisabled(self))) return this; if (destination == mobile.ToCell) diff --git a/OpenRA.Mods.Common/Scripting/Properties/MobileProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/MobileProperties.cs index 7fad4b2834..217edd41c6 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/MobileProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/MobileProperties.cs @@ -61,5 +61,8 @@ namespace OpenRA.Mods.Common.Scripting { Self.QueueActivity(new EnterTransport(Self, transport, 1, true)); } + + [Desc("Whether the actor can move (false if immobilized).")] + public bool IsMobile { get { return !mobile.IsTraitDisabled; } } } } \ No newline at end of file diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 835acd1ab0..804a3b7312 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits } [Desc("Unit is able to move.")] - public class MobileInfo : IMoveInfo, IPositionableInfo, IOccupySpaceInfo, IFacingInfo, + public class MobileInfo : UpgradableTraitInfo, IMoveInfo, IPositionableInfo, IOccupySpaceInfo, IFacingInfo, UsesInit, UsesInit, UsesInit { [FieldLoader.LoadUsing("LoadSpeeds", true)] @@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Traits [VoiceReference] public readonly string Voice = "Action"; - public virtual object Create(ActorInitializer init) { return new Mobile(init, this); } + public override object Create(ActorInitializer init) { return new Mobile(init, this); } static object LoadSpeeds(MiniYaml y) { @@ -304,8 +304,8 @@ namespace OpenRA.Mods.Common.Traits bool IOccupySpaceInfo.SharesCell { get { return SharesCell; } } } - public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync, IDeathActorInitModifier, - INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove + public class Mobile : UpgradableTrait, IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync, + IDeathActorInitModifier, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove { const int AverageTicksBeforePathing = 5; const int SpreadTicksBeforePathing = 5; @@ -313,7 +313,6 @@ namespace OpenRA.Mods.Common.Traits readonly Actor self; readonly Lazy> speedModifiers; - public readonly MobileInfo Info; public bool IsMoving { get; set; } int facing; @@ -349,9 +348,9 @@ namespace OpenRA.Mods.Common.Traits } public Mobile(ActorInitializer init, MobileInfo info) + : base(info) { self = init.Self; - Info = info; speedModifiers = Exts.Lazy(() => self.TraitsImplementing().ToArray().Select(x => x.GetSpeedModifier())); @@ -438,7 +437,7 @@ namespace OpenRA.Mods.Common.Traits self.World.ScreenMap.Remove(self); } - public IEnumerable Orders { get { yield return new MoveOrderTargeter(self, Info); } } + public IEnumerable Orders { get { yield return new MoveOrderTargeter(self, this); } } // Note: Returns a valid order even if the unit can't move to the target public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued) @@ -629,6 +628,9 @@ namespace OpenRA.Mods.Common.Traits public void Nudge(Actor self, Actor nudger, bool force) { + if (IsTraitDisabled) + return; + /* initial fairly braindead implementation. */ if (!force && self.Owner.Stances[nudger.Owner] != Stance.Ally) return; /* don't allow ourselves to be pushed around @@ -691,14 +693,14 @@ namespace OpenRA.Mods.Common.Traits class MoveOrderTargeter : IOrderTargeter { - readonly MobileInfo unitType; + readonly Mobile mobile; readonly bool rejectMove; readonly IDisableMove[] moveDisablers; public bool OverrideSelection { get { return false; } } - public MoveOrderTargeter(Actor self, MobileInfo unitType) + public MoveOrderTargeter(Actor self, Mobile unit) { - this.unitType = unitType; + this.mobile = unit; rejectMove = !self.AcceptsOrder("Move"); moveDisablers = self.TraitsImplementing().ToArray(); } @@ -717,12 +719,13 @@ namespace OpenRA.Mods.Common.Traits var explored = self.Owner.Shroud.IsExplored(location); cursor = self.World.Map.Contains(location) ? - (self.World.Map.GetTerrainInfo(location).CustomCursor ?? unitType.Cursor) : unitType.BlockedCursor; + (self.World.Map.GetTerrainInfo(location).CustomCursor ?? mobile.Info.Cursor) : mobile.Info.BlockedCursor; - if ((!explored && !unitType.MoveIntoShroud) - || (explored && unitType.MovementCostForCell(self.World, location) == int.MaxValue) + if (mobile.IsTraitDisabled + || (!explored && !mobile.Info.MoveIntoShroud) + || (explored && mobile.Info.MovementCostForCell(self.World, location) == int.MaxValue) || moveDisablers.Any(d => d.MoveDisabled(self))) - cursor = unitType.BlockedCursor; + cursor = mobile.Info.BlockedCursor; return true; }