diff options
author | maedhros <maedhros@openttd.org> | 2007-03-06 19:33:28 +0000 |
---|---|---|
committer | maedhros <maedhros@openttd.org> | 2007-03-06 19:33:28 +0000 |
commit | b838a906572d85369356d521ca292ce762bc86a1 (patch) | |
tree | dd3c567c0980606c17509a28df3ceea5975adb03 | |
parent | c59146a710a4f61bb1de015407264288ba808e24 (diff) | |
download | openttd-b838a906572d85369356d521ca292ce762bc86a1.tar.xz |
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
mutually exclusive. At the same time, add an INITIALISED state which makes it
possible to check if a grf is not yet active but will be later on during the
GLS_ACTIVATION loading stage.
-rw-r--r-- | src/network/network_udp.cpp | 6 | ||||
-rw-r--r-- | src/newgrf.cpp | 32 | ||||
-rw-r--r-- | src/newgrf_config.cpp | 18 | ||||
-rw-r--r-- | src/newgrf_config.h | 20 | ||||
-rw-r--r-- | src/newgrf_gui.cpp | 25 | ||||
-rw-r--r-- | src/openttd.cpp | 8 | ||||
-rw-r--r-- | src/settings.cpp | 2 |
7 files changed, 62 insertions, 49 deletions
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp index 4dab77b8b..08d207d8b 100644 --- a/src/network/network_udp.cpp +++ b/src/network/network_udp.cpp @@ -288,8 +288,8 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_RESPONSE) struct sockaddr_in out_addr; for (c = item->info.grfconfig; c != NULL; c = c->next) { - if (HASBIT(c->flags, GCF_NOT_FOUND)) item->info.compatible = false; - if (!HASBIT(c->flags, GCF_NOT_FOUND) || strcmp(c->name, UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue; + if (c->status == GCS_NOT_FOUND) item->info.compatible = false; + if (c->status == GCS_NOT_FOUND || strcmp(c->name, UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue; in_request[in_request_count] = c; in_request_count++; } @@ -392,7 +392,7 @@ void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFCo * already resolved name for this GRF (another server has sent the * name of the GRF already */ config->name = FindUnknownGRFName(config->grfid, config->md5sum, true); - SETBIT(config->flags, GCF_NOT_FOUND); + config->status = GCS_NOT_FOUND; } else { config->filename = f->filename; config->name = f->name; diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 07c51791f..fa217f476 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2535,24 +2535,24 @@ static void SkipIf(byte *buf, int len) switch (condtype) { /* Tests 6 to 10 are only for param 0x88, GRFID checks */ case 6: /* Is GRFID active? */ - result = HASBIT(c->flags, GCF_ACTIVATED); + result = c->status == GCS_ACTIVATED; break; case 7: /* Is GRFID non-active? */ - result = !HASBIT(c->flags, GCF_ACTIVATED); + result = c->status != GCS_ACTIVATED; break; case 8: /* GRFID is not but will be active? */ - result = !HASBIT(c->flags, GCF_ACTIVATED) && !HASBIT(c->flags, GCF_DISABLED); + result = c->status == GCS_INITIALISED; break; case 9: /* GRFID is or will be active? */ - result = !HASBIT(c->flags, GCF_NOT_FOUND) && !HASBIT(c->flags, GCF_DISABLED); + result = c->status == GCS_ACTIVATED || c->status == GCS_INITIALISED; break; case 10: /* GRFID is not nor will be active */ /* 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); + result = c == NULL || c->flags == GCS_DISABLED || c->status == GCS_NOT_FOUND; break; default: grfmsg(1, "Unsupported GRF test %d. Ignoring", condtype); return; @@ -2616,7 +2616,7 @@ static void SkipIf(byte *buf, int len) _skip_sprites = -1; /* If an action 8 hasn't been encountered yet, disable the grf. */ - if (!HASBIT(_cur_grfconfig->flags, GCF_ACTIVATED)) SETBIT(_cur_grfconfig->flags, GCF_DISABLED); + if (_cur_grfconfig->status != GCS_ACTIVATED) _cur_grfconfig->status = GCS_DISABLED; } } @@ -2673,7 +2673,7 @@ static void GRFInfo(byte *buf, int len) _cur_grffile->grfid = grfid; _cur_grffile->grf_version = version; - SETBIT(_cur_grfconfig->flags, GCF_ACTIVATED); + _cur_grfconfig->status = _cur_stage < GLS_ACTIVATION ? GCS_INITIALISED : GCS_ACTIVATED; /* Do swap the GRFID for displaying purposes since people expect that */ DEBUG(grf, 1, "Loaded GRFv%d set %08lX - %s", version, BSWAP32(grfid), name); @@ -2779,8 +2779,7 @@ static void GRFLoadError(byte *buf, int len) } else if (severity == 3) { /* This is a fatal error, so make sure the GRF is deactivated and no * more of it gets loaded. */ - SETBIT(_cur_grfconfig->flags, GCF_DISABLED); - CLRBIT(_cur_grfconfig->flags, GCF_ACTIVATED); + _cur_grfconfig->status = GCS_DISABLED; _skip_sprites = -1; } @@ -2981,8 +2980,7 @@ static void ParamSet(byte *buf, int len) if (op != 4 && op != 5) { /* Deactivate GRF */ grfmsg(0, "GRM: Unable to allocate %d vehicles, deactivating", count); - SETBIT(_cur_grfconfig->flags, GCF_DISABLED); - CLRBIT(_cur_grfconfig->flags, GCF_ACTIVATED); + _cur_grfconfig->status = GCS_DISABLED; _skip_sprites = -1; return; @@ -3000,8 +2998,7 @@ static void ParamSet(byte *buf, int len) /* Check if the allocated sprites will fit below the original sprite limit */ if (_cur_spriteid + count >= 16384) { grfmsg(0, "GRM: Unable to allocate %d sprites; try changing NewGRF order", count); - SETBIT(_cur_grfconfig->flags, GCF_DISABLED); - CLRBIT(_cur_grfconfig->flags, GCF_ACTIVATED); + _cur_grfconfig->status = GCS_DISABLED; _skip_sprites = -1; return; @@ -3218,8 +3215,7 @@ static void GRFInhibit(byte *buf, int len) /* Unset activation flag */ if (file != NULL && file != _cur_grfconfig) { grfmsg(2, "GRFInhibit: Deactivating file '%s'", file->filename); - SETBIT(file->flags, GCF_DISABLED); - CLRBIT(file->flags, GCF_ACTIVATED); + file->status = GCS_DISABLED; } } } @@ -3950,11 +3946,9 @@ void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage) if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) { _cur_grffile = GetFileByFilename(filename); if (_cur_grffile == NULL) error("File '%s' lost in cache.\n", filename); - if (stage == GLS_ACTIVATION && !HASBIT(config->flags, GCF_ACTIVATED)) return; + if (stage == GLS_ACTIVATION && config->status != GCS_INITIALISED) return; } - if (stage == GLS_ACTIVATION) CLRBIT(config->flags, GCF_ACTIVATED); - FioOpenFile(file_index, filename); _file_index = file_index; // XXX @@ -4037,7 +4031,7 @@ void LoadNewGRF(uint load_index, uint file_index) _cur_stage = stage; _cur_spriteid = load_index; for (c = _grfconfig; c != NULL; c = c->next) { - if (HASBIT(c->flags, GCF_DISABLED) || HASBIT(c->flags, GCF_NOT_FOUND)) continue; + if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND) continue; // TODO usererror() if (!FioCheckFileExists(c->filename)) error("NewGRF file is missing '%s'", c->filename); diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index ccd212055..c994f20d6 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -60,7 +60,7 @@ static bool CalcGRFMD5Sum(GRFConfig *config) bool FillGRFDetails(GRFConfig *config, bool is_static) { if (!FioCheckFileExists(config->filename)) { - SETBIT(config->flags, GCF_NOT_FOUND); + config->status = GCS_NOT_FOUND; return false; } @@ -210,14 +210,14 @@ void ResetGRFConfig(bool defaults) /** Check if all GRFs in the GRF config from a savegame can be loaded. * @return will return any of the following 3 values:<br> * <ul> - * <li> GCF_ACTIVATED: No problems occured, all GRF files were found and loaded - * <li> GCF_COMPATIBLE: For one or more GRF's no exact match was found, but a + * <li> GLC_ALL_GOOD: No problems occured, all GRF files were found and loaded + * <li> GLC_COMPATIBLE: For one or more GRF's no exact match was found, but a * compatible GRF with the same grfid was found and used instead - * <li> GCF_NOT_FOUND: For one or more GRF's no match was found at all + * <li> GLC_NOT_FOUND: For one or more GRF's no match was found at all * </ul> */ -GCF_Flags IsGoodGRFConfigList(void) +GRFListCompatibility IsGoodGRFConfigList(void) { - GCF_Flags res = GCF_ACTIVATED; + GRFListCompatibility res = GLC_ALL_GOOD; for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) { const GRFConfig *f = FindGRFConfig(c->grfid, c->md5sum); @@ -233,7 +233,7 @@ GCF_Flags IsGoodGRFConfigList(void) SETBIT(c->flags, GCF_COMPATIBLE); /* Non-found has precedence over compatibility load */ - if (res != GCF_NOT_FOUND) res = GCF_COMPATIBLE; + if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE; goto compatible_grf; } @@ -241,8 +241,8 @@ GCF_Flags IsGoodGRFConfigList(void) md5sumToString(buf, lastof(buf), c->md5sum); DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->grfid), c->filename, buf); - SETBIT(c->flags, GCF_NOT_FOUND); - res = GCF_NOT_FOUND; + c->status = GCS_NOT_FOUND; + res = GLC_NOT_FOUND; } else { compatible_grf: DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->grfid), f->filename); diff --git a/src/newgrf_config.h b/src/newgrf_config.h index 94be7ee34..66530fe76 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -7,9 +7,6 @@ /* GRF config bit flags */ typedef enum { - GCF_DISABLED, ///< GRF file is disabled - GCF_NOT_FOUND, ///< GRF file was not found in the local cache - GCF_ACTIVATED, ///< GRF file is active GCF_SYSTEM, ///< GRF file is an openttd-internal system grf GCF_UNSAFE, ///< GRF file is unsafe for static usage GCF_STATIC, ///< GRF file is used statically (can be used in any MP game) @@ -17,6 +14,20 @@ typedef enum { GCF_COPY, ///< The data is copied from a grf in _all_grfs } GCF_Flags; +typedef enum { + GCS_UNKNOWN, ///< The status of this grf file is unknown + GCS_DISABLED, ///< GRF file is disabled + GCS_NOT_FOUND, ///< GRF file was not found in the local cache + GCS_INITIALISED, ///< GRF file has been initialised + GCS_ACTIVATED ///< GRF file has been activated +} GRFStatus; + +typedef enum { + GLC_ALL_GOOD, + GLC_COMPATIBLE, + GLC_NOT_FOUND +} GRFListCompatibility; + typedef struct GRFIdentifier { uint32 grfid; uint8 md5sum[16]; @@ -37,6 +48,7 @@ typedef struct GRFConfig : public GRFIdentifier { GRFError *error; uint8 flags; + GRFStatus status; uint32 param[0x80]; uint8 num_params; @@ -64,7 +76,7 @@ void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el); void ClearGRFConfig(GRFConfig **config); void ClearGRFConfigList(GRFConfig **config); void ResetGRFConfig(bool defaults); -GCF_Flags IsGoodGRFConfigList(void); +GRFListCompatibility IsGoodGRFConfigList(void); bool FillGRFDetails(GRFConfig *config, bool is_static); char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last); diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 54cbdd536..3a1c49719 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -91,8 +91,8 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, bool show } /* Show flags */ - if (HASBIT(c->flags, GCF_NOT_FOUND)) y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w); - if (HASBIT(c->flags, GCF_DISABLED)) y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w); + if (c->status == GCS_NOT_FOUND) y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w); + if (c->status == GCS_DISABLED) y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w); if (HASBIT(c->flags, GCF_COMPATIBLE)) y += DrawStringMultiLine(x, y, STR_NEWGRF_COMPATIBLE_LOADED, w); /* Draw GRF info if it exists */ @@ -335,16 +335,23 @@ static void NewGRFWndProc(Window *w, WindowEvent *e) SpriteID pal; /* Pick a colour */ - if (HASBIT(c->flags, GCF_NOT_FOUND) || HASBIT(c->flags, GCF_DISABLED)) { - pal = PALETTE_TO_RED; - } else if (HASBIT(c->flags, GCF_STATIC)) { + switch (c->status) { + case GCS_NOT_FOUND: + case GCS_DISABLED: + pal = PALETTE_TO_RED; + break; + case GCS_ACTIVATED: + pal = PALETTE_TO_GREEN; + break; + default: + pal = PALETTE_TO_BLUE; + break; + } + + if (HASBIT(c->flags, GCF_STATIC)) { pal = PALETTE_TO_GREY; } else if (HASBIT(c->flags, GCF_COMPATIBLE)) { pal = PALETTE_TO_ORANGE; - } else if (HASBIT(c->flags, GCF_ACTIVATED)) { - pal = PALETTE_TO_GREEN; - } else { - pal = PALETTE_TO_BLUE; } DrawSprite(SPR_SQUARE, pal, 5, y + 2); diff --git a/src/openttd.cpp b/src/openttd.cpp index 29a57d27c..170f40e87 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1209,12 +1209,12 @@ bool AfterLoadGame(void) if (_opt.road_side) _opt.road_side = 1; /* Check if all NewGRFs are present, we are very strict in MP mode */ - GCF_Flags gcf_res = IsGoodGRFConfigList(); - if (_networking && gcf_res != GCF_ACTIVATED) return false; + GRFListCompatibility gcf_res = IsGoodGRFConfigList(); + if (_networking && gcf_res != GLC_ALL_GOOD) return false; switch (gcf_res) { - case GCF_COMPATIBLE: _switch_mode_errorstr = STR_NEWGRF_COMPATIBLE_LOAD_WARNING; break; - case GCF_NOT_FOUND: _switch_mode_errorstr = STR_NEWGRF_DISABLED_WARNING; break; + case GLC_COMPATIBLE: _switch_mode_errorstr = STR_NEWGRF_COMPATIBLE_LOAD_WARNING; break; + case GLC_NOT_FOUND: _switch_mode_errorstr = STR_NEWGRF_DISABLED_WARNING; break; default: break; } diff --git a/src/settings.cpp b/src/settings.cpp index 0e9c73a76..b73b31a29 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1530,7 +1530,7 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati if (!FillGRFDetails(c, is_static)) { const char *msg; - if (HASBIT(c->flags, GCF_NOT_FOUND)) { + if (c->status == GCS_NOT_FOUND) { msg = "not found"; } else if (HASBIT(c->flags, GCF_UNSAFE)) { msg = "unsafe for static use"; |