summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-01-28 23:17:28 +0000
committeryexo <yexo@openttd.org>2010-01-28 23:17:28 +0000
commitd75b9f1642f24dd3336437d818b41c2a6d295905 (patch)
treedb80d07dbbae17ffbfbb6507256a33d4db4a2905
parentfa01b25f740d92ffa74de4bc630ca42cdc8046a0 (diff)
downloadopenttd-d75b9f1642f24dd3336437d818b41c2a6d295905.tar.xz
(svn r18943) -Feature [FS#2885]: make it possible to change newgame settings from within a game via the console (use setting_newgame instead of setting)
-rw-r--r--src/console_cmds.cpp21
-rw-r--r--src/settings.cpp18
-rw-r--r--src/settings_func.h4
-rw-r--r--src/settings_internal.h2
4 files changed, 37 insertions, 8 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 6e50b50db..fd74b0c89 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -1713,6 +1713,25 @@ DEF_CONSOLE_CMD(ConSetting)
return true;
}
+DEF_CONSOLE_CMD(ConSettingNewgame)
+{
+ if (argc == 0) {
+ IConsoleHelp("Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'");
+ IConsoleHelp("Omitting <value> will print out the current value of the setting.");
+ return true;
+ }
+
+ if (argc == 1 || argc > 3) return false;
+
+ if (argc == 2) {
+ IConsoleGetSetting(argv[1], true);
+ } else {
+ IConsoleSetSetting(argv[1], argv[2], true);
+ }
+
+ return true;
+}
+
DEF_CONSOLE_CMD(ConListSettings)
{
if (argc == 0) {
@@ -1818,6 +1837,7 @@ void IConsoleStdLibRegister()
IConsoleCmdRegister("pwd", ConPrintWorkingDirectory);
IConsoleCmdRegister("clear", ConClearBuffer);
IConsoleCmdRegister("setting", ConSetting);
+ IConsoleCmdRegister("setting_newgame", ConSettingNewgame);
IConsoleCmdRegister("list_settings",ConListSettings);
IConsoleCmdRegister("gamelog", ConGamelogPrint);
@@ -1828,6 +1848,7 @@ void IConsoleStdLibRegister()
IConsoleAliasRegister("new_game", "newgame");
IConsoleAliasRegister("patch", "setting %+");
IConsoleAliasRegister("set", "setting %+");
+ IConsoleAliasRegister("set_newgame", "setting_newgame %+");
IConsoleAliasRegister("list_patches", "list_settings %+");
diff --git a/src/settings.cpp b/src/settings.cpp
index a136c3d75..ccc3c5c85 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1515,8 +1515,9 @@ CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32
* @param index offset in the SettingDesc array of the Settings struct which
* identifies the setting member we want to change
* @param value new value of the setting
+ * @param force_newgame force the newgame settings
*/
-bool SetSettingValue(uint index, int32 value)
+bool SetSettingValue(uint index, int32 value, bool force_newgame)
{
const SettingDesc *sd = &_settings[index];
/* If an item is company-based, we do not send it over the network
@@ -1536,6 +1537,12 @@ bool SetSettingValue(uint index, int32 value)
return true;
}
+ if (force_newgame) {
+ void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
+ Write_ValidateSetting(var2, sd, value);
+ return true;
+ }
+
/* send non-company-based settings over the network */
if (!_networking || (_networking && _network_server)) {
return DoCommandP(0, index, value, CMD_CHANGE_SETTING);
@@ -1661,7 +1668,7 @@ const SettingDesc *GetSettingFromName(const char *name, uint *i)
/* Those 2 functions need to be here, else we have to make some stuff non-static
* and besides, it is also better to keep stuff like this at the same place */
-void IConsoleSetSetting(const char *name, const char *value)
+void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
{
uint index;
const SettingDesc *sd = GetSettingFromName(name, &index);
@@ -1683,7 +1690,7 @@ void IConsoleSetSetting(const char *name, const char *value)
return;
}
- success = SetSettingValue(index, val);
+ success = SetSettingValue(index, val, force_newgame);
}
if (!success) {
@@ -1706,8 +1713,9 @@ void IConsoleSetSetting(const char *name, int value)
/**
* Output value of a specific setting to the console
* @param name Name of the setting to output its value
+ * @param force_newgame force the newgame settings
*/
-void IConsoleGetSetting(const char *name)
+void IConsoleGetSetting(const char *name, bool force_newgame)
{
char value[20];
uint index;
@@ -1719,7 +1727,7 @@ void IConsoleGetSetting(const char *name)
return;
}
- ptr = GetVariableAddress((_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game, &sd->save);
+ ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
if (sd->desc.cmd == SDT_STRING) {
IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, (const char *)ptr);
diff --git a/src/settings_func.h b/src/settings_func.h
index 29c9ad836..65fca20f8 100644
--- a/src/settings_func.h
+++ b/src/settings_func.h
@@ -15,9 +15,9 @@
#include "core/smallvec_type.hpp"
#include "company_type.h"
-void IConsoleSetSetting(const char *name, const char *value);
+void IConsoleSetSetting(const char *name, const char *value, bool force_newgame = false);
void IConsoleSetSetting(const char *name, int32 value);
-void IConsoleGetSetting(const char *name);
+void IConsoleGetSetting(const char *name, bool force_newgame = false);
void IConsoleListSettings(const char *prefilter);
void LoadFromConfig();
diff --git a/src/settings_internal.h b/src/settings_internal.h
index 316c43342..009e50f96 100644
--- a/src/settings_internal.h
+++ b/src/settings_internal.h
@@ -85,7 +85,7 @@ struct SettingDesc {
typedef SettingDesc SettingDescGlobVarList;
const SettingDesc *GetSettingFromName(const char *name, uint *i);
-bool SetSettingValue(uint index, int32 value);
+bool SetSettingValue(uint index, int32 value, bool force_newgame = false);
bool SetSettingValue(uint index, const char *value);
void SetCompanySetting(uint index, int32 value);