OpenTTD Source: src/train.h Source File

OpenTTD Source 15.0-RC2

train.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef TRAIN_H
11#define TRAIN_H
12
13#include "core/enum_type.hpp"
14
15#include "newgrf_engine.h"
16#include "cargotype.h"
17#include "rail.h"
18#include "engine_base.h"
19#include "rail_map.h"
20#include "ground_vehicle.hpp"
21
22struct Train;
23
25 enum VehicleRailFlag : uint8_t {
26 Reversing = 0,
27 PoweredWagon = 3,
28 Flipped = 4,
29
30 AllowedOnNormalRail = 6,
31 Reversed = 7,
32 Stuck = 8,
33 LeavingStation = 9,
34};
35using VehicleRailFlags = EnumBitSet<VehicleRailFlag, uint16_t>;
36
38 enum TrainForceProceeding : uint8_t {
39 TFP_NONE = 0,
40 TFP_STUCK = 1,
41 TFP_SIGNAL = 2,
42};
43
45 enum class ConsistChangeFlag : uint8_t {
46 Length,
47 Capacity,
48};
49
50using ConsistChangeFlags = EnumBitSet<ConsistChangeFlag, uint8_t>;
51
52 static constexpr ConsistChangeFlags CCF_TRACK{};
53 static constexpr ConsistChangeFlags CCF_LOADUNLOAD{};
54 static constexpr ConsistChangeFlags CCF_AUTOREFIT{ConsistChangeFlag::Capacity};
55 static constexpr ConsistChangeFlags CCF_REFIT{ConsistChangeFlag::Length, ConsistChangeFlag::Capacity};
56 static constexpr ConsistChangeFlags CCF_ARRANGE{ConsistChangeFlag::Length, ConsistChangeFlag::Capacity};
57 static constexpr ConsistChangeFlags CCF_SAVELOAD{ConsistChangeFlag::Length};
58
59uint8_t FreightWagonMult(CargoType cargo);
60
61void CheckTrainsLengths();
62
63void FreeTrainTrackReservation(const Train *v);
64bool TryPathReserve(Train *v, bool mark_as_stuck = false, bool first_tile_okay = false);
65
66int GetTrainStopLocation(StationID station_id, TileIndex tile, const Train *v, int *station_ahead, int *station_length);
67
68void GetTrainSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
69
70bool TrainOnCrossing(TileIndex tile);
71void NormalizeTrainVehInDepot(const Train *u);
72
74 struct TrainCache {
75 /* Cached wagon override spritegroup */
76 const struct SpriteGroup *cached_override = nullptr;
77
78 /* cached values, recalculated on load and each time a vehicle is added to/removed from the consist. */
79 bool cached_tilt = false;
80 uint8_t user_def_data = 0;
81
82 int16_t cached_curve_speed_mod = 0;
83 uint16_t cached_max_curve_speed = 0;
84
85 auto operator<=>(const TrainCache &) const = default;
86};
87
91 struct Train final : public GroundVehicle<Train, VEH_TRAIN> {
92 VehicleRailFlags flags{};
93 uint16_t crash_anim_pos = 0;
94 uint16_t wait_counter = 0;
95
96 TrainCache tcache{};
97
98 /* Link between the two ends of a multiheaded engine */
99 Train *other_multiheaded_part = nullptr;
100
101 RailTypes compatible_railtypes{};
102 RailTypes railtypes{};
103
104 TrackBits track{};
105 TrainForceProceeding force_proceed{};
106
108 Train() : GroundVehicleBase() {}
110 virtual ~Train() { this->PreDestructor(); }
111
112 friend struct GroundVehicle<Train, VEH_TRAIN>; // GroundVehicle needs to use the acceleration functions defined at Train.
113
114 void MarkDirty() override;
115 void UpdateDeltaXY() override;
116 ExpensesType GetExpenseType(bool income) const override { return income ? EXPENSES_TRAIN_REVENUE : EXPENSES_TRAIN_RUN; }
117 void PlayLeaveStationSound(bool force = false) const override;
118 bool IsPrimaryVehicle() const override { return this->IsFrontEngine(); }
119 void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override;
120 int GetDisplaySpeed() const override { return this->gcache.last_speed; }
121 int GetDisplayMaxSpeed() const override { return this->vcache.cached_max_speed; }
122 Money GetRunningCost() const override;
123 int GetCursorImageOffset() const;
124 int GetDisplayImageWidth(Point *offset = nullptr) const;
125 bool IsInDepot() const override { return this->track == TRACK_BIT_DEPOT; }
126 bool Tick() override;
127 void OnNewCalendarDay() override;
128 void OnNewEconomyDay() override;
129 uint Crash(bool flooded = false) override;
130 Trackdir GetVehicleTrackdir() const override;
131 TileIndex GetOrderStationLocation(StationID station) override;
132 ClosestDepot FindClosestDepot() override;
133
134 void ReserveTrackUnderConsist() const;
135
136 uint16_t GetCurveSpeedLimit() const;
137
138 void ConsistChanged(ConsistChangeFlags allowed_changes);
139
140 int UpdateSpeed();
141
142 void UpdateAcceleration();
143
144 int GetCurrentMaxSpeed() const override;
145
150 inline Train *GetNextUnit() const
151 {
152 Train *v = this->GetNextVehicle();
153 if (v != nullptr && v->IsRearDualheaded()) v = v->GetNextVehicle();
154
155 return v;
156 }
157
162 inline Train *GetPrevUnit()
163 {
164 Train *v = this->GetPrevVehicle();
165 if (v != nullptr && v->IsRearDualheaded()) v = v->GetPrevVehicle();
166
167 return v;
168 }
169
174 int CalcNextVehicleOffset() const
175 {
176 /* For vehicles with odd lengths the part before the center will be one unit
177 * longer than the part after the center. This means we have to round up the
178 * length of the next vehicle but may not round the length of the current
179 * vehicle. */
180 return this->gcache.cached_veh_length / 2 + (this->Next() != nullptr ? this->Next()->gcache.cached_veh_length + 1 : 0) / 2;
181 }
182
187 inline VehicleAccelerationModel GetAccelerationType() const
188 {
189 return GetRailTypeInfo(GetRailType(this->tile))->acceleration_type;
190 }
191
192protected: // These functions should not be called outside acceleration code.
193
198 inline uint16_t GetPower() const
199 {
200 /* Power is not added for articulated parts */
201 if (!this->IsArticulatedPart() && HasPowerOnRail(this->railtypes, GetRailType(this->tile))) {
202 uint16_t power = GetVehicleProperty(this, PROP_TRAIN_POWER, RailVehInfo(this->engine_type)->power);
203 /* Halve power for multiheaded parts */
204 if (this->IsMultiheaded()) power /= 2;
205 return power;
206 }
207
208 return 0;
209 }
210
215 inline uint16_t GetPoweredPartPower(const Train *head) const
216 {
217 /* For powered wagons the engine defines the type of engine (i.e. railtype) */
218 if (this->flags.Test(VehicleRailFlag::PoweredWagon) && HasPowerOnRail(head->railtypes, GetRailType(this->tile))) {
219 return RailVehInfo(this->gcache.first_engine)->pow_wag_power;
220 }
221
222 return 0;
223 }
224
229 inline uint16_t GetWeight() const
230 {
231 uint16_t weight = CargoSpec::Get(this->cargo_type)->WeightOfNUnitsInTrain(this->cargo.StoredCount());
232
233 /* Vehicle weight is not added for articulated parts. */
234 if (!this->IsArticulatedPart()) {
235 weight += GetVehicleProperty(this, PROP_TRAIN_WEIGHT, RailVehInfo(this->engine_type)->weight);
236 }
237
238 /* Powered wagons have extra weight added. */
239 if (this->flags.Test(VehicleRailFlag::PoweredWagon)) {
240 weight += RailVehInfo(this->gcache.first_engine)->pow_wag_weight;
241 }
242
243 return weight;
244 }
245
250 uint16_t GetMaxWeight() const override;
251
256 inline uint8_t GetTractiveEffort() const
257 {
258 return GetVehicleProperty(this, PROP_TRAIN_TRACTIVE_EFFORT, RailVehInfo(this->engine_type)->tractive_effort);
259 }
260
265 inline uint8_t GetAirDragArea() const
266 {
267 /* Air drag is higher in tunnels due to the limited cross-section. */
268 return (this->track == TRACK_BIT_WORMHOLE && this->vehstatus.Test(VehState::Hidden)) ? 28 : 14;
269 }
270
275 inline uint8_t GetAirDrag() const
276 {
277 return RailVehInfo(this->engine_type)->air_drag;
278 }
279
284 inline AccelStatus GetAccelerationStatus() const
285 {
286 return this->vehstatus.Test(VehState::Stopped) || this->flags.Any({VehicleRailFlag::Reversing, VehicleRailFlag::Stuck}) ? AS_BRAKE : AS_ACCEL;
287 }
288
293 inline uint16_t GetCurrentSpeed() const
294 {
295 return this->cur_speed;
296 }
297
302 inline uint32_t GetRollingFriction() const
303 {
304 /* Rolling friction for steel on steel is between 0.1% and 0.2%.
305 * The friction coefficient increases with speed in a way that
306 * it doubles at 512 km/h, triples at 1024 km/h and so on. */
307 return 15 * (512 + this->GetCurrentSpeed()) / 512;
308 }
309
314 inline uint32_t GetSlopeSteepness() const
315 {
316 return _settings_game.vehicle.train_slope_steepness;
317 }
318
323 inline uint16_t GetMaxTrackSpeed() const
324 {
325 return GetRailTypeInfo(GetRailType(this->tile))->max_speed;
326 }
327
332 inline int16_t GetCurveSpeedModifier() const
333 {
334 return GetVehicleProperty(this, PROP_TRAIN_CURVE_SPEED_MOD, RailVehInfo(this->engine_type)->curve_speed_mod, true);
335 }
336
341 inline bool TileMayHaveSlopedTrack() const
342 {
343 /* Any track that isn't TRACK_BIT_X or TRACK_BIT_Y cannot be sloped. */
344 return this->track == TRACK_BIT_X || this->track == TRACK_BIT_Y;
345 }
346
352 inline bool HasToUseGetSlopePixelZ()
353 {
354 return false;
355 }
356};
357
358#endif /* TRAIN_H */
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
cargotype.h
Types/functions related to cargoes.
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Any
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Definition base_bitset_type.hpp:170
EnumBitSet< VehicleRailFlag, uint16_t >
OverflowSafeInt< int64_t >
RailTypeInfo::max_speed
uint16_t max_speed
Maximum speed for vehicles travelling on this rail type.
Definition rail.h:220
RailTypeInfo::acceleration_type
VehicleAccelerationModel acceleration_type
Acceleration type of this rail type.
Definition rail.h:215
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition cargopacket.h:425
Direction
Direction
Defines the 8 directions on the map.
Definition direction_type.h:24
ExpensesType
ExpensesType
Types of expenses.
Definition economy_type.h:178
EXPENSES_TRAIN_RUN
@ EXPENSES_TRAIN_RUN
Running costs trains.
Definition economy_type.h:181
EXPENSES_TRAIN_REVENUE
@ EXPENSES_TRAIN_REVENUE
Revenue from trains.
Definition economy_type.h:186
engine_base.h
Base class for engines.
VehicleAccelerationModel
VehicleAccelerationModel
Acceleration model of a vehicle.
Definition engine_type.h:47
enum_type.hpp
Type (helpers) for enums.
ground_vehicle.hpp
Base class and functions for all vehicles that move through ground.
AccelStatus
AccelStatus
What is the status of our acceleration?
Definition ground_vehicle.hpp:21
AS_BRAKE
@ AS_BRAKE
We want to stop.
Definition ground_vehicle.hpp:23
AS_ACCEL
@ AS_ACCEL
We want to go faster, if possible of course.
Definition ground_vehicle.hpp:22
newgrf_engine.h
Functions for NewGRF engines.
PROP_TRAIN_CURVE_SPEED_MOD
@ PROP_TRAIN_CURVE_SPEED_MOD
Modifier to maximum speed in curves.
Definition newgrf_properties.h:31
PROP_TRAIN_WEIGHT
@ PROP_TRAIN_WEIGHT
Weight in t (if dualheaded: for each single vehicle)
Definition newgrf_properties.h:25
PROP_TRAIN_TRACTIVE_EFFORT
@ PROP_TRAIN_TRACTIVE_EFFORT
Tractive effort coefficient in 1/256.
Definition newgrf_properties.h:27
PROP_TRAIN_POWER
@ PROP_TRAIN_POWER
Power in hp (if dualheaded: sum of both vehicles)
Definition newgrf_properties.h:22
rail.h
Rail specific functions.
HasPowerOnRail
bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
Definition rail.h:376
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:300
rail_map.h
Hides the direct accesses to the map array with map accessors.
GetRailType
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition rail_map.h:115
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
Definition cargotype.h:137
ClosestDepot
Structure to return information about the closest depot location, and whether it could be found.
Definition vehicle_base.h:192
Coord2D< int >
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition settings_type.h:641
GroundVehicleCache::first_engine
EngineID first_engine
Cached EngineID of the front vehicle. EngineID::Invalid() for the front vehicle itself.
Definition ground_vehicle.hpp:44
GroundVehicleCache::last_speed
uint16_t last_speed
The last speed we did display, so we only have to redraw when this changes.
Definition ground_vehicle.hpp:48
GroundVehicleCache::cached_veh_length
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...
Definition ground_vehicle.hpp:45
GroundVehicle
Base class for all vehicles that move through ground.
Definition ground_vehicle.hpp:82
GroundVehicle< Train, VEH_TRAIN >::gcache
GroundVehicleCache gcache
Cache of often calculated values.
Definition ground_vehicle.hpp:83
GroundVehicle::IsRearDualheaded
bool IsRearDualheaded() const
Tell if we are dealing with the rear end of a multiheaded engine.
Definition ground_vehicle.hpp:336
GroundVehicle< Train, VEH_TRAIN >::IsMultiheaded
bool IsMultiheaded() const
Check if the vehicle is a multiheaded engine.
Definition ground_vehicle.hpp:330
PoolID< uint16_t, struct StationIDTag, 64000, 0xFFFF >
RailVehicleInfo::pow_wag_power
uint16_t pow_wag_power
Extra power applied to consist if wagon should be powered.
Definition engine_type.h:88
RailVehicleInfo::air_drag
uint8_t air_drag
Coefficient of air drag.
Definition engine_type.h:93
RailVehicleInfo::pow_wag_weight
uint8_t pow_wag_weight
Extra weight applied to consist if wagon should be powered.
Definition engine_type.h:89
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition vehicle_base.h:1049
SpecializedVehicle::GetPrevVehicle
T * GetPrevVehicle() const
Get the previous real (non-articulated part) vehicle in the consist.
Definition vehicle_base.h:1099
SpecializedVehicle::GetNextVehicle
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
Definition vehicle_base.h:1093
SpriteGroup
Definition newgrf_spritegroup.h:47
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TrainCache
Variables that are cached to improve performance and such.
Definition train.h:74
TrainCache::cached_max_curve_speed
uint16_t cached_max_curve_speed
max consist speed limited by curves
Definition train.h:83
TrainCache::cached_curve_speed_mod
int16_t cached_curve_speed_mod
curve speed modifier of the entire train
Definition train.h:82
TrainCache::user_def_data
uint8_t user_def_data
Cached property 0x25. Can be set by Callback 0x36.
Definition train.h:80
TrainCache::cached_tilt
bool cached_tilt
train can tilt; feature provides a bonus in curves
Definition train.h:79
Train
'Train' is either a loco or a wagon.
Definition train.h:91
Train::PlayLeaveStationSound
void PlayLeaveStationSound(bool force=false) const override
Play a sound for a train leaving the station.
Definition train_cmd.cpp:2212
Train::IsInDepot
bool IsInDepot() const override
Check whether the vehicle is in the depot.
Definition train.h:125
Train::UpdateAcceleration
void UpdateAcceleration()
Update acceleration of the train from the cached power and weight.
Definition train_cmd.cpp:427
Train::OnNewCalendarDay
void OnNewCalendarDay() override
Calendar day handler.
Definition train_cmd.cpp:4177
Train::GetNextUnit
Train * GetNextUnit() const
Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consis...
Definition train.h:150
Train::GetVehicleTrackdir
Trackdir GetVehicleTrackdir() const override
Get the tracks of the train vehicle.
Definition train_cmd.cpp:4221
Train::GetImage
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override
Get the sprite to display the train.
Definition train_cmd.cpp:491
Train::GetDisplayMaxSpeed
int GetDisplayMaxSpeed() const override
Gets the maximum speed in km-ish/h that can be sent into string parameters for string processing.
Definition train.h:121
Train::crash_anim_pos
uint16_t crash_anim_pos
Crash animation counter.
Definition train.h:93
Train::GetTractiveEffort
uint8_t GetTractiveEffort() const
Allows to know the tractive effort value that this vehicle will use.
Definition train.h:256
Train::Tick
bool Tick() override
Update train vehicle data for a tick.
Definition train_cmd.cpp:4110
Train::HasToUseGetSlopePixelZ
bool HasToUseGetSlopePixelZ()
Trains can always use the faster algorithm because they have always the same direction as the track u...
Definition train.h:352
Train::GetCurrentSpeed
uint16_t GetCurrentSpeed() const
Calculates the current speed of this vehicle.
Definition train.h:293
Train::ReserveTrackUnderConsist
void ReserveTrackUnderConsist() const
Tries to reserve track under whole train consist.
Definition train_cmd.cpp:3117
Train::GetOrderStationLocation
TileIndex GetOrderStationLocation(StationID station) override
Get the location of the next station to visit.
Definition train_cmd.cpp:2981
Train::GetPrevUnit
Train * GetPrevUnit()
Get the previous real (non-articulated part and non rear part of dualheaded engine) vehicle in the co...
Definition train.h:162
Train::GetPoweredPartPower
uint16_t GetPoweredPartPower(const Train *head) const
Returns a value if this articulated part is powered.
Definition train.h:215
Train::GetRollingFriction
uint32_t GetRollingFriction() const
Returns the rolling friction coefficient of this vehicle.
Definition train.h:302
Train::GetDisplayImageWidth
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
Definition train_cmd.cpp:457
Train::FindClosestDepot
ClosestDepot FindClosestDepot() override
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Definition train_cmd.cpp:2203
Train::UpdateDeltaXY
void UpdateDeltaXY() override
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition train_cmd.cpp:1490
Train::GetMaxTrackSpeed
uint16_t GetMaxTrackSpeed() const
Gets the maximum speed allowed by the track for this vehicle.
Definition train.h:323
Train::CalcNextVehicleOffset
int CalcNextVehicleOffset() const
Calculate the offset from this vehicle's center to the following center taking the vehicle lengths in...
Definition train.h:174
Train::GetMaxWeight
uint16_t GetMaxWeight() const override
Calculates the weight value that this vehicle will have when fully loaded with its current cargo.
Definition train_cmd.cpp:4238
Train::GetCurveSpeedLimit
uint16_t GetCurveSpeedLimit() const
Computes train speed limit caused by curves.
Definition train_cmd.cpp:304
Train::GetAirDrag
uint8_t GetAirDrag() const
Gets the air drag coefficient of this vehicle.
Definition train.h:275
Train::IsPrimaryVehicle
bool IsPrimaryVehicle() const override
Whether this is the primary vehicle in the chain.
Definition train.h:118
Train::MarkDirty
void MarkDirty() override
Goods at the consist have changed, update the graphics, cargo, and acceleration.
Definition train_cmd.cpp:2996
Train::GetDisplaySpeed
int GetDisplaySpeed() const override
Gets the speed in km-ish/h that can be sent into string parameters for string processing.
Definition train.h:120
Train::UpdateSpeed
int UpdateSpeed()
This function looks at the vehicle and updates its speed (cur_speed and subspeed) variables.
Definition train_cmd.cpp:3016
Train::Crash
uint Crash(bool flooded=false) override
The train vehicle crashed! Update its status and other parts around it.
Definition train_cmd.cpp:3139
Train::GetAccelerationType
VehicleAccelerationModel GetAccelerationType() const
Allows to know the acceleration type of a vehicle.
Definition train.h:187
Train::Train
Train()
We don't want GCC to zero our struct! It already is zeroed and has an index!
Definition train.h:108
Train::GetAccelerationStatus
AccelStatus GetAccelerationStatus() const
Checks the current acceleration status of this vehicle.
Definition train.h:284
Train::~Train
virtual ~Train()
We want to 'destruct' the right class.
Definition train.h:110
Train::OnNewEconomyDay
void OnNewEconomyDay() override
Economy day handler.
Definition train_cmd.cpp:4183
Train::GetCurveSpeedModifier
int16_t GetCurveSpeedModifier() const
Returns the curve speed modifier of this vehicle.
Definition train.h:332
Train::TileMayHaveSlopedTrack
bool TileMayHaveSlopedTrack() const
Checks if the vehicle is at a tile that can be sloped.
Definition train.h:341
Train::GetWeight
uint16_t GetWeight() const
Allows to know the weight value that this vehicle will use.
Definition train.h:229
Train::ConsistChanged
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
Definition train_cmd.cpp:107
Train::GetExpenseType
ExpensesType GetExpenseType(bool income) const override
Sets the expense type associated to this vehicle type.
Definition train.h:116
Train::GetRunningCost
Money GetRunningCost() const override
Get running cost for the train consist.
Definition train_cmd.cpp:4085
Train::GetAirDragArea
uint8_t GetAirDragArea() const
Gets the area used for calculating air drag.
Definition train.h:265
Train::GetPower
uint16_t GetPower() const
Allows to know the power value that this vehicle will use.
Definition train.h:198
Train::wait_counter
uint16_t wait_counter
Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through sign...
Definition train.h:94
Train::GetSlopeSteepness
uint32_t GetSlopeSteepness() const
Returns the slope steepness used by this vehicle.
Definition train.h:314
Train::GetCurrentMaxSpeed
int GetCurrentMaxSpeed() const override
Calculates the maximum speed of the vehicle under its current conditions.
Definition train_cmd.cpp:379
VehicleCache::cached_max_speed
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition vehicle_base.h:93
VehicleSettings::train_slope_steepness
uint8_t train_slope_steepness
Steepness of hills for trains when using realistic acceleration.
Definition settings_type.h:522
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition vehicle_base.h:102
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition vehicle_base.h:278
Vehicle::direction
Direction direction
facing
Definition vehicle_base.h:268
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition vehicle_base.h:296
Vehicle::vehstatus
VehStates vehstatus
Status.
Definition vehicle_base.h:309
Vehicle::IsArticulatedPart
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition vehicle_base.h:922
Vehicle::cargo_type
CargoType cargo_type
type of cargo this vehicle is carrying
Definition vehicle_base.h:297
Vehicle::PreDestructor
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
Definition vehicle.cpp:796
Vehicle::vcache
VehicleCache vcache
Cache of often used vehicle values.
Definition vehicle_base.h:319
Vehicle::cur_speed
uint16_t cur_speed
current speed
Definition vehicle_base.h:283
Vehicle::IsFrontEngine
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition vehicle_base.h:913
Vehicle::tile
TileIndex tile
Current tile index.
Definition vehicle_base.h:225
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition track_type.h:35
TRACK_BIT_WORMHOLE
@ TRACK_BIT_WORMHOLE
Bitflag for a wormhole (used for tunnels)
Definition track_type.h:52
TRACK_BIT_DEPOT
@ TRACK_BIT_DEPOT
Bitflag for a depot.
Definition track_type.h:53
TRACK_BIT_Y
@ TRACK_BIT_Y
Y-axis track.
Definition track_type.h:38
TRACK_BIT_X
@ TRACK_BIT_X
X-axis track.
Definition track_type.h:37
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition track_type.h:66
ConsistChangeFlag
ConsistChangeFlag
Flags for Train::ConsistChanged.
Definition train.h:45
ConsistChangeFlag::Capacity
@ Capacity
Allow vehicles to change capacity.
ConsistChangeFlag::Length
@ Length
Allow vehicles to change length.
CCF_TRACK
static constexpr ConsistChangeFlags CCF_TRACK
Valid changes while vehicle is driving, and possibly changing tracks.
Definition train.h:52
TryPathReserve
bool TryPathReserve(Train *v, bool mark_as_stuck=false, bool first_tile_okay=false)
Try to reserve a path to a safe position.
Definition train_cmd.cpp:2896
CCF_SAVELOAD
static constexpr ConsistChangeFlags CCF_SAVELOAD
Valid changes when loading a savegame. (Everything that is not stored in the save....
Definition train.h:57
NormalizeTrainVehInDepot
void NormalizeTrainVehInDepot(const Train *u)
Move all free vehicles in the depot to the train.
Definition train_cmd.cpp:714
FreightWagonMult
uint8_t FreightWagonMult(CargoType cargo)
Return the cargo weight multiplier to use for a rail vehicle.
Definition train_cmd.cpp:68
FreeTrainTrackReservation
void FreeTrainTrackReservation(const Train *v)
Free the reserved path in front of a vehicle.
Definition train_cmd.cpp:2416
CCF_LOADUNLOAD
static constexpr ConsistChangeFlags CCF_LOADUNLOAD
Valid changes while vehicle is loading/unloading.
Definition train.h:53
CheckTrainsLengths
void CheckTrainsLengths()
Checks if lengths of all rail vehicles are valid.
Definition train_cmd.cpp:75
TrainOnCrossing
bool TrainOnCrossing(TileIndex tile)
Check if a level crossing tile has a train on it.
Definition train_cmd.cpp:1699
VehicleRailFlag
VehicleRailFlag
Rail vehicle flags.
Definition train.h:25
Reversed
@ Reversed
Used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle ...
Definition train.h:31
AllowedOnNormalRail
@ AllowedOnNormalRail
Electric train engine is allowed to run on normal rail. *‍/.
Definition train.h:30
Stuck
@ Stuck
Train can't get a path reservation.
Definition train.h:32
Flipped
@ Flipped
Reverse the visible direction of the vehicle.
Definition train.h:28
PoweredWagon
@ PoweredWagon
Wagon is powered.
Definition train.h:27
LeavingStation
@ LeavingStation
Train is just leaving a station.
Definition train.h:33
Reversing
@ Reversing
Train is slowing down to reverse.
Definition train.h:26
GetTrainStopLocation
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.
Definition train_cmd.cpp:260
TrainForceProceeding
TrainForceProceeding
Modes for ignoring signals.
Definition train.h:38
TFP_SIGNAL
@ TFP_SIGNAL
Ignore next signal, after the signal ignore being stuck.
Definition train.h:41
TFP_NONE
@ TFP_NONE
Normal operation.
Definition train.h:39
TFP_STUCK
@ TFP_STUCK
Proceed till next signal, but ignore being stuck till then. This includes force leaving depots.
Definition train.h:40
CCF_REFIT
static constexpr ConsistChangeFlags CCF_REFIT
Valid changes for refitting in a depot.
Definition train.h:55
CCF_AUTOREFIT
static constexpr ConsistChangeFlags CCF_AUTOREFIT
Valid changes for autorefitting in stations.
Definition train.h:54
GetTrainSpriteSize
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).
Definition train_cmd.cpp:579
CCF_ARRANGE
static constexpr ConsistChangeFlags CCF_ARRANGE
Valid changes for arranging the consist in a depot.
Definition train.h:56
VehState::Hidden
@ Hidden
Vehicle is not visible.
VehState::Stopped
@ Stopped
Vehicle is stopped by the player.
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition vehicle_type.h:74
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:25