1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
8 /** @file script_waypoint.cpp Implementation of ScriptWaypoint. */
9 
10 #include "../../stdafx.h"
11 #include "script_waypoint.hpp"
12 #include "script_rail.hpp"
13 #include "script_marine.hpp"
14 #include "../../waypoint_base.h"
15 
16 #include "../../safeguards.h"
17 
IsValidWaypoint(StationID waypoint_id)18 /* static */ bool ScriptWaypoint::IsValidWaypoint(StationID waypoint_id)
19 {
20 	const Waypoint *wp = ::Waypoint::GetIfValid(waypoint_id);
21 	return wp != nullptr && (wp->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY || wp->owner == OWNER_NONE);
22 }
23 
GetWaypointID(TileIndex tile)24 /* static */ StationID ScriptWaypoint::GetWaypointID(TileIndex tile)
25 {
26 	if (!ScriptRail::IsRailWaypointTile(tile) && !ScriptMarine::IsBuoyTile(tile)) return STATION_INVALID;
27 
28 	return ::GetStationIndex(tile);
29 }
30 
HasWaypointType(StationID waypoint_id,WaypointType waypoint_type)31 /* static */ bool ScriptWaypoint::HasWaypointType(StationID waypoint_id, WaypointType waypoint_type)
32 {
33 	if (!IsValidWaypoint(waypoint_id)) return false;
34 	if (!HasExactlyOneBit(waypoint_type)) return false;
35 
36 	return (::Waypoint::Get(waypoint_id)->facilities & waypoint_type) != 0;
37 }
38