OpenTTD Source  20241121-master-g67a0fccfad
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)
 Count the number of articulated parts of an engine. More...
 
CargoArray GetCapacityOfArticulatedParts (EngineID engine)
 Get the capacity of the parts of a given engine. More...
 
CargoTypes GetCargoTypesOfArticulatedParts (EngineID engine)
 Get the cargo mask of the parts of a given engine. More...
 
void AddArticulatedParts (Vehicle *first)
 Add the remaining articulated parts to the given vehicle. More...
 
void GetArticulatedRefitMasks (EngineID engine, bool include_initial_cargo_type, CargoTypes *union_mask, CargoTypes *intersection_mask)
 Merges the refit_masks of all articulated parts. More...
 
CargoTypes GetUnionOfArticulatedRefitMasks (EngineID engine, bool include_initial_cargo_type)
 Ors the refit_masks of all articulated parts. More...
 
CargoTypes GetCargoTypesOfArticulatedVehicle (const Vehicle *v, CargoID *cargo_type)
 Get cargo mask of all cargoes carried by an articulated vehicle. More...
 
bool IsArticulatedVehicleRefittable (EngineID engine)
 Checks whether any of the articulated parts is refittable. More...
 
bool IsArticulatedEngine (EngineID engine_type)
 Does a NewGRF report that this should be an articulated vehicle? More...
 
void CheckConsistencyOfArticulatedVehicle (const Vehicle *v)
 Checks whether the specs of freshly build articulated vehicles are consistent with the information specified in the purchase list. More...
 

Detailed Description

Functions related to articulated vehicles.

Definition in file articulated_vehicles.h.

Function Documentation

◆ AddArticulatedParts()

void AddArticulatedParts ( Vehicle first)

Add the remaining articulated parts to the given vehicle.

Parameters
firstThe head of the articulated bit.

Definition at line 339 of file articulated_vehicles.cpp.

References HasBit(), and BaseVehicle::type.

◆ CheckConsistencyOfArticulatedVehicle()

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

References Vehicle::engine_type, GetArticulatedRefitMasks(), GetCapacityOfArticulatedParts(), and Vehicle::GetEngine().

◆ CountArticulatedParts()

uint CountArticulatedParts ( EngineID  engine_type,
bool  purchase_window 
)

Count the number of articulated parts of an engine.

Parameters
engine_typeThe engine to get the number of parts of.
purchase_windowWhether we are in the scope of the purchase window or not, i.e. whether we cannot allocate vehicles.
Returns
The number of parts.

Definition at line 75 of file articulated_vehicles.cpp.

References HasBit().

Referenced by CmdBuildVehicle().

◆ GetArticulatedRefitMasks()

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

Merges the refit_masks of all articulated parts.

Parameters
enginethe first part
include_initial_cargo_typeif true the default cargo type of the vehicle is included; if false only the refit_mask
union_maskreturns bit mask of CargoIDs which are a refit option for at least one articulated part
intersection_maskreturns bit mask of CargoIDs which are a refit option for every articulated part (with default capacity > 0)

Definition at line 225 of file articulated_vehicles.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), and GetAvailableVehicleCargoTypes().

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

◆ GetCapacityOfArticulatedParts()

CargoArray GetCapacityOfArticulatedParts ( EngineID  engine)

Get the capacity of the parts of a given engine.

Parameters
engineThe engine to get the capacities from.
Returns
The cargo capacities.

Definition at line 141 of file articulated_vehicles.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().

Referenced by CheckConsistencyOfArticulatedVehicle(), and GetTotalCapacityOfArticulatedParts().

◆ GetCargoTypesOfArticulatedParts()

CargoTypes GetCargoTypesOfArticulatedParts ( EngineID  engine)

Get the cargo mask of the parts of a given engine.

Parameters
engineThe engine to get the capacities from.
Returns
The cargo mask.

Definition at line 170 of file articulated_vehicles.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().

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

◆ GetCargoTypesOfArticulatedVehicle()

CargoTypes GetCargoTypesOfArticulatedVehicle ( const Vehicle v,
CargoID cargo_type 
)

Get cargo mask of all cargoes carried by an articulated vehicle.

Note: Vehicles not carrying anything are ignored

Parameters
vthe first vehicle in the chain
cargo_typereturns the common CargoID if needed. (INVALID_CARGO if no part is carrying something or they are carrying different things)
Returns
cargo mask, may be 0 if the no vehicle parts have cargo capacity

Definition at line 265 of file articulated_vehicles.cpp.

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

◆ GetUnionOfArticulatedRefitMasks()

CargoTypes GetUnionOfArticulatedRefitMasks ( EngineID  engine,
bool  include_initial_cargo_type 
)

Ors the refit_masks of all articulated parts.

Parameters
enginethe first part
include_initial_cargo_typeif 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 251 of file articulated_vehicles.cpp.

References GetArticulatedRefitMasks().

Referenced by CargoAndEngineFilter(), EnginesHaveCargoInCommon(), GetIncompatibleRefitOrderIdForAutoreplace(), GetPreviewCompany(), and VerifyAutoreplaceRefitForOrders().

◆ IsArticulatedEngine()

bool IsArticulatedEngine ( EngineID  engine_type)

Does a NewGRF report that this should be an articulated vehicle?

Parameters
engine_typeThe engine to check.
Returns
True iff the articulated engine callback flag is set.

Definition at line 64 of file articulated_vehicles.cpp.

References HasBit().

◆ IsArticulatedVehicleRefittable()

bool IsArticulatedVehicleRefittable ( EngineID  engine)