summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-06-06 11:47:21 +0000
committerrubidium <rubidium@openttd.org>2009-06-06 11:47:21 +0000
commitec3ef70adb40d9ff371082a7360652d58e425284 (patch)
tree232721f0f75e9a1b9075d8d3721d7e775b0307fc
parent0b8ceb3007c018954203519b3768c45b3fa21920 (diff)
downloadopenttd-ec3ef70adb40d9ff371082a7360652d58e425284.tar.xz
(svn r16524) -Fix [FS#2963]: missing guards in the NoAI API making it possible to hit an assert in OpenTTD.
-rw-r--r--src/ai/api/ai_tile.cpp12
-rw-r--r--src/ai/api/ai_tile.hpp10
-rw-r--r--src/ai/api/ai_tilelist.cpp8
-rw-r--r--src/ai/api/ai_tilelist.hpp8
4 files changed, 24 insertions, 14 deletions
diff --git a/src/ai/api/ai_tile.cpp b/src/ai/api/ai_tile.cpp
index 70bb1fb83..df44cac66 100644
--- 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];
}
diff --git a/src/ai/api/ai_tile.hpp b/src/ai/api/ai_tile.hpp
index 1083c8aa1..965a829f6 100644
--- a/src/ai/api/ai_tile.hpp
+++ b/src/ai/api/ai_tile.hpp
@@ -303,9 +303,12 @@ public:
* @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 @@ public:
* @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.
diff --git a/src/ai/api/ai_tilelist.cpp b/src/ai/api/ai_tilelist.cpp
index 31ea81861..5d3039156 100644
--- a/src/ai/api/ai_tilelist.cpp
+++ b/src/ai/api/ai_tilelist.cpp
@@ -68,9 +68,9 @@ void AITileList::RemoveTile(TileIndex 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);
@@ -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))
}
-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);
diff --git a/src/ai/api/ai_tilelist.hpp b/src/ai/api/ai_tilelist.hpp
index f3d2f658d..085dc756a 100644
--- a/src/ai/api/ai_tilelist.hpp
+++ b/src/ai/api/ai_tilelist.hpp
@@ -71,8 +71,10 @@ public:
/**
* @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 @@ public:
/**
* @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);
};
/**