Changeset - r14376:b8882984cdf2
[Not reviewed]
master
0 4 0
yexo - 15 years ago 2010-01-28 23:17:28
yexo@openttd.org
(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)
4 files changed with 37 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -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 %+");
 

	
 

	
src/settings.cpp
Show inline comments
 
@@ -1515,8 +1515,9 @@ CommandCost CmdChangeCompanySetting(Tile
 
 * @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 v
 
		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(co
 

	
 
/* 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
 
			return;
 
		}
 

	
 
		success = SetSettingValue(index, val);
 
		success = SetSettingValue(index, val, force_newgame);
 
	}
 

	
 
	if (!success) {
 
@@ -1706,8 +1713,9 @@ void IConsoleSetSetting(const char *name
 
/**
 
 * 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);
src/settings_func.h
Show inline comments
 
@@ -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();
src/settings_internal.h
Show inline comments
 
@@ -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);
 

	
0 comments (0 inline, 0 general)