diff --git a/OpenRA.Mods.RA/Activities/Hunt.cs b/OpenRA.Mods.RA/Activities/Hunt.cs index c20a804070..55b8d22ff4 100644 --- a/OpenRA.Mods.RA/Activities/Hunt.cs +++ b/OpenRA.Mods.RA/Activities/Hunt.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Activities return this; return Util.SequenceActivities( - new AttackMove.AttackMoveActivity(self, new Move.Move(target.Location, WRange.FromCells(2))), + new AttackMove.AttackMoveActivity(self, new Move.Move(self, target.Location, WRange.FromCells(2))), new Wait(25), this); } diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index f4ae825988..0b81a9cace 100644 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -432,7 +432,7 @@ namespace OpenRA.Mods.RA.Move ticksBeforePathing = avgTicksBeforePathing + self.World.SharedRandom.Next(-spreadTicksBeforePathing, spreadTicksBeforePathing); - self.QueueActivity(new Move(currentLocation, 8)); + self.QueueActivity(new Move(self, currentLocation, 8)); self.SetTargetLine(Target.FromCell(self.World, currentLocation), Color.Green); } @@ -585,7 +585,7 @@ namespace OpenRA.Mods.RA.Move { self.CancelActivity(); self.SetTargetLine(Target.FromCell(self.World, moveTo.Value), Color.Green, false); - self.QueueActivity(new Move(moveTo.Value, 0)); + self.QueueActivity(new Move(self, moveTo.Value, 0)); Log.Write("debug", "OnNudge #{0} from {1} to {2}", self.ActorID, self.Location, moveTo.Value); @@ -631,13 +631,13 @@ namespace OpenRA.Mods.RA.Move } } - public Activity ScriptedMove(CPos cell) { return new Move(cell); } - public Activity MoveTo(CPos cell, int nearEnough) { return new Move(cell, nearEnough); } - public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Move(cell, ignoredActor); } + public Activity ScriptedMove(CPos cell) { return new Move(self, cell); } + public Activity MoveTo(CPos cell, int nearEnough) { return new Move(self, cell, nearEnough); } + public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Move(self, cell, ignoredActor); } public Activity MoveWithinRange(Target target, WRange range) { return new MoveWithinRange(self, target, WRange.Zero, range); } public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange) { return new MoveWithinRange(self, target, minRange, maxRange); } public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new Follow(self, target, minRange, maxRange); } - public Activity MoveTo(Func> pathFunc) { return new Move(pathFunc); } + public Activity MoveTo(Func> pathFunc) { return new Move(self, pathFunc); } public void OnNotifyBlockingMove(Actor self, Actor blocking) { diff --git a/OpenRA.Mods.RA/Move/Move.cs b/OpenRA.Mods.RA/Move/Move.cs index 1d792d800a..59243df776 100644 --- a/OpenRA.Mods.RA/Move/Move.cs +++ b/OpenRA.Mods.RA/Move/Move.cs @@ -22,11 +22,13 @@ namespace OpenRA.Mods.RA.Move { static readonly List NoPath = new List(); - CPos? destination; - WRange nearEnough; + readonly Mobile mobile; + readonly WRange nearEnough; + readonly Func> getPath; + readonly Actor ignoreBuilding; + List path; - Func> getPath; - Actor ignoreBuilding; + CPos? destination; // For dealing with blockers bool hasWaited; @@ -35,9 +37,11 @@ namespace OpenRA.Mods.RA.Move // Scriptable move order // Ignores lane bias and nearby units - public Move(CPos destination) + public Move(Actor self, CPos destination) { - this.getPath = (self, mobile) => + mobile = self.Trait(); + + getPath = () => self.World.WorldActor.Trait().FindPath( PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, destination, false) .WithoutLaneBias()); @@ -46,28 +50,34 @@ namespace OpenRA.Mods.RA.Move } // HACK: for legacy code - public Move(CPos destination, int nearEnough) - : this(destination, WRange.FromCells(nearEnough)) { } + public Move(Actor self, CPos destination, int nearEnough) + : this(self, destination, WRange.FromCells(nearEnough)) { } - public Move(CPos destination, WRange nearEnough) + public Move(Actor self, CPos destination, WRange nearEnough) { - this.getPath = (self, mobile) => self.World.WorldActor.Trait() + mobile = self.Trait(); + + getPath = () => self.World.WorldActor.Trait() .FindUnitPath(mobile.toCell, destination, self); this.destination = destination; this.nearEnough = nearEnough; } - public Move(CPos destination, SubCell subCell, WRange nearEnough) + public Move(Actor self, CPos destination, SubCell subCell, WRange nearEnough) { - this.getPath = (self, mobile) => self.World.WorldActor.Trait() + mobile = self.Trait(); + + getPath = () => self.World.WorldActor.Trait() .FindUnitPathToRange(mobile.fromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self); this.destination = destination; this.nearEnough = nearEnough; } - public Move(CPos destination, Actor ignoreBuilding) + public Move(Actor self, CPos destination, Actor ignoreBuilding) { - this.getPath = (self, mobile) => + mobile = self.Trait(); + + getPath = () => self.World.WorldActor.Trait().FindPath( PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, destination, false) .WithIgnoredBuilding(ignoreBuilding)); @@ -77,9 +87,11 @@ namespace OpenRA.Mods.RA.Move this.ignoreBuilding = ignoreBuilding; } - public Move(Target target, WRange range) + public Move(Actor self, Target target, WRange range) { - this.getPath = (self, mobile) => + mobile = self.Trait(); + + getPath = () => { if (!target.IsValidFor(self)) return NoPath; @@ -88,15 +100,18 @@ namespace OpenRA.Mods.RA.Move mobile.toCell, mobile.toSubCell, target.CenterPosition, range, self); }; - this.destination = null; - this.nearEnough = range; + destination = null; + nearEnough = range; } - public Move(Func> getPath) + public Move(Actor self, Func> getPath) { - this.getPath = (_1, _2) => getPath(); - this.destination = null; - this.nearEnough = WRange.Zero; + mobile = self.Trait(); + + this.getPath = getPath; + + destination = null; + nearEnough = WRange.Zero; } static int HashList(List xs) @@ -111,14 +126,13 @@ namespace OpenRA.Mods.RA.Move List EvalPath(Actor self, Mobile mobile) { - var path = getPath(self, mobile).TakeWhile(a => a != mobile.toCell).ToList(); + var path = getPath().TakeWhile(a => a != mobile.toCell).ToList(); mobile.PathHash = HashList(path); return path; } public override Activity Tick(Actor self) { - var mobile = self.Trait(); if (destination == mobile.toCell) return NextActivity; @@ -297,7 +311,7 @@ namespace OpenRA.Mods.RA.Move public override Activity Tick(Actor self) { var mobile = self.Trait(); - var ret = InnerTick(self, mobile); + var ret = InnerTick(self, move.mobile); mobile.IsMoving = ret is MovePart; if (moveFraction > moveFractionTotal) diff --git a/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs b/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs index 9d3ebc2de6..fe8e22b888 100644 --- a/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs +++ b/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs @@ -324,9 +324,9 @@ namespace OpenRA.Mods.RA.Scripting public void AttackMove(Actor actor, CPos location, double nearEnough) { if (actor.HasTrait()) - actor.QueueActivity(new AttackMove.AttackMoveActivity(actor, new Move.Move(location, (int)nearEnough))); + actor.QueueActivity(new AttackMove.AttackMoveActivity(actor, new Move.Move(actor, location, (int)nearEnough))); else - actor.QueueActivity(new Move.Move(location, (int)nearEnough)); + actor.QueueActivity(new Move.Move(actor, location, (int)nearEnough)); } [LuaGlobal] diff --git a/OpenRA.Mods.RA/Scripting/Properties/MobileProperties.cs b/OpenRA.Mods.RA/Scripting/Properties/MobileProperties.cs index e404255aa3..0af7444f78 100644 --- a/OpenRA.Mods.RA/Scripting/Properties/MobileProperties.cs +++ b/OpenRA.Mods.RA/Scripting/Properties/MobileProperties.cs @@ -25,14 +25,14 @@ namespace OpenRA.Mods.RA.Scripting "(in cells) that will be considered close enough to complete the activity.")] public void Move(CPos cell, int closeEnough = 0) { - self.QueueActivity(new Move.Move(cell, WRange.FromCells(closeEnough))); + self.QueueActivity(new Move.Move(self, cell, WRange.FromCells(closeEnough))); } [ScriptActorPropertyActivity] [Desc("Moves within the cell grid, ignoring lane biases.")] public void ScriptedMove(CPos cell) { - self.QueueActivity(new Move.Move(cell)); + self.QueueActivity(new Move.Move(self, cell)); } [ScriptActorPropertyActivity]