From 02ce7990c045ea92a856e5f89217acb8c0082043 Mon Sep 17 00:00:00 2001 From: Bob Date: Thu, 21 Jan 2010 13:51:09 +1300 Subject: [PATCH] more refs to Game.world (PathSearch) --- OpenRa.Game/PathFinder.cs | 12 ++++----- OpenRa.Game/PathSearch.cs | 28 ++++++++++----------- OpenRa.Game/Traits/Activities/DeliverOre.cs | 4 +-- OpenRa.Game/Traits/Activities/Harvest.cs | 2 +- OpenRa.Game/Traits/Activities/Move.cs | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/OpenRa.Game/PathFinder.cs b/OpenRa.Game/PathFinder.cs index 7c47e00825..2fac57d5b4 100644 --- a/OpenRa.Game/PathFinder.cs +++ b/OpenRa.Game/PathFinder.cs @@ -31,8 +31,8 @@ namespace OpenRa using (new PerfSample("find_unit_path")) { var pb = FindBidiPath( - PathSearch.FromPoint(target, from, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4)), - PathSearch.FromPoint(from, target, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4))); + PathSearch.FromPoint(world, target, from, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4)), + PathSearch.FromPoint(world, from, target, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4))); CheckSanePath2(pb, from, target); return pb; @@ -46,7 +46,7 @@ namespace OpenRa var tilesInRange = world.FindTilesInCircle(target, range) .Where( t => world.IsCellBuildable( t, umt ) ); - var path = FindPath( PathSearch.FromPoints( tilesInRange, src, umt, false ).WithCustomBlocker(AvoidUnitsNear(src, 4))); + var path = FindPath( PathSearch.FromPoints( world, tilesInRange, src, umt, false ).WithCustomBlocker(AvoidUnitsNear(src, 4))); path.Reverse(); return path; } @@ -66,7 +66,7 @@ namespace OpenRa { while (!search.queue.Empty) { - var p = search.Expand( passableCost ); + var p = search.Expand( world, passableCost ); PerfHistory.Increment("nodes_expanded", .01); if (search.heuristic(p) == 0) @@ -103,13 +103,13 @@ namespace OpenRa while (!fromSrc.queue.Empty && !fromDest.queue.Empty) { /* make some progress on the first search */ - var p = fromSrc.Expand( passableCost ); + var p = fromSrc.Expand( world, passableCost ); if (fromDest.cellInfo[p.X, p.Y].Seen && fromDest.cellInfo[p.X, p.Y].MinCost < float.PositiveInfinity) return MakeBidiPath(fromSrc, fromDest, p); /* make some progress on the second search */ - var q = fromDest.Expand( passableCost ); + var q = fromDest.Expand( world, passableCost ); if (fromSrc.cellInfo[q.X, q.Y].Seen && fromSrc.cellInfo[q.X, q.Y].MinCost < float.PositiveInfinity) return MakeBidiPath(fromSrc, fromDest, q); diff --git a/OpenRa.Game/PathSearch.cs b/OpenRa.Game/PathSearch.cs index f6a9c0266c..c18e263709 100755 --- a/OpenRa.Game/PathSearch.cs +++ b/OpenRa.Game/PathSearch.cs @@ -34,12 +34,12 @@ namespace OpenRa return this; } - public int2 Expand( float[][ , ] passableCost ) + public int2 Expand( World world, float[][ , ] passableCost ) { var p = queue.Pop(); cellInfo[ p.Location.X, p.Location.Y ].Seen = true; - var custom2 = Game.world.customTerrain[p.Location.X, p.Location.Y]; + var custom2 = world.customTerrain[p.Location.X, p.Location.Y]; var thisCost = (custom2 != null) ? custom2.GetCost(p.Location, umt) : passableCost[(int)umt][p.Location.X, p.Location.Y]; @@ -51,24 +51,24 @@ namespace OpenRa { int2 newHere = p.Location + d; - if (!Game.world.Map.IsInMap(newHere.X, newHere.Y)) continue; + if (!world.Map.IsInMap(newHere.X, newHere.Y)) continue; if( cellInfo[ newHere.X, newHere.Y ].Seen ) continue; - var custom = Game.world.customTerrain[newHere.X, newHere.Y]; + var custom = world.customTerrain[newHere.X, newHere.Y]; var costHere = (custom != null) ? custom.GetCost(newHere, umt) : passableCost[(int)umt][newHere.X, newHere.Y]; if (costHere == float.PositiveInfinity) continue; - if (!Game.world.BuildingInfluence.CanMoveHere(newHere) && - Game.world.BuildingInfluence.GetBuildingAt(newHere) != ignoreBuilding) + if (!world.BuildingInfluence.CanMoveHere(newHere) && + world.BuildingInfluence.GetBuildingAt(newHere) != ignoreBuilding) continue; - if (Game.world.Map.IsOverlaySolid(newHere)) + if (world.Map.IsOverlaySolid(newHere)) continue; // Replicate real-ra behavior of not being able to enter a cell if there is a mixture of crushable and uncrushable units - if (checkForBlocked && (Game.world.UnitInfluence.GetUnitsAt(newHere).Any(a => !Game.world.IsActorPathableToCrush(a, umt)))) + if (checkForBlocked && (world.UnitInfluence.GetUnitsAt(newHere).Any(a => !world.IsActorPathableToCrush(a, umt)))) continue; if (customBlock != null && customBlock(newHere)) @@ -93,27 +93,27 @@ namespace OpenRa return p.Location; } - public void AddInitialCell( int2 location ) + public void AddInitialCell( World world, int2 location ) { - if (!Game.world.Map.IsInMap(location.X, location.Y)) + if (!world.Map.IsInMap(location.X, location.Y)) return; cellInfo[ location.X, location.Y ] = new CellInfo( 0, location, false ); queue.Add( new PathDistance( heuristic( location ), location ) ); } - public static PathSearch FromPoint( int2 from, int2 target, UnitMovementType umt, bool checkForBlocked ) + public static PathSearch FromPoint( World world, int2 from, int2 target, UnitMovementType umt, bool checkForBlocked ) { var search = new PathSearch { heuristic = DefaultEstimator( target ), umt = umt, checkForBlocked = checkForBlocked }; - search.AddInitialCell( from ); + search.AddInitialCell( world, from ); return search; } - public static PathSearch FromPoints(IEnumerable froms, int2 target, UnitMovementType umt, bool checkForBlocked) + public static PathSearch FromPoints(World world, IEnumerable froms, int2 target, UnitMovementType umt, bool checkForBlocked) { var search = new PathSearch { @@ -123,7 +123,7 @@ namespace OpenRa }; foreach (var sl in froms) - search.AddInitialCell(sl); + search.AddInitialCell(world, sl); return search; } diff --git a/OpenRa.Game/Traits/Activities/DeliverOre.cs b/OpenRa.Game/Traits/Activities/DeliverOre.cs index fe20499cd9..3717c7cf58 100644 --- a/OpenRa.Game/Traits/Activities/DeliverOre.cs +++ b/OpenRa.Game/Traits/Activities/DeliverOre.cs @@ -45,10 +45,10 @@ namespace OpenRa.Traits.Activities var refineries = self.World.Actors.Where( x => x.traits.Contains() && x.Owner == self.Owner ).ToList(); if( refinery != null ) - search.AddInitialCell( refinery.Location + refineryDeliverOffset ); + search.AddInitialCell( self.World, refinery.Location + refineryDeliverOffset ); else foreach( var r in refineries ) - search.AddInitialCell( r.Location + refineryDeliverOffset ); + search.AddInitialCell( self.World, r.Location + refineryDeliverOffset ); var path = self.World.PathFinder.FindPath( search ); path.Reverse(); diff --git a/OpenRa.Game/Traits/Activities/Harvest.cs b/OpenRa.Game/Traits/Activities/Harvest.cs index 9ac0d84089..587836a8fe 100644 --- a/OpenRa.Game/Traits/Activities/Harvest.cs +++ b/OpenRa.Game/Traits/Activities/Harvest.cs @@ -62,7 +62,7 @@ namespace OpenRa.Traits.Activities umt = UnitMovementType.Wheel, checkForBlocked = true }; - search.AddInitialCell(self.Location); + search.AddInitialCell(self.World, self.Location); return self.World.PathFinder.FindPath(search); })); self.QueueActivity(new Harvest()); diff --git a/OpenRa.Game/Traits/Activities/Move.cs b/OpenRa.Game/Traits/Activities/Move.cs index c016f87264..b5cec75a2e 100755 --- a/OpenRa.Game/Traits/Activities/Move.cs +++ b/OpenRa.Game/Traits/Activities/Move.cs @@ -31,7 +31,7 @@ namespace OpenRa.Traits.Activities { this.getPath = (self, mobile) => self.World.PathFinder.FindPath( - PathSearch.FromPoint( self.Location, destination, mobile.GetMovementType(), false ) + PathSearch.FromPoint( self.World, self.Location, destination, mobile.GetMovementType(), false ) .WithCustomBlocker( self.World.PathFinder.AvoidUnitsNear( self.Location, 4 )).WithIgnoredBuilding( ignoreBuilding )); this.destination = destination;