diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index 53fbaa5998..1a45d0408b 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -315,13 +315,12 @@ namespace OpenRA.Mods.Common.Activities public override Activity Tick(Actor self) { - var mobile = self.Trait(); var ret = InnerTick(self, Move.mobile); - mobile.IsMoving = ret is MovePart; + Move.mobile.IsMoving = ret is MovePart; if (moveFraction > MoveFractionTotal) moveFraction = MoveFractionTotal; - UpdateCenterLocation(self, mobile); + UpdateCenterLocation(self, Move.mobile); return ret; } diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 0d0000c387..78dc552ee2 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -312,6 +312,7 @@ namespace OpenRA.Mods.Common.Traits internal int TicksBeforePathing = 0; readonly Actor self; + readonly ISpeedModifier[] speedModifiers; public readonly MobileInfo Info; public bool IsMoving { get; set; } @@ -351,6 +352,8 @@ namespace OpenRA.Mods.Common.Traits self = init.Self; Info = info; + speedModifiers = self.TraitsImplementing().ToArray(); + ToSubCell = FromSubCell = info.SharesCell ? init.World.Map.DefaultSubCell : SubCell.FullCell; if (init.Contains()) FromSubCell = ToSubCell = init.Get(); @@ -597,7 +600,7 @@ namespace OpenRA.Mods.Common.Traits return 0; speed *= Info.Speed; - foreach (var t in self.TraitsImplementing()) + foreach (var t in speedModifiers) speed *= t.GetSpeedModifier() / 100m; return (int)(speed / 100); diff --git a/OpenRA.Mods.Common/Traits/Render/WithMuzzleFlash.cs b/OpenRA.Mods.Common/Traits/Render/WithMuzzleFlash.cs index 253739ce95..e768b56f03 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithMuzzleFlash.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithMuzzleFlash.cs @@ -27,9 +27,10 @@ namespace OpenRA.Mods.Common.Traits class WithMuzzleFlash : UpgradableTrait, INotifyAttack, IRender, ITick { - Dictionary visible = new Dictionary(); - Dictionary anims = new Dictionary(); - Func getFacing; + readonly Dictionary visible = new Dictionary(); + readonly Dictionary anims = new Dictionary(); + readonly Func getFacing; + readonly Armament[] armaments; public WithMuzzleFlash(Actor self, WithMuzzleFlashInfo info) : base(info) @@ -37,7 +38,9 @@ namespace OpenRA.Mods.Common.Traits var render = self.Trait(); var facing = self.TraitOrDefault(); - foreach (var arm in self.TraitsImplementing()) + armaments = self.TraitsImplementing().ToArray(); + + foreach (var arm in armaments) { var armClosure = arm; // closure hazard in AnimationWithOffset @@ -87,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits public IEnumerable Render(Actor self, WorldRenderer wr) { - foreach (var arm in self.TraitsImplementing()) + foreach (var arm in armaments) { var palette = wr.Palette(arm.Info.MuzzlePalette); foreach (var kv in anims) diff --git a/OpenRA.Mods.Common/Traits/Turreted.cs b/OpenRA.Mods.Common/Traits/Turreted.cs index ad78fa147e..1035cea8e5 100644 --- a/OpenRA.Mods.Common/Traits/Turreted.cs +++ b/OpenRA.Mods.Common/Traits/Turreted.cs @@ -13,7 +13,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public class TurretedInfo : ITraitInfo, UsesInit + public class TurretedInfo : ITraitInfo, UsesInit, Requires { public readonly string Turret = "primary"; [Desc("Rate of Turning")] @@ -34,6 +34,7 @@ namespace OpenRA.Mods.Common.Traits readonly TurretedInfo info; AttackTurreted attack; IFacing facing; + IBodyOrientation body; [Sync] public int QuantizedFacings = 0; [Sync] public int TurretFacing = 0; @@ -67,6 +68,7 @@ namespace OpenRA.Mods.Common.Traits { attack = self.TraitOrDefault(); facing = self.TraitOrDefault(); + body = self.Trait(); } public virtual void Tick(Actor self) @@ -94,7 +96,6 @@ namespace OpenRA.Mods.Common.Traits // Turret offset in world-space public WVec Position(Actor self) { - var body = self.Trait(); var bodyOrientation = body.QuantizeOrientation(self, self.Orientation); return body.LocalToWorld(Offset.Rotate(bodyOrientation)); }