diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index f974131200..9680c28656 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -19,7 +19,6 @@ namespace OpenRa public static World world; internal static Viewport viewport; - public static PathFinder PathFinder; public static Controller controller; internal static Chrome chrome; public static UserSettings Settings; @@ -90,8 +89,6 @@ namespace OpenRa LoadMapActors(Rules.AllRules); skipMakeAnims = false; - PathFinder = new PathFinder(); - chrome = new Chrome(renderer); SpawnPoints = Rules.AllRules.GetSection("Waypoints") @@ -336,7 +333,7 @@ namespace OpenRa foreach (var t in Footprint.Tiles(buildingName, bi, position)) search.AddInitialCell(t); - return Game.PathFinder.FindPath(search).Count != 0; + return Game.world.PathFinder.FindPath(search).Count != 0; } public static void SyncLobbyInfo(string data) diff --git a/OpenRa.Game/PathFinder.cs b/OpenRa.Game/PathFinder.cs index fa1f1436a4..c6428f9d0b 100644 --- a/OpenRa.Game/PathFinder.cs +++ b/OpenRa.Game/PathFinder.cs @@ -11,15 +11,15 @@ namespace OpenRa { float[][,] passableCost = new float[4][,]; - public PathFinder() + public PathFinder( World world ) { for (var umt = UnitMovementType.Foot; umt <= UnitMovementType.Float; umt++) passableCost[(int)umt] = new float[128, 128]; for( int x = 0 ; x < 128 ; x++ ) for( int y = 0 ; y < 128 ; y++ ) for (var umt = UnitMovementType.Foot; umt <= UnitMovementType.Float; umt++ ) - passableCost[(int)umt][ x, y ] = ( Game.world.Map.IsInMap( x, y ) ) - ? (float)TerrainCosts.Cost( umt, Game.world.TileSet.GetWalkability( Game.world.Map.MapTiles[ x, y ] ) ) + passableCost[(int)umt][ x, y ] = ( world.Map.IsInMap( x, y ) ) + ? (float)TerrainCosts.Cost( umt, world.TileSet.GetWalkability( world.Map.MapTiles[ x, y ] ) ) : float.PositiveInfinity; } diff --git a/OpenRa.Game/Traits/Activities/DeliverOre.cs b/OpenRa.Game/Traits/Activities/DeliverOre.cs index 7f7de0f55d..93b7d4b1f0 100644 --- a/OpenRa.Game/Traits/Activities/DeliverOre.cs +++ b/OpenRa.Game/Traits/Activities/DeliverOre.cs @@ -50,7 +50,7 @@ namespace OpenRa.Traits.Activities foreach( var r in refineries ) search.AddInitialCell( r.Location + refineryDeliverOffset ); - var path = Game.PathFinder.FindPath( search ); + var path = Game.world.PathFinder.FindPath( search ); path.Reverse(); if( path.Count != 0 ) { diff --git a/OpenRa.Game/Traits/Activities/Harvest.cs b/OpenRa.Game/Traits/Activities/Harvest.cs index 894d9a658b..3e2c8516e2 100644 --- a/OpenRa.Game/Traits/Activities/Harvest.cs +++ b/OpenRa.Game/Traits/Activities/Harvest.cs @@ -63,7 +63,7 @@ namespace OpenRa.Traits.Activities checkForBlocked = true }; search.AddInitialCell(self.Location); - return Game.PathFinder.FindPath(search); + return Game.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 a421cab39f..7f12749983 100755 --- a/OpenRa.Game/Traits/Activities/Move.cs +++ b/OpenRa.Game/Traits/Activities/Move.cs @@ -20,7 +20,7 @@ namespace OpenRa.Traits.Activities public Move( int2 destination, int nearEnough ) { - this.getPath = ( self, mobile ) => Game.PathFinder.FindUnitPath( + this.getPath = ( self, mobile ) => Game.world.PathFinder.FindUnitPath( self.Location, destination, mobile.GetMovementType() ); this.destination = destination; @@ -30,9 +30,9 @@ namespace OpenRa.Traits.Activities public Move(int2 destination, Actor ignoreBuilding) { this.getPath = (self, mobile) => - Game.PathFinder.FindPath( + Game.world.PathFinder.FindPath( PathSearch.FromPoint( self.Location, destination, mobile.GetMovementType(), false ) - .WithCustomBlocker( Game.PathFinder.AvoidUnitsNear( self.Location, 4 )).WithIgnoredBuilding( ignoreBuilding )); + .WithCustomBlocker( Game.world.PathFinder.AvoidUnitsNear( self.Location, 4 )).WithIgnoredBuilding( ignoreBuilding )); this.destination = destination; this.nearEnough = 0; @@ -41,7 +41,7 @@ namespace OpenRa.Traits.Activities public Move( Actor target, int range ) { - this.getPath = ( self, mobile ) => Game.PathFinder.FindUnitPathToRange( + this.getPath = ( self, mobile ) => Game.world.PathFinder.FindUnitPathToRange( self.Location, target.Location, mobile.GetMovementType(), range ); this.destination = null; diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index cd63b90b1d..ff1e212d17 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -16,6 +16,8 @@ namespace OpenRa public readonly BuildingInfluenceMap BuildingInfluence; public readonly UnitInfluenceMap UnitInfluence; + public readonly PathFinder PathFinder; + public readonly Map Map; public readonly TileSet TileSet; @@ -37,6 +39,8 @@ namespace OpenRa oreTicks = oreFrequency; Map.InitOreDensity(); + PathFinder = new PathFinder(this); + CreateActor("World", new int2(int.MaxValue, int.MaxValue), null); WorldRenderer = new WorldRenderer(this, Game.renderer);