changeset 15711:b4b3c56d7c82 draft

(svn r20377) -Feature: [NewGRF] prop 0x0A tile layout for airports
author yexo <yexo@openttd.org>
date Thu, 05 Aug 2010 12:10:22 +0000
parents 642a03a3d91e
children 7502e804286a
files src/newgrf.cpp
diffstat 1 files changed, 74 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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<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();