diff options
author | PeterN <peter@fuzzle.org> | 2019-03-30 22:20:26 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-30 22:20:26 +0000 |
commit | e1069eee05b648a64ff5dac3dd5701b01cfa2034 (patch) | |
tree | 019da19b2cc4b98fc7fb0f09e1738db17fe8a307 /src/newgrf_airport.cpp | |
parent | 32fda83d3916197a46215c83ddd85b2e50128a02 (diff) | |
download | openttd-e1069eee05b648a64ff5dac3dd5701b01cfa2034.tar.xz |
Codechange: Check airport layout would fit within map bounds before iterating tiles. (#7429)
Diffstat (limited to 'src/newgrf_airport.cpp')
-rw-r--r-- | src/newgrf_airport.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp index 46f15b0e1..615292aef 100644 --- a/src/newgrf_airport.cpp +++ b/src/newgrf_airport.cpp @@ -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() |