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