1
0
Fork 0

(svn r548) -newgrf: minor style changes, and application of boolean type

release/0.4.5
darkvater 2004-11-12 18:43:12 +00:00
parent fd80b53f39
commit a2869639b2
1 changed files with 131 additions and 193 deletions

View File

@ -87,9 +87,9 @@ static uint16 grf_load_dword(byte **buf)
} }
typedef int (*VCI_Handler)(uint engine, int numinfo, int prop, byte **buf, int len); typedef bool (*VCI_Handler)(uint engine, int numinfo, int prop, byte **buf, int len);
#define foreach_engine for (i = 0; i < numinfo; i++) #define FOR_EACH_ENGINE for (i = 0; i < numinfo; i++)
static void dewagonize(int condition, int engine) static void dewagonize(int condition, int engine)
{ {
@ -105,98 +105,83 @@ static void dewagonize(int condition, int engine)
} }
} }
static int RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len) static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
{ {
EngineInfo *ei = &_engine_info[engine]; EngineInfo *ei = &_engine_info[engine];
RailVehicleInfo *rvi = &_rail_vehicle_info[engine]; RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
byte *buf = *bufp; byte *buf = *bufp;
int i; int i;
int ret = 0; bool ret = false;
switch (prop) { switch (prop) {
case 0x05: case 0x05: { /* Track type */
{ /* Track type */ FOR_EACH_ENGINE {
foreach_engine {
uint8 tracktype = grf_load_byte(&buf); uint8 tracktype = grf_load_byte(&buf);
ei[i].railtype_climates &= 0xf; ei[i].railtype_climates &= 0xf;
ei[i].railtype_climates |= tracktype << 4; ei[i].railtype_climates |= tracktype << 4;
} }
break; } break;
} case 0x08: { /* AI passenger service */
case 0x08:
{ /* AI passenger service */
/* TODO */ /* TODO */
foreach_engine { FOR_EACH_ENGINE {
grf_load_byte(&buf); grf_load_byte(&buf);
} }
ret = 1; ret = true;
break; } break;
} case 0x09: { /* Speed */
case 0x09: FOR_EACH_ENGINE {
{ /* Speed */
foreach_engine {
uint16 speed = grf_load_word(&buf); uint16 speed = grf_load_word(&buf);
rvi[i].max_speed = speed; rvi[i].max_speed = speed;
dewagonize(speed, engine + i); dewagonize(speed, engine + i);
} }
break; } break;
} case 0x0B: { /* Power */
case 0x0b: FOR_EACH_ENGINE {
{ /* Power */
foreach_engine {
uint16 power = grf_load_word(&buf); uint16 power = grf_load_word(&buf);
rvi[i].power = power; rvi[i].power = power;
dewagonize(power, engine + i); dewagonize(power, engine + i);
} }
break; } break;
} case 0x0D: { /* Running cost factor */
case 0x0d: FOR_EACH_ENGINE {
{ /* Running cost factor */
foreach_engine {
uint8 runcostfact = grf_load_byte(&buf); uint8 runcostfact = grf_load_byte(&buf);
rvi[i].running_cost_base = runcostfact; rvi[i].running_cost_base = runcostfact;
dewagonize(runcostfact, engine + i); dewagonize(runcostfact, engine + i);
} }
break; } break;
} case 0x0E: { /* Running cost base */
case 0x0e: FOR_EACH_ENGINE {
{ /* Running cost base */
foreach_engine {
uint32 base = grf_load_dword(&buf); uint32 base = grf_load_dword(&buf);
switch (base) { switch (base) {
case 0x4c30: case 0x4C30:
rvi[i].engclass = 0; rvi[i].engclass = 0;
break; break;
case 0x4c36: case 0x4C36:
rvi[i].engclass = 1; rvi[i].engclass = 1;
break; break;
case 0x4c3c: case 0x4C3C:
rvi[i].engclass = 2; rvi[i].engclass = 2;
break; break;
} }
dewagonize(base, engine + i); dewagonize(base, engine + i);
} }
break; } break;
} case 0x12: { /* Sprite ID */
case 0x12: FOR_EACH_ENGINE {
{ /* Sprite ID */
foreach_engine {
uint8 spriteid = grf_load_byte(&buf); uint8 spriteid = grf_load_byte(&buf);
if (spriteid == 0xfd && rvi[i].image_index != 0xfd) if (spriteid == 0xFD && rvi[i].image_index != 0xFD)
_engine_original_sprites[engine + i] = rvi[i].image_index; _engine_original_sprites[engine + i] = rvi[i].image_index;
rvi[i].image_index = spriteid; rvi[i].image_index = spriteid;
} }
break; } break;
} case 0x13: { /* Dual-headed */
case 0x13: FOR_EACH_ENGINE {
{ /* Dual-headed */
foreach_engine {
uint8 dual = grf_load_byte(&buf); uint8 dual = grf_load_byte(&buf);
if (dual) { if (dual) {
@ -205,58 +190,46 @@ static int RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp
rvi[i].flags &= ~1; rvi[i].flags &= ~1;
} }
} }
break; } break;
} case 0x14: { /* Cargo capacity */
case 0x14: FOR_EACH_ENGINE {
{ /* Cargo capacity */
foreach_engine {
uint8 capacity = grf_load_byte(&buf); uint8 capacity = grf_load_byte(&buf);
rvi[i].capacity = capacity; rvi[i].capacity = capacity;
} }
break; } break;
} case 0x15: { /* Cargo type */
case 0x15: FOR_EACH_ENGINE {
{ /* Cargo type */
foreach_engine {
uint8 ctype = grf_load_byte(&buf); uint8 ctype = grf_load_byte(&buf);
rvi[i].cargo_type = ctype; rvi[i].cargo_type = ctype;
} }
break; } break;
} case 0x16: { /* Weight */
case 0x16: FOR_EACH_ENGINE {
{ /* Weight */
foreach_engine {
uint8 weight = grf_load_byte(&buf); uint8 weight = grf_load_byte(&buf);
rvi[i].weight = weight; rvi[i].weight = weight;
} }
break; } break;
} case 0x17: { /* Cost factor */
case 0x17: FOR_EACH_ENGINE {
{ /* Cost factor */
foreach_engine {
uint8 cfactor = grf_load_byte(&buf); uint8 cfactor = grf_load_byte(&buf);
rvi[i].base_cost = cfactor; rvi[i].base_cost = cfactor;
} }
break; } break;
} case 0x18: { /* AI rank */
case 0x18:
{ /* AI rank */
/* TODO: _railveh_score should be merged to _rail_vehicle_info. */ /* TODO: _railveh_score should be merged to _rail_vehicle_info. */
foreach_engine { FOR_EACH_ENGINE {
grf_load_byte(&buf); grf_load_byte(&buf);
} }
ret = 1; ret = true;
break; } break;
} case 0x19: { /* Engine traction type */
case 0x19:
{ /* Engine traction type */
/* TODO: What do the individual numbers mean? /* TODO: What do the individual numbers mean?
* XXX: And in what base are they, in fact? --pasky */ * XXX: And in what base are they, in fact? --pasky */
foreach_engine { FOR_EACH_ENGINE {
uint8 traction = grf_load_byte(&buf); uint8 traction = grf_load_byte(&buf);
int engclass; int engclass;
@ -271,100 +244,87 @@ static int RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp
rvi[i].engclass = engclass; rvi[i].engclass = engclass;
} }
break; } break;
}
/* TODO */ /* TODO */
/* Fall-through for unimplemented four bytes long properties. */ /* Fall-through for unimplemented four bytes long properties. */
case 0x1d: /* Refit cargo */ case 0x1D: /* Refit cargo */
foreach_engine { FOR_EACH_ENGINE {
grf_load_word(&buf); grf_load_word(&buf);
} }
/* Fall-through for unimplemented two bytes long properties. */ /* Fall-through for unimplemented two bytes long properties. */
case 0x1b: /* Powered wagons power bonus */ case 0x1B: /* Powered wagons power bonus */
foreach_engine { FOR_EACH_ENGINE {
grf_load_byte(&buf); grf_load_byte(&buf);
} }
/* Fall-through for unimplemented one byte long properties. */ /* Fall-through for unimplemented one byte long properties. */
case 0x1a: /* Sort order */ case 0x1A: /* Sort order */
case 0x1c: /* Refit cost */ case 0x1C: /* Refit cost */
case 0x1e: /* Callback */ case 0x1E: /* Callback */
case 0x1f: /* Tractive effort */ case 0x1F: /* Tractive effort */
case 0x21: /* Shorter tenders */ case 0x21: /* Shorter tenders */
case 0x22: /* Visual */ case 0x22: /* Visual */
case 0x23: /* Powered wagons weight bonus */ case 0x23: {/* Powered wagons weight bonus */
/* TODO */ /* TODO */
foreach_engine { FOR_EACH_ENGINE {
grf_load_byte(&buf); grf_load_byte(&buf);
} }
ret = 1; ret = true;
break; } break;
default: default:
ret = 1; ret = true;
break;
} }
*bufp = buf; *bufp = buf;
return ret; return ret;
} }
static int ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len) static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
{ {
ShipVehicleInfo *svi = &_ship_vehicle_info[engine]; ShipVehicleInfo *svi = &_ship_vehicle_info[engine];
byte *buf = *bufp; byte *buf = *bufp;
int i; int i;
int ret = 0; bool ret = false;
//printf("e %x prop %x?\n", engine, prop); //printf("e %x prop %x?\n", engine, prop);
switch (prop) { switch (prop) {
case 0x08: case 0x08: { /* Sprite ID */
{ /* Sprite ID */ FOR_EACH_ENGINE {
foreach_engine {
uint8 spriteid = grf_load_byte(&buf); uint8 spriteid = grf_load_byte(&buf);
if (spriteid == 0xff) if (spriteid == 0xFF)
spriteid = 0xfd; // ships have different custom id in the GRF file spriteid = 0xFD; // ships have different custom id in the GRF file
// This is currently not used but there's no reason // This is currently not used but there's no reason
// in not having it here for the future. // in not having it here for the future.
if (spriteid == 0xfd if (spriteid == 0xFD && svi[i].image_index != 0xFD)
&& svi[i].image_index != 0xfd) _engine_original_sprites[SHIP_ENGINES_INDEX + engine + i] = svi[i].image_index;
_engine_original_sprites[SHIP_ENGINES_INDEX
+ engine + i]
= svi[i].image_index;
svi[i].image_index = spriteid; svi[i].image_index = spriteid;
} }
break; } break;
} case 0x09: { /* Refittable */
case 0x09: FOR_EACH_ENGINE {
{ /* Refittable */
foreach_engine {
uint8 refittable = grf_load_byte(&buf); uint8 refittable = grf_load_byte(&buf);
svi[i].refittable = refittable; svi[i].refittable = refittable;
} }
break; } break;
} case 0x0A: { /* Cost factor */
case 0x0a: FOR_EACH_ENGINE {
{ /* Cost factor */
foreach_engine {
uint8 cost_factor = grf_load_byte(&buf); uint8 cost_factor = grf_load_byte(&buf);
svi[i].base_cost = cost_factor; // ?? is it base_cost? svi[i].base_cost = cost_factor; // ?? is it base_cost?
} }
break; } break;
} case 0x0B: { /* Speed */
case 0x0b: FOR_EACH_ENGINE {
{ /* Speed */
foreach_engine {
uint8 speed = grf_load_byte(&buf); uint8 speed = grf_load_byte(&buf);
svi[i].max_speed = speed; // ?? units svi[i].max_speed = speed; // ?? units
} }
break; } break;
} case 0x0C: { /* Cargo type */
case 0x0c: FOR_EACH_ENGINE {
{ /* Cargo type */
foreach_engine {
uint8 cargo = grf_load_byte(&buf); uint8 cargo = grf_load_byte(&buf);
// XXX: Need to consult this with patchman yet. // XXX: Need to consult this with patchman yet.
@ -376,53 +336,40 @@ static int ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp
#endif #endif
svi[i].cargo_type = cargo; svi[i].cargo_type = cargo;
} }
break; } break;
} case 0x0D: { /* Cargo capacity */
case 0x0d: FOR_EACH_ENGINE {
{ /* Cargo capacity */
foreach_engine {
uint16 capacity = grf_load_word(&buf); uint16 capacity = grf_load_word(&buf);
svi[i].capacity = capacity; svi[i].capacity = capacity;
} }
break; } break;
} case 0x0F: { /* Running cost factor */
case 0x0f: FOR_EACH_ENGINE {
{ /* Running cost factor */
foreach_engine {
uint8 runcost = grf_load_byte(&buf); uint8 runcost = grf_load_byte(&buf);
svi[i].running_cost = runcost; svi[i].running_cost = runcost;
} }
break; } break;
} case 0x10: { /* SFX */
case 0x10: FOR_EACH_ENGINE {
{ /* SFX */
foreach_engine {
uint8 sfx = grf_load_byte(&buf); uint8 sfx = grf_load_byte(&buf);
svi[i].sfx = sfx; svi[i].sfx = sfx;
} }
break; } break;
} case 0x11: { /* Cargos available for refitting */
case 0x11: FOR_EACH_ENGINE {
{ /* Cargos available for refitting */
foreach_engine {
uint32 refit_mask = grf_load_dword(&buf); uint32 refit_mask = grf_load_dword(&buf);
_engine_refit_masks[SHIP_ENGINES_INDEX + engine + i] = refit_mask; _engine_refit_masks[SHIP_ENGINES_INDEX + engine + i] = refit_mask;
} }
break; } break;
} case 0x12: { /* Callback TODO */
case 0x12: ret = true;
{ /* Callback */ } break;
/* TODO */
ret = 1;
break;
}
default: default:
ret = 1; ret = true;
break;
} }
*bufp = buf; *bufp = buf;
@ -457,6 +404,7 @@ static void VehicleChangeInfo(byte *buf, int len)
NULL, NULL,
NULL, NULL,
}; };
uint8 feature; uint8 feature;
uint8 numprops; uint8 numprops;
uint8 numinfo; uint8 numinfo;
@ -482,67 +430,56 @@ static void VehicleChangeInfo(byte *buf, int len)
uint8 prop = grf_load_byte(&buf); uint8 prop = grf_load_byte(&buf);
switch (prop) { switch (prop) {
case 0x00: { case 0x00: { /* Introduction date */
/* Introduction date */ FOR_EACH_ENGINE {
foreach_engine {
uint16 date = grf_load_word(&buf); uint16 date = grf_load_word(&buf);
ei[i].base_intro = date; ei[i].base_intro = date;
} }
break; } break;
} case 0x02: { /* Decay speed */
case 0x02: { FOR_EACH_ENGINE {
/* Decay speed */
foreach_engine {
uint8 decay = grf_load_byte(&buf); uint8 decay = grf_load_byte(&buf);
ei[i].unk2 &= 0x80; ei[i].unk2 &= 0x80;
ei[i].unk2 |= decay & 0x7f; ei[i].unk2 |= decay & 0x7f;
} }
break; } break;
} case 0x03: { /* Vehicle life */
case 0x03: { FOR_EACH_ENGINE {
/* Vehicle life */
foreach_engine {
uint8 life = grf_load_byte(&buf); uint8 life = grf_load_byte(&buf);
ei[i].lifelength = life; ei[i].lifelength = life;
} }
break; } break;
} case 0x04: { /* Model life */
case 0x04: { FOR_EACH_ENGINE {
/* Model life */
foreach_engine {
uint8 life = grf_load_byte(&buf); uint8 life = grf_load_byte(&buf);
ei[i].base_life = life; ei[i].base_life = life;
} }
break; } break;
} case 0x06: { /* Climates available */
case 0x06: { FOR_EACH_ENGINE {
/* Climates available */
foreach_engine {
uint8 climates = grf_load_byte(&buf); uint8 climates = grf_load_byte(&buf);
ei[i].railtype_climates &= 0xf0; ei[i].railtype_climates &= 0xf0;
ei[i].railtype_climates |= climates; ei[i].railtype_climates |= climates;
} }
break; } break;
} case 0x07: { /* Loading spee */
case 0x07: { /* TODO */ /* TODO */
/* Loading speed */
/* Hyronymus explained me what does /* Hyronymus explained me what does
* this mean and insists on having a * this mean and insists on having a
* credit ;-). --pasky */ * credit ;-). --pasky */
/* TODO: This needs to be supported by /* TODO: This needs to be supported by
* LoadUnloadVehicle() first. */ * LoadUnloadVehicle() first. */
foreach_engine { FOR_EACH_ENGINE {
grf_load_byte(&buf); grf_load_byte(&buf);
} }
goto ignoring; goto ignoring;
} }
default: default: {
{
if (handler[feature](engine, numinfo, prop, &buf, bufend - buf)) { if (handler[feature](engine, numinfo, prop, &buf, bufend - buf)) {
ignoring: ignoring:
grfmsg(GMS_NOTICE, "VehicleChangeInfo: Ignoring property %x (not implemented).", prop); grfmsg(GMS_NOTICE, "VehicleChangeInfo: Ignoring property %x (not implemented).", prop);
@ -750,7 +687,7 @@ static void VehicleMapSpriteSuperset(byte *buf, int len)
check_length(len, 7, "VehicleMapSpriteSuperset"); check_length(len, 7, "VehicleMapSpriteSuperset");
feature = buf[1]; feature = buf[1];
idcount = buf[2] & 0x7f; idcount = buf[2] & 0x7F;
wagover = buf[2] & 0x80; wagover = buf[2] & 0x80;
cidcount = buf[3 + idcount]; cidcount = buf[3 + idcount];
@ -786,7 +723,7 @@ static void VehicleMapSpriteSuperset(byte *buf, int len)
return; return;
} }
if (ctype == 0xff) if (ctype == 0xFF)
ctype = CID_PURCHASE; ctype = CID_PURCHASE;
if (wagover) { if (wagover) {
@ -926,7 +863,8 @@ static void SkipIf(byte *buf, int len)
uint8 paramsize; uint8 paramsize;
uint8 condtype; uint8 condtype;
uint8 numsprites; uint8 numsprites;
int param_val = 0, cond_val = 0, result; int param_val = 0, cond_val = 0;
bool result;
check_length(len, 6, "SkipIf"); check_length(len, 6, "SkipIf");
param = buf[1]; param = buf[1];
@ -982,7 +920,7 @@ static void SkipIf(byte *buf, int len)
return; return;
} }
if (result == 0) { if (!result) {
grfmsg(GMS_NOTICE, "Not skipping sprites, test was false."); grfmsg(GMS_NOTICE, "Not skipping sprites, test was false.");
return; return;
} }
@ -1065,7 +1003,7 @@ static void GRFError(byte *buf, int len)
severity = buf[1]; severity = buf[1];
msgid = buf[3]; msgid = buf[3];
if (msgid == 0xff) { if (msgid == 0xFF) {
grfmsg(severity, "%s", buf+4); grfmsg(severity, "%s", buf+4);
} else { } else {
grfmsg(severity, msgstr[msgid], buf+4); grfmsg(severity, msgstr[msgid], buf+4);
@ -1124,7 +1062,7 @@ static void GRFInhibit(byte *buf, int len)
void DecodeSpecialSprite(const char *filename, int num, int spriteid) void DecodeSpecialSprite(const char *filename, int num, int spriteid)
{ {
#define NUM_ACTIONS 0xf #define NUM_ACTIONS 0xF
static const SpecialSpriteHandler handlers[NUM_ACTIONS] = { static const SpecialSpriteHandler handlers[NUM_ACTIONS] = {
/* 0x0 */ VehicleChangeInfo, /* 0x0 */ VehicleChangeInfo,
/* 0x1 */ SpriteNewSet, /* 0x1 */ SpriteNewSet,