2009-02-19 08:40:08 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2009-02-19 08:40:08 +01:00
|
|
|
/** @file ai_waypoint.cpp Implementation of AIWaypoint. */
|
|
|
|
|
|
|
|
#include "ai_waypoint.hpp"
|
|
|
|
#include "ai_rail.hpp"
|
2010-01-04 20:42:29 +01:00
|
|
|
#include "ai_marine.hpp"
|
2009-02-19 08:40:08 +01:00
|
|
|
#include "../../company_func.h"
|
2009-07-22 12:18:19 +02:00
|
|
|
#include "../../waypoint_base.h"
|
2009-02-19 08:40:08 +01:00
|
|
|
|
2009-08-01 00:30:54 +02:00
|
|
|
/* static */ bool AIWaypoint::IsValidWaypoint(StationID waypoint_id)
|
2009-02-19 08:40:08 +01:00
|
|
|
{
|
2009-05-18 18:21:28 +02:00
|
|
|
const Waypoint *wp = ::Waypoint::GetIfValid(waypoint_id);
|
2010-01-04 20:42:29 +01:00
|
|
|
return wp != NULL && (wp->owner == _current_company || wp->owner == OWNER_NONE);
|
2009-02-19 08:40:08 +01:00
|
|
|
}
|
|
|
|
|
2009-08-01 00:30:54 +02:00
|
|
|
/* static */ StationID AIWaypoint::GetWaypointID(TileIndex tile)
|
2009-02-19 08:40:08 +01:00
|
|
|
{
|
2010-01-04 20:42:29 +01:00
|
|
|
if (!AIRail::IsRailWaypointTile(tile) && !AIMarine::IsBuoyTile(tile)) return STATION_INVALID;
|
2009-02-19 08:40:08 +01:00
|
|
|
|
2009-07-22 10:59:57 +02:00
|
|
|
return ::GetStationIndex(tile);
|
2009-02-19 08:40:08 +01:00
|
|
|
}
|
2010-01-04 20:42:29 +01:00
|
|
|
|
|
|
|
/* static */ bool AIWaypoint::HasWaypointType(StationID waypoint_id, WaypointType waypoint_type)
|
|
|
|
{
|
|
|
|
if (!IsValidWaypoint(waypoint_id)) return false;
|
|
|
|
if (CountBits(waypoint_type) != 1) return false;
|
|
|
|
|
|
|
|
return (::Waypoint::Get(waypoint_id)->facilities & waypoint_type) != 0;
|
|
|
|
}
|