From d2f9b87ccd370db55f360995609963b7c2d864df Mon Sep 17 00:00:00 2001 From: yexo Date: Thu, 5 Aug 2010 12:00:09 +0000 Subject: (svn r20366) -Codechange: store the rotation of the airport layout in the station struct and use it to rotate hangar tiles --- src/station_base.h | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'src/station_base.h') 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 @@ -81,6 +82,30 @@ struct Airport : public TileArea { return this->GetSpec()->nof_depots > 0; } + /** + * 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. @@ -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; } } -- cgit v1.2.3-54-g00ecf