Changeset - r26978:c6bc28c39f37
[Not reviewed]
master
0 3 0
glx22 - 21 months ago 2023-03-04 14:51:14
glx@openttd.org
Codechange: Use SQInteger for generic numbers in script_map
3 files changed with 26 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_map.cpp
Show inline comments
 
@@ -18,57 +18,57 @@
 
	return ::IsValidTile(t);
 
}
 

	
 
/* static */ TileIndex ScriptMap::GetMapSize()
 
/* static */ SQInteger ScriptMap::GetMapSize()
 
{
 
	return ::Map::Size();
 
}
 

	
 
/* static */ uint32 ScriptMap::GetMapSizeX()
 
/* static */ SQInteger ScriptMap::GetMapSizeX()
 
{
 
	return ::Map::SizeX();
 
}
 

	
 
/* static */ uint32 ScriptMap::GetMapSizeY()
 
/* static */ SQInteger ScriptMap::GetMapSizeY()
 
{
 
	return ::Map::SizeY();
 
}
 

	
 
/* static */ int32 ScriptMap::GetTileX(TileIndex t)
 
/* static */ SQInteger ScriptMap::GetTileX(TileIndex t)
 
{
 
	if (!::IsValidTile(t)) return -1;
 
	return ::TileX(t);
 
}
 

	
 
/* static */ int32 ScriptMap::GetTileY(TileIndex t)
 
/* static */ SQInteger ScriptMap::GetTileY(TileIndex t)
 
{
 
	if (!::IsValidTile(t)) return -1;
 
	return ::TileY(t);
 
}
 

	
 
/* static */ TileIndex ScriptMap::GetTileIndex(uint32 x, uint32 y)
 
/* static */ TileIndex ScriptMap::GetTileIndex(SQInteger x, SQInteger 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;
 
	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;
 
	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;
 
	return ::DistanceSquare(t1, t2);
 
}
 

	
 
/* static */ int32 ScriptMap::DistanceFromEdge(TileIndex t)
 
/* static */ SQInteger ScriptMap::DistanceFromEdge(TileIndex t)
 
{
 
	if (!::IsValidTile(t)) return -1;
 
	return ::DistanceFromEdge(t);
src/script/api/script_map.hpp
Show inline comments
 
@@ -33,21 +33,21 @@ public:
 
	 * @return The size of the map in tiles.
 
	 * @post Return value is always positive.
 
	 */
 
	static TileIndex GetMapSize();
 
	static SQInteger GetMapSize();
 

	
 
	/**
 
	 * Gets the amount of tiles along the SW and NE border.
 
	 * @return The length along the SW and NE borders.
 
	 * @post Return value is always positive.
 
	 */
 
	static uint32 GetMapSizeX();
 
	static SQInteger GetMapSizeX();
 

	
 
	/**
 
	 * Gets the amount of tiles along the SE and NW border.
 
	 * @return The length along the SE and NW borders.
 
	 * @post Return value is always positive.
 
	 */
 
	static uint32 GetMapSizeY();
 
	static SQInteger GetMapSizeY();
 

	
 
	/**
 
	 * Gets the place along the SW/NE border (X-value).
 
@@ -56,7 +56,7 @@ public:
 
	 * @return The X-value.
 
	 * @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).
 
@@ -65,17 +65,18 @@ public:
 
	 * @return The Y-value.
 
	 * @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.
 
	 * @param x The X coordinate.
 
	 * @param y The Y coordinate.
 
	 * @pre x < GetMapSizeX().
 
	 * @pre y < GetMapSizeY().
 
	 * @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
 
@@ -86,7 +87,7 @@ public:
 
	 * @pre IsValidTile(tile_to).
 
	 * @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.
 
@@ -98,7 +99,7 @@ public:
 
	 * @pre IsValidTile(tile_to).
 
	 * @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.
 
@@ -110,7 +111,7 @@ public:
 
	 * @pre IsValidTile(tile_to).
 
	 * @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.
 
@@ -118,7 +119,7 @@ public:
 
	 * @pre IsValidTile(tile).
 
	 * @return The distances to the closest edge.
 
	 */
 
	static int32 DistanceFromEdge(TileIndex tile);
 
	static SQInteger DistanceFromEdge(TileIndex tile);
 
};
 

	
 
#endif /* SCRIPT_MAP_HPP */
src/script/api/script_rail.cpp
Show inline comments
 
@@ -276,11 +276,11 @@
 

	
 
	if (tile - from == 1) {
 
		if (to - tile == 1) return (GetRailTracks(tile) & RAILTRACK_NE_SW) != 0;
 
		if (to - tile == ScriptMap::GetMapSizeX()) return (GetRailTracks(tile) & RAILTRACK_NE_SE) != 0;
 
	} else if (tile - from == ScriptMap::GetMapSizeX()) {
 
		if (to - tile == (int)ScriptMap::GetMapSizeX()) return (GetRailTracks(tile) & RAILTRACK_NE_SE) != 0;
 
	} else if (tile - from == (int)ScriptMap::GetMapSizeX()) {
 
		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 == ScriptMap::GetMapSizeX()) return (GetRailTracks(tile) & RAILTRACK_NW_SE) != 0;
 
		if (to - tile == (int)ScriptMap::GetMapSizeX()) return (GetRailTracks(tile) & RAILTRACK_NW_SE) != 0;
 
	} else {
 
		return (GetRailTracks(tile) & RAILTRACK_SW_SE) != 0;
 
	}
0 comments (0 inline, 0 general)