OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
18 #include "table/strings.h"
34 assert(front ==
nullptr || front->engine_type == front_type);
41 if (front_engine->
GetGRF()->grf_version < 8) {
43 callback =
GB(callback, 0, 8);
45 if (mirrored !=
nullptr) *mirrored =
HasBit(callback, 7);
46 callback =
GB(callback, 0, 7);
50 if (mirrored !=
nullptr) *mirrored =
HasBit(callback, 14);
51 callback =
GB(callback, 0, 14);
82 if (!purchase_window) {
109 if (cargo_type !=
nullptr) *cargo_type = cargo;
125 CargoTypes cargoes = e->info.refit_mask;
127 if (include_initial_cargo_type) {
146 if (cargo_type <
NUM_CARGO) capacity[cargo_type] = cargo_capacity;
157 if (cargo_type <
NUM_CARGO) capacity[cargo_type] += cargo_capacity;
179 if (cargo_type < NUM_CARGO && cargo_capacity > 0) {
180 (*cargoes)[cargo_type] += cargo_capacity;
191 if (cargo_type < NUM_CARGO && cargo_capacity > 0) {
192 (*cargoes)[cargo_type] += cargo_capacity;
233 *union_mask = veh_cargoes;
234 *intersection_mask = (veh_cargoes != 0) ? veh_cargoes : ALL_CARGOTYPES;
244 *union_mask |= veh_cargoes;
245 if (veh_cargoes != 0) *intersection_mask &= veh_cargoes;
257 CargoTypes union_mask, intersection_mask;
270 CargoTypes union_mask, intersection_mask;
272 return intersection_mask;
291 if (cargo_type !=
nullptr) *cargo_type =
CT_INVALID;
297 }
while (v !=
nullptr);
299 if (cargo_type !=
nullptr) *cargo_type = first_cargo;
315 CargoTypes purchase_refit_union, purchase_refit_intersection;
319 CargoTypes real_refit_union = 0;
320 CargoTypes real_refit_intersection = ALL_CARGOTYPES;
325 real_refit_union |= refit_mask;
326 if (refit_mask != 0) real_refit_intersection &= refit_mask;
332 }
while (v !=
nullptr);
335 bool carries_more =
false;
337 if (real_default_capacity[cid] != 0 && purchase_default_capacity[cid] == 0) {
344 if (real_refit_union != purchase_refit_union || real_refit_intersection != purchase_refit_intersection || carries_more) {
373 default: NOT_REACHED();
382 t->track = front->track;
383 t->railtype = front->railtype;
385 t->
spritenum = e_artic->u.rail.image_index;
412 rv->
spritenum = e_artic->u.road.image_index;
415 rv->
cargo_cap = e_artic->u.road.capacity;
Buses, trucks and trams belong to this class.
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
uint GetDisplayDefaultCapacity(uint16 *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
static Titem * Get(size_t index)
Returns Titem with given index.
VehicleSpriteSeq sprite_seq
Vehicle appearance.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Money value
Value of the vehicle.
@ GBUG_VEH_REFIT
Articulated vehicles carry different cargoes resp. are differently refittable than specified in purch...
@ CBID_VEHICLE_ARTIC_ENGINE
Builds articulated engines for trains and RVs.
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
Checks whether the specs of freshly build articulated vehicles are consistent with the information sp...
static CargoTypes GetAvailableVehicleCargoTypes(EngineID engine, bool include_initial_cargo_type)
Returns all cargoes a vehicle can carry.
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, CargoTypes *union_mask, CargoTypes *intersection_mask)
Merges the refit_masks of all articulated parts.
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
Tindex index
Index of this pool item.
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
void AddArticulatedParts(Vehicle *first)
Add the remaining articulated parts to the given vehicle.
Class for storing amounts of cargo.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
RoadType roadtype
Roadtype of this vehicle.
@ VEH_ROAD
Road vehicle type.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Owner owner
Which company owns the vehicle?
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
@ CBM_VEHICLE_ARTIC_ENGINE
Add articulated engines (trains and road vehicles)
uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
Count the number of articulated parts of an engine.
void Clear()
Reset all entries.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
uint16 EngineID
Unique identification number of an engine.
Cached, frequently calculated values.
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
byte callback_mask
Bitmask of vehicle callbacks that have to be called.
TileIndex tile
Current tile index.
EngineID engine_type
The type of engine used for this vehicle.
uint8 cached_veh_length
Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can b...
@ VS_STOPPED
Vehicle is stopped by the player.
CargoTypes 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.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
'Train' is either a loco or a wagon.
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id)
Return the ID of a new engine.
void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical)
Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking.
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
VehicleType
Available vehicle types.
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
Direction direction
facing
bool IsGroundVehicle() const
Check if the engine is a ground vehicle.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
CompanyID _current_company
Company currently doing an action.
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
uint16 cargo_cap
total capacity
bool CanCarryCargo() const
Determines whether an engine can carry something.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
void SetArticulatedPart()
Set a vehicle to be an articulated part.
byte VehicleRandomBits()
Get a value for a vehicle's random_bits.
@ NUM_CARGO
Maximal number of cargo types in a game.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Year build_year
Year the vehicle has been built.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front=nullptr, bool *mirrored=nullptr)
Determines the next articulated part to attach.
bool IsArticulatedEngine(EngineID engine_type)
Does a NewGRF report that this should be an articulated vehicle?
byte CargoID
Cargo slots to indicate a cargo type within a game.
CargoID cargo_type
type of cargo this vehicle is carrying
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
byte cargo_subtype
Used for livery refits (NewGRF variations)
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
@ VEH_TRAIN
Train vehicle type.
byte capacity
Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine.
VehicleType type
Type of vehicle.
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits, CargoID cargo_type, uint cargo_capacity)
Get the default cargoes and refits of an articulated vehicle.
void UpdatePosition()
Update the position of the vehicle.
static uint16 GetVehicleDefaultCapacity(EngineID engine, CargoID *cargo_type)
Returns the default (non-refitted) capacity of a specific EngineID.
@ CT_INVALID
Invalid cargo type.
static const uint MAX_ARTICULATED_PARTS
Maximum of articulated parts per vehicle, i.e. when to abort calling the articulated vehicle callback...
@ RVSB_IN_DEPOT
The vehicle is in a depot.
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
uint16 refit_cap
Capacity left over from before last refit.
Date date_of_last_service
Last date the vehicle had a service at a depot.