# 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"`
`#include "engine_base.h"`
`#include "engine_func.h"`
`#include "table/strings.h"`
`#include "table/sprites.h"`

Go to the source code of this file.

## Functions
static EngineID | GetNextArticPart (uint index, EngineID front_type, Vehicle *front=NULL, bool *mirrored=NULL)
| Determines the next articulated part to attach.
uint | CountArticulatedParts (EngineID engine_type, bool purchase_window)
static uint16 | GetVehicleDefaultCapacity (EngineID engine, CargoID *cargo_type)
| Returns the default (non-refitted) capacity of a specific EngineID.
static uint32 | GetAvailableVehicleCargoTypes (EngineID engine, bool include_initial_cargo_type)
| Returns all cargos a vehicle can carry.
CargoArray | GetCapacityOfArticulatedParts (EngineID engine)
bool | IsArticulatedVehicleRefittable (EngineID engine)
| Checks whether any of the articulated parts is refittable.
void | GetArticulatedRefitMasks (EngineID engine, bool include_initial_cargo_type, uint32 *union_mask, uint32 *intersection_mask)
| Merges the refit_masks of all articulated parts.
uint32 | GetUnionOfArticulatedRefitMasks (EngineID engine, bool include_initial_cargo_type)
| Ors the refit_masks of all articulated parts.
uint32 | GetIntersectionOfArticulatedRefitMasks (EngineID engine, 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 | CheckConsistencyOfArticulatedVehicle (const Vehicle *v)
| Checks whether the specs of freshly build articulated vehicles are consistent with the information specified in the purchase list.
void | AddArticulatedParts (Vehicle *first)
## 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

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

References Vehicle::cargo_cap, Vehicle::cargo_type, SpecializedVehicle< RoadVehicle, VEH_ROAD >::From(), SpecializedVehicle< Train, VEH_TRAIN >::From(), GBUG_VEH_REFIT, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetArticulatedRefitMasks(), GetAvailableVehicleCargoTypes(), Train::GetNextArticPart(), RoadVehicle::HasArticulatedPart(), Train::HasArticulatedPart(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::Next(), NUM_CARGO, ShowNewGrfVehicleError(), BaseVehicle::type, VEH_ROAD, and VEH_TRAIN.

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

void GetArticulatedRefitMasks | ( | EngineID | engine,
|  | bool | include_initial_cargo_type,
|  | uint32 * | union_mask,
|  | uint32 * | intersection_mask |
| ) |  |  |

Merges the refit_masks of all articulated parts.

Parameters:

  | engine | the first part
  | include_initial_cargo_type | if true the default cargo type of the vehicle is included; if false only the refit_mask
  | union_mask | returns bit mask of CargoIDs which are a refit option for at least one articulated part
  | intersection_mask | returns bit mask of CargoIDs which are a refit option for every articulated part (with default capacity > 0)

Definition at line 159 of file articulated_vehicles.cpp.

References EngineInfo::callback_mask, CBM_VEHICLE_ARTIC_ENGINE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetAvailableVehicleCargoTypes(), GetNextArticPart(), HasBit(), Engine::type, VEH_ROAD, and VEH_TRAIN.

Referenced by CheckConsistencyOfArticulatedVehicle(), GetIntersectionOfArticulatedRefitMasks(), GetNewCargoTypeForReplace(), GetUnionOfArticulatedRefitMasks(), and Vehicle::NeedsServicing().

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

Returns all cargos a vehicle can carry.

Parameters:

  | engine | the EngineID of iterest
  | 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 90 of file articulated_vehicles.cpp.

References GetVehicleDefaultCapacity(), NUM_CARGO, and SetBit().

Referenced by CheckConsistencyOfArticulatedVehicle(), and GetArticulatedRefitMasks().

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

Ands the refit_masks of all articulated parts.

Parameters:

  | engine | the first part
  | 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 198 of file articulated_vehicles.cpp.

References GetArticulatedRefitMasks().

static EngineID GetNextArticPart | ( | uint | index,
|  | EngineID | front_type,
|  | Vehicle * | front = `NULL`,
|  | bool * | mirrored = `NULL` |
| ) |  |  | `[static]`

Determines the next articulated part to attach.

Parameters:

  | index | Position in chain
  | front_type | Front engine type
  | front | Front engine
  | mirrored | Returns whether the part shall be flipped.

Returns:
  engine to add or INVALID_ENGINE

Definition at line 33 of file articulated_vehicles.cpp.

References CALLBACK_FAILED, CBID_VEHICLE_ARTIC_ENGINE, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetEngineGRF(), GetVehicleCallback(), and HasBit().

Referenced by GetArticulatedRefitMasks(), and IsArticulatedVehicleRefittable().

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

Ors the refit_masks of all articulated parts.

Parameters:

  | engine | the first part
  | 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 185 of file articulated_vehicles.cpp.

References GetArticulatedRefitMasks().

Referenced by AIEngine::CanRefitCargo(), CargoFilter(), EnginesHaveCargoInCommon(), ShowRefitOptionsList(), and VerifyAutoreplaceRefitForOrders().

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

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

Parameters:

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

Returns:
  capacity

Definition at line 75 of file articulated_vehicles.cpp.

References Engine::CanCarryCargo(), CT_INVALID, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetDefaultCargoType(), and Engine::GetDisplayDefaultCapacity().

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

References Vehicle::cargo_cap, Vehicle::cargo_type, CT_INVALID, SpecializedVehicle< RoadVehicle, VEH_ROAD >::From(), SpecializedVehicle< Train, VEH_TRAIN >::From(), Train::GetNextArticPart(), RoadVehicle::HasArticulatedPart(), Train::HasArticulatedPart(), Vehicle::Next(), BaseVehicle::type, VEH_ROAD, and VEH_TRAIN.

Referenced by GetNewCargoTypeForReplace(), and Vehicle::NeedsServicing().

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

References EngineInfo::callback_mask, CBM_VEHICLE_ARTIC_ENGINE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetNextArticPart(), HasBit(), IsEngineRefittable(), Engine::type, VEH_ROAD, and VEH_TRAIN.

Referenced by DrawVehiclePurchaseInfo().