summaryrefslogtreecommitdiff
path: root/settings.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-03-02 01:41:25 +0000
committerDarkvater <Darkvater@openttd.org>2006-03-02 01:41:25 +0000
commit2269685c23c07d265e0d539d225e916209462520 (patch)
tree79d987885acc57b06525b224bd2eb12a17f9cf5c /settings.c
parenta9d33943d734671990920fc093d0025845479370 (diff)
downloadopenttd-2269685c23c07d265e0d539d225e916209462520.tar.xz
(svn r3722) - [4/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. The last part finishes the transition with the merging of the settings_gui table(s).
- Because patches are (will be in a few commits) saved, you cannot specify the order of the GUI-items in the SettingDesc tables themselves. Doing so would mean messing around with the savegame-version, or doing expensive lookups. So the GUI-tables are now just simple indeces into the original table. No more is needed since that table contains all information - The only change in functionality is that the stepsize has been automated. It is calculated from the minimum and maximum values such that within 50 clicks you will have gone from one end to the other if scrolling. - The GUI has kept its flags intact. These are: SGF_0ISDISABLED: the variable might have a domain higher than zero, but a special value of nul is used as telling that feature is disabled. SGF_NOCOMMA: represent the number without any thousand-seperators SGF_MULTISTRING: internally the variable is a number, but its representation is a string based on a simple offset. SGF_NETWORK_ONLY: this setting can only be changed during network games SGF_CURRENCY: the variable represents money and will be shown in the local currency - - NOTE! The game is not compilable after this commit (because console hooks have not been updated)
Diffstat (limited to 'settings.c')
-rw-r--r--settings.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/settings.c b/settings.c
index 862155dc6..99eeee90c 100644
--- a/settings.c
+++ b/settings.c
@@ -1255,6 +1255,34 @@ void SaveToConfig(void)
ini_free(ini);
}
+const SettingDesc *GetSettingDescription(uint index)
+{
+ if (index >= lengthof(_patch_settings)) return NULL;
+ return &_patch_settings[index];
+}
+
+/* Top function to save the new value of an element of the Patches struct
+ * @param index offset in the SettingDesc array of the Patches struct which
+ * identifies the patch member we want to change
+ * @param object pointer to a valid patches struct that has its settings change.
+ * This only affects patch-members that are not needed to be the same on all
+ * clients in a network game.
+ * @param value new value of the patch */
+void SetPatchValue(uint index, const Patches *object, int32 value)
+{
+ const SettingDesc *sd = &_patch_settings[index];
+ /* If an item is player-based, we do not send it over the network
+ * (if any) to change. Also *hack*hack* we update the _newgame version
+ * of patches because changing a player-based setting in a game also
+ * changes its defaults. At least that is the convention we have chosen */
+ if (sd->save.conv & SLF_NETWORK_NO) {
+ void *var = ini_get_variable(&sd->save, object);
+ Write_ValidateSetting(var, sd, value);
+ } else {
+ DoCommandP(0, index, value, NULL, CMD_CHANGE_PATCH_SETTING);
+ }
+}
+
/** Save and load handler for patches/settings
* @param osd SettingDesc struct containing all information
* @param object can be either NULL in which case we load global variables or