From 6c22efc8404e36487086097e2ba1d443527ba217 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 31 Jul 2010 09:36:09 +0000 Subject: [PATCH] (svn r20252) -Codechange: deduplicate logic for setting a suitable (initial) palette for NewGRFs --- src/newgrf_config.cpp | 16 +++++++++++++--- src/newgrf_config.h | 2 ++ src/saveload/newgrf_sl.cpp | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index d7769a394d..9ce1962ce1 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -85,6 +85,16 @@ const char *GRFConfig::GetDescription() const return GetGRFStringFromGRFText(this->info); } +/** + * Set the palette of this GRFConfig to something suitable. + * That is either the setting coming from the NewGRF or + * the globally used palette. + */ +void GRFConfig::SetSuitablePalette() +{ + this->windows_paletted = (_use_palette == PAL_WINDOWS); +} + GRFConfig *_all_grfs; GRFConfig *_grfconfig; GRFConfig *_grfconfig_newgame; @@ -133,8 +143,8 @@ GRFError::~GRFError() */ void UpdateNewGRFConfigPalette() { - for (GRFConfig *c = _grfconfig_newgame; c != NULL; c = c->next) c->windows_paletted = (_use_palette == PAL_WINDOWS); - for (GRFConfig *c = _grfconfig_static; c != NULL; c = c->next) c->windows_paletted = (_use_palette == PAL_WINDOWS); + for (GRFConfig *c = _grfconfig_newgame; c != NULL; c = c->next) c->SetSuitablePalette(); + for (GRFConfig *c = _grfconfig_static; c != NULL; c = c->next) c->SetSuitablePalette(); } /** Calculate the MD5 sum for a GRF, and store it in the config. @@ -191,7 +201,7 @@ bool FillGRFDetails(GRFConfig *config, bool is_static) if (HasBit(config->flags, GCF_UNSAFE)) return false; } - config->windows_paletted = (_use_palette == PAL_WINDOWS); + config->SetSuitablePalette(); return CalcGRFMD5Sum(config); } diff --git a/src/newgrf_config.h b/src/newgrf_config.h index 56131e766f..3c851a139b 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -108,6 +108,8 @@ struct GRFConfig : ZeroedMemoryAllocator { const char *GetName() const; const char *GetDescription() const; + + void SetSuitablePalette(); }; extern GRFConfig *_all_grfs; ///< First item in list of all scanned NewGRFs diff --git a/src/saveload/newgrf_sl.cpp b/src/saveload/newgrf_sl.cpp index 735306c3c3..f132bc03f6 100644 --- a/src/saveload/newgrf_sl.cpp +++ b/src/saveload/newgrf_sl.cpp @@ -47,7 +47,7 @@ static void Load_NGRF_common(GRFConfig *&grfconfig) while (SlIterateArray() != -1) { GRFConfig *c = new GRFConfig(); SlObject(c, _grfconfig_desc); - if (CheckSavegameVersion(101)) c->windows_paletted = (_use_palette == PAL_WINDOWS); + if (CheckSavegameVersion(101)) c->SetSuitablePalette(); AppendToGRFConfigList(&grfconfig, c); } }