From abdfac6e85848cbaed50b890242eeb96795b53cb Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 21 Jul 2013 11:19:26 +1200 Subject: [PATCH] More style fixes for Move. --- OpenRA.Mods.RA/Move/Move.cs | 64 +++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/OpenRA.Mods.RA/Move/Move.cs b/OpenRA.Mods.RA/Move/Move.cs index b0a527c1ec..8d7152d7a6 100755 --- a/OpenRA.Mods.RA/Move/Move.cs +++ b/OpenRA.Mods.RA/Move/Move.cs @@ -20,11 +20,13 @@ namespace OpenRA.Mods.RA.Move { class Move : Activity { + static readonly List NoPath = new List(); + CPos? destination; WRange nearEnough; - public List path; + List path; Func> getPath; - public Actor ignoreBuilding; + Actor ignoreBuilding; // For dealing with blockers bool hasWaited; @@ -35,9 +37,9 @@ namespace OpenRA.Mods.RA.Move // Ignores lane bias and nearby units public Move(CPos destination) { - this.getPath = (self,mobile) => + this.getPath = (self, mobile) => self.World.WorldActor.Trait().FindPath( - PathSearch.FromPoint( self.World, mobile.Info, self, mobile.toCell, destination, false ) + PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, destination, false) .WithoutLaneBias()); this.destination = destination; this.nearEnough = WRange.Zero; @@ -45,29 +47,28 @@ namespace OpenRA.Mods.RA.Move // Hack for legacy code public Move(CPos destination, int nearEnough) - : this(destination, WRange.FromCells(nearEnough)) {} + : this(destination, WRange.FromCells(nearEnough)) { } public Move(CPos destination, WRange nearEnough) { - this.getPath = (self,mobile) => self.World.WorldActor.Trait().FindUnitPath( mobile.toCell, destination, self ); + this.getPath = (self, mobile) => self.World.WorldActor.Trait() + .FindUnitPath(mobile.toCell, destination, self); this.destination = destination; this.nearEnough = nearEnough; } public Move(CPos destination, Actor ignoreBuilding) { - this.getPath = (self,mobile) => + this.getPath = (self, mobile) => self.World.WorldActor.Trait().FindPath( PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, destination, false) - .WithIgnoredBuilding(ignoreBuilding) - ); + .WithIgnoredBuilding(ignoreBuilding)); this.destination = destination; this.nearEnough = WRange.Zero; this.ignoreBuilding = ignoreBuilding; } - static readonly List NoPath = new List(); public Move(Target target, WRange range) { this.getPath = (self, mobile) => @@ -85,7 +86,7 @@ namespace OpenRA.Mods.RA.Move public Move(Func> getPath) { - this.getPath = (_1,_2) => getPath(); + this.getPath = (_1, _2) => getPath(); this.destination = null; this.nearEnough = WRange.Zero; } @@ -132,7 +133,7 @@ namespace OpenRA.Mods.RA.Move } path = EvalPath(self, mobile); - SanityCheckPath( mobile ); + SanityCheckPath(mobile); } if (path.Count == 0) @@ -151,7 +152,7 @@ namespace OpenRA.Mods.RA.Move var firstFacing = Util.GetFacing(dir, mobile.Facing); if (firstFacing != mobile.Facing) { - path.Add( nextCell.Value.First ); + path.Add(nextCell.Value.First); return Util.SequenceActivities(new Turn(firstFacing), this); } else @@ -163,8 +164,7 @@ namespace OpenRA.Mods.RA.Move Util.BetweenCells(mobile.fromCell, mobile.toCell) + (MobileInfo.SubCellOffsets[mobile.fromSubCell] + MobileInfo.SubCellOffsets[mobile.toSubCell]) / 2, mobile.Facing, mobile.Facing, - 0 - ); + 0); return move; } @@ -206,7 +206,7 @@ namespace OpenRA.Mods.RA.Move { // Are we close enough? var cellRange = nearEnough.Range / 1024; - if ((mobile.toCell - destination.Value).LengthSquared <= cellRange*cellRange) + if ((mobile.toCell - destination.Value).LengthSquared <= cellRange * cellRange) { path.Clear(); return null; @@ -255,9 +255,9 @@ namespace OpenRA.Mods.RA.Move return Pair.New(nextCell, subCell); } - public override void Cancel( Actor self ) + public override void Cancel(Actor self) { - path = new List(0); + path = NoPath; base.Cancel(self); } @@ -272,11 +272,11 @@ namespace OpenRA.Mods.RA.Move abstract class MovePart : Activity { - public readonly Move move; - public readonly PPos from, to; - public readonly int fromFacing, toFacing; - public int moveFraction; - public readonly int moveFractionTotal; + protected readonly Move move; + protected readonly PPos from, to; + protected readonly int fromFacing, toFacing; + protected readonly int moveFractionTotal; + protected int moveFraction; public MovePart(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction) { @@ -286,7 +286,7 @@ namespace OpenRA.Mods.RA.Move this.fromFacing = fromFacing; this.toFacing = toFacing; this.moveFraction = startingFraction; - this.moveFractionTotal = 3*(to - from).Length; + this.moveFractionTotal = 3 * (to - from).Length; } public override void Cancel(Actor self) @@ -304,7 +304,7 @@ namespace OpenRA.Mods.RA.Move { var mobile = self.Trait(); var ret = InnerTick(self, mobile); - mobile.IsMoving = (ret is MovePart); + mobile.IsMoving = ret is MovePart; if (moveFraction > moveFractionTotal) moveFraction = moveFractionTotal; @@ -372,8 +372,7 @@ namespace OpenRA.Mods.RA.Move Util.BetweenCells(mobile.toCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2, mobile.Facing, Util.GetNearestFacing(mobile.Facing, Util.GetFacing(nextCell.Value.First - mobile.toCell, mobile.Facing)), - moveFraction - moveFractionTotal - ); + moveFraction - moveFractionTotal); mobile.SetLocation(mobile.toCell, mobile.toSubCell, nextCell.Value.First, nextCell.Value.Second); return ret; @@ -388,8 +387,7 @@ namespace OpenRA.Mods.RA.Move Util.CenterOfCell(mobile.toCell) + toSubcellOffset, mobile.Facing, mobile.Facing, - moveFraction - moveFractionTotal - ); + moveFraction - moveFractionTotal); mobile.EnteringCell(self); mobile.SetLocation(mobile.toCell, mobile.toSubCell, mobile.toCell, mobile.toSubCell); @@ -400,7 +398,7 @@ namespace OpenRA.Mods.RA.Move class MoveSecondHalf : MovePart { public MoveSecondHalf(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction) - : base(move, from, to, fromFacing, toFacing, startingFraction) {} + : base(move, from, to, fromFacing, toFacing, startingFraction) { } protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent) { @@ -416,12 +414,10 @@ namespace OpenRA.Mods.RA.Move { public static bool IsMoving(this Actor self) { - if (self.IsIdle) + var a = self.GetCurrentActivity(); + if (a == null) return false; - Activity a = self.GetCurrentActivity(); - Debug.Assert(a != null); - // Dirty, but it suffices until we do something better: if (a.GetType() == typeof(Move)) return true; if (a.GetType() == typeof(MoveAdjacentTo)) return true;