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_road.hpp Everything to query and build roads. */
9 
10 #ifndef SCRIPT_ROAD_HPP
11 #define SCRIPT_ROAD_HPP
12 
13 #include "script_tile.hpp"
14 #include "../../../road.h"
15 
16 /**
17  * Class that handles all road related functions.
18  * @api ai game
19  */
20 class ScriptRoad : public ScriptObject {
21 public:
22 	/**
23 	 * All road related error messages.
24 	 */
25 	enum ErrorMessages {
26 		/** Base for road building / maintaining errors */
27 		ERR_ROAD_BASE = ScriptError::ERR_CAT_ROAD << ScriptError::ERR_CAT_BIT_SIZE,
28 
29 		/** Road works are in progress */
30 		ERR_ROAD_WORKS_IN_PROGRESS,                   // [STR_ERROR_ROAD_WORKS_IN_PROGRESS]
31 
32 		/** Drive through is in the wrong direction */
33 		ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION,       // [STR_ERROR_DRIVE_THROUGH_DIRECTION]
34 
35 		/** Drive through roads can't be build on town owned roads */
36 		ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD,           // [STR_ERROR_DRIVE_THROUGH_ON_TOWN_ROAD]
37 
38 		/** One way roads can't have junctions */
39 		ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS, // [STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION]
40 
41 		/** This roadtype cannot have crossings */
42 		ERR_ROADTYPE_DISALLOWS_CROSSING,              // [STR_ERROR_CROSSING_DISALLOWED_ROAD]
43 
44 		/** No suitable road could be found */
45 		ERR_UNSUITABLE_ROAD,                          // [STR_ERROR_NO_SUITABLE_ROAD, STR_ERROR_NO_SUITABLE_TRAMWAY]
46 	};
47 
48 	/**
49 	 * Types of road known to the game.
50 	 */
51 	enum RoadType {
52 		/* Note: these values represent part of the in-game static values */
53 		ROADTYPE_ROAD    = ::ROADTYPE_ROAD,    ///< Build road objects.
54 		ROADTYPE_TRAM    = ::ROADTYPE_TRAM,    ///< Build tram objects.
55 
56 		/* Custom added value, only valid for this API */
57 		ROADTYPE_INVALID = -1,                 ///< Invalid RoadType.
58 	};
59 
60 	/**
61 	 * Road/tram types
62 	 */
63 	enum RoadTramTypes : uint8 {
64 		ROADTRAMTYPES_ROAD = ::RTTB_ROAD, ///< Road road types.
65 		ROADTRAMTYPES_TRAM = ::RTTB_TRAM, ///< Tram road types.
66 	};
67 
68 	/**
69 	 * Type of road station.
70 	 */
71 	enum RoadVehicleType {
72 		ROADVEHTYPE_BUS,   ///< Build objects useable for busses and passenger trams
73 		ROADVEHTYPE_TRUCK, ///< Build objects useable for trucks and cargo trams
74 	};
75 
76 	/**
77 	 * Types of road-related objects in the game.
78 	 */
79 	enum BuildType {
80 		BT_ROAD,       ///< Build a piece of road
81 		BT_DEPOT,      ///< Build a road depot
82 		BT_BUS_STOP,   ///< Build a bus stop
83 		BT_TRUCK_STOP, ///< Build a truck stop
84 	};
85 
86 	/**
87 	 * Get the name of a road type.
88 	 * @param road_type The road type to get the name of.
89 	 * @pre IsRoadTypeAvailable(road_type).
90 	 * @return The name the road type has.
91 	 */
92 	static char *GetName(RoadType road_type);
93 
94 	/**
95 	 * Determines whether a busstop or a truckstop is needed to transport a certain cargo.
96 	 * @param cargo_type The cargo to test.
97 	 * @pre ScriptCargo::IsValidCargo(cargo_type).
98 	 * @return The road vehicle type needed to transport the cargo.
99 	 */
100 	static RoadVehicleType GetRoadVehicleTypeForCargo(CargoID cargo_type);
101 
102 	/**
103 	 * Checks whether the given tile is actually a tile with road that can be
104 	 *  used to traverse a tile. This excludes road depots and 'normal' road
105 	 *  stations, but includes drive through stations.
106 	 * @param tile The tile to check.
107 	 * @pre ScriptMap::IsValidTile(tile).
108 	 * @return True if and only if the tile has road.
109 	 */
110 	static bool IsRoadTile(TileIndex tile);
111 
112 	/**
113 	 * Checks whether the given tile is actually a tile with a road depot.
114 	 * @param tile The tile to check.
115 	 * @pre ScriptMap::IsValidTile(tile).
116 	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
117 	 * @return True if and only if the tile has a road depot.
118 	 */
119 	static bool IsRoadDepotTile(TileIndex tile);
120 
121 	/**
122 	 * Checks whether the given tile is actually a tile with a road station.
123 	 * @param tile The tile to check.
124 	 * @pre ScriptMap::IsValidTile(tile).
125 	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
126 	 * @return True if and only if the tile has a road station.
127 	 */
128 	static bool IsRoadStationTile(TileIndex tile);
129 
130 	/**
131 	 * Checks whether the given tile is actually a tile with a drive through
132 	 *  road station.
133 	 * @param tile The tile to check.
134 	 * @pre ScriptMap::IsValidTile(tile).
135 	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
136 	 * @return True if and only if the tile has a drive through road station.
137 	 */
138 	static bool IsDriveThroughRoadStationTile(TileIndex tile);
139 
140 	/**
141 	 * Check if a given RoadType is available.
142 	 * @param road_type The RoadType to check for.
143 	 * @game @pre Valid ScriptCompanyMode active in scope.
144 	 * @return True if this RoadType can be used.
145 	 */
146 	static bool IsRoadTypeAvailable(RoadType road_type);
147 
148 	/**
149 	 * Get the current RoadType set for all ScriptRoad functions.
150 	 * @return The RoadType currently set.
151 	 */
152 	static RoadType GetCurrentRoadType();
153 
154 	/**
155 	 * Set the RoadType for all further ScriptRoad functions.
156 	 * @param road_type The RoadType to set.
157 	 */
158 	static void SetCurrentRoadType(RoadType road_type);
159 
160 	/**
161 	 * Check if a road vehicle built for a road type can run on another road type.
162 	 * @param engine_road_type The road type the road vehicle is built for.
163 	 * @param track_road_type The road type you want to check.
164 	 * @pre ScriptRoad::IsRoadTypeAvailable(engine_road_type).
165 	 * @pre ScriptRoad::IsRoadTypeAvailable(road_road_type).
166 	 * @return Whether a road vehicle built for 'engine_road_type' can run on 'road_road_type'.
167 	 */
168 	static bool RoadVehCanRunOnRoad(ScriptRoad::RoadType engine_road_type, ScriptRoad::RoadType road_road_type);
169 
170 	/**
171 	 * Check if a road vehicle built for a road type has power on another road type.
172 	 * @param engine_road_type The road type the road vehicle is built for.
173 	 * @param road_road_type The road type you want to check.
174 	 * @pre ScriptRoad::IsRoadTypeAvailable(engine_road_type).
175 	 * @pre ScriptRoad::IsRoadTypeAvailable(road_road_type).
176 	 * @return Whether a road vehicle built for 'engine_road_type' has power on 'road_road_type'.
177 	 */
178 	static bool RoadVehHasPowerOnRoad(ScriptRoad::RoadType engine_road_type, ScriptRoad::RoadType road_road_type);
179 
180 
181 	/**
182 	 * Convert the road on all tiles within a rectangle to another RoadType.
183 	 * @param start_tile One corner of the rectangle.
184 	 * @param end_tile The opposite corner of the rectangle.
185 	 * @param road_type The RoadType you want to convert.
186 	 * @pre ScriptMap::IsValidTile(start_tile).
187 	 * @pre ScriptMap::IsValidTile(end_tile).
188 	 * @pre IsRoadTypeAvailable(road_type).
189 	 * @game @pre Valid ScriptCompanyMode active in scope.
190 	 * @exception ScriptRoad::ERR_UNSUITABLE_ROAD
191 	 * @return Whether at least some road has been converted successfully.
192 	 */
193 	static bool ConvertRoadType(TileIndex start_tile, TileIndex end_tile, RoadType road_type);
194 
195 	/**
196 	 * Check if a given tile has RoadType.
197 	 * @param tile The tile to check.
198 	 * @param road_type The RoadType to check for.
199 	 * @pre ScriptMap::IsValidTile(tile).
200 	 * @pre IsRoadTypeAvailable(road_type).
201 	 * @return True if the tile contains a RoadType object.
202 	 */
203 	static bool HasRoadType(TileIndex tile, RoadType road_type);
204 
205 	/**
206 	 * Checks whether the given tiles are directly connected, i.e. whether
207 	 *  a road vehicle can travel from the center of the first tile to the
208 	 * center of the second tile.
209 	 * @param tile_from The source tile.
210 	 * @param tile_to The destination tile.
211 	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
212 	 * @pre ScriptMap::IsValidTile(tile_from).
213 	 * @pre ScriptMap::IsValidTile(tile_to).
214 	 * @pre 'tile_from' and 'tile_to' are directly neighbouring tiles.
215 	 * @return True if and only if a road vehicle can go from tile_from to tile_to.
216 	 */
217 	static bool AreRoadTilesConnected(TileIndex tile_from, TileIndex tile_to);
218 
219 	/**
220 	 * Lookup function for building road parts independent of whether the
221 	 *  "building on slopes" setting is enabled or not.
222 	 *  This implementation can be used for abstract reasoning about a tile as
223 	 *  it needs the slope and existing road parts of the tile as information.
224 	 * @param slope The slope of the tile to examine.
225 	 * @param existing An array with the existing neighbours in the same format
226 	 *                 as "start" and "end", e.g. ScriptMap.GetTileIndex(0, 1).
227 	 *                 As a result of this all values of the existing array
228 	 *                 must be of type integer.
229 	 * @param start The tile from where the 'tile to be considered' will be
230 	 *              entered. This is a relative tile, so valid parameters are:
231 	 *              ScriptMap.GetTileIndex(0, 1), ScriptMap.GetTileIndex(0, -1),
232 	 *              ScriptMap.GetTileIndex(1, 0) and ScriptMap.GetTileIndex(-1, 0).
233 	 * @param end The tile from where the 'tile to be considered' will be
234 	 *            exited. This is a relative tile, sovalid parameters are:
235 	 *              ScriptMap.GetTileIndex(0, 1), ScriptMap.GetTileIndex(0, -1),
236 	 *              ScriptMap.GetTileIndex(1, 0) and ScriptMap.GetTileIndex(-1, 0).
237 	 * @pre start != end.
238 	 * @pre slope must be a valid slope, i.e. one specified in ScriptTile::Slope.
239 	 * @note Passing data that would be invalid in-game, e.g. existing containing
240 	 *       road parts that can not be build on a tile with the given slope,
241 	 *       does not necessarily means that -1 is returned, i.e. not all
242 	 *       preconditions written here or assumed by the game are extensively
243 	 *       checked to make sure the data entered is valid.
244 	 * @return 0 when the build parts do not connect, 1 when they do connect once
245 	 *         they are build or 2 when building the first part automatically
246 	 *         builds the second part. -1 means the preconditions are not met.
247 	 */
248 	static int32 CanBuildConnectedRoadParts(ScriptTile::Slope slope, struct Array *existing, TileIndex start, TileIndex end);
249 
250 	/**
251 	 * Lookup function for building road parts independent of whether the
252 	 *  "building on slopes" setting is enabled or not.
253 	 *  This implementation can be used for reasoning about an existing tile.
254 	 * @param tile The tile to examine.
255 	 * @param start The tile from where "tile" will be entered.
256 	 * @param end The tile from where "tile" will be exited.
257 	 * @pre start != end.
258 	 * @pre tile != start.
259 	 * @pre tile != end.
260 	 * @pre ScriptMap.IsValidTile(tile).
261 	 * @pre ScriptMap.IsValidTile(start).
262 	 * @pre ScriptMap.IsValidTile(end).
263 	 * @pre ScriptMap.GetDistanceManhattanToTile(tile, start) == 1.
264 	 * @pre ScriptMap.GetDistanceManhattanToTile(tile, end) == 1.
265 	 * @return 0 when the build parts do not connect, 1 when they do connect once
266 	 *         they are build or 2 when building the first part automatically
267 	 *         builds the second part. -1 means the preconditions are not met.
268 	 */
269 	static int32 CanBuildConnectedRoadPartsHere(TileIndex tile, TileIndex start, TileIndex end);
270 
271 	/**
272 	 * Count how many neighbours are road.
273 	 * @param tile The tile to check on.
274 	 * @pre ScriptMap::IsValidTile(tile).
275 	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
276 	 * @return 0 means no neighbour road; max value is 4.
277 	 */
278 	static int32 GetNeighbourRoadCount(TileIndex tile);
279 
280 	/**
281 	 * Gets the tile in front of a road depot.
282 	 * @param depot The road depot tile.
283 	 * @pre IsRoadDepotTile(depot).
284 	 * @return The tile in front of the depot.
285 	 */
286 	static TileIndex GetRoadDepotFrontTile(TileIndex depot);
287 
288 	/**
289 	 * Gets the tile in front of a road station.
290 	 * @param station The road station tile.
291 	 * @pre IsRoadStationTile(station).
292 	 * @return The tile in front of the road station.
293 	 */
294 	static TileIndex GetRoadStationFrontTile(TileIndex station);
295 
296 	/**
297 	 * Gets the tile at the back of a drive through road station.
298 	 *  So, one side of the drive through station is retrieved with
299 	 *  GetTileInFrontOfStation, the other with this function.
300 	 * @param station The road station tile.
301 	 * @pre IsDriveThroughRoadStationTile(station).
302 	 * @return The tile at the back of the drive through road station.
303 	 */
304 	static TileIndex GetDriveThroughBackTile(TileIndex station);
305 
306 	/**
307 	 * Builds a road from the center of tile start to the center of tile end.
308 	 * @param start The start tile of the road.
309 	 * @param end The end tile of the road.
310 	 * @pre 'start' is not equal to 'end'.
311 	 * @pre ScriptMap::IsValidTile(start).
312 	 * @pre ScriptMap::IsValidTile(end).
313 	 * @pre 'start' and 'end' are in a straight line, i.e.
314 	 *  ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or
315 	 *  ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
316 	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
317 	 * @exception ScriptError::ERR_ALREADY_BUILT
318 	 * @exception ScriptError::ERR_LAND_SLOPED_WRONG
319 	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
320 	 * @exception ScriptRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS
321 	 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
322 	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
323 	 * @note Construction will fail if an obstacle is found between the start and end tiles.
324 	 * @game @note Building a piece of road (without CompanyMode) results in a piece of road owned by towns.
325 	 * @return Whether the road has been/can be build or not.
326 	 */
327 	static bool BuildRoad(TileIndex start, TileIndex end);
328 
329 	/**
330 	 * Builds a one-way road from the center of tile start to the center
331 	 *  of tile end. If the road already exists, it is made one-way road.
332 	 *  If the road already exists and is already one-way in this direction,
333 	 *  the road is made two-way again. If the road already exists but is
334 	 *  one-way in the other direction, it's made a 'no'-way road (it's
335 	 *  forbidden to enter the tile from any direction).
336 	 * @param start The start tile of the road.
337 	 * @param end The end tile of the road.
338 	 * @pre 'start' is not equal to 'end'.
339 	 * @pre ScriptMap::IsValidTile(start).
340 	 * @pre ScriptMap::IsValidTile(end).
341 	 * @pre 'start' and 'end' are in a straight line, i.e.
342 	 *  ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or
343 	 *  ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
344 	 * @pre GetCurrentRoadType() == ROADTYPE_ROAD.
345 	 * @game @pre Valid ScriptCompanyMode active in scope.
346 	 * @exception ScriptError::ERR_ALREADY_BUILT
347 	 * @exception ScriptError::ERR_LAND_SLOPED_WRONG
348 	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
349 	 * @exception ScriptRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS
350 	 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
351 	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
352 	 * @note Construction will fail if an obstacle is found between the start and end tiles.
353 	 * @return Whether the road has been/can be build or not.
354 	 */
355 	static bool BuildOneWayRoad(TileIndex start, TileIndex end);
356 
357 	/**
358 	 * Builds a road from the edge of tile start to the edge of tile end (both
359 	 *  included).
360 	 * @param start The start tile of the road.
361 	 * @param end The end tile of the road.
362 	 * @pre 'start' is not equal to 'end'.
363 	 * @pre ScriptMap::IsValidTile(start).
364 	 * @pre ScriptMap::IsValidTile(end).
365 	 * @pre 'start' and 'end' are in a straight line, i.e.
366 	 *  ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or
367 	 *  ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
368 	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
369 	 * @exception ScriptError::ERR_ALREADY_BUILT
370 	 * @exception ScriptError::ERR_LAND_SLOPED_WRONG
371 	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
372 	 * @exception ScriptRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS
373 	 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
374 	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
375 	 * @note Construction will fail if an obstacle is found between the start and end tiles.
376 	 * @game @note Building a piece of road (without CompanyMode) results in a piece of road owned by towns.
377 	 * @return Whether the road has been/can be build or not.
378 	 */
379 	static bool BuildRoadFull(TileIndex start, TileIndex end);
380 
381 	/**
382 	 * Builds a one-way road from the edge of tile start to the edge of tile end
383 	 *  (both included). If the road already exists, it is made one-way road.
384 	 *  If the road already exists and is already one-way in this direction,
385 	 *  the road is made two-way again. If the road already exists but is
386 	 *  one-way in the other direction, it's made a 'no'-way road (it's
387 	 *  forbidden to enter the tile from any direction).
388 	 * @param start The start tile of the road.
389 	 * @param start The start tile of the road.
390 	 * @param end The end tile of the road.
391 	 * @pre 'start' is not equal to 'end'.
392 	 * @pre ScriptMap::IsValidTile(start).
393 	 * @pre ScriptMap::IsValidTile(end).
394 	 * @pre 'start' and 'end' are in a straight line, i.e.
395 	 *  ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or
396 	 *  ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
397 	 * @pre GetCurrentRoadType() == ROADTYPE_ROAD.
398 	 * @game @pre Valid ScriptCompanyMode active in scope.
399 	 * @exception ScriptError::ERR_ALREADY_BUILT
400 	 * @exception ScriptError::ERR_LAND_SLOPED_WRONG
401 	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
402 	 * @exception ScriptRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS
403 	 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
404 	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
405 	 * @note Construction will fail if an obstacle is found between the start and end tiles.
406 	 * @return Whether the road has been/can be build or not.
407 	 */
408 	static bool BuildOneWayRoadFull(TileIndex start, TileIndex end);
409 
410 	/**
411 	 * Builds a road depot.
412 	 * @param tile Place to build the depot.
413 	 * @param front The tile exactly in front of the depot.
414 	 * @pre ScriptMap::IsValidTile(tile).
415 	 * @pre ScriptMap::IsValidTile(front).
416 	 * @pre 'tile' is not equal to 'front', but in a straight line of it.
417 	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
418 	 * @game @pre Valid ScriptCompanyMode active in scope.
419 	 * @exception ScriptError::ERR_FLAT_LAND_REQUIRED
420 	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
421 	 * @return Whether the road depot has been/can be build or not.
422 	 */
423 	static bool BuildRoadDepot(TileIndex tile, TileIndex front);
424 
425 	/**
426 	 * Builds a road bus or truck station.
427 	 * @param tile Place to build the station.
428 	 * @param front The tile exactly in front of the station.
429 	 * @param road_veh_type Whether to build a truck or bus station.
430 	 * @param station_id The station to join, ScriptStation::STATION_NEW or ScriptStation::STATION_JOIN_ADJACENT.
431 	 * @pre ScriptMap::IsValidTile(tile).
432 	 * @pre ScriptMap::IsValidTile(front).
433 	 * @pre 'tile' is not equal to 'front', but in a straight line of it.
434 	 * @pre station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id).
435 	 * @pre GetCurrentRoadType() == ROADTYPE_ROAD.
436 	 * @game @pre Valid ScriptCompanyMode active in scope.
437 	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
438 	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
439 	 * @exception ScriptError::ERR_FLAT_LAND_REQUIRED
440 	 * @exception ScriptRoad::ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION
441 	 * @exception ScriptRoad::ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD
442 	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
443 	 * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION
444 	 * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS
445 	 * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN
446 	 * @return Whether the station has been/can be build or not.
447 	 */
448 	static bool BuildRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id);
449 
450 	/**
451 	 * Builds a drive-through road bus or truck station.
452 	 * @param tile Place to build the station.
453 	 * @param front A tile on the same axis with 'tile' as the station shall be oriented.
454 	 * @param road_veh_type Whether to build a truck or bus station.
455 	 * @param station_id The station to join, ScriptStation::STATION_NEW or ScriptStation::STATION_JOIN_ADJACENT.
456 	 * @pre ScriptMap::IsValidTile(tile).
457 	 * @pre ScriptMap::IsValidTile(front).
458 	 * @pre 'tile' is not equal to 'front', but in a straight line of it.
459 	 * @pre station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id).
460 	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
461 	 * @game @pre Valid ScriptCompanyMode active in scope.
462 	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
463 	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
464 	 * @exception ScriptError::ERR_FLAT_LAND_REQUIRED
465 	 * @exception ScriptRoad::ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION
466 	 * @exception ScriptRoad::ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD
467 	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
468 	 * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION
469 	 * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS
470 	 * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN
471 	 * @return Whether the station has been/can be build or not.
472 	 */
473 	static bool BuildDriveThroughRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id);
474 
475 	/**
476 	 * Removes a road from the center of tile start to the center of tile end.
477 	 * @param start The start tile of the road.
478 	 * @param end The end tile of the road.
479 	 * @pre 'start' is not equal to 'end'.
480 	 * @pre ScriptMap::IsValidTile(start).
481 	 * @pre ScriptMap::IsValidTile(end).
482 	 * @pre 'start' and 'end' are in a straight line, i.e.
483 	 *  ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or
484 	 *  ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
485 	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
486 	 * @game @pre Valid ScriptCompanyMode active in scope.
487 	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
488 	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
489 	 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
490 	 * @return Whether the road has been/can be removed or not.
491 	 */
492 	static bool RemoveRoad(TileIndex start, TileIndex end);
493 
494 	/**
495 	 * Removes a road from the edge of tile start to the edge of tile end (both
496 	 *  included).
497 	 * @param start The start tile of the road.
498 	 * @param end The end tile of the road.
499 	 * @pre 'start' is not equal to 'end'.
500 	 * @pre ScriptMap::IsValidTile(start).
501 	 * @pre ScriptMap::IsValidTile(end).
502 	 * @pre 'start' and 'end' are in a straight line, i.e.
503 	 *  ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or
504 	 *  ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
505 	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
506 	 * @game @pre Valid ScriptCompanyMode active in scope.
507 	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
508 	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
509 	 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
510 	 * @return Whether the road has been/can be removed or not.
511 	 */
512 	static bool RemoveRoadFull(TileIndex start, TileIndex end);
513 
514 	/**
515 	 * Removes a road depot.
516 	 * @param tile Place to remove the depot from.
517 	 * @pre ScriptMap::IsValidTile(tile).
518 	 * @pre Tile is a road depot.
519 	 * @game @pre Valid ScriptCompanyMode active in scope.
520 	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
521 	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
522 	 * @return Whether the road depot has been/can be removed or not.
523 	 */
524 	static bool RemoveRoadDepot(TileIndex tile);
525 
526 	/**
527 	 * Removes a road bus or truck station.
528 	 * @param tile Place to remove the station from.
529 	 * @pre ScriptMap::IsValidTile(tile).
530 	 * @pre Tile is a road station.
531 	 * @game @pre Valid ScriptCompanyMode active in scope.
532 	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
533 	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
534 	 * @return Whether the station has been/can be removed or not.
535 	 */
536 	static bool RemoveRoadStation(TileIndex tile);
537 
538 	/**
539 	 * Get the baseprice of building a road-related object.
540 	 * @param roadtype the roadtype of the object to build
541 	 * @param build_type the type of object to build
542 	 * @pre IsRoadTypeAvailable(roadtype)
543 	 * @return The baseprice of building the given object.
544 	 */
545 	static Money GetBuildCost(RoadType roadtype, BuildType build_type);
546 
547 	/**
548 	 * Test if a road type is for road or trams.
549 	 * @param roadtype the roadtype to test.
550 	 * @return RoadTramTypes of the road types.
551 	 */
552 	static RoadTramTypes GetRoadTramType(RoadType roadtype);
553 
554 	/**
555 	 * Get the maximum speed of road vehicles running on this roadtype.
556 	 * @param road_type The roadtype to get the maximum speed of.
557 	 * @pre IsRoadTypeAvailable(road_type)
558 	 * @return The maximum speed road vehicles can run on this roadtype
559 	 *   or 0 if there is no limit.
560 	 * @note The speed is in OpenTTD's internal speed unit.
561 	 *       This is mph / 0.8, which is roughly 0.5 km/h.
562 	 *       To get km/h multiply this number by 2.01168.
563 	 */
564 	static int32 GetMaxSpeed(RoadType road_type);
565 
566 	/**
567 	 * Get the maintenance cost factor of a road type.
568 	 * @param roadtype The road type to get the maintenance factor of.
569 	 * @pre IsRoadTypeAvailable(roadtype)
570 	 * @return Maintenance cost factor of the roadtype.
571 	 */
572 	static uint16 GetMaintenanceCostFactor(RoadType roadtype);
573 
574 private:
575 
576 	/**
577 	 * Internal function used by Build(OneWay)Road(Full).
578 	 */
579 	static bool _BuildRoadInternal(TileIndex start, TileIndex end, bool one_way, bool full);
580 
581 	/**
582 	 * Internal function used by Build(DriveThrough)RoadStation.
583 	 */
584 	static bool _BuildRoadStationInternal(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, bool drive_through, StationID station_id);
585 };
586 
587 #endif /* SCRIPT_ROAD_HPP */
588