Skip to content

Commit

Permalink
Fix: huge airports broke the appearance of airports in old savegames
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Apr 9, 2020
1 parent 78366d7 commit 03a16fa
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/airport.h
Expand Up @@ -21,7 +21,9 @@ static const uint MAX_ELEMENTS = 767; ///< maximum number
static const uint NUM_AIRPORTTILES_PER_GRF = 255; ///< Number of airport tiles per NewGRF; limited to 255 to allow extending Action3 with an extended byte later on.

static const uint NUM_AIRPORTTILES = 256; ///< Total number of airport tiles.
static const uint NEW_AIRPORTTILE_OFFSET = 96; ///< offset of first newgrf airport tile
static const uint NEW_AIRPORTTILE_OFFSET = 74; ///< offset of first newgrf airport tile
static const uint HUGE_AIRPORTTILE_OFFSET = 223; ///< offset of first huge airport tile

static const uint INVALID_AIRPORTTILE = NUM_AIRPORTTILES; ///< id for an invalid airport tile

/** Airport types */
Expand Down
4 changes: 2 additions & 2 deletions src/newgrf.cpp
Expand Up @@ -4687,7 +4687,7 @@ static ChangeInfoResult AirportTilesChangeInfo(uint airtid, int numinfo, int pro
AirportTileSpec **tilespec = &_cur.grffile->airtspec[airtid + i];
byte subs_id = buf->ReadByte();

if (subs_id >= NEW_AIRPORTTILE_OFFSET) {
if (subs_id >= NEW_AIRPORTTILE_OFFSET && subs_id < HUGE_AIRPORTTILE_OFFSET) {
/* The substitute id must be one of the original airport tiles. */
grfmsg(2, "AirportTileChangeInfo: Attempt to use new airport tile %u as substitute airport tile for %u. Ignoring.", subs_id, airtid + i);
continue;
Expand Down Expand Up @@ -4715,7 +4715,7 @@ static ChangeInfoResult AirportTilesChangeInfo(uint airtid, int numinfo, int pro
byte override = buf->ReadByte();

/* The airport tile being overridden must be an original airport tile. */
if (override >= NEW_AIRPORTTILE_OFFSET) {
if (override >= NEW_AIRPORTTILE_OFFSET && override < HUGE_AIRPORTTILE_OFFSET) {
grfmsg(2, "AirportTileChangeInfo: Attempt to override new airport tile %u with airport tile id %u. Ignoring.", override, airtid + i);
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion src/newgrf_airporttiles.cpp
Expand Up @@ -58,6 +58,7 @@ void AirportTileSpec::ResetAirportTiles()
{
memset(&AirportTileSpec::tiles, 0, sizeof(AirportTileSpec::tiles));
memcpy(&AirportTileSpec::tiles, &_origin_airporttile_specs, sizeof(_origin_airporttile_specs));
memcpy(&AirportTileSpec::tiles[HUGE_AIRPORTTILE_OFFSET], &_huge_airporttile_specs, sizeof(_huge_airporttile_specs));

/* Reset any overrides that have been set. */
_airporttile_mngr.ResetOverride();
Expand Down Expand Up @@ -132,7 +133,7 @@ static uint32 GetAirportTileIDAtOffset(TileIndex tile, const Station *st, uint32
StationGfx gfx = GetAirportGfx(tile);
const AirportTileSpec *ats = AirportTileSpec::Get(gfx);

if (gfx < NEW_AIRPORTTILE_OFFSET) { // Does it belongs to an old type?
if (gfx < NEW_AIRPORTTILE_OFFSET || gfx >= HUGE_AIRPORTTILE_OFFSET) { // Does it belongs to an old type?
/* It is an old tile. We have to see if it's been overridden */
if (ats->grf_prop.override == INVALID_AIRPORTTILE) { // has it been overridden?
return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile
Expand Down
15 changes: 15 additions & 0 deletions src/saveload/afterload.cpp
Expand Up @@ -893,6 +893,21 @@ bool AfterLoadGame()
st->airport.type = AT_CIRCLE;
}
}
if(SlXvIsFeaturePresent(XSLFI_HUGE_AIRPORTS, 1, 2)) {
for (Station *st : Station::Iterate()) {
if (st->airport.tile == INVALID_TILE) continue;
if (st->airport.type != AT_INTERCONTINENTAL2 && st->airport.type != AT_CIRCLE) continue;
const AirportSpec *as = AirportSpec::Get(st->airport.type);
/* Move airport sprites */
for (AirportTileTableIterator iter(as->table[st->airport.layout], st->airport.tile); iter != INVALID_TILE; ++iter) {
StationGfx gfx = GetStationGfx(iter);
if(gfx >= 74 && gfx < 96) {
SetStationGfx(iter, iter.GetStationGfx());
}
}
}
}

if (SlXvIsFeaturePresent(XSLFI_SPRINGPP)) {
/*
* Reject huge airports
Expand Down
2 changes: 1 addition & 1 deletion src/saveload/extended_ver_sl.cpp
Expand Up @@ -113,7 +113,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_FLOW_STAT_FLAGS, XSCF_NULL, 1, 1, "flow_stat_flags", nullptr, nullptr, nullptr },
{ XSLFI_SPEED_RESTRICTION, XSCF_NULL, 1, 1, "speed_restriction", nullptr, nullptr, "VESR" },
{ XSLFI_STATION_GOODS_EXTRA, XSCF_NULL, 1, 1, "station_goods_extra", nullptr, nullptr, nullptr },
{ XSLFI_HUGE_AIRPORTS, XSCF_NULL, 2, 2, "huge_airports", nullptr, nullptr, nullptr },
{ XSLFI_HUGE_AIRPORTS, XSCF_NULL, 3, 3, "huge_airports", nullptr, nullptr, nullptr },
{ XSLFI_TRIP_HISTORY, XSCF_NULL, 1, 1, "trip_history", nullptr, nullptr, nullptr },
{ XSLFI_PLANE_TAXI_SPEED, XSCF_NULL, 1, 1, "plane_taxi_speed", nullptr, nullptr, nullptr },
{ XSLFI_INDUSTRY_PRODUCTION_HISTORY, XSCF_NULL, 1, 1, "ind_prod_history", nullptr, nullptr, nullptr },
Expand Down
4 changes: 3 additions & 1 deletion src/station_cmd.cpp
Expand Up @@ -2988,6 +2988,8 @@ static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)

const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx)
{
if(st == STATION_AIRPORT && gfx >= HUGE_AIRPORTTILE_OFFSET)
return &_station_display_datas_huge_airport[gfx-HUGE_AIRPORTTILE_OFFSET];
return &_station_display_datas[st][gfx];
}

Expand Down Expand Up @@ -3103,7 +3105,7 @@ static void DrawTile_Station(TileInfo *ti, DrawTileProcParams params)
StationGfx gfx = GetStationGfx(ti->tile);
if (IsAirport(ti->tile)) {
gfx = GetAirportGfx(ti->tile);
if (gfx >= NEW_AIRPORTTILE_OFFSET) {
if (gfx >= NEW_AIRPORTTILE_OFFSET && gfx < HUGE_AIRPORTTILE_OFFSET) {
const AirportTileSpec *ats = AirportTileSpec::Get(gfx);
if (ats->grf_prop.spritegroup[0] != nullptr && DrawNewAirportTile(ti, Station::GetByTile(ti->tile), gfx, ats)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/table/airporttile_ids.h
Expand Up @@ -85,7 +85,7 @@ enum AirportTiles {
APT_APRON_HALF_EAST,
APT_APRON_HALF_WEST,
APT_GRASS_FENCE_NE_FLAG_2,
APT_NSRUNWAY_4,
APT_NSRUNWAY_4 = HUGE_AIRPORTTILE_OFFSET,
APT_NSRUNWAY_4_SW,
APT_NSRUNWAY_4_NE,
APT_NSRUNWAY_END_FENCE_SW,
Expand Down
3 changes: 3 additions & 0 deletions src/table/airporttiles.h
Expand Up @@ -102,6 +102,9 @@ static const AirportTileSpec _origin_airporttile_specs[] = {
AT_NOANIM,
AT_NOANIM,
AT(3, 1), // APT_GRASS_FENCE_NE_FLAG_2
};

static const AirportTileSpec _huge_airporttile_specs[] = {
AT_NOANIM,
AT_NOANIM,
AT_NOANIM,
Expand Down
16 changes: 15 additions & 1 deletion src/table/station_land.h
Expand Up @@ -915,7 +915,10 @@ static const DrawTileSprites _station_display_datas_airport[] = {
TILE_SPRITE_LINE(SPR_AIRPORT_APRON, _station_display_grass_west) // APT_APRON_HALF_EAST
TILE_SPRITE_LINE(SPR_AIRPORT_APRON, _station_display_grass_east) // APT_APRON_HALF_WEST
TILE_SPRITE_NULL() // APT_GRASS_FENCE_NE_FLAG_2,
TILE_SPRITE_LINE(SPR_NSRUNWAY4, _station_display_nothing) // APT_NSRUNWAY_4
};

static const DrawTileSprites _station_display_datas_huge_airport[] = {
TILE_SPRITE_LINE(SPR_NSRUNWAY4, _station_display_nothing) // APT_NSRUNWAY_4
TILE_SPRITE_LINE(SPR_NSRUNWAY4, _station_display_fence_sw) // APT_NSRUNWAY_4_SW
TILE_SPRITE_LINE(SPR_NSRUNWAY4, _station_display_fence_ne) // APT_NSRUNWAY_4_NE
TILE_SPRITE_LINE(SPR_NSRUNWAY_END, _station_display_fence_sw) // APT_NSRUNWAY_END_FENCE_SW
Expand All @@ -937,6 +940,17 @@ static const DrawTileSprites _station_display_datas_airport[] = {
TILE_SPRITE_LINE(SPR_NSRUNWAY_END, _station_display_fence_ne_nw) // APT_NSRUNWAY_END_NE_NW
TILE_SPRITE_LINE(SPR_NSRUNWAY_END, _station_display_fence_se_sw) // APT_NSRUNWAY_END_SE_SW
TILE_SPRITE_LINE(SPR_NSRUNWAY_END, _station_display_fence_nw_sw) // APT_NSRUNWAY_END_NW_SW
TILE_SPRITE_NULL()
TILE_SPRITE_NULL()
TILE_SPRITE_NULL()
TILE_SPRITE_NULL()
TILE_SPRITE_NULL()
TILE_SPRITE_NULL()
TILE_SPRITE_NULL()
TILE_SPRITE_NULL()
TILE_SPRITE_NULL()
TILE_SPRITE_NULL()
TILE_SPRITE_NULL()
};

static const DrawTileSprites _station_display_datas_airport_radar_grass_fence_sw[] = {
Expand Down

0 comments on commit 03a16fa

Please sign in to comment.