From be9fd1e277e48ceea0b756f5750d3e1816f1757e Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 10 Jan 2010 14:15:45 +1300 Subject: [PATCH] using StatelessTraitInfo<> for some things --- OpenRa.Game/Chrome.cs | 2 +- OpenRa.Game/Traits/Passenger.cs | 12 ++---------- OpenRa.Game/Traits/Plane.cs | 3 --- OpenRa.Game/Traits/Production.cs | 4 ++-- OpenRa.Game/Traits/ProductionSurround.cs | 5 +---- OpenRa.Game/Traits/ProvidesRadar.cs | 19 +++---------------- OpenRa.Game/Traits/RenderBuilding.cs | 2 -- OpenRa.Game/Traits/RenderBuildingCharge.cs | 6 +----- OpenRa.Game/Traits/RenderBuildingOre.cs | 3 +-- OpenRa.Game/Traits/RenderInfantry.cs | 8 +------- OpenRa.Game/Traits/RenderSimple.cs | 1 - OpenRa.Game/Traits/RenderUnitSpinner.cs | 4 +--- OpenRa.Game/Traits/RenderUnitTurreted.cs | 4 +--- OpenRa.Game/Traits/SeedsOre.cs | 7 +------ OpenRa.Game/Traits/Selectable.cs | 9 ++------- OpenRa.Game/Traits/StoresOre.cs | 6 +----- OpenRa.Game/Traits/Thief.cs | 7 +------ OpenRa.Game/Traits/WithShadow.cs | 7 +------ 18 files changed, 20 insertions(+), 89 deletions(-) diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index e350f282f6..3033c1a2fc 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -198,7 +198,7 @@ namespace OpenRa.Game { var hasRadar = Game.world.Actors.Any(a => a.Owner == Game.LocalPlayer && a.traits.Contains() - && a.traits.Get().IsActive()); + && a.traits.Get().IsActive(a)); if (hasRadar != hadRadar) Sound.Play((hasRadar) ? "radaron2.aud" : "radardn1.aud"); diff --git a/OpenRa.Game/Traits/Passenger.cs b/OpenRa.Game/Traits/Passenger.cs index 36cc0f3f5f..7a7305a060 100644 --- a/OpenRa.Game/Traits/Passenger.cs +++ b/OpenRa.Game/Traits/Passenger.cs @@ -1,20 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Linq; using OpenRa.Game.Traits.Activities; namespace OpenRa.Game.Traits { - class PassengerInfo : ITraitInfo - { - public object Create(Actor self) { return new Passenger(self); } - } + class PassengerInfo : StatelessTraitInfo {} class Passenger : IIssueOrder, IResolveOrder { - public Passenger(Actor self) { } - public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { if (mi.Button != MouseButton.Right) diff --git a/OpenRa.Game/Traits/Plane.cs b/OpenRa.Game/Traits/Plane.cs index cd4af54edd..17602323e3 100644 --- a/OpenRa.Game/Traits/Plane.cs +++ b/OpenRa.Game/Traits/Plane.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using OpenRa.Game.Traits.Activities; namespace OpenRa.Game.Traits diff --git a/OpenRa.Game/Traits/Production.cs b/OpenRa.Game/Traits/Production.cs index 406109f882..fa17b7fbff 100755 --- a/OpenRa.Game/Traits/Production.cs +++ b/OpenRa.Game/Traits/Production.cs @@ -1,6 +1,6 @@ -using OpenRa.Game.GameRules; +using System.Collections.Generic; using System.Linq; -using System.Collections.Generic; +using OpenRa.Game.GameRules; namespace OpenRa.Game.Traits { diff --git a/OpenRa.Game/Traits/ProductionSurround.cs b/OpenRa.Game/Traits/ProductionSurround.cs index 39facf6cc8..fb81449bb1 100644 --- a/OpenRa.Game/Traits/ProductionSurround.cs +++ b/OpenRa.Game/Traits/ProductionSurround.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Linq; using OpenRa.Game.GameRules; namespace OpenRa.Game.Traits diff --git a/OpenRa.Game/Traits/ProvidesRadar.cs b/OpenRa.Game/Traits/ProvidesRadar.cs index db8b01fc4e..ec6c0c0536 100644 --- a/OpenRa.Game/Traits/ProvidesRadar.cs +++ b/OpenRa.Game/Traits/ProvidesRadar.cs @@ -1,24 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace OpenRa.Game.Traits { - class ProvidesRadarInfo : ITraitInfo - { - public object Create(Actor self) { return new ProvidesRadar(self); } - } + class ProvidesRadarInfo : StatelessTraitInfo {} class ProvidesRadar { - Actor self; - public ProvidesRadar(Actor self) - { - this.self = self; - } - - public bool IsActive() + public bool IsActive(Actor self) { // TODO: Check for nearby MRJ diff --git a/OpenRa.Game/Traits/RenderBuilding.cs b/OpenRa.Game/Traits/RenderBuilding.cs index d73b16915b..48e58af0ca 100644 --- a/OpenRa.Game/Traits/RenderBuilding.cs +++ b/OpenRa.Game/Traits/RenderBuilding.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using OpenRa.Game.Graphics; using OpenRa.Game.Effects; namespace OpenRa.Game.Traits diff --git a/OpenRa.Game/Traits/RenderBuildingCharge.cs b/OpenRa.Game/Traits/RenderBuildingCharge.cs index f76821b972..9c6b88efd5 100644 --- a/OpenRa.Game/Traits/RenderBuildingCharge.cs +++ b/OpenRa.Game/Traits/RenderBuildingCharge.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace OpenRa.Game.Traits { class RenderBuildingChargeInfo : RenderBuildingInfo diff --git a/OpenRa.Game/Traits/RenderBuildingOre.cs b/OpenRa.Game/Traits/RenderBuildingOre.cs index 0909475d78..1e06072a1e 100644 --- a/OpenRa.Game/Traits/RenderBuildingOre.cs +++ b/OpenRa.Game/Traits/RenderBuildingOre.cs @@ -1,5 +1,4 @@ -using System; - + namespace OpenRa.Game.Traits { class RenderBuildingOreInfo : RenderBuildingInfo diff --git a/OpenRa.Game/Traits/RenderInfantry.cs b/OpenRa.Game/Traits/RenderInfantry.cs index babf20589f..d3edc1ee33 100644 --- a/OpenRa.Game/Traits/RenderInfantry.cs +++ b/OpenRa.Game/Traits/RenderInfantry.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using OpenRa.Game.Graphics; -using OpenRa.Game.GameRules; -using OpenRa.Game.Effects; +using OpenRa.Game.Effects; namespace OpenRa.Game.Traits { diff --git a/OpenRa.Game/Traits/RenderSimple.cs b/OpenRa.Game/Traits/RenderSimple.cs index 7975607053..4eb4570dad 100644 --- a/OpenRa.Game/Traits/RenderSimple.cs +++ b/OpenRa.Game/Traits/RenderSimple.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using IjwFramework.Collections; using OpenRa.Game.Graphics; namespace OpenRa.Game.Traits diff --git a/OpenRa.Game/Traits/RenderUnitSpinner.cs b/OpenRa.Game/Traits/RenderUnitSpinner.cs index 8dc54c535b..ab1212f97f 100755 --- a/OpenRa.Game/Traits/RenderUnitSpinner.cs +++ b/OpenRa.Game/Traits/RenderUnitSpinner.cs @@ -10,14 +10,12 @@ namespace OpenRa.Game.Traits class RenderUnitSpinner : RenderUnit { - public Animation spinnerAnim; - public RenderUnitSpinner( Actor self ) : base(self) { var unit = self.traits.Get(); - spinnerAnim = new Animation( self.Info.Name ); + var spinnerAnim = new Animation( self.Info.Name ); spinnerAnim.PlayRepeating( "spinner" ); anims.Add( "spinner", new AnimationWithOffset( spinnerAnim, diff --git a/OpenRa.Game/Traits/RenderUnitTurreted.cs b/OpenRa.Game/Traits/RenderUnitTurreted.cs index 041fa20c78..e88d9fd29a 100644 --- a/OpenRa.Game/Traits/RenderUnitTurreted.cs +++ b/OpenRa.Game/Traits/RenderUnitTurreted.cs @@ -11,8 +11,6 @@ namespace OpenRa.Game.Traits class RenderUnitTurreted : RenderUnit { - public Animation muzzleFlash; - public RenderUnitTurreted(Actor self) : base(self) { @@ -37,7 +35,7 @@ namespace OpenRa.Game.Traits if( self.Info.MuzzleFlash ) { - muzzleFlash = new Animation( self.Info.Name ); + var muzzleFlash = new Animation( self.Info.Name ); muzzleFlash.PlayFetchIndex( "muzzle", () => ( Util.QuantizeFacing( self.traits.Get().turretFacing, 8 ) ) * 6 + (int)( attack.primaryRecoil * 5.9f ) ); /* hack: recoil can be 1.0f, but don't overflow into next anim */ diff --git a/OpenRa.Game/Traits/SeedsOre.cs b/OpenRa.Game/Traits/SeedsOre.cs index f5dd4a123d..a722e3f858 100644 --- a/OpenRa.Game/Traits/SeedsOre.cs +++ b/OpenRa.Game/Traits/SeedsOre.cs @@ -1,15 +1,10 @@  namespace OpenRa.Game.Traits { - class SeedsOreInfo : ITraitInfo - { - public object Create(Actor self) { return new SeedsOre(self); } - } + class SeedsOreInfo : StatelessTraitInfo {} class SeedsOre : ITick { - public SeedsOre( Actor self ) {} - const double OreSeedProbability = .05; // todo: push this out into rules public void Tick(Actor self) diff --git a/OpenRa.Game/Traits/Selectable.cs b/OpenRa.Game/Traits/Selectable.cs index 85f8b01592..5e7a42c575 100755 --- a/OpenRa.Game/Traits/Selectable.cs +++ b/OpenRa.Game/Traits/Selectable.cs @@ -5,17 +5,12 @@ using System.Text; namespace OpenRa.Game.Traits { - class SelectableInfo : ITraitInfo + class SelectableInfo : StatelessTraitInfo { public readonly int Priority = 10; public readonly int[] Bounds = null; public readonly string Voice = "GenericVoice"; - - public object Create(Actor self) { return new Selectable(self); } } - class Selectable - { - public Selectable( Actor self ) { } - } + class Selectable {} } diff --git a/OpenRa.Game/Traits/StoresOre.cs b/OpenRa.Game/Traits/StoresOre.cs index fad732b83c..4fa5945e96 100644 --- a/OpenRa.Game/Traits/StoresOre.cs +++ b/OpenRa.Game/Traits/StoresOre.cs @@ -3,18 +3,14 @@ using System; using OpenRa.Game.GameRules; namespace OpenRa.Game.Traits { - class StoresOreInfo : ITraitInfo + class StoresOreInfo : StatelessTraitInfo { public readonly int Pips = 0; public readonly int Capacity = 0; - - public object Create(Actor self) { return new StoresOre(self); } } class StoresOre : IPips, IAcceptThief { - public StoresOre(Actor self) {} - public void OnSteal(Actor self, Actor thief) { // Steal half the ore the building holds diff --git a/OpenRa.Game/Traits/Thief.cs b/OpenRa.Game/Traits/Thief.cs index 591391a164..685ccefa68 100644 --- a/OpenRa.Game/Traits/Thief.cs +++ b/OpenRa.Game/Traits/Thief.cs @@ -3,15 +3,10 @@ using System.Collections.Generic; using System.Linq; namespace OpenRa.Game.Traits { - class ThiefInfo : ITraitInfo - { - public object Create(Actor self) { return new Thief(self); } - } + class ThiefInfo : StatelessTraitInfo { } class Thief : IIssueOrder, IResolveOrder { - public Thief(Actor self) { } - public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { if (mi.Button != MouseButton.Right) return null; diff --git a/OpenRa.Game/Traits/WithShadow.cs b/OpenRa.Game/Traits/WithShadow.cs index 39153ba058..5eb49890bc 100644 --- a/OpenRa.Game/Traits/WithShadow.cs +++ b/OpenRa.Game/Traits/WithShadow.cs @@ -6,15 +6,10 @@ using OpenRa.Game.Graphics; namespace OpenRa.Game.Traits { - class WithShadowInfo : ITraitInfo - { - public object Create(Actor self) { return new WithShadow(self); } - } + class WithShadowInfo : StatelessTraitInfo {} class WithShadow : IRenderModifier { - public WithShadow(Actor self) {} - public IEnumerable ModifyRender(Actor self, IEnumerable r) { var unit = self.traits.Get();