diff --git a/OpenRA.Mods.Common/Traits/Air/Helicopter.cs b/OpenRA.Mods.Common/Traits/Air/Helicopter.cs index ee5cc8eafb..be611b586d 100644 --- a/OpenRA.Mods.Common/Traits/Air/Helicopter.cs +++ b/OpenRA.Mods.Common/Traits/Air/Helicopter.cs @@ -36,7 +36,6 @@ namespace OpenRA.Mods.Common.Traits public class Helicopter : Aircraft, ITick, IResolveOrder, IMove { public readonly HelicopterInfo Info; - readonly bool fallsToEarth; Actor self; bool firstTick = true; public bool IsMoving { get { return self.CenterPosition.Z > 0; } set { } } @@ -46,7 +45,6 @@ namespace OpenRA.Mods.Common.Traits { self = init.Self; Info = info; - fallsToEarth = self.HasTrait(); } public void ResolveOrder(Actor self, Order order) @@ -132,7 +130,7 @@ namespace OpenRA.Mods.Common.Traits if (firstTick) { firstTick = false; - if (!fallsToEarth) // TODO: Aircraft husks don't properly unreserve. + if (!self.HasTrait()) // TODO: Aircraft husks don't properly unreserve. ReserveSpawnBuilding(); var host = GetActorBelow(); diff --git a/OpenRA.Mods.Common/Traits/Air/Plane.cs b/OpenRA.Mods.Common/Traits/Air/Plane.cs index a9ac2f6be3..8e18c49e9d 100644 --- a/OpenRA.Mods.Common/Traits/Air/Plane.cs +++ b/OpenRA.Mods.Common/Traits/Air/Plane.cs @@ -26,7 +26,6 @@ namespace OpenRA.Mods.Common.Traits public class Plane : Aircraft, IResolveOrder, IMove, ITick, ISync { public readonly PlaneInfo Info; - readonly bool fallsToEarth; [Sync] public WPos RTBPathHash; Actor self; public bool IsMoving { get { return self.CenterPosition.Z > 0; } set { } } @@ -36,7 +35,6 @@ namespace OpenRA.Mods.Common.Traits { self = init.Self; Info = info; - fallsToEarth = self.HasTrait(); } bool firstTick = true; @@ -45,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits if (firstTick) { firstTick = false; - if (!fallsToEarth) // TODO: Aircraft husks don't properly unreserve. + if (!self.HasTrait()) // TODO: Aircraft husks don't properly unreserve. ReserveSpawnBuilding(); var host = GetActorBelow(); diff --git a/OpenRA.Mods.Common/Traits/ExternalCapturable.cs b/OpenRA.Mods.Common/Traits/ExternalCapturable.cs index 7160af26e7..f046deaecd 100644 --- a/OpenRA.Mods.Common/Traits/ExternalCapturable.cs +++ b/OpenRA.Mods.Common/Traits/ExternalCapturable.cs @@ -51,20 +51,21 @@ namespace OpenRA.Mods.Common.Traits public class ExternalCapturable : ITick { - readonly Building building; [Sync] public int CaptureProgressTime = 0; [Sync] public Actor Captor; + private Actor self; public ExternalCapturableInfo Info; public bool CaptureInProgress { get { return Captor != null; } } public ExternalCapturable(Actor self, ExternalCapturableInfo info) { + this.self = self; Info = info; - building = self.TraitOrDefault(); } public void BeginCapture(Actor captor) { + var building = self.TraitOrDefault(); if (building != null) building.Lock(); @@ -73,6 +74,7 @@ namespace OpenRA.Mods.Common.Traits public void EndCapture() { + var building = self.TraitOrDefault(); if (building != null) building.Unlock(); diff --git a/OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs b/OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs index d52ddeed22..a54b1af6e0 100644 --- a/OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs +++ b/OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs @@ -13,7 +13,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("Makes the unit automatically run around when taking damage.")] - class ScaredyCatInfo : ITraitInfo + class ScaredyCatInfo : ITraitInfo, Requires { [Desc("How long (in ticks) the actor should panic for.")] public readonly int PanicLength = 25 * 10; diff --git a/OpenRA.Mods.Common/Traits/RepairableNear.cs b/OpenRA.Mods.Common/Traits/RepairableNear.cs index 99ff27c40e..76eeb80f0c 100644 --- a/OpenRA.Mods.Common/Traits/RepairableNear.cs +++ b/OpenRA.Mods.Common/Traits/RepairableNear.cs @@ -17,7 +17,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - class RepairableNearInfo : ITraitInfo, Requires + class RepairableNearInfo : ITraitInfo, Requires, Requires { [ActorReference] public readonly string[] Buildings = { "spen", "syrd" }; public readonly int CloseEnough = 4; /* cells */ diff --git a/OpenRA.Mods.Common/Traits/Sellable.cs b/OpenRA.Mods.Common/Traits/Sellable.cs index 393ab5e6ad..30f179c884 100644 --- a/OpenRA.Mods.Common/Traits/Sellable.cs +++ b/OpenRA.Mods.Common/Traits/Sellable.cs @@ -30,8 +30,6 @@ namespace OpenRA.Mods.Common.Traits readonly Actor self; readonly Lazy health; readonly SellableInfo info; - readonly Building building; - readonly WithMakeAnimation makeAnimation; public Sellable(Actor self, SellableInfo info) : base(info) @@ -39,8 +37,6 @@ namespace OpenRA.Mods.Common.Traits this.self = self; this.info = info; health = Exts.Lazy(() => self.TraitOrDefault()); - building = self.TraitOrDefault(); - makeAnimation = self.TraitOrDefault(); } public void ResolveOrder(Actor self, Order order) @@ -54,6 +50,7 @@ namespace OpenRA.Mods.Common.Traits if (IsTraitDisabled) return; + var building = self.TraitOrDefault(); if (building != null && !building.Lock()) return; @@ -65,6 +62,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var ns in self.TraitsImplementing()) ns.Selling(self); + var makeAnimation = self.TraitOrDefault(); if (makeAnimation != null) makeAnimation.Reverse(self, new Sell(self), false); else diff --git a/OpenRA.Mods.Common/Traits/Transforms.cs b/OpenRA.Mods.Common/Traits/Transforms.cs index 9ad74b49cf..6bbe0cae65 100644 --- a/OpenRA.Mods.Common/Traits/Transforms.cs +++ b/OpenRA.Mods.Common/Traits/Transforms.cs @@ -46,18 +46,14 @@ namespace OpenRA.Mods.Common.Traits { readonly Actor self; readonly TransformsInfo info; - readonly Building building; readonly BuildingInfo buildingInfo; readonly string race; - readonly WithMakeAnimation makeAnimation; public Transforms(ActorInitializer init, TransformsInfo info) { self = init.Self; this.info = info; buildingInfo = self.World.Map.Rules.Actors[info.IntoActor].Traits.GetOrDefault(); - building = self.TraitOrDefault(); - makeAnimation = self.TraitOrDefault(); race = init.Contains() ? init.Get() : self.Owner.Country.Race; } @@ -68,6 +64,7 @@ namespace OpenRA.Mods.Common.Traits bool CanDeploy() { + var building = self.TraitOrDefault(); if (building != null && building.Locked) return false; @@ -89,6 +86,7 @@ namespace OpenRA.Mods.Common.Traits public void DeployTransform(bool queued) { + var building = self.TraitOrDefault(); if (!CanDeploy() || (building != null && !building.Lock())) { foreach (var s in info.NoTransformSounds) @@ -117,6 +115,7 @@ namespace OpenRA.Mods.Common.Traits Race = race }; + var makeAnimation = self.TraitOrDefault(); if (makeAnimation != null) makeAnimation.Reverse(self, transform); else