Codechange: Check airport layout would fit within map bounds before iterating tiles. (#7429)

This commit is contained in:
PeterN
2019-03-30 22:20:26 +00:00
committed by GitHub
parent 32fda83d39
commit e1069eee05
4 changed files with 25 additions and 1 deletions

View File

@@ -130,6 +130,24 @@ bool AirportSpec::IsAvailable() const
return _cur_year <= this->max_year;
}
/**
* 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.
*/