|
OpenTTD Source
14.0-beta3
|
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; }
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;
@ 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
#define TILE_ADD(x, y)
Adds two tiles together.
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
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.
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
bool CanExitOldTile()
return true if we can leave m_old_tile in m_exitdir
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
DiagDirection GetRoadStopDir(Tile t)
Gets the direction the road stop entrance points towards.
@ TRANSPORT_WATER
Transport over water.
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
Roadtype of this vehicle.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Owner
Enum for all companies/owners.
RailTypes
Allow incrementing of Track variables.
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.
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.
@ TRANSPORT_RAIL
Transport by train.
TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
@ ROAD_NE
North-east part.
bool IsBayRoadStopTile(Tile t)
Is tile t a bay (non-drive through) road stop station?
RailType
Enumeration for all possible railtypes.
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.
bool IsTunnel(Tile t)
Is this a tunnel (entrance)?
TransportType
Available types of transport.
@ TRACKDIR_BIT_NONE
No track build.
@ INVALID_OWNER
An invalid owner.
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
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.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
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
Roadtypes this consist is powered on.
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
int32_t TileIndexDiff
An offset value between two tiles.
DiagDirection
Enumeration for diagonal directions.
VehicleType
Available vehicle types.
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.
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.
TrackdirBits GetTrackdirBitsForRoad(TileIndex tile, RoadTramType rtt)
Wrapper around GetTileTrackStatus() and TrackStatusToTrackdirBits(), as for single tram bits GetTileT...
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
bool HasStationReservation(Tile t)
Get the reservation state of the rail station.
RailType GetTileRailType(Tile tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
RoadType
The different roadtypes we support.
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Owner m_veh_owner
owner of the vehicle
RoadBits
Enumeration for the road parts on a tile.
TileIndex m_new_tile
the new tile (the vehicle has entered)
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
TrackBits
Allow incrementing of Track variables.
@ ROAD_NW
North-west part.
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
@ ROAD_SW
South-west part.
bool Follow(TileIndex old_tile, Trackdir old_td)
main follower routine.
@ ROAD_SE
South-east part.
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
@ TRANSPORT_ROAD
Transport by road vehicle.
Trackdir
Enumeration for tracks and directions.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
@ VEH_TRAIN
Train vehicle type.
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.
Track
These are used to specify a single track.
bool IsRoadStopTile(Tile t)
Is tile t a road stop station?
@ DIAGDIR_NE
Northeast, upper right on your monitor.
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.