# articulated_vehicles.h File Reference

Functions related to articulated vehicles. More...

`#include "vehicle_type.h"`
`#include "engine_type.h"`

Go to the source code of this file.

## Functions
uint | CountArticulatedParts (EngineID engine_type, bool purchase_window)
uint16 * | GetCapacityOfArticulatedParts (EngineID engine, VehicleType type)
void | AddArticulatedParts (Vehicle **vl, VehicleType type)
uint32 | GetUnionOfArticulatedRefitMasks (EngineID engine, VehicleType type, bool include_initial_cargo_type)
| Ors the refit_masks of all articulated parts.
uint32 | GetIntersectionOfArticulatedRefitMasks (EngineID engine, VehicleType type, bool include_initial_cargo_type)
| Ands the refit_masks of all articulated parts.
bool | IsArticulatedVehicleCarryingDifferentCargos (const Vehicle *v, CargoID *cargo_type)
| Tests if all parts of an articulated vehicle are refitted to the same cargo.
bool | IsArticulatedVehicleRefittable (EngineID engine)
| Checks whether any of the articulated parts is refittable.
void | CheckConsistencyOfArticulatedVehicle (const Vehicle *v)
| Checks whether the specs of freshly build articulated vehicles are consistent with the information specified in the purchase list.

## Detailed Description

Functions related to articulated vehicles.

Definition in file articulated_vehicles.h.

## Function Documentation

void CheckConsistencyOfArticulatedVehicle | ( | const Vehicle * | v | ) |

Checks whether the specs of freshly build articulated vehicles are consistent with the information specified in the purchase list.

Only essential information is checked to leave room for magic tricks/workarounds to grfcoders. It checks: For autoreplace/-renew:

- Default cargo type (without capacity)
- intersection and union of refit masks.

Definition at line 235 of file articulated_vehicles.cpp.

References EngineHasArticPart(), GBUG_VEH_REFIT, GetAvailableVehicleCargoTypes(), GetIntersectionOfArticulatedRefitMasks(), GetNextArticPart(), GetUnionOfArticulatedRefitMasks(), and ShowNewGrfVehicleError().

Referenced by CmdBuildRailVehicle(), CmdBuildRailWagon(), and CmdBuildRoadVeh().

uint32 GetIntersectionOfArticulatedRefitMasks | ( | EngineID | engine,
|  | VehicleType | type,
|  | bool | include_initial_cargo_type |
| ) |  |  |

Ands the refit_masks of all articulated parts.

Parameters:

  | engine | the first part
  | type | the vehicle type
  | include_initial_cargo_type | if true the default cargo type of the vehicle is included; if false only the refit_mask

Returns:
  bit mask of CargoIDs which are a refit option for every articulated part (with default capacity > 0)

Definition at line 164 of file articulated_vehicles.cpp.

References CALLBACK_FAILED, CBID_VEHICLE_ARTIC_ENGINE, CBM_VEHICLE_ARTIC_ENGINE, GB(), GetAvailableVehicleCargoTypes(), GetEngineGRF(), GetVehicleCallback(), and HasBit().

Referenced by CheckConsistencyOfArticulatedVehicle(), and GetNewCargoTypeForReplace().

uint32 GetUnionOfArticulatedRefitMasks | ( | EngineID | engine,
|  | VehicleType | type,
|  | bool | include_initial_cargo_type |
| ) |  |  |

Ors the refit_masks of all articulated parts.

Parameters:

  | engine | the first part
  | type | the vehicle type
  | include_initial_cargo_type | if true the default cargo type of the vehicle is included; if false only the refit_mask

Returns:
  bit mask of CargoIDs which are a refit option for at least one articulated part

Definition at line 138 of file articulated_vehicles.cpp.

References CALLBACK_FAILED, CBID_VEHICLE_ARTIC_ENGINE, CBM_VEHICLE_ARTIC_ENGINE, GB(), GetAvailableVehicleCargoTypes(), GetEngineGRF(), GetVehicleCallback(), and HasBit().

Referenced by CheckConsistencyOfArticulatedVehicle(), EnginesGotCargoInCommon(), GetNewCargoTypeForReplace(), ShowRefitOptionsList(), and VerifyAutoreplaceRefitForOrders().

bool IsArticulatedVehicleCarryingDifferentCargos | ( | const Vehicle * | v,
|  | CargoID * | cargo_type |
| ) |  |  |

Tests if all parts of an articulated vehicle are refitted to the same cargo.

Note: Vehicles not carrying anything are ignored

Parameters:

  | v | the first vehicle in the chain
  | cargo_type | returns the common CargoID if needed. (CT_INVALID if no part is carrying something or they are carrying different things)

Returns:
  true if some parts are carrying different cargos, false if all parts are carrying the same (nothing is also the same)

Definition at line 195 of file articulated_vehicles.cpp.

References EngineHasArticPart(), and GetNextArticPart().

Referenced by GetNewCargoTypeForReplace().

bool IsArticulatedVehicleRefittable | ( | EngineID | engine | ) |

Checks whether any of the articulated parts is refittable.

Parameters:

  | engine | the first part

Returns:
  true if refittable

Definition at line 111 of file articulated_vehicles.cpp.

References CALLBACK_FAILED, CBID_VEHICLE_ARTIC_ENGINE, CBM_VEHICLE_ARTIC_ENGINE, GB(), GetEngineGRF(), GetVehicleCallback(), HasBit(), and IsEngineRefittable().

Referenced by DrawVehiclePurchaseInfo().