OpenTTD Source
20241124-master-g9399a92a4f
|
Implementation of articulated vehicles. More...
#include "stdafx.h"
#include "core/bitmath_func.hpp"
#include "core/random_func.hpp"
#include "train.h"
#include "roadveh.h"
#include "vehicle_func.h"
#include "engine_func.h"
#include "company_func.h"
#include "newgrf.h"
#include "table/strings.h"
#include "safeguards.h"
Go to the source code of this file.
Functions | |
static EngineID | GetNextArticulatedPart (uint index, EngineID front_type, Vehicle *front=nullptr, bool *mirrored=nullptr) |
Determines the next articulated part to attach. More... | |
bool | IsArticulatedEngine (EngineID engine_type) |
Does a NewGRF report that this should be an articulated vehicle? More... | |
uint | CountArticulatedParts (EngineID engine_type, bool purchase_window) |
Count the number of articulated parts of an engine. More... | |
static uint16_t | GetVehicleDefaultCapacity (EngineID engine, CargoID *cargo_type) |
Returns the default (non-refitted) capacity of a specific EngineID. More... | |
static CargoTypes | GetAvailableVehicleCargoTypes (EngineID engine, bool include_initial_cargo_type) |
Returns all cargoes a vehicle can carry. 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... | |
bool | IsArticulatedVehicleRefittable (EngineID engine) |
Checks whether any of the articulated parts is refittable. 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... | |
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... | |
void | AddArticulatedParts (Vehicle *first) |
Add the remaining articulated parts to the given vehicle. More... | |
Variables | |
static const uint | MAX_ARTICULATED_PARTS = 100 |
Maximum of articulated parts per vehicle, i.e. when to abort calling the articulated vehicle callback. | |
Implementation of articulated vehicles.
Definition in file articulated_vehicles.cpp.
void AddArticulatedParts | ( | Vehicle * | first | ) |
Add the remaining articulated parts to the given vehicle.
first | The head of the articulated bit. |
Definition at line 339 of file articulated_vehicles.cpp.
References HasBit(), and BaseVehicle::type.
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:
Definition at line 297 of file articulated_vehicles.cpp.
References Vehicle::engine_type, GetArticulatedRefitMasks(), GetCapacityOfArticulatedParts(), and Vehicle::GetEngine().
uint CountArticulatedParts | ( | EngineID | engine_type, |
bool | purchase_window | ||
) |
Count the number of articulated parts of an engine.
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. |
Definition at line 75 of file articulated_vehicles.cpp.
References HasBit().
Referenced by CmdBuildVehicle().
void GetArticulatedRefitMasks | ( | EngineID | engine, |
bool | include_initial_cargo_type, | ||
CargoTypes * | union_mask, | ||
CargoTypes * | intersection_mask | ||
) |
Merges the refit_masks of all articulated parts.
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 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().
|
inlinestatic |
Returns all cargoes a vehicle can carry.
engine | the EngineID of interest |
include_initial_cargo_type | if true the default cargo type of the vehicle is included; if false only the refit_mask |
Definition at line 122 of file articulated_vehicles.cpp.
References Engine::CanCarryCargo(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetDefaultCargoType(), and SetBit().
Referenced by GetArticulatedRefitMasks().
CargoArray GetCapacityOfArticulatedParts | ( | EngineID | engine | ) |
Get the capacity of the parts of a given engine.
engine | The engine to get the capacities from. |
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().
CargoTypes GetCargoTypesOfArticulatedParts | ( | EngineID | engine | ) |
Get the cargo mask of the parts of a given engine.
engine | The engine to get the capacities from. |
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().
Get cargo mask of all cargoes carried by an articulated vehicle.
Note: Vehicles not carrying anything are ignored
v | the first vehicle in the chain |
cargo_type | returns the common CargoID if needed. (INVALID_CARGO if no part is carrying something or they are carrying different things) |
Definition at line 265 of file articulated_vehicles.cpp.
Referenced by GetNewCargoTypeForReplace(), and Vehicle::NeedsServicing().
|
static |
Determines the next articulated part to attach.
index | Position in chain |
front_type | Front engine type |
front | Front engine |
mirrored | Returns whether the part shall be flipped. |
Definition at line 34 of file articulated_vehicles.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().
Referenced by IsArticulatedVehicleRefittable().
CargoTypes GetUnionOfArticulatedRefitMasks | ( | EngineID | engine, |
bool | include_initial_cargo_type | ||
) |
Ors the refit_masks of all articulated parts.
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 |
Definition at line 251 of file articulated_vehicles.cpp.
References GetArticulatedRefitMasks().
Referenced by CargoAndEngineFilter(), EnginesHaveCargoInCommon(), GetIncompatibleRefitOrderIdForAutoreplace(), GetPreviewCompany(), and VerifyAutoreplaceRefitForOrders().
Returns the default (non-refitted) capacity of a specific EngineID.
engine | the EngineID of interest |
cargo_type | returns the default cargo type, if needed |
Definition at line 107 of file articulated_vehicles.cpp.
bool IsArticulatedEngine | ( | EngineID | engine_type | ) |
Does a NewGRF report that this should be an articulated vehicle?
engine_type | The engine to check. |
Definition at line 64 of file articulated_vehicles.cpp.
References HasBit().
bool IsArticulatedVehicleRefittable | ( | EngineID | engine | ) |
Checks whether any of the articulated parts is refittable.
engine | the first part |
Definition at line 199 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(), GetNextArticulatedPart(), HasBit(), INVALID_ENGINE, IsEngineRefittable(), Engine::IsGroundVehicle(), and MAX_ARTICULATED_PARTS.