summaryrefslogtreecommitdiff
path: root/src/script/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/game/game_gamesettings.hpp.sq1
-rw-r--r--src/script/api/script_gamesettings.cpp18
-rw-r--r--src/script/api/script_gamesettings.hpp11
3 files changed, 28 insertions, 2 deletions
diff --git a/src/script/api/game/game_gamesettings.hpp.sq b/src/script/api/game/game_gamesettings.hpp.sq
index 13e1b06dd..9aeba7199 100644
--- a/src/script/api/game/game_gamesettings.hpp.sq
+++ b/src/script/api/game/game_gamesettings.hpp.sq
@@ -23,6 +23,7 @@ void SQGSGameSettings_Register(Squirrel *engine)
SQGSGameSettings.DefSQStaticMethod(engine, &ScriptGameSettings::IsValid, "IsValid", 2, "..");
SQGSGameSettings.DefSQStaticMethod(engine, &ScriptGameSettings::GetValue, "GetValue", 2, "..");
+ SQGSGameSettings.DefSQStaticMethod(engine, &ScriptGameSettings::SetValue, "SetValue", 3, "..i");
SQGSGameSettings.PostRegister(engine);
}
diff --git a/src/script/api/script_gamesettings.cpp b/src/script/api/script_gamesettings.cpp
index 839486b8b..928ec9a96 100644
--- a/src/script/api/script_gamesettings.cpp
+++ b/src/script/api/script_gamesettings.cpp
@@ -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) {
diff --git a/src/script/api/script_gamesettings.hpp b/src/script/api/script_gamesettings.hpp
index 217748571..40630a4e7 100644
--- a/src/script/api/script_gamesettings.hpp
+++ b/src/script/api/script_gamesettings.hpp
@@ -62,6 +62,17 @@ public:
static int32 GetValue(const char *setting);
/**
+ * Sets the value of the game setting.
+ * @param setting The setting to set the value of.
+ * @param value The value to set the setting to.
+ * @pre IsValid(setting).
+ * @return True if the action succeeded.
+ * @note Results achieved in the past offer no gurantee for the future.
+ * @api -ai
+ */
+ static bool SetValue(const char *setting, int value);
+
+ /**
* Checks whether the given vehicle-type is disabled for AIs.
* @param vehicle_type The vehicle-type to check.
* @return True if the vehicle-type is disabled.