1
0
Fork 0

(svn r2115) Spring cleaning, no functional changes

release/0.4.5
tron 2005-04-01 10:43:20 +00:00
parent 725060b353
commit 3d6d4b1bfd
1 changed files with 61 additions and 47 deletions

108
newgrf.c
View File

@ -1612,18 +1612,17 @@ static void SkipIf(byte *buf, int len)
condtype = buf[3]; condtype = buf[3];
if (condtype < 2) { if (condtype < 2) {
/* Always 1 for bit tests, the given value should /* Always 1 for bit tests, the given value should be ignored. */
* be ignored. */
paramsize = 1; paramsize = 1;
} }
buf += 4; buf += 4;
if (paramsize == 4) switch (paramsize) {
cond_val = grf_load_dword(&buf); case 4: cond_val = grf_load_dword(&buf); break;
else if (paramsize == 2) case 2: cond_val = grf_load_word(&buf); break;
cond_val = grf_load_word(&buf); case 1: cond_val = grf_load_byte(&buf); break;
else if (paramsize == 1) default: break;
cond_val = grf_load_byte(&buf); }
switch (param) { switch (param) {
case 0x83: /* current climate, 0=temp, 1=arctic, 2=trop, 3=toyland */ case 0x83: /* current climate, 0=temp, 1=arctic, 2=trop, 3=toyland */
@ -1640,10 +1639,7 @@ static void SkipIf(byte *buf, int len)
param_val = _opt.road_side << 4; param_val = _opt.road_side << 4;
break; break;
case 0x88: { /* see if specified GRFID is active */ case 0x88: { /* see if specified GRFID is active */
GRFFile *file; param_val = (GetFileByGRFID(cond_val) != NULL);
file = GetFileByGRFID(cond_val);
param_val = (file != NULL);
} break; } break;
case 0x8B: /* TTDPatch version */ case 0x8B: /* TTDPatch version */
param_val = 0xFFFF; param_val = 0xFFFF;
@ -2053,23 +2049,21 @@ void DecodeSpecialSprite(const char *filename, int num, int spriteid, int stage)
/* 0xd */ ParamSet, /* 0xd */ ParamSet,
/* 0xe */ GRFInhibit, /* 0xe */ GRFInhibit,
}; };
static int initialized; static bool initialized = false;
byte action; byte action;
byte *buf = malloc(num); byte *buf = malloc(num);
int i;
if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory"); if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
if (initialized == 0) { if (!initialized) {
InitializeGRFSpecial(); InitializeGRFSpecial();
initialized = 1; initialized = true;
} }
_cur_stage = stage; _cur_stage = stage;
_cur_spriteid = spriteid; _cur_spriteid = spriteid;
for (i = 0; i != num; i++) FioReadBlock(buf, num);
buf[i] = FioReadByte();
action = buf[0]; action = buf[0];
@ -2084,21 +2078,28 @@ void DecodeSpecialSprite(const char *filename, int num, int spriteid, int stage)
* --pasky */ * --pasky */
if (stage == 0) { if (stage == 0) {
/* During initialization, actions 0, 1, 2, 3, 4, 5 and 7 are ignored. */ switch (action) {
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x07:
/* During initialization, these actions are ignored. */
DEBUG (grf, 7) (
"DecodeSpecialSprite: Action: %x, Stage 0, Skipped", action);
break;
if ((action == 0x00) || (action == 0x01) || (action == 0x02) || (action == 0x03) default:
|| (action == 0x04) || (action == 0x05) || (action == 0x07)) { if (action < NUM_ACTIONS) {
DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 0, Skipped", action); DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 0", action);
/* Do nothing. */ handlers[action](buf, num);
} else {
} else if (action < NUM_ACTIONS) { grfmsg(GMS_WARN,
DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 0", action); "Unknown special sprite action %x, skipping.", action);
handlers[action](buf, num); }
} else {
grfmsg(GMS_WARN, "Unknown special sprite action %x, skipping.", action);
} }
} else if (stage == 1) { } else if (stage == 1) {
/* A .grf file is activated only if it was active when the game was /* A .grf file is activated only if it was active when the game was
* started. If a game is loaded, only its active .grfs will be * started. If a game is loaded, only its active .grfs will be
@ -2110,30 +2111,43 @@ void DecodeSpecialSprite(const char *filename, int num, int spriteid, int stage)
* carried out. All others are ignored, because they only need to be * carried out. All others are ignored, because they only need to be
* processed once at initialization. */ * processed once at initialization. */
if ((_cur_grffile == NULL) || strcmp(_cur_grffile->filename, filename)) if (_cur_grffile == NULL || strcmp(_cur_grffile->filename, filename) != 0)
_cur_grffile = GetFileByFilename(filename); _cur_grffile = GetFileByFilename(filename);
if (_cur_grffile == NULL) if (_cur_grffile == NULL)
error("File ``%s'' lost in cache.\n", filename); error("File ``%s'' lost in cache.\n", filename);
if (!(_cur_grffile->flags & 0x0001)) { if (_cur_grffile->flags & 0x0001) {
DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 1, Not activated", action); switch (action) {
/* Do nothing. */ case 0x00:
case 0x01:
} else if ((action == 0x00) || (action == 0x01) || (action == 0x02) || (action == 0x03) case 0x02:
|| (action == 0x04) || (action == 0x05) || (action == 0x07) || (action == 0x08) case 0x03:
|| (action == 0x09) || (action == 0x0A) || (action == 0x0B)) { case 0x04:
DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 1", action); case 0x05:
handlers[action](buf, num); case 0x07:
case 0x08:
} else if (action < NUM_ACTIONS) { case 0x09:
DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 1, Skipped", action); case 0x0A:
/* Do nothing. */ case 0x0B:
DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 1", action);
handlers[action](buf, num);
break;
default:
if (action < NUM_ACTIONS) {
DEBUG (grf, 7) (
"DecodeSpecialSprite: Action: %x, Stage 1, Skipped", action);
} else {
grfmsg(GMS_WARN,
"Unknown special sprite action %x, skipping.", action);
}
break;
}
} else { } else {
grfmsg(GMS_WARN, "Unknown special sprite action %x, skipping.", action); DEBUG (grf, 7) (
"DecodeSpecialSprite: Action: %x, Stage 1, Not activated", action);
} }
} else { } else {
error("Invalid stage %d", stage); error("Invalid stage %d", stage);
} }