1
0
Fork 0

(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.

release/0.5
peter1138 2006-12-04 13:45:20 +00:00
parent 05559bcdcd
commit 11474c26d7
4 changed files with 53 additions and 24 deletions

View File

@ -2385,28 +2385,43 @@ static void SkipIf(byte *buf, int len)
break; break;
case 5: result = (param_val > cond_val); case 5: result = (param_val > cond_val);
break; break;
/* Tests 6 to 10 are only for param 0x88, GRFID checks */ /* Tests 6 to 10 are only for param 0x88, GRFID checks */
case 6: /* Is GRFID active? */ case 6: { /* Is GRFID active? */
case 9: /* GRFID is or will be active? */ const GRFConfig *c = GetGRFConfig(cond_val);
result = (GetFileByGRFID(cond_val)->flags & 1) == 1; if (c == NULL) return;
break; result = HASBIT(c->flags, GCF_ACTIVATED);
case 7: /* Is GRFID non-active? */
case 10: /* GRFID is not nor will be active */
result = (GetFileByGRFID(cond_val)->flags & 1) == 0;
break;
case 8: /* GRFID is not but will be active? */
result = 0;
if ((GetFileByGRFID(cond_val)->flags & 1) == 1) {
const GRFFile *file;
for (file = _first_grffile; file != NULL; file = file->next) {
if (file->grfid == cond_val) break;
if (file == _cur_grffile) {
result = 1;
break; break;
} }
}
} case 7: { /* Is GRFID non-active? */
const GRFConfig *c = GetGRFConfig(cond_val);
if (c == NULL) return;
result = !HASBIT(c->flags, GCF_ACTIVATED);
break; break;
}
case 8: { /* GRFID is not but will be active? */
const GRFConfig *c = GetGRFConfig(cond_val);
if (c == NULL) return;
result = !HASBIT(c->flags, GCF_ACTIVATED) && !HASBIT(c->flags, GCF_DISABLED);
break;
}
case 9: { /* GRFID is or will be active? */
const GRFConfig *c = GetGRFConfig(cond_val);
if (c == NULL) return;
result = !HASBIT(c->flags, GCF_NOT_FOUND) && !HASBIT(c->flags, GCF_DISABLED);
break;
}
case 10: { /* GRFID is not nor will be active */
const GRFConfig *c = GetGRFConfig(cond_val);
/* This is the only condtype that doesn't get ignored if the GRFID is not found */
result = c == NULL || HASBIT(c->flags, GCF_DISABLED) || HASBIT(c->flags, GCF_NOT_FOUND);
break;
}
default: default:
grfmsg(GMS_WARN, "Unsupported test %d. Ignoring.", condtype); grfmsg(GMS_WARN, "Unsupported test %d. Ignoring.", condtype);
return; return;
@ -2496,7 +2511,7 @@ static void GRFInfo(byte *buf, int len)
_cur_grffile->grfid = grfid; _cur_grffile->grfid = grfid;
_cur_grffile->grf_version = version; _cur_grffile->grf_version = version;
_cur_grffile->flags |= 0x0001; /* set active flag */ SETBIT(_cur_grfconfig->flags, GCF_ACTIVATED);
/* Do swap the GRFID for displaying purposes since people expect that */ /* Do swap the GRFID for displaying purposes since people expect that */
DEBUG(grf, 1) ("[%s] Loaded GRFv%d set %08lx - %s:\n%s", DEBUG(grf, 1) ("[%s] Loaded GRFv%d set %08lx - %s:\n%s",
@ -2712,8 +2727,8 @@ static void ParamSet(byte *buf, int len)
if (op != 4 && op != 5) { if (op != 4 && op != 5) {
/* Deactivate GRF */ /* Deactivate GRF */
grfmsg(GMS_FATAL, "GRM: Unable to allocate %d vehicles, deactivating", count); grfmsg(GMS_FATAL, "GRM: Unable to allocate %d vehicles, deactivating", count);
SETBIT(_cur_grffile->flags, 2); SETBIT(_cur_grfconfig->flags, GCF_DISABLED);
CLRBIT(_cur_grffile->flags, 1); CLRBIT(_cur_grfconfig->flags, GCF_ACTIVATED);
_skip_sprites = -1; _skip_sprites = -1;
return; return;
@ -2912,7 +2927,8 @@ static void GRFInhibit(byte *buf, int len)
/* Unset activation flag */ /* Unset activation flag */
if (file != NULL) { if (file != NULL) {
grfmsg(GMS_NOTICE, "GRFInhibit: Deactivating file ``%s''", file->filename); grfmsg(GMS_NOTICE, "GRFInhibit: Deactivating file ``%s''", file->filename);
file->flags &= 0xFFFE; SETBIT(_cur_grfconfig->flags, GCF_DISABLED);
CLRBIT(_cur_grfconfig->flags, GCF_ACTIVATED);
} }
} }
} }
@ -3560,7 +3576,7 @@ void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage)
if (stage != GLS_FILESCAN && stage != GLS_LABELSCAN) { if (stage != GLS_FILESCAN && stage != GLS_LABELSCAN) {
_cur_grffile = GetFileByFilename(filename); _cur_grffile = GetFileByFilename(filename);
if (_cur_grffile == NULL) error("File ``%s'' lost in cache.\n", filename); if (_cur_grffile == NULL) error("File ``%s'' lost in cache.\n", filename);
if (stage == GLS_ACTIVATION && !(_cur_grffile->flags & 0x0001)) return; if (stage == GLS_ACTIVATION && !HASBIT(config->flags, GCF_ACTIVATED)) return;
} }
FioOpenFile(file_index, filename); FioOpenFile(file_index, filename);

View File

@ -24,7 +24,6 @@ typedef struct GRFLabel {
typedef struct GRFFile { typedef struct GRFFile {
char *filename; char *filename;
uint32 grfid; uint32 grfid;
uint16 flags;
uint16 sprite_offset; uint16 sprite_offset;
byte grf_version; byte grf_version;
struct GRFFile *next; struct GRFFile *next;

View File

@ -248,6 +248,19 @@ const GRFConfig *FindGRFConfig(uint32 grfid, uint8 *md5sum)
} }
/* Retrieve a NewGRF from the current config by its grfid */
const GRFConfig *GetGRFConfig(uint32 grfid)
{
GRFConfig *c;
for (c = _grfconfig; c != NULL; c = c->next) {
if (c->grfid == grfid) return c;
}
return NULL;
}
static const SaveLoad _grfconfig_desc[] = { static const SaveLoad _grfconfig_desc[] = {
SLE_STR(GRFConfig, filename, SLE_STR, 0x40), SLE_STR(GRFConfig, filename, SLE_STR, 0x40),
SLE_VAR(GRFConfig, grfid, SLE_UINT32), SLE_VAR(GRFConfig, grfid, SLE_UINT32),

View File

@ -35,6 +35,7 @@ extern GRFConfig *_grfconfig_newgame;
void ScanNewGRFFiles(void); void ScanNewGRFFiles(void);
const GRFConfig *FindGRFConfig(uint32 grfid, uint8 *md5sum); const GRFConfig *FindGRFConfig(uint32 grfid, uint8 *md5sum);
const GRFConfig *GetGRFConfig(uint32 grfid);
void ClearGRFConfigList(GRFConfig *config); void ClearGRFConfigList(GRFConfig *config);
void ResetGRFConfig(bool defaults); void ResetGRFConfig(bool defaults);
bool IsGoodGRFConfigList(void); bool IsGoodGRFConfigList(void);