From a1f28ec88bf3987236fb1b9df9c9dbe8c68419b7 Mon Sep 17 00:00:00 2001 From: yexo Date: Mon, 18 Jan 2010 14:32:47 +0000 Subject: [PATCH] (svn r18860) -Codechange: introduce a wrapper to get an hangar tile from a station --- src/ai/api/ai_airport.cpp | 2 +- src/ai/api/ai_depotlist.cpp | 2 +- src/ai/api/ai_order.cpp | 5 ++--- src/aircraft_cmd.cpp | 4 +--- src/station_base.h | 9 ++++++++- src/station_cmd.cpp | 4 ++-- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/ai/api/ai_airport.cpp b/src/ai/api/ai_airport.cpp index b966bc5421..ce30782cb7 100644 --- a/src/ai/api/ai_airport.cpp +++ b/src/ai/api/ai_airport.cpp @@ -109,7 +109,7 @@ if (st->owner != _current_company) return INVALID_TILE; if ((st->facilities & FACIL_AIRPORT) == 0) return INVALID_TILE; - return ::ToTileIndexDiff(st->GetAirportSpec()->depot_table[0]) + st->airport_tile; + return st->GetHangarTile(0); } /* static */ AIAirport::AirportType AIAirport::GetAirportType(TileIndex tile) diff --git a/src/ai/api/ai_depotlist.cpp b/src/ai/api/ai_depotlist.cpp index 1dc68fb7bc..a40c13a31d 100644 --- a/src/ai/api/ai_depotlist.cpp +++ b/src/ai/api/ai_depotlist.cpp @@ -31,7 +31,7 @@ AIDepotList::AIDepotList(AITile::TransportType transport_type) if (st->owner == ::_current_company) { const AirportSpec *as = st->GetAirportSpec(); for (uint i = 0; i < as->nof_depots; i++) { - this->AddItem(st->airport_tile + ToTileIndexDiff(as->depot_table[i])); + this->AddItem(st->GetHangarTile(i)); } } } diff --git a/src/ai/api/ai_order.cpp b/src/ai/api/ai_order.cpp index 9cde814d84..b6280be1fa 100644 --- a/src/ai/api/ai_order.cpp +++ b/src/ai/api/ai_order.cpp @@ -181,9 +181,8 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or if (v->type != VEH_AIRCRAFT) return ::Depot::Get(order->GetDestination())->xy; /* Aircraft's hangars are referenced by StationID, not DepotID */ const Station *st = ::Station::Get(order->GetDestination()); - const AirportSpec *as = st->GetAirportSpec(); - if (as == NULL || as->nof_depots == 0) return INVALID_TILE; - return st->airport_tile + ::ToTileIndexDiff(as->depot_table[0]); + if (st->GetAirportSpec()->nof_depots == 0) return INVALID_TILE; + return st->GetHangarTile(0); } case OT_GOTO_STATION: { diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 91e6fb88e5..719fc971d4 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -334,11 +334,9 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin * of all depots, it is simple */ for (uint i = 0;; i++) { const Station *st = Station::GetByTile(tile); - const AirportSpec *as = st->GetAirportSpec(); const AirportFTAClass *apc = st->Airport(); - assert(i != as->nof_depots); - if (st->airport_tile + ToTileIndexDiff(as->depot_table[i]) == tile) { + if (st->GetHangarTile(i) == tile) { assert(apc->layout[i].heading == HANGAR); v->pos = apc->layout[i].position; break; diff --git a/src/station_base.h b/src/station_base.h index def8c595d5..251902493f 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -121,11 +121,18 @@ public: return IsRailStationTile(tile) && GetStationIndex(tile) == this->index; } - /* virtual */ FORCEINLINE bool TileBelongsToAirport(TileIndex tile) const + FORCEINLINE bool TileBelongsToAirport(TileIndex tile) const { return IsAirportTile(tile) && GetStationIndex(tile) == this->index; } + FORCEINLINE TileIndex GetHangarTile(uint hangar_num) const + { + assert(this->airport_tile != INVALID_TILE); + assert(hangar_num < this->GetAirportSpec()->nof_depots); + return this->airport_tile + ToTileIndexDiff(this->GetAirportSpec()->depot_table[hangar_num]); + } + /* virtual */ uint32 GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const; /* virtual */ void GetTileArea(TileArea *ta, StationType type) const; diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 1e24a70fc0..e029573d6d 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -66,7 +66,7 @@ bool IsHangar(TileIndex t) const AirportSpec *as = st->GetAirportSpec(); for (uint i = 0; i < as->nof_depots; i++) { - if (st->airport_tile + ToTileIndexDiff(as->depot_table[i]) == t) return true; + if (st->GetHangarTile(i) == t) return true; } return false; @@ -2090,7 +2090,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags) if (flags & DC_EXEC) { for (uint i = 0; i < as->nof_depots; ++i) { DeleteWindowById( - WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(as->depot_table[i]) + WC_VEHICLE_DEPOT, st->GetHangarTile(i) ); }