diff --git a/OpenRa.Game/Bridges.cs b/OpenRa.Game/Bridges.cs index 939bc5f2b3..1d9ad28626 100644 --- a/OpenRa.Game/Bridges.cs +++ b/OpenRa.Game/Bridges.cs @@ -52,7 +52,7 @@ namespace OpenRa { var a = w.CreateActor("Bridge", new int2(ni, nj), null); var br = a.traits.Get(); - br.SetTiles(template, replacedTiles); + br.SetTiles(w, template, replacedTiles); } } diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 71246c54cf..96e3f572fb 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -58,6 +58,7 @@ namespace OpenRa FileSystem.UnmountTemporaryPackages(); Rules.LoadRules(mapName, usingAftermath); + world = null; // trying to access the old world will NRE, rather than silently doing it wrong. world = new World(); Game.world.ActorAdded += a => { diff --git a/OpenRa.Game/PathFinder.cs b/OpenRa.Game/PathFinder.cs index e27ca54284..aabf600d62 100644 --- a/OpenRa.Game/PathFinder.cs +++ b/OpenRa.Game/PathFinder.cs @@ -4,6 +4,7 @@ using System.Linq; using OpenRa.FileFormats; using OpenRa.Support; using OpenRa.Traits; +using System.Diagnostics; namespace OpenRa { @@ -143,9 +144,7 @@ namespace OpenRa return ret; } - - - [System.Diagnostics.Conditional( "SANITY_CHECKS" )] + [Conditional( "SANITY_CHECKS" )] static void CheckSanePath( List path ) { if( path.Count == 0 ) @@ -160,7 +159,7 @@ namespace OpenRa } } - [System.Diagnostics.Conditional("SANITY_CHECKS")] + [Conditional("SANITY_CHECKS")] static void CheckSanePath2(List path, int2 src, int2 dest) { if (path.Count == 0) diff --git a/OpenRa.Game/PathSearch.cs b/OpenRa.Game/PathSearch.cs index e4db641604..30c79ae194 100755 --- a/OpenRa.Game/PathSearch.cs +++ b/OpenRa.Game/PathSearch.cs @@ -39,7 +39,12 @@ namespace OpenRa var p = queue.Pop(); cellInfo[ p.Location.X, p.Location.Y ].Seen = true; - if (passableCost[(int)umt][p.Location.X, p.Location.Y] == float.PositiveInfinity) + var custom2 = Game.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]; + + if (thisCost == float.PositiveInfinity) return p.Location; foreach( int2 d in Util.directions ) @@ -51,6 +56,7 @@ namespace OpenRa continue; var custom = Game.world.customTerrain[newHere.X, newHere.Y]; + if (custom != null) throw new NotImplementedException(); var costHere = (custom != null) ? custom.GetCost(newHere, umt) : passableCost[(int)umt][newHere.X, newHere.Y]; if (costHere == float.PositiveInfinity) diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index 0ef1ff41f1..5cc841a203 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -32,17 +32,17 @@ namespace OpenRa.Traits yield return new Renderable(t.Value, Game.CellSize * t.Key, PaletteType.Gold); } - public void SetTiles(TileTemplate template, Dictionary replacedTiles) + public void SetTiles(World world, TileTemplate template, Dictionary replacedTiles) { Template = template; Tiles = replacedTiles; foreach (var t in replacedTiles.Keys) - Game.world.customTerrain[t.X, t.Y] = this; + world.customTerrain[t.X, t.Y] = this; - if (cachedTheater != Game.world.Map.Theater) + if (cachedTheater != world.Map.Theater) { - cachedTheater = Game.world.Map.Theater; + cachedTheater = world.Map.Theater; sprites = new Cache( x => SheetBuilder.Add(Game.world.TileSet.GetBytes(x), new Size(Game.CellSize, Game.CellSize)));