Functions

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.
CargoArray GetCapacityOfArticulatedParts (EngineID engine)
 Get the capacity of the parts of a given engine.
void AddArticulatedParts (Vehicle *first)
 Add the remaining articulated parts to the given vehicle.
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 IsArticulatedVehicleCarryingDifferentCargoes (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 AddArticulatedParts ( Vehicle first  ) 
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 267 of file articulated_vehicles.cpp.

References Vehicle::cargo_cap, Vehicle::cargo_type, Vehicle::engine_type, GBUG_VEH_REFIT, GetArticulatedRefitMasks(), GetAvailableVehicleCargoTypes(), GetCapacityOfArticulatedParts(), Vehicle::GetEngine(), Vehicle::GetNextArticulatedPart(), Vehicle::HasArticulatedPart(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, NUM_CARGO, and ShowNewGrfVehicleError().

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

uint CountArticulatedParts ( EngineID  engine_type,
bool  purchase_window 
)

Count the number of articulated parts of an engine.

Parameters:
engine_type The engine to get the number of parts of.
purchase_window Whether we are in the scope of the purchase window or not, i.e. whether we cannot allocate vehicles.
Returns:
The nmumber of parts.

Definition at line 64 of file articulated_vehicles.cpp.

References _current_company, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::CanAllocateItem(), CBM_VEHICLE_ARTIC_ENGINE, Vehicle::engine_type, GetNextArticulatedPart(), HasBit(), INVALID_ENGINE, MAX_ARTICULATED_PARTS, and Vehicle::owner.

Referenced by CmdBuildVehicle(), and ScriptEngine::IsArticulated().

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

References EngineInfo::callback_mask, CBM_VEHICLE_ARTIC_ENGINE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetAvailableVehicleCargoTypes(), GetNextArticulatedPart(), HasBit(), INVALID_ENGINE, Engine::IsGroundVehicle(), and MAX_ARTICULATED_PARTS.

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

CargoArray GetCapacityOfArticulatedParts ( EngineID  engine  ) 
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 224 of file articulated_vehicles.cpp.

References GetArticulatedRefitMasks().

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

References GetArticulatedRefitMasks().

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

bool IsArticulatedVehicleCarryingDifferentCargoes ( 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 cargoes, false if all parts are carrying the same (nothing is also the same)

Definition at line 239 of file articulated_vehicles.cpp.

References Vehicle::cargo_cap, Vehicle::cargo_type, CT_INVALID, Vehicle::GetNextArticulatedPart(), and Vehicle::HasArticulatedPart().

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

bool IsArticulatedVehicleRefittable ( EngineID  engine  )