Update: Translations from eints
[openttd-github.git] / src / script / api / script_vehicle.hpp
blob9344d65086b6e3ea096bc1948503d5dc743d3c84
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 */
8 /** @file script_vehicle.hpp Everything to query and build vehicles. */
10 #ifndef SCRIPT_VEHICLE_HPP
11 #define SCRIPT_VEHICLE_HPP
13 #include "script_road.hpp"
15 /**
16 * Class that handles all vehicle related functions.
17 * @api ai game
19 class ScriptVehicle : public ScriptObject {
20 public:
21 /**
22 * All vehicle related error messages.
24 * @see ScriptErrorType
26 enum ErrorMessages {
27 /** Base for vehicle related errors */
28 ERR_VEHICLE_BASE = ScriptError::ERR_CAT_VEHICLE << ScriptError::ERR_CAT_BIT_SIZE,
30 /** Too many vehicles in the game, can't build any more. */
31 ERR_VEHICLE_TOO_MANY, // [STR_ERROR_TOO_MANY_VEHICLES_IN_GAME]
33 /** Vehicle is not available */
34 ERR_VEHICLE_NOT_AVAILABLE, // [STR_ERROR_AIRCRAFT_NOT_AVAILABLE, STR_ERROR_ROAD_VEHICLE_NOT_AVAILABLE, STR_ERROR_SHIP_NOT_AVAILABLE, STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE]
36 /** Vehicle can't be build due to game settigns */
37 ERR_VEHICLE_BUILD_DISABLED, // [STR_ERROR_CAN_T_BUY_TRAIN, STR_ERROR_CAN_T_BUY_ROAD_VEHICLE, STR_ERROR_CAN_T_BUY_SHIP, STR_ERROR_CAN_T_BUY_AIRCRAFT]
39 /** Vehicle can't be build in the selected depot */
40 ERR_VEHICLE_WRONG_DEPOT, // [STR_ERROR_DEPOT_WRONG_DEPOT_TYPE]
42 /** Vehicle can't return to the depot */
43 ERR_VEHICLE_CANNOT_SEND_TO_DEPOT, // [STR_ERROR_CAN_T_SEND_TRAIN_TO_DEPOT, STR_ERROR_CAN_T_SEND_ROAD_VEHICLE_TO_DEPOT, STR_ERROR_CAN_T_SEND_SHIP_TO_DEPOT, STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR]
45 /** Vehicle can't start / stop */
46 ERR_VEHICLE_CANNOT_START_STOP, // [STR_ERROR_CAN_T_STOP_START_TRAIN, STR_ERROR_CAN_T_STOP_START_ROAD_VEHICLE, STR_ERROR_CAN_T_STOP_START_SHIP, STR_ERROR_CAN_T_STOP_START_AIRCRAFT]
48 /** Vehicle can't turn */
49 ERR_VEHICLE_CANNOT_TURN, // [STR_ERROR_CAN_T_MAKE_ROAD_VEHICLE_TURN, STR_ERROR_CAN_T_REVERSE_DIRECTION_TRAIN, STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE, STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE_MULTIPLE_UNITS]
51 /** Vehicle can't be refit */
52 ERR_VEHICLE_CANNOT_REFIT, // [STR_ERROR_CAN_T_REFIT_TRAIN, STR_ERROR_CAN_T_REFIT_ROAD_VEHICLE, STR_ERROR_CAN_T_REFIT_SHIP, STR_ERROR_CAN_T_REFIT_AIRCRAFT]
54 /** Vehicle is destroyed */
55 ERR_VEHICLE_IS_DESTROYED, // [STR_ERROR_VEHICLE_IS_DESTROYED]
57 /** Vehicle is not in a depot */
58 ERR_VEHICLE_NOT_IN_DEPOT, // [STR_ERROR_AIRCRAFT_MUST_BE_STOPPED_INSIDE_HANGAR, STR_ERROR_ROAD_VEHICLE_MUST_BE_STOPPED_INSIDE_DEPOT, STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT, STR_ERROR_SHIP_MUST_BE_STOPPED_INSIDE_DEPOT]
60 /** Vehicle is flying */
61 ERR_VEHICLE_IN_FLIGHT, // [STR_ERROR_AIRCRAFT_IS_IN_FLIGHT]
63 /** Vehicle is without power */
64 ERR_VEHICLE_NO_POWER, // [STR_ERROR_TRAIN_START_NO_POWER]
66 /** Vehicle would get too long during construction. */
67 ERR_VEHICLE_TOO_LONG, // [STR_ERROR_TRAIN_TOO_LONG]
70 /**
71 * The type of a vehicle available in the game. Trams for example are
72 * road vehicles, as maglev is a rail vehicle.
74 enum VehicleType {
75 VT_RAIL, ///< Rail type vehicle.
76 VT_ROAD, ///< Road type vehicle (bus / truck).
77 VT_WATER, ///< Water type vehicle.
78 VT_AIR, ///< Air type vehicle.
79 VT_INVALID = 0xFF, ///< Invalid vehicle type.
82 /**
83 * The different states a vehicle can be in.
85 enum VehicleState {
86 VS_RUNNING, ///< The vehicle is currently running.
87 VS_STOPPED, ///< The vehicle is stopped manually.
88 VS_IN_DEPOT, ///< The vehicle is stopped in the depot.
89 VS_AT_STATION, ///< The vehicle is stopped at a station and is currently loading or unloading.
90 VS_BROKEN, ///< The vehicle has broken down and will start running again in a while.
91 VS_CRASHED, ///< The vehicle is crashed (and will never run again).
93 VS_INVALID = 0xFF, ///< An invalid vehicle state.
96 static const VehicleID VEHICLE_INVALID = 0xFFFFF; ///< Invalid VehicleID.
98 /**
99 * Checks whether the given vehicle is valid and owned by you.
100 * @param vehicle_id The vehicle to check.
101 * @return True if and only if the vehicle is valid.
102 * @note Also returns true when the leading part of the vehicle is a wagon.
103 * Use IsPrimaryVehicle() to check for a valid vehicle with a leading engine.
105 static bool IsValidVehicle(VehicleID vehicle_id);
108 * Checks whether this is a primary vehicle.
109 * @param vehicle_id The vehicle to check.
110 * @pre IsValidVehicle(vehicle_id).
111 * @return True if the vehicle is a primary vehicle.
112 * @note Returns false when the leading part of the vehicle is a wagon.
114 static bool IsPrimaryVehicle(VehicleID vehicle_id);
117 * Get the number of wagons a vehicle has.
118 * @param vehicle_id The vehicle to get the number of wagons from.
119 * @pre IsValidVehicle(vehicle_id).
120 * @return The number of wagons the vehicle has.
122 static SQInteger GetNumWagons(VehicleID vehicle_id);
125 * Set the name of a vehicle.
126 * @param vehicle_id The vehicle to set the name for.
127 * @param name The name for the vehicle (can be either a raw string, or a ScriptText object).
128 * @pre IsPrimaryVehicle(vehicle_id).
129 * @pre name != null && len(name) != 0.
130 * @game @pre ScriptCompanyMode::IsValid().
131 * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
132 * @return True if and only if the name was changed.
134 static bool SetName(VehicleID vehicle_id, Text *name);
137 * Get the name of a vehicle.
138 * @param vehicle_id The vehicle to get the name of.
139 * @pre IsPrimaryVehicle(vehicle_id).
140 * @return The name the vehicle has.
142 static std::optional<std::string> GetName(VehicleID vehicle_id);
145 * Get the owner of a vehicle.
146 * @param vehicle_id The vehicle to get the owner of.
147 * @pre IsValidVehicle(vehicle_id).
148 * @return The owner the vehicle has.
149 * @api -ai
151 static ScriptCompany::CompanyID GetOwner(VehicleID vehicle_id);
154 * Get the current location of a vehicle.
155 * @param vehicle_id The vehicle to get the location of.
156 * @pre IsValidVehicle(vehicle_id).
157 * @return The tile the vehicle is currently on.
159 static TileIndex GetLocation(VehicleID vehicle_id);
162 * Get the engine-type of a vehicle.
163 * @param vehicle_id The vehicle to get the engine-type of.
164 * @pre IsValidVehicle(vehicle_id).
165 * @return The engine type the vehicle has.
167 static EngineID GetEngineType(VehicleID vehicle_id);
170 * Get the engine-type of a wagon.
171 * @param vehicle_id The vehicle to get the engine-type of.
172 * @param wagon The wagon in the vehicle to get the engine-type of.
173 * @pre IsValidVehicle(vehicle_id).
174 * @pre wagon < GetNumWagons(vehicle_id).
175 * @return The engine type the vehicle has.
177 static EngineID GetWagonEngineType(VehicleID vehicle_id, SQInteger wagon);
180 * Get the unitnumber of a vehicle.
181 * @param vehicle_id The vehicle to get the unitnumber of.
182 * @pre IsPrimaryVehicle(vehicle_id).
183 * @return The unitnumber the vehicle has.
185 static SQInteger GetUnitNumber(VehicleID vehicle_id);
188 * Get the current age of a vehicle.
189 * @param vehicle_id The vehicle to get the age of.
190 * @pre IsValidVehicle(vehicle_id).
191 * @return The current age of the vehicle in calendar-days.
192 * @see \ref ScriptCalendarTime
194 static SQInteger GetAge(VehicleID vehicle_id);
197 * Get the current age of a second (or third, etc.) engine in a train vehicle.
198 * @param vehicle_id The vehicle to get the age of.
199 * @param wagon The wagon in the vehicle to get the age of.
200 * @pre IsValidVehicle(vehicle_id).
201 * @pre wagon < GetNumWagons(vehicle_id).
202 * @return The current age of the vehicle in calendar-days.
203 * @see \ref ScriptCalendarTime
205 static SQInteger GetWagonAge(VehicleID vehicle_id, SQInteger wagon);
208 * Get the maximum age of a vehicle.
209 * @param vehicle_id The vehicle to get the age of.
210 * @pre IsPrimaryVehicle(vehicle_id).
211 * @return The maximum age for the vehicle in calendar-days.
212 * @see \ref ScriptCalendarTime
214 static SQInteger GetMaxAge(VehicleID vehicle_id);
217 * Get the age a vehicle has left (maximum - current).
218 * @param vehicle_id The vehicle to get the age of.
219 * @pre IsPrimaryVehicle(vehicle_id).
220 * @return The remaining age of the vehicle in calendar-days.
221 * @see \ref ScriptCalendarTime
223 static SQInteger GetAgeLeft(VehicleID vehicle_id);
226 * Get the current speed of a vehicle.
227 * @param vehicle_id The vehicle to get the speed of.
228 * @pre IsPrimaryVehicle(vehicle_id).
229 * @return The current speed of the vehicle.
230 * @note The speed is in OpenTTD's internal speed unit.
231 * This is mph / 1.6, which is roughly km/h.
232 * To get km/h multiply this number by 1.00584.
234 static SQInteger GetCurrentSpeed(VehicleID vehicle_id);
237 * Get the current state of a vehicle.
238 * @param vehicle_id The vehicle to get the state of.
239 * @pre IsValidVehicle(vehicle_id).
240 * @return The current state of the vehicle.
242 static VehicleState GetState(VehicleID vehicle_id);
245 * Get the running cost of this vehicle.
246 * @param vehicle_id The vehicle to get the running cost of.
247 * @pre IsPrimaryVehicle(vehicle_id).
248 * @return The running cost of the vehicle per economy-year.
249 * @note This is not equal to ScriptEngine::GetRunningCost for Trains, because
250 * wagons and second engines can add up in the calculation too.
251 * @see \ref ScriptEconomyTime
253 static Money GetRunningCost(VehicleID vehicle_id);
256 * Get the current profit of a vehicle.
257 * @param vehicle_id The vehicle to get the profit of.
258 * @pre IsPrimaryVehicle(vehicle_id).
259 * @return The profit the vehicle has made this economy-year so far.
260 * @see \ref ScriptEconomyTime
262 static Money GetProfitThisYear(VehicleID vehicle_id);
265 * Get the profit of last year of a vehicle.
266 * @param vehicle_id The vehicle to get the profit of.
267 * @pre IsPrimaryVehicle(vehicle_id).
268 * @return The profit the vehicle made in the previous economy-year.
269 * @see \ref ScriptEconomyTime
271 static Money GetProfitLastYear(VehicleID vehicle_id);
275 * Get the current value of a vehicle.
276 * @param vehicle_id The vehicle to get the value of.
277 * @pre IsValidVehicle(vehicle_id).
278 * @return The value the vehicle currently has (the amount you should get
279 * when you would sell the vehicle right now).
281 static Money GetCurrentValue(VehicleID vehicle_id);
284 * Get the type of vehicle.
285 * @param vehicle_id The vehicle to get the type of.
286 * @pre IsValidVehicle(vehicle_id).
287 * @return The vehicle type.
289 static ScriptVehicle::VehicleType GetVehicleType(VehicleID vehicle_id);
292 * Get the RoadType of the vehicle.
293 * @param vehicle_id The vehicle to get the RoadType of.
294 * @pre IsValidVehicle(vehicle_id).
295 * @pre GetVehicleType(vehicle_id) == VT_ROAD.
296 * @return The RoadType the vehicle has.
298 static ScriptRoad::RoadType GetRoadType(VehicleID vehicle_id);
301 * Check if a vehicle is in a depot.
302 * @param vehicle_id The vehicle to check.
303 * @pre IsValidVehicle(vehicle_id).
304 * @return True if and only if the vehicle is in a depot.
306 static bool IsInDepot(VehicleID vehicle_id);
309 * Check if a vehicle is in a depot and stopped.
310 * @param vehicle_id The vehicle to check.
311 * @pre IsValidVehicle(vehicle_id).
312 * @return True if and only if the vehicle is in a depot and stopped.
314 static bool IsStoppedInDepot(VehicleID vehicle_id);
317 * Builds a vehicle with the given engine at the given depot.
318 * @param depot The depot where the vehicle will be build.
319 * @param engine_id The engine to use for this vehicle.
320 * @pre The tile at depot has a depot that can build the engine and
321 * is owned by you.
322 * @pre ScriptEngine::IsBuildable(engine_id).
323 * @game @pre ScriptCompanyMode::IsValid().
324 * @exception ScriptVehicle::ERR_VEHICLE_TOO_MANY
325 * @exception ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED
326 * @exception ScriptVehicle::ERR_VEHICLE_WRONG_DEPOT
327 * @return The VehicleID of the new vehicle, or an invalid VehicleID when
328 * it failed. Check the return value using IsValidVehicle. In test-mode
329 * 0 is returned if it was successful; any other value indicates failure.
330 * @note Unlike the GUI, wagons are not automatically attached to trains,
331 * only to existing free wagons. This means that BuildVehicle can sometimes
332 * return an ID indicating success, but IsValidVehicle check will
333 * fail. You should use MoveWagon to attach free wagons to trains.
334 * @note In Test Mode it means you can't assign orders yet to this vehicle,
335 * as the vehicle isn't really built yet. Build it for real first before
336 * assigning orders.
338 static VehicleID BuildVehicle(TileIndex depot, EngineID engine_id);
341 * Builds a vehicle with the given engine at the given depot and refits it to the given cargo.
342 * @param depot The depot where the vehicle will be build.
343 * @param engine_id The engine to use for this vehicle.
344 * @param cargo The cargo to refit to.
345 * @pre The tile at depot has a depot that can build the engine and
346 * is owned by you.
347 * @pre ScriptEngine::IsBuildable(engine_id).
348 * @pre ScriptCargo::IsValidCargo(cargo).
349 * @game @pre ScriptCompanyMode::IsValid().
350 * @exception ScriptVehicle::ERR_VEHICLE_TOO_MANY
351 * @exception ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED
352 * @exception ScriptVehicle::ERR_VEHICLE_WRONG_DEPOT
353 * @return The VehicleID of the new vehicle, or an invalid VehicleID when
354 * it failed. Check the return value using IsValidVehicle. In test-mode
355 * 0 is returned if it was successful; any other value indicates failure.
356 * @note In Test Mode it means you can't assign orders yet to this vehicle,
357 * as the vehicle isn't really built yet. Build it for real first before
358 * assigning orders.
360 static VehicleID BuildVehicleWithRefit(TileIndex depot, EngineID engine_id, CargoID cargo);
363 * Gets the capacity of a vehicle built at the given depot with the given engine and refitted to the given cargo.
364 * @param depot The depot where the vehicle will be build.
365 * @param engine_id The engine to use for this vehicle.
366 * @param cargo The cargo to refit to.
367 * @pre The tile at depot has a depot that can build the engine and
368 * is owned by you.
369 * @pre ScriptEngine::IsBuildable(engine_id).
370 * @pre ScriptCargo::IsValidCargo(cargo).
371 * @return The capacity the vehicle will have when refited.
373 static SQInteger GetBuildWithRefitCapacity(TileIndex depot, EngineID engine_id, CargoID cargo);
376 * Clones a vehicle at the given depot, copying or cloning its orders.
377 * @param depot The depot where the vehicle will be build.
378 * @param vehicle_id The vehicle to use as example for the new vehicle.
379 * @param share_orders Should the orders be copied or shared?
380 * @pre The tile 'depot' has a depot on it, allowing 'vehicle_id'-type vehicles.
381 * @pre IsPrimaryVehicle(vehicle_id).
382 * @game @pre ScriptCompanyMode::IsValid().
383 * @exception ScriptVehicle::ERR_VEHICLE_TOO_MANY
384 * @exception ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED
385 * @exception ScriptVehicle::ERR_VEHICLE_WRONG_DEPOT
386 * @return The VehicleID of the new vehicle, or an invalid VehicleID when
387 * it failed. Check the return value using IsValidVehicle. In test-mode
388 * 0 is returned if it was successful; any other value indicates failure.
390 static VehicleID CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders);
393 * Move a wagon after another wagon.
394 * @param source_vehicle_id The vehicle to move a wagon away from.
395 * @param source_wagon The wagon in source_vehicle to move.
396 * @param dest_vehicle_id The vehicle to move the wagon to, or -1 to create a new vehicle.
397 * @param dest_wagon The wagon in dest_vehicle to place source_wagon after.
398 * @pre IsValidVehicle(source_vehicle_id).
399 * @pre source_wagon < GetNumWagons(source_vehicle_id).
400 * @pre dest_vehicle_id == -1 || (IsValidVehicle(dest_vehicle_id) && dest_wagon < GetNumWagons(dest_vehicle_id)).
401 * @pre GetVehicleType(source_vehicle_id) == VT_RAIL.
402 * @pre dest_vehicle_id == -1 || GetVehicleType(dest_vehicle_id) == VT_RAIL.
403 * @game @pre ScriptCompanyMode::IsValid().
404 * @return Whether or not moving the wagon succeeded.
406 static bool MoveWagon(VehicleID source_vehicle_id, SQInteger source_wagon, SQInteger dest_vehicle_id, SQInteger dest_wagon);
409 * Move a chain of wagons after another wagon.
410 * @param source_vehicle_id The vehicle to move a wagon away from.
411 * @param source_wagon The first wagon in source_vehicle to move.
412 * @param dest_vehicle_id The vehicle to move the wagons to, or -1 to create a new vehicle.
413 * @param dest_wagon The wagon in dest_vehicle to place source_wagon and following wagons after.
414 * @pre IsValidVehicle(source_vehicle_id).
415 * @pre source_wagon < GetNumWagons(source_vehicle_id).
416 * @pre dest_vehicle_id == -1 || (IsValidVehicle(dest_vehicle_id) && dest_wagon < GetNumWagons(dest_vehicle_id)).
417 * @pre GetVehicleType(source_vehicle_id) == VT_RAIL.
418 * @pre dest_vehicle_id == -1 || GetVehicleType(dest_vehicle_id) == VT_RAIL.
419 * @game @pre ScriptCompanyMode::IsValid().
420 * @return Whether or not moving the wagons succeeded.
422 static bool MoveWagonChain(VehicleID source_vehicle_id, SQInteger source_wagon, SQInteger dest_vehicle_id, SQInteger dest_wagon);
425 * Gets the capacity of the given vehicle when refitted to the given cargo type.
426 * @param vehicle_id The vehicle to refit.
427 * @param cargo The cargo to refit to.
428 * @pre IsValidVehicle(vehicle_id).
429 * @pre ScriptCargo::IsValidCargo(cargo).
430 * @pre You must own the vehicle.
431 * @pre The vehicle must be stopped in the depot.
432 * @return The capacity the vehicle will have when refited.
434 static SQInteger GetRefitCapacity(VehicleID vehicle_id, CargoID cargo);
437 * Refits a vehicle to the given cargo type.
438 * @param vehicle_id The vehicle to refit.
439 * @param cargo The cargo to refit to.
440 * @pre IsValidVehicle(vehicle_id).
441 * @pre ScriptCargo::IsValidCargo(cargo).
442 * @pre You must own the vehicle.
443 * @pre The vehicle must be stopped in the depot.
444 * @game @pre ScriptCompanyMode::IsValid().
445 * @exception ScriptVehicle::ERR_VEHICLE_CANNOT_REFIT
446 * @exception ScriptVehicle::ERR_VEHICLE_IS_DESTROYED
447 * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT
448 * @return True if and only if the refit succeeded.
450 static bool RefitVehicle(VehicleID vehicle_id, CargoID cargo);
453 * Sells the given vehicle.
454 * @param vehicle_id The vehicle to sell.
455 * @pre IsValidVehicle(vehicle_id).
456 * @pre You must own the vehicle.
457 * @pre The vehicle must be stopped in the depot.
458 * @game @pre ScriptCompanyMode::IsValid().
459 * @exception ScriptVehicle::ERR_VEHICLE_IS_DESTROYED
460 * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT
461 * @return True if and only if the vehicle has been sold.
463 static bool SellVehicle(VehicleID vehicle_id);
466 * Sells the given wagon from the vehicle.
467 * @param vehicle_id The vehicle to sell a wagon from.
468 * @param wagon The wagon to sell.
469 * @pre IsValidVehicle(vehicle_id).
470 * @pre wagon < GetNumWagons(vehicle_id).
471 * @pre You must own the vehicle.
472 * @pre The vehicle must be stopped in the depot.
473 * @game @pre ScriptCompanyMode::IsValid().
474 * @exception ScriptVehicle::ERR_VEHICLE_IS_DESTROYED
475 * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT
476 * @return True if and only if the wagon has been sold.
478 static bool SellWagon(VehicleID vehicle_id, SQInteger wagon);
481 * Sells all wagons from the vehicle starting from a given position.
482 * @param vehicle_id The vehicle to sell a wagon from.
483 * @param wagon The wagon to sell.
484 * @pre IsValidVehicle(vehicle_id).
485 * @pre wagon < GetNumWagons(vehicle_id).
486 * @pre You must own the vehicle.
487 * @pre The vehicle must be stopped in the depot.
488 * @game @pre ScriptCompanyMode::IsValid().
489 * @exception ScriptVehicle::ERR_VEHICLE_IS_DESTROYED
490 * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT
491 * @return True if and only if the wagons have been sold.
493 static bool SellWagonChain(VehicleID vehicle_id, SQInteger wagon);
496 * Sends the given vehicle to a depot. If the vehicle has already been
497 * sent to a depot it continues with its normal orders instead.
498 * @param vehicle_id The vehicle to send to a depot.
499 * @pre IsPrimaryVehicle(vehicle_id).
500 * @game @pre ScriptCompanyMode::IsValid().
501 * @exception ScriptVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT
502 * @return True if the current order was changed.
504 static bool SendVehicleToDepot(VehicleID vehicle_id);
507 * Sends the given vehicle to a depot for servicing. If the vehicle has
508 * already been sent to a depot it continues with its normal orders instead.
509 * @param vehicle_id The vehicle to send to a depot for servicing.
510 * @pre IsPrimaryVehicle(vehicle_id).
511 * @game @pre ScriptCompanyMode::IsValid().
512 * @exception ScriptVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT
513 * @return True if the current order was changed.
515 static bool SendVehicleToDepotForServicing(VehicleID vehicle_id);
518 * Starts or stops the given vehicle depending on the current state.
519 * @param vehicle_id The vehicle to start/stop.
520 * @pre IsPrimaryVehicle(vehicle_id).
521 * @game @pre ScriptCompanyMode::IsValid().
522 * @exception ScriptVehicle::ERR_VEHICLE_CANNOT_START_STOP
523 * @exception (For aircraft only): ScriptVehicle::ERR_VEHICLE_IN_FLIGHT
524 * @exception (For trains only): ScriptVehicle::ERR_VEHICLE_NO_POWER
525 * @return True if and only if the vehicle has been started or stopped.
527 static bool StartStopVehicle(VehicleID vehicle_id);
530 * Turn the given vehicle so it'll drive the other way.
531 * @param vehicle_id The vehicle to turn.
532 * @pre IsPrimaryVehicle(vehicle_id).
533 * @pre GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL.
534 * @game @pre ScriptCompanyMode::IsValid().
535 * @return True if and only if the vehicle has started to turn.
536 * @note Vehicles cannot always be reversed. For example busses and trucks need to be running
537 * and not be inside a depot.
539 static bool ReverseVehicle(VehicleID vehicle_id);
542 * Get the maximum amount of a specific cargo the given vehicle can transport.
543 * @param vehicle_id The vehicle to get the capacity of.
544 * @param cargo The cargo to get the capacity for.
545 * @pre IsValidVehicle(vehicle_id).
546 * @pre ScriptCargo::IsValidCargo(cargo).
547 * @return The maximum amount of the given cargo the vehicle can transport.
549 static SQInteger GetCapacity(VehicleID vehicle_id, CargoID cargo);
552 * Get the length of a the total vehicle in 1/16's of a tile.
553 * @param vehicle_id The vehicle to get the length of.
554 * @pre IsValidVehicle(vehicle_id).
555 * @pre GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL.
556 * @return The length of the engine.
558 static SQInteger GetLength(VehicleID vehicle_id);
561 * Get the amount of a specific cargo the given vehicle is transporting.
562 * @param vehicle_id The vehicle to get the load amount of.
563 * @param cargo The cargo to get the loaded amount for.
564 * @pre IsValidVehicle(vehicle_id).
565 * @pre ScriptCargo::IsValidCargo(cargo).
566 * @return The amount of the given cargo the vehicle is currently transporting.
568 static SQInteger GetCargoLoad(VehicleID vehicle_id, CargoID cargo);
571 * Get the group of a given vehicle.
572 * @param vehicle_id The vehicle to get the group from.
573 * @pre IsPrimaryVehicle(vehicle_id).
574 * @return The group of the given vehicle.
576 static GroupID GetGroupID(VehicleID vehicle_id);
579 * Check if the vehicle is articulated.
580 * @param vehicle_id The vehicle to check.
581 * @pre IsValidVehicle(vehicle_id).
582 * @pre GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL.
583 * @return True if the vehicle is articulated.
585 static bool IsArticulated(VehicleID vehicle_id);
588 * Check if the vehicle has shared orders.
589 * @param vehicle_id The vehicle to check.
590 * @pre IsPrimaryVehicle(vehicle_id).
591 * @return True if the vehicle has shared orders.
593 static bool HasSharedOrders(VehicleID vehicle_id);
596 * Get the current reliability of a vehicle.
597 * @param vehicle_id The vehicle to check.
598 * @pre IsPrimaryVehicle(vehicle_id).
599 * @return The current reliability (0-100%).
601 static SQInteger GetReliability(VehicleID vehicle_id);
604 * Get the maximum allowed distance between two orders for a vehicle.
605 * The distance returned is a vehicle-type specific distance independent from other
606 * map distances, you may use the result of this function to compare it
607 * with the result of ScriptOrder::GetOrderDistance.
608 * @param vehicle_id The vehicle to get the distance for.
609 * @pre IsPrimaryVehicle(vehicle_id).
610 * @return The maximum distance between two orders for this vehicle
611 * or 0 if the distance is unlimited.
612 * @note The unit of the order distances is unspecified and should
613 * not be compared with map distances
614 * @see ScriptOrder::GetOrderDistance
616 static SQInteger GetMaximumOrderDistance(VehicleID vehicle_id);
618 private:
620 * Internal function used by BuildVehicle(WithRefit).
622 static VehicleID _BuildVehicleInternal(TileIndex depot, EngineID engine_id, CargoID cargo);
625 * Internal function used by SellWagon(Chain).
627 static bool _SellWagonInternal(VehicleID vehicle_id, SQInteger wagon, bool sell_attached_wagons);
630 * Internal function used by MoveWagon(Chain).
632 static bool _MoveWagonInternal(VehicleID source_vehicle_id, SQInteger source_wagon, bool move_attached_wagons, SQInteger dest_vehicle_id, SQInteger dest_wagon);
635 #endif /* SCRIPT_VEHICLE_HPP */