Feature: [AI/GS] Missing water related functions and objects (#8390)

This commit is contained in:
SamuXarick
2021-09-14 21:06:55 +01:00
committed by GitHub
parent c6035158ca
commit 37de878129
8 changed files with 319 additions and 61 deletions

View File

@@ -21,6 +21,11 @@
* \li AINewGRF
* \li AINewGRFList
* \li AIGroup::GetNumVehicles
* \li AIMarine::BT_LOCK
* \li AIMarine::BT_CANAL
* \li AITile::IsSeaTile
* \li AITile::IsRiverTile
* \li AITile::BT_CLEAR_WATER
*
* \b 1.11.0
*

View File

@@ -20,6 +20,11 @@
* API additions:
* \li GSNewGRF
* \li GSNewGRFList
* \li GSMarine::BT_LOCK
* \li GSMarine::BT_CANAL
* \li GSTile::IsSeaTile
* \li GSTile::IsRiverTile
* \li GSTile::BT_CLEAR_WATER
*
* \b 1.11.0
*

View File

@@ -167,6 +167,8 @@
case BT_DOCK: return ::GetPrice(PR_BUILD_STATION_DOCK, 1, nullptr);
case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_SHIP, 1, nullptr);
case BT_BUOY: return ::GetPrice(PR_BUILD_WAYPOINT_BUOY, 1, nullptr);
case BT_LOCK: return ::GetPrice(PR_BUILD_LOCK, 1, nullptr);
case BT_CANAL: return ::GetPrice(PR_BUILD_CANAL, 1, nullptr);
default: return -1;
}
}

View File

@@ -36,6 +36,8 @@ public:
BT_DOCK, ///< Build a dock
BT_DEPOT, ///< Build a ship depot
BT_BUOY, ///< Build a buoy
BT_LOCK, ///< Build a lock
BT_CANAL, ///< Build a canal
};
/**

View File

@@ -58,6 +58,20 @@
return true;
}
/* static */ bool ScriptTile::IsSeaTile(TileIndex tile)
{
if (!::IsValidTile(tile)) return false;
return ::IsTileType(tile, MP_WATER) && ::IsSea(tile);
}
/* static */ bool ScriptTile::IsRiverTile(TileIndex tile)
{
if (!::IsValidTile(tile)) return false;
return ::IsTileType(tile, MP_WATER) && ::IsRiver(tile);
}
/* static */ bool ScriptTile::IsWaterTile(TileIndex tile)
{
if (!::IsValidTile(tile)) return false;
@@ -320,6 +334,7 @@
case BT_CLEAR_ROCKY: return ::GetPrice(PR_CLEAR_ROCKS, 1, nullptr);
case BT_CLEAR_FIELDS: return ::GetPrice(PR_CLEAR_FIELDS, 1, nullptr);
case BT_CLEAR_HOUSE: return ::GetPrice(PR_CLEAR_HOUSE, 1, nullptr);
case BT_CLEAR_WATER: return ::GetPrice(PR_CLEAR_WATER, 1, nullptr);
default: return -1;
}
}

View File

@@ -119,6 +119,7 @@ public:
BT_CLEAR_ROCKY, ///< Clear a tile with rocks
BT_CLEAR_FIELDS, ///< Clear a tile with farm fields
BT_CLEAR_HOUSE, ///< Clear a tile with a house
BT_CLEAR_WATER, ///< Clear a tile with either river or sea
};
/**
@@ -158,11 +159,28 @@ public:
*/
static bool IsBuildableRectangle(TileIndex tile, uint width, uint 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.
*/
static bool IsSeaTile(TileIndex tile);
/**
* Checks whether the given tile is actually a river tile.
* @param tile The tile to check on.
* @pre ScriptMap::IsValidTile(tile).
* @return True if and only if the tile is a river tile.
*/
static bool IsRiverTile(TileIndex tile);
/**
* Checks whether the given tile is actually a water tile.
* @param tile The tile to check on.
* @pre ScriptMap::IsValidTile(tile).
* @return True if and only if the tile is a water tile.
* @note Returns false when a buoy is on the tile.
*/
static bool IsWaterTile(TileIndex tile);