diff --git a/OpenRa.FileFormats/Map.cs b/OpenRa.FileFormats/Map.cs index 4776132f25..8e2d0c85f3 100644 --- a/OpenRa.FileFormats/Map.cs +++ b/OpenRa.FileFormats/Map.cs @@ -126,6 +126,11 @@ namespace OpenRa.FileFormats foreach( KeyValuePair kv in terrain ) Trees.Add( new TreeReference( int.Parse( kv.Key ), kv.Value ) ); } + + public bool IsInMap(int x, int y) + { + return (x >= XOffset && y >= YOffset && x < XOffset + Width && y < YOffset + Height); + } } public struct TileReference diff --git a/OpenRa.FileFormats/TileSet.cs b/OpenRa.FileFormats/TileSet.cs index 170cafca6e..cec71e1ad0 100644 --- a/OpenRa.FileFormats/TileSet.cs +++ b/OpenRa.FileFormats/TileSet.cs @@ -9,7 +9,8 @@ namespace OpenRa.FileFormats public class TileSet { public readonly Dictionary tiles = new Dictionary(); - public readonly Dictionary> walk = + + readonly Dictionary> walk = new Dictionary>(); // cjf will fix public readonly Package MixFile; @@ -78,5 +79,13 @@ namespace OpenRa.FileFormats return missingTile; } + + public int GetWalkability(TileReference r) + { + if (r.tile == 0xff || r.tile == 0xffff) + r.image = 0; + + return walk[r.tile][r.image]; + } } } diff --git a/OpenRa.Game/PathFinder.cs b/OpenRa.Game/PathFinder.cs index 96692dc711..9271b6525a 100644 --- a/OpenRa.Game/PathFinder.cs +++ b/OpenRa.Game/PathFinder.cs @@ -29,26 +29,16 @@ namespace OpenRa.Game } } - public PathFinder( Map map, TileSet tileSet ) + public PathFinder(Map map, TileSet tileSet) { this.map = map; - for( int x = 0 ; x < 128 ; x++ ) - { - for( int y = 0 ; y < 128 ; y++ ) - { - if (x < map.XOffset || y < map.YOffset || x >= map.XOffset + map.Width || y >= map.YOffset + map.Height) - passable[x, y] = false; - else - { - TileReference r = map.MapTiles[x, y]; - if (r.tile == 0xffff || r.tile == 0xff) - r.image = 0; + //todo: speed hax for roads - passable[x, y] = IsPassable(tileSet.walk[r.tile][r.image]); - } - } - } + for (int x = 0; x < 128; x++) + for (int y = 0; y < 128; y++) + passable[x, y] = map.IsInMap(x, y) && + IsPassable(tileSet.GetWalkability(map.MapTiles[x, y])); } public List FindUnitPath( World world, Unit unit, int2 destination )