diff --git a/OpenRA.Game/Traits/CreatesShroud.cs b/OpenRA.Game/Traits/CreatesShroud.cs index 93f14fa1cc..9b0f009add 100644 --- a/OpenRA.Game/Traits/CreatesShroud.cs +++ b/OpenRA.Game/Traits/CreatesShroud.cs @@ -29,7 +29,7 @@ namespace OpenRA.Traits public void Tick(Actor self) { - if (!self.TraitsImplementing().Any(d => d.Disabled)) + if (!self.IsDisabled()) self.World.WorldActor.Trait().HideActor(self, Info.Range); } } diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 4f8184a8c2..5ae50ac14b 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Linq; using OpenRA.FileFormats; using OpenRA.GameRules; using OpenRA.Graphics; @@ -224,4 +225,12 @@ namespace OpenRA.Traits public interface ILintPass { void Run(Action emitError, Action emitWarning); } public interface IObjectivesPanel { string ObjectivesPanel { get; } } + + public static class DisableExts + { + public static bool IsDisabled(this Actor a) + { + return a.TraitsImplementing().Any(d => d.Disabled); + } + } } diff --git a/OpenRA.Mods.RA/Attack/AttackBase.cs b/OpenRA.Mods.RA/Attack/AttackBase.cs index 5db1666756..0e40a07d0c 100644 --- a/OpenRA.Mods.RA/Attack/AttackBase.cs +++ b/OpenRA.Mods.RA/Attack/AttackBase.cs @@ -81,7 +81,7 @@ namespace OpenRA.Mods.RA { if (!target.IsValid) return false; if (Weapons.All(w => w.IsReloading)) return false; - if (self.TraitsImplementing().Any(d => d.Disabled)) return false; + if (self.IsDisabled()) return false; if (target.IsActor && target.Actor.HasTrait() && !target.Actor.Trait().TargetableBy(target.Actor,self)) diff --git a/OpenRA.Mods.RA/Attack/AttackTurreted.cs b/OpenRA.Mods.RA/Attack/AttackTurreted.cs index f17470ba95..76b98fad87 100644 --- a/OpenRA.Mods.RA/Attack/AttackTurreted.cs +++ b/OpenRA.Mods.RA/Attack/AttackTurreted.cs @@ -81,8 +81,7 @@ namespace OpenRA.Mods.RA { if( IsCanceled || !target.IsValid ) return NextActivity; - if (self.TraitsImplementing().Any(d => d.Disabled)) - return this; + if (self.IsDisabled()) return this; var attack = self.Trait(); const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */ diff --git a/OpenRA.Mods.RA/Player/ClassicProductionQueue.cs b/OpenRA.Mods.RA/Player/ClassicProductionQueue.cs index 03866a8af0..a77bc145a6 100755 --- a/OpenRA.Mods.RA/Player/ClassicProductionQueue.cs +++ b/OpenRA.Mods.RA/Player/ClassicProductionQueue.cs @@ -55,16 +55,14 @@ namespace OpenRA.Mods.RA && x.Trait.Info.Produces.Contains(Info.Type)) .OrderByDescending(x => x.Actor.IsPrimaryBuilding() ? 1 : 0 ); // prioritize the primary. - if (producers.Count() == 0) + if (!producers.Any()) { CancelProduction(name,1); return true; } - foreach (var p in producers) + foreach (var p in producers.Where(p => !p.Actor.IsDisabled())) { - if (IsDisabledBuilding(p.Actor)) continue; - if (p.Trait.Produce(p.Actor, Rules.Info[ name ])) { FinishProduction(); diff --git a/OpenRA.Mods.RA/Player/ProductionQueue.cs b/OpenRA.Mods.RA/Player/ProductionQueue.cs index ebf3117414..43010b059f 100755 --- a/OpenRA.Mods.RA/Player/ProductionQueue.cs +++ b/OpenRA.Mods.RA/Player/ProductionQueue.cs @@ -294,11 +294,6 @@ namespace OpenRA.Mods.RA Queue.Add(item); } - protected static bool IsDisabledBuilding(Actor a) - { - return a.TraitsImplementing().Any(d => d.Disabled); - } - // Builds a unit from the actor that holds this queue (1 queue per building) // Returns false if the unit can't be built protected virtual bool BuildUnit( string name ) @@ -311,7 +306,7 @@ namespace OpenRA.Mods.RA } var sp = self.TraitsImplementing().FirstOrDefault(p => p.Info.Produces.Contains(Info.Type)); - if (sp != null && !IsDisabledBuilding(self) && sp.Produce(self, Rules.Info[ name ])) + if (sp != null && !self.IsDisabled() && sp.Produce(self, Rules.Info[ name ])) { FinishProduction(); return true; diff --git a/OpenRA.Mods.RA/ProvidesRadar.cs b/OpenRA.Mods.RA/ProvidesRadar.cs index 8ac6d28813..05be93ab1a 100755 --- a/OpenRA.Mods.RA/ProvidesRadar.cs +++ b/OpenRA.Mods.RA/ProvidesRadar.cs @@ -24,8 +24,7 @@ namespace OpenRA.Mods.RA bool UpdateActive(Actor self) { // Check if powered - if (self.TraitsImplementing().Any(d => d.Disabled)) - return false; + if (self.IsDisabled()) return false; var isJammed = self.World.ActorsWithTrait().Any(a => self.Owner != a.Actor.Owner && (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get().Range); diff --git a/OpenRA.Mods.RA/Render/RenderBuilding.cs b/OpenRA.Mods.RA/Render/RenderBuilding.cs index 245015f29b..1977b314d1 100755 --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA.Render public IEnumerable ModifyRender(Actor self, IEnumerable r) { - var disabled = self.TraitsImplementing().Any(d => d.Disabled); + var disabled = self.IsDisabled(); foreach (var a in r) { var ret = a.WithPos(a.Pos - Info.Origin); diff --git a/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs index 9cff445cf8..1aa535c135 100755 --- a/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs @@ -131,36 +131,31 @@ namespace OpenRA.Mods.RA Key = key; } - static bool InstanceDisabled(SupportPower sp) - { - return sp.self.TraitsImplementing().Any(d => d.Disabled); - } - bool notifiedCharging; bool notifiedReady; + public void Tick() { - Active = !Disabled && Instances.Any(i => !InstanceDisabled(i)); + if (Disabled || Instances.All(i => i.self.IsDisabled())) + return; - if (Active) + if (Manager.devMode.FastCharge && RemainingTime > 25) + RemainingTime = 25; + + if (RemainingTime > 0) --RemainingTime; + + var power = Instances.First(); + + if (!notifiedCharging) { - var power = Instances.First(); - if (Manager.devMode.FastCharge && RemainingTime > 25) - RemainingTime = 25; + power.Charging(power.self, Key); + notifiedCharging = true; + } - if (RemainingTime > 0) --RemainingTime; - if (!notifiedCharging) - { - power.Charging(power.self, Key); - notifiedCharging = true; - } - - if (RemainingTime == 0 - && !notifiedReady) - { - power.Charged(power.self, Key); - notifiedReady = true; - } + if (RemainingTime == 0 && !notifiedReady) + { + power.Charged(power.self, Key); + notifiedReady = true; } } @@ -177,7 +172,7 @@ namespace OpenRA.Mods.RA if (!Ready) return; - var power = Instances.First(i => !InstanceDisabled(i)); + var power = Instances.First(i => !i.self.IsDisabled()); // Note: order.Subject is the *player* actor power.Activate(power.self, order);