OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
10 #ifndef FOLLOW_TRACK_HPP
11 #define FOLLOW_TRACK_HPP
14 #include "../roadveh.h"
15 #include "../station_base.h"
17 #include "../tunnelbridge.h"
18 #include "../tunnelbridge_map.h"
19 #include "../depot_map.h"
27 template <TransportType Ttr_type_,
typename VehicleType,
bool T90deg_turns_allowed_ = true,
bool Tmask_reserved_tracks = false>
55 Init(v, railtype_override);
62 Init(o, railtype_override);
67 assert(!IsRailTT() || (v !=
nullptr && v->type ==
VEH_TRAIN));
74 assert(!IsRoadTT() ||
m_veh !=
nullptr);
86 m_railtypes = railtype_override;
90 debug_inline
static bool IsWaterTT() {
return TT() ==
TRANSPORT_WATER; }
91 debug_inline
static bool IsRailTT() {
return TT() ==
TRANSPORT_RAIL; }
93 debug_inline
static bool IsRoadTT() {
return TT() ==
TRANSPORT_ROAD; }
94 inline static bool Allow90degTurns() {
return T90deg_turns_allowed_; }
95 inline static bool DoTrackMasking() {
return Tmask_reserved_tracks; }
127 const uint sub_mode = (IsRoadTT() &&
m_veh !=
nullptr) ? (this->IsTram() ? RTT_TRAM : RTT_ROAD) : 0;
150 if (IsRoadTT() && !IsTram() &&
TryReverse())
return true;
169 inline bool MaskReservedTracks()
171 if (!DoTrackMasking())
return true;
240 }
else if (IsRoadTT()) {
332 if (!
HasBit(m_railtypes, rail_type)) {
334 m_err = EC_RAIL_ROAD_TYPE;
345 m_err = EC_RAIL_ROAD_TYPE;
423 if (IsRoadTT() && !IsTram()) {
445 int max_speed = INT_MAX;
450 if (IsRoadTT()) spd *= 2;
451 max_speed = std::min(max_speed, spd);
456 if (rail_speed > 0) max_speed = std::min<int>(max_speed, rail_speed);
461 if (road_speed > 0) max_speed = std::min<int>(max_speed, road_speed);
465 if (pmin_speed !=
nullptr) *pmin_speed = min_speed;
@ INVALID_RAILTYPES
Invalid railtypes.
Buses, trucks and trams belong to this class.
bool Rail90DegTurnDisallowed(RailType rt1, RailType rt2, bool def=_settings_game.pf.forbid_90_deg)
Test if 90 degree turns are disallowed between two railtypes.
bool m_is_station
last turn passed station
@ DIAGDIR_NE
Northeast, upper right on your monitor.
constexpr TileIndex TileAdd(TileIndex tile, TileIndexDiff offset)
Adds a given offset to a tile.
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
RoadBits
Enumeration for the road parts on a tile.
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
TileIndex m_old_tile
the origin (vehicle moved from) before move
TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
TrackBits GetReservedTrackbits(TileIndex t)
Get the reserved trackbits for any tile, regardless of type.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
@ TRANSPORT_WATER
Transport over water.
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
@ INVALID_OWNER
An invalid owner.
TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
@ ROAD_SE
South-east part.
Owner
Enum for all companies/owners.
RailType
Enumeration for all possible railtypes.
bool CanExitOldTile()
return true if we can leave m_old_tile in m_exitdir
@ VEH_TRAIN
Train vehicle type.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
DiagDirection
Enumeration for diagonal directions.
DiagDirection GetRoadStopDir(Tile t)
Gets the direction the road stop entrance points towards.
uint16_t speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
bool QueryNewTileTrackStatus()
stores track status (available trackdirs) for the new tile into m_new_td_bits
RoadType roadtype
NOSAVE: Roadtype of this vehicle.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
RailTypes
Allow incrementing of Track variables.
@ ROAD_NW
North-west part.
bool m_is_bridge
last turn passed bridge ramp
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
@ TRANSPORT_ROAD
Transport by road vehicle.
DiagDirection GetRoadDepotDirection(Tile t)
Get the direction of the exit of a road depot.
DiagDirection GetRailDepotDirection(Tile t)
Returns the direction the depot is facing to.
TransportType
Available types of transport.
TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
bool IsBayRoadStopTile(Tile t)
Is tile t a bay (non-drive through) road stop station?
const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Iterable ensemble of each set bit in a value.
TrackdirBits TrackToTrackdirBits(Track track)
Returns a TrackdirBit mask from a given Track.
TrackBits
Allow incrementing of Track variables.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
@ ROAD_SW
South-west part.
bool IsTunnel(Tile t)
Is this a tunnel (entrance)?
@ TRACKDIR_BIT_NONE
No track build.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
RoadType
The different roadtypes we support.
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
static debug_inline bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
bool IsDepotTypeTile(Tile tile, TransportType type)
Check if a tile is a depot and it is a depot of the given type.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
RoadTypes compatible_roadtypes
NOSAVE: Roadtypes this consist is powered on.
int32_t TileIndexDiff
An offset value between two tiles.
void FollowTileExit()
Follow the m_exitdir from m_old_tile and fill m_new_tile and m_tiles_skipped.
static debug_inline bool IsPlainRailTile(Tile t)
Checks whether the tile is a rail tile or rail tile with signals.
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
Trackdir m_old_td
the trackdir (the vehicle was on) before move
uint16_t max_speed
Maximum speed for vehicles travelling on this rail type.
bool IsStationRoadStopTile(Tile t)
Is tile t a road stop station?
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Track
These are used to specify a single track.
TrackdirBits GetTrackdirBitsForRoad(TileIndex tile, RoadTramType rtt)
Wrapper around GetTileTrackStatus() and TrackStatusToTrackdirBits(), as for single tram bits GetTileT...
Trackdir
Enumeration for tracks and directions.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
@ TRANSPORT_RAIL
Transport by train.
bool HasStationReservation(Tile t)
Get the reservation state of the rail station.
@ ROAD_NE
North-east part.
RailType GetTileRailType(Tile tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Owner m_veh_owner
owner of the vehicle
TileIndex m_new_tile
the new tile (the vehicle has entered)
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
bool Follow(TileIndex old_tile, Trackdir old_td)
main follower routine.
DiagDirection m_exitdir
exit direction (leaving the old tile)
bool CanEnterNewTile()
return true if we can enter m_new_tile from m_exitdir
TrackdirBits m_new_td_bits
the new set of available trackdirs
VehicleType
Available vehicle types.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
virtual uint GetPlatformLength(TileIndex tile) const =0
Obtain the length of a platform.
TrackdirBits
Allow incrementing of Trackdir variables.
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
int GetSpeedLimit(int *pmin_speed=nullptr) const
Helper for pathfinders - get min/max speed on the m_old_tile/m_old_td.
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
const VehicleType * m_veh
moving vehicle
bool ForcedReverse()
return true if we must reverse (in depots and single tram bits)
DiagDirection GetSingleTramBit(TileIndex tile)
Tests if a tile is a road tile with a single tramtrack (tram can reverse)
Track follower helper template class (can serve pathfinders and vehicle controllers).
int m_tiles_skipped
number of skipped tunnel or station tiles
bool m_is_tunnel
last turn passed tunnel
BridgeType GetBridgeType(Tile t)
Determines the type of bridge on a tile.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
bool TryReverse()
return true if we successfully reversed at end of road/track
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.