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