summaryrefslogtreecommitdiff
path: root/src/saveload/newgrf_sl.cpp
diff options
context:
space:
mode:
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,
};