83 auto operator<=>(
const TrainCache &)
const =
default;
97 Train *other_multiheaded_part;
121 int GetCursorImageOffset()
const;
124 bool Tick()
override;
127 uint
Crash(
bool flooded =
false)
override;
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Types/functions related to cargoes.
uint16_t max_speed
Maximum speed for vehicles travelling on this rail type.
uint8_t acceleration_type
Acceleration type of this rail type.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Direction
Defines the 8 directions on the map.
ExpensesType
Types of expenses.
@ EXPENSES_TRAIN_RUN
Running costs trains.
@ EXPENSES_TRAIN_REVENUE
Revenue from trains.
uint16_t EngineID
Unique identification number of an engine.
Type (helpers) for enums.
Base class and functions for all vehicles that move through ground.
AccelStatus
What is the status of our acceleration?
@ AS_BRAKE
We want to stop.
@ AS_ACCEL
We want to go faster, if possible of course.
Functions for NewGRF engines.
@ PROP_TRAIN_CURVE_SPEED_MOD
Modifier to maximum speed in curves.
@ PROP_TRAIN_WEIGHT
Weight in t (if dualheaded: for each single vehicle)
@ PROP_TRAIN_TRACTIVE_EFFORT
Tractive effort coefficient in 1/256.
@ PROP_TRAIN_POWER
Power in hp (if dualheaded: sum of both vehicles)
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
Hides the direct accesses to the map array with map accessors.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
RailTypes
Allow incrementing of Track variables.
RailType
Enumeration for all possible railtypes.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Structure to return information about the closest depot location, and whether it could be found.
VehicleSettings vehicle
options for vehicles
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
uint16_t last_speed
The last speed we did display, so we only have to redraw when this changes.
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...
Base class for all vehicles that move through ground.
GroundVehicleCache gcache
Cache of often calculated values.
bool IsRearDualheaded() const
Tell if we are dealing with the rear end of a multiheaded engine.
bool IsMultiheaded() const
Check if the vehicle is a multiheaded engine.
Coordinates of a point in 2D.
uint16_t pow_wag_power
Extra power applied to consist if wagon should be powered.
uint8_t air_drag
Coefficient of air drag.
uint8_t pow_wag_weight
Extra weight applied to consist if wagon should be powered.
T * GetPrevVehicle() const
Get the previous real (non-articulated part) vehicle in the consist.
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
T * Next() const
Get next vehicle in the chain.
Variables that are cached to improve performance and such.
uint16_t cached_max_curve_speed
max consist speed limited by curves
int16_t cached_curve_speed_mod
curve speed modifier of the entire train
uint8_t user_def_data
Cached property 0x25. Can be set by Callback 0x36.
bool cached_tilt
train can tilt; feature provides a bonus in curves
'Train' is either a loco or a wagon.
void PlayLeaveStationSound(bool force=false) const override
Play a sound for a train leaving the station.
Train * GetNextUnit() const
Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consis...
int GetAccelerationType() const
Allows to know the acceleration type of a vehicle.
bool IsInDepot() const override
Check whether the vehicle is in the depot.
void UpdateAcceleration()
Update acceleration of the train from the cached power and weight.
void OnNewCalendarDay() override
Calendar day handler.
Trackdir GetVehicleTrackdir() const override
Get the tracks of the train vehicle.
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override
Get the sprite to display the train.
int GetDisplayMaxSpeed() const override
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
uint16_t crash_anim_pos
Crash animation counter.
uint8_t GetTractiveEffort() const
Allows to know the tractive effort value that this vehicle will use.
bool Tick() override
Update train vehicle data for a tick.
bool HasToUseGetSlopePixelZ()
Trains can always use the faster algorithm because they have always the same direction as the track u...
uint16_t GetCurrentSpeed() const
Calculates the current speed of this vehicle.
void ReserveTrackUnderConsist() const
Tries to reserve track under whole train consist.
TileIndex GetOrderStationLocation(StationID station) override
Get the location of the next station to visit.
uint16_t GetPoweredPartPower(const Train *head) const
Returns a value if this articulated part is powered.
uint32_t GetRollingFriction() const
Returns the rolling friction coefficient of this vehicle.
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
ClosestDepot FindClosestDepot() override
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
void UpdateDeltaXY() override
Updates the x and y offsets and the size of the sprite used for this vehicle.
uint16_t GetMaxTrackSpeed() const
Gets the maximum speed allowed by the track for this vehicle.
int CalcNextVehicleOffset() const
Calculate the offset from this vehicle's center to the following center taking the vehicle lengths in...
Train * GetPrevUnit()
Get the previous real (non-articulated part and non rear part of dualheaded engine) vehicle in the co...
uint16_t GetMaxWeight() const override
Calculates the weight value that this vehicle will have when fully loaded with its current cargo.
uint16_t GetCurveSpeedLimit() const
Computes train speed limit caused by curves.
uint8_t GetAirDrag() const
Gets the air drag coefficient of this vehicle.
bool IsPrimaryVehicle() const override
Whether this is the primary vehicle in the chain.
void MarkDirty() override
Goods at the consist have changed, update the graphics, cargo, and acceleration.
int GetDisplaySpeed() const override
Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
int UpdateSpeed()
This function looks at the vehicle and updates its speed (cur_speed and subspeed) variables.
uint Crash(bool flooded=false) override
The train vehicle crashed! Update its status and other parts around it.
Train()
We don't want GCC to zero our struct! It already is zeroed and has an index!
AccelStatus GetAccelerationStatus() const
Checks the current acceleration status of this vehicle.
virtual ~Train()
We want to 'destruct' the right class.
void OnNewEconomyDay() override
Economy day handler.
int16_t GetCurveSpeedModifier() const
Returns the curve speed modifier of this vehicle.
bool TileMayHaveSlopedTrack() const
Checks if the vehicle is at a tile that can be sloped.
uint16_t GetWeight() const
Allows to know the weight value that this vehicle will use.
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
Money GetRunningCost() const override
Get running cost for the train consist.
uint8_t GetAirDragArea() const
Gets the area used for calculating air drag.
uint16_t GetPower() const
Allows to know the power value that this vehicle will use.
uint16_t wait_counter
Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through sign...
uint32_t GetSlopeSteepness() const
Returns the slope steepness used by this vehicle.
int GetCurrentMaxSpeed() const override
Calculates the maximum speed of the vehicle under its current conditions.
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
uint8_t train_slope_steepness
Steepness of hills for trains when using realistic acceleration.
Sprite sequence for a vehicle part.
EngineID engine_type
The type of engine used for this vehicle.
Direction direction
facing
VehicleCargoList cargo
The cargo this vehicle is carrying.
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
debug_inline bool IsFrontEngine() const
Check if the vehicle is a front engine.
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
CargoID cargo_type
type of cargo this vehicle is carrying
VehicleCache vcache
Cache of often used vehicle values.
virtual ExpensesType GetExpenseType([[maybe_unused]] bool income) const
Sets the expense type associated to this vehicle type.
uint16_t cur_speed
current speed
TileIndex tile
Current tile index.
TrackBits
Allow incrementing of Track variables.
@ TRACK_BIT_WORMHOLE
Bitflag for a wormhole (used for tunnels)
@ TRACK_BIT_DEPOT
Bitflag for a depot.
@ TRACK_BIT_Y
Y-axis track.
@ TRACK_BIT_X
X-axis track.
Trackdir
Enumeration for tracks and directions.
bool TryPathReserve(Train *v, bool mark_as_stuck=false, bool first_tile_okay=false)
Try to reserve a path to a safe position.
VehicleRailFlags
Rail vehicle flags.
@ VRF_POWEREDWAGON
Wagon is powered.
@ VRF_LEAVING_STATION
Train is just leaving a station.
@ VRF_TOGGLE_REVERSE
Used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle ...
@ VRF_REVERSE_DIRECTION
Reverse the visible direction of the vehicle.
@ VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL
Electric train engine is allowed to run on normal rail. */.
@ VRF_TRAIN_STUCK
Train can't get a path reservation.
void NormalizeTrainVehInDepot(const Train *u)
Move all free vehicles in the depot to the train.
uint8_t FreightWagonMult(CargoID cargo)
Return the cargo weight multiplier to use for a rail vehicle.
void FreeTrainTrackReservation(const Train *v)
Free the reserved path in front of a vehicle.
ConsistChangeFlags
Flags for Train::ConsistChanged.
@ CCF_AUTOREFIT
Valid changes for autorefitting in stations.
@ CCF_CAPACITY
Allow vehicles to change capacity.
@ CCF_ARRANGE
Valid changes for arranging the consist in a depot.
@ CCF_LENGTH
Allow vehicles to change length.
@ CCF_REFIT
Valid changes for refitting in a depot.
@ CCF_TRACK
Valid changes while vehicle is driving, and possibly changing tracks.
@ CCF_LOADUNLOAD
Valid changes while vehicle is loading/unloading.
@ CCF_SAVELOAD
Valid changes when loading a savegame. (Everything that is not stored in the save....
void CheckTrainsLengths()
Checks if lengths of all rail vehicles are valid.
bool TrainOnCrossing(TileIndex tile)
Check if a level crossing tile has a train on it.
int GetTrainStopLocation(StationID station_id, TileIndex tile, const Train *v, int *station_ahead, int *station_length)
Get the stop location of (the center) of the front vehicle of a train at a platform of a station.
TrainForceProceeding
Modes for ignoring signals.
@ TFP_SIGNAL
Ignore next signal, after the signal ignore being stuck.
@ TFP_NONE
Normal operation.
@ TFP_STUCK
Proceed till next signal, but ignore being stuck till then. This includes force leaving depots.
void GetTrainSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
Get the size of the sprite of a train sprite heading west, or both heads (used for lists).
@ VS_STOPPED
Vehicle is stopped by the player.
@ VS_HIDDEN
Vehicle is not visible.
EngineImageType
Visualisation contexts of vehicles and engines.
@ VEH_TRAIN
Train vehicle type.