00001 /* $Id: script_gamesettings.cpp 23616 2011-12-19 20:57:43Z truebrain $ */ 00002 00003 /* 00004 * This file is part of OpenTTD. 00005 * 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. 00006 * 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. 00007 * 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/>. 00008 */ 00009 00012 #include "../../stdafx.h" 00013 #include "script_gamesettings.hpp" 00014 #include "../../settings_internal.h" 00015 #include "../../command_type.h" 00016 00017 /* static */ bool ScriptGameSettings::IsValid(const char *setting) 00018 { 00019 uint i; 00020 const SettingDesc *sd = GetSettingFromName(setting, &i); 00021 return sd != NULL && sd->desc.cmd != SDT_STRING; 00022 } 00023 00024 /* static */ int32 ScriptGameSettings::GetValue(const char *setting) 00025 { 00026 if (!IsValid(setting)) return -1; 00027 00028 uint index; 00029 const SettingDesc *sd = GetSettingFromName(setting, &index); 00030 00031 void *ptr = GetVariableAddress(&_settings_game, &sd->save); 00032 if (sd->desc.cmd == SDT_BOOLX) return *(bool*)ptr; 00033 00034 return (int32)ReadValue(ptr, sd->save.conv); 00035 } 00036 00037 /* static */ bool ScriptGameSettings::SetValue(const char *setting, int value) 00038 { 00039 if (!IsValid(setting)) return false; 00040 00041 uint index; 00042 const SettingDesc *sd = GetSettingFromName(setting, &index); 00043 00044 if ((sd->save.conv & SLF_NO_NETWORK_SYNC) != 0) return false; 00045 if (sd->desc.cmd != SDT_BOOLX && sd->desc.cmd != SDT_NUMX) return false; 00046 00047 return ScriptObject::DoCommand(0, index, value, CMD_CHANGE_SETTING); 00048 } 00049 00050 /* static */ bool ScriptGameSettings::IsDisabledVehicleType(ScriptVehicle::VehicleType vehicle_type) 00051 { 00052 switch (vehicle_type) { 00053 case ScriptVehicle::VT_RAIL: return _settings_game.ai.ai_disable_veh_train; 00054 case ScriptVehicle::VT_ROAD: return _settings_game.ai.ai_disable_veh_roadveh; 00055 case ScriptVehicle::VT_WATER: return _settings_game.ai.ai_disable_veh_ship; 00056 case ScriptVehicle::VT_AIR: return _settings_game.ai.ai_disable_veh_aircraft; 00057 default: return true; 00058 } 00059 }