mirror of https://github.com/OpenTTD/OpenTTD
(svn r6450) -Feature: Make the 'patch' console command available for offline use and for
online use for player-based settings.release/0.5
parent
2d329463bf
commit
dc93d63478
|
@ -1373,7 +1373,12 @@ DEF_CONSOLE_CMD(ConPatch)
|
||||||
IConsoleGetPatchSetting(argv[1]);
|
IConsoleGetPatchSetting(argv[1]);
|
||||||
} else {
|
} else {
|
||||||
uint32 val;
|
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;
|
return true;
|
||||||
|
@ -1459,6 +1464,7 @@ void IConsoleStdLibRegister(void)
|
||||||
IConsoleCmdRegister("cd", ConChangeDirectory);
|
IConsoleCmdRegister("cd", ConChangeDirectory);
|
||||||
IConsoleCmdRegister("pwd", ConPrintWorkingDirectory);
|
IConsoleCmdRegister("pwd", ConPrintWorkingDirectory);
|
||||||
IConsoleCmdRegister("clear", ConClearBuffer);
|
IConsoleCmdRegister("clear", ConClearBuffer);
|
||||||
|
IConsoleCmdRegister("patch", ConPatch);
|
||||||
|
|
||||||
IConsoleAliasRegister("dir", "ls");
|
IConsoleAliasRegister("dir", "ls");
|
||||||
IConsoleAliasRegister("del", "rm %+");
|
IConsoleAliasRegister("del", "rm %+");
|
||||||
|
@ -1514,8 +1520,6 @@ void IConsoleStdLibRegister(void)
|
||||||
IConsoleCmdRegister("unpause", ConUnPauseGame);
|
IConsoleCmdRegister("unpause", ConUnPauseGame);
|
||||||
IConsoleCmdHookAdd("unpause", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
IConsoleCmdHookAdd("unpause", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||||
|
|
||||||
IConsoleCmdRegister("patch", ConPatch);
|
|
||||||
|
|
||||||
/*** Networking variables ***/
|
/*** 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");
|
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);
|
IConsoleVarHookAdd("net_frame_freq", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||||
|
|
22
settings.c
22
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
|
* This only affects patch-members that are not needed to be the same on all
|
||||||
* clients in a network game.
|
* clients in a network game.
|
||||||
* @param value new value of the patch */
|
* @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];
|
const SettingDesc *sd = &_patch_settings[index];
|
||||||
/* If an item is player-based, we do not send it over the network
|
/* If an item is player-based, we do not send it over the network
|
||||||
|
@ -1594,9 +1594,15 @@ void SetPatchValue(uint index, const Patches *object, int32 value)
|
||||||
void *var2 = ini_get_variable(&sd->save, &_patches_newgame);
|
void *var2 = ini_get_variable(&sd->save, &_patches_newgame);
|
||||||
Write_ValidateSetting(var2, sd, value);
|
Write_ValidateSetting(var2, sd, value);
|
||||||
}
|
}
|
||||||
} else {
|
InvalidateWindow(WC_GAME_OPTIONS, 0);
|
||||||
DoCommandP(0, index, value, NULL, CMD_CHANGE_PATCH_SETTING);
|
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)
|
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
|
/* 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 */
|
* 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;
|
uint index;
|
||||||
const SettingDesc *sd = GetPatchFromName(name, &index);
|
const SettingDesc *sd = GetPatchFromName(name, &index);
|
||||||
const Patches *patches_ptr;
|
const Patches *patches_ptr;
|
||||||
|
@ -1622,14 +1629,15 @@ void IConsoleSetPatchSetting(const char *name, int32 value)
|
||||||
|
|
||||||
if (sd == NULL) {
|
if (sd == NULL) {
|
||||||
IConsolePrintF(_icolour_warn, "'%s' is an unknown patch setting.", name);
|
IConsolePrintF(_icolour_warn, "'%s' is an unknown patch setting.", name);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
|
patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
|
||||||
ptr = ini_get_variable(&sd->save, patches_ptr);
|
ptr = ini_get_variable(&sd->save, patches_ptr);
|
||||||
|
|
||||||
SetPatchValue(index, patches_ptr, value);
|
success = SetPatchValue(index, patches_ptr, value);
|
||||||
if (sd->desc.proc != NULL) sd->desc.proc(value);
|
if (success && sd->desc.proc != NULL) sd->desc.proc(value);
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IConsoleGetPatchSetting(const char *name)
|
void IConsoleGetPatchSetting(const char *name)
|
||||||
|
|
|
@ -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 */
|
/** The patch values that are used for new games and/or modified in config file */
|
||||||
extern Patches _patches_newgame;
|
extern Patches _patches_newgame;
|
||||||
|
|
||||||
void IConsoleSetPatchSetting(const char *name, int32 value);
|
bool IConsoleSetPatchSetting(const char *name, int32 value);
|
||||||
void IConsoleGetPatchSetting(const char *name);
|
void IConsoleGetPatchSetting(const char *name);
|
||||||
const SettingDesc *GetPatchFromName(const char *name, uint *i);
|
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 */
|
#endif /* SETTINGS_H */
|
||||||
|
|
Loading…
Reference in New Issue