diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index eaf14c9b48..572a190541 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -136,8 +136,8 @@ namespace OpenRA if (useAltitude) { - var unit = traits.GetOrDefault(); - if (unit != null) loc -= new float2(0, unit.Altitude); + var move = traits.GetOrDefault(); + if (move != null) loc -= new float2(0, move.Altitude); } return new RectangleF(loc.X, loc.Y, size.X, size.Y); diff --git a/OpenRA.Game/Traits/Activities/Move.cs b/OpenRA.Game/Traits/Activities/Move.cs index 4fbc10cb6f..4fc9734b82 100755 --- a/OpenRA.Game/Traits/Activities/Move.cs +++ b/OpenRA.Game/Traits/Activities/Move.cs @@ -90,7 +90,6 @@ namespace OpenRA.Traits.Activities public IActivity Tick( Actor self ) { - var unit = self.traits.Get(); var mobile = self.traits.Get(); if( move != null ) @@ -127,8 +126,8 @@ namespace OpenRA.Traits.Activities return this; int2 dir = nextCell.Value - mobile.fromCell; - var firstFacing = Util.GetFacing( dir, unit.Facing ); - if( firstFacing != unit.Facing ) + var firstFacing = Util.GetFacing( dir, mobile.Facing ); + if( firstFacing != mobile.Facing ) { path.Add( nextCell.Value ); @@ -140,8 +139,8 @@ namespace OpenRA.Traits.Activities move = new MoveFirstHalf( Util.CenterOfCell( mobile.fromCell ), Util.BetweenCells( mobile.fromCell, mobile.toCell ), - unit.Facing, - unit.Facing, + mobile.Facing, + mobile.Facing, 0 ); move.TickMove( self, mobile, this ); @@ -262,9 +261,9 @@ namespace OpenRA.Traits.Activities self.CenterLocation = float2.Lerp( from, to, frac ); if( moveFraction >= moveFractionTotal ) - unit.Facing = toFacing & 0xFF; + mobile.Facing = toFacing & 0xFF; else - unit.Facing = ( fromFacing + ( toFacing - fromFacing ) * moveFraction / moveFractionTotal ) & 0xFF; + mobile.Facing = ( fromFacing + ( toFacing - fromFacing ) * moveFraction / moveFractionTotal ) & 0xFF; } protected abstract MovePart OnComplete( Actor self, Mobile mobile, Move parent ); @@ -289,8 +288,8 @@ namespace OpenRA.Traits.Activities var ret = new MoveFirstHalf( Util.BetweenCells( mobile.fromCell, mobile.toCell ), Util.BetweenCells( mobile.toCell, nextCell.Value ), - unit.Facing, - Util.GetNearestFacing( unit.Facing, Util.GetFacing( nextCell.Value - mobile.toCell, unit.Facing ) ), + mobile.Facing, + Util.GetNearestFacing( mobile.Facing, Util.GetFacing( nextCell.Value - mobile.toCell, mobile.Facing ) ), moveFraction - moveFractionTotal ); mobile.fromCell = mobile.toCell; mobile.toCell = nextCell.Value; @@ -302,8 +301,8 @@ namespace OpenRA.Traits.Activities var ret2 = new MoveSecondHalf( Util.BetweenCells( mobile.fromCell, mobile.toCell ), Util.CenterOfCell( mobile.toCell ), - unit.Facing, - unit.Facing, + mobile.Facing, + mobile.Facing, moveFraction - moveFractionTotal ); mobile.fromCell = mobile.toCell; return ret2; diff --git a/OpenRA.Game/Traits/Activities/Turn.cs b/OpenRA.Game/Traits/Activities/Turn.cs index 6bdabeb5ab..9bcda278cb 100755 --- a/OpenRA.Game/Traits/Activities/Turn.cs +++ b/OpenRA.Game/Traits/Activities/Turn.cs @@ -25,22 +25,22 @@ namespace OpenRA.Traits.Activities public IActivity Tick( Actor self ) { - var unit = self.traits.Get(); + var mobile = self.traits.Get(); var ROT = self.traits.Get().ROT; - if( desiredFacing == unit.Facing ) + if( desiredFacing == mobile.Facing ) return NextActivity; - Util.TickFacing(ref unit.Facing, desiredFacing, ROT); + mobile.Facing = Util.TickFacing(mobile.Facing, desiredFacing, ROT); return this; } public void Cancel( Actor self ) { - var unit = self.traits.Get(); + var mobile = self.traits.Get(); - desiredFacing = unit.Facing; + desiredFacing = mobile.Facing; NextActivity = null; } } diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index 5da4585e6f..5b9334266a 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -39,6 +39,13 @@ namespace OpenRA.Traits public readonly Dictionary TerrainSpeed; [Sync] + public int Facing { get; set; } + [Sync] + public int Altitude { get; set; } + [Sync] + public int ROT { get { return Info.ROT; } } + public int InitialFacing { get { return Info.InitialFacing; } } + int2 __fromCell, __toCell; public int2 fromCell { @@ -90,9 +97,6 @@ namespace OpenRA.Traits TerrainSpeed.Add(info.TerrainTypes[i], info.TerrainSpeeds[i]); } } - - public int ROT { get { return Info.ROT; } } - public int InitialFacing { get { return Info.InitialFacing; } } public void SetPosition(Actor self, int2 cell) { diff --git a/OpenRA.Game/Traits/Production.cs b/OpenRA.Game/Traits/Production.cs index dbb96e34e6..6b36be405b 100755 --- a/OpenRA.Game/Traits/Production.cs +++ b/OpenRA.Game/Traits/Production.cs @@ -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/Selectable.cs b/OpenRA.Game/Traits/Selectable.cs index 0b16dd497c..af021b22b3 100644 --- a/OpenRA.Game/Traits/Selectable.cs +++ b/OpenRA.Game/Traits/Selectable.cs @@ -156,11 +156,10 @@ namespace OpenRA.Traits { if (!Game.world.LocalPlayer.PlayerActor.traits.Get().PathDebug) return; - var mobile = self.traits.WithInterface().FirstOrDefault(); + var mobile = self.traits.GetOrDefault(); if (mobile != null) { - var unit = self.traits.Get(); - var alt = (unit != null)? new float2(0, -unit.Altitude) : float2.Zero; + var alt = new float2(0, -mobile.Altitude); var path = mobile.GetCurrentPath(self); var start = self.CenterLocation + alt; diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 671090dd17..6b890ab19c 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -111,6 +111,8 @@ namespace OpenRA.Traits float MovementSpeedForCell(Actor self, int2 cell); IEnumerable GetCurrentPath(Actor self); int ROT { get; } + int Altitude { get; set; } + int Facing { get; set; } int InitialFacing { get; } } diff --git a/OpenRA.Game/Traits/Turreted.cs b/OpenRA.Game/Traits/Turreted.cs index 585cdeb8cb..6c1be7b77a 100644 --- a/OpenRA.Game/Traits/Turreted.cs +++ b/OpenRA.Game/Traits/Turreted.cs @@ -10,12 +10,12 @@ namespace OpenRA.Traits { - class TurretedInfo : ITraitInfo + public class TurretedInfo : ITraitInfo { public readonly int ROT = 255; public readonly int InitialFacing = 128; - public object Create(ActorInitializer init) { return new Turreted(init.self); } + public object Create(ActorInitializer init) { return new Turreted(init.self, this); } } public class Turreted : ITick @@ -23,16 +23,20 @@ namespace OpenRA.Traits [Sync] public int turretFacing = 0; public int? desiredFacing; - - public Turreted(Actor self) + TurretedInfo Info; + IMove Move; + + public Turreted(Actor self, TurretedInfo info) { - turretFacing = self.Info.Traits.Get().InitialFacing; + Info = info; + turretFacing = info.InitialFacing; + Move = self.traits.GetOrDefault(); } public void Tick( Actor self ) { - var df = desiredFacing ?? ( self.traits.Contains() ? self.traits.Get().Facing : turretFacing ); - Util.TickFacing(ref turretFacing, df, self.Info.Traits.Get().ROT); + var df = desiredFacing ?? ( Move != null ? Move.Facing : turretFacing ); + turretFacing = Util.TickFacing(turretFacing, df, Info.ROT); } } } diff --git a/OpenRA.Game/Traits/Unit.cs b/OpenRA.Game/Traits/Unit.cs index 640c78dee2..8f7b3042f1 100755 --- a/OpenRA.Game/Traits/Unit.cs +++ b/OpenRA.Game/Traits/Unit.cs @@ -20,12 +20,7 @@ namespace OpenRA.Traits } public class Unit : INotifyDamage, IRadarSignature - { - [Sync] - public int Facing; - [Sync] - public int Altitude; - + { public void Damaged(Actor self, AttackInfo e) { if (e.DamageState == DamageState.Dead) diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index 166115732a..0a6efdd507 100755 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -17,16 +17,16 @@ namespace OpenRA.Traits { public static class Util { - public static void TickFacing( ref int facing, int desiredFacing, int rot ) + public static int TickFacing( int facing, int desiredFacing, int rot ) { var leftTurn = ( facing - desiredFacing ) & 0xFF; var rightTurn = ( desiredFacing - facing ) & 0xFF; if( Math.Min( leftTurn, rightTurn ) < rot ) - facing = desiredFacing & 0xFF; + return desiredFacing & 0xFF; else if( rightTurn < leftTurn ) - facing = ( facing + rot ) & 0xFF; + return ( facing + rot ) & 0xFF; else - facing = ( facing - rot ) & 0xFF; + return ( facing - rot ) & 0xFF; } static float2[] fvecs = Graphics.Util.MakeArray( 32, diff --git a/OpenRA.Mods.Cnc/MobileAir.cs b/OpenRA.Mods.Cnc/MobileAir.cs index ecb02a9f12..68baee1507 100644 --- a/OpenRA.Mods.Cnc/MobileAir.cs +++ b/OpenRA.Mods.Cnc/MobileAir.cs @@ -84,17 +84,17 @@ namespace OpenRA.Traits int offsetTicks = 0; public void Tick(Actor self) { - var unit = self.traits.Get(); + var move = self.traits.Get(); //if (unit.Altitude <= 0) // return; - if (unit.Altitude < AirInfo.CruiseAltitude) - unit.Altitude++; + if (move.Altitude < AirInfo.CruiseAltitude) + move.Altitude++; if (--offsetTicks <= 0) { self.CenterLocation += AirInfo.InstabilityMagnitude * self.World.SharedRandom.Gauss2D(5); - unit.Altitude += (int)(AirInfo.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5)); + move.Altitude += (int)(AirInfo.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5)); offsetTicks = AirInfo.InstabilityTicks; } } diff --git a/OpenRA.Mods.Cnc/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/ProductionAirdrop.cs index 2df903a0dc..7653990307 100644 --- a/OpenRA.Mods.Cnc/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/ProductionAirdrop.cs @@ -40,8 +40,9 @@ namespace OpenRA.Mods.Cnc { var a = w.CreateActor("C17", startPos, owner); var cargo = a.traits.Get(); - a.traits.Get().Facing = 64; - a.traits.Get().Altitude = a.Info.Traits.Get().CruiseAltitude; + var aMove = a.traits.Get(); + aMove.Facing = 64; + aMove.Altitude = a.Info.Traits.Get().CruiseAltitude; var newUnit = new Actor(self.World, producee.Name, new int2(0, 0), self.Owner); cargo.Load(a, newUnit); @@ -58,8 +59,8 @@ namespace OpenRA.Mods.Cnc self.World.AddFrameEndTask(ww => { ww.Add(actor); - actor.traits.WithInterface().FirstOrDefault().SetPosition(actor, self.Location + unloadOffset); - newUnit.traits.Get().Facing = 192; + actor.traits.Get().SetPosition(actor, self.Location + unloadOffset); + 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 124906ae20..9f3758044a 100755 --- a/OpenRA.Mods.RA/Activities/Attack.cs +++ b/OpenRA.Mods.RA/Activities/Attack.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Activities public IActivity Tick( Actor self ) { - var unit = self.traits.Get(); + var move = self.traits.Get(); if (!Target.IsValid) return NextActivity; @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Activities var numDirs = (renderUnit != null) ? renderUnit.anim.CurrentSequence.Facings : 8; - if (Util.QuantizeFacing(unit.Facing, numDirs) + if (Util.QuantizeFacing(move.Facing, numDirs) != Util.QuantizeFacing(desiredFacing, numDirs)) { return new Turn( desiredFacing ) { NextActivity = this }; diff --git a/OpenRA.Mods.RA/Activities/Fly.cs b/OpenRA.Mods.RA/Activities/Fly.cs index a76e987f5b..be91060222 100644 --- a/OpenRA.Mods.RA/Activities/Fly.cs +++ b/OpenRA.Mods.RA/Activities/Fly.cs @@ -34,15 +34,14 @@ namespace OpenRA.Mods.RA.Activities if (d.LengthSquared < 50) /* close enough */ return NextActivity; - var unit = self.traits.Get(); + var aircraft = self.traits.Get(); - var desiredFacing = Util.GetFacing(d, unit.Facing); - if (unit.Altitude == cruiseAltitude) - Util.TickFacing(ref unit.Facing, desiredFacing, - self.Info.Traits.Get().ROT); + var desiredFacing = Util.GetFacing(d, aircraft.Facing); + if (aircraft.Altitude == cruiseAltitude) + aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT); - if (unit.Altitude < cruiseAltitude) - ++unit.Altitude; + if (aircraft.Altitude < cruiseAltitude) + ++aircraft.Altitude; FlyUtil.Fly(self, cruiseAltitude); return this; @@ -55,16 +54,12 @@ namespace OpenRA.Mods.RA.Activities { public static void Fly(Actor self, int desiredAltitude ) { - var unit = self.traits.Get(); - var mobile = self.traits.WithInterface().FirstOrDefault(); - var speed = .2f * mobile.MovementSpeedForCell(self, self.Location); - var angle = unit.Facing / 128f * Math.PI; var aircraft = self.traits.Get(); - + var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location); + var angle = aircraft.Facing / 128f * Math.PI; self.CenterLocation += speed * -float2.FromAngle((float)angle); aircraft.Location = Util.CellContaining(self.CenterLocation); - - unit.Altitude += Math.Sign(desiredAltitude - unit.Altitude); + aircraft.Altitude += Math.Sign(desiredAltitude - aircraft.Altitude); } } } diff --git a/OpenRA.Mods.RA/Activities/HeliAttack.cs b/OpenRA.Mods.RA/Activities/HeliAttack.cs index 054cc14b3c..a7c4948b47 100644 --- a/OpenRA.Mods.RA/Activities/HeliAttack.cs +++ b/OpenRA.Mods.RA/Activities/HeliAttack.cs @@ -32,22 +32,21 @@ namespace OpenRA.Mods.RA.Activities self.QueueActivity(new HeliReturn()); return NextActivity; } - var unit = self.traits.Get(); + + var aircraft = self.traits.Get(); var info = self.Info.Traits.Get(); - if (unit.Altitude != info.CruiseAltitude) + if (aircraft.Altitude != info.CruiseAltitude) { - unit.Altitude += Math.Sign(info.CruiseAltitude - unit.Altitude); + aircraft.Altitude += Math.Sign(info.CruiseAltitude - aircraft.Altitude); return this; } var range = self.traits.Get().GetMaximumRange() - 1; var dist = target.CenterLocation - self.CenterLocation; - var desiredFacing = Util.GetFacing(dist, unit.Facing); - Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.Traits.Get().ROT); - - var mobile = self.traits.WithInterface().FirstOrDefault(); - var rawSpeed = .2f * mobile.MovementSpeedForCell(self, self.Location); + var desiredFacing = Util.GetFacing(dist, aircraft.Facing); + aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT); + var rawSpeed = .2f * aircraft.MovementSpeedForCell(self, self.Location); if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize)) self.CenterLocation += (rawSpeed / dist.Length) * dist; diff --git a/OpenRA.Mods.RA/Activities/HeliFly.cs b/OpenRA.Mods.RA/Activities/HeliFly.cs index be4db31496..c906d79a56 100644 --- a/OpenRA.Mods.RA/Activities/HeliFly.cs +++ b/OpenRA.Mods.RA/Activities/HeliFly.cs @@ -30,13 +30,12 @@ namespace OpenRA.Mods.RA.Activities if (isCanceled) return NextActivity; - var unit = self.traits.Get(); var info = self.Info.Traits.Get(); var aircraft = self.traits.Get(); - if (unit.Altitude != info.CruiseAltitude) + if (aircraft.Altitude != info.CruiseAltitude) { - unit.Altitude += Math.Sign(info.CruiseAltitude - unit.Altitude); + aircraft.Altitude += Math.Sign(info.CruiseAltitude - aircraft.Altitude); return this; } @@ -48,12 +47,11 @@ namespace OpenRA.Mods.RA.Activities return NextActivity; } - var desiredFacing = Util.GetFacing(dist, unit.Facing); - Util.TickFacing(ref unit.Facing, desiredFacing, - self.Info.Traits.Get().ROT); + var desiredFacing = Util.GetFacing(dist, aircraft.Facing); + aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, + aircraft.ROT); - var mobile = self.traits.WithInterface().FirstOrDefault(); - var rawSpeed = .2f * mobile.MovementSpeedForCell(self, self.Location); + var rawSpeed = .2f * aircraft.MovementSpeedForCell(self, self.Location); self.CenterLocation += (rawSpeed / dist.Length) * dist; aircraft.Location = Util.CellContaining(self.CenterLocation); diff --git a/OpenRA.Mods.RA/Activities/HeliLand.cs b/OpenRA.Mods.RA/Activities/HeliLand.cs index 521e132e9b..eb214c8ceb 100644 --- a/OpenRA.Mods.RA/Activities/HeliLand.cs +++ b/OpenRA.Mods.RA/Activities/HeliLand.cs @@ -23,14 +23,14 @@ namespace OpenRA.Mods.RA.Activities public IActivity Tick(Actor self) { if (isCanceled) return NextActivity; - var unit = self.traits.Get(); - if (unit.Altitude == 0) + var aircraft = self.traits.Get(); + if (aircraft.Altitude == 0) return NextActivity; - if (requireSpace && !self.traits.Get().CanEnterCell(self.Location)) + if (requireSpace && !aircraft.CanEnterCell(self.Location)) return this; - --unit.Altitude; + --aircraft.Altitude; return this; } diff --git a/OpenRA.Mods.RA/Activities/Land.cs b/OpenRA.Mods.RA/Activities/Land.cs index abade04f2b..daaba94011 100644 --- a/OpenRA.Mods.RA/Activities/Land.cs +++ b/OpenRA.Mods.RA/Activities/Land.cs @@ -39,17 +39,15 @@ namespace OpenRA.Mods.RA.Activities if (d.LengthSquared < 50) /* close enough */ return NextActivity; - var unit = self.traits.Get(); var aircraft = self.traits.Get(); - if (unit.Altitude > 0) - --unit.Altitude; + if (aircraft.Altitude > 0) + --aircraft.Altitude; - var desiredFacing = Util.GetFacing(d, unit.Facing); - Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.Traits.Get().ROT); - var mobile = self.traits.WithInterface().FirstOrDefault(); - var speed = .2f * mobile.MovementSpeedForCell(self, self.Location); - var angle = unit.Facing / 128f * Math.PI; + var desiredFacing = Util.GetFacing(d, aircraft.Facing); + aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT); + var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location); + var angle = aircraft.Facing / 128f * Math.PI; self.CenterLocation += speed * -float2.FromAngle((float)angle); aircraft.Location = Util.CellContaining(self.CenterLocation); diff --git a/OpenRA.Mods.RA/Activities/ReturnToBase.cs b/OpenRA.Mods.RA/Activities/ReturnToBase.cs index 0d2a3d60e8..f8e5d247d5 100644 --- a/OpenRA.Mods.RA/Activities/ReturnToBase.cs +++ b/OpenRA.Mods.RA/Activities/ReturnToBase.cs @@ -41,15 +41,15 @@ namespace OpenRA.Mods.RA.Activities self.traits.Get().reservation = res.Reserve(self); var landPos = dest.CenterLocation; - var unit = self.traits.Get(); - var mobile = self.traits.WithInterface().FirstOrDefault(); - var speed = .2f * mobile.MovementSpeedForCell(self, self.Location); + var aircraft = self.traits.Get(); + + var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location); - var approachStart = landPos - new float2(unit.Altitude * speed, 0); + var approachStart = landPos - new float2(aircraft.Altitude * speed, 0); var turnRadius = (128f / self.Info.Traits.Get().ROT) * speed / (float)Math.PI; /* work out the center points */ - var fwd = -float2.FromAngle(unit.Facing / 128f * (float)Math.PI); + var fwd = -float2.FromAngle(aircraft.Facing / 128f * (float)Math.PI); var side = new float2(-fwd.Y, fwd.X); /* rotate */ var sideTowardBase = new[] { side, -side } .OrderBy(a => float2.Dot(a, self.CenterLocation - approachStart)) diff --git a/OpenRA.Mods.RA/Activities/Transform.cs b/OpenRA.Mods.RA/Activities/Transform.cs index d4303926c0..4b48a649f5 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 unit = a.traits.GetOrDefault(); - if (unit != null) - unit.Facing = facing; + var move = a.traits.GetOrDefault(); + if (move != null) + move.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 ec2b0d50bd..7e0e816b95 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 unit = self.traits.GetOrDefault(); + var move = self.traits.GetOrDefault(); var unloadFacing = self.Info.Traits.Get().UnloadFacing; - if (unit != null && unit.Facing != unloadFacing) + if (move != null && move.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 90a8903454..be46e84f16 100755 --- a/OpenRA.Mods.RA/Aircraft.cs +++ b/OpenRA.Mods.RA/Aircraft.cs @@ -32,6 +32,11 @@ namespace OpenRA.Mods.RA { [Sync] public int2 Location; + [Sync] + public int Facing { get; set; } + [Sync] + public int Altitude { get; set; } + AircraftInfo Info; public Aircraft( ActorInitializer init , AircraftInfo info) diff --git a/OpenRA.Mods.RA/AttackBase.cs b/OpenRA.Mods.RA/AttackBase.cs index a8f1fe4312..5be5d0a1b0 100644 --- a/OpenRA.Mods.RA/AttackBase.cs +++ b/OpenRA.Mods.RA/AttackBase.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made @@ -102,15 +102,13 @@ namespace OpenRA.Mods.RA { if( !CanAttack( self ) ) return; - var unit = self.traits.GetOrDefault(); - var info = self.Info.Traits.Get(); - + var move = self.traits.GetOrDefault(); foreach (var w in Weapons) - if (CheckFire(self, unit, w)) + if (CheckFire(self, move, w)) w.FiredShot(); } - bool CheckFire(Actor self, Unit unit, Weapon w) + bool CheckFire(Actor self, IMove move, Weapon w) { if (w.FireDelay > 0) return false; @@ -124,8 +122,7 @@ namespace OpenRA.Mods.RA if (!w.IsValidAgainst(target)) return false; var barrel = w.Barrels[w.Burst % w.Barrels.Length]; - - var destUnit = target.IsActor ? target.Actor.traits.GetOrDefault() : null; + var destMove = target.IsActor ? target.Actor.traits.GetOrDefault() : null; var args = new ProjectileArgs { @@ -135,15 +132,15 @@ namespace OpenRA.Mods.RA target = this.target, src = (self.CenterLocation - + Combat.GetTurretPosition(self, unit, w.Turret) - + Combat.GetBarrelPosition(self, unit, w.Turret, barrel)).ToInt2(), - srcAltitude = unit != null ? unit.Altitude : 0, + + Combat.GetTurretPosition(self, move, w.Turret) + + Combat.GetBarrelPosition(self, move, w.Turret, barrel)).ToInt2(), + srcAltitude = move != null ? move.Altitude : 0, dest = target.CenterLocation.ToInt2(), - destAltitude = destUnit != null ? destUnit.Altitude : 0, + destAltitude = destMove != null ? destMove.Altitude : 0, facing = barrel.Facing + (self.traits.Contains() ? self.traits.Get().turretFacing : - unit != null ? unit.Facing : Util.GetFacing(target.CenterLocation - self.CenterLocation, 0)), + move != null ? move.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 94ff6874f3..31e3384520 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 unit = self.traits.Get(); - var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, unit.Facing); + var move = self.traits.Get(); + var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, move.Facing); - if (Math.Abs(facingToTarget - unit.Facing) % 256 < FacingTolerance) + if (Math.Abs(facingToTarget - move.Facing) % 256 < FacingTolerance) DoAttack(self); } } diff --git a/OpenRA.Mods.RA/Cargo.cs b/OpenRA.Mods.RA/Cargo.cs index 09bd074f69..f255642fcb 100644 --- a/OpenRA.Mods.RA/Cargo.cs +++ b/OpenRA.Mods.RA/Cargo.cs @@ -51,8 +51,8 @@ namespace OpenRA.Mods.RA return false; // Cannot unload mid-air - var unit = self.traits.GetOrDefault(); - if (unit != null && unit.Altitude > 0) + var move = self.traits.GetOrDefault(); + if (move != null && move.Altitude > 0) return false; // Todo: Check if there is a free tile to unload to diff --git a/OpenRA.Mods.RA/CarpetBomb.cs b/OpenRA.Mods.RA/CarpetBomb.cs index 1872ef6564..eeb54f7572 100644 --- a/OpenRA.Mods.RA/CarpetBomb.cs +++ b/OpenRA.Mods.RA/CarpetBomb.cs @@ -43,13 +43,14 @@ namespace OpenRA.Mods.RA var weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()]; dropDelay = weapon.ROF; + var move = self.traits.Get(); var args = new ProjectileArgs { - srcAltitude = self.traits.Get().Altitude, + srcAltitude = move.Altitude, destAltitude = 0, src = self.CenterLocation.ToInt2(), dest = self.CenterLocation.ToInt2(), - facing = self.traits.Get().Facing, + facing = move.Facing, firedBy = self, weapon = weapon }; diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs index 5e173ae7c1..4e05986d01 100755 --- a/OpenRA.Mods.RA/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -193,13 +193,13 @@ namespace OpenRA.Mods.RA return Util.RotateVectorByFacing(localRecoil, facing, .7f); } - public static float2 GetTurretPosition(Actor self, Unit unit, Turret turret) + public static float2 GetTurretPosition(Actor self, IMove move, Turret turret) { - if (unit == null) return turret.ScreenSpacePosition; + if(move == 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 = unit.Facing; + var bodyFacing = move.Facing; var quantizedFacing = Util.QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs); return (Util.RotateVectorByFacing(turret.UnitSpacePosition, quantizedFacing, .7f) @@ -208,14 +208,14 @@ namespace OpenRA.Mods.RA } // gets the screen-space position of a barrel. - public static float2 GetBarrelPosition(Actor self, Unit unit, Turret turret, Barrel barrel) + public static float2 GetBarrelPosition(Actor self, IMove move, Turret turret, Barrel barrel) { var turreted = self.traits.GetOrDefault(); - if (turreted == null && unit == null) + if (turreted == null && move == null) return float2.Zero; - var turretFacing = turreted != null ? turreted.turretFacing : unit.Facing; + var turretFacing = turreted != null ? turreted.turretFacing : move.Facing; return Util.RotateVectorByFacing(barrel.Position, turretFacing, .7f); } diff --git a/OpenRA.Mods.RA/CrateDrop.cs b/OpenRA.Mods.RA/CrateDrop.cs index 00ac4c13af..dec5bcdb14 100644 --- a/OpenRA.Mods.RA/CrateDrop.cs +++ b/OpenRA.Mods.RA/CrateDrop.cs @@ -72,7 +72,8 @@ namespace OpenRA.Mods.RA var startPos = w.ChooseRandomEdgeCell(); var plane = w.CreateActor("BADR", startPos, w.WorldActor.Owner); - plane.traits.Get().Facing = Util.GetFacing(p - startPos, 0); + var aircraft = plane.traits.Get(); + aircraft.Facing = Util.GetFacing(p - startPos, 0); plane.CancelActivity(); plane.QueueActivity(new FlyCircle(p)); plane.traits.Get().SetLZ(p, null); diff --git a/OpenRA.Mods.RA/DemoTruck.cs b/OpenRA.Mods.RA/DemoTruck.cs index 21bedd8600..5c5f7ae6d3 100644 --- a/OpenRA.Mods.RA/DemoTruck.cs +++ b/OpenRA.Mods.RA/DemoTruck.cs @@ -33,9 +33,9 @@ namespace OpenRA.Mods.RA public void Detonate(Actor self, Actor detonatedBy) { - var unit = self.traits.GetOrDefault(); + var move = self.traits.GetOrDefault(); var info = self.Info.Traits.Get(); - var altitude = unit != null ? unit.Altitude : 0; + var altitude = move != null ? move.Altitude : 0; self.World.AddFrameEndTask( w => { diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index 7ef71bade1..ea21cb8d20 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -76,11 +76,11 @@ namespace OpenRA.Mods.RA.Effects var targetPosition = Args.target.CenterLocation + offset; var targetAltitude = 0; - if (Args.target.IsActor && Args.target.Actor.traits.Contains()) - targetAltitude = Args.target.Actor.traits.Get().Altitude; + if (Args.target.IsActor && Args.target.Actor.traits.Contains()) + targetAltitude = Args.target.Actor.traits.Get().Altitude; Altitude += Math.Sign(targetAltitude - Altitude); - Traits.Util.TickFacing(ref Facing, + Facing = Traits.Util.TickFacing(Facing, Traits.Util.GetFacing(targetPosition - Pos, Facing), Info.ROT); diff --git a/OpenRA.Mods.RA/Explodes.cs b/OpenRA.Mods.RA/Explodes.cs index 3f991c7b00..89e0cdce2d 100644 --- a/OpenRA.Mods.RA/Explodes.cs +++ b/OpenRA.Mods.RA/Explodes.cs @@ -30,8 +30,8 @@ namespace OpenRA.Mods.RA var weapon = ChooseWeaponForExplosion(self); if (weapon != null) { - var unit = self.traits.GetOrDefault(); - var altitude = unit != null ? unit.Altitude : 0; + var move = self.traits.GetOrDefault(); + var altitude = move != null ? move.Altitude : 0; Combat.DoExplosion(e.Attacker, weapon, self.CenterLocation, altitude); } } diff --git a/OpenRA.Mods.RA/FreeActor.cs b/OpenRA.Mods.RA/FreeActor.cs index 0dc7cb1264..ac603bfd7b 100644 --- a/OpenRA.Mods.RA/FreeActor.cs +++ b/OpenRA.Mods.RA/FreeActor.cs @@ -33,10 +33,10 @@ namespace OpenRA.Mods.RA { var a = w.CreateActor(info.Actor, self.Location + info.SpawnOffset, self.Owner); - var unit = a.traits.WithInterface().FirstOrDefault(); - - if (unit != null) - unit.Facing = info.Facing; + + var move = a.traits.GetOrDefault(); + if (move != null) + move.Facing = info.Facing; if (info.InitialActivity != null) a.QueueActivity(Game.CreateObject(info.InitialActivity)); diff --git a/OpenRA.Mods.RA/Helicopter.cs b/OpenRA.Mods.RA/Helicopter.cs index 9ef9f7863e..0695e1b4d7 100644 --- a/OpenRA.Mods.RA/Helicopter.cs +++ b/OpenRA.Mods.RA/Helicopter.cs @@ -129,12 +129,11 @@ namespace OpenRA.Mods.RA int offsetTicks = 0; public void Tick(Actor self) { - var unit = self.traits.Get(); - if (unit.Altitude <= 0) + var aircraft = self.traits.Get(); + if (aircraft.Altitude <= 0) return; - var mobile = self.traits.WithInterface().FirstOrDefault(); - var rawSpeed = .2f * mobile.MovementSpeedForCell(self, self.Location); + var rawSpeed = .2f * aircraft.MovementSpeedForCell(self, self.Location); var otherHelis = self.World.FindUnitsInCircle(self.CenterLocation, Info.IdealSeparation) .Where(a => a.traits.Contains()); @@ -147,7 +146,7 @@ namespace OpenRA.Mods.RA if (--offsetTicks <= 0) { self.CenterLocation += Info.InstabilityMagnitude * self.World.SharedRandom.Gauss2D(5); - unit.Altitude += (int)(Info.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5)); + aircraft.Altitude += (int)(Info.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5)); offsetTicks = Info.InstabilityTicks; } diff --git a/OpenRA.Mods.RA/LeavesHusk.cs b/OpenRA.Mods.RA/LeavesHusk.cs index bed5690bbf..3cef70d581 100644 --- a/OpenRA.Mods.RA/LeavesHusk.cs +++ b/OpenRA.Mods.RA/LeavesHusk.cs @@ -28,8 +28,10 @@ namespace OpenRA.Mods.RA var info = self.Info.Traits.Get(); var husk = w.CreateActor(info.HuskActor, self.Location, self.Owner); husk.CenterLocation = self.CenterLocation; - husk.traits.Get().Altitude = self.traits.Get().Altitude; - husk.traits.Get().Facing = self.traits.Get().Facing; + var move = self.traits.Get(); + var huskMove = husk.traits.Get(); + huskMove.Altitude = move.Altitude; + huskMove.Facing = move.Facing; var turreted = self.traits.GetOrDefault(); if (turreted != null) diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 9d994e83c1..593d331470 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -1,4 +1,4 @@ - + Debug diff --git a/OpenRA.Mods.RA/OreRefineryDockAction.cs b/OpenRA.Mods.RA/OreRefineryDockAction.cs index 291a42f7b2..bdbabada2a 100644 --- a/OpenRA.Mods.RA/OreRefineryDockAction.cs +++ b/OpenRA.Mods.RA/OreRefineryDockAction.cs @@ -24,10 +24,10 @@ namespace OpenRA.Mods.RA Actor dockedHarv = null; public void OnDock(Actor self, Actor harv, DeliverResources dockOrder) { - var unit = harv.traits.Get(); + var move = harv.traits.Get(); var harvester = harv.traits.Get(); - if (unit.Facing != 64) + if (move.Facing != 64) harv.QueueActivity (new Turn (64)); harv.QueueActivity (new CallFunc (() => diff --git a/OpenRA.Mods.RA/ParaDrop.cs b/OpenRA.Mods.RA/ParaDrop.cs index 6d4ec53261..c310e34bec 100644 --- a/OpenRA.Mods.RA/ParaDrop.cs +++ b/OpenRA.Mods.RA/ParaDrop.cs @@ -57,10 +57,11 @@ namespace OpenRA.Mods.RA var a = cargo.Unload(self); var rs = a.traits.Get(); + var aircraft = self.traits.Get(); self.World.AddFrameEndTask(w => w.Add( new Parachute(self.Owner, rs.anim.Name, Util.CenterOfCell(Util.CellContaining(self.CenterLocation)), - self.traits.Get().Altitude, a))); + aircraft.Altitude, a))); Sound.Play(info.ChuteSound, self.CenterLocation); } diff --git a/OpenRA.Mods.RA/Plane.cs b/OpenRA.Mods.RA/Plane.cs index 00def236a9..200ce9da1e 100644 --- a/OpenRA.Mods.RA/Plane.cs +++ b/OpenRA.Mods.RA/Plane.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA if (firstTick) { firstTick = false; - if (self.traits.Get().Altitude == 0) + if (self.traits.Get().Altitude == 0) { /* not spawning in the air, so try to assoc. with our afld. this is a hack. */ var res = self.World.FindUnits(self.CenterLocation, self.CenterLocation) diff --git a/OpenRA.Mods.RA/ProducesHelicopters.cs b/OpenRA.Mods.RA/ProducesHelicopters.cs index 0ff7fb9048..24e987754a 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 8947a3128e..3f15678172 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 46754487f1..f4c33c36ab 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.Get().Facing) + : 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 cb2874ad7c..2bc9872468 100755 --- a/OpenRA.Mods.RA/Render/RenderUnitRotor.cs +++ b/OpenRA.Mods.RA/Render/RenderUnitRotor.cs @@ -24,19 +24,20 @@ namespace OpenRA.Mods.RA.Render class RenderUnitRotor : RenderUnit { public Animation rotorAnim, secondRotorAnim; + IMove move; public RenderUnitRotor(Actor self) : base(self) { - var unit = self.traits.Get(); + move = 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, unit, new Turret(info.PrimaryOffset)), - null) { ZOffset = 1 }); + () => Combat.GetTurretPosition( self, move, new Turret(info.PrimaryOffset)), + null ) { ZOffset = 1 } ); if (info.SecondaryOffset == null) return; @@ -44,18 +45,15 @@ namespace OpenRA.Mods.RA.Render secondRotorAnim.PlayRepeating("rotor2"); anims.Add("rotor_2", new AnimationWithOffset( secondRotorAnim, - () => Combat.GetTurretPosition(self, unit, new Turret(info.SecondaryOffset)), + () => Combat.GetTurretPosition(self, move, new Turret(info.SecondaryOffset)), null) { ZOffset = 1 }); } public override void Tick(Actor self) { base.Tick(self); - - var unit = self.traits.Get(); - var isFlying = unit.Altitude > 0; - + var isFlying = move.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 f835e1948f..55cd212bb4 100755 --- a/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs +++ b/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs @@ -24,14 +24,14 @@ namespace OpenRA.Mods.RA.Render public RenderUnitSpinner(Actor self) : base(self) { - var unit = self.traits.Get(); + 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, unit, new Turret(info.Offset)), + () => Combat.GetTurretPosition(self, move, new Turret(info.Offset)), null) { ZOffset = 1 }); } } diff --git a/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs b/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs index d0b78d0fe0..10c74b9bfb 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 unit = self.traits.Get(); + var move = 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, unit, turret ), + () => Combat.GetTurretPosition( self, move, 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, unit, turret), + () => Combat.GetTurretPosition(self, move, turret), () => turret.Recoil <= 0)); } } diff --git a/OpenRA.Mods.RA/ReturnOnIdle.cs b/OpenRA.Mods.RA/ReturnOnIdle.cs index 5e593c45d0..e5e0ce91f3 100644 --- a/OpenRA.Mods.RA/ReturnOnIdle.cs +++ b/OpenRA.Mods.RA/ReturnOnIdle.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA { public void Idle(Actor self) { - var altitude = self.traits.Get().Altitude; + var altitude = self.traits.Get().Altitude; if (altitude == 0) return; // we're on the ground, let's stay there. var airfield = ReturnToBase.ChooseAirfield(self); diff --git a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs index eabe1d1ce7..aa5e54c45c 100755 --- a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs @@ -48,8 +48,9 @@ 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); - a.traits.Get().Facing = Util.GetFacing(order.TargetLocation - startPos, 0); - a.traits.Get().Altitude = a.Info.Traits.Get().CruiseAltitude; + var aMove = a.traits.Get(); + aMove.Facing = Util.GetFacing(order.TargetLocation - startPos, 0); + aMove.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 022426b765..924e49570a 100755 --- a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs @@ -61,8 +61,9 @@ namespace OpenRA.Mods.RA var flare = flareType != null ? w.CreateActor(flareType, p, owner) : null; var a = w.CreateActor((Info as ParatroopersPowerInfo).UnitType, startPos, owner); - a.traits.Get().Facing = Util.GetFacing(p - startPos, 0); - a.traits.Get().Altitude = a.Info.Traits.Get().CruiseAltitude; + var aMove = a.traits.Get(); + aMove.Facing = Util.GetFacing(p - startPos, 0); + aMove.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 29c982f7a3..8b60a8e6d3 100755 --- a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs @@ -46,8 +46,9 @@ namespace OpenRA.Mods.RA var enterCell = self.World.ChooseRandomEdgeCell(); var plane = self.World.CreateActor("U2", enterCell, self.Owner); - plane.traits.Get().Altitude = plane.Info.Traits.Get().CruiseAltitude; - plane.traits.Get().Facing = Util.GetFacing(order.TargetLocation - enterCell, 0); + var planeMove = plane.traits.Get(); + planeMove.Altitude = plane.Info.Traits.Get().CruiseAltitude; + planeMove.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 8ba671249d..2a87320c87 100644 --- a/OpenRA.Mods.RA/ThrowsParticles.cs +++ b/OpenRA.Mods.RA/ThrowsParticles.cs @@ -48,7 +48,8 @@ namespace OpenRA.Mods.RA if (info != null) { alt = 0; - pos = Combat.GetTurretPosition(self, self.traits.Get(), new Turret(info.Offset)); + var move = self.traits.Get(); + pos = Combat.GetTurretPosition(self, move, new Turret(info.Offset)); var ru = self.traits.Get(); v = Game.CosmeticRandom.Gauss2D(1) * info.Spread.RelOffset(); @@ -56,7 +57,7 @@ namespace OpenRA.Mods.RA va = info.Speed; if (!info.UseTurretFacing) InitialFacing = null; - facing = InitialFacing ?? self.traits.Get().Facing; + facing = InitialFacing ?? move.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 4b155519e2..8840059544 100644 --- a/OpenRA.Mods.RA/WithMuzzleFlash.cs +++ b/OpenRA.Mods.RA/WithMuzzleFlash.cs @@ -25,11 +25,11 @@ namespace OpenRA.Mods.RA public WithMuzzleFlash(Actor self) { - var unit = self.traits.Get(); + var move = self.traits.Get(); var attackInfo = self.Info.Traits.Get(); var render = self.traits.Get(); - muzzleFlash = new Animation(render.GetImage(self), () => unit.Facing); + muzzleFlash = new Animation(render.GetImage(self), () => move.Facing); muzzleFlash.Play("muzzle"); render.anims.Add("muzzle", new RenderSimple.AnimationWithOffset( diff --git a/OpenRA.Mods.RA/WithShadow.cs b/OpenRA.Mods.RA/WithShadow.cs index 9f8026f2e6..afc4e6af9e 100644 --- a/OpenRA.Mods.RA/WithShadow.cs +++ b/OpenRA.Mods.RA/WithShadow.cs @@ -20,11 +20,11 @@ namespace OpenRA.Mods.RA { public IEnumerable ModifyRender(Actor self, IEnumerable r) { - var unit = self.traits.Get(); + var move = self.traits.Get(); var shadowSprites = r.Select(a => a.WithPalette("shadow")); - var flyingSprites = (unit.Altitude <= 0) ? r - : r.Select(a => a.WithPos(a.Pos - new float2(0, unit.Altitude)).WithZOffset(3)); + var flyingSprites = (move.Altitude <= 0) ? r + : r.Select(a => a.WithPos(a.Pos - new float2(0, move.Altitude)).WithZOffset(3)); return shadowSprites.Concat(flyingSprites); }