mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use setting name instead of index for HandleOldDiffCustom() (#9311)
parent
bcd7a7aafe
commit
e9e4588db1
|
@ -22,6 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
#include <array>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include "currency.h"
|
#include "currency.h"
|
||||||
#include "screenshot.h"
|
#include "screenshot.h"
|
||||||
|
@ -1227,7 +1228,9 @@ static void PrepareOldDiffCustom()
|
||||||
*/
|
*/
|
||||||
static void HandleOldDiffCustom(bool savegame)
|
static void HandleOldDiffCustom(bool savegame)
|
||||||
{
|
{
|
||||||
uint options_to_load = GAME_DIFFICULTY_NUM - ((savegame && IsSavegameVersionBefore(SLV_4)) ? 1 : 0);
|
/* Savegames before v4 didn't have "town_council_tolerance" in savegame yet. */
|
||||||
|
bool has_no_town_council_tolerance = savegame && IsSavegameVersionBefore(SLV_4);
|
||||||
|
uint options_to_load = GAME_DIFFICULTY_NUM - (has_no_town_council_tolerance ? 1 : 0);
|
||||||
|
|
||||||
if (!savegame) {
|
if (!savegame) {
|
||||||
/* If we did read to old_diff_custom, then at least one value must be non 0. */
|
/* If we did read to old_diff_custom, then at least one value must be non 0. */
|
||||||
|
@ -1239,11 +1242,21 @@ static void HandleOldDiffCustom(bool savegame)
|
||||||
if (!old_diff_custom_used) return;
|
if (!old_diff_custom_used) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint i = 0; i < options_to_load; i++) {
|
/* Iterate over all the old difficulty settings, and convert the list-value to the new setting. */
|
||||||
const SettingDesc *sd = GetSettingDescription(i);
|
uint i = 0;
|
||||||
/* Skip deprecated options */
|
for (const auto &name : _old_diff_settings) {
|
||||||
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
|
if (has_no_town_council_tolerance && name == "town_council_tolerance") continue;
|
||||||
int32 value = (int32)((i == 4 ? 1000 : 1) * _old_diff_custom[i]);
|
|
||||||
|
std::string fullname = "difficulty." + name;
|
||||||
|
const SettingDesc *sd = GetSettingFromName(fullname.c_str());
|
||||||
|
|
||||||
|
/* Some settings are no longer in use; skip reading those. */
|
||||||
|
if (sd == nullptr) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 value = (int32)((name == "max_loan" ? 1000 : 1) * _old_diff_custom[i++]);
|
||||||
sd->AsIntSetting()->MakeValueValidAndWrite(savegame ? &_settings_game : &_settings_newgame, value);
|
sd->AsIntSetting()->MakeValueValidAndWrite(savegame ? &_settings_game : &_settings_newgame, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,9 @@ enum IndustryDensity {
|
||||||
|
|
||||||
/** Settings related to the difficulty of the game */
|
/** Settings related to the difficulty of the game */
|
||||||
struct DifficultySettings {
|
struct DifficultySettings {
|
||||||
|
byte competitor_start_time; ///< Unused value, used to load old savegames.
|
||||||
|
byte competitor_intelligence; ///< Unused value, used to load old savegames.
|
||||||
|
|
||||||
byte max_no_competitors; ///< the number of competitors (AIs)
|
byte max_no_competitors; ///< the number of competitors (AIs)
|
||||||
byte number_towns; ///< the amount of towns
|
byte number_towns; ///< the amount of towns
|
||||||
byte industry_density; ///< The industry density. @see IndustryDensity
|
byte industry_density; ///< The industry density. @see IndustryDensity
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
[pre-amble]
|
[pre-amble]
|
||||||
static const uint GAME_DIFFICULTY_NUM = 18;
|
static const uint GAME_DIFFICULTY_NUM = 18;
|
||||||
|
static const std::array<std::string, GAME_DIFFICULTY_NUM> _old_diff_settings{"max_no_competitors", "competitor_start_time", "number_towns", "industry_density", "max_loan", "initial_interest", "vehicle_costs", "competitor_speed", "competitor_intelligence", "vehicle_breakdowns", "subsidy_multiplier", "construction_cost", "terrain_type", "quantity_sea_lakes", "economy", "line_reverse_mode", "disasters", "town_council_tolerance"};
|
||||||
static uint16 _old_diff_custom[GAME_DIFFICULTY_NUM];
|
static uint16 _old_diff_custom[GAME_DIFFICULTY_NUM];
|
||||||
uint8 _old_diff_level; ///< Old difficulty level from old savegames
|
uint8 _old_diff_level; ///< Old difficulty level from old savegames
|
||||||
uint8 _old_units; ///< Old units from old savegames
|
uint8 _old_units; ///< Old units from old savegames
|
||||||
|
|
|
@ -94,7 +94,7 @@ startup = false
|
||||||
|
|
||||||
|
|
||||||
; Saved settings variables.
|
; Saved settings variables.
|
||||||
; Do not ADD or REMOVE something in this "difficulty.XXX" table or before it. It breaks savegame compatibility.
|
; The next 18 entries are important for savegame compatibility. Do NOT remove those. See HandleOldDiffCustom() for more details.
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
var = difficulty.max_no_competitors
|
var = difficulty.max_no_competitors
|
||||||
type = SLE_UINT8
|
type = SLE_UINT8
|
||||||
|
@ -106,10 +106,14 @@ interval = 1
|
||||||
post_cb = MaxNoAIsChange
|
post_cb = MaxNoAIsChange
|
||||||
cat = SC_BASIC
|
cat = SC_BASIC
|
||||||
|
|
||||||
[SDT_NULL]
|
[SDT_VAR]
|
||||||
length = 1
|
var = difficulty.competitor_start_time
|
||||||
|
type = SLE_UINT8
|
||||||
from = SLV_97
|
from = SLV_97
|
||||||
to = SLV_110
|
to = SLV_110
|
||||||
|
def = 2
|
||||||
|
min = 0
|
||||||
|
max = 3
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
var = difficulty.number_towns
|
var = difficulty.number_towns
|
||||||
|
@ -192,10 +196,14 @@ strhelp = STR_CONFIG_SETTING_CONSTRUCTION_SPEED_HELPTEXT
|
||||||
strval = STR_AI_SPEED_VERY_SLOW
|
strval = STR_AI_SPEED_VERY_SLOW
|
||||||
cat = SC_BASIC
|
cat = SC_BASIC
|
||||||
|
|
||||||
[SDT_NULL]
|
[SDT_VAR]
|
||||||
length = 1
|
var = difficulty.competitor_intelligence
|
||||||
|
type = SLE_UINT8
|
||||||
from = SLV_97
|
from = SLV_97
|
||||||
to = SLV_110
|
to = SLV_110
|
||||||
|
def = 0
|
||||||
|
min = 0
|
||||||
|
max = 2
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
var = difficulty.vehicle_breakdowns
|
var = difficulty.vehicle_breakdowns
|
||||||
|
|
Loading…
Reference in New Issue