1
0
Fork 0

(svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)

release/0.4.5
tron 2005-09-13 09:23:23 +00:00
parent b84e36d717
commit 42813c5426
1 changed files with 67 additions and 56 deletions

123
newgrf.c
View File

@ -1053,70 +1053,81 @@ static void VehicleChangeInfo(byte *buf, int len)
while (numprops-- && buf < bufend) { while (numprops-- && buf < bufend) {
uint8 prop = grf_load_byte(&buf); uint8 prop = grf_load_byte(&buf);
bool ignoring = false;
if (feature == GSF_STATION) switch (feature) {
// stations don't share those common properties case GSF_TRAIN:
goto run_handler; case GSF_ROAD:
case GSF_SHIP:
case GSF_AIRCRAFT:
/* Common properties for vehicles */
switch (prop) {
case 0x00: { /* Introduction date */
FOR_EACH_OBJECT {
uint16 date = grf_load_word(&buf);
switch (prop) { ei[i].base_intro = date;
case 0x00: { /* Introduction date */ }
FOR_EACH_OBJECT { } break;
uint16 date = grf_load_word(&buf); case 0x02: { /* Decay speed */
FOR_EACH_OBJECT {
uint8 decay = grf_load_byte(&buf);
ei[i].base_intro = date; ei[i].unk2 &= 0x80;
} ei[i].unk2 |= decay & 0x7f;
} break; }
case 0x02: { /* Decay speed */ } break;
FOR_EACH_OBJECT { case 0x03: { /* Vehicle life */
uint8 decay = grf_load_byte(&buf); FOR_EACH_OBJECT {
uint8 life = grf_load_byte(&buf);
ei[i].unk2 &= 0x80; ei[i].lifelength = life;
ei[i].unk2 |= decay & 0x7f; }
} } break;
} break; case 0x04: { /* Model life */
case 0x03: { /* Vehicle life */ FOR_EACH_OBJECT {
FOR_EACH_OBJECT { uint8 life = grf_load_byte(&buf);
uint8 life = grf_load_byte(&buf);
ei[i].lifelength = life; ei[i].base_life = life;
} }
} break; } break;
case 0x04: { /* Model life */ case 0x06: { /* Climates available */
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
uint8 life = grf_load_byte(&buf); uint8 climates = grf_load_byte(&buf);
ei[i].base_life = life; ei[i].railtype_climates &= 0xf0;
} ei[i].railtype_climates |= climates;
} break; }
case 0x06: { /* Climates available */ } break;
FOR_EACH_OBJECT { case 0x07: { /* Loading speed */
uint8 climates = grf_load_byte(&buf); /* TODO */
/* Hyronymus explained me what does
* this mean and insists on having a
* credit ;-). --pasky */
/* TODO: This needs to be supported by
* LoadUnloadVehicle() first. */
FOR_EACH_OBJECT {
grf_load_byte(&buf);
}
ignoring = true;
break;
}
ei[i].railtype_climates &= 0xf0; default:
ei[i].railtype_climates |= climates; if (handler[feature](engine, numinfo, prop, &buf, bufend - buf))
} ignoring = true;
} break; break;
case 0x07: { /* Loading speed */ }
/* TODO */ break;
/* Hyronymus explained me what does
* this mean and insists on having a default:
* credit ;-). --pasky */ if (handler[feature](engine, numinfo, prop, &buf, bufend - buf))
/* TODO: This needs to be supported by ignoring = true;
* LoadUnloadVehicle() first. */ break;
FOR_EACH_OBJECT {
grf_load_byte(&buf);
}
goto ignoring;
}
default: {
run_handler:
if (handler[feature](engine, numinfo, prop, &buf, bufend - buf)) {
ignoring:
grfmsg(GMS_NOTICE, "VehicleChangeInfo: Ignoring property %x (not implemented).", prop);
}
break;
}
} }
if (ignoring)
grfmsg(GMS_NOTICE, "VehicleChangeInfo: Ignoring property %x (not implemented).", prop);
} }
} }