00001 /* $Id: script_waypoint.cpp 23632 2011-12-19 21:05:25Z 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_waypoint.hpp" 00014 #include "script_rail.hpp" 00015 #include "script_marine.hpp" 00016 #include "../../waypoint_base.h" 00017 00018 /* static */ bool ScriptWaypoint::IsValidWaypoint(StationID waypoint_id) 00019 { 00020 const Waypoint *wp = ::Waypoint::GetIfValid(waypoint_id); 00021 return wp != NULL && (wp->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY || wp->owner == OWNER_NONE); 00022 } 00023 00024 /* static */ StationID ScriptWaypoint::GetWaypointID(TileIndex tile) 00025 { 00026 if (!ScriptRail::IsRailWaypointTile(tile) && !ScriptMarine::IsBuoyTile(tile)) return STATION_INVALID; 00027 00028 return ::GetStationIndex(tile); 00029 } 00030 00031 /* static */ bool ScriptWaypoint::HasWaypointType(StationID waypoint_id, WaypointType waypoint_type) 00032 { 00033 if (!IsValidWaypoint(waypoint_id)) return false; 00034 if (!HasExactlyOneBit(waypoint_type)) return false; 00035 00036 return (::Waypoint::Get(waypoint_id)->facilities & waypoint_type) != 0; 00037 }