Changeset - r13129:9becfa618607
[Not reviewed]
master
0 4 0
rubidium - 15 years ago 2009-09-26 17:43:06
rubidium@openttd.org
(svn r17644) -Fix [FS#3219]: some inconsistencies with the difficulty settings in the scenario editor. Also re-enable changing some difficulty settings (e.g. max loan) in the scenario editor.
4 files changed with 19 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/settings.cpp
Show inline comments
 
@@ -1413,25 +1413,29 @@ static const SettingDesc *GetSettingDesc
 
 * @return the cost of this operation or an error
 
 * @see _settings
 
 */
 
CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	const SettingDesc *sd = GetSettingDescription(p1);
 

	
 
	if (sd == NULL) return CMD_ERROR;
 
	if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) return CMD_ERROR;
 

	
 
	if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return CMD_ERROR;
 
	if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return CMD_ERROR;
 
	if ((sd->desc.flags & SGF_NEWGAME_ONLY) && _game_mode != GM_MENU) return CMD_ERROR;
 
	if ((sd->desc.flags & SGF_NEWGAME_ONLY) &&
 
			(_game_mode == GM_NORMAL ||
 
			(_game_mode == GM_EDITOR && (sd->desc.flags & SGF_SCENEDIT_TOO) == 0))) {
 
		return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		GameSettings *s = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
 
		void *var = GetVariableAddress(s, &sd->save);
 

	
 
		int32 oldval = (int32)ReadValue(var, sd->save.conv);
 
		int32 newval = (int32)p2;
 

	
 
		Write_ValidateSetting(var, sd, newval);
 
		newval = (int32)ReadValue(var, sd->save.conv);
 

	
 
		if (oldval == newval) return CommandCost();
src/settings_gui.cpp
Show inline comments
 
@@ -538,25 +538,25 @@ public:
 
	/** The number of widgets per difficulty setting */
 
	static const uint WIDGETS_PER_DIFFICULTY = 3;
 

	
 
	GameDifficultyWindow(const WindowDesc *desc) : Window()
 
	{
 
		this->InitNested(desc);
 

	
 
		/* Copy current settings (ingame or in intro) to temporary holding place
 
		 * change that when setting stuff, copy back on clicking 'OK' */
 
		this->opt_mod_temp = (_game_mode == GM_MENU) ? _settings_newgame : _settings_game;
 
		/* Setup disabled buttons when creating window
 
		 * disable all other difficulty buttons during gameplay except for 'custom' */
 
		this->SetWidgetsDisabledState(_game_mode == GM_NORMAL,
 
		this->SetWidgetsDisabledState(_game_mode != GM_MENU,
 
			GDW_LVL_EASY,
 
			GDW_LVL_MEDIUM,
 
			GDW_LVL_HARD,
 
			GDW_LVL_CUSTOM,
 
			WIDGET_LIST_END);
 
		this->SetWidgetDisabledState(GDW_HIGHSCORE, _game_mode == GM_EDITOR || _networking); // highscore chart in multiplayer
 
		this->SetWidgetDisabledState(GDW_ACCEPT, _networking && !_network_server); // Save-button in multiplayer (and if client)
 
		this->LowerWidget(GDW_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
 
		this->OnInvalidateData();
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
@@ -601,28 +601,24 @@ public:
 
	{
 
		if (widget >= GDW_OPTIONS_START) {
 
			widget -= GDW_OPTIONS_START;
 
			if ((widget % 3) == 2) return;
 

	
 
			/* Don't allow clients to make any changes */
 
			if (_networking && !_network_server) return;
 

	
 
			uint i;
 
			const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i) + (widget / 3);
 
			const SettingDescBase *sdb = &sd->desc;
 

	
 
			/* Clicked disabled button? */
 
			bool editable = (_game_mode == GM_MENU || (sdb->flags & SGF_NEWGAME_ONLY) == 0);
 
			if (!editable) return;
 

	
 
			int32 val = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
 
			if (widget % 3 == 1) {
 
				/* Increase button clicked */
 
				val = min(val + sdb->interval, (int32)sdb->max);
 
			} else {
 
				/* Decrease button clicked */
 
				val -= sdb->interval;
 
				val = max(val, sdb->min);
 
			}
 

	
 
			/* save value in temporary variable */
 
			WriteValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv, val);
 
@@ -681,28 +677,30 @@ public:
 
		}
 
	}
 

	
 
	virtual void OnInvalidateData(int data = 0)
 
	{
 
		uint i;
 
		const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
 
		for (i = 0; i < GAME_DIFFICULTY_NUM; i++, sd++) {
 
			const SettingDescBase *sdb = &sd->desc;
 
			/* skip deprecated difficulty options */
 
			if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
 
			int32 value = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
 
			bool editable = (_game_mode == GM_MENU || (sdb->flags & SGF_NEWGAME_ONLY) == 0);
 
			bool disable = (sd->desc.flags & SGF_NEWGAME_ONLY) &&
 
					(_game_mode == GM_NORMAL ||
 
					(_game_mode == GM_EDITOR && (sd->desc.flags & SGF_SCENEDIT_TOO) == 0));
 

	
 
			this->SetWidgetDisabledState(GDW_OPTIONS_START + i * 3 + 0, !editable || sdb->min == value);
 
			this->SetWidgetDisabledState(GDW_OPTIONS_START + i * 3 + 1, !editable || sdb->max == (uint32)value);
 
			this->SetWidgetDisabledState(GDW_OPTIONS_START + i * 3 + 0, disable || sdb->min == value);
 
			this->SetWidgetDisabledState(GDW_OPTIONS_START + i * 3 + 1, disable || sdb->max == (uint32)value);
 
		}
 
	}
 
};
 

	
 
static NWidgetBase *MakeDifficultyOptionsWidgets(int *biggest_index)
 
{
 
	NWidgetVertical *vert_desc = new NWidgetVertical;
 

	
 
	int widnum = GDW_OPTIONS_START;
 
	uint i, j;
 
	const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
 

	
src/settings_internal.h
Show inline comments
 
@@ -35,29 +35,30 @@ typedef SimpleTinyEnumT<SettingDescTypeL
 

	
 

	
 
enum SettingGuiFlagLong {
 
	/* 1 byte allocated for a maximum of 8 flags
 
	 * Flags directing saving/loading of a variable */
 
	SGF_NONE = 0,
 
	SGF_0ISDISABLED  = 1 << 0, ///< a value of zero means the feature is disabled
 
	SGF_NOCOMMA      = 1 << 1, ///< number without any thousand seperators (no formatting)
 
	SGF_MULTISTRING  = 1 << 2, ///< the value represents a limited number of string-options (internally integer)
 
	SGF_NETWORK_ONLY = 1 << 3, ///< this setting only applies to network games
 
	SGF_CURRENCY     = 1 << 4, ///< the number represents money, so when reading value multiply by exchange rate
 
	SGF_NO_NETWORK   = 1 << 5, ///< this setting does not apply to network games; it may not be changed during the game
 
	SGF_NEWGAME_ONLY = 1 << 6, ///< this setting cannot be changed in inside a game
 
	SGF_PER_COMPANY  = 1 << 7, ///< this setting can be different for each company (saved in company struct)
 
	SGF_NEWGAME_ONLY = 1 << 6, ///< this setting cannot be changed in a game
 
	SGF_SCENEDIT_TOO = 1 << 7, ///< this setting can be changed in the scenario editor (only makes sense when SGF_NEWGAME_ONLY is set)
 
	SGF_PER_COMPANY  = 1 << 8, ///< this setting can be different for each company (saved in company struct)
 
};
 
DECLARE_ENUM_AS_BIT_SET(SettingGuiFlagLong);
 
typedef SimpleTinyEnumT<SettingGuiFlagLong, byte> SettingGuiFlag;
 
typedef SimpleTinyEnumT<SettingGuiFlagLong, uint16> SettingGuiFlag;
 

	
 

	
 
typedef bool OnChange(int32 var);           ///< callback prototype on data modification
 
typedef int32 OnConvert(const char *value); ///< callback prototype for convertion error
 

	
 
struct SettingDescBase {
 
	const char *name;       ///< name of the setting. Used in configuration file and for console
 
	const void *def;        ///< default value given when none is present
 
	SettingDescType cmd;    ///< various flags for the variable
 
	SettingGuiFlag flags;   ///< handles how a setting would show up in the GUI (text/currency, etc.)
 
	int32 min;              ///< minimum values
 
	uint32 max;             ///< maximum values
src/table/settings.h
Show inline comments
 
@@ -204,24 +204,25 @@ static bool UpdateClientConfigValues(int
 
 * we also don't sync it in a network game */
 
#define S SLF_SAVE_NO | SLF_NETWORK_NO
 
#define C SLF_CONFIG_NO
 
#define N SLF_NETWORK_NO
 

	
 
#define D0 SGF_0ISDISABLED
 
#define NC SGF_NOCOMMA
 
#define MS SGF_MULTISTRING
 
#define NO SGF_NETWORK_ONLY
 
#define CR SGF_CURRENCY
 
#define NN SGF_NO_NETWORK
 
#define NG SGF_NEWGAME_ONLY
 
#define NS (SGF_NEWGAME_ONLY | SGF_SCENEDIT_TOO)
 
#define PC SGF_PER_COMPANY
 

	
 
static const SettingDesc _music_settings[] = {
 
	 SDT_VAR(MusicFileSettings, playlist,   SLE_UINT8, S, 0,   0, 0,   5, 1,  STR_NULL, NULL),
 
	 SDT_VAR(MusicFileSettings, music_vol,  SLE_UINT8, S, 0, 127, 0, 127, 1,  STR_NULL, NULL),
 
	 SDT_VAR(MusicFileSettings, effect_vol, SLE_UINT8, S, 0, 127, 0, 127, 1,  STR_NULL, NULL),
 
	SDT_LIST(MusicFileSettings, custom_1,   SLE_UINT8, S, 0, NULL,            STR_NULL, NULL),
 
	SDT_LIST(MusicFileSettings, custom_2,   SLE_UINT8, S, 0, NULL,            STR_NULL, NULL),
 
	SDT_BOOL(MusicFileSettings, playing,               S, 0, true,            STR_NULL, NULL),
 
	SDT_BOOL(MusicFileSettings, shuffle,               S, 0, false,           STR_NULL, NULL),
 
	 SDT_END()
 
};
 
@@ -326,32 +327,32 @@ static const SettingDesc _gameopt_settin
 
 * service_interval value to the v->service_interval, meaning that every client
 
 * assigns his value. If the setting was company-based, that would mean that
 
 * vehicles could decide on different moments that they are heading back to a
 
 * service depot, causing desyncs on a massive scale. */
 
const SettingDesc _settings[] = {
 
	/***************************************************************************/
 
	/* Saved settings variables. */
 
	/* Do not ADD or REMOVE something in this "difficulty.XXX" table or before it. It breaks savegame compatability. */
 
	 SDT_CONDVAR(GameSettings, difficulty.max_no_competitors,        SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     2,0,MAX_COMPANIES-1,1,STR_NULL,                                  DifficultyChange),
 
	SDT_CONDNULL(                                                            1, 97, 109),
 
	 SDT_CONDVAR(GameSettings, difficulty.number_towns,              SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     2,     0,      4,  1, STR_NUM_VERY_LOW,                          DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.number_industries,         SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     4,     0,      4,  1, STR_NONE,                                  DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.max_loan,                 SLE_UINT32, 97, SL_MAX_VERSION, 0,NG|CR,300000,100000,500000,50000,STR_NULL,                               DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.initial_interest,          SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     2,     2,      4,  1, STR_NULL,                                  DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.max_loan,                 SLE_UINT32, 97, SL_MAX_VERSION, 0,NS|CR,300000,100000,500000,50000,STR_NULL,                               DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.initial_interest,          SLE_UINT8, 97, SL_MAX_VERSION, 0,NS,     2,     2,      4,  1, STR_NULL,                                  DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.vehicle_costs,             SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     0,     0,      2,  1, STR_SEA_LEVEL_LOW,                         DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.competitor_speed,          SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     2,     0,      4,  1, STR_AI_SPEED_VERY_SLOW,                    DifficultyChange),
 
	SDT_CONDNULL(                                                            1, 97, 109),
 
	 SDT_CONDVAR(GameSettings, difficulty.vehicle_breakdowns,        SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     1,     0,      2,  1, STR_DISASTER_NONE,                         DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.subsidy_multiplier,        SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     2,     0,      3,  1, STR_SUBSIDY_X1_5,                          DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.construction_cost,         SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     0,     0,      2,  1, STR_SEA_LEVEL_LOW,                         DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.construction_cost,         SLE_UINT8, 97, SL_MAX_VERSION, 0,NS,     0,     0,      2,  1, STR_SEA_LEVEL_LOW,                         DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.terrain_type,              SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     1,     0,      3,  1, STR_TERRAIN_TYPE_VERY_FLAT,                DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.quantity_sea_lakes,        SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     0,     0,      3,  1, STR_SEA_LEVEL_VERY_LOW,                    DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.economy,                   SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     0,     0,      1,  1, STR_ECONOMY_STEADY,                        DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.line_reverse_mode,         SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     0,     0,      1,  1, STR_REVERSE_AT_END_OF_LINE_AND_AT_STATIONS,DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.disasters,                 SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     0,     0,      1,  1, STR_DISASTERS_OFF,                         DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.town_council_tolerance,    SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     0,     0,      2,  1, STR_CITY_APPROVAL_PERMISSIVE,                            DifficultyNoiseChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.diff_level,                SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     0,     0,      3,  0, STR_NULL,                                  DifficultyReset),
 

	
 
	/* There are only 21 predefined town_name values (0-20), but you can have more with newgrf action F so allow these bigger values (21-255). Invalid values will fallback to english on use and (undefined string) in GUI. */
 
 SDT_CONDOMANY(GameSettings, game_creation.town_name,              SLE_UINT8, 97, SL_MAX_VERSION, 0,NN, 0, 255, _town_names,      STR_NULL,                                  NULL, NULL),
 
 SDT_CONDOMANY(GameSettings, game_creation.landscape,              SLE_UINT8, 97, SL_MAX_VERSION, 0,NN, 0,   3, _climates,        STR_NULL,                                  NULL, ConvertLandscape),
 
	 SDT_CONDVAR(GameSettings, game_creation.snow_line,              SLE_UINT8, 97, SL_MAX_VERSION, 0,NN, 7 * TILE_HEIGHT, 2 * TILE_HEIGHT, 13 * TILE_HEIGHT, 0, STR_NULL,     NULL),
0 comments (0 inline, 0 general)