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 */ 7 8 /** @file script_gamesettings.hpp Everything to read game settings. */ 9 10 #ifndef SCRIPT_GAMESETTINGS_HPP 11 #define SCRIPT_GAMESETTINGS_HPP 12 13 #include "script_vehicle.hpp" 14 15 /** 16 * Class that handles all game settings related functions. 17 * @api ai game 18 * 19 * @note ScriptGameSettings::IsValid and ScriptGameSettings::GetValue are functions 20 * that rely on the settings as OpenTTD stores them in savegame and 21 * openttd.cfg. No guarantees can be given on the long term validity, 22 * consistency and stability of the names, values and value ranges. 23 * Using these settings can be dangerous and could cause issues in 24 * future versions. To make sure that a setting still exists in the 25 * current version you have to run ScriptGameSettings::IsValid before 26 * accessing it. 27 * 28 * @note The names of the setting for ScriptGameSettings::IsValid and 29 * ScriptGameSettings::GetValue are the same ones as those that are shown by 30 * the list_settings command in the in-game console. Settings that are 31 * string based are NOT supported and GameSettings::IsValid will return 32 * false for them. These settings will not be supported either because 33 * they have no relevance for the script (default client names, server IPs, 34 * etc.). 35 */ 36 class ScriptGameSettings : public ScriptObject { 37 public: 38 /** 39 * Is the given game setting a valid setting for this instance of OpenTTD? 40 * @param setting The setting to check for existence. 41 * @warning Results of this function are not governed by the API. This means 42 * that a setting that previously existed can be gone or has 43 * changed its name. 44 * @note Results achieved in the past offer no guarantee for the future. 45 * @return True if and only if the setting is valid. 46 */ 47 static bool IsValid(const char *setting); 48 49 /** 50 * Gets the value of the game setting. 51 * @param setting The setting to get the value of. 52 * @pre IsValid(setting). 53 * @warning Results of this function are not governed by the API. This means 54 * that the value of settings may be out of the expected range. It 55 * also means that a setting that previously existed can be gone or 56 * has changed its name/characteristics. 57 * @note Results achieved in the past offer no guarantee for the future. 58 * @return The value for the setting. 59 */ 60 static int32 GetValue(const char *setting); 61 62 /** 63 * Sets the value of the game setting. 64 * @param setting The setting to set the value of. 65 * @param value The value to set the setting to. 66 * @pre IsValid(setting). 67 * @return True if the action succeeded. 68 * @note Results achieved in the past offer no guarantee for the future. 69 * @api -ai 70 */ 71 static bool SetValue(const char *setting, int value); 72 73 /** 74 * Checks whether the given vehicle-type is disabled for companies. 75 * @param vehicle_type The vehicle-type to check. 76 * @return True if the vehicle-type is disabled. 77 * @api -game 78 */ 79 static bool IsDisabledVehicleType(ScriptVehicle::VehicleType vehicle_type); 80 }; 81 82 #endif /* SCRIPT_GAMESETTINGS_HPP */ 83