mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use SQInteger for generic numbers in script_map
parent
a225fda9fe
commit
ca67075397
|
@ -18,57 +18,57 @@
|
||||||
return ::IsValidTile(t);
|
return ::IsValidTile(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ TileIndex ScriptMap::GetMapSize()
|
/* static */ SQInteger ScriptMap::GetMapSize()
|
||||||
{
|
{
|
||||||
return ::Map::Size();
|
return ::Map::Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ uint32 ScriptMap::GetMapSizeX()
|
/* static */ SQInteger ScriptMap::GetMapSizeX()
|
||||||
{
|
{
|
||||||
return ::Map::SizeX();
|
return ::Map::SizeX();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ uint32 ScriptMap::GetMapSizeY()
|
/* static */ SQInteger ScriptMap::GetMapSizeY()
|
||||||
{
|
{
|
||||||
return ::Map::SizeY();
|
return ::Map::SizeY();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ int32 ScriptMap::GetTileX(TileIndex t)
|
/* static */ SQInteger ScriptMap::GetTileX(TileIndex t)
|
||||||
{
|
{
|
||||||
if (!::IsValidTile(t)) return -1;
|
if (!::IsValidTile(t)) return -1;
|
||||||
return ::TileX(t);
|
return ::TileX(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ int32 ScriptMap::GetTileY(TileIndex t)
|
/* static */ SQInteger ScriptMap::GetTileY(TileIndex t)
|
||||||
{
|
{
|
||||||
if (!::IsValidTile(t)) return -1;
|
if (!::IsValidTile(t)) return -1;
|
||||||
return ::TileY(t);
|
return ::TileY(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ TileIndex ScriptMap::GetTileIndex(uint32 x, uint32 y)
|
/* static */ TileIndex ScriptMap::GetTileIndex(SQInteger x, SQInteger y)
|
||||||
{
|
{
|
||||||
return ::TileXY(x, y);
|
return ::TileXY(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ int32 ScriptMap::DistanceManhattan(TileIndex t1, TileIndex t2)
|
/* static */ SQInteger ScriptMap::DistanceManhattan(TileIndex t1, TileIndex t2)
|
||||||
{
|
{
|
||||||
if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1;
|
if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1;
|
||||||
return ::DistanceManhattan(t1, t2);
|
return ::DistanceManhattan(t1, t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ int32 ScriptMap::DistanceMax(TileIndex t1, TileIndex t2)
|
/* static */ SQInteger ScriptMap::DistanceMax(TileIndex t1, TileIndex t2)
|
||||||
{
|
{
|
||||||
if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1;
|
if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1;
|
||||||
return ::DistanceMax(t1, t2);
|
return ::DistanceMax(t1, t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ int32 ScriptMap::DistanceSquare(TileIndex t1, TileIndex t2)
|
/* static */ SQInteger ScriptMap::DistanceSquare(TileIndex t1, TileIndex t2)
|
||||||
{
|
{
|
||||||
if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1;
|
if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1;
|
||||||
return ::DistanceSquare(t1, t2);
|
return ::DistanceSquare(t1, t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ int32 ScriptMap::DistanceFromEdge(TileIndex t)
|
/* static */ SQInteger ScriptMap::DistanceFromEdge(TileIndex t)
|
||||||
{
|
{
|
||||||
if (!::IsValidTile(t)) return -1;
|
if (!::IsValidTile(t)) return -1;
|
||||||
return ::DistanceFromEdge(t);
|
return ::DistanceFromEdge(t);
|
||||||
|
|
|
@ -33,21 +33,21 @@ public:
|
||||||
* @return The size of the map in tiles.
|
* @return The size of the map in tiles.
|
||||||
* @post Return value is always positive.
|
* @post Return value is always positive.
|
||||||
*/
|
*/
|
||||||
static TileIndex GetMapSize();
|
static SQInteger GetMapSize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the amount of tiles along the SW and NE border.
|
* Gets the amount of tiles along the SW and NE border.
|
||||||
* @return The length along the SW and NE borders.
|
* @return The length along the SW and NE borders.
|
||||||
* @post Return value is always positive.
|
* @post Return value is always positive.
|
||||||
*/
|
*/
|
||||||
static uint32 GetMapSizeX();
|
static SQInteger GetMapSizeX();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the amount of tiles along the SE and NW border.
|
* Gets the amount of tiles along the SE and NW border.
|
||||||
* @return The length along the SE and NW borders.
|
* @return The length along the SE and NW borders.
|
||||||
* @post Return value is always positive.
|
* @post Return value is always positive.
|
||||||
*/
|
*/
|
||||||
static uint32 GetMapSizeY();
|
static SQInteger GetMapSizeY();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the place along the SW/NE border (X-value).
|
* Gets the place along the SW/NE border (X-value).
|
||||||
|
@ -56,7 +56,7 @@ public:
|
||||||
* @return The X-value.
|
* @return The X-value.
|
||||||
* @post Return value is always lower than GetMapSizeX().
|
* @post Return value is always lower than GetMapSizeX().
|
||||||
*/
|
*/
|
||||||
static int32 GetTileX(TileIndex tile);
|
static SQInteger GetTileX(TileIndex tile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the place along the SE/NW border (Y-value).
|
* Gets the place along the SE/NW border (Y-value).
|
||||||
|
@ -65,17 +65,18 @@ public:
|
||||||
* @return The Y-value.
|
* @return The Y-value.
|
||||||
* @post Return value is always lower than GetMapSizeY().
|
* @post Return value is always lower than GetMapSizeY().
|
||||||
*/
|
*/
|
||||||
static int32 GetTileY(TileIndex tile);
|
static SQInteger GetTileY(TileIndex tile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the TileIndex given a x,y-coordinate.
|
* Gets the TileIndex given a x,y-coordinate.
|
||||||
* @param x The X coordinate.
|
* @param x The X coordinate.
|
||||||
* @param y The Y coordinate.
|
* @param y The Y coordinate.
|
||||||
* @pre x < GetMapSizeX().
|
|
||||||
* @pre y < GetMapSizeY().
|
|
||||||
* @return The TileIndex for the given (x,y) coordinate.
|
* @return The TileIndex for the given (x,y) coordinate.
|
||||||
|
* @post When 0 <= x && x < GetMapSizeX() && 0 <= y && y < GetMapSizeY(), then a valid tile index is returned.
|
||||||
|
* Otherwise it may be invalid, but could be used to calculated neighbouring tiles, e.g. tile + AIMap.GetTileIndex(-1, -1) gets
|
||||||
|
* the tile index of the tile to the north. But be aware that even when tile is a valid tile, the result might not be a valid tile.
|
||||||
*/
|
*/
|
||||||
static TileIndex GetTileIndex(uint32 x, uint32 y);
|
static TileIndex GetTileIndex(SQInteger x, SQInteger y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the Manhattan distance; the difference of
|
* Calculates the Manhattan distance; the difference of
|
||||||
|
@ -86,7 +87,7 @@ public:
|
||||||
* @pre IsValidTile(tile_to).
|
* @pre IsValidTile(tile_to).
|
||||||
* @return The Manhattan distance between the tiles.
|
* @return The Manhattan distance between the tiles.
|
||||||
*/
|
*/
|
||||||
static int32 DistanceManhattan(TileIndex tile_from, TileIndex tile_to);
|
static SQInteger DistanceManhattan(TileIndex tile_from, TileIndex tile_to);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the distance between two tiles via 1D calculation.
|
* Calculates the distance between two tiles via 1D calculation.
|
||||||
|
@ -98,7 +99,7 @@ public:
|
||||||
* @pre IsValidTile(tile_to).
|
* @pre IsValidTile(tile_to).
|
||||||
* @return The maximum distance between the tiles.
|
* @return The maximum distance between the tiles.
|
||||||
*/
|
*/
|
||||||
static int32 DistanceMax(TileIndex tile_from, TileIndex tile_to);
|
static SQInteger DistanceMax(TileIndex tile_from, TileIndex tile_to);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The squared distance between the two tiles.
|
* The squared distance between the two tiles.
|
||||||
|
@ -110,7 +111,7 @@ public:
|
||||||
* @pre IsValidTile(tile_to).
|
* @pre IsValidTile(tile_to).
|
||||||
* @return The squared distance between the tiles.
|
* @return The squared distance between the tiles.
|
||||||
*/
|
*/
|
||||||
static int32 DistanceSquare(TileIndex tile_from, TileIndex tile_to);
|
static SQInteger DistanceSquare(TileIndex tile_from, TileIndex tile_to);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the shortest distance to the edge.
|
* Calculates the shortest distance to the edge.
|
||||||
|
@ -118,7 +119,7 @@ public:
|
||||||
* @pre IsValidTile(tile).
|
* @pre IsValidTile(tile).
|
||||||
* @return The distances to the closest edge.
|
* @return The distances to the closest edge.
|
||||||
*/
|
*/
|
||||||
static int32 DistanceFromEdge(TileIndex tile);
|
static SQInteger DistanceFromEdge(TileIndex tile);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SCRIPT_MAP_HPP */
|
#endif /* SCRIPT_MAP_HPP */
|
||||||
|
|
|
@ -276,11 +276,11 @@
|
||||||
|
|
||||||
if (tile - from == 1) {
|
if (tile - from == 1) {
|
||||||
if (to - tile == 1) return (GetRailTracks(tile) & RAILTRACK_NE_SW) != 0;
|
if (to - tile == 1) return (GetRailTracks(tile) & RAILTRACK_NE_SW) != 0;
|
||||||
if (to - tile == ScriptMap::GetMapSizeX()) return (GetRailTracks(tile) & RAILTRACK_NE_SE) != 0;
|
if (to - tile == (int)ScriptMap::GetMapSizeX()) return (GetRailTracks(tile) & RAILTRACK_NE_SE) != 0;
|
||||||
} else if (tile - from == ScriptMap::GetMapSizeX()) {
|
} else if (tile - from == (int)ScriptMap::GetMapSizeX()) {
|
||||||
if (tile - to == 1) return (GetRailTracks(tile) & RAILTRACK_NW_NE) != 0;
|
if (tile - to == 1) return (GetRailTracks(tile) & RAILTRACK_NW_NE) != 0;
|
||||||
if (to - tile == 1) return (GetRailTracks(tile) & RAILTRACK_NW_SW) != 0;
|
if (to - tile == 1) return (GetRailTracks(tile) & RAILTRACK_NW_SW) != 0;
|
||||||
if (to - tile == ScriptMap::GetMapSizeX()) return (GetRailTracks(tile) & RAILTRACK_NW_SE) != 0;
|
if (to - tile == (int)ScriptMap::GetMapSizeX()) return (GetRailTracks(tile) & RAILTRACK_NW_SE) != 0;
|
||||||
} else {
|
} else {
|
||||||
return (GetRailTracks(tile) & RAILTRACK_SW_SE) != 0;
|
return (GetRailTracks(tile) & RAILTRACK_SW_SE) != 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue