diff options
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/api/ai_map.cpp | 19 | ||||
-rw-r--r-- | src/ai/api/ai_map.hpp | 12 |
2 files changed, 19 insertions, 12 deletions
diff --git a/src/ai/api/ai_map.cpp b/src/ai/api/ai_map.cpp index 2c8547f95..b3a7f753c 100644 --- a/src/ai/api/ai_map.cpp +++ b/src/ai/api/ai_map.cpp @@ -26,37 +26,44 @@ return ::MapSizeY(); } -/* static */ uint32 AIMap::GetTileX(TileIndex t) +/* static */ int32 AIMap::GetTileX(TileIndex t) { + if (!::IsValidTile(t)) return -1; return ::TileX(t); } -/* static */ uint32 AIMap::GetTileY(TileIndex t) +/* static */ int32 AIMap::GetTileY(TileIndex t) { + if (!::IsValidTile(t)) return -1; return ::TileY(t); } /* static */ TileIndex AIMap::GetTileIndex(uint32 x, uint32 y) { + if (x >= ::MapSizeX() || y >= MapSizeY()) return INVALID_TILE; return ::TileXY(x, y); } -/* static */ uint32 AIMap::DistanceManhattan(TileIndex t1, TileIndex t2) +/* static */ int32 AIMap::DistanceManhattan(TileIndex t1, TileIndex t2) { + if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1; return ::DistanceManhattan(t1, t2); } -/* static */ uint32 AIMap::DistanceMax(TileIndex t1, TileIndex t2) +/* static */ int32 AIMap::DistanceMax(TileIndex t1, TileIndex t2) { + if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1; return ::DistanceMax(t1, t2); } -/* static */ uint32 AIMap::DistanceSquare(TileIndex t1, TileIndex t2) +/* static */ int32 AIMap::DistanceSquare(TileIndex t1, TileIndex t2) { + if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1; return ::DistanceSquare(t1, t2); } -/* static */ uint32 AIMap::DistanceFromEdge(TileIndex t) +/* static */ int32 AIMap::DistanceFromEdge(TileIndex t) { + if (!::IsValidTile(t)) return -1; return ::DistanceFromEdge(t); } diff --git a/src/ai/api/ai_map.hpp b/src/ai/api/ai_map.hpp index f14c360eb..9c544ea25 100644 --- a/src/ai/api/ai_map.hpp +++ b/src/ai/api/ai_map.hpp @@ -49,7 +49,7 @@ public: * @return The X-value. * @post Return value is always lower than GetMapSizeX(). */ - static uint32 GetTileX(TileIndex tile); + static int32 GetTileX(TileIndex tile); /** * Gets the place along the SE/NW border (Y-value). @@ -58,7 +58,7 @@ public: * @return The Y-value. * @post Return value is always lower than GetMapSizeY(). */ - static uint32 GetTileY(TileIndex tile); + static int32 GetTileY(TileIndex tile); /** * Gets the TileIndex given a x,y-coordinate. @@ -79,7 +79,7 @@ public: * @pre IsValidTile(tile_to). * @return The Manhattan distance between the tiles. */ - static uint32 DistanceManhattan(TileIndex tile_from, TileIndex tile_to); + static int32 DistanceManhattan(TileIndex tile_from, TileIndex tile_to); /** * Calculates the distance between two tiles via 1D calculation. @@ -91,7 +91,7 @@ public: * @pre IsValidTile(tile_to). * @return The maximum distance between the tiles. */ - static uint32 DistanceMax(TileIndex tile_from, TileIndex tile_to); + static int32 DistanceMax(TileIndex tile_from, TileIndex tile_to); /** * The squared distance between the two tiles. @@ -103,7 +103,7 @@ public: * @pre IsValidTile(tile_to). * @return The squared distance between the tiles. */ - static uint32 DistanceSquare(TileIndex tile_from, TileIndex tile_to); + static int32 DistanceSquare(TileIndex tile_from, TileIndex tile_to); /** * Calculates the shortest distance to the edge. @@ -111,7 +111,7 @@ public: * @pre IsValidTile(tile). * @return The distances to the closest edge. */ - static uint32 DistanceFromEdge(TileIndex tile); + static int32 DistanceFromEdge(TileIndex tile); }; #endif /* AI_MAP_HPP */ |