diff options
author | yexo <yexo@openttd.org> | 2010-08-05 12:00:09 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2010-08-05 12:00:09 +0000 |
commit | d2f9b87ccd370db55f360995609963b7c2d864df (patch) | |
tree | 648158aa814a6329c6e8ff6f9602985e203996c5 /src/station_base.h | |
parent | 330c2f979e794f751ccd0ee05256f7b788f13091 (diff) | |
download | openttd-d2f9b87ccd370db55f360995609963b7c2d864df.tar.xz |
(svn r20366) -Codechange: store the rotation of the airport layout in the station struct and use it to rotate hangar tiles
Diffstat (limited to 'src/station_base.h')
-rw-r--r-- | src/station_base.h | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/src/station_base.h b/src/station_base.h index 5329a2642..997539943 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -49,9 +49,10 @@ struct GoodsEntry { struct Airport : public TileArea { Airport() : TileArea(INVALID_TILE, 0, 0) {} - uint64 flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32 - byte type; ///< Type of this airport, @see AirportTypes. - byte layout; ///< Airport layout number. + uint64 flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32 + byte type; ///< Type of this airport, @see AirportTypes. + byte layout; ///< Airport layout number. + Direction rotation; ///< How this airport is rotated. /** * Get the AirportSpec that from the airport type of this airport. If there @@ -82,6 +83,30 @@ struct Airport : public TileArea { } /** + * Add the tileoffset to the base tile of this airport but rotate it first. + * The base tile is the northernmost tile of this airport. This function + * helps to make sure that getting the tile of a hangar works even for + * rotated airport layouts without requiring a rotated array of hangar tiles. + * @param tidc The tilediff to add to the airport tile. + * @return The tile of this airport plus the rotated offset. + */ + FORCEINLINE TileIndex GetRotatedTileFromOffset(TileIndexDiffC tidc) const + { + const AirportSpec *as = this->GetSpec(); + switch (this->rotation) { + case DIR_N: return this->tile + ToTileIndexDiff(tidc); + + case DIR_E: return this->tile + TileDiffXY(tidc.y, as->size_x - 1 - tidc.x); + + case DIR_S: return this->tile + TileDiffXY(as->size_x - 1 - tidc.x, as->size_y - 1 - tidc.y); + + case DIR_W: return this->tile + TileDiffXY(as->size_y - 1 - tidc.y, tidc.x); + + default: NOT_REACHED(); + } + } + + /** * Get the first tile of the given hangar. * @param hangar_num The hangar to get the location of. * @pre hangar_num < GetNumHangars(). @@ -92,7 +117,7 @@ struct Airport : public TileArea { const AirportSpec *as = this->GetSpec(); for (uint i = 0; i < as->nof_depots; i++) { if (as->depot_table[i].hangar_num == hangar_num) { - return this->tile + ToTileIndexDiff(as->depot_table[i].ti); + return this->GetRotatedTileFromOffset(as->depot_table[i].ti); } } NOT_REACHED(); @@ -108,7 +133,7 @@ struct Airport : public TileArea { { const AirportSpec *as = this->GetSpec(); for (uint i = 0; i < as->nof_depots; i++) { - if (this->tile + ToTileIndexDiff(as->depot_table[i].ti) == tile) { + if (this->GetRotatedTileFromOffset(as->depot_table[i].ti) == tile) { return as->depot_table[i].hangar_num; } } |