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/>.
8 /** @file script_road.hpp Everything to query and build roads. */
10 #ifndef SCRIPT_ROAD_HPP
11 #define SCRIPT_ROAD_HPP
13 #include "script_tile.hpp"
14 #include "../squirrel_helper_type.hpp"
15 #include "../../../road.h"
18 * Class that handles all road related functions.
21 class ScriptRoad
: public ScriptObject
{
24 * All road related error messages.
27 /** Base for road building / maintaining errors */
28 ERR_ROAD_BASE
= ScriptError::ERR_CAT_ROAD
<< ScriptError::ERR_CAT_BIT_SIZE
,
30 /** Road works are in progress */
31 ERR_ROAD_WORKS_IN_PROGRESS
, // [STR_ERROR_ROAD_WORKS_IN_PROGRESS]
33 /** Drive through is in the wrong direction */
34 ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION
, // [STR_ERROR_DRIVE_THROUGH_DIRECTION]
36 /** Drive through roads can't be build on town owned roads */
37 ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD
, // [STR_ERROR_DRIVE_THROUGH_ON_TOWN_ROAD]
39 /** One way roads can't have junctions */
40 ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS
, // [STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION]
42 /** This roadtype cannot have crossings */
43 ERR_ROADTYPE_DISALLOWS_CROSSING
, // [STR_ERROR_CROSSING_DISALLOWED_ROAD]
45 /** No suitable road could be found */
46 ERR_UNSUITABLE_ROAD
, // [STR_ERROR_NO_SUITABLE_ROAD, STR_ERROR_NO_SUITABLE_TRAMWAY]
50 * Types of road known to the game.
53 /* Note: these values represent part of the in-game static values */
54 ROADTYPE_ROAD
= ::ROADTYPE_ROAD
, ///< Build road objects.
55 ROADTYPE_TRAM
= ::ROADTYPE_TRAM
, ///< Build tram objects.
57 /* Custom added value, only valid for this API */
58 ROADTYPE_INVALID
= -1, ///< Invalid RoadType.
64 enum RoadTramTypes
: uint8_t {
65 ROADTRAMTYPES_ROAD
= ::RTTB_ROAD
, ///< Road road types.
66 ROADTRAMTYPES_TRAM
= ::RTTB_TRAM
, ///< Tram road types.
70 * Type of road station.
72 enum RoadVehicleType
{
73 ROADVEHTYPE_BUS
, ///< Build objects useable for busses and passenger trams
74 ROADVEHTYPE_TRUCK
, ///< Build objects useable for trucks and cargo trams
78 * Types of road-related objects in the game.
81 BT_ROAD
, ///< Build a piece of road
82 BT_DEPOT
, ///< Build a road depot
83 BT_BUS_STOP
, ///< Build a bus stop
84 BT_TRUCK_STOP
, ///< Build a truck stop
88 * Get the name of a road type.
89 * @param road_type The road type to get the name of.
90 * @pre IsRoadTypeAvailable(road_type).
91 * @return The name the road type has.
93 static std::optional
<std::string
> GetName(RoadType road_type
);
96 * Determines whether a busstop or a truckstop is needed to transport a certain cargo.
97 * @param cargo_type The cargo to test.
98 * @pre ScriptCargo::IsValidCargo(cargo_type).
99 * @return The road vehicle type needed to transport the cargo.
101 static RoadVehicleType
GetRoadVehicleTypeForCargo(CargoID cargo_type
);
104 * Checks whether the given tile is actually a tile with road that can be
105 * used to traverse a tile. This excludes road depots and 'normal' road
106 * stations, but includes drive through stations.
107 * @param tile The tile to check.
108 * @pre ScriptMap::IsValidTile(tile).
109 * @return True if and only if the tile has road.
111 static bool IsRoadTile(TileIndex tile
);
114 * Checks whether the given tile is actually a tile with a road depot.
115 * @param tile The tile to check.
116 * @pre ScriptMap::IsValidTile(tile).
117 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
118 * @return True if and only if the tile has a road depot.
120 static bool IsRoadDepotTile(TileIndex tile
);
123 * Checks whether the given tile is actually a tile with a road station.
124 * @param tile The tile to check.
125 * @pre ScriptMap::IsValidTile(tile).
126 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
127 * @return True if and only if the tile has a road station.
129 static bool IsRoadStationTile(TileIndex tile
);
132 * Checks whether the given tile is actually a tile with a drive through
134 * @param tile The tile to check.
135 * @pre ScriptMap::IsValidTile(tile).
136 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
137 * @return True if and only if the tile has a drive through road station.
139 static bool IsDriveThroughRoadStationTile(TileIndex tile
);
142 * Check if a given RoadType is available.
143 * @param road_type The RoadType to check for.
144 * @game @pre ScriptCompanyMode::IsValid().
145 * @return True if this RoadType can be used.
147 static bool IsRoadTypeAvailable(RoadType road_type
);
150 * Get the current RoadType set for all ScriptRoad functions.
151 * @return The RoadType currently set.
153 static RoadType
GetCurrentRoadType();
156 * Set the RoadType for all further ScriptRoad functions.
157 * @param road_type The RoadType to set.
159 static void SetCurrentRoadType(RoadType road_type
);
162 * Check if a road vehicle built for a road type can run on another road type.
163 * @param engine_road_type The road type the road vehicle is built for.
164 * @param road_road_type The road type you want to check.
165 * @pre ScriptRoad::IsRoadTypeAvailable(engine_road_type).
166 * @pre ScriptRoad::IsRoadTypeAvailable(road_road_type).
167 * @return Whether a road vehicle built for 'engine_road_type' can run on 'road_road_type'.
169 static bool RoadVehCanRunOnRoad(ScriptRoad::RoadType engine_road_type
, ScriptRoad::RoadType road_road_type
);
172 * Check if a road vehicle built for a road type has power on another road type.
173 * @param engine_road_type The road type the road vehicle is built for.
174 * @param road_road_type The road type you want to check.
175 * @pre ScriptRoad::IsRoadTypeAvailable(engine_road_type).
176 * @pre ScriptRoad::IsRoadTypeAvailable(road_road_type).
177 * @return Whether a road vehicle built for 'engine_road_type' has power on 'road_road_type'.
179 static bool RoadVehHasPowerOnRoad(ScriptRoad::RoadType engine_road_type
, ScriptRoad::RoadType road_road_type
);
183 * Convert the road on all tiles within a rectangle to another RoadType.
184 * @param start_tile One corner of the rectangle.
185 * @param end_tile The opposite corner of the rectangle.
186 * @param road_type The RoadType you want to convert.
187 * @pre ScriptMap::IsValidTile(start_tile).
188 * @pre ScriptMap::IsValidTile(end_tile).
189 * @pre IsRoadTypeAvailable(road_type).
190 * @game @pre ScriptCompanyMode::IsValid().
191 * @exception ScriptRoad::ERR_UNSUITABLE_ROAD
192 * @return Whether at least some road has been converted successfully.
194 static bool ConvertRoadType(TileIndex start_tile
, TileIndex end_tile
, RoadType road_type
);
197 * Check if a given tile has RoadType.
198 * @param tile The tile to check.
199 * @param road_type The RoadType to check for.
200 * @pre ScriptMap::IsValidTile(tile).
201 * @pre IsRoadTypeAvailable(road_type).
202 * @return True if the tile contains a RoadType object.
204 static bool HasRoadType(TileIndex tile
, RoadType road_type
);
207 * Checks whether the given tiles are directly connected, i.e. whether
208 * a road vehicle can travel from the center of the first tile to the
209 * center of the second tile.
210 * @param tile_from The source tile.
211 * @param tile_to The destination tile.
212 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
213 * @pre ScriptMap::IsValidTile(tile_from).
214 * @pre ScriptMap::IsValidTile(tile_to).
215 * @pre 'tile_from' and 'tile_to' are directly neighbouring tiles.
216 * @return True if and only if a road vehicle can go from tile_from to tile_to.
218 static bool AreRoadTilesConnected(TileIndex tile_from
, TileIndex tile_to
);
221 * Lookup function for building road parts independent of whether the
222 * "building on slopes" setting is enabled or not.
223 * This implementation can be used for abstract reasoning about a tile as
224 * it needs the slope and existing road parts of the tile as information.
225 * @param slope The slope of the tile to examine.
226 * @param existing An array with the existing neighbours in the same format
227 * as "start" and "end", e.g. ScriptMap.GetTileIndex(0, 1).
228 * As a result of this all values of the existing array
229 * must be of type integer.
230 * @param start The tile from where the 'tile to be considered' will be
231 * entered. This is a relative tile, so valid parameters are:
232 * ScriptMap.GetTileIndex(0, 1), ScriptMap.GetTileIndex(0, -1),
233 * ScriptMap.GetTileIndex(1, 0) and ScriptMap.GetTileIndex(-1, 0).
234 * @param end The tile from where the 'tile to be considered' will be
235 * exited. This is a relative tile, sovalid parameters are:
236 * ScriptMap.GetTileIndex(0, 1), ScriptMap.GetTileIndex(0, -1),
237 * ScriptMap.GetTileIndex(1, 0) and ScriptMap.GetTileIndex(-1, 0).
239 * @pre slope must be a valid slope, i.e. one specified in ScriptTile::Slope.
240 * @note Passing data that would be invalid in-game, e.g. existing containing
241 * road parts that can not be build on a tile with the given slope,
242 * does not necessarily means that -1 is returned, i.e. not all
243 * preconditions written here or assumed by the game are extensively
244 * checked to make sure the data entered is valid.
245 * @return 0 when the build parts do not connect, 1 when they do connect once
246 * they are build or 2 when building the first part automatically
247 * builds the second part. -1 means the preconditions are not met.
249 static SQInteger
CanBuildConnectedRoadParts(ScriptTile::Slope slope
, Array
<> &&existing
, TileIndex start
, TileIndex end
);
252 * Lookup function for building road parts independent of whether the
253 * "building on slopes" setting is enabled or not.
254 * This implementation can be used for reasoning about an existing tile.
255 * @param tile The tile to examine.
256 * @param start The tile from where "tile" will be entered.
257 * @param end The tile from where "tile" will be exited.
259 * @pre tile != start.
261 * @pre ScriptMap.IsValidTile(tile).
262 * @pre ScriptMap.IsValidTile(start).
263 * @pre ScriptMap.IsValidTile(end).
264 * @pre ScriptMap.GetDistanceManhattanToTile(tile, start) == 1.
265 * @pre ScriptMap.GetDistanceManhattanToTile(tile, end) == 1.
266 * @return 0 when the build parts do not connect, 1 when they do connect once
267 * they are build or 2 when building the first part automatically
268 * builds the second part. -1 means the preconditions are not met.
270 static SQInteger
CanBuildConnectedRoadPartsHere(TileIndex tile
, TileIndex start
, TileIndex end
);
273 * Count how many neighbours are road.
274 * @param tile The tile to check on.
275 * @pre ScriptMap::IsValidTile(tile).
276 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
277 * @return 0 means no neighbour road; max value is 4.
279 static SQInteger
GetNeighbourRoadCount(TileIndex tile
);
282 * Gets the tile in front of a road depot.
283 * @param depot The road depot tile.
284 * @pre IsRoadDepotTile(depot).
285 * @return The tile in front of the depot.
287 static TileIndex
GetRoadDepotFrontTile(TileIndex depot
);
290 * Gets the tile in front of a road station.
291 * @param station The road station tile.
292 * @pre IsRoadStationTile(station).
293 * @return The tile in front of the road station.
295 static TileIndex
GetRoadStationFrontTile(TileIndex station
);
298 * Gets the tile at the back of a drive through road station.
299 * So, one side of the drive through station is retrieved with
300 * GetTileInFrontOfStation, the other with this function.
301 * @param station The road station tile.
302 * @pre IsDriveThroughRoadStationTile(station).
303 * @return The tile at the back of the drive through road station.
305 static TileIndex
GetDriveThroughBackTile(TileIndex station
);
308 * Builds a road from the center of tile start to the center of tile end.
309 * @param start The start tile of the road.
310 * @param end The end tile of the road.
311 * @pre 'start' is not equal to 'end'.
312 * @pre ScriptMap::IsValidTile(start).
313 * @pre ScriptMap::IsValidTile(end).
314 * @pre 'start' and 'end' are in a straight line, i.e.
315 * ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or
316 * ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
317 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
318 * @exception ScriptError::ERR_ALREADY_BUILT
319 * @exception ScriptError::ERR_LAND_SLOPED_WRONG
320 * @exception ScriptError::ERR_AREA_NOT_CLEAR
321 * @exception ScriptRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS
322 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
323 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
324 * @note Construction will fail if an obstacle is found between the start and end tiles.
325 * @game @note Building a piece of road as deity (ScriptCompanyMode::IsDeity()) results in a piece of road owned by towns.
326 * @return Whether the road has been/can be build or not.
328 static bool BuildRoad(TileIndex start
, TileIndex end
);
331 * Builds a one-way road from the center of tile start to the center
332 * of tile end. If the road already exists, it is made one-way road.
333 * If the road already exists and is already one-way in this direction,
334 * the road is made two-way again. If the road already exists but is
335 * one-way in the other direction, it's made a 'no'-way road (it's
336 * forbidden to enter the tile from any direction).
337 * @param start The start tile of the road.
338 * @param end The end tile of the road.
339 * @pre 'start' is not equal to 'end'.
340 * @pre ScriptMap::IsValidTile(start).
341 * @pre ScriptMap::IsValidTile(end).
342 * @pre 'start' and 'end' are in a straight line, i.e.
343 * ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or
344 * ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
345 * @pre GetCurrentRoadType() == ROADTYPE_ROAD.
346 * @game @pre ScriptCompanyMode::IsValid().
347 * @exception ScriptError::ERR_ALREADY_BUILT
348 * @exception ScriptError::ERR_LAND_SLOPED_WRONG
349 * @exception ScriptError::ERR_AREA_NOT_CLEAR
350 * @exception ScriptRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS
351 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
352 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
353 * @note Construction will fail if an obstacle is found between the start and end tiles.
354 * @return Whether the road has been/can be build or not.
356 static bool BuildOneWayRoad(TileIndex start
, TileIndex end
);
359 * Builds a road from the edge of tile start to the edge of tile end (both
361 * @param start The start tile of the road.
362 * @param end The end tile of the road.
363 * @pre 'start' is not equal to 'end'.
364 * @pre ScriptMap::IsValidTile(start).
365 * @pre ScriptMap::IsValidTile(end).
366 * @pre 'start' and 'end' are in a straight line, i.e.
367 * ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or
368 * ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
369 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
370 * @exception ScriptError::ERR_ALREADY_BUILT
371 * @exception ScriptError::ERR_LAND_SLOPED_WRONG
372 * @exception ScriptError::ERR_AREA_NOT_CLEAR
373 * @exception ScriptRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS
374 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
375 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
376 * @note Construction will fail if an obstacle is found between the start and end tiles.
377 * @game @note Building a piece of road as deity (ScriptCompanyMode::IsDeity()) results in a piece of road owned by towns.
378 * @return Whether the road has been/can be build or not.
380 static bool BuildRoadFull(TileIndex start
, TileIndex end
);
383 * Builds a one-way road from the edge of tile start to the edge of tile end
384 * (both included). If the road already exists, it is made one-way road.
385 * If the road already exists and is already one-way in this direction,
386 * the road is made two-way again. If the road already exists but is
387 * one-way in the other direction, it's made a 'no'-way road (it's
388 * forbidden to enter the tile from any direction).
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 ScriptCompanyMode::IsValid().
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.
408 static bool BuildOneWayRoadFull(TileIndex start
, TileIndex end
);
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 ScriptCompanyMode::IsValid().
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.
423 static bool BuildRoadDepot(TileIndex tile
, TileIndex front
);
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 ScriptCompanyMode::IsValid().
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.
448 static bool BuildRoadStation(TileIndex tile
, TileIndex front
, RoadVehicleType road_veh_type
, StationID station_id
);
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 ScriptCompanyMode::IsValid().
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.
473 static bool BuildDriveThroughRoadStation(TileIndex tile
, TileIndex front
, RoadVehicleType road_veh_type
, StationID station_id
);
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 ScriptCompanyMode::IsValid().
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.
492 static bool RemoveRoad(TileIndex start
, TileIndex end
);
495 * Removes a road from the edge of tile start to the edge of tile end (both
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 ScriptCompanyMode::IsValid().
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.
512 static bool RemoveRoadFull(TileIndex start
, TileIndex end
);
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 ScriptCompanyMode::IsValid().
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.
524 static bool RemoveRoadDepot(TileIndex tile
);
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 ScriptCompanyMode::IsValid().
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.
536 static bool RemoveRoadStation(TileIndex tile
);
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.
545 static Money
GetBuildCost(RoadType roadtype
, BuildType build_type
);
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.
552 static RoadTramTypes
GetRoadTramType(RoadType roadtype
);
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.
564 static SQInteger
GetMaxSpeed(RoadType road_type
);
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.
572 static SQInteger
GetMaintenanceCostFactor(RoadType roadtype
);
577 * Internal function used by Build(OneWay)Road(Full).
579 static bool _BuildRoadInternal(TileIndex start
, TileIndex end
, bool one_way
, bool full
);
582 * Internal function used by Build(DriveThrough)RoadStation.
584 static bool _BuildRoadStationInternal(TileIndex tile
, TileIndex front
, RoadVehicleType road_veh_type
, bool drive_through
, StationID station_id
);
587 #endif /* SCRIPT_ROAD_HPP */