diff --git a/OpenRA.Game/PathFinder.cs b/OpenRA.Game/PathFinder.cs index 64450889c8..a5dd764e24 100644 --- a/OpenRA.Game/PathFinder.cs +++ b/OpenRA.Game/PathFinder.cs @@ -49,11 +49,13 @@ namespace OpenRA cached.tick = Game.LocalTick; return new List(cached.result); } + + var mi = self.Info.Traits.Get(); var pb = FindBidiPath( - PathSearch.FromPoint(self, target, from, true) + PathSearch.FromPoint(world, mi, target, from, true) .WithCustomBlocker(AvoidUnitsNear(from, 4, self)), - PathSearch.FromPoint(self, from, target, true) + PathSearch.FromPoint(world, mi, from, target, true) .WithCustomBlocker(AvoidUnitsNear(from, 4, self)) .InReverse()); @@ -69,11 +71,11 @@ namespace OpenRA { using( new PerfSample( "find_unit_path_multiple_src" ) ) { - var mobile = self.Trait(); + var mobileInfo = self.Info.Traits.Get(); var tilesInRange = world.FindTilesInCircle(target, range) - .Where( t => mobile.CanEnterCell(t)); + .Where( t => Mobile.CanEnterCell(self.World, mobileInfo, t, null, true)); - var path = FindPath( PathSearch.FromPoints( self, tilesInRange, src, false ) + var path = FindPath( PathSearch.FromPoints( world, mobileInfo, tilesInRange, src, false ) .WithCustomBlocker(AvoidUnitsNear(src, 4, self)) .InReverse()); path.Reverse(); diff --git a/OpenRA.Game/PathSearch.cs b/OpenRA.Game/PathSearch.cs index eb2d22aab4..69176d3095 100755 --- a/OpenRA.Game/PathSearch.cs +++ b/OpenRA.Game/PathSearch.cs @@ -24,16 +24,19 @@ namespace OpenRA Func customBlock; public bool checkForBlocked; public Actor ignoreBuilding; - Actor self; public bool inReverse; - Mobile mobile; - - public PathSearch(Actor self) + + MobileInfo mobileInfo; + BuildingInfluence bim; + UnitInfluence uim; + + public PathSearch(World world, MobileInfo mobileInfo) { - this.self = self; - world = self.World; + this.world = world; + bim = world.WorldActor.Trait(); + uim = world.WorldActor.Trait(); cellInfo = InitCellInfo(); - mobile = self.Trait(); + this.mobileInfo = mobileInfo; queue = new PriorityQueue(); } @@ -69,7 +72,7 @@ namespace OpenRA public PathSearch FromPoint(int2 from) { - AddInitialCell( self.World, from ); + AddInitialCell( world, from ); return this; } @@ -86,7 +89,7 @@ namespace OpenRA cellInfo[p.Location.X, p.Location.Y].Seen = true; - var thisCost = mobile.MovementCostForCell(self, p.Location); + var thisCost = Mobile.MovementCostForCell(mobileInfo, world, p.Location); if (thisCost == float.PositiveInfinity) return p.Location; @@ -99,12 +102,12 @@ namespace OpenRA if( cellInfo[ newHere.X, newHere.Y ].Seen ) continue; - var costHere = mobile.MovementCostForCell(self, newHere); + var costHere = Mobile.MovementCostForCell(mobileInfo, world, newHere); if (costHere == float.PositiveInfinity) continue; - if (!mobile.CanEnterCell(newHere, ignoreBuilding, checkForBlocked)) + if (!Mobile.CanEnterCell(mobileInfo, world, uim, bim, newHere, ignoreBuilding, checkForBlocked)) continue; if (customBlock != null && customBlock(newHere)) @@ -160,33 +163,33 @@ namespace OpenRA queue.Add( new PathDistance( heuristic( location ), location ) ); } - public static PathSearch Search( Actor self, bool checkForBlocked ) + public static PathSearch Search( World world, MobileInfo mi, bool checkForBlocked ) { - var search = new PathSearch(self) { + var search = new PathSearch(world, mi) { checkForBlocked = checkForBlocked }; return search; } - public static PathSearch FromPoint( Actor self, int2 from, int2 target, bool checkForBlocked ) + public static PathSearch FromPoint( World world, MobileInfo mi, int2 from, int2 target, bool checkForBlocked ) { - var search = new PathSearch(self) { + var search = new PathSearch(world, mi) { heuristic = DefaultEstimator( target ), checkForBlocked = checkForBlocked }; - search.AddInitialCell( self.World, from ); + search.AddInitialCell( world, from ); return search; } - public static PathSearch FromPoints(Actor self, IEnumerable froms, int2 target, bool checkForBlocked) + public static PathSearch FromPoints(World world, MobileInfo mi, IEnumerable froms, int2 target, bool checkForBlocked) { - var search = new PathSearch(self) + var search = new PathSearch(world, mi) { heuristic = DefaultEstimator(target), checkForBlocked = checkForBlocked }; foreach (var sl in froms) - search.AddInitialCell(self.World, sl); + search.AddInitialCell(world, sl); return search; } diff --git a/OpenRA.Game/Traits/Activities/Move.cs b/OpenRA.Game/Traits/Activities/Move.cs index e65c164083..c6788a05ea 100755 --- a/OpenRA.Game/Traits/Activities/Move.cs +++ b/OpenRA.Game/Traits/Activities/Move.cs @@ -45,7 +45,7 @@ namespace OpenRA.Traits.Activities { this.getPath = (self,mobile) => self.World.PathFinder.FindPath( - PathSearch.FromPoint( self, mobile.toCell, destination, false ) + PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, destination, false ) .WithoutLaneBias()); this.destination = destination; this.nearEnough = 0; @@ -55,8 +55,7 @@ namespace OpenRA.Traits.Activities public Move( int2 destination, int nearEnough ) : this() { - this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPath( - mobile.toCell, destination, self ); + this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPath( mobile.toCell, destination, self ); this.destination = destination; this.nearEnough = nearEnough; } @@ -66,7 +65,7 @@ namespace OpenRA.Traits.Activities { this.getPath = (self,mobile) => self.World.PathFinder.FindPath( - PathSearch.FromPoint( self, mobile.toCell, destination, false ) + PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, destination, false ) .WithCustomBlocker( self.World.PathFinder.AvoidUnitsNear( mobile.toCell, 4, self )) .WithIgnoredBuilding( ignoreBuilding )); diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index a6b69fca29..bbc4dbbba3 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -207,19 +207,25 @@ namespace OpenRA.Traits return CanEnterCell( p, null, true); } + public static bool CanEnterCell( World world, MobileInfo mi, int2 cell, Actor ignoreActor, bool checkTransientActors ) + { + var bim = world.WorldActor.Trait(); + var uim = world.WorldActor.Trait(); + return Mobile.CanEnterCell( mi, world, uim, bim, cell, ignoreActor, checkTransientActors ); + } + public bool CanEnterCell( int2 cell, Actor ignoreActor, bool checkTransientActors ) { - return CanEnterCell( Info, self.World, cell, ignoreActor, checkTransientActors ); + var bim = self.World.WorldActor.Trait(); + var uim = self.World.WorldActor.Trait(); + return CanEnterCell( Info, self.World, uim, bim, cell, ignoreActor, checkTransientActors ); } - public static bool CanEnterCell( MobileInfo mobileInfo, World world, int2 cell, Actor ignoreActor, bool checkTransientActors ) + public static bool CanEnterCell( MobileInfo mobileInfo, World world, UnitInfluence uim, BuildingInfluence bim, int2 cell, Actor ignoreActor, bool checkTransientActors ) { if (MovementCostForCell(mobileInfo, world, cell) == float.PositiveInfinity) return false; - var bim = world.WorldActor.Trait(); - var uim = world.WorldActor.Trait(); - // Check for buildings var building = bim.GetBuildingBlocking(cell); if (building != null && building != ignoreActor) diff --git a/OpenRA.Game/Traits/Production.cs b/OpenRA.Game/Traits/Production.cs index 23de0090dd..1fd146e44e 100755 --- a/OpenRA.Game/Traits/Production.cs +++ b/OpenRA.Game/Traits/Production.cs @@ -95,11 +95,13 @@ namespace OpenRA.Traits // required for 3-arg CanEnterCell //var mobile = newUnit.Trait(); var mobileInfo = producee.Traits.Get(); + var bim = self.World.WorldActor.Trait(); + var uim = self.World.WorldActor.Trait(); // Pick a spawn/exit point pair // Todo: Reorder in a synced random way foreach (var s in self.Info.Traits.WithInterface()) - if( Mobile.CanEnterCell( mobileInfo, self.World, self.Location + s.ExitCell,self,true ) ) + if( Mobile.CanEnterCell( mobileInfo, self.World, uim, bim, self.Location + s.ExitCell,self,true ) ) { DoProduction(self, producee, s); return true; diff --git a/OpenRA.Mods.RA/Activities/Harvest.cs b/OpenRA.Mods.RA/Activities/Harvest.cs index de9ad50459..c5e93788a8 100755 --- a/OpenRA.Mods.RA/Activities/Harvest.cs +++ b/OpenRA.Mods.RA/Activities/Harvest.cs @@ -62,11 +62,11 @@ namespace OpenRA.Mods.RA.Activities { var res = self.World.WorldActor.Trait(); var harv = self.Info.Traits.Get(); - + var mobileInfo = self.Info.Traits.Get(); self.QueueActivity(new Move( () => { - return self.World.PathFinder.FindPath(PathSearch.Search(self, true) + return self.World.PathFinder.FindPath(PathSearch.Search(self.World, mobileInfo, 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 a1dfb5cbaf..d85162bcfb 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -63,8 +63,8 @@ namespace OpenRA.Mods.RA var refs = self.World.Queries.OwnedBy[self.Owner] .Where(x => x != ignore && x.HasTrait()) .ToList(); - - var path = self.World.PathFinder.FindPath(PathSearch.FromPoints(self, + var mi = self.Info.Traits.Get(); + var path = self.World.PathFinder.FindPath(PathSearch.FromPoints(self.World, mi, refs.Select(r => r.Location + r.Trait().DeliverOffset), self.Location, false));