1
0
Fork 0

Codechange: Use SQInteger for generic numbers in script_tile

pull/10532/head
glx22 2023-03-04 19:09:36 +01:00 committed by Loïc Guilloux
parent 07b73a8c02
commit cada18a6f8
2 changed files with 25 additions and 23 deletions

View File

@ -44,10 +44,10 @@
} }
} }
/* 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 */ /* 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 tx = ScriptMap::GetTileX(tile);
uint ty = ScriptMap::GetTileY(tile); uint ty = ScriptMap::GetTileY(tile);
@ -180,21 +180,21 @@
return (Slope)::ComplementSlope((::Slope)slope); return (Slope)::ComplementSlope((::Slope)slope);
} }
/* static */ int32 ScriptTile::GetMinHeight(TileIndex tile) /* static */ SQInteger ScriptTile::GetMinHeight(TileIndex tile)
{ {
if (!::IsValidTile(tile)) return -1; if (!::IsValidTile(tile)) return -1;
return ::GetTileZ(tile); return ::GetTileZ(tile);
} }
/* static */ int32 ScriptTile::GetMaxHeight(TileIndex tile) /* static */ SQInteger ScriptTile::GetMaxHeight(TileIndex tile)
{ {
if (!::IsValidTile(tile)) return -1; if (!::IsValidTile(tile)) return -1;
return ::GetTileMaxZ(tile); 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; if (!::IsValidTile(tile) || !::IsValidCorner((::Corner)corner)) return -1;
@ -224,7 +224,7 @@
} }
} }
/* 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; if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !ScriptCargo::IsValidCargo(cargo_type)) return -1;
@ -232,7 +232,7 @@
return acceptance[cargo_type]; 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; if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !ScriptCargo::IsValidCargo(cargo_type)) return -1;
@ -240,17 +240,17 @@
return produced[cargo_type]; 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); 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); 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, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, tile < ScriptMap::GetMapSize()); EnforcePrecondition(false, tile < ScriptMap::GetMapSize());
@ -258,7 +258,7 @@
return ScriptObject::Command<CMD_TERRAFORM_LAND>::Do(tile, (::Slope)slope, true); 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, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, tile < ScriptMap::GetMapSize()); EnforcePrecondition(false, tile < ScriptMap::GetMapSize());
@ -290,7 +290,7 @@
return ScriptObject::Command<CMD_PLANT_TREE>::Do(tile, tile, TREE_INVALID, false); 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, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, ::IsValidTile(tile));

View File

@ -155,9 +155,11 @@ public:
* @param width The width of the rectangle. * @param width The width of the rectangle.
* @param height The height of the rectangle. * @param height The height of the rectangle.
* @pre ScriptMap::IsValidTile(tile). * @pre ScriptMap::IsValidTile(tile).
* @pre width >= 0.
* @pre height >= 0.
* @return True if it is buildable, false if not. * @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. * Checks whether the given tile is actually a sea tile.
@ -308,7 +310,7 @@ public:
* @pre ScriptMap::IsValidTile(tile). * @pre ScriptMap::IsValidTile(tile).
* @return The height of the lowest corner of the tile, ranging from 0 to 15. * @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. * Get the maximal height on a tile.
@ -317,7 +319,7 @@ public:
* @pre ScriptMap::IsValidTile(tile). * @pre ScriptMap::IsValidTile(tile).
* @return The height of the highest corner of the tile, ranging from 0 to 15. * @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. * Get the height of a certain corner of a tile.
@ -327,7 +329,7 @@ public:
* @pre ScriptMap::IsValidTile(tile). * @pre ScriptMap::IsValidTile(tile).
* @return The height of the lowest corner of the tile, ranging from 0 to 15. * @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. * Get the owner of the tile.
@ -372,7 +374,7 @@ public:
* @pre radius >= 0. * @pre radius >= 0.
* @return Values below 8 mean no acceptance; the more the better. * @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. * Checks how many producers in the radius produces this cargo.
@ -389,7 +391,7 @@ public:
* @pre radius >= 0. * @pre radius >= 0.
* @return The number of producers that produce this cargo within radius of the tile. * @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. * Get the manhattan distance from the tile to the tile.
@ -397,7 +399,7 @@ public:
* @param tile_to The tile to get the distance to. * @param tile_to The tile to get the distance to.
* @return The distance between the two tiles. * @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. * Get the square distance from the tile to the tile.
@ -405,7 +407,7 @@ public:
* @param tile_to The tile to get the distance to. * @param tile_to The tile to get the distance to.
* @return The distance between the two tiles. * @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, * Raise the given corners of the tile. The corners can be combined,
@ -422,7 +424,7 @@ public:
* @exception ScriptTile::ERR_TILE_TOO_HIGH * @exception ScriptTile::ERR_TILE_TOO_HIGH
* @return 0 means failed, 1 means success. * @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, * Lower the given corners of the tile. The corners can be combined,
@ -439,7 +441,7 @@ public:
* @exception ScriptTile::ERR_TILE_TOO_LOW * @exception ScriptTile::ERR_TILE_TOO_LOW
* @return 0 means failed, 1 means success. * @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 * Level all tiles in the rectangle between start_tile and end_tile so they
@ -489,7 +491,7 @@ public:
* @game @pre Valid ScriptCompanyMode active in scope. * @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. * @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. * Find out if this tile is within the rating influence of a town.