12 #ifndef FOLLOW_TRACK_HPP 13 #define FOLLOW_TRACK_HPP 16 #include "../roadveh.h" 17 #include "../station_base.h" 19 #include "../tunnelbridge.h" 20 #include "../tunnelbridge_map.h" 21 #include "../depot_map.h" 29 template <TransportType Ttr_type_,
typename VehicleType,
bool T90deg_turns_allowed_ = true,
bool Tmask_reserved_tracks = false>
58 Init(v, railtype_override, pPerf);
64 Init(o, railtype_override, pPerf);
69 assert(!IsRailTT() || (v != NULL && v->type ==
VEH_TRAIN));
76 assert(!IsRoadTT() || m_veh != NULL);
86 m_is_station = m_is_bridge = m_is_tunnel =
false;
89 m_railtypes = railtype_override;
97 inline static bool Allow90degTurns() {
return T90deg_turns_allowed_; }
98 inline static bool DoTrackMasking() {
return Tmask_reserved_tracks; }
124 m_old_tile = old_tile;
151 if (IsRoadTT() && !IsTram() &&
TryReverse())
return true;
160 if (!Allow90degTurns()) {
170 inline bool MaskReservedTracks()
172 if (!DoTrackMasking())
return true;
177 for (
TileIndex tile = m_new_tile - diff * m_tiles_skipped; tile !=
m_new_tile; tile += diff) {
205 m_is_station = m_is_bridge = m_is_tunnel =
false;
211 if (enterdir == m_exitdir) {
273 if (exitdir != m_exitdir) {
291 if (exitdir != m_exitdir) {
342 if (IsRailTT() &&
GetTileOwner(m_new_tile) != m_veh_owner) {
351 if (!
HasBit(m_railtypes, rail_type)) {
353 m_err = EC_RAIL_TYPE;
363 if (tunnel_enterdir != m_exitdir) {
371 if (ramp_enderdir != m_exitdir) {
380 if (IsRailTT() && m_is_station) {
385 m_tiles_skipped = length - 1;
389 m_new_tile =
TILE_ADD(m_new_tile, diff);
402 if (exitdir != m_exitdir) {
408 m_is_tunnel = m_is_bridge = m_is_station =
false;
421 m_is_tunnel = m_is_bridge = m_is_station =
false;
431 if (IsRoadTT() && !IsTram()) {
453 int max_speed = INT_MAX;
458 if (IsRoadTT()) spd *= 2;
459 if (max_speed > spd) max_speed = spd;
464 if (rail_speed > 0) max_speed =
min(max_speed, rail_speed);
468 if (pmin_speed != NULL) *pmin_speed = min_speed;
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
virtual uint GetPlatformLength(TileIndex tile) const =0
Obtain the length of a platform.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
DiagDirection GetSingleTramBit(TileIndex tile)
Tests if a tile is a road tile with a single tramtrack (tram can reverse)
bool Follow(TileIndex old_tile, Trackdir old_td)
main follower routine.
RailType
Enumeration for all possible railtypes.
TrackdirBits m_new_td_bits
the new set of available trackdirs
bool m_is_tunnel
last turn passed tunnel
const VehicleType * m_veh
moving vehicle
Flag for an invalid DiagDirection.
int32 TileIndexDiff
An offset value between to tiles.
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Track
These are used to specify a single track.
static TrackdirBits TrackToTrackdirBits(Track track)
Returns a TrackdirBit mask from a given Track.
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
static RoadBits GetRoadBits(TileIndex t, RoadType rt)
Get the present road bits for a specific road type.
Northeast, upper right on your monitor.
uint16 speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
TileIndex m_old_tile
the origin (vehicle moved from) before move
static DiagDirection GetRoadDepotDirection(TileIndex t)
Get the direction of the exit of a road depot.
static TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction...
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
bool m_is_station
last turn passed station
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
bool m_is_bridge
last turn passed bridge ramp
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
TrackBits
Bitfield corresponding to Track.
Track x-axis, direction north-east.
int GetSpeedLimit(int *pmin_speed=NULL) const
Helper for pathfinders - get min/max speed on the m_old_tile/m_old_td.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
static bool HasStationReservation(TileIndex t)
Get the reservation state of the rail station.
void FollowTileExit()
Follow the m_exitdir from m_old_tile and fill m_new_tile and m_tiles_skipped.
VehicleType
Available vehicle types.
bool CanExitOldTile()
return true if we can leave m_old_tile in m_exitdir
static bool IsDepotTypeTile(TileIndex tile, TransportType type)
Check if a tile is a depot and it is a depot of the given type.
static TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
static DiagDirection GetRoadStopDir(TileIndex t)
Gets the direction the road stop entrance points towards.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
static DiagDirection GetRailDepotDirection(TileIndex t)
Returns the direction the depot is facing to.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
static const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
#define FOR_EACH_SET_TRACK(var, track_bits)
Iterate through each set Track in a TrackBits value.
RoadBits
Enumeration for the road parts on a tile.
Trackdir
Enumeration for tracks and directions.
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
DiagDirection
Enumeration for diagonal directions.
static T min(const T a, const T b)
Returns the minimum of two values.
RailTypes
The different railtypes we support, but then a bitmask of them.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
static bool IsPlainRailTile(TileIndex t)
Checks whether the tile is a rail tile or rail tile with signals.
Track follower helper template class (can serve pathfinders and vehicle controllers).
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
static BridgeType GetBridgeType(TileIndex t)
Determines the type of bridge on a tile.
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
RailType GetTileRailType(TileIndex tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
bool ForcedReverse()
return true if we must reverse (in depots and single tram bits)
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
Tunnel entry/exit and bridge heads.
Track x-axis, direction south-west.
uint32 TileIndex
The index/ID of a Tile.
Track y-axis, direction north-west.
TrackBits GetReservedTrackbits(TileIndex t)
Get the reserved trackbits for any tile, regardless of type.
TileIndex m_new_tile
the new tile (the vehicle has entered)
TransportType
Available types of transport.
Transport by road vehicle.
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
static bool IsRoadStopTile(TileIndex t)
Is tile t a road stop station?
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
DiagDirection m_exitdir
exit direction (leaving the old tile)
bool TryReverse()
return true if we successfully reversed at end of road/track
Trackdir m_old_td
the trackdir (the vehicle was on) before move
Track y-axis, direction south-east.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Owner m_veh_owner
owner of the vehicle
static TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Owner
Enum for all companies/owners.
Flag for an invalid trackdir.
#define TILE_ADD(x, y)
Adds to tiles together.
int m_tiles_skipped
number of skipped tunnel or station tiles
static TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
static bool IsTunnel(TileIndex t)
Is this a tunnel (entrance)?
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
static bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
bool CanEnterNewTile()
return true if we can enter m_new_tile from m_exitdir
bool QueryNewTileTrackStatus()
stores track status (available trackdirs) for the new tile into m_new_td_bits