mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-16 00:42:45 +01:00
Codechange: Use vector for airport tile layouts. (#12607)
Simplify AirportSpec data by storing layout information together in a vector, instead of separate arrays. This removes manual memory management and separate count members. The default layouts will be copied instead of always referring to the originals.
This commit is contained in:
@@ -98,8 +98,8 @@ bool IsHangar(Tile t)
|
||||
const Station *st = Station::GetByTile(t);
|
||||
const AirportSpec *as = st->airport.GetSpec();
|
||||
|
||||
for (uint i = 0; i < as->nof_depots; i++) {
|
||||
if (st->airport.GetHangarTile(i) == TileIndex(t)) return true;
|
||||
for (const auto &depot : as->depots) {
|
||||
if (st->airport.GetRotatedTileFromOffset(depot.ti) == TileIndex(t)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -2414,10 +2414,10 @@ CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, uint8_t airport
|
||||
|
||||
/* Check if a valid, buildable airport was chosen for construction */
|
||||
const AirportSpec *as = AirportSpec::Get(airport_type);
|
||||
if (!as->IsAvailable() || layout >= as->num_table) return CMD_ERROR;
|
||||
if (!as->IsAvailable() || layout >= as->layouts.size()) return CMD_ERROR;
|
||||
if (!as->IsWithinMapBounds(layout, tile)) return CMD_ERROR;
|
||||
|
||||
Direction rotation = as->rotation[layout];
|
||||
Direction rotation = as->layouts[layout].rotation;
|
||||
int w = as->size_x;
|
||||
int h = as->size_y;
|
||||
if (rotation == DIR_E || rotation == DIR_W) Swap(w, h);
|
||||
@@ -2427,7 +2427,7 @@ CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, uint8_t airport
|
||||
return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
|
||||
}
|
||||
|
||||
AirportTileTableIterator tile_iter(as->table[layout], tile);
|
||||
AirportTileTableIterator tile_iter(as->layouts[layout].tiles.data(), tile);
|
||||
CommandCost cost = CheckFlatLandAirport(tile_iter, flags);
|
||||
if (cost.Failed()) return cost;
|
||||
|
||||
@@ -2477,7 +2477,7 @@ CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, uint8_t airport
|
||||
return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_AIRPORT);
|
||||
}
|
||||
|
||||
for (AirportTileTableIterator iter(as->table[layout], tile); iter != INVALID_TILE; ++iter) {
|
||||
for (AirportTileTableIterator iter(as->layouts[layout].tiles.data(), tile); iter != INVALID_TILE; ++iter) {
|
||||
cost.AddCost(_price[PR_BUILD_STATION_AIRPORT]);
|
||||
}
|
||||
|
||||
@@ -2493,7 +2493,7 @@ CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, uint8_t airport
|
||||
|
||||
st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY);
|
||||
|
||||
for (AirportTileTableIterator iter(as->table[layout], tile); iter != INVALID_TILE; ++iter) {
|
||||
for (AirportTileTableIterator iter(as->layouts[layout].tiles.data(), tile); iter != INVALID_TILE; ++iter) {
|
||||
Tile t(iter);
|
||||
MakeAirport(t, st->owner, st->index, iter.GetStationGfx(), WATER_CLASS_INVALID);
|
||||
SetStationTileRandomBits(t, GB(Random(), 0, 4));
|
||||
@@ -2503,7 +2503,7 @@ CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, uint8_t airport
|
||||
}
|
||||
|
||||
/* Only call the animation trigger after all tiles have been built */
|
||||
for (AirportTileTableIterator iter(as->table[layout], tile); iter != INVALID_TILE; ++iter) {
|
||||
for (AirportTileTableIterator iter(as->layouts[layout].tiles.data(), tile); iter != INVALID_TILE; ++iter) {
|
||||
AirportTileAnimationTrigger(st, iter, AAT_BUILT);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user