Update: Translations from eints
[openttd-github.git] / src / script / api / script_gamesettings.cpp
blob2749bb6773bfee1caa66e612f28ac7b0df35747c
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file script_gamesettings.cpp Implementation of ScriptGameSettings. */
10 #include "../../stdafx.h"
11 #include "script_gamesettings.hpp"
12 #include "../../settings_internal.h"
13 #include "../../settings_type.h"
14 #include "../../command_type.h"
15 #include "../../settings_cmd.h"
17 #include "../../safeguards.h"
19 /* static */ bool ScriptGameSettings::IsValid(const std::string &setting)
21 const SettingDesc *sd = GetSettingFromName(setting);
22 return sd != nullptr && sd->IsIntSetting();
25 /* static */ SQInteger ScriptGameSettings::GetValue(const std::string &setting)
27 if (!IsValid(setting)) return -1;
29 const SettingDesc *sd = GetSettingFromName(setting);
30 assert(sd != nullptr);
31 return sd->AsIntSetting()->Read(&_settings_game);
34 /* static */ bool ScriptGameSettings::SetValue(const std::string &setting, SQInteger value)
36 EnforceDeityOrCompanyModeValid(false);
37 if (!IsValid(setting)) return false;
39 const SettingDesc *sd = GetSettingFromName(setting);
40 assert(sd != nullptr);
42 if ((sd->flags & SF_NO_NETWORK_SYNC) != 0) return false;
44 value = Clamp<SQInteger>(value, INT32_MIN, INT32_MAX);
46 return ScriptObject::Command<CMD_CHANGE_SETTING>::Do(sd->GetName(), value);
49 /* static */ bool ScriptGameSettings::IsDisabledVehicleType(ScriptVehicle::VehicleType vehicle_type)
51 switch (vehicle_type) {
52 case ScriptVehicle::VT_RAIL: return _settings_game.ai.ai_disable_veh_train;
53 case ScriptVehicle::VT_ROAD: return _settings_game.ai.ai_disable_veh_roadveh;
54 case ScriptVehicle::VT_WATER: return _settings_game.ai.ai_disable_veh_ship;
55 case ScriptVehicle::VT_AIR: return _settings_game.ai.ai_disable_veh_aircraft;
56 default: return true;