summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-09-14 23:26:58 +0000
committerDarkvater <darkvater@openttd.org>2006-09-14 23:26:58 +0000
commitdc93d63478d41e913bf86ca4ff84e37bf381c9f8 (patch)
tree986f5c07418dce4d799bc3ee9135d38693876a07
parent2d329463bf7b3d0146a64d19207721756837d924 (diff)
downloadopenttd-dc93d63478d41e913bf86ca4ff84e37bf381c9f8.tar.xz
(svn r6450) -Feature: Make the 'patch' console command available for offline use and for
online use for player-based settings.
-rw-r--r--console_cmds.c10
-rw-r--r--settings.c24
-rw-r--r--settings.h4
3 files changed, 25 insertions, 13 deletions
diff --git a/console_cmds.c b/console_cmds.c
index 5543ccb8d..8a44054e3 100644
--- a/console_cmds.c
+++ b/console_cmds.c
@@ -1373,7 +1373,12 @@ DEF_CONSOLE_CMD(ConPatch)
IConsoleGetPatchSetting(argv[1]);
} else {
uint32 val;
- if (GetArgumentInteger(&val, argv[2])) IConsoleSetPatchSetting(argv[1], val);
+
+ if (GetArgumentInteger(&val, argv[2])) {
+ if (!IConsoleSetPatchSetting(argv[1], val)) {
+ IConsoleError("This command/variable is only available to a network server.");
+ }
+ }
}
return true;
@@ -1459,6 +1464,7 @@ void IConsoleStdLibRegister(void)
IConsoleCmdRegister("cd", ConChangeDirectory);
IConsoleCmdRegister("pwd", ConPrintWorkingDirectory);
IConsoleCmdRegister("clear", ConClearBuffer);
+ IConsoleCmdRegister("patch", ConPatch);
IConsoleAliasRegister("dir", "ls");
IConsoleAliasRegister("del", "rm %+");
@@ -1514,8 +1520,6 @@ void IConsoleStdLibRegister(void)
IConsoleCmdRegister("unpause", ConUnPauseGame);
IConsoleCmdHookAdd("unpause", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
- IConsoleCmdRegister("patch", ConPatch);
-
/*** Networking variables ***/
IConsoleVarRegister("net_frame_freq", &_network_frame_freq, ICONSOLE_VAR_BYTE, "The amount of frames before a command will be (visibly) executed. Default value: 1");
IConsoleVarHookAdd("net_frame_freq", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
diff --git a/settings.c b/settings.c
index 31b8e26b4..46c51b19b 100644
--- a/settings.c
+++ b/settings.c
@@ -1579,7 +1579,7 @@ int32 CmdChangePatchSetting(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
* 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)
+bool 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
@@ -1591,12 +1591,18 @@ void SetPatchValue(uint index, const Patches *object, int32 value)
Write_ValidateSetting(var, sd, value);
if (_game_mode != GM_MENU) {
- void* var2 = ini_get_variable(&sd->save, &_patches_newgame);
+ void *var2 = ini_get_variable(&sd->save, &_patches_newgame);
Write_ValidateSetting(var2, sd, value);
}
- } else {
- DoCommandP(0, index, value, NULL, CMD_CHANGE_PATCH_SETTING);
+ InvalidateWindow(WC_GAME_OPTIONS, 0);
+ return true;
+ }
+
+ /* send non-player-based settings over the network */
+ if (!_networking || (_networking && _network_server)) {
+ return DoCommandP(0, index, value, NULL, CMD_CHANGE_PATCH_SETTING);
}
+ return false;
}
const SettingDesc *GetPatchFromName(const char *name, uint *i)
@@ -1613,8 +1619,9 @@ const SettingDesc *GetPatchFromName(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 IConsoleSetPatchSetting(const char *name, int32 value)
+bool IConsoleSetPatchSetting(const char *name, int32 value)
{
+ bool success;
uint index;
const SettingDesc *sd = GetPatchFromName(name, &index);
const Patches *patches_ptr;
@@ -1622,14 +1629,15 @@ void IConsoleSetPatchSetting(const char *name, int32 value)
if (sd == NULL) {
IConsolePrintF(_icolour_warn, "'%s' is an unknown patch setting.", name);
- return;
+ return true;
}
patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
ptr = ini_get_variable(&sd->save, patches_ptr);
- SetPatchValue(index, patches_ptr, value);
- if (sd->desc.proc != NULL) sd->desc.proc(value);
+ success = SetPatchValue(index, patches_ptr, value);
+ if (success && sd->desc.proc != NULL) sd->desc.proc(value);
+ return success;
}
void IConsoleGetPatchSetting(const char *name)
diff --git a/settings.h b/settings.h
index d1f9f7198..1eb26e2a0 100644
--- a/settings.h
+++ b/settings.h
@@ -78,9 +78,9 @@ static inline void *ini_get_variable(const SaveLoad *sld, const void *object)
/** The patch values that are used for new games and/or modified in config file */
extern Patches _patches_newgame;
-void IConsoleSetPatchSetting(const char *name, int32 value);
+bool IConsoleSetPatchSetting(const char *name, int32 value);
void IConsoleGetPatchSetting(const char *name);
const SettingDesc *GetPatchFromName(const char *name, uint *i);
-void SetPatchValue(uint index, const Patches *object, int32 value);
+bool SetPatchValue(uint index, const Patches *object, int32 value);
#endif /* SETTINGS_H */