20 #include "table/strings.h" 36 assert(front == NULL || front->engine_type == front_type);
43 if (front_engine->
GetGRF()->grf_version < 8) {
45 callback =
GB(callback, 0, 8);
47 if (mirrored != NULL) *mirrored =
HasBit(callback, 7);
48 callback =
GB(callback, 0, 7);
52 if (mirrored != NULL) *mirrored =
HasBit(callback, 14);
53 callback =
GB(callback, 0, 14);
84 if (!purchase_window) {
111 if (cargo_type != NULL) *cargo_type = cargo;
127 uint32 cargoes = e->info.refit_mask;
129 if (include_initial_cargo_type) {
148 if (cargo_type <
NUM_CARGO) capacity[cargo_type] = cargo_capacity;
159 if (cargo_type <
NUM_CARGO) capacity[cargo_type] += cargo_capacity;
181 if (cargo_type < NUM_CARGO && cargo_capacity > 0) {
182 (*cargoes)[cargo_type] += cargo_capacity;
193 if (cargo_type < NUM_CARGO && cargo_capacity > 0) {
194 (*cargoes)[cargo_type] += cargo_capacity;
235 *union_mask = veh_cargoes;
236 *intersection_mask = (veh_cargoes != 0) ? veh_cargoes : UINT32_MAX;
246 *union_mask |= veh_cargoes;
247 if (veh_cargoes != 0) *intersection_mask &= veh_cargoes;
259 uint32 union_mask, intersection_mask;
272 uint32 union_mask, intersection_mask;
274 return intersection_mask;
293 if (cargo_type != NULL) *cargo_type =
CT_INVALID;
301 if (cargo_type != NULL) *cargo_type = first_cargo;
317 uint32 purchase_refit_union, purchase_refit_intersection;
321 uint32 real_refit_union = 0;
322 uint32 real_refit_intersection = UINT_MAX;
327 real_refit_union |= refit_mask;
328 if (refit_mask != 0) real_refit_intersection &= refit_mask;
337 bool carries_more =
false;
339 if (real_default_capacity[cid] != 0 && purchase_default_capacity[cid] == 0) {
346 if (real_refit_union != purchase_refit_union || real_refit_intersection != purchase_refit_intersection || carries_more) {
375 default: NOT_REACHED();
384 t->track = front->track;
385 t->railtype = front->railtype;
387 t->
spritenum = e_artic->u.rail.image_index;
411 rv->roadtype = front->roadtype;
412 rv->compatible_roadtypes = front->compatible_roadtypes;
414 rv->
spritenum = e_artic->u.road.image_index;
417 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.
uint GetDisplayDefaultCapacity(uint16 *mail_capacity=NULL) const
Determines the default cargo capacity of an engine for display purposes.
DirectionByte direction
facing
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.
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.
Functions related to vehicles.
bool IsArticulatedEngine(EngineID engine_type)
Does a NewGRF report that this should be an articulated vehicle?
void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, uint32 *union_mask, uint32 *intersection_mask)
Merges the refit_masks of all articulated parts.
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 #EffectVehicles/#TrainSubTypes/#AircraftSubTypes) ...
Buses, trucks and trams belong to this class.
uint16 cargo_cap
total capacity
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.
VehicleType
Available vehicle types.
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.
uint32 GetIntersectionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ands the refit_masks of all articulated parts.
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)
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.
Maximal number of cargo types in a game.
uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
Count the number of articulated parts of an engine.
static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front=NULL, bool *mirrored=NULL)
Determines the next articulated part to attach.
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.
CompanyByte _current_company
Company currently doing an action.
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.
OwnerByte owner
Which company owns the vehicle?
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, uint32 *refits)
Get the default cargoes and refits of an articulated vehicle.
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.
static uint32 GetAvailableVehicleCargoTypes(EngineID engine, bool include_initial_cargo_type)
Returns all cargoes a vehicle can carry.
uint32 GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
VehicleTypeByte type
Type of vehicle.
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
Base for the NewGRF implementation.