OpenTTD Source
12.0-beta2
|
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;
94 inline static bool Allow90degTurns() {
return T90deg_turns_allowed_; }
95 inline static bool DoTrackMasking() {
return Tmask_reserved_tracks; }
148 if (IsRoadTT() && !IsTram() &&
TryReverse())
return true;
167 inline bool MaskReservedTracks()
169 if (!DoTrackMasking())
return true;
238 }
else if (IsRoadTT()) {
330 if (!
HasBit(m_railtypes, rail_type)) {
332 m_err = EC_RAIL_ROAD_TYPE;
343 m_err = EC_RAIL_ROAD_TYPE;
421 if (IsRoadTT() && !IsTram()) {
443 int max_speed = INT_MAX;
448 if (IsRoadTT()) spd *= 2;
449 max_speed = std::min(max_speed, spd);
454 if (rail_speed > 0) max_speed = std::min<int>(max_speed, rail_speed);
459 if (road_speed > 0) max_speed = std::min<int>(max_speed, road_speed);
463 if (pmin_speed !=
nullptr) *pmin_speed = min_speed;
Buses, trucks and trams belong to this class.
bool m_is_station
last turn passed station
static DiagDirection GetRoadDepotDirection(TileIndex t)
Get the direction of the exit of a road depot.
uint32 TileIndex
The index/ID of a Tile.
#define TILE_ADD(x, y)
Adds to tiles together.
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
static BridgeType GetBridgeType(TileIndex t)
Determines the type of bridge on a tile.
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
TileIndex m_old_tile
the origin (vehicle moved from) before move
@ TRANSPORT_RAIL
Transport by train.
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.
@ ROAD_SW
South-west part.
bool CanExitOldTile()
return true if we can leave m_old_tile in m_exitdir
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static bool IsDepotTypeTile(TileIndex tile, TransportType type)
Check if a tile is a depot and it is a depot of the given type.
static bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
bool QueryNewTileTrackStatus()
stores track status (available trackdirs) for the new tile into m_new_td_bits
static bool Rail90DegTurnDisallowed(RailType rt1, RailType rt2, bool def=_settings_game.pf.forbid_90_deg)
Test if 90 degree turns are disallowed between two railtypes.
RoadType roadtype
Roadtype of this vehicle.
TransportType
Available types of transport.
Owner
Enum for all companies/owners.
uint16 speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
@ INVALID_RAILTYPES
Invalid railtypes.
static DiagDirection GetRailDepotDirection(TileIndex t)
Returns the direction the depot is facing to.
bool m_is_bridge
last turn passed bridge ramp
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
@ TRANSPORT_ROAD
Transport by road vehicle.
RoadBits
Enumeration for the road parts on a tile.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
static const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
static RoadBits GetRoadBits(TileIndex t, RoadTramType rtt)
Get the present road bits for a specific road type.
RailType
Enumeration for all possible railtypes.
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Iterable ensemble of each set bit in a value.
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
int32 TileIndexDiff
An offset value between to tiles.
static 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.
static TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
@ ROAD_NE
North-east part.
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
@ ROAD_SE
South-east part.
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
static bool HasStationReservation(TileIndex t)
Get the reservation state of the rail station.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
static DiagDirection GetRoadStopDir(TileIndex t)
Gets the direction the road stop entrance points towards.
DiagDirection
Enumeration for diagonal directions.
RoadType
The different roadtypes we support.
VehicleType
Available vehicle types.
void FollowTileExit()
Follow the m_exitdir from m_old_tile and fill m_new_tile and m_tiles_skipped.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
@ ROAD_NW
North-west part.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Trackdir m_old_td
the trackdir (the vehicle was on) before move
static TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.
static TrackdirBits GetTrackdirBitsForRoad(TileIndex tile, RoadTramType rtt)
Wrapper around GetTileTrackStatus() and TrackStatusToTrackdirBits(), as for single tram bits GetTileT...
@ TRACKDIR_BIT_NONE
No track build.
static bool IsRoadStopTile(TileIndex t)
Is tile t a road stop station?
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
static bool IsTunnel(TileIndex t)
Is this a tunnel (entrance)?
static TrackdirBits TrackToTrackdirBits(Track track)
Returns a TrackdirBit mask from a given Track.
@ TRANSPORT_WATER
Transport over water.
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
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.
TrackBits
Bitfield corresponding to Track.
static TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
bool Follow(TileIndex old_tile, Trackdir old_td)
main follower routine.
uint16 max_speed
Maximum speed for vehicles travelling on this road type.
DiagDirection m_exitdir
exit direction (leaving the old tile)
bool CanEnterNewTile()
return true if we can enter m_new_tile from m_exitdir
static bool IsPlainRailTile(TileIndex t)
Checks whether the tile is a rail tile or rail tile with signals.
TrackdirBits m_new_td_bits
the new set of available trackdirs
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
RailType GetTileRailType(TileIndex tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Trackdir
Enumeration for tracks and directions.
@ VEH_TRAIN
Train vehicle type.
virtual uint GetPlatformLength(TileIndex tile) const =0
Obtain the length of a platform.
Track
These are used to specify a single track.
static TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
RailTypes
The different railtypes we support, but then a bitmask of them.
int GetSpeedLimit(int *pmin_speed=nullptr) const
Helper for pathfinders - get min/max speed on the m_old_tile/m_old_td.
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
bool TryReverse()
return true if we successfully reversed at end of road/track