diff --git a/OpenRA.Game/PathFinder.cs b/OpenRA.Game/PathFinder.cs index 7e869639db..0f8c0a2b53 100644 --- a/OpenRA.Game/PathFinder.cs +++ b/OpenRA.Game/PathFinder.cs @@ -60,8 +60,9 @@ namespace OpenRA List CachedPaths = new List(); const int MaxPathAge = 50; /* x 40ms ticks */ - public List FindUnitPath(int2 from, int2 target, UnitMovementType umt, Actor self) + public List FindUnitPath(int2 from, int2 target, Actor self) { + var umt = self.traits.Get().GetMovementType(); using (new PerfSample("find_unit_path")) { var cached = CachedPaths.FirstOrDefault(p => p.from == from && p.to == target && p.umt == umt); @@ -72,9 +73,9 @@ namespace OpenRA } var pb = FindBidiPath( - PathSearch.FromPoint(self, target, from, umt, true) + PathSearch.FromPoint(self, target, from, true) .WithCustomBlocker(AvoidUnitsNear(from, 4, self)), - PathSearch.FromPoint(self, from, target, umt, true) + PathSearch.FromPoint(self, from, target, true) .WithCustomBlocker(AvoidUnitsNear(from, 4, self)) .InReverse()); @@ -86,7 +87,7 @@ namespace OpenRA } } - public List FindUnitPathToRange( int2 src, int2 target, UnitMovementType umt, int range, Actor self ) + public List FindUnitPathToRange( int2 src, int2 target, int range, Actor self ) { using( new PerfSample( "find_unit_path_multiple_src" ) ) { @@ -94,7 +95,7 @@ namespace OpenRA var tilesInRange = world.FindTilesInCircle(target, range) .Where( t => mobile.CanEnterCell(t)); - var path = FindPath( PathSearch.FromPoints( self, tilesInRange, src, umt, false ) + var path = FindPath( PathSearch.FromPoints( self, tilesInRange, src, false ) .WithCustomBlocker(AvoidUnitsNear(src, 4, self)) .InReverse()); path.Reverse(); diff --git a/OpenRA.Game/PathSearch.cs b/OpenRA.Game/PathSearch.cs index 4eead3e6ba..595d1c047c 100755 --- a/OpenRA.Game/PathSearch.cs +++ b/OpenRA.Game/PathSearch.cs @@ -49,6 +49,8 @@ namespace OpenRA world = self.World; cellInfo = InitCellInfo(); queue = new PriorityQueue(); + + umt = self.traits.Get().GetMovementType(); buildingInfluence = world.WorldActor.traits.Get(); unitInfluence = world.WorldActor.traits.Get(); @@ -172,31 +174,28 @@ namespace OpenRA queue.Add( new PathDistance( heuristic( location ), location ) ); } - public static PathSearch Search( Actor self, UnitMovementType umt, bool checkForBlocked ) + public static PathSearch Search( Actor self, bool checkForBlocked ) { var search = new PathSearch(self) { - umt = umt, checkForBlocked = checkForBlocked }; return search; } - public static PathSearch FromPoint( Actor self, int2 from, int2 target, UnitMovementType umt, bool checkForBlocked ) + public static PathSearch FromPoint( Actor self, int2 from, int2 target, bool checkForBlocked ) { var search = new PathSearch(self) { heuristic = DefaultEstimator( target ), - umt = umt, checkForBlocked = checkForBlocked }; search.AddInitialCell( self.World, from ); return search; } - public static PathSearch FromPoints(Actor self, IEnumerable froms, int2 target, UnitMovementType umt, bool checkForBlocked) + public static PathSearch FromPoints(Actor self, IEnumerable froms, int2 target, bool checkForBlocked) { var search = new PathSearch(self) { heuristic = DefaultEstimator(target), - umt = umt, checkForBlocked = checkForBlocked }; diff --git a/OpenRA.Game/Traits/Activities/Move.cs b/OpenRA.Game/Traits/Activities/Move.cs index e3ec8bd41d..4edbee0671 100755 --- a/OpenRA.Game/Traits/Activities/Move.cs +++ b/OpenRA.Game/Traits/Activities/Move.cs @@ -32,7 +32,7 @@ namespace OpenRA.Traits.Activities int2? destination; int nearEnough; public List path; - Func> getPath; + Func> getPath; public Actor ignoreBuilding; MovePart move; @@ -50,9 +50,8 @@ namespace OpenRA.Traits.Activities public Move( int2 destination, int nearEnough ) : this() { - this.getPath = ( self, mobile ) => self.World.PathFinder.FindUnitPath( - self.Location, destination, - mobile.GetMovementType(), self ); + this.getPath = self => self.World.PathFinder.FindUnitPath( + self.Location, destination, self ); this.destination = destination; this.nearEnough = nearEnough; } @@ -60,9 +59,9 @@ namespace OpenRA.Traits.Activities public Move(int2 destination, Actor ignoreBuilding) : this() { - this.getPath = (self, mobile) => + this.getPath = self => self.World.PathFinder.FindPath( - PathSearch.FromPoint( self, self.Location, destination, mobile.GetMovementType(), false ) + PathSearch.FromPoint( self, self.Location, destination, false ) .WithCustomBlocker( self.World.PathFinder.AvoidUnitsNear( self.Location, 4, self )) .WithIgnoredBuilding( ignoreBuilding )); @@ -74,9 +73,9 @@ namespace OpenRA.Traits.Activities public Move( Actor target, int range ) : this() { - this.getPath = ( self, mobile ) => self.World.PathFinder.FindUnitPathToRange( + this.getPath = self => self.World.PathFinder.FindUnitPathToRange( self.Location, target.Location, - mobile.GetMovementType(), range, self ); + range, self ); this.destination = null; this.nearEnough = range; } @@ -84,7 +83,7 @@ namespace OpenRA.Traits.Activities public Move(Func> getPath) : this() { - this.getPath = (_, _2) => getPath(); + this.getPath = _ => getPath(); this.destination = null; this.nearEnough = 0; } @@ -111,7 +110,7 @@ namespace OpenRA.Traits.Activities return this; } - path = getPath( self, mobile ).TakeWhile( a => a != self.Location ).ToList(); + path = getPath( self ).TakeWhile( a => a != self.Location ).ToList(); SanityCheckPath( mobile ); } @@ -187,7 +186,7 @@ namespace OpenRA.Traits.Activities return null; self.World.WorldActor.traits.Get().Remove( self, mobile ); - var newPath = getPath(self, mobile).TakeWhile(a => a != self.Location).ToList(); + var newPath = getPath(self).TakeWhile(a => a != self.Location).ToList(); self.World.WorldActor.traits.Get().Add( self, mobile ); if (newPath.Count != 0) diff --git a/OpenRA.Mods.RA/Activities/Harvest.cs b/OpenRA.Mods.RA/Activities/Harvest.cs index dbe79bea23..7ecc77a8df 100755 --- a/OpenRA.Mods.RA/Activities/Harvest.cs +++ b/OpenRA.Mods.RA/Activities/Harvest.cs @@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA.Activities self.QueueActivity(new Move( () => { - return self.World.PathFinder.FindPath(PathSearch.Search(self, UnitMovementType.Wheel, true) + return self.World.PathFinder.FindPath(PathSearch.Search(self, true) .WithHeuristic(loc => (res.GetResource(loc) != null && harv.Resources.Contains( res.GetResource(loc).info.Name )) ? 0 : 1) .FromPoint(self.Location)); })); diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index 01b166fad3..643145f5e9 100755 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -66,8 +66,6 @@ namespace OpenRA.Mods.RA Actor ClosestProc(Actor self, Actor ignore) { - var mobile = self.traits.Get(); - var refs = self.World.Queries.OwnedBy[self.Owner] .Where(x => x != ignore && x.traits.Contains()) .ToList(); @@ -75,7 +73,6 @@ namespace OpenRA.Mods.RA var path = self.World.PathFinder.FindPath(PathSearch.FromPoints(self, refs.Select(r => r.Location + r.traits.Get().DeliverOffset), self.Location, - mobile.GetMovementType(), false)); path.Reverse(); if (path.Count != 0)