summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-02-22 14:17:07 +0000
committeryexo <yexo@openttd.org>2010-02-22 14:17:07 +0000
commit698737f485cfbdd1605faecd50395bb67f7dac75 (patch)
treeb79303520896365e70a9aa3224a5f1c6a14b5aba
parent7ca4c31cf558ff29b3cbe14cd348bcf649445dfc (diff)
downloadopenttd-698737f485cfbdd1605faecd50395bb67f7dac75.tar.xz
(svn r19198) -Codechange: store the size of stations in savegames
-rw-r--r--src/ai/api/ai_order.cpp7
-rw-r--r--src/aircraft_cmd.cpp18
-rw-r--r--src/disaster_cmd.cpp4
-rw-r--r--src/newgrf_airporttiles.cpp8
-rw-r--r--src/saveload/afterload.cpp12
-rw-r--r--src/saveload/oldloader_sl.cpp2
-rw-r--r--src/saveload/station_sl.cpp8
-rw-r--r--src/station.cpp6
-rw-r--r--src/station_base.h10
-rw-r--r--src/station_cmd.cpp32
-rw-r--r--src/town_gui.cpp2
-rw-r--r--src/water_cmd.cpp7
12 files changed, 60 insertions, 56 deletions
diff --git a/src/ai/api/ai_order.cpp b/src/ai/api/ai_order.cpp
index cdc56ccf8..71b111f8a 100644
--- a/src/ai/api/ai_order.cpp
+++ b/src/ai/api/ai_order.cpp
@@ -197,10 +197,9 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
return st->bus_stops->xy;
} else if (st->truck_stops != NULL) {
return st->truck_stops->xy;
- } else if (st->airport_tile != INVALID_TILE) {
- const AirportSpec *as = st->GetAirportSpec();
- TILE_LOOP(tile, as->size_x, as->size_y, st->airport_tile) {
- if (!::IsHangar(tile)) return tile;
+ } else if (st->airport.tile != INVALID_TILE) {
+ TILE_AREA_LOOP(tile, st->airport) {
+ if (st->TileBelongsToAirport(tile) && !::IsHangar(tile)) return tile;
}
}
return INVALID_TILE;
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index e5be7fe5b..395c6edcc 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -127,7 +127,7 @@ static StationID FindNearestHangar(const Aircraft *v)
}
/* v->tile can't be used here, when aircraft is flying v->tile is set to 0 */
- uint distance = DistanceSquare(vtile, st->airport_tile);
+ uint distance = DistanceSquare(vtile, st->airport.tile);
if (distance < best || index == INVALID_STATION) {
best = distance;
index = st->index;
@@ -806,7 +806,7 @@ static byte AircraftGetEntryPoint(const Aircraft *v, const AirportFTAClass *apc)
const Station *st = Station::GetIfValid(v->targetairport);
if (st != NULL) {
/* Make sure we don't go to INVALID_TILE if the airport has been removed. */
- tile = (st->airport_tile != INVALID_TILE) ? st->airport_tile : st->xy;
+ tile = (st->airport.tile != INVALID_TILE) ? st->airport.tile : st->xy;
}
int delta_x = v->x_pos - TileX(tile) * TILE_SIZE;
@@ -842,13 +842,13 @@ static bool AircraftController(Aircraft *v)
/* INVALID_TILE if there is no station */
TileIndex tile = INVALID_TILE;
if (st != NULL) {
- tile = (st->airport_tile != INVALID_TILE) ? st->airport_tile : st->xy;
+ tile = (st->airport.tile != INVALID_TILE) ? st->airport.tile : st->xy;
}
/* DUMMY if there is no station or no airport */
const AirportFTAClass *afc = tile == INVALID_TILE ? GetAirport(AT_DUMMY) : st->Airport();
/* prevent going to INVALID_TILE if airport is deleted. */
- if (st == NULL || st->airport_tile == INVALID_TILE) {
+ if (st == NULL || st->airport.tile == INVALID_TILE) {
/* Jump into our "holding pattern" state machine if possible */
if (v->pos >= afc->nofelements) {
v->pos = v->previous_pos = AircraftGetEntryPoint(v, afc);
@@ -988,8 +988,8 @@ static bool AircraftController(Aircraft *v)
v->y_pos + ((y + amd->y > v->y_pos) ? 1 : -1) :
v->y_pos;
- /* Oilrigs must keep v->tile as st->airport_tile, since the landing pad is in a non-airport tile */
- gp.new_tile = (st->airport_type == AT_OILRIG) ? st->airport_tile : TileVirtXY(gp.x, gp.y);
+ /* Oilrigs must keep v->tile as st->airport.tile, since the landing pad is in a non-airport tile */
+ gp.new_tile = (st->airport_type == AT_OILRIG) ? st->airport.tile : TileVirtXY(gp.x, gp.y);
} else {
@@ -1044,7 +1044,7 @@ static bool AircraftController(Aircraft *v)
if ((amd->flag & AMED_HOLD) && (z > 150)) z--;
if (amd->flag & AMED_LAND) {
- if (st->airport_tile == INVALID_TILE) {
+ if (st->airport.tile == INVALID_TILE) {
/* Airport has been removed, abort the landing procedure */
v->state = FLYING;
UpdateAircraftCache(v);
@@ -1526,7 +1526,7 @@ static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
/* runway busy or not allowed to use this airstation, circle */
if ((apc->flags & (v->subtype == AIR_HELICOPTER ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES)) &&
- st->airport_tile != INVALID_TILE &&
+ st->airport.tile != INVALID_TILE &&
(st->owner == OWNER_NONE || st->owner == v->owner)) {
/* {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41},
* if it is an airplane, look for LANDING, for helicopter HELILANDING
@@ -1964,7 +1964,7 @@ Station *GetTargetAirportIfValid(const Aircraft *v)
Station *st = Station::GetIfValid(v->targetairport);
if (st == NULL) return NULL;
- return st->airport_tile == INVALID_TILE ? NULL : st;
+ return st->airport.tile == INVALID_TILE ? NULL : st;
}
/**
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 142ec01d7..6ff1ed1ba 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -680,8 +680,8 @@ static void Disaster_Zeppeliner_Init()
Station *st;
FOR_ALL_STATIONS(st) {
- if (st->airport_tile != INVALID_TILE && (st->airport_type == AT_SMALL || st->airport_type == AT_LARGE)) {
- x = (TileX(st->airport_tile) + 2) * TILE_SIZE;
+ if (st->airport.tile != INVALID_TILE && (st->airport_type == AT_SMALL || st->airport_type == AT_LARGE)) {
+ x = (TileX(st->airport.tile) + 2) * TILE_SIZE;
break;
}
}
diff --git a/src/newgrf_airporttiles.cpp b/src/newgrf_airporttiles.cpp
index b190c043f..05e7951a4 100644
--- a/src/newgrf_airporttiles.cpp
+++ b/src/newgrf_airporttiles.cpp
@@ -180,7 +180,7 @@ static uint32 AirportTileGetVariable(const ResolverObject *object, byte variable
case 0x42: return GetTownRadiusGroup(ClosestTownFromTile(tile, UINT_MAX), tile);
/* Position relative to most northern airport tile. */
- case 0x43: return GetRelativePosition(tile, st->airport_tile);
+ case 0x43: return GetRelativePosition(tile, st->airport.tile);
/* Animation frame of tile */
case 0x44: return GetStationAnimationFrame(tile);
@@ -390,13 +390,11 @@ void AirportTileAnimationTrigger(Station *st, TileIndex tile, AirpAnimationTrigg
void AirportAnimationTrigger(Station *st, AirpAnimationTrigger trigger, CargoID cargo_type)
{
- if (st->airport_tile == INVALID_TILE) return;
+ if (st->airport.tile == INVALID_TILE) return;
const AirportSpec *as = st->GetAirportSpec();
- int w = as->size_x;
- int h = as->size_y;
- TILE_LOOP(tile, w, h, st->airport_tile) {
+ TILE_AREA_LOOP(tile, st->airport) {
if (st->TileBelongsToAirport(tile)) AirportTileAnimationTrigger(st, tile, trigger, cargo_type);
}
}
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index dfb379c11..f918e9972 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -525,7 +525,7 @@ bool AfterLoadGame()
/* no station is determined by 'tile == INVALID_TILE' now (instead of '0') */
Station *st;
FOR_ALL_STATIONS(st) {
- if (st->airport_tile == 0) st->airport_tile = INVALID_TILE;
+ if (st->airport.tile == 0) st->airport.tile = INVALID_TILE;
if (st->dock_tile == 0) st->dock_tile = INVALID_TILE;
if (st->train_station.tile == 0) st->train_station.tile = INVALID_TILE;
}
@@ -2063,6 +2063,16 @@ bool AfterLoadGame()
}
}
+ if (CheckSavegameVersion(139)) {
+ Station *st;
+ FOR_ALL_STATIONS(st) {
+ if (st->airport.tile != INVALID_TILE) {
+ st->airport.w = st->GetAirportSpec()->size_x;
+ st->airport.h = st->GetAirportSpec()->size_y;
+ }
+ }
+ }
+
/* Road stops is 'only' updating some caches */
AfterLoadRoadStops();
AfterLoadLabelMaps();
diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp
index d21a3975c..d358fc35e 100644
--- a/src/saveload/oldloader_sl.cpp
+++ b/src/saveload/oldloader_sl.cpp
@@ -712,7 +712,7 @@ static const OldChunks station_chunk[] = {
OCL_NULL( 4 ), ///< bus/lorry tile
OCL_SVAR( OC_TILE, Station, train_station.tile ),
- OCL_SVAR( OC_TILE, Station, airport_tile ),
+ OCL_SVAR( OC_TILE, Station, airport.tile ),
OCL_SVAR( OC_TILE, Station, dock_tile ),
OCL_SVAR( OC_UINT8, Station, train_station.w ),
diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp
index 99161ae1c..72f107eb8 100644
--- a/src/saveload/station_sl.cpp
+++ b/src/saveload/station_sl.cpp
@@ -151,8 +151,10 @@ static const SaveLoad _old_station_desc[] = {
SLE_CONDNULL(4, 0, 5), ///< bus/lorry tile
SLE_CONDVAR(Station, train_station.tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, train_station.tile, SLE_UINT32, 6, SL_MAX_VERSION),
- SLE_CONDVAR(Station, airport_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
- SLE_CONDVAR(Station, airport_tile, SLE_UINT32, 6, SL_MAX_VERSION),
+ SLE_CONDVAR(Station, airport.tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
+ SLE_CONDVAR(Station, airport.tile, SLE_UINT32, 6, SL_MAX_VERSION),
+ SLE_CONDVAR(Station, airport.w, SLE_UINT8, 139, SL_MAX_VERSION),
+ SLE_CONDVAR(Station, airport.h, SLE_UINT8, 139, SL_MAX_VERSION),
SLE_CONDVAR(Station, dock_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, dock_tile, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_REF(Station, town, REF_TOWN),
@@ -331,7 +333,7 @@ static const SaveLoad _station_desc[] = {
SLE_REF(Station, bus_stops, REF_ROADSTOPS),
SLE_REF(Station, truck_stops, REF_ROADSTOPS),
SLE_VAR(Station, dock_tile, SLE_UINT32),
- SLE_VAR(Station, airport_tile, SLE_UINT32),
+ SLE_VAR(Station, airport.tile, SLE_UINT32),
SLE_VAR(Station, airport_type, SLE_UINT8),
SLE_VAR(Station, airport_flags, SLE_UINT64),
diff --git a/src/station.cpp b/src/station.cpp
index fef63b305..039be313e 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -40,7 +40,7 @@ Station::Station(TileIndex tile) :
SpecializedStation<Station, false>(tile),
bus_station(INVALID_TILE, 0, 0),
truck_station(INVALID_TILE, 0, 0),
- airport_tile(INVALID_TILE),
+ airport(INVALID_TILE, 0, 0),
dock_tile(INVALID_TILE),
indtype(IT_INVALID),
time_since_load(255),
@@ -223,9 +223,9 @@ uint Station::GetCatchmentRadius() const
if (this->truck_stops != NULL) ret = max<uint>(ret, CA_TRUCK);
if (this->train_station.tile != INVALID_TILE) ret = max<uint>(ret, CA_TRAIN);
if (this->dock_tile != INVALID_TILE) ret = max<uint>(ret, CA_DOCK);
- if (this->airport_tile != INVALID_TILE) ret = max<uint>(ret, this->GetAirportSpec()->catchment);
+ if (this->airport.tile != INVALID_TILE) ret = max<uint>(ret, this->GetAirportSpec()->catchment);
} else {
- if (this->bus_stops != NULL || this->truck_stops != NULL || this->train_station.tile != INVALID_TILE || this->dock_tile != INVALID_TILE || this->airport_tile != INVALID_TILE) {
+ if (this->bus_stops != NULL || this->truck_stops != NULL || this->train_station.tile != INVALID_TILE || this->dock_tile != INVALID_TILE || this->airport.tile != INVALID_TILE) {
ret = CA_UNMODIFIED;
}
}
diff --git a/src/station_base.h b/src/station_base.h
index 251902493..222bb5893 100644
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -59,13 +59,13 @@ public:
const AirportFTAClass *Airport() const
{
- if (airport_tile == INVALID_TILE) return GetAirport(AT_DUMMY);
+ if (airport.tile == INVALID_TILE) return GetAirport(AT_DUMMY);
return GetAirport(airport_type);
}
const AirportSpec *GetAirportSpec() const
{
- if (airport_tile == INVALID_TILE) return &AirportSpec::dummy;
+ if (airport.tile == INVALID_TILE) return &AirportSpec::dummy;
return AirportSpec::Get(this->airport_type);
}
@@ -74,7 +74,7 @@ public:
RoadStop *truck_stops; ///< All the truck stops
TileArea truck_station; ///< Tile area the truck 'station' part covers
- TileIndex airport_tile; ///< The location of the airport
+ TileArea airport; ///< Tile area the airport covers
TileIndex dock_tile; ///< The location of the dock
IndustryType indtype; ///< Industry type to get the name from
@@ -128,9 +128,9 @@ public:
FORCEINLINE TileIndex GetHangarTile(uint hangar_num) const
{
- assert(this->airport_tile != INVALID_TILE);
+ assert(this->airport.tile != INVALID_TILE);
assert(hangar_num < this->GetAirportSpec()->nof_depots);
- return this->airport_tile + ToTileIndexDiff(this->GetAirportSpec()->depot_table[hangar_num]);
+ return this->airport.tile + ToTileIndexDiff(this->GetAirportSpec()->depot_table[hangar_num]);
}
/* virtual */ uint32 GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const;
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index e0f23202a..d3e033ccf 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -383,9 +383,7 @@ void Station::GetTileArea(TileArea *ta, StationType type) const
return;
case STATION_AIRPORT:
- ta->tile = this->airport_tile;
- ta->w = this->GetAirportSpec()->size_x;
- ta->h = this->GetAirportSpec()->size_y;
+ *ta = this->airport;
return;
case STATION_TRUCK:
@@ -1848,7 +1846,7 @@ CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
* Computes the minimal distance from town's xy to any airport's tile.
* @param as airport's description
* @param town_tile town's tile (t->xy)
- * @param airport_tile st->airport_tile
+ * @param airport_tile st->airport.tile
* @return minimal manhattan distance from town_tile to any airport's tile
*/
static uint GetMinimalAirportDistanceToTile(const AirportSpec *as, TileIndex town_tile, TileIndex airport_tile)
@@ -1906,7 +1904,7 @@ uint8 GetAirportNoiseLevelForTown(const AirportSpec *as, TileIndex town_tile, Ti
* Finds the town nearest to given airport. Based on minimal manhattan distance to any airport's tile.
* If two towns have the same distance, town with lower index is returned.
* @param as airport's description
- * @param airport_tile st->airport_tile
+ * @param airport_tile st->airport.tile
* @return nearest town to airport
*/
Town *AirportGetNearestTown(const AirportSpec *as, TileIndex airport_tile)
@@ -1937,10 +1935,10 @@ void UpdateAirportsNoise()
FOR_ALL_TOWNS(t) t->noise_reached = 0;
FOR_ALL_STATIONS(st) {
- if (st->airport_tile != INVALID_TILE) {
+ if (st->airport.tile != INVALID_TILE) {
const AirportSpec *as = st->GetAirportSpec();
- Town *nearest = AirportGetNearestTown(as, st->airport_tile);
- nearest->noise_reached += GetAirportNoiseLevelForTown(as, nearest->xy, st->airport_tile);
+ Town *nearest = AirportGetNearestTown(as, st->airport.tile);
+ nearest->noise_reached += GetAirportNoiseLevelForTown(as, nearest->xy, st->airport.tile);
}
}
}
@@ -2032,7 +2030,7 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (!st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TEST)) return CMD_ERROR;
- if (st->airport_tile != INVALID_TILE) {
+ if (st->airport.tile != INVALID_TILE) {
return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_AIRPORT);
}
} else {
@@ -2059,7 +2057,6 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
/* Always add the noise, so there will be no need to recalculate when option toggles */
nearest->noise_reached += newnoise_level;
- st->airport_tile = tile;
st->AddFacility(FACIL_AIRPORT, tile);
st->airport_type = (byte)p1;
st->airport_flags = 0;
@@ -2079,6 +2076,7 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
do {
TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
MakeAirport(cur_tile, st->owner, st->index, it->gfx);
+ st->airport.Add(cur_tile);
if (AirportTileSpec::Get(GetTranslatedAirportTileID(it->gfx))->animation_info != 0xFFFF) AddAnimatedTile(cur_tile);
} while ((++it)->ti.x != -0x80);
@@ -2119,7 +2117,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
return CMD_ERROR;
}
- tile = st->airport_tile;
+ tile = st->airport.tile;
const AirportSpec *as = st->GetAirportSpec();
int w = as->size_x;
@@ -2133,11 +2131,11 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
if (a->targetairport == st->index && a->state != FLYING) return CMD_ERROR;
}
- TILE_LOOP(tile_cur, w, h, tile) {
- if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
-
+ TILE_AREA_LOOP(tile_cur, st->airport) {
if (!st->TileBelongsToAirport(tile_cur)) continue;
+ if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
+
cost.AddCost(_price[PR_CLEAR_STATION_AIRPORT]);
if (flags & DC_EXEC) {
@@ -2161,7 +2159,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
st->rect.AfterRemoveRect(st, tile, w, h);
- st->airport_tile = INVALID_TILE;
+ st->airport.Clear();
st->facilities &= ~FACIL_AIRPORT;
SetWindowWidgetDirty(WC_STATION_VIEW, st->index, SVW_PLANES);
@@ -3206,7 +3204,7 @@ void BuildOilRig(TileIndex tile)
st->owner = OWNER_NONE;
st->airport_type = AT_OILRIG;
- st->airport_tile = tile;
+ st->airport.Add(tile);
st->dock_tile = tile;
st->facilities = FACIL_AIRPORT | FACIL_DOCK;
st->build_date = _date;
@@ -3234,7 +3232,7 @@ void DeleteOilRig(TileIndex tile)
MarkTileDirtyByTile(tile);
st->dock_tile = INVALID_TILE;
- st->airport_tile = INVALID_TILE;
+ st->airport.Clear();
st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK);
st->airport_flags = 0;
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index be4f3b3a8..56732d5d8 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -482,7 +482,7 @@ public:
/* Non-oil rig stations are always a problem. */
if (!(st->facilities & FACIL_AIRPORT) || st->airport_type != AT_OILRIG) return false;
/* We can only automatically delete oil rigs *if* there's no vehicle on them. */
- if (DoCommand(st->airport_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR).Failed()) return false;
+ if (DoCommand(st->airport.tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR).Failed()) return false;
}
}
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index 25d876792..5bcde05b2 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -728,11 +728,8 @@ static void FloodVehicles(TileIndex tile)
const Station *st = Station::GetByTile(tile);
const AirportSpec *as = st->GetAirportSpec();
z = 1 + st->Airport()->delta_z;
- for (uint x = 0; x < as->size_x; x++) {
- for (uint y = 0; y < as->size_y; y++) {
- tile = TILE_ADDXY(st->airport_tile, x, y);
- FindVehicleOnPos(tile, &z, &FloodVehicleProc);
- }
+ TILE_AREA_LOOP(tile, st->airport) {
+ if (st->TileBelongsToAirport(tile)) FindVehicleOnPos(tile, &z, &FloodVehicleProc);
}
/* No vehicle could be flooded on this airport anymore */