diff --git a/OpenRA.Game/GameRules/WeaponInfo.cs b/OpenRA.Game/GameRules/WeaponInfo.cs index 83e96eae68..448c5f8ec7 100644 --- a/OpenRA.Game/GameRules/WeaponInfo.cs +++ b/OpenRA.Game/GameRules/WeaponInfo.cs @@ -19,8 +19,8 @@ namespace OpenRA.GameRules public class ProjectileArgs { public WeaponInfo Weapon; - public IEnumerable DamageModifiers; - public IEnumerable InaccuracyModifiers; + public int[] DamageModifiers; + public int[] InaccuracyModifiers; public int Facing; public WPos Source; public Actor SourceActor; diff --git a/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs b/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs index ef20515a01..806efaba29 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Activities { readonly Target target; readonly AttackPlane attackPlane; - readonly IEnumerable ammoPools; + readonly AmmoPool[] ammoPools; Activity inner; int ticksUntilTurn; @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Activities { this.target = target; attackPlane = self.TraitOrDefault(); - ammoPools = self.TraitsImplementing(); + ammoPools = self.TraitsImplementing().ToArray(); ticksUntilTurn = attackPlane.AttackPlaneInfo.AttackTurnDelay; } @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Activities // Move to the next activity only if all ammo pools are depleted and none reload automatically // TODO: This should check whether there is ammo left that is actually suitable for the target - if (ammoPools != null && ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo())) + if (ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo())) return NextActivity; if (attackPlane != null) diff --git a/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs b/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs index 0e2839bd6f..e9155ecf9f 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs @@ -22,14 +22,14 @@ namespace OpenRA.Mods.Common.Activities readonly Target target; readonly Helicopter helicopter; readonly AttackHeli attackHeli; - readonly IEnumerable ammoPools; + readonly AmmoPool[] ammoPools; public HeliAttack(Actor self, Target target) { this.target = target; helicopter = self.Trait(); attackHeli = self.Trait(); - ammoPools = self.TraitsImplementing(); + ammoPools = self.TraitsImplementing().ToArray(); } public override Activity Tick(Actor self) @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Activities // If all ammo pools are depleted and none reload automatically, return to helipad to reload and then move to next activity // TODO: This should check whether there is ammo left that is actually suitable for the target - if (ammoPools != null && ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo())) + if (ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo())) return Util.SequenceActivities(new HeliReturn(self), NextActivity); var dist = target.CenterPosition - self.CenterPosition; diff --git a/OpenRA.Mods.Common/Activities/Demolish.cs b/OpenRA.Mods.Common/Activities/Demolish.cs index 1ce0282d2a..c72b89290b 100644 --- a/OpenRA.Mods.Common/Activities/Demolish.cs +++ b/OpenRA.Mods.Common/Activities/Demolish.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Activities class Demolish : Enter { readonly Actor target; - readonly IEnumerable demolishables; + readonly IDemolishable[] demolishables; readonly int delay; readonly int flashes; readonly int flashesDelay; @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Activities : base(self, target) { this.target = target; - demolishables = target.TraitsImplementing(); + demolishables = target.TraitsImplementing().ToArray(); this.delay = delay; this.flashes = flashes; this.flashesDelay = flashesDelay; diff --git a/OpenRA.Mods.Common/Activities/Move/Drag.cs b/OpenRA.Mods.Common/Activities/Move/Drag.cs index b4174169c2..0095b9d6c7 100644 --- a/OpenRA.Mods.Common/Activities/Move/Drag.cs +++ b/OpenRA.Mods.Common/Activities/Move/Drag.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Activities { readonly IPositionable positionable; readonly IMove movement; - readonly IEnumerable moveDisablers; + readonly IDisableMove[] moveDisablers; WPos start, end; int length; int ticks = 0; @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Activities { positionable = self.Trait(); movement = self.TraitOrDefault(); - moveDisablers = self.TraitsImplementing(); + moveDisablers = self.TraitsImplementing().ToArray(); this.start = start; this.end = end; this.length = length; diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index 1a45d0408b..9092a14af7 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Activities static readonly List NoPath = new List(); readonly Mobile mobile; - readonly IEnumerable moveDisablers; + readonly IDisableMove[] moveDisablers; readonly WRange nearEnough; readonly Func> getPath; readonly Actor ignoredActor; @@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Activities public Move(Actor self, CPos destination) { mobile = self.Trait(); - moveDisablers = self.TraitsImplementing(); + moveDisablers = self.TraitsImplementing().ToArray(); getPath = () => self.World.WorldActor.Trait().FindPath( @@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Activities public Move(Actor self, CPos destination, WRange nearEnough) { mobile = self.Trait(); - moveDisablers = self.TraitsImplementing(); + moveDisablers = self.TraitsImplementing().ToArray(); getPath = () => self.World.WorldActor.Trait() .FindUnitPath(mobile.ToCell, destination, self); @@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Activities public Move(Actor self, CPos destination, SubCell subCell, WRange nearEnough) { mobile = self.Trait(); - moveDisablers = self.TraitsImplementing(); + moveDisablers = self.TraitsImplementing().ToArray(); getPath = () => self.World.WorldActor.Trait() .FindUnitPathToRange(mobile.FromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self); @@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Activities public Move(Actor self, CPos destination, Actor ignoredActor) { mobile = self.Trait(); - moveDisablers = self.TraitsImplementing(); + moveDisablers = self.TraitsImplementing().ToArray(); getPath = () => self.World.WorldActor.Trait().FindPath( @@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Activities public Move(Actor self, Target target, WRange range) { mobile = self.Trait(); - moveDisablers = self.TraitsImplementing(); + moveDisablers = self.TraitsImplementing().ToArray(); getPath = () => { @@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Activities public Move(Actor self, Func> getPath) { mobile = self.Trait(); - moveDisablers = self.TraitsImplementing(); + moveDisablers = self.TraitsImplementing().ToArray(); this.getPath = getPath; diff --git a/OpenRA.Mods.Common/Activities/Rearm.cs b/OpenRA.Mods.Common/Activities/Rearm.cs index 3a63d52d94..6c4bace567 100644 --- a/OpenRA.Mods.Common/Activities/Rearm.cs +++ b/OpenRA.Mods.Common/Activities/Rearm.cs @@ -17,12 +17,12 @@ namespace OpenRA.Mods.Common.Activities { public class Rearm : Activity { - readonly IEnumerable ammoPools; + readonly AmmoPool[] ammoPools; readonly Dictionary ammoPoolsReloadTimes; public Rearm(Actor self) { - ammoPools = self.TraitsImplementing().Where(p => !p.Info.SelfReloads); + ammoPools = self.TraitsImplementing().Where(p => !p.Info.SelfReloads).ToArray(); if (ammoPools == null) return; diff --git a/OpenRA.Mods.Common/Activities/Turn.cs b/OpenRA.Mods.Common/Activities/Turn.cs index bbfc01d302..fe5d986edd 100644 --- a/OpenRA.Mods.Common/Activities/Turn.cs +++ b/OpenRA.Mods.Common/Activities/Turn.cs @@ -17,12 +17,12 @@ namespace OpenRA.Mods.Common.Activities { public class Turn : Activity { - readonly IEnumerable moveDisablers; + readonly IDisableMove[] moveDisablers; readonly int desiredFacing; public Turn(Actor self, int desiredFacing) { - moveDisablers = self.TraitsImplementing(); + moveDisablers = self.TraitsImplementing().ToArray(); this.desiredFacing = desiredFacing; } diff --git a/OpenRA.Mods.Common/Scripting/Properties/PowerProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/PowerProperties.cs index a942f8809d..450ec40076 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/PowerProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/PowerProperties.cs @@ -59,12 +59,12 @@ namespace OpenRA.Mods.Common.Scripting [ScriptPropertyGroup("Power")] public class ActorPowerProperties : ScriptActorProperties, Requires { - readonly IEnumerable power; + readonly PowerTrait[] power; public ActorPowerProperties(ScriptContext context, Actor self) : base(context, self) { - power = self.TraitsImplementing(); + power = self.TraitsImplementing().ToArray(); } [Desc("Returns the power drained/provided by this actor.")] diff --git a/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs index abc5f73f8b..06d4f607f0 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs @@ -84,13 +84,13 @@ namespace OpenRA.Mods.Common.Scripting [ScriptPropertyGroup("Production")] public class ProductionQueueProperties : ScriptActorProperties, Requires, Requires { - readonly List queues; + readonly ProductionQueue[] queues; readonly ScriptTriggers triggers; public ProductionQueueProperties(ScriptContext context, Actor self) : base(context, self) { - queues = self.TraitsImplementing().Where(q => q.Enabled).ToList(); + queues = self.TraitsImplementing().Where(q => q.Enabled).ToArray(); triggers = TriggerGlobal.GetScriptTriggers(self); } diff --git a/OpenRA.Mods.Common/Traits/Armament.cs b/OpenRA.Mods.Common/Traits/Armament.cs index c28b6453c2..4afb573f11 100644 --- a/OpenRA.Mods.Common/Traits/Armament.cs +++ b/OpenRA.Mods.Common/Traits/Armament.cs @@ -167,10 +167,10 @@ namespace OpenRA.Mods.Common.Traits Facing = legacyFacing, DamageModifiers = self.TraitsImplementing() - .Select(a => a.GetFirepowerModifier()), + .Select(a => a.GetFirepowerModifier()).ToArray(), InaccuracyModifiers = self.TraitsImplementing() - .Select(a => a.GetInaccuracyModifier()), + .Select(a => a.GetInaccuracyModifier()).ToArray(), Source = muzzlePosition, SourceActor = self, diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index a76bccee40..83057ff250 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits this.self = self; var armaments = Exts.Lazy(() => self.TraitsImplementing() - .Where(a => info.Armaments.Contains(a.Info.Name))); + .Where(a => info.Armaments.Contains(a.Info.Name)).ToArray()); getArmaments = () => armaments.Value; diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs b/OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs index 0badcb0b29..aca0f97111 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs @@ -9,6 +9,7 @@ #endregion using System.Collections.Generic; +using System.Linq; using OpenRA.Activities; using OpenRA.Traits; @@ -22,12 +23,12 @@ namespace OpenRA.Mods.Common.Traits public class AttackTurreted : AttackFollow, ITick, ISync { - protected IEnumerable turrets; + protected Turreted[] turrets; public AttackTurreted(Actor self, AttackTurretedInfo info) : base(self, info) { - turrets = self.TraitsImplementing(); + turrets = self.TraitsImplementing().ToArray(); } protected override bool CanAttack(Actor self, Target target) diff --git a/OpenRA.Mods.Common/Traits/Render/WithTurret.cs b/OpenRA.Mods.Common/Traits/Render/WithTurret.cs index e13708d5f0..a5c254ee2c 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithTurret.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithTurret.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Traits IBodyOrientation body; AttackBase ab; Turreted t; - IEnumerable arms; + Armament[] arms; Animation anim; public WithTurret(Actor self, WithTurretInfo info) @@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Traits t = self.TraitsImplementing() .First(tt => tt.Name == info.Turret); arms = self.TraitsImplementing() - .Where(w => w.Info.Turret == info.Turret); + .Where(w => w.Info.Turret == info.Turret).ToArray(); anim = new Animation(self.World, rs.GetImage(self), () => t.TurretFacing); anim.Play(info.Sequence); diff --git a/OpenRA.Mods.Common/Traits/Repairable.cs b/OpenRA.Mods.Common/Traits/Repairable.cs index e3df40b5c5..b275311bfa 100644 --- a/OpenRA.Mods.Common/Traits/Repairable.cs +++ b/OpenRA.Mods.Common/Traits/Repairable.cs @@ -29,13 +29,13 @@ namespace OpenRA.Mods.Common.Traits { readonly RepairableInfo info; readonly Health health; - readonly IEnumerable ammoPools; + readonly AmmoPool[] ammoPools; public Repairable(Actor self, RepairableInfo info) { this.info = info; health = self.Trait(); - ammoPools = self.TraitsImplementing(); + ammoPools = self.TraitsImplementing().ToArray(); } public IEnumerable Orders @@ -72,10 +72,7 @@ namespace OpenRA.Mods.Common.Traits bool CanRearm() { - if (ammoPools != null) - return ammoPools.Any(x => !x.Info.SelfReloads && !x.FullAmmo()); - else - return false; + return ammoPools.Any(x => !x.Info.SelfReloads && !x.FullAmmo()); } public string VoicePhraseForOrder(Actor self, Order order) diff --git a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs index eb32bd562a..dbd83528dd 100644 --- a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Widgets public WorldTooltipType TooltipType { get; private set; } public IToolTip ActorTooltip { get; private set; } - public IEnumerable ActorTooltipExtra { get; private set; } + public IProvideTooltipInfo[] ActorTooltipExtra { get; private set; } public FrozenActor FrozenActorTooltip { get; private set; } public int EdgeScrollThreshold = 15; @@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Widgets if (underCursor != null) { ActorTooltip = underCursor.TraitsImplementing().First(); - ActorTooltipExtra = underCursor.TraitsImplementing(); + ActorTooltipExtra = underCursor.TraitsImplementing().ToArray(); TooltipType = WorldTooltipType.Actor; return; } @@ -125,7 +125,7 @@ namespace OpenRA.Mods.Common.Widgets { FrozenActorTooltip = frozen; if (frozen.Actor != null) - ActorTooltipExtra = frozen.Actor.TraitsImplementing(); + ActorTooltipExtra = frozen.Actor.TraitsImplementing().ToArray(); TooltipType = WorldTooltipType.FrozenActor; } } diff --git a/OpenRA.Mods.D2k/Traits/ThrowsShrapnel.cs b/OpenRA.Mods.D2k/Traits/ThrowsShrapnel.cs index c1d7a4abe7..8d024c5efc 100644 --- a/OpenRA.Mods.D2k/Traits/ThrowsShrapnel.cs +++ b/OpenRA.Mods.D2k/Traits/ThrowsShrapnel.cs @@ -50,10 +50,10 @@ namespace OpenRA.Mods.D2k.Traits Facing = self.World.SharedRandom.Next(-1, 255), DamageModifiers = self.TraitsImplementing() - .Select(a => a.GetFirepowerModifier()), + .Select(a => a.GetFirepowerModifier()).ToArray(), InaccuracyModifiers = self.TraitsImplementing() - .Select(a => a.GetInaccuracyModifier()), + .Select(a => a.GetInaccuracyModifier()).ToArray(), Source = self.CenterPosition, SourceActor = self, diff --git a/OpenRA.Mods.RA/Activities/LayMines.cs b/OpenRA.Mods.RA/Activities/LayMines.cs index bff5105113..be26ed2fe9 100644 --- a/OpenRA.Mods.RA/Activities/LayMines.cs +++ b/OpenRA.Mods.RA/Activities/LayMines.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Activities { readonly Minelayer minelayer; readonly MinelayerInfo info; - readonly IEnumerable ammoPools; + readonly AmmoPool[] ammoPools; readonly IMove movement; readonly string[] rearmBuildings; @@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Activities { minelayer = self.TraitOrDefault(); info = self.Info.Traits.Get(); - ammoPools = self.TraitsImplementing(); + ammoPools = self.TraitsImplementing().ToArray(); movement = self.Trait(); rearmBuildings = info.RearmBuildings; }