(svn r6450) -Feature: Make the 'patch' console command available for offline use and for

online use for player-based settings.
pull/155/head
Darkvater 18 years ago
parent 8515079501
commit c34691d2b0

@ -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);

@ -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)

@ -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 */

Loading…
Cancel
Save