OpenTTD
|
Implementation of articulated vehicles. More...
#include "stdafx.h"
#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=NULL, bool *mirrored=NULL) |
Determines the next articulated part to attach. | |
bool | IsArticulatedEngine (EngineID engine_type) |
Does a NewGRF report that this should be an articulated vehicle? | |
uint | CountArticulatedParts (EngineID engine_type, bool purchase_window) |
Count the number of articulated parts of an engine. | |
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 cargoes a vehicle can carry. | |
CargoArray | GetCapacityOfArticulatedParts (EngineID engine) |
Get the capacity of the parts of a given engine. | |
void | GetArticulatedVehicleCargoesAndRefits (EngineID engine, CargoArray *cargoes, uint32 *refits) |
Get the default cargoes and refits of an articulated vehicle. | |
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 | IsArticulatedVehicleCarryingDifferentCargoes (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) |
Add the remaining articulated parts to the given vehicle. |
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 355 of file articulated_vehicles.cpp.
References Vehicle::build_year, GroundVehicleCache::cached_veh_length, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::CanAllocateItem(), Engine::CanCarryCargo(), RailVehicleInfo::capacity, Vehicle::cargo_cap, Vehicle::cargo_subtype, Vehicle::cargo_type, CBM_VEHICLE_ARTIC_ENGINE, Vehicle::date_of_last_service, Vehicle::direction, Vehicle::engine_type, GroundVehicleCache::first_engine, SpecializedVehicle< Train, Type >::From(), SpecializedVehicle< RoadVehicle, Type >::From(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetDefaultCargoType(), Vehicle::GetGroundVehicleCache(), GetNextArticulatedPart(), HasBit(), INVALID_ENGINE, Vehicle::max_age, MAX_ARTICULATED_PARTS, Vehicle::owner, Vehicle::random_bits, Vehicle::refit_cap, RVSB_IN_DEPOT, VehicleSpriteSeq::Set(), GroundVehicle< T, Type >::SetArticulatedPart(), Vehicle::SetNext(), Vehicle::sprite_seq, Vehicle::spritenum, RoadVehicle::state, Vehicle::subtype, Vehicle::tile, BaseVehicle::type, Vehicle::UpdatePosition(), Vehicle::value, VEH_ROAD, VEH_TRAIN, VEHICLE_LENGTH, VehicleRandomBits(), Vehicle::vehstatus, VS_STOPPED, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.
Referenced by CmdBuildRailVehicle(), CmdBuildRailWagon(), and CmdBuildRoadVehicle().
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 313 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.
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 _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().
void GetArticulatedRefitMasks | ( | EngineID | engine, |
bool | include_initial_cargo_type, | ||
uint32 * | union_mask, | ||
uint32 * | 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 231 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().
void GetArticulatedVehicleCargoesAndRefits | ( | EngineID | engine, |
CargoArray * | cargoes, | ||
uint32 * | refits | ||
) |
Get the default cargoes and refits of an articulated vehicle.
The refits are linked to a cargo rather than an articulated part to prevent a long list of parts.
engine | Model to investigate. | |
[out] | cargoes | Total amount of units that can be transported, summed by cargo. |
[out] | refits | Whether a (possibly partial) refit for each cargo is possible. |
Definition at line 172 of file articulated_vehicles.cpp.
References EngineInfo::callback_mask, CBM_VEHICLE_ARTIC_ENGINE, CargoArray::Clear(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetNextArticulatedPart(), GetVehicleDefaultCapacity(), HasBit(), INVALID_ENGINE, IsEngineRefittable(), Engine::IsGroundVehicle(), MAX_ARTICULATED_PARTS, and SetBit().
|
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 CheckConsistencyOfArticulatedVehicle(), and 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 EngineInfo::callback_mask, CBM_VEHICLE_ARTIC_ENGINE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetNextArticulatedPart(), GetVehicleDefaultCapacity(), HasBit(), INVALID_ENGINE, Engine::IsGroundVehicle(), MAX_ARTICULATED_PARTS, and NUM_CARGO.
Referenced by CheckConsistencyOfArticulatedVehicle(), and GetTotalCapacityOfArticulatedParts().
uint32 GetIntersectionOfArticulatedRefitMasks | ( | EngineID | engine, |
bool | include_initial_cargo_type | ||
) |
Ands 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 270 of file articulated_vehicles.cpp.
References GetArticulatedRefitMasks().
|
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 CALLBACK_FAILED, CBID_VEHICLE_ARTIC_ENGINE, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetGRF(), GetNewEngineID(), GetVehicleCallback(), HasBit(), INVALID_ENGINE, and Engine::type.
Referenced by AddArticulatedParts(), CountArticulatedParts(), GetArticulatedRefitMasks(), GetArticulatedVehicleCargoesAndRefits(), GetCapacityOfArticulatedParts(), and IsArticulatedVehicleRefittable().
uint32 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 257 of file articulated_vehicles.cpp.
References GetArticulatedRefitMasks().
Referenced by CargoFilter(), EnginesHaveCargoInCommon(), GetPreviewCompany(), ShowRefitOptionsList(), 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.
References Engine::CanCarryCargo(), CT_INVALID, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetDefaultCargoType(), and Engine::GetDisplayDefaultCapacity().
Referenced by GetArticulatedVehicleCargoesAndRefits(), and GetCapacityOfArticulatedParts().
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 CBM_VEHICLE_ARTIC_ENGINE, and HasBit().
Tests if all parts of an articulated vehicle are refitted to the same cargo.
Note: Vehicles not carrying anything are ignored
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) |
Definition at line 285 of file articulated_vehicles.cpp.
References Engine::CanCarryCargo(), Vehicle::cargo_type, CT_INVALID, Vehicle::GetEngine(), Vehicle::GetNextArticulatedPart(), and Vehicle::HasArticulatedPart().
Referenced by GetNewCargoTypeForReplace(), and Vehicle::NeedsServicing().
bool IsArticulatedVehicleRefittable | ( | EngineID | engine | ) |
Checks whether any of the articulated parts is refittable.
engine | the first part |
Definition at line 205 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.
Referenced by DrawVehiclePurchaseInfo().