diff options
author | yexo <yexo@openttd.org> | 2010-08-05 12:10:22 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2010-08-05 12:10:22 +0000 |
commit | d00cf483233e93df234399270d3d8f50ad675fb9 (patch) | |
tree | 7f9c528fe0ca1eed4ef348fba55cd1b901f83d3c | |
parent | a3a24f4c689052f11c6f62922323017fe20928de (diff) | |
download | openttd-d00cf483233e93df234399270d3d8f50ad675fb9.tar.xz |
(svn r20377) -Feature: [NewGRF] prop 0x0A tile layout for airports
-rw-r--r-- | src/newgrf.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 94a2e56b8..ebb5ece3a 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2779,6 +2779,80 @@ static ChangeInfoResult AirportChangeInfo(uint airport, int numinfo, int prop, B break; } + case 0x0A: { // Set airport layout + as->num_table = buf->ReadByte(); // Number of layaouts + as->rotation = MallocT<Direction>(as->num_table); + uint32 defsize = buf->ReadDWord(); // Total size of the definition + AirportTileTable **tile_table = CallocT<AirportTileTable*>(as->num_table); // Table with tiles to compose the airport + AirportTileTable *att = CallocT<AirportTileTable>(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<byte>(as->size_x, att[k].ti.y + 1); + as->size_y = max<byte>(as->size_y, att[k].ti.x + 1); + } else { + as->size_x = max<byte>(as->size_x, att[k].ti.x + 1); + as->size_y = max<byte>(as->size_y, att[k].ti.y + 1); + } + } + tile_table[j] = CallocT<AirportTileTable>(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(); |