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.hpp Everything to query and build waypoints. */
9 
10 #ifndef SCRIPT_WAYPOINT_HPP
11 #define SCRIPT_WAYPOINT_HPP
12 
13 #include "script_basestation.hpp"
14 #include "script_error.hpp"
15 #include "../../station_type.h"
16 
17 /**
18  * Class that handles all waypoint related functions.
19  * @api ai game
20  */
21 class ScriptWaypoint : public ScriptBaseStation {
22 public:
23 	/**
24 	 * All waypoint related error messages.
25 	 */
26 	enum ErrorMessages {
27 		/** Base for waypoint related errors */
28 		ERR_WAYPOINT_BASE = ScriptError::ERR_CAT_WAYPOINT << ScriptError::ERR_CAT_BIT_SIZE,
29 
30 		/** The waypoint is build too close to another waypoint */
31 		ERR_WAYPOINT_TOO_CLOSE_TO_ANOTHER_WAYPOINT, // [STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT]
32 
33 		/** The waypoint would join more than one existing waypoint together. */
34 		ERR_WAYPOINT_ADJOINS_MULTIPLE_WAYPOINTS,    // [STR_ERROR_WAYPOINT_ADJOINS_MORE_THAN_ONE_EXISTING]
35 	};
36 
37 	/**
38 	 * Type of waypoints known in the game.
39 	 */
40 	enum WaypointType {
41 		/* Note: these values represent part of the in-game StationFacility enum */
42 		WAYPOINT_RAIL      = (int)::FACIL_TRAIN, ///< Rail waypoint
43 		WAYPOINT_BUOY      = (int)::FACIL_DOCK,  ///< Buoy
44 		WAYPOINT_ANY       = WAYPOINT_RAIL | WAYPOINT_BUOY, ///< All waypoint types
45 	};
46 
47 	/**
48 	 * Checks whether the given waypoint is valid and owned by you.
49 	 * @param waypoint_id The waypoint to check.
50 	 * @return True if and only if the waypoint is valid.
51 	 */
52 	static bool IsValidWaypoint(StationID waypoint_id);
53 
54 	/**
55 	 * Get the StationID of a tile.
56 	 * @param tile The tile to find the StationID of.
57 	 * @pre ScriptRail::IsRailWaypointTile(tile).
58 	 * @return StationID of the waypoint.
59 	 */
60 	static StationID GetWaypointID(TileIndex tile);
61 
62 	/**
63 	 * Check if any part of the waypoint contains a waypoint of the type waypoint_type
64 	 * @param waypoint_id The waypoint to look at.
65 	 * @param waypoint_type The WaypointType to look for.
66 	 * @return True if the waypoint has a waypoint part of the type waypoint_type.
67 	 */
68 	static bool HasWaypointType(StationID waypoint_id, WaypointType waypoint_type);
69 };
70 
71 DECLARE_ENUM_AS_BIT_SET(ScriptWaypoint::WaypointType)
72 
73 #endif /* SCRIPT_WAYPOINT_HPP */
74