Files @ r28558:9d9a6cccb728
Branch filter:

Location: cpp/openttd-patchpack/source/src/script/api/script_vehicle.hpp

Tyler Trahan
Add: AI/GS Time Mode to choose between economy (default) and calendar time (#11603)
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
/*
 * This file is part of OpenTTD.
 * 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.
 * 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.
 * 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/>.
 */

/** @file script_vehicle.hpp Everything to query and build vehicles. */

#ifndef SCRIPT_VEHICLE_HPP
#define SCRIPT_VEHICLE_HPP

#include "script_road.hpp"

/**
 * Class that handles all vehicle related functions.
 * @api ai game
 */
class ScriptVehicle : public ScriptObject {
public:
	/**
	 * All vehicle related error messages.
	 */
	enum ErrorMessages {
		/** Base for vehicle related errors */
		ERR_VEHICLE_BASE = ScriptError::ERR_CAT_VEHICLE << ScriptError::ERR_CAT_BIT_SIZE,

		/** Too many vehicles in the game, can't build any more. */
		ERR_VEHICLE_TOO_MANY,                   // [STR_ERROR_TOO_MANY_VEHICLES_IN_GAME]

		/** Vehicle is not available */
		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]

		/** Vehicle can't be build due to game settigns */
		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]

		/** Vehicle can't be build in the selected depot */
		ERR_VEHICLE_WRONG_DEPOT,                // [STR_ERROR_DEPOT_WRONG_DEPOT_TYPE]

		/** Vehicle can't return to the depot */
		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]

		/** Vehicle can't start / stop */
		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]

		/** Vehicle can't turn */
		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]

		/** Vehicle can't be refit */
		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]

		/** Vehicle is destroyed */
		ERR_VEHICLE_IS_DESTROYED,               // [STR_ERROR_VEHICLE_IS_DESTROYED]

		/** Vehicle is not in a depot */
		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]

		/** Vehicle is flying */
		ERR_VEHICLE_IN_FLIGHT,                  // [STR_ERROR_AIRCRAFT_IS_IN_FLIGHT]

		/** Vehicle is without power */
		ERR_VEHICLE_NO_POWER,                   // [STR_ERROR_TRAIN_START_NO_POWER]

		/** Vehicle would get too long during construction. */
		ERR_VEHICLE_TOO_LONG,                   // [STR_ERROR_TRAIN_TOO_LONG]
	};

	/**
	 * The type of a vehicle available in the game. Trams for example are
	 *  road vehicles, as maglev is a rail vehicle.
	 */
	enum VehicleType {
		VT_RAIL,           ///< Rail type vehicle.
		VT_ROAD,           ///< Road type vehicle (bus / truck).
		VT_WATER,          ///< Water type vehicle.
		VT_AIR,            ///< Air type vehicle.
		VT_INVALID = 0xFF, ///< Invalid vehicle type.
	};

	/**
	 * The different states a vehicle can be in.
	 */
	enum VehicleState {
		VS_RUNNING,        ///< The vehicle is currently running.
		VS_STOPPED,        ///< The vehicle is stopped manually.
		VS_IN_DEPOT,       ///< The vehicle is stopped in the depot.
		VS_AT_STATION,     ///< The vehicle is stopped at a station and is currently loading or unloading.
		VS_BROKEN,         ///< The vehicle has broken down and will start running again in a while.
		VS_CRASHED,        ///< The vehicle is crashed (and will never run again).

		VS_INVALID = 0xFF, ///< An invalid vehicle state.
	};

	static const VehicleID VEHICLE_INVALID = 0xFFFFF; ///< Invalid VehicleID.

	/**
	 * Checks whether the given vehicle is valid and owned by you.
	 * @param vehicle_id The vehicle to check.
	 * @return True if and only if the vehicle is valid.
	 * @note Also returns true when the leading part of the vehicle is a wagon.
	 *       Use IsPrimaryVehicle() to check for a valid vehicle with a leading engine.
	 */
	static bool IsValidVehicle(VehicleID vehicle_id);

	/**
	 * Checks whether this is a primary vehicle.
	 * @param vehicle_id The vehicle to check.
	 * @pre IsValidVehicle(vehicle_id).
	 * @return True if the vehicle is a primary vehicle.
	 * @note Returns false when the leading part of the vehicle is a wagon.
	 */
	static bool IsPrimaryVehicle(VehicleID vehicle_id);

	/**
	 * Get the number of wagons a vehicle has.
	 * @param vehicle_id The vehicle to get the number of wagons from.
	 * @pre IsValidVehicle(vehicle_id).
	 * @return The number of wagons the vehicle has.
	 */
	static SQInteger GetNumWagons(VehicleID vehicle_id);

	/**
	 * Set the name of a vehicle.
	 * @param vehicle_id The vehicle to set the name for.
	 * @param name The name for the vehicle (can be either a raw string, or a ScriptText object).
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @pre name != null && len(name) != 0.
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
	 * @return True if and only if the name was changed.
	 */
	static bool SetName(VehicleID vehicle_id, Text *name);

	/**
	 * Get the name of a vehicle.
	 * @param vehicle_id The vehicle to get the name of.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @return The name the vehicle has.
	 */
	static std::optional<std::string> GetName(VehicleID vehicle_id);

	/**
	 * Get the owner of a vehicle.
	 * @param vehicle_id The vehicle to get the owner of.
	 * @pre IsValidVehicle(vehicle_id).
	 * @return The owner the vehicle has.
	 * @api -ai
	 */
	static ScriptCompany::CompanyID GetOwner(VehicleID vehicle_id);

	/**
	 * Get the current location of a vehicle.
	 * @param vehicle_id The vehicle to get the location of.
	 * @pre IsValidVehicle(vehicle_id).
	 * @return The tile the vehicle is currently on.
	 */
	static TileIndex GetLocation(VehicleID vehicle_id);

	/**
	 * Get the engine-type of a vehicle.
	 * @param vehicle_id The vehicle to get the engine-type of.
	 * @pre IsValidVehicle(vehicle_id).
	 * @return The engine type the vehicle has.
	 */
	static EngineID GetEngineType(VehicleID vehicle_id);

	/**
	 * Get the engine-type of a wagon.
	 * @param vehicle_id The vehicle to get the engine-type of.
	 * @param wagon The wagon in the vehicle to get the engine-type of.
	 * @pre IsValidVehicle(vehicle_id).
	 * @pre wagon < GetNumWagons(vehicle_id).
	 * @return The engine type the vehicle has.
	 */
	static EngineID GetWagonEngineType(VehicleID vehicle_id, SQInteger wagon);

	/**
	 * Get the unitnumber of a vehicle.
	 * @param vehicle_id The vehicle to get the unitnumber of.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @return The unitnumber the vehicle has.
	 */
	static SQInteger GetUnitNumber(VehicleID vehicle_id);

	/**
	 * Get the current age of a vehicle.
	 * @param vehicle_id The vehicle to get the age of.
	 * @pre IsValidVehicle(vehicle_id).
	 * @return The current age the vehicle has.
	 * @note The age is in days.
	 */
	static SQInteger GetAge(VehicleID vehicle_id);

	/**
	 * Get the current age of a second (or third, etc.) engine in a train vehicle.
	 * @param vehicle_id The vehicle to get the age of.
	 * @param wagon The wagon in the vehicle to get the age of.
	 * @pre IsValidVehicle(vehicle_id).
	 * @pre wagon < GetNumWagons(vehicle_id).
	 * @return The current age the vehicle has.
	 * @note The age is in days.
	 */
	static SQInteger GetWagonAge(VehicleID vehicle_id, SQInteger wagon);

	/**
	 * Get the maximum age of a vehicle.
	 * @param vehicle_id The vehicle to get the age of.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @return The maximum age the vehicle has.
	 * @note The age is in days.
	 */
	static SQInteger GetMaxAge(VehicleID vehicle_id);

	/**
	 * Get the age a vehicle has left (maximum - current).
	 * @param vehicle_id The vehicle to get the age of.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @return The age the vehicle has left.
	 * @note The age is in days.
	 */
	static SQInteger GetAgeLeft(VehicleID vehicle_id);

	/**
	 * Get the current speed of a vehicle.
	 * @param vehicle_id The vehicle to get the speed of.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @return The current speed of the vehicle.
	 * @note The speed is in OpenTTD's internal speed unit.
	 *       This is mph / 1.6, which is roughly km/h.
	 *       To get km/h multiply this number by 1.00584.
	 */
	static SQInteger GetCurrentSpeed(VehicleID vehicle_id);

	/**
	 * Get the current state of a vehicle.
	 * @param vehicle_id The vehicle to get the state of.
	 * @pre IsValidVehicle(vehicle_id).
	 * @return The current state of the vehicle.
	 */
	static VehicleState GetState(VehicleID vehicle_id);

	/**
	 * Get the running cost of this vehicle.
	 * @param vehicle_id The vehicle to get the running cost of.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @return The running cost of the vehicle per year.
	 * @note Cost is per year; divide by 365 to get per day.
	 * @note This is not equal to ScriptEngine::GetRunningCost for Trains, because
	 *   wagons and second engines can add up in the calculation too.
	 */
	static Money GetRunningCost(VehicleID vehicle_id);

	/**
	 * Get the current profit of a vehicle.
	 * @param vehicle_id The vehicle to get the profit of.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @return The current profit the vehicle has.
	 */
	static Money GetProfitThisYear(VehicleID vehicle_id);

	/**
	 * Get the profit of last year of a vehicle.
	 * @param vehicle_id The vehicle to get the profit of.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @return The profit the vehicle had last year.
	 */
	static Money GetProfitLastYear(VehicleID vehicle_id);


	/**
	 * Get the current value of a vehicle.
	 * @param vehicle_id The vehicle to get the value of.
	 * @pre IsValidVehicle(vehicle_id).
	 * @return The value the vehicle currently has (the amount you should get
	 *  when you would sell the vehicle right now).
	 */
	static Money GetCurrentValue(VehicleID vehicle_id);

	/**
	 * Get the type of vehicle.
	 * @param vehicle_id The vehicle to get the type of.
	 * @pre IsValidVehicle(vehicle_id).
	 * @return The vehicle type.
	 */
	static ScriptVehicle::VehicleType GetVehicleType(VehicleID vehicle_id);

	/**
	 * Get the RoadType of the vehicle.
	 * @param vehicle_id The vehicle to get the RoadType of.
	 * @pre IsValidVehicle(vehicle_id).
	 * @pre GetVehicleType(vehicle_id) == VT_ROAD.
	 * @return The RoadType the vehicle has.
	 */
	static ScriptRoad::RoadType GetRoadType(VehicleID vehicle_id);

	/**
	 * Check if a vehicle is in a depot.
	 * @param vehicle_id The vehicle to check.
	 * @pre IsValidVehicle(vehicle_id).
	 * @return True if and only if the vehicle is in a depot.
	 */
	static bool IsInDepot(VehicleID vehicle_id);

	/**
	 * Check if a vehicle is in a depot and stopped.
	 * @param vehicle_id The vehicle to check.
	 * @pre IsValidVehicle(vehicle_id).
	 * @return True if and only if the vehicle is in a depot and stopped.
	 */
	static bool IsStoppedInDepot(VehicleID vehicle_id);

	/**
	 * Builds a vehicle with the given engine at the given depot.
	 * @param depot The depot where the vehicle will be build.
	 * @param engine_id The engine to use for this vehicle.
	 * @pre The tile at depot has a depot that can build the engine and
	 *   is owned by you.
	 * @pre ScriptEngine::IsBuildable(engine_id).
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @exception ScriptVehicle::ERR_VEHICLE_TOO_MANY
	 * @exception ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED
	 * @exception ScriptVehicle::ERR_VEHICLE_WRONG_DEPOT
	 * @return The VehicleID of the new vehicle, or an invalid VehicleID when
	 *   it failed. Check the return value using IsValidVehicle. In test-mode
	 *   0 is returned if it was successful; any other value indicates failure.
	 * @note Unlike the GUI, wagons are not automatically attached to trains,
	 *   only to existing free wagons. This means that BuildVehicle can sometimes
	 *   return an ID indicating success, but IsValidVehicle check will
	 *   fail. You should use MoveWagon to attach free wagons to trains.
	 * @note In Test Mode it means you can't assign orders yet to this vehicle,
	 *   as the vehicle isn't really built yet. Build it for real first before
	 *   assigning orders.
	 */
	static VehicleID BuildVehicle(TileIndex depot, EngineID engine_id);

	/**
	 * Builds a vehicle with the given engine at the given depot and refits it to the given cargo.
	 * @param depot The depot where the vehicle will be build.
	 * @param engine_id The engine to use for this vehicle.
	 * @param cargo The cargo to refit to.
	 * @pre The tile at depot has a depot that can build the engine and
	 *   is owned by you.
	 * @pre ScriptEngine::IsBuildable(engine_id).
	 * @pre ScriptCargo::IsValidCargo(cargo).
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @exception ScriptVehicle::ERR_VEHICLE_TOO_MANY
	 * @exception ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED
	 * @exception ScriptVehicle::ERR_VEHICLE_WRONG_DEPOT
	 * @return The VehicleID of the new vehicle, or an invalid VehicleID when
	 *   it failed. Check the return value using IsValidVehicle. In test-mode
	 *   0 is returned if it was successful; any other value indicates failure.
	 * @note In Test Mode it means you can't assign orders yet to this vehicle,
	 *   as the vehicle isn't really built yet. Build it for real first before
	 *   assigning orders.
	 */
	static VehicleID BuildVehicleWithRefit(TileIndex depot, EngineID engine_id, CargoID cargo);

	/**
	 * Gets the capacity of a vehicle built at the given depot with the given engine and refitted to the given cargo.
	 * @param depot The depot where the vehicle will be build.
	 * @param engine_id The engine to use for this vehicle.
	 * @param cargo The cargo to refit to.
	 * @pre The tile at depot has a depot that can build the engine and
	 *   is owned by you.
	 * @pre ScriptEngine::IsBuildable(engine_id).
	 * @pre ScriptCargo::IsValidCargo(cargo).
	 * @return The capacity the vehicle will have when refited.
	 */
	static SQInteger GetBuildWithRefitCapacity(TileIndex depot, EngineID engine_id, CargoID cargo);

	/**
	 * Clones a vehicle at the given depot, copying or cloning its orders.
	 * @param depot The depot where the vehicle will be build.
	 * @param vehicle_id The vehicle to use as example for the new vehicle.
	 * @param share_orders Should the orders be copied or shared?
	 * @pre The tile 'depot' has a depot on it, allowing 'vehicle_id'-type vehicles.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @exception ScriptVehicle::ERR_VEHICLE_TOO_MANY
	 * @exception ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED
	 * @exception ScriptVehicle::ERR_VEHICLE_WRONG_DEPOT
	 * @return The VehicleID of the new vehicle, or an invalid VehicleID when
	 *   it failed. Check the return value using IsValidVehicle. In test-mode
	 *   0 is returned if it was successful; any other value indicates failure.
	 */
	static VehicleID CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders);

	/**
	 * Move a wagon after another wagon.
	 * @param source_vehicle_id The vehicle to move a wagon away from.
	 * @param source_wagon The wagon in source_vehicle to move.
	 * @param dest_vehicle_id The vehicle to move the wagon to, or -1 to create a new vehicle.
	 * @param dest_wagon The wagon in dest_vehicle to place source_wagon after.
	 * @pre IsValidVehicle(source_vehicle_id).
	 * @pre source_wagon < GetNumWagons(source_vehicle_id).
	 * @pre dest_vehicle_id == -1 || (IsValidVehicle(dest_vehicle_id) && dest_wagon < GetNumWagons(dest_vehicle_id)).
	 * @pre GetVehicleType(source_vehicle_id) == VT_RAIL.
	 * @pre dest_vehicle_id == -1 || GetVehicleType(dest_vehicle_id) == VT_RAIL.
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @return Whether or not moving the wagon succeeded.
	 */
	static bool MoveWagon(VehicleID source_vehicle_id, SQInteger source_wagon, SQInteger dest_vehicle_id, SQInteger dest_wagon);

	/**
	 * Move a chain of wagons after another wagon.
	 * @param source_vehicle_id The vehicle to move a wagon away from.
	 * @param source_wagon The first wagon in source_vehicle to move.
	 * @param dest_vehicle_id The vehicle to move the wagons to, or -1 to create a new vehicle.
	 * @param dest_wagon The wagon in dest_vehicle to place source_wagon and following wagons after.
	 * @pre IsValidVehicle(source_vehicle_id).
	 * @pre source_wagon < GetNumWagons(source_vehicle_id).
	 * @pre dest_vehicle_id == -1 || (IsValidVehicle(dest_vehicle_id) && dest_wagon < GetNumWagons(dest_vehicle_id)).
	 * @pre GetVehicleType(source_vehicle_id) == VT_RAIL.
	 * @pre dest_vehicle_id == -1 || GetVehicleType(dest_vehicle_id) == VT_RAIL.
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @return Whether or not moving the wagons succeeded.
	 */
	static bool MoveWagonChain(VehicleID source_vehicle_id, SQInteger source_wagon, SQInteger dest_vehicle_id, SQInteger dest_wagon);

	/**
	 * Gets the capacity of the given vehicle when refitted to the given cargo type.
	 * @param vehicle_id The vehicle to refit.
	 * @param cargo The cargo to refit to.
	 * @pre IsValidVehicle(vehicle_id).
	 * @pre ScriptCargo::IsValidCargo(cargo).
	 * @pre You must own the vehicle.
	 * @pre The vehicle must be stopped in the depot.
	 * @return The capacity the vehicle will have when refited.
	 */
	static SQInteger GetRefitCapacity(VehicleID vehicle_id, CargoID cargo);

	/**
	 * Refits a vehicle to the given cargo type.
	 * @param vehicle_id The vehicle to refit.
	 * @param cargo The cargo to refit to.
	 * @pre IsValidVehicle(vehicle_id).
	 * @pre ScriptCargo::IsValidCargo(cargo).
	 * @pre You must own the vehicle.
	 * @pre The vehicle must be stopped in the depot.
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @exception ScriptVehicle::ERR_VEHICLE_CANNOT_REFIT
	 * @exception ScriptVehicle::ERR_VEHICLE_IS_DESTROYED
	 * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT
	 * @return True if and only if the refit succeeded.
	 */
	static bool RefitVehicle(VehicleID vehicle_id, CargoID cargo);

	/**
	 * Sells the given vehicle.
	 * @param vehicle_id The vehicle to sell.
	 * @pre IsValidVehicle(vehicle_id).
	 * @pre You must own the vehicle.
	 * @pre The vehicle must be stopped in the depot.
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @exception ScriptVehicle::ERR_VEHICLE_IS_DESTROYED
	 * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT
	 * @return True if and only if the vehicle has been sold.
	 */
	static bool SellVehicle(VehicleID vehicle_id);

	/**
	 * Sells the given wagon from the vehicle.
	 * @param vehicle_id The vehicle to sell a wagon from.
	 * @param wagon The wagon to sell.
	 * @pre IsValidVehicle(vehicle_id).
	 * @pre wagon < GetNumWagons(vehicle_id).
	 * @pre You must own the vehicle.
	 * @pre The vehicle must be stopped in the depot.
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @exception ScriptVehicle::ERR_VEHICLE_IS_DESTROYED
	 * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT
	 * @return True if and only if the wagon has been sold.
	 */
	static bool SellWagon(VehicleID vehicle_id, SQInteger wagon);

	/**
	 * Sells all wagons from the vehicle starting from a given position.
	 * @param vehicle_id The vehicle to sell a wagon from.
	 * @param wagon The wagon to sell.
	 * @pre IsValidVehicle(vehicle_id).
	 * @pre wagon < GetNumWagons(vehicle_id).
	 * @pre You must own the vehicle.
	 * @pre The vehicle must be stopped in the depot.
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @exception ScriptVehicle::ERR_VEHICLE_IS_DESTROYED
	 * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT
	 * @return True if and only if the wagons have been sold.
	 */
	static bool SellWagonChain(VehicleID vehicle_id, SQInteger wagon);

	/**
	 * Sends the given vehicle to a depot. If the vehicle has already been
	 * sent to a depot it continues with its normal orders instead.
	 * @param vehicle_id The vehicle to send to a depot.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @exception ScriptVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT
	 * @return True if the current order was changed.
	 */
	static bool SendVehicleToDepot(VehicleID vehicle_id);

	/**
	 * Sends the given vehicle to a depot for servicing. If the vehicle has
	 * already been sent to a depot it continues with its normal orders instead.
	 * @param vehicle_id The vehicle to send to a depot for servicing.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @exception ScriptVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT
	 * @return True if the current order was changed.
	 */
	static bool SendVehicleToDepotForServicing(VehicleID vehicle_id);

	/**
	 * Starts or stops the given vehicle depending on the current state.
	 * @param vehicle_id The vehicle to start/stop.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @exception ScriptVehicle::ERR_VEHICLE_CANNOT_START_STOP
	 * @exception (For aircraft only): ScriptVehicle::ERR_VEHICLE_IN_FLIGHT
	 * @exception (For trains only): ScriptVehicle::ERR_VEHICLE_NO_POWER
	 * @return True if and only if the vehicle has been started or stopped.
	 */
	static bool StartStopVehicle(VehicleID vehicle_id);

	/**
	 * Turn the given vehicle so it'll drive the other way.
	 * @param vehicle_id The vehicle to turn.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @pre GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL.
	 * @game @pre ScriptCompanyMode::IsValid().
	 * @return True if and only if the vehicle has started to turn.
	 * @note Vehicles cannot always be reversed. For example busses and trucks need to be running
	 *  and not be inside a depot.
	 */
	static bool ReverseVehicle(VehicleID vehicle_id);

	/**
	 * Get the maximum amount of a specific cargo the given vehicle can transport.
	 * @param vehicle_id The vehicle to get the capacity of.
	 * @param cargo The cargo to get the capacity for.
	 * @pre IsValidVehicle(vehicle_id).
	 * @pre ScriptCargo::IsValidCargo(cargo).
	 * @return The maximum amount of the given cargo the vehicle can transport.
	 */
	static SQInteger GetCapacity(VehicleID vehicle_id, CargoID cargo);

	/**
	 * Get the length of a the total vehicle in 1/16's of a tile.
	 * @param vehicle_id The vehicle to get the length of.
	 * @pre IsValidVehicle(vehicle_id).
	 * @pre GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL.
	 * @return The length of the engine.
	 */
	static SQInteger GetLength(VehicleID vehicle_id);

	/**
	 * Get the amount of a specific cargo the given vehicle is transporting.
	 * @param vehicle_id The vehicle to get the load amount of.
	 * @param cargo The cargo to get the loaded amount for.
	 * @pre IsValidVehicle(vehicle_id).
	 * @pre ScriptCargo::IsValidCargo(cargo).
	 * @return The amount of the given cargo the vehicle is currently transporting.
	 */
	static SQInteger GetCargoLoad(VehicleID vehicle_id, CargoID cargo);

	/**
	 * Get the group of a given vehicle.
	 * @param vehicle_id The vehicle to get the group from.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @return The group of the given vehicle.
	 */
	static GroupID GetGroupID(VehicleID vehicle_id);

	/**
	 * Check if the vehicle is articulated.
	 * @param vehicle_id The vehicle to check.
	 * @pre IsValidVehicle(vehicle_id).
	 * @pre GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL.
	 * @return True if the vehicle is articulated.
	 */
	static bool IsArticulated(VehicleID vehicle_id);

	/**
	 * Check if the vehicle has shared orders.
	 * @param vehicle_id The vehicle to check.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @return True if the vehicle has shared orders.
	 */
	static bool HasSharedOrders(VehicleID vehicle_id);

	/**
	 * Get the current reliability of a vehicle.
	 * @param vehicle_id The vehicle to check.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @return The current reliability (0-100%).
	 */
	static SQInteger GetReliability(VehicleID vehicle_id);

	/**
	 * Get the maximum allowed distance between two orders for a vehicle.
	 * The distance returned is a vehicle-type specific distance independent from other
	 * map distances, you may use the result of this function to compare it
	 * with the result of ScriptOrder::GetOrderDistance.
	 * @param vehicle_id The vehicle to get the distance for.
	 * @pre IsPrimaryVehicle(vehicle_id).
	 * @return The maximum distance between two orders for this vehicle
	 *         or 0 if the distance is unlimited.
	 * @note   The unit of the order distances is unspecified and should
	 *         not be compared with map distances
	 * @see ScriptOrder::GetOrderDistance
	 */
	static SQInteger GetMaximumOrderDistance(VehicleID vehicle_id);

private:
	/**
	 * Internal function used by BuildVehicle(WithRefit).
	 */
	static VehicleID _BuildVehicleInternal(TileIndex depot, EngineID engine_id, CargoID cargo);

	/**
	 * Internal function used by SellWagon(Chain).
	 */
	static bool _SellWagonInternal(VehicleID vehicle_id, SQInteger wagon, bool sell_attached_wagons);

	/**
	 * Internal function used by MoveWagon(Chain).
	 */
	static bool _MoveWagonInternal(VehicleID source_vehicle_id, SQInteger source_wagon, bool move_attached_wagons, SQInteger dest_vehicle_id, SQInteger dest_wagon);
};

#endif /* SCRIPT_VEHICLE_HPP */