script_gamesettings.cpp

Go to the documentation of this file.
00001 /* $Id$ */
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 
00016 /* static */ bool ScriptGameSettings::IsValid(const char *setting)
00017 {
00018   uint i;
00019   const SettingDesc *sd = GetSettingFromName(setting, &i);
00020   return sd != NULL && sd->desc.cmd != SDT_STRING;
00021 }
00022 
00023 /* static */ int32 ScriptGameSettings::GetValue(const char *setting)
00024 {
00025   if (!IsValid(setting)) return -1;
00026 
00027   uint i;
00028   const SettingDesc *sd = GetSettingFromName(setting, &i);
00029 
00030   void *ptr = GetVariableAddress(&_settings_game, &sd->save);
00031   if (sd->desc.cmd == SDT_BOOLX) return *(bool*)ptr;
00032 
00033   return (int32)ReadValue(ptr, sd->save.conv);
00034 }
00035 
00036 /* static */ bool ScriptGameSettings::IsDisabledVehicleType(ScriptVehicle::VehicleType vehicle_type)
00037 {
00038   switch (vehicle_type) {
00039     case ScriptVehicle::VT_RAIL:  return _settings_game.ai.ai_disable_veh_train;
00040     case ScriptVehicle::VT_ROAD:  return _settings_game.ai.ai_disable_veh_roadveh;
00041     case ScriptVehicle::VT_WATER: return _settings_game.ai.ai_disable_veh_ship;
00042     case ScriptVehicle::VT_AIR:   return _settings_game.ai.ai_disable_veh_aircraft;
00043     default:                       return true;
00044   }
00045 }