# HG changeset patch # User yexo # Date 1281010222 0 # Node ID b4b3c56d7c8223d044203431111c7ffbad5b3507 # Parent 642a03a3d91e8dc2517cd1e3302cbdd5e903a7ad (svn r20377) -Feature: [NewGRF] prop 0x0A tile layout for airports diff --git a/src/newgrf.cpp b/src/newgrf.cpp --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2779,6 +2779,80 @@ break; } + case 0x0A: { // Set airport layout + as->num_table = buf->ReadByte(); // Number of layaouts + as->rotation = MallocT(as->num_table); + uint32 defsize = buf->ReadDWord(); // Total size of the definition + AirportTileTable **tile_table = CallocT(as->num_table); // Table with tiles to compose the airport + AirportTileTable *att = CallocT(defsize); // Temporary array to read the tile layouts from the GRF + int size; + const AirportTileTable *copy_from; + try { + for (byte j = 0; j < as->num_table; j++) { + as->rotation[j] = (Direction)buf->ReadByte(); + for (int k = 0;; k++) { + att[k].ti.x = buf->ReadByte(); // Offsets from northermost tile + att[k].ti.y = buf->ReadByte(); + + if (att[k].ti.x == 0 && att[k].ti.y == 0x80) { + /* Not the same terminator. The one we are using is rather + x= -80, y = 0 . So, adjust it. */ + att[k].ti.x = -0x80; + att[k].ti.y = 0; + att[k].gfx = 0; + + size = k + 1; + copy_from = att; + break; + } + + att[k].gfx = buf->ReadByte(); + + if (att[k].gfx == 0xFE) { + /* Use a new tile from this GRF */ + int local_tile_id = buf->ReadWord(); + + /* Read the ID from the _airporttile_mngr. */ + uint16 tempid = _airporttile_mngr.GetID(local_tile_id, _cur_grffile->grfid); + + if (tempid == INVALID_AIRPORTTILE) { + grfmsg(2, "AirportChangeInfo: Attempt to use airport tile %u with airport id %u, not yet defined. Ignoring.", local_tile_id, airport + i); + } else { + /* Declared as been valid, can be used */ + att[k].gfx = tempid; + size = k + 1; + copy_from = att; + } + } else if (att[k].gfx == 0xFF) { + att[k].ti.x = (int8)GB(att[k].ti.x, 0, 8); + att[k].ti.y = (int8)GB(att[k].ti.y, 0, 8); + } + + if (as->rotation[j] == DIR_E || as->rotation[j] == DIR_W) { + as->size_x = max(as->size_x, att[k].ti.y + 1); + as->size_y = max(as->size_y, att[k].ti.x + 1); + } else { + as->size_x = max(as->size_x, att[k].ti.x + 1); + as->size_y = max(as->size_y, att[k].ti.y + 1); + } + } + tile_table[j] = CallocT(size); + memcpy(tile_table[j], copy_from, sizeof(*copy_from) * size); + } + /* Install final layout construction in the airport spec */ + as->table = tile_table; + free(att); + } catch (...) { + for (int i = 0; i < as->num_table; i++) { + free(tile_table[i]); + } + free(tile_table); + free(att); + throw; + } + break; + } + case 0x0C: as->min_year = buf->ReadWord(); as->max_year = buf->ReadWord();