1
0
Fork 0

(svn r16524) -Fix [FS#2963]: missing guards in the NoAI API making it possible to hit an assert in OpenTTD.

release/1.0
rubidium 2009-06-06 11:47:21 +00:00
parent 0b8ceb3007
commit ec3ef70adb
4 changed files with 24 additions and 14 deletions

View File

@ -175,21 +175,21 @@
return ::TrackStatusToTrackdirBits(::GetTileTrackStatus(tile, (::TransportType)transport_type, UINT32_MAX)) != TRACKDIR_BIT_NONE; 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; 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]; 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; 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]; return produced[cargo_type];
} }

View File

@ -303,9 +303,12 @@ public:
* @param height The height of the station. * @param height The height of the station.
* @param radius The radius of the station. * @param radius The radius of the station.
* @pre AIMap::IsValidTile(tile). * @pre AIMap::IsValidTile(tile).
* @pre width > 0.
* @pre height > 0.
* @pre radius > 0.
* @return Value below 8 means no acceptance; the more the better. * @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. * Checks how many tiles in the radius produces this cargo.
@ -317,10 +320,13 @@ public:
* @param height The height of the station. * @param height The height of the station.
* @param radius The radius of the station. * @param radius The radius of the station.
* @pre AIMap::IsValidTile(tile). * @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. * @return The tiles that produce this cargo within radius of the tile.
* @note Town(houses) are not included in the value. * @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. * Get the manhattan distance from the tile to the tile.

View File

@ -68,9 +68,9 @@ void AITileList::RemoveTile(TileIndex tile)
this->RemoveItem(tile); 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); const Industry *i = ::Industry::Get(industry_id);
@ -106,9 +106,9 @@ AITileList_IndustryAccepting::AITileList_IndustryAccepting(IndustryID industry_i
} END_TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius)) } 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); const Industry *i = ::Industry::Get(industry_id);

View File

@ -71,8 +71,10 @@ public:
/** /**
* @param industry_id The industry to create the AITileList around. * @param industry_id The industry to create the AITileList around.
* @param radius The radius of the station you will be using. * @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 @@ public:
/** /**
* @param industry_id The industry to create the AITileList around. * @param industry_id The industry to create the AITileList around.
* @param radius The radius of the station you will be using. * @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);
}; };
/** /**