Changeset - r26989:928659421025
[Not reviewed]
master
0 2 0
glx22 - 16 months ago 2023-03-04 18:09:36
glx@openttd.org
Codechange: Use SQInteger for generic numbers in script_tile
2 files changed with 25 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_tile.cpp
Show inline comments
 
@@ -41,16 +41,16 @@
 
			if (::IsRoadOwner(tile, RTT_ROAD, OWNER_TOWN)) return true;
 
			if (::IsRoadOwner(tile, RTT_ROAD, ScriptObject::GetCompany())) return true;
 
			return false;
 
	}
 
}
 

	
 
/* static */ bool ScriptTile::IsBuildableRectangle(TileIndex tile, uint width, uint height)
 
/* static */ bool ScriptTile::IsBuildableRectangle(TileIndex tile, SQInteger width, SQInteger height)
 
{
 
	/* Check whether we can extract valid X and Y */
 
	if (!::IsValidTile(tile)) return false;
 
	if (!::IsValidTile(tile) || width < 0 || height < 0) return false;
 

	
 
	uint tx = ScriptMap::GetTileX(tile);
 
	uint ty = ScriptMap::GetTileY(tile);
 

	
 
	for (uint x = tx; x < width + tx; x++) {
 
		for (uint y = ty; y < height + ty; y++) {
 
@@ -177,27 +177,27 @@
 
{
 
	if ((slope & ~SLOPE_ELEVATED) != 0) return SLOPE_INVALID;
 

	
 
	return (Slope)::ComplementSlope((::Slope)slope);
 
}
 

	
 
/* static */ int32 ScriptTile::GetMinHeight(TileIndex tile)
 
/* static */ SQInteger ScriptTile::GetMinHeight(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return -1;
 

	
 
	return ::GetTileZ(tile);
 
}
 

	
 
/* static */ int32 ScriptTile::GetMaxHeight(TileIndex tile)
 
/* static */ SQInteger ScriptTile::GetMaxHeight(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return -1;
 

	
 
	return ::GetTileMaxZ(tile);
 
}
 

	
 
/* static */ int32 ScriptTile::GetCornerHeight(TileIndex tile, Corner corner)
 
/* static */ SQInteger ScriptTile::GetCornerHeight(TileIndex tile, Corner corner)
 
{
 
	if (!::IsValidTile(tile) || !::IsValidCorner((::Corner)corner)) return -1;
 

	
 
	int z;
 
	::Slope slope = ::GetTileSlope(tile, &z);
 
	return (z + ::GetSlopeZInCorner(slope, (::Corner)corner));
 
@@ -221,47 +221,47 @@
 
				::TrackStatusToTrackdirBits(::GetTileTrackStatus(tile, (::TransportType)transport_type, 1)) != TRACKDIR_BIT_NONE;
 
	} else {
 
		return ::TrackStatusToTrackdirBits(::GetTileTrackStatus(tile, (::TransportType)transport_type, 0)) != TRACKDIR_BIT_NONE;
 
	}
 
}
 

	
 
/* static */ int32 ScriptTile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, int width, int height, int radius)
 
/* static */ SQInteger ScriptTile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, SQInteger width, SQInteger height, SQInteger radius)
 
{
 
	if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !ScriptCargo::IsValidCargo(cargo_type)) return -1;
 

	
 
	CargoArray acceptance = ::GetAcceptanceAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED);
 
	return acceptance[cargo_type];
 
}
 

	
 
/* static */ int32 ScriptTile::GetCargoProduction(TileIndex tile, CargoID cargo_type, int width, int height, int radius)
 
/* static */ SQInteger ScriptTile::GetCargoProduction(TileIndex tile, CargoID cargo_type, SQInteger width, SQInteger height, SQInteger radius)
 
{
 
	if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !ScriptCargo::IsValidCargo(cargo_type)) return -1;
 

	
 
	CargoArray produced = ::GetProductionAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED);
 
	return produced[cargo_type];
 
}
 

	
 
/* static */ int32 ScriptTile::GetDistanceManhattanToTile(TileIndex tile_from, TileIndex tile_to)
 
/* static */ SQInteger ScriptTile::GetDistanceManhattanToTile(TileIndex tile_from, TileIndex tile_to)
 
{
 
	return ScriptMap::DistanceManhattan(tile_from, tile_to);
 
}
 

	
 
/* static */ int32 ScriptTile::GetDistanceSquareToTile(TileIndex tile_from, TileIndex tile_to)
 
/* static */ SQInteger ScriptTile::GetDistanceSquareToTile(TileIndex tile_from, TileIndex tile_to)
 
{
 
	return ScriptMap::DistanceSquare(tile_from, tile_to);
 
}
 

	
 
/* static */ bool ScriptTile::RaiseTile(TileIndex tile, int32 slope)
 
/* static */ bool ScriptTile::RaiseTile(TileIndex tile, Slope slope)
 
{
 
	EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
 
	EnforcePrecondition(false, tile < ScriptMap::GetMapSize());
 

	
 
	return ScriptObject::Command<CMD_TERRAFORM_LAND>::Do(tile, (::Slope)slope, true);
 
}
 

	
 
/* static */ bool ScriptTile::LowerTile(TileIndex tile, int32 slope)
 
/* static */ bool ScriptTile::LowerTile(TileIndex tile, Slope slope)
 
{
 
	EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
 
	EnforcePrecondition(false, tile < ScriptMap::GetMapSize());
 

	
 
	return ScriptObject::Command<CMD_TERRAFORM_LAND>::Do(tile, (::Slope)slope, false);
 
}
 
@@ -287,13 +287,13 @@
 
	EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
 
	EnforcePrecondition(false, ::IsValidTile(tile));
 

	
 
	return ScriptObject::Command<CMD_PLANT_TREE>::Do(tile, tile, TREE_INVALID, false);
 
}
 

	
 
/* static */ bool ScriptTile::PlantTreeRectangle(TileIndex tile, uint width, uint height)
 
/* static */ bool ScriptTile::PlantTreeRectangle(TileIndex tile, SQInteger width, SQInteger height)
 
{
 
	EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
 
	EnforcePrecondition(false, ::IsValidTile(tile));
 
	EnforcePrecondition(false, width >= 1 && width <= 20);
 
	EnforcePrecondition(false, height >= 1 && height <= 20);
 
	TileIndex end_tile = tile + ::TileDiffXY(width - 1, height - 1);
src/script/api/script_tile.hpp
Show inline comments
 
@@ -152,15 +152,17 @@ public:
 
	 * Check if this tile is buildable in a rectangle around a tile, with the
 
	 *  entry in the list as top-left.
 
	 * @param tile The tile to check on.
 
	 * @param width The width of the rectangle.
 
	 * @param height The height of the rectangle.
 
	 * @pre ScriptMap::IsValidTile(tile).
 
	 * @pre width >= 0.
 
	 * @pre height >= 0.
 
	 * @return True if it is buildable, false if not.
 
	 */
 
	static bool IsBuildableRectangle(TileIndex tile, uint width, uint height);
 
	static bool IsBuildableRectangle(TileIndex tile, SQInteger width, SQInteger height);
 

	
 
	/**
 
	 * Checks whether the given tile is actually a sea tile.
 
	 * @param tile The tile to check on.
 
	 * @pre ScriptMap::IsValidTile(tile).
 
	 * @return True if and only if the tile is a sea tile.
 
@@ -305,32 +307,32 @@ public:
 
	 * Get the minimal height on a tile.
 
	 * The returned height is the height of the bare tile. A possible foundation on the tile does not influence this height.
 
	 * @param tile The tile to check on.
 
	 * @pre ScriptMap::IsValidTile(tile).
 
	 * @return The height of the lowest corner of the tile, ranging from 0 to 15.
 
	 */
 
	static int32 GetMinHeight(TileIndex tile);
 
	static SQInteger GetMinHeight(TileIndex tile);
 

	
 
	/**
 
	 * Get the maximal height on a tile.
 
	 * The returned height is the height of the bare tile. A possible foundation on the tile does not influence this height.
 
	 * @param tile The tile to check on.
 
	 * @pre ScriptMap::IsValidTile(tile).
 
	 * @return The height of the highest corner of the tile, ranging from 0 to 15.
 
	 */
 
	static int32 GetMaxHeight(TileIndex tile);
 
	static SQInteger GetMaxHeight(TileIndex tile);
 

	
 
	/**
 
	 * Get the height of a certain corner of a tile.
 
	 * The returned height is the height of the bare tile. A possible foundation on the tile does not influence this height.
 
	 * @param tile The tile to check on.
 
	 * @param corner The corner to query.
 
	 * @pre ScriptMap::IsValidTile(tile).
 
	 * @return The height of the lowest corner of the tile, ranging from 0 to 15.
 
	 */
 
	static int32 GetCornerHeight(TileIndex tile, Corner corner);
 
	static SQInteger GetCornerHeight(TileIndex tile, Corner corner);
 

	
 
	/**
 
	 * Get the owner of the tile.
 
	 * @param tile The tile to get the owner from.
 
	 * @pre ScriptMap::IsValidTile(tile).
 
	 * @return The CompanyID of the owner of the tile, or COMPANY_INVALID if
 
@@ -369,13 +371,13 @@ public:
 
	 * @pre ScriptCargo::IsValidCargo(cargo_type)
 
	 * @pre width > 0.
 
	 * @pre height > 0.
 
	 * @pre radius >= 0.
 
	 * @return Values below 8 mean no acceptance; the more the better.
 
	 */
 
	static int32 GetCargoAcceptance(TileIndex tile, CargoID cargo_type, int width, int height, int radius);
 
	static SQInteger GetCargoAcceptance(TileIndex tile, CargoID cargo_type, SQInteger width, SQInteger height, SQInteger radius);
 

	
 
	/**
 
	 * Checks how many producers in the radius produces this cargo.
 
	 *  It creates a radius around the tile, and counts all producer of this cargo.
 
	 * @param tile The tile to check on.
 
	 * @param cargo_type The cargo to check the production of.
 
@@ -386,29 +388,29 @@ public:
 
	 * @pre ScriptCargo::IsValidCargo(cargo_type)
 
	 * @pre width > 0.
 
	 * @pre height > 0.
 
	 * @pre radius >= 0.
 
	 * @return The number of producers that produce this cargo within radius of the tile.
 
	 */
 
	static int32 GetCargoProduction(TileIndex tile, CargoID cargo_type, int width, int height, int radius);
 
	static SQInteger GetCargoProduction(TileIndex tile, CargoID cargo_type, SQInteger width, SQInteger height, SQInteger radius);
 

	
 
	/**
 
	 * Get the manhattan distance from the tile to the tile.
 
	 * @param tile_from The tile to get the distance to.
 
	 * @param tile_to The tile to get the distance to.
 
	 * @return The distance between the two tiles.
 
	 */
 
	static int32 GetDistanceManhattanToTile(TileIndex tile_from, TileIndex tile_to);
 
	static SQInteger GetDistanceManhattanToTile(TileIndex tile_from, TileIndex tile_to);
 

	
 
	/**
 
	 * Get the square distance from the tile to the tile.
 
	 * @param tile_from The tile to get the distance to.
 
	 * @param tile_to The tile to get the distance to.
 
	 * @return The distance between the two tiles.
 
	 */
 
	static int32 GetDistanceSquareToTile(TileIndex tile_from, TileIndex tile_to);
 
	static SQInteger GetDistanceSquareToTile(TileIndex tile_from, TileIndex tile_to);
 

	
 
	/**
 
	 * Raise the given corners of the tile. The corners can be combined,
 
	 *  for example: SLOPE_N | SLOPE_W (= SLOPE_NW) will raise the west and the north corner.
 
	 * @note The corners will be modified in the order west (first), south, east, north (last).
 
	 *       Changing one corner might cause another corner to be changed too. So modifiing
 
@@ -419,13 +421,13 @@ public:
 
	 * @game @pre Valid ScriptCompanyMode active in scope.
 
	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
 
	 * @exception ScriptError::ERR_TOO_CLOSE_TO_EDGE
 
	 * @exception ScriptTile::ERR_TILE_TOO_HIGH
 
	 * @return 0 means failed, 1 means success.
 
	 */
 
	static bool RaiseTile(TileIndex tile, int32 slope);
 
	static bool RaiseTile(TileIndex tile, Slope slope);
 

	
 
	/**
 
	 * Lower the given corners of the tile. The corners can be combined,
 
	 *  for example: SLOPE_N | SLOPE_W (= SLOPE_NW) will lower the west and the north corner.
 
	 * @note The corners will be modified in the order west (first), south, east, north (last).
 
	 *       Changing one corner might cause another corner to be changed too. So modifiing
 
@@ -436,13 +438,13 @@ public:
 
	 * @game @pre Valid ScriptCompanyMode active in scope.
 
	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
 
	 * @exception ScriptError::ERR_TOO_CLOSE_TO_EDGE
 
	 * @exception ScriptTile::ERR_TILE_TOO_LOW
 
	 * @return 0 means failed, 1 means success.
 
	 */
 
	static bool LowerTile(TileIndex tile, int32 slope);
 
	static bool LowerTile(TileIndex tile, Slope slope);
 

	
 
	/**
 
	 * Level all tiles in the rectangle between start_tile and end_tile so they
 
	 *  are at the same height. All tiles will be raised or lowered until
 
	 *  they are at height ScriptTile::GetCornerHeight(start_tile, ScriptTile::CORNER_N).
 
	 * @param start_tile One corner of the rectangle to level.
 
@@ -486,13 +488,13 @@ public:
 
	 * @pre ScriptMap::IsValidTile(tile).
 
	 * @pre width >= 1 && width <= 20.
 
	 * @pre height >= 1 && height <= 20.
 
	 * @game @pre Valid ScriptCompanyMode active in scope.
 
	 * @return True if and only if a tree was added on any of the tiles in the rectangle.
 
	 */
 
	static bool PlantTreeRectangle(TileIndex tile, uint width, uint height);
 
	static bool PlantTreeRectangle(TileIndex tile, SQInteger width, SQInteger height);
 

	
 
	/**
 
	 * Find out if this tile is within the rating influence of a town.
 
	 *  If a station sign would be on this tile, the servicing quality of the station would
 
	 *  influence the rating of the town.
 
	 * @param tile The tile to check.
0 comments (0 inline, 0 general)