00001 /* $Id: ai_waypoint.cpp 21888 2011-01-22 10:33:16Z rubidium $ */ 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 "ai_waypoint.hpp" 00014 #include "ai_rail.hpp" 00015 #include "ai_marine.hpp" 00016 #include "../../company_func.h" 00017 #include "../../waypoint_base.h" 00018 00019 /* static */ bool AIWaypoint::IsValidWaypoint(StationID waypoint_id) 00020 { 00021 const Waypoint *wp = ::Waypoint::GetIfValid(waypoint_id); 00022 return wp != NULL && (wp->owner == _current_company || wp->owner == OWNER_NONE); 00023 } 00024 00025 /* static */ StationID AIWaypoint::GetWaypointID(TileIndex tile) 00026 { 00027 if (!AIRail::IsRailWaypointTile(tile) && !AIMarine::IsBuoyTile(tile)) return STATION_INVALID; 00028 00029 return ::GetStationIndex(tile); 00030 } 00031 00032 /* static */ bool AIWaypoint::HasWaypointType(StationID waypoint_id, WaypointType waypoint_type) 00033 { 00034 if (!IsValidWaypoint(waypoint_id)) return false; 00035 if (!HasExactlyOneBit(waypoint_type)) return false; 00036 00037 return (::Waypoint::Get(waypoint_id)->facilities & waypoint_type) != 0; 00038 }