# articulated_vehicles.cpp File Reference

Implementation of articulated vehicles. More...

`#include "stdafx.h"`
`#include "train.h"`
`#include "roadveh.h"`
`#include "newgrf_engine.h"`
`#include "vehicle_func.h"`

Go to the source code of this file.

## Functions

uint | CountArticulatedParts (EngineID engine_type, bool purchase_window)
static uint16 | GetVehicleDefaultCapacity (EngineID engine, VehicleType type, CargoID *cargo_type)
| Returns the default (non-refitted) capacity of a specific EngineID.
static uint32 | GetAvailableVehicleCargoTypes (EngineID engine, VehicleType type, bool include_initial_cargo_type)
| Returns all cargos a vehicle can carry.
uint16 * | GetCapacityOfArticulatedParts (EngineID engine, 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.
void | AddArticulatedParts (Vehicle **vl, VehicleType type)

## Variables

static const uint | MAX_ARTICULATED_PARTS = 100
| Maximum of articulated parts per vehicle, i.e. when to abort calling the articulated vehicle callback.

## Detailed Description

Implementation of articulated vehicles.

Definition in file articulated_vehicles.cpp.

## Function Documentation

static uint32 GetAvailableVehicleCargoTypes | ( | EngineID | engine,
|  | VehicleType | type,
|  | bool | include_initial_cargo_type |
| ) |  |  | `[inline, static]`

Returns all cargos a vehicle can carry.

Parameters:

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

Returns:
  bit set of CargoIDs

Definition at line 85 of file articulated_vehicles.cpp.

References GetVehicleDefaultCapacity(), EngineInfo::refit_mask, and SetBit().

Referenced by GetIntersectionOfArticulatedRefitMasks(), and GetUnionOfArticulatedRefitMasks().

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

Ands the refit_masks of all articulated parts.

Note: Vehicles with a default capacity of zero are ignored.

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 162 of file articulated_vehicles.cpp.

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

Referenced by GetNewCargoTypeForReplace().

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

Ors the refit_masks of all articulated parts.

Note: Vehicles with a default capacity of zero are ignored.

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 135 of file articulated_vehicles.cpp.

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

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

static uint16 GetVehicleDefaultCapacity | ( | EngineID | engine,
|  | VehicleType | type,
|  | CargoID * | cargo_type |
| ) |  |  | `[inline, static]`

Returns the default (non-refitted) capacity of a specific EngineID.

Parameters:

  | engine | the EngineID of iterest
  | type | the type of the engine
  | cargo_type | returns the default cargo type, if needed

Returns:
  capacity

Definition at line 46 of file articulated_vehicles.cpp.

References RAILVEH_MULTIHEAD.

Referenced by GetAvailableVehicleCargoTypes().

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 193 of file articulated_vehicles.cpp.

References EngineHasArticPart(), and GetNextArticPart().

Referenced by GetNewCargoTypeForReplace().