(svn r22726) -Fix: AITile::GetCargoAcceptance, AITile::GetCargoProduction and AIRail::BuildNewGRFRailStation did not check the cargo argument for validity.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
frosch 13 years ago
parent ba7356b520
commit c76d1c54b7

@ -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));

@ -279,6 +279,7 @@ public:
* @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

@ -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];

@ -319,6 +319,7 @@ public:
* @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 @@ public:
* @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.

Loading…
Cancel
Save