20#include "table/strings.h"
36 assert(front ==
nullptr || front->engine_type == front_type);
43 if (front_engine->
GetGRF()->grf_version < 8) {
45 callback =
GB(callback, 0, 8);
47 if (mirrored !=
nullptr) *mirrored =
HasBit(callback, 7);
48 callback =
GB(callback, 0, 7);
52 if (mirrored !=
nullptr) *mirrored =
HasBit(callback, 14);
53 callback =
GB(callback, 0, 14);
84 if (!purchase_window) {
124 CargoTypes cargoes = e->info.refit_mask;
126 if (include_initial_cargo_type) {
144 capacity[cargo] = cap;
156 capacity[cargo] += cap;
170 CargoTypes cargoes = 0;
228 *union_mask = veh_cargoes;
229 *intersection_mask = (veh_cargoes != 0) ? veh_cargoes : ALL_CARGOTYPES;
239 *union_mask |= veh_cargoes;
240 if (veh_cargoes != 0) *intersection_mask &= veh_cargoes;
252 CargoTypes union_mask, intersection_mask;
266 CargoTypes cargoes = 0;
267 CargoID first_cargo = INVALID_CARGO;
274 if (cargo_type !=
nullptr) {
275 *cargo_type = INVALID_CARGO;
276 cargo_type =
nullptr;
282 }
while (v !=
nullptr);
284 if (cargo_type !=
nullptr) *cargo_type = first_cargo;
300 CargoTypes purchase_refit_union, purchase_refit_intersection;
304 CargoTypes real_refit_union = 0;
305 CargoTypes real_refit_intersection = ALL_CARGOTYPES;
306 CargoTypes real_default_cargoes = 0;
310 real_refit_union |= refit_mask;
311 if (refit_mask != 0) real_refit_intersection &= refit_mask;
317 }
while (v !=
nullptr);
320 bool carries_more =
false;
322 if (purchase_default_capacity[cid] == 0) {
329 if (real_refit_union != purchase_refit_union || real_refit_intersection != purchase_refit_intersection || carries_more) {
358 default: NOT_REACHED();
367 t->track = front->track;
368 t->railtype = front->railtype;
370 t->
spritenum = e_artic->u.rail.image_index;
397 rv->
spritenum = e_artic->u.road.image_index;
401 rv->
cargo_cap = e_artic->u.road.capacity;
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
CargoTypes GetCargoTypesOfArticulatedVehicle(const Vehicle *v, CargoID *cargo_type)
Get cargo mask of all cargoes carried by an articulated vehicle.
bool IsArticulatedEngine(EngineID engine_type)
Does a NewGRF report that this should be an articulated vehicle?
static const uint MAX_ARTICULATED_PARTS
Maximum of articulated parts per vehicle, i.e. when to abort calling the articulated vehicle callback...
void AddArticulatedParts(Vehicle *first)
Add the remaining articulated parts to the given vehicle.
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, CargoTypes *union_mask, CargoTypes *intersection_mask)
Merges the refit_masks of all articulated parts.
static std::pair< CargoID, uint16_t > GetVehicleDefaultCapacity(EngineID engine)
Returns the default (non-refitted) cargo and capacity of a specific EngineID.
void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
Checks whether the specs of freshly build articulated vehicles are consistent with the information sp...
CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine)
Get the cargo mask of the parts of a given engine.
static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front=nullptr, bool *mirrored=nullptr)
Determines the next articulated part to attach.
uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
Count the number of articulated parts of an engine.
static CargoTypes GetAvailableVehicleCargoTypes(EngineID engine, bool include_initial_cargo_type)
Returns all cargoes a vehicle can carry.
Functions related to bit mathematics.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Functions related to engines.
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
uint16_t EngineID
Unique identification number of an engine.
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16_t internal_id)
Return the ID of a new engine.
Base for the NewGRF implementation.
@ CBID_VEHICLE_ARTIC_ENGINE
Builds articulated engines for trains and RVs.
@ CBM_VEHICLE_ARTIC_ENGINE
Add articulated engines (trains and road vehicles)
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
@ GBUG_VEH_REFIT
Articulated vehicles carry different cargoes resp. are differently refittable than specified in purch...
bool TestVehicleBuildProbability(Vehicle *v, EngineID engine, BuildProbabilityType type)
Test for vehicle build probablity type.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Pseudo random number generator.
@ RVSB_IN_DEPOT
The vehicle is in a depot.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
VehicleType type
Type of vehicle.
Class for storing amounts of cargo.
uint16_t callback_mask
Bitmask of vehicle callbacks that have to be called.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
uint GetDisplayDefaultCapacity(uint16_t *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
bool CanCarryCargo() const
Determines whether an engine can carry something.
bool IsGroundVehicle() const
Check if the engine is a ground vehicle.
Cached, frequently calculated values.
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
uint8_t cached_veh_length
Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can b...
void SetArticulatedPart()
Set a vehicle to be an articulated part.
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Tindex index
Index of this pool item.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static Titem * Get(size_t index)
Returns Titem with given index.
uint8_t capacity
Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine.
Buses, trucks and trams belong to this class.
RoadTypes compatible_roadtypes
NOSAVE: Roadtypes this consist is powered on.
RoadType roadtype
NOSAVE: Roadtype of this vehicle.
Iterable ensemble of each set bit in a value.
static T * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
'Train' is either a loco or a wagon.
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
EngineID engine_type
The type of engine used for this vehicle.
int32_t z_pos
z coordinate.
Direction direction
facing
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
uint16_t cargo_cap
total capacity
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
uint16_t random_bits
Bits used for randomized variational spritegroups.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
TimerGameCalendar::Date date_of_last_service_newgrf
Last calendar date the vehicle had a service at a depot, unchanged by the date cheat to protect again...
CargoID cargo_type
type of cargo this vehicle is carrying
int32_t y_pos
y coordinate.
int32_t x_pos
x coordinate.
Money value
Value of the vehicle.
uint16_t refit_cap
Capacity left over from before last refit.
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
uint8_t spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
uint8_t cargo_subtype
Used for livery refits (NewGRF variations)
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
TimerGameCalendar::Date max_age
Maximum age.
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
TileIndex tile
Current tile index.
void UpdatePosition()
Update the position of the vehicle.
TimerGameCalendar::Year build_year
Year the vehicle has been built.
Owner owner
Which company owns the vehicle?
Base for the train class.
@ VRF_REVERSE_DIRECTION
Reverse the visible direction of the vehicle.
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.
Functions related to vehicles.
VehicleType
Available vehicle types.
@ VEH_ROAD
Road vehicle type.
@ VEH_TRAIN
Train vehicle type.
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.