(svn r19198) -Codechange: store the size of stations in savegames

This commit is contained in:
yexo 2010-02-22 14:17:07 +00:00
parent 7ca4c31cf5
commit 698737f485
12 changed files with 60 additions and 56 deletions

View File

@ -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;

View File

@ -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;
}
/**

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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 ),

View File

@ -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),

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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 */