mirror of https://github.com/OpenTTD/OpenTTD
(svn r21695) -Codechange: add helper function to get the currently applicable GameSettings object
parent
a25d6c64dd
commit
3ca65ab7b3
|
@ -44,7 +44,7 @@ extern CurrencySpec _currency_specs[NUM_CURRENCY];
|
||||||
|
|
||||||
/* XXX small hack, but makes the rest of the code a bit nicer to read */
|
/* XXX small hack, but makes the rest of the code a bit nicer to read */
|
||||||
#define _custom_currency (_currency_specs[CUSTOM_CURRENCY_ID])
|
#define _custom_currency (_currency_specs[CUSTOM_CURRENCY_ID])
|
||||||
#define _currency ((const CurrencySpec*)&_currency_specs[_game_mode == GM_MENU ? _settings_newgame.locale.currency : _settings_game.locale.currency])
|
#define _currency ((const CurrencySpec*)&_currency_specs[GetGameSettings().locale.currency])
|
||||||
|
|
||||||
uint GetMaskOfAllowedCurrencies();
|
uint GetMaskOfAllowedCurrencies();
|
||||||
void CheckSwitchToEuro();
|
void CheckSwitchToEuro();
|
||||||
|
|
|
@ -980,7 +980,7 @@ static bool DifficultyReset(int32 level)
|
||||||
/* In game / in the scenario editor you can set the difficulty level only to custom. This is
|
/* In game / in the scenario editor you can set the difficulty level only to custom. This is
|
||||||
* needed by the AI Gui code that sets the difficulty level when you change any AI settings. */
|
* needed by the AI Gui code that sets the difficulty level when you change any AI settings. */
|
||||||
if (_game_mode != GM_MENU && level != 3) return false;
|
if (_game_mode != GM_MENU && level != 3) return false;
|
||||||
SetDifficultyLevel(level, (_game_mode == GM_MENU) ? &_settings_newgame.difficulty : &_settings_game.difficulty);
|
SetDifficultyLevel(level, &GetGameSettings().difficulty);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1020,7 +1020,7 @@ static bool DifficultyNoiseChange(int32 i)
|
||||||
|
|
||||||
static bool MaxNoAIsChange(int32 i)
|
static bool MaxNoAIsChange(int32 i)
|
||||||
{
|
{
|
||||||
if (((_game_mode == GM_MENU) ? _settings_newgame.difficulty : _settings_game.difficulty).max_no_competitors != 0 &&
|
if (GetGameSettings().difficulty.max_no_competitors != 0 &&
|
||||||
#ifdef ENABLE_AI
|
#ifdef ENABLE_AI
|
||||||
AI::GetInfoList()->size() == 0 &&
|
AI::GetInfoList()->size() == 0 &&
|
||||||
#endif /* ENABLE_AI */
|
#endif /* ENABLE_AI */
|
||||||
|
@ -1644,8 +1644,7 @@ CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
GameSettings *s = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
|
void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
|
||||||
void *var = GetVariableAddress(s, &sd->save);
|
|
||||||
|
|
||||||
int32 oldval = (int32)ReadValue(var, sd->save.conv);
|
int32 oldval = (int32)ReadValue(var, sd->save.conv);
|
||||||
int32 newval = (int32)p2;
|
int32 newval = (int32)p2;
|
||||||
|
@ -1724,7 +1723,7 @@ bool SetSettingValue(uint index, int32 value, bool force_newgame)
|
||||||
* of settings because changing a company-based setting in a game also
|
* of settings because changing a company-based setting in a game also
|
||||||
* changes its defaults. At least that is the convention we have chosen */
|
* changes its defaults. At least that is the convention we have chosen */
|
||||||
if (sd->save.conv & SLF_NETWORK_NO) {
|
if (sd->save.conv & SLF_NETWORK_NO) {
|
||||||
void *var = GetVariableAddress((_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game, &sd->save);
|
void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
|
||||||
Write_ValidateSetting(var, sd, value);
|
Write_ValidateSetting(var, sd, value);
|
||||||
|
|
||||||
if (_game_mode != GM_MENU) {
|
if (_game_mode != GM_MENU) {
|
||||||
|
@ -1963,7 +1962,7 @@ void IConsoleListSettings(const char *prefilter)
|
||||||
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
|
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
|
||||||
if (prefilter != NULL && strstr(sd->desc.name, prefilter) == NULL) continue;
|
if (prefilter != NULL && strstr(sd->desc.name, prefilter) == NULL) continue;
|
||||||
char value[80];
|
char value[80];
|
||||||
const void *ptr = GetVariableAddress((_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game, &sd->save);
|
const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save);
|
||||||
|
|
||||||
if (sd->desc.cmd == SDT_BOOLX) {
|
if (sd->desc.cmd == SDT_BOOLX) {
|
||||||
snprintf(value, lengthof(value), (*(bool*)ptr == 1) ? "on" : "off");
|
snprintf(value, lengthof(value), (*(bool*)ptr == 1) ? "on" : "off");
|
||||||
|
|
|
@ -186,7 +186,7 @@ struct GameOptionsWindow : Window {
|
||||||
|
|
||||||
GameOptionsWindow(const WindowDesc *desc) : Window()
|
GameOptionsWindow(const WindowDesc *desc) : Window()
|
||||||
{
|
{
|
||||||
this->opt = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
|
this->opt = &GetGameSettings();
|
||||||
this->reload = false;
|
this->reload = false;
|
||||||
|
|
||||||
this->InitNested(desc);
|
this->InitNested(desc);
|
||||||
|
@ -591,7 +591,7 @@ public:
|
||||||
|
|
||||||
/* Copy current settings (ingame or in intro) to temporary holding place
|
/* Copy current settings (ingame or in intro) to temporary holding place
|
||||||
* change that when setting stuff, copy back on clicking 'OK' */
|
* change that when setting stuff, copy back on clicking 'OK' */
|
||||||
this->opt_mod_temp = (_game_mode == GM_MENU) ? _settings_newgame : _settings_game;
|
this->opt_mod_temp = GetGameSettings();
|
||||||
/* Setup disabled buttons when creating window
|
/* Setup disabled buttons when creating window
|
||||||
* disable all other difficulty buttons during gameplay except for 'custom' */
|
* disable all other difficulty buttons during gameplay except for 'custom' */
|
||||||
this->SetWidgetsDisabledState(_game_mode != GM_MENU,
|
this->SetWidgetsDisabledState(_game_mode != GM_MENU,
|
||||||
|
@ -696,7 +696,7 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GDW_ACCEPT: { // Save button - save changes
|
case GDW_ACCEPT: { // Save button - save changes
|
||||||
GameSettings *opt_ptr = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
|
GameSettings *opt_ptr = &GetGameSettings();
|
||||||
|
|
||||||
uint i;
|
uint i;
|
||||||
GetSettingFromName("difficulty.diff_level", &i);
|
GetSettingFromName("difficulty.diff_level", &i);
|
||||||
|
@ -1526,7 +1526,7 @@ struct GameSettingsWindow : Window {
|
||||||
{
|
{
|
||||||
static bool first_time = true;
|
static bool first_time = true;
|
||||||
|
|
||||||
settings_ptr = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
|
settings_ptr = &GetGameSettings();
|
||||||
|
|
||||||
/* Build up the dynamic settings-array only once per OpenTTD session */
|
/* Build up the dynamic settings-array only once per OpenTTD session */
|
||||||
if (first_time) {
|
if (first_time) {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "transport_type.h"
|
#include "transport_type.h"
|
||||||
#include "network/core/config.h"
|
#include "network/core/config.h"
|
||||||
#include "company_type.h"
|
#include "company_type.h"
|
||||||
|
#include "openttd.h"
|
||||||
|
|
||||||
/** Settings related to the difficulty of the game */
|
/** Settings related to the difficulty of the game */
|
||||||
struct DifficultySettings {
|
struct DifficultySettings {
|
||||||
|
@ -438,4 +439,13 @@ extern GameSettings _settings_game;
|
||||||
/** The settings values that are used for new games and/or modified in config file. */
|
/** The settings values that are used for new games and/or modified in config file. */
|
||||||
extern GameSettings _settings_newgame;
|
extern GameSettings _settings_newgame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the settings-object applicable for the current situation: the newgame settings
|
||||||
|
* when we're in the main menu and otherwise the settings of the current game.
|
||||||
|
*/
|
||||||
|
static inline GameSettings &GetGameSettings()
|
||||||
|
{
|
||||||
|
return (_game_mode == GM_MENU) ? _settings_newgame : _settings_game;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* SETTINGS_TYPE_H */
|
#endif /* SETTINGS_TYPE_H */
|
||||||
|
|
Loading…
Reference in New Issue