Changeset - r23570:fd1a0734432c
[Not reviewed]
master
0 4 0
PeterN - 6 years ago 2019-03-30 22:20:26
peter@fuzzle.org
Codechange: Check airport layout would fit within map bounds before iterating tiles. (#7429)
4 files changed with 25 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/newgrf_airport.cpp
Show inline comments
 
@@ -131,6 +131,24 @@ bool AirportSpec::IsAvailable() const
 
}
 

	
 
/**
 
 * Check if the airport would be within the map bounds at the given tile.
 
 * @param table Selected layout table. This affects airport rotation, and therefore dimenions.
 
 * @param tile Top corner of the airport.
 
 * @return true iff the airport would be within the map bounds at the given tile.
 
 */
 
bool AirportSpec::IsWithinMapBounds(byte table, TileIndex tile) const
 
{
 
	if (table >= this->num_table) return false;
 

	
 
	byte w = this->size_x;
 
	byte h = this->size_y;
 
	if (this->rotation[table] == DIR_E || this->rotation[table] == DIR_W) Swap(w, h);
 

	
 
	return TileX(tile) + w < MapSizeX() &&
 
		TileY(tile) + h < MapSizeY();
 
}
 

	
 
/**
 
 * This function initializes the airportspec array.
 
 */
 
void AirportSpec::ResetAirports()
src/newgrf_airport.h
Show inline comments
 
@@ -123,6 +123,7 @@ struct AirportSpec {
 
	static AirportSpec *GetWithoutOverride(byte type);
 

	
 
	bool IsAvailable() const;
 
	bool IsWithinMapBounds(byte table, TileIndex index) const;
 

	
 
	static void ResetAirports();
 

	
src/script/api/script_airport.cpp
Show inline comments
 
@@ -136,8 +136,10 @@
 
	if (!::IsValidTile(tile)) return -1;
 
	if (!IsAirportInformationAvailable(type)) return -1;
 

	
 
	const AirportSpec *as = ::AirportSpec::Get(type);
 
	if (!as->IsWithinMapBounds(0, tile)) return -1;
 

	
 
	if (_settings_game.economy.station_noise_level) {
 
		const AirportSpec *as = ::AirportSpec::Get(type);
 
		AirportTileTableIterator it(as->table[0], tile);
 
		uint dist;
 
		AirportGetNearestTown(as, it, dist);
 
@@ -155,6 +157,8 @@
 
	if (!IsAirportInformationAvailable(type)) return INVALID_TOWN;
 

	
 
	const AirportSpec *as = AirportSpec::Get(type);
 
	if (!as->IsWithinMapBounds(0, tile)) return INVALID_TOWN;
 

	
 
	uint dist;
 
	return AirportGetNearestTown(as, AirportTileTableIterator(as->table[0], tile), dist)->index;
 
}
src/station_cmd.cpp
Show inline comments
 
@@ -2268,6 +2268,7 @@ CommandCost CmdBuildAirport(TileIndex ti
 
	/* Check if a valid, buildable airport was chosen for construction */
 
	const AirportSpec *as = AirportSpec::Get(airport_type);
 
	if (!as->IsAvailable() || layout >= as->num_table) return CMD_ERROR;
 
	if (!as->IsWithinMapBounds(layout, tile)) return CMD_ERROR;
 

	
 
	Direction rotation = as->rotation[layout];
 
	int w = as->size_x;
0 comments (0 inline, 0 general)