summaryrefslogtreecommitdiff
path: root/src/saveload/newgrf_sl.cpp
diff options
context:
space:
mode:
authorglx22 <glx@openttd.org>2021-06-07 23:24:37 +0200
committerLoïc Guilloux <glx22@users.noreply.github.com>2021-07-06 22:29:08 +0200
commit2c941cd8b3cb1774f4982b86735e276597a91750 (patch)
treeae545cd8e0b66ece181fb5b5bc9ebe8db48c374a /src/saveload/newgrf_sl.cpp
parentc1a9fe6fbd736c9e3a93314b0721d8f2cb8a2052 (diff)
downloadopenttd-2c941cd8b3cb1774f4982b86735e276597a91750.tar.xz
Codechange: Use ChunkHandlers sub-classes
Diffstat (limited to 'src/saveload/newgrf_sl.cpp')
-rw-r--r--src/saveload/newgrf_sl.cpp81
1 files changed, 44 insertions, 37 deletions
diff --git a/src/saveload/newgrf_sl.cpp b/src/saveload/newgrf_sl.cpp
index 10a65e936..43f0bd01a 100644
--- a/src/saveload/newgrf_sl.cpp
+++ b/src/saveload/newgrf_sl.cpp
@@ -73,55 +73,62 @@ static const SaveLoad _grfconfig_desc[] = {
};
-static void Save_NGRF()
-{
- SlTableHeader(_grfconfig_desc);
+struct NGRFChunkHandler : ChunkHandler {
+ NGRFChunkHandler() : ChunkHandler('NGRF', CH_TABLE)
+ {
+ this->load_check = true;
+ }
- int index = 0;
+ void Save() const override
+ {
+ SlTableHeader(_grfconfig_desc);
- for (GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
- if (HasBit(c->flags, GCF_STATIC)) continue;
- SlSetArrayIndex(index++);
- SlObject(c, _grfconfig_desc);
+ int index = 0;
+
+ for (GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
+ if (HasBit(c->flags, GCF_STATIC)) continue;
+ SlSetArrayIndex(index++);
+ SlObject(c, _grfconfig_desc);
+ }
}
-}
-static void Load_NGRF_common(GRFConfig *&grfconfig)
-{
- const std::vector<SaveLoad> slt = SlCompatTableHeader(_grfconfig_desc, _grfconfig_sl_compat);
-
- ClearGRFConfigList(&grfconfig);
- while (SlIterateArray() != -1) {
- GRFConfig *c = new GRFConfig();
- SlObject(c, slt);
- if (IsSavegameVersionBefore(SLV_101)) c->SetSuitablePalette();
- AppendToGRFConfigList(&grfconfig, c);
+ void LoadCommon(GRFConfig *&grfconfig) const
+ {
+ const std::vector<SaveLoad> slt = SlCompatTableHeader(_grfconfig_desc, _grfconfig_sl_compat);
+
+ ClearGRFConfigList(&grfconfig);
+ while (SlIterateArray() != -1) {
+ GRFConfig *c = new GRFConfig();
+ SlObject(c, slt);
+ if (IsSavegameVersionBefore(SLV_101)) c->SetSuitablePalette();
+ AppendToGRFConfigList(&grfconfig, c);
+ }
}
-}
-static void Load_NGRF()
-{
- Load_NGRF_common(_grfconfig);
+ void Load() const override
+ {
+ this->LoadCommon(_grfconfig);
- if (_game_mode == GM_MENU) {
- /* Intro game must not have NewGRF. */
- if (_grfconfig != nullptr) SlErrorCorrupt("The intro game must not use NewGRF");
+ if (_game_mode == GM_MENU) {
+ /* Intro game must not have NewGRF. */
+ if (_grfconfig != nullptr) SlErrorCorrupt("The intro game must not use NewGRF");
- /* Activate intro NewGRFs (townnames) */
- ResetGRFConfig(false);
- } else {
- /* Append static NewGRF configuration */
- AppendStaticGRFConfigs(&_grfconfig);
+ /* Activate intro NewGRFs (townnames) */
+ ResetGRFConfig(false);
+ } else {
+ /* Append static NewGRF configuration */
+ AppendStaticGRFConfigs(&_grfconfig);
+ }
}
-}
-static void Check_NGRF()
-{
- Load_NGRF_common(_load_check_data.grfconfig);
-}
+ void LoadCheck(size_t) const override
+ {
+ this->LoadCommon(_load_check_data.grfconfig);
+ }
+};
-static const ChunkHandler NGRF{ 'NGRF', Save_NGRF, Load_NGRF, nullptr, Check_NGRF, CH_TABLE };
+static const NGRFChunkHandler NGRF;
static const ChunkHandlerRef newgrf_chunk_handlers[] = {
NGRF,
};