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);
46 if (callback == 0xFF)
return EngineID::Invalid();
47 if (mirrored !=
nullptr) *mirrored =
HasBit(callback, 7);
48 callback =
GB(callback, 0, 7);
51 if (callback == 0x7FFF)
return EngineID::Invalid();
52 if (mirrored !=
nullptr) *mirrored =
HasBit(callback, 14);
53 callback =
GB(callback, 0, 14);
78 Vehicle v(VehicleID::Invalid());
114 CargoTypes cargoes = e->info.refit_mask;
116 if (include_initial_cargo_type) {
134 capacity[cargo] = cap;
143 if (artic_engine == EngineID::Invalid())
break;
146 capacity[cargo] += cap;
160 CargoTypes cargoes = 0;
173 if (artic_engine == EngineID::Invalid())
break;
199 if (artic_engine == EngineID::Invalid())
break;
218 *union_mask = veh_cargoes;
219 *intersection_mask = (veh_cargoes != 0) ? veh_cargoes : ALL_CARGOTYPES;
226 if (artic_engine == EngineID::Invalid())
break;
229 *union_mask |= veh_cargoes;
230 if (veh_cargoes != 0) *intersection_mask &= veh_cargoes;
242 CargoTypes union_mask, intersection_mask;
256 CargoTypes cargoes = 0;
264 if (cargo_type !=
nullptr) {
265 *cargo_type = INVALID_CARGO;
266 cargo_type =
nullptr;
272 }
while (v !=
nullptr);
274 if (cargo_type !=
nullptr) *cargo_type = first_cargo;
290 CargoTypes purchase_refit_union, purchase_refit_intersection;
294 CargoTypes real_refit_union = 0;
295 CargoTypes real_refit_intersection = ALL_CARGOTYPES;
296 CargoTypes real_default_cargoes = 0;
300 real_refit_union |= refit_mask;
301 if (refit_mask != 0) real_refit_intersection &= refit_mask;
307 }
while (v !=
nullptr);
310 bool carries_more =
false;
312 if (purchase_default_capacity[cargo_type] == 0) {
319 if (real_refit_union != purchase_refit_union || real_refit_intersection != purchase_refit_intersection || carries_more) {
337 if (engine_type == EngineID::Invalid())
return;
348 default: NOT_REACHED();
357 t->track = front->track;
358 t->railtypes = front->railtypes;
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?
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.
CargoTypes GetCargoTypesOfArticulatedVehicle(const Vehicle *v, CargoType *cargo_type)
Get cargo mask of all cargoes carried by an articulated vehicle.
static std::pair< CargoType, uint16_t > GetVehicleDefaultCapacity(EngineID engine)
Returns the default (non-refitted) cargo and capacity of a specific EngineID.
void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, CargoTypes *union_mask, CargoTypes *intersection_mask)
Merges the refit_masks of all articulated parts.
uint CountArticulatedParts(EngineID engine_type)
Count the number of articulated parts of an engine.
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.
static CargoTypes GetAvailableVehicleCargoTypes(EngineID engine, bool include_initial_cargo_type)
Returns all cargoes a vehicle can carry.
Functions related to bit mathematics.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
static const CargoType NUM_CARGO
Maximum number of cargo types in a game.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
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.
CargoType GetDefaultCargoType() const
Determines the default cargo type of an engine.
bool CanCarryCargo() const
Determines whether an engine can carry something.
bool IsGroundVehicle() const
Check if the engine is a ground vehicle.
static constexpr TimerGame< struct Calendar >::Date MIN_DATE
The date on January 1, year 0.
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.
@ Random
Randomise borders.
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16_t internal_id)
Return the ID of a new engine.
Base for the NewGRF implementation.
@ ArticEngine
Add articulated engines (trains and road vehicles)
@ CBID_VEHICLE_ARTIC_ENGINE
Builds articulated engines for trains and RVs.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
@ VehRefit
Articulated vehicles carry different cargoes resp. are differently refittable than specified in purch...
std::optional< bool > TestVehicleBuildProbability(Vehicle *v, EngineID engine, BuildProbabilityType type)
Test for vehicle build probability type.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, std::span< int32_t > regs100)
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.
VehicleCallbackMasks callback_mask
Bitmask of vehicle callbacks that have to be called.
Cached, frequently calculated values.
EngineID first_engine
Cached EngineID of the front vehicle. EngineID::Invalid() 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.
static Titem * Get(auto index)
Returns Titem with given index.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
const Tindex index
Index of this pool item.
Information about a rail vehicle.
Information about a road vehicle.
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.
static T * Create(Targs &&... args)
Creates a new T-object in the vehicle pool.
'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.
VehStates vehstatus
Status.
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...
CargoType 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.
@ Flipped
Reverse the visible direction of the vehicle.
void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBug bug_type, bool critical)
Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking.
@ Stopped
Vehicle is stopped by the player.
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.