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;
Vehicle is stopped by the player.
Money value
Value of the vehicle.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Direction direction
facing
CargoTypes GetIntersectionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ands the refit_masks of all articulated parts.
static Titem * Get(size_t index)
Returns Titem with given index.
bool CanCarryCargo() const
Determines whether an engine can carry something.
Base for the train class.
void AddArticulatedParts(Vehicle *first)
Add the remaining articulated parts to the given vehicle.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Maximal number of cargo types in a game.
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
Builds articulated engines for trains and RVs.
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
static uint16 GetVehicleDefaultCapacity(EngineID engine, CargoID *cargo_type)
Returns the default (non-refitted) capacity of a specific EngineID.
VehicleType
Available vehicle types.
Functions related to vehicles.
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
bool IsArticulatedEngine(EngineID engine_type)
Does a NewGRF report that this should be an articulated vehicle?
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Tindex index
Index of this pool item.
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
bool IsArticulatedVehicleCarryingDifferentCargoes(const Vehicle *v, CargoID *cargo_type)
Tests if all parts of an articulated vehicle are refitted to the same cargo.
Cached, frequently calculated values.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
static const uint MAX_ARTICULATED_PARTS
Maximum of articulated parts per vehicle, i.e. when to abort calling the articulated vehicle callback...
byte VehicleRandomBits()
Get a value for a vehicle's random_bits.
VehicleSpriteSeq sprite_seq
Vehicle appearance.
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Buses, trucks and trams belong to this class.
uint16 cargo_cap
total capacity
RoadType roadtype
Roadtype of this vehicle.
void Clear()
Reset all entries.
byte cargo_subtype
Used for livery refits (NewGRF variations)
Functions related to engines.
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
byte callback_mask
Bitmask of vehicle callbacks that have to be called.
Definition of base types and functions in a cross-platform compatible way.
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
A number of safeguards to prevent using unsafe methods.
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
The vehicle is in a depot.
CargoID cargo_type
type of cargo this vehicle is carrying
byte capacity
Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine.
TileIndex tile
Current tile index.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id)
Return the ID of a new engine.
Owner owner
Which company owns the vehicle?
uint16 refit_cap
Capacity left over from before last refit.
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
Add articulated engines (trains and road vehicles)
static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front=nullptr, bool *mirrored=nullptr)
Determines the next articulated part to attach.
Year build_year
Year the vehicle has been built.
Articulated vehicles carry different cargoes resp. are differently refittable than specified in purch...
'Train' is either a loco or a wagon.
uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
Count the number of articulated parts of an engine.
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits, CargoID cargo_type, uint16 cargo_capacity)
Get the default cargoes and refits of an articulated vehicle.
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Functions related to companies.
void UpdatePosition()
Update the position of the vehicle.
void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
Checks whether the specs of freshly build articulated vehicles are consistent with the information sp...
Class for storing amounts of cargo.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
uint16 EngineID
Unique identification number of an engine.
static CargoTypes GetAvailableVehicleCargoTypes(EngineID engine, bool include_initial_cargo_type)
Returns all cargoes a vehicle can carry.
Date date_of_last_service
Last date the vehicle had a service at a depot.
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.
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, CargoTypes *union_mask, CargoTypes *intersection_mask)
Merges the refit_masks of all articulated parts.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
VehicleType type
Type of vehicle.
uint GetDisplayDefaultCapacity(uint16 *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
CompanyID _current_company
Company currently doing an action.
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
uint8 cached_veh_length
Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can b...
bool IsGroundVehicle() const
Check if the engine is a ground vehicle.
EngineID engine_type
The type of engine used for this vehicle.
void SetArticulatedPart()
Set a vehicle to be an articulated part.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
byte CargoID
Cargo slots to indicate a cargo type within a game.
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
Base for the NewGRF implementation.