Mercurial > hg > openttd
changeset 12111:faa0b6550e1f draft
(svn r16524) -Fix [FS#2963]: missing guards in the NoAI API making it possible to hit an assert in OpenTTD.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sat, 06 Jun 2009 11:47:21 +0000 |
parents | ec2c917b3560 |
children | 527e86d95414 |
files | src/ai/api/ai_tile.cpp src/ai/api/ai_tile.hpp src/ai/api/ai_tilelist.cpp src/ai/api/ai_tilelist.hpp |
diffstat | 4 files changed, 24 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ai/api/ai_tile.cpp +++ b/src/ai/api/ai_tile.cpp @@ -175,21 +175,21 @@ return ::TrackStatusToTrackdirBits(::GetTileTrackStatus(tile, (::TransportType)transport_type, UINT32_MAX)) != TRACKDIR_BIT_NONE; } -/* static */ int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius) +/* static */ int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, int width, int height, int radius) { - if (!::IsValidTile(tile)) return false; + if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius <= 0) return -1; AcceptedCargo accepts; - ::GetAcceptanceAroundTiles(accepts, tile, width, height, _settings_game.station.modified_catchment ? radius : (uint)CA_UNMODIFIED); + ::GetAcceptanceAroundTiles(accepts, tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED); return accepts[cargo_type]; } -/* static */ int32 AITile::GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius) +/* static */ int32 AITile::GetCargoProduction(TileIndex tile, CargoID cargo_type, int width, int height, int radius) { - if (!::IsValidTile(tile)) return false; + if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius <= 0) return -1; AcceptedCargo produced; - ::GetProductionAroundTiles(produced, tile, width, height, _settings_game.station.modified_catchment ? radius : (uint)CA_UNMODIFIED); + ::GetProductionAroundTiles(produced, tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED); return produced[cargo_type]; }
--- a/src/ai/api/ai_tile.hpp +++ b/src/ai/api/ai_tile.hpp @@ -303,9 +303,12 @@ * @param height The height of the station. * @param radius The radius of the station. * @pre AIMap::IsValidTile(tile). + * @pre width > 0. + * @pre height > 0. + * @pre radius > 0. * @return Value below 8 means no acceptance; the more the better. */ - static int32 GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius); + static int32 GetCargoAcceptance(TileIndex tile, CargoID cargo_type, int width, int height, int radius); /** * Checks how many tiles in the radius produces this cargo. @@ -317,10 +320,13 @@ * @param height The height of the station. * @param radius The radius of the station. * @pre AIMap::IsValidTile(tile). + * @pre width > 0. + * @pre height > 0. + * @pre radius > 0. * @return The tiles that produce this cargo within radius of the tile. * @note Town(houses) are not included in the value. */ - static int32 GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius); + static int32 GetCargoProduction(TileIndex tile, CargoID cargo_type, int width, int height, int radius); /** * Get the manhattan distance from the tile to the tile.
--- a/src/ai/api/ai_tilelist.cpp +++ b/src/ai/api/ai_tilelist.cpp @@ -68,9 +68,9 @@ this->RemoveItem(tile); } -AITileList_IndustryAccepting::AITileList_IndustryAccepting(IndustryID industry_id, uint radius) +AITileList_IndustryAccepting::AITileList_IndustryAccepting(IndustryID industry_id, int radius) { - if (!AIIndustry::IsValidIndustry(industry_id)) return; + if (!AIIndustry::IsValidIndustry(industry_id) || radius <= 0) return; const Industry *i = ::Industry::Get(industry_id); @@ -106,9 +106,9 @@ } END_TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius)) } -AITileList_IndustryProducing::AITileList_IndustryProducing(IndustryID industry_id, uint radius) +AITileList_IndustryProducing::AITileList_IndustryProducing(IndustryID industry_id, int radius) { - if (!AIIndustry::IsValidIndustry(industry_id)) return; + if (!AIIndustry::IsValidIndustry(industry_id) || radius <= 0) return; const Industry *i = ::Industry::Get(industry_id);
--- a/src/ai/api/ai_tilelist.hpp +++ b/src/ai/api/ai_tilelist.hpp @@ -71,8 +71,10 @@ /** * @param industry_id The industry to create the AITileList around. * @param radius The radius of the station you will be using. + * @pre AIIndustry::IsValidIndustry(industry_id). + * @pre radius > 0. */ - AITileList_IndustryAccepting(IndustryID industry_id, uint radius); + AITileList_IndustryAccepting(IndustryID industry_id, int radius); }; /** @@ -87,8 +89,10 @@ /** * @param industry_id The industry to create the AITileList around. * @param radius The radius of the station you will be using. + * @pre AIIndustry::IsValidIndustry(industry_id). + * @pre radius > 0. */ - AITileList_IndustryProducing(IndustryID industry_id, uint radius); + AITileList_IndustryProducing(IndustryID industry_id, int radius); }; /**