From d29e3f3f0ec7eb74b16c90837f3a68de345a4363 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 31 Jul 2010 23:38:36 +1200 Subject: [PATCH] Split facing into its own interface; fix husks --- OpenRA.Game/Traits/Activities/Turn.cs | 13 ++++--------- OpenRA.Game/Traits/Mobile.cs | 2 +- OpenRA.Game/Traits/Production.cs | 4 ++-- OpenRA.Game/Traits/TraitsInterfaces.cs | 6 +++++- OpenRA.Game/Traits/Turreted.cs | 12 ++++++------ OpenRA.Mods.Cnc/ProductionAirdrop.cs | 7 +++---- OpenRA.Mods.RA/Activities/Attack.cs | 5 ++--- OpenRA.Mods.RA/Activities/Transform.cs | 6 +++--- OpenRA.Mods.RA/Activities/UnloadCargo.cs | 4 ++-- OpenRA.Mods.RA/Aircraft.cs | 2 +- OpenRA.Mods.RA/AttackBase.cs | 13 +++++++------ OpenRA.Mods.RA/AttackFrontal.cs | 6 +++--- OpenRA.Mods.RA/CarpetBomb.cs | 5 ++--- OpenRA.Mods.RA/Combat.cs | 13 ++++++------- OpenRA.Mods.RA/FreeActor.cs | 6 +++--- OpenRA.Mods.RA/Husk.cs | 7 ++++++- OpenRA.Mods.RA/LeavesHusk.cs | 5 +---- OpenRA.Mods.RA/OreRefineryDockAction.cs | 3 +-- OpenRA.Mods.RA/ProducesHelicopters.cs | 2 +- OpenRA.Mods.RA/Render/RenderInfantry.cs | 2 +- OpenRA.Mods.RA/Render/RenderUnit.cs | 2 +- OpenRA.Mods.RA/Render/RenderUnitRotor.cs | 11 +++++------ OpenRA.Mods.RA/Render/RenderUnitSpinner.cs | 5 ++--- OpenRA.Mods.RA/Render/RenderUnitTurreted.cs | 6 +++--- OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs | 5 ++--- OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs | 5 ++--- OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs | 5 ++--- OpenRA.Mods.RA/ThrowsParticles.cs | 6 +++--- OpenRA.Mods.RA/WithMuzzleFlash.cs | 3 +-- 29 files changed, 81 insertions(+), 90 deletions(-) diff --git a/OpenRA.Game/Traits/Activities/Turn.cs b/OpenRA.Game/Traits/Activities/Turn.cs index 9bcda278cb..d3a4076170 100755 --- a/OpenRA.Game/Traits/Activities/Turn.cs +++ b/OpenRA.Game/Traits/Activities/Turn.cs @@ -15,7 +15,6 @@ namespace OpenRA.Traits.Activities public class Turn : IActivity { public IActivity NextActivity { get; set; } - int desiredFacing; public Turn( int desiredFacing ) @@ -25,22 +24,18 @@ namespace OpenRA.Traits.Activities public IActivity Tick( Actor self ) { - var mobile = self.traits.Get(); - var ROT = self.traits.Get().ROT; + var facing = self.traits.Get(); - if( desiredFacing == mobile.Facing ) + if( desiredFacing == facing.Facing ) return NextActivity; - - mobile.Facing = Util.TickFacing(mobile.Facing, desiredFacing, ROT); + facing.Facing = Util.TickFacing(facing.Facing, desiredFacing, facing.ROT); return this; } public void Cancel( Actor self ) { - var mobile = self.traits.Get(); - - desiredFacing = mobile.Facing; + desiredFacing = self.traits.Get().Facing; NextActivity = null; } } diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index 5b9334266a..8187bf3edc 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -31,7 +31,7 @@ namespace OpenRA.Traits public virtual object Create(ActorInitializer init) { return new Mobile(init, this); } } - public class Mobile : IIssueOrder, IResolveOrder, IOrderCursor, IOrderVoice, IOccupySpace, IMove, INudge + public class Mobile : IIssueOrder, IResolveOrder, IOrderCursor, IOrderVoice, IOccupySpace, IMove, IFacing, INudge { public readonly Actor self; public readonly MobileInfo Info; diff --git a/OpenRA.Game/Traits/Production.cs b/OpenRA.Game/Traits/Production.cs index 6b36be405b..8436eda603 100755 --- a/OpenRA.Game/Traits/Production.cs +++ b/OpenRA.Game/Traits/Production.cs @@ -46,7 +46,7 @@ namespace OpenRA.Traits public virtual int CreationFacing( Actor self, Actor newUnit ) { - return newUnit.traits.Get().InitialFacing; + return newUnit.traits.Get().InitialFacing; } public virtual bool Produce( Actor self, ActorInfo producee ) @@ -56,7 +56,7 @@ namespace OpenRA.Traits return false; var newUnit = self.World.CreateActor( producee.Name, location.Value, self.Owner ); - newUnit.traits.Get().Facing = CreationFacing( self, newUnit ); ; + newUnit.traits.Get().Facing = CreationFacing( self, newUnit ); ; var pi = self.Info.Traits.Get(); var rp = self.traits.GetOrDefault(); diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 6b890ab19c..3e97f6fbbb 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -110,8 +110,12 @@ namespace OpenRA.Traits float MovementCostForCell(Actor self, int2 cell); float MovementSpeedForCell(Actor self, int2 cell); IEnumerable GetCurrentPath(Actor self); - int ROT { get; } int Altitude { get; set; } + } + + public interface IFacing + { + int ROT { get; } int Facing { get; set; } int InitialFacing { get; } } diff --git a/OpenRA.Game/Traits/Turreted.cs b/OpenRA.Game/Traits/Turreted.cs index 6c1be7b77a..0012ffb6c2 100644 --- a/OpenRA.Game/Traits/Turreted.cs +++ b/OpenRA.Game/Traits/Turreted.cs @@ -23,20 +23,20 @@ namespace OpenRA.Traits [Sync] public int turretFacing = 0; public int? desiredFacing; - TurretedInfo Info; - IMove Move; + TurretedInfo info; + IFacing facing; public Turreted(Actor self, TurretedInfo info) { - Info = info; + this.info = info; turretFacing = info.InitialFacing; - Move = self.traits.GetOrDefault(); + facing = self.traits.GetOrDefault(); } public void Tick( Actor self ) { - var df = desiredFacing ?? ( Move != null ? Move.Facing : turretFacing ); - turretFacing = Util.TickFacing(turretFacing, df, Info.ROT); + var df = desiredFacing ?? ( facing != null ? facing.Facing : turretFacing ); + turretFacing = Util.TickFacing(turretFacing, df, info.ROT); } } } diff --git a/OpenRA.Mods.Cnc/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/ProductionAirdrop.cs index 7653990307..46de5f4075 100644 --- a/OpenRA.Mods.Cnc/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/ProductionAirdrop.cs @@ -40,9 +40,8 @@ namespace OpenRA.Mods.Cnc { var a = w.CreateActor("C17", startPos, owner); var cargo = a.traits.Get(); - var aMove = a.traits.Get(); - aMove.Facing = 64; - aMove.Altitude = a.Info.Traits.Get().CruiseAltitude; + a.traits.Get().Facing = 64; + a.traits.Get().Altitude = a.Info.Traits.Get().CruiseAltitude; var newUnit = new Actor(self.World, producee.Name, new int2(0, 0), self.Owner); cargo.Load(a, newUnit); @@ -60,7 +59,7 @@ namespace OpenRA.Mods.Cnc { ww.Add(actor); actor.traits.Get().SetPosition(actor, self.Location + unloadOffset); - newUnit.traits.Get().Facing = 192; + newUnit.traits.Get().Facing = 192; actor.CancelActivity(); actor.QueueActivity(new Move(self.Location + exitOffset, self)); actor.QueueActivity(new Move(rp.rallyPoint, 0)); diff --git a/OpenRA.Mods.RA/Activities/Attack.cs b/OpenRA.Mods.RA/Activities/Attack.cs index 9f3758044a..c0ca817702 100755 --- a/OpenRA.Mods.RA/Activities/Attack.cs +++ b/OpenRA.Mods.RA/Activities/Attack.cs @@ -30,8 +30,7 @@ namespace OpenRA.Mods.RA.Activities public IActivity Tick( Actor self ) { - var move = self.traits.Get(); - + var facing = self.traits.Get(); if (!Target.IsValid) return NextActivity; @@ -45,7 +44,7 @@ namespace OpenRA.Mods.RA.Activities var numDirs = (renderUnit != null) ? renderUnit.anim.CurrentSequence.Facings : 8; - if (Util.QuantizeFacing(move.Facing, numDirs) + if (Util.QuantizeFacing(facing.Facing, numDirs) != Util.QuantizeFacing(desiredFacing, numDirs)) { return new Turn( desiredFacing ) { NextActivity = this }; diff --git a/OpenRA.Mods.RA/Activities/Transform.cs b/OpenRA.Mods.RA/Activities/Transform.cs index 4b48a649f5..8c4c0abb59 100644 --- a/OpenRA.Mods.RA/Activities/Transform.cs +++ b/OpenRA.Mods.RA/Activities/Transform.cs @@ -58,9 +58,9 @@ namespace OpenRA.Mods.RA.Activities if (oldHealth != null && newHealth != null) newHealth.HPFraction = oldHealth.HPFraction; - var move = a.traits.GetOrDefault(); - if (move != null) - move.Facing = facing; + var ifacing = a.traits.GetOrDefault(); + if (ifacing != null) + ifacing.Facing = facing; if (selected) w.Selection.Add(w, a); diff --git a/OpenRA.Mods.RA/Activities/UnloadCargo.cs b/OpenRA.Mods.RA/Activities/UnloadCargo.cs index 7e0e816b95..616822ebb9 100644 --- a/OpenRA.Mods.RA/Activities/UnloadCargo.cs +++ b/OpenRA.Mods.RA/Activities/UnloadCargo.cs @@ -44,9 +44,9 @@ namespace OpenRA.Mods.RA.Activities // if we're a thing that can turn, turn to the // right facing for the unload animation - var move = self.traits.GetOrDefault(); + var facing = self.traits.GetOrDefault(); var unloadFacing = self.Info.Traits.Get().UnloadFacing; - if (move != null && move.Facing != unloadFacing) + if (facing != null && facing.Facing != unloadFacing) return new Turn(unloadFacing) { NextActivity = this }; // todo: handle the BS of open/close sequences, which are inconsistent, diff --git a/OpenRA.Mods.RA/Aircraft.cs b/OpenRA.Mods.RA/Aircraft.cs index be46e84f16..d847878e7d 100755 --- a/OpenRA.Mods.RA/Aircraft.cs +++ b/OpenRA.Mods.RA/Aircraft.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA public virtual object Create( ActorInitializer init ) { return new Aircraft( init , this ); } } - public class Aircraft : IMove, IOccupySpace + public class Aircraft : IMove, IFacing, IOccupySpace { [Sync] public int2 Location; diff --git a/OpenRA.Mods.RA/AttackBase.cs b/OpenRA.Mods.RA/AttackBase.cs index 5be5d0a1b0..4deb961ffe 100644 --- a/OpenRA.Mods.RA/AttackBase.cs +++ b/OpenRA.Mods.RA/AttackBase.cs @@ -103,13 +103,14 @@ namespace OpenRA.Mods.RA if( !CanAttack( self ) ) return; var move = self.traits.GetOrDefault(); + var facing = self.traits.GetOrDefault(); foreach (var w in Weapons) - if (CheckFire(self, move, w)) + if (CheckFire(self, move, facing, w)) w.FiredShot(); } - bool CheckFire(Actor self, IMove move, Weapon w) - { + bool CheckFire(Actor self, IMove move, IFacing facing, Weapon w) + { if (w.FireDelay > 0) return false; var limitedAmmo = self.traits.GetOrDefault(); @@ -132,15 +133,15 @@ namespace OpenRA.Mods.RA target = this.target, src = (self.CenterLocation - + Combat.GetTurretPosition(self, move, w.Turret) - + Combat.GetBarrelPosition(self, move, w.Turret, barrel)).ToInt2(), + + Combat.GetTurretPosition(self, facing, w.Turret) + + Combat.GetBarrelPosition(self, facing, w.Turret, barrel)).ToInt2(), srcAltitude = move != null ? move.Altitude : 0, dest = target.CenterLocation.ToInt2(), destAltitude = destMove != null ? destMove.Altitude : 0, facing = barrel.Facing + (self.traits.Contains() ? self.traits.Get().turretFacing : - move != null ? move.Facing : Util.GetFacing(target.CenterLocation - self.CenterLocation, 0)), + facing != null ? facing.Facing : Util.GetFacing(target.CenterLocation - self.CenterLocation, 0)), }; ScheduleDelayedAction( FireDelay( self, self.Info.Traits.Get() ), () => diff --git a/OpenRA.Mods.RA/AttackFrontal.cs b/OpenRA.Mods.RA/AttackFrontal.cs index 31e3384520..fe67c54bb9 100644 --- a/OpenRA.Mods.RA/AttackFrontal.cs +++ b/OpenRA.Mods.RA/AttackFrontal.cs @@ -26,10 +26,10 @@ namespace OpenRA.Mods.RA if (!target.IsValid) return; - var move = self.traits.Get(); - var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, move.Facing); + var facing = self.traits.Get().Facing; + var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, facing); - if (Math.Abs(facingToTarget - move.Facing) % 256 < FacingTolerance) + if (Math.Abs(facingToTarget - facing) % 256 < FacingTolerance) DoAttack(self); } } diff --git a/OpenRA.Mods.RA/CarpetBomb.cs b/OpenRA.Mods.RA/CarpetBomb.cs index eeb54f7572..7fe1ada802 100644 --- a/OpenRA.Mods.RA/CarpetBomb.cs +++ b/OpenRA.Mods.RA/CarpetBomb.cs @@ -43,14 +43,13 @@ namespace OpenRA.Mods.RA var weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()]; dropDelay = weapon.ROF; - var move = self.traits.Get(); var args = new ProjectileArgs { - srcAltitude = move.Altitude, + srcAltitude = self.traits.Get().Altitude, destAltitude = 0, src = self.CenterLocation.ToInt2(), dest = self.CenterLocation.ToInt2(), - facing = move.Facing, + facing = self.traits.Get().Facing, firedBy = self, weapon = weapon }; diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs index 4e05986d01..a919d2237f 100755 --- a/OpenRA.Mods.RA/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -192,14 +192,13 @@ namespace OpenRA.Mods.RA return Util.RotateVectorByFacing(localRecoil, facing, .7f); } - - public static float2 GetTurretPosition(Actor self, IMove move, Turret turret) + public static float2 GetTurretPosition(Actor self, IFacing facing, Turret turret) { - if(move == null) return turret.ScreenSpacePosition; /* things that don't have a rotating base don't need the turrets repositioned */ + if(facing == null) return turret.ScreenSpacePosition; /* things that don't have a rotating base don't need the turrets repositioned */ var ru = self.traits.GetOrDefault(); var numDirs = (ru != null) ? ru.anim.CurrentSequence.Facings : 8; - var bodyFacing = move.Facing; + var bodyFacing = facing.Facing; var quantizedFacing = Util.QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs); return (Util.RotateVectorByFacing(turret.UnitSpacePosition, quantizedFacing, .7f) @@ -208,14 +207,14 @@ namespace OpenRA.Mods.RA } // gets the screen-space position of a barrel. - public static float2 GetBarrelPosition(Actor self, IMove move, Turret turret, Barrel barrel) + public static float2 GetBarrelPosition(Actor self, IFacing facing, Turret turret, Barrel barrel) { var turreted = self.traits.GetOrDefault(); - if (turreted == null && move == null) + if (turreted == null && facing == null) return float2.Zero; - var turretFacing = turreted != null ? turreted.turretFacing : move.Facing; + var turretFacing = turreted != null ? turreted.turretFacing : facing.Facing; return Util.RotateVectorByFacing(barrel.Position, turretFacing, .7f); } diff --git a/OpenRA.Mods.RA/FreeActor.cs b/OpenRA.Mods.RA/FreeActor.cs index ac603bfd7b..2aa79d202b 100644 --- a/OpenRA.Mods.RA/FreeActor.cs +++ b/OpenRA.Mods.RA/FreeActor.cs @@ -34,9 +34,9 @@ namespace OpenRA.Mods.RA var a = w.CreateActor(info.Actor, self.Location + info.SpawnOffset, self.Owner); - var move = a.traits.GetOrDefault(); - if (move != null) - move.Facing = info.Facing; + var facing = a.traits.GetOrDefault(); + if (facing != null) + facing.Facing = info.Facing; if (info.InitialActivity != null) a.QueueActivity(Game.CreateObject(info.InitialActivity)); diff --git a/OpenRA.Mods.RA/Husk.cs b/OpenRA.Mods.RA/Husk.cs index 0fdee0d3da..9a64a2705c 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -18,11 +18,16 @@ namespace OpenRA.Mods.RA public object Create( ActorInitializer init ) { return new Husk( init ); } } - class Husk : IOccupySpace + class Husk : IOccupySpace, IFacing { Actor self; [Sync] int2 location; + + [Sync] + public int Facing { get; set; } + public int ROT { get { return 0; } } + public int InitialFacing { get { return 0; } } public Husk(ActorInitializer init) { diff --git a/OpenRA.Mods.RA/LeavesHusk.cs b/OpenRA.Mods.RA/LeavesHusk.cs index 3cef70d581..c8a525c37c 100644 --- a/OpenRA.Mods.RA/LeavesHusk.cs +++ b/OpenRA.Mods.RA/LeavesHusk.cs @@ -28,10 +28,7 @@ namespace OpenRA.Mods.RA var info = self.Info.Traits.Get(); var husk = w.CreateActor(info.HuskActor, self.Location, self.Owner); husk.CenterLocation = self.CenterLocation; - var move = self.traits.Get(); - var huskMove = husk.traits.Get(); - huskMove.Altitude = move.Altitude; - huskMove.Facing = move.Facing; + husk.traits.Get().Facing = self.traits.Get().Facing; var turreted = self.traits.GetOrDefault(); if (turreted != null) diff --git a/OpenRA.Mods.RA/OreRefineryDockAction.cs b/OpenRA.Mods.RA/OreRefineryDockAction.cs index bdbabada2a..d847dc190d 100644 --- a/OpenRA.Mods.RA/OreRefineryDockAction.cs +++ b/OpenRA.Mods.RA/OreRefineryDockAction.cs @@ -24,10 +24,9 @@ namespace OpenRA.Mods.RA Actor dockedHarv = null; public void OnDock(Actor self, Actor harv, DeliverResources dockOrder) { - var move = harv.traits.Get(); var harvester = harv.traits.Get(); - if (move.Facing != 64) + if (harv.traits.Get().Facing != 64) harv.QueueActivity (new Turn (64)); harv.QueueActivity (new CallFunc (() => diff --git a/OpenRA.Mods.RA/ProducesHelicopters.cs b/OpenRA.Mods.RA/ProducesHelicopters.cs index 24e987754a..40350e849e 100644 --- a/OpenRA.Mods.RA/ProducesHelicopters.cs +++ b/OpenRA.Mods.RA/ProducesHelicopters.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA return false; var newUnit = self.World.CreateActor( producee.Name, location.Value, self.Owner ); - newUnit.traits.Get().Facing = CreationFacing( self, newUnit ); ; + newUnit.traits.Get().Facing = CreationFacing( self, newUnit ); ; var pi = self.Info.Traits.Get(); var rp = self.traits.GetOrDefault(); diff --git a/OpenRA.Mods.RA/Render/RenderInfantry.cs b/OpenRA.Mods.RA/Render/RenderInfantry.cs index 3f15678172..132eabcd75 100644 --- a/OpenRA.Mods.RA/Render/RenderInfantry.cs +++ b/OpenRA.Mods.RA/Render/RenderInfantry.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render public class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamage { public RenderInfantry(Actor self) - : base(self, () => self.traits.Get().Facing) + : base(self, () => self.traits.Get().Facing) { anim.Play("stand"); } diff --git a/OpenRA.Mods.RA/Render/RenderUnit.cs b/OpenRA.Mods.RA/Render/RenderUnit.cs index f4c33c36ab..0e400c329f 100644 --- a/OpenRA.Mods.RA/Render/RenderUnit.cs +++ b/OpenRA.Mods.RA/Render/RenderUnit.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render public class RenderUnit : RenderSimple, INotifyDamage { public RenderUnit(Actor self) - : base(self, () => self.traits.Contains() ? self.traits.Get().Facing : 0) + : base(self, () => self.traits.Contains() ? self.traits.Get().Facing : 0) { anim.Play("idle"); anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) ); diff --git a/OpenRA.Mods.RA/Render/RenderUnitRotor.cs b/OpenRA.Mods.RA/Render/RenderUnitRotor.cs index 2bc9872468..7996a5740a 100755 --- a/OpenRA.Mods.RA/Render/RenderUnitRotor.cs +++ b/OpenRA.Mods.RA/Render/RenderUnitRotor.cs @@ -24,19 +24,18 @@ namespace OpenRA.Mods.RA.Render class RenderUnitRotor : RenderUnit { public Animation rotorAnim, secondRotorAnim; - IMove move; - public RenderUnitRotor(Actor self) + public RenderUnitRotor( Actor self ) : base(self) { - move = self.traits.Get(); + var facing = self.traits.Get(); var info = self.Info.Traits.Get(); rotorAnim = new Animation(GetImage(self)); rotorAnim.PlayRepeating("rotor"); anims.Add("rotor_1", new AnimationWithOffset( rotorAnim, - () => Combat.GetTurretPosition( self, move, new Turret(info.PrimaryOffset)), + () => Combat.GetTurretPosition( self, facing, new Turret(info.PrimaryOffset)), null ) { ZOffset = 1 } ); if (info.SecondaryOffset == null) return; @@ -45,7 +44,7 @@ namespace OpenRA.Mods.RA.Render secondRotorAnim.PlayRepeating("rotor2"); anims.Add("rotor_2", new AnimationWithOffset( secondRotorAnim, - () => Combat.GetTurretPosition(self, move, new Turret(info.SecondaryOffset)), + () => Combat.GetTurretPosition(self, facing, new Turret(info.SecondaryOffset)), null) { ZOffset = 1 }); } @@ -53,7 +52,7 @@ namespace OpenRA.Mods.RA.Render { base.Tick(self); - var isFlying = move.Altitude > 0; + var isFlying = self.traits.Get().Altitude > 0; if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor")) return; diff --git a/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs b/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs index 55cd212bb4..2db18fa898 100755 --- a/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs +++ b/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs @@ -24,15 +24,14 @@ namespace OpenRA.Mods.RA.Render public RenderUnitSpinner(Actor self) : base(self) { - var move = self.traits.Get(); var info = self.Info.Traits.Get(); var spinnerAnim = new Animation(GetImage(self)); spinnerAnim.PlayRepeating("spinner"); anims.Add("spinner", new AnimationWithOffset( spinnerAnim, - () => Combat.GetTurretPosition(self, move, new Turret(info.Offset)), - null) { ZOffset = 1 }); + () => Combat.GetTurretPosition( self, self.traits.Get(), new Turret(info.Offset)), + null ) { ZOffset = 1 } ); } } } diff --git a/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs b/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs index 10c74b9bfb..ed85f92088 100755 --- a/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs +++ b/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Render public RenderUnitTurreted(Actor self) : base(self) { - var move = self.traits.Get(); + var facing = self.traits.Get(); var turreted = self.traits.Get(); var attack = self.traits.GetOrDefault(); var attackInfo = self.Info.Traits.Get(); @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Render var turret = attack.Turrets[i]; anims.Add( "turret_{0}".F(i), new AnimationWithOffset( turretAnim, - () => Combat.GetTurretPosition( self, move, turret ), + () => Combat.GetTurretPosition( self, facing, turret ), null) { ZOffset = 1 }); if (attackInfo.MuzzleFlash) @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Render () => (int)(turret.Recoil * 5.9f)); /* hack: dumb crap */ anims.Add("muzzle_flash_{0}".F(i), new AnimationWithOffset(muzzleFlash, - () => Combat.GetTurretPosition(self, move, turret), + () => Combat.GetTurretPosition(self, facing, turret), () => turret.Recoil <= 0)); } } diff --git a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs index aa5e54c45c..16b79fd37f 100755 --- a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs @@ -48,9 +48,8 @@ namespace OpenRA.Mods.RA var flare = flareType != null ? w.CreateActor(flareType, order.TargetLocation, Owner) : null; var a = w.CreateActor((Info as AirstrikePowerInfo).UnitType, startPos, Owner); - var aMove = a.traits.Get(); - aMove.Facing = Util.GetFacing(order.TargetLocation - startPos, 0); - aMove.Altitude = a.Info.Traits.Get().CruiseAltitude; + a.traits.Get().Facing = Util.GetFacing(order.TargetLocation - startPos, 0); + a.traits.Get().Altitude = a.Info.Traits.Get().CruiseAltitude; a.traits.Get().SetTarget(order.TargetLocation); a.CancelActivity(); diff --git a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs index 924e49570a..5de8cf607d 100755 --- a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs @@ -61,9 +61,8 @@ namespace OpenRA.Mods.RA var flare = flareType != null ? w.CreateActor(flareType, p, owner) : null; var a = w.CreateActor((Info as ParatroopersPowerInfo).UnitType, startPos, owner); - var aMove = a.traits.Get(); - aMove.Facing = Util.GetFacing(p - startPos, 0); - aMove.Altitude = a.Info.Traits.Get().CruiseAltitude; + a.traits.Get().Facing = Util.GetFacing(p - startPos, 0); + a.traits.Get().Altitude = a.Info.Traits.Get().CruiseAltitude; a.CancelActivity(); a.QueueActivity(new FlyCircle(p)); diff --git a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs index 8b60a8e6d3..16c068ddab 100755 --- a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs @@ -46,9 +46,8 @@ namespace OpenRA.Mods.RA var enterCell = self.World.ChooseRandomEdgeCell(); var plane = self.World.CreateActor("U2", enterCell, self.Owner); - var planeMove = plane.traits.Get(); - planeMove.Altitude = plane.Info.Traits.Get().CruiseAltitude; - planeMove.Facing = Util.GetFacing(order.TargetLocation - enterCell, 0); + plane.traits.Get().Altitude = plane.Info.Traits.Get().CruiseAltitude; + plane.traits.Get().Facing = Util.GetFacing(order.TargetLocation - enterCell, 0); plane.CancelActivity(); plane.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation))); diff --git a/OpenRA.Mods.RA/ThrowsParticles.cs b/OpenRA.Mods.RA/ThrowsParticles.cs index 2a87320c87..2b0564265b 100644 --- a/OpenRA.Mods.RA/ThrowsParticles.cs +++ b/OpenRA.Mods.RA/ThrowsParticles.cs @@ -48,8 +48,8 @@ namespace OpenRA.Mods.RA if (info != null) { alt = 0; - var move = self.traits.Get(); - pos = Combat.GetTurretPosition(self, move, new Turret(info.Offset)); + var ifacing = self.traits.Get(); + pos = Combat.GetTurretPosition(self, ifacing, new Turret(info.Offset)); var ru = self.traits.Get(); v = Game.CosmeticRandom.Gauss2D(1) * info.Spread.RelOffset(); @@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA va = info.Speed; if (!info.UseTurretFacing) InitialFacing = null; - facing = InitialFacing ?? move.Facing; + facing = InitialFacing ?? ifacing.Facing; var anim = new Animation(ru.GetImage(self), () => (int)facing); anim.PlayRepeating(info.Anim); diff --git a/OpenRA.Mods.RA/WithMuzzleFlash.cs b/OpenRA.Mods.RA/WithMuzzleFlash.cs index 8840059544..ac1d7d132d 100644 --- a/OpenRA.Mods.RA/WithMuzzleFlash.cs +++ b/OpenRA.Mods.RA/WithMuzzleFlash.cs @@ -25,11 +25,10 @@ namespace OpenRA.Mods.RA public WithMuzzleFlash(Actor self) { - var move = self.traits.Get(); var attackInfo = self.Info.Traits.Get(); var render = self.traits.Get(); - muzzleFlash = new Animation(render.GetImage(self), () => move.Facing); + muzzleFlash = new Animation(render.GetImage(self), () => self.traits.Get().Facing); muzzleFlash.Play("muzzle"); render.anims.Add("muzzle", new RenderSimple.AnimationWithOffset(