(svn r23616) -Add: ScriptGameSettings::SetValue, to set gamesettings (GameScript only)

This commit is contained in:
truebrain
2011-12-19 20:57:43 +00:00
parent 9359c6fc47
commit e53b2f2ab0
3 changed files with 28 additions and 2 deletions

View File

@@ -12,6 +12,7 @@
#include "../../stdafx.h"
#include "script_gamesettings.hpp"
#include "../../settings_internal.h"
#include "../../command_type.h"
/* static */ bool ScriptGameSettings::IsValid(const char *setting)
{
@@ -24,8 +25,8 @@
{
if (!IsValid(setting)) return -1;
uint i;
const SettingDesc *sd = GetSettingFromName(setting, &i);
uint index;
const SettingDesc *sd = GetSettingFromName(setting, &index);
void *ptr = GetVariableAddress(&_settings_game, &sd->save);
if (sd->desc.cmd == SDT_BOOLX) return *(bool*)ptr;
@@ -33,6 +34,19 @@
return (int32)ReadValue(ptr, sd->save.conv);
}
/* static */ bool ScriptGameSettings::SetValue(const char *setting, int value)
{
if (!IsValid(setting)) return false;
uint index;
const SettingDesc *sd = GetSettingFromName(setting, &index);
if ((sd->save.conv & SLF_NO_NETWORK_SYNC) != 0) return false;
if (sd->desc.cmd != SDT_BOOLX && sd->desc.cmd != SDT_NUMX) return false;
return ScriptObject::DoCommand(0, index, value, CMD_CHANGE_SETTING);
}
/* static */ bool ScriptGameSettings::IsDisabledVehicleType(ScriptVehicle::VehicleType vehicle_type)
{
switch (vehicle_type) {