changeset 17921:b7b66cf219d3 draft

(svn r22726) -Fix: AITile::GetCargoAcceptance, AITile::GetCargoProduction and AIRail::BuildNewGRFRailStation did not check the cargo argument for validity.
author frosch <frosch@openttd.org>
date Sat, 06 Aug 2011 17:20:21 +0000
parents e6f389ce78a7
children ac620fe8d4db
files src/ai/api/ai_rail.cpp src/ai/api/ai_rail.hpp src/ai/api/ai_tile.cpp src/ai/api/ai_tile.hpp
diffstat 4 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/ai/api/ai_rail.cpp
+++ b/src/ai/api/ai_rail.cpp
@@ -14,6 +14,7 @@
 #include "ai_map.hpp"
 #include "ai_station.hpp"
 #include "ai_industrytype.hpp"
+#include "ai_cargo.hpp"
 #include "../../debug.h"
 #include "../../station_base.h"
 #include "../../company_func.h"
@@ -170,6 +171,7 @@
 	EnforcePrecondition(false, platform_length > 0 && platform_length <= 0xFF);
 	EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
 	EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id));
+	EnforcePrecondition(false, AICargo::IsValidCargo(cargo_id));
 	EnforcePrecondition(false, source_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(source_industry));
 	EnforcePrecondition(false, goal_industry   == AIIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry   == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(goal_industry));
 
--- a/src/ai/api/ai_rail.hpp
+++ b/src/ai/api/ai_rail.hpp
@@ -279,6 +279,7 @@
 	 * @pre num_platforms > 0 && num_platforms <= 255.
 	 * @pre platform_length > 0 && platform_length <= 255.
 	 * @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id).
+	 * @pre AICargo::IsValidCargo(cargo_type)
 	 * @pre source_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(source_industry).
 	 * @pre goal_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(goal_industry).
 	 * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
--- a/src/ai/api/ai_tile.cpp
+++ b/src/ai/api/ai_tile.cpp
@@ -13,6 +13,7 @@
 #include "ai_tile.hpp"
 #include "ai_map.hpp"
 #include "ai_town.hpp"
+#include "ai_cargo.hpp"
 #include "../../station_func.h"
 #include "../../company_func.h"
 #include "../../water_map.h"
@@ -192,7 +193,7 @@
 
 /* static */ int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, int width, int height, int radius)
 {
-	if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0) return -1;
+	if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !AICargo::IsValidCargo(cargo_type)) return -1;
 
 	CargoArray acceptance = ::GetAcceptanceAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED);
 	return acceptance[cargo_type];
@@ -200,7 +201,7 @@
 
 /* static */ int32 AITile::GetCargoProduction(TileIndex tile, CargoID cargo_type, int width, int height, int radius)
 {
-	if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0) return -1;
+	if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !AICargo::IsValidCargo(cargo_type)) return -1;
 
 	CargoArray produced = ::GetProductionAroundTiles(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
@@ -319,6 +319,7 @@
 	 * @param height The height of the station.
 	 * @param radius The radius of the station.
 	 * @pre AIMap::IsValidTile(tile).
+	 * @pre AICargo::IsValidCargo(cargo_type)
 	 * @pre width > 0.
 	 * @pre height > 0.
 	 * @pre radius >= 0.
@@ -335,6 +336,7 @@
 	 * @param height The height of the station.
 	 * @param radius The radius of the station.
 	 * @pre AIMap::IsValidTile(tile).
+	 * @pre AICargo::IsValidCargo(cargo_type)
 	 * @pre width > 0.
 	 * @pre height > 0.
 	 * @pre radius >= 0.