mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-10 00:11:31 +00:00
(svn r23616) -Add: ScriptGameSettings::SetValue, to set gamesettings (GameScript only)
This commit is contained in:
parent
9359c6fc47
commit
e53b2f2ab0
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -61,6 +61,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.
|
||||
|
Loading…
Reference in New Issue
Block a user