OpenTTD Source 20241224-master-gf74b0cf984
|
Track follower helper template class (can serve pathfinders and vehicle controllers). More...
#include <follow_track.hpp>
Public Types | |
enum | ErrorCode { EC_NONE , EC_OWNER , EC_RAIL_ROAD_TYPE , EC_90DEG , EC_NO_WAY , EC_RESERVED } |
Public Member Functions | |
CFollowTrackT (const VehicleType *v=nullptr, RailTypes railtype_override=INVALID_RAILTYPES) | |
CFollowTrackT (Owner o, RailTypes railtype_override=INVALID_RAILTYPES) | |
void | Init (const VehicleType *v, RailTypes railtype_override) |
void | Init (Owner o, RailTypes railtype_override) |
bool | IsTram () |
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. | |
bool | MaskReservedTracks () |
int | GetSpeedLimit (int *pmin_speed=nullptr) const |
Helper for pathfinders - get min/max speed on the old_tile/old_td. | |
Static Public Member Functions | |
static debug_inline TransportType | TT () |
static debug_inline bool | IsWaterTT () |
static debug_inline bool | IsRailTT () |
static debug_inline bool | IsRoadTT () |
static bool | Allow90degTurns () |
static bool | DoTrackMasking () |
Data Fields | |
const VehicleType * | veh |
moving vehicle | |
Owner | veh_owner |
owner of the vehicle | |
TileIndex | old_tile |
the origin (vehicle moved from) before move | |
Trackdir | old_td |
the trackdir (the vehicle was on) before move | |
TileIndex | new_tile |
the new tile (the vehicle has entered) | |
TrackdirBits | new_td_bits |
the new set of available trackdirs | |
DiagDirection | exitdir |
exit direction (leaving the old tile) | |
bool | is_tunnel |
last turn passed tunnel | |
bool | is_bridge |
last turn passed bridge ramp | |
bool | is_station |
last turn passed station | |
int | tiles_skipped |
number of skipped tunnel or station tiles | |
ErrorCode | err |
RailTypes | railtypes |
Protected Member Functions | |
void | FollowTileExit () |
Follow the exitdir from old_tile and fill new_tile and tiles_skipped. | |
bool | QueryNewTileTrackStatus () |
stores track status (available trackdirs) for the new tile into new_td_bits | |
bool | CanExitOldTile () |
return true if we can leave old_tile in exitdir | |
bool | CanEnterNewTile () |
return true if we can enter new_tile from exitdir | |
bool | ForcedReverse () |
return true if we must reverse (in depots and single tram bits) | |
bool | TryReverse () |
return true if we successfully reversed at end of road/track | |
Track follower helper template class (can serve pathfinders and vehicle controllers).
See 6 different typedefs below for 3 different transport types w/ or w/o 90-deg turns allowed
Definition at line 28 of file follow_track.hpp.
enum CFollowTrackT::ErrorCode |
Definition at line 30 of file follow_track.hpp.
|
inline |
Definition at line 53 of file follow_track.hpp.
|
inline |
Definition at line 58 of file follow_track.hpp.
|
inlinestatic |
Definition at line 96 of file follow_track.hpp.
|
inlineprotected |
return true if we can enter new_tile from exitdir
Definition at line 285 of file follow_track.hpp.
References RoadVehicle::compatible_roadtypes, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::exitdir, SpecializedVehicle< T, Type >::From(), GetBayRoadStopDir(), BaseStation::GetByTile(), BaseStation::GetPlatformLength(), GetRailDepotDirection(), GetRoadDepotDirection(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::GetSingleTramBit(), GetTileOwner(), GetTileRailType(), GetTunnelBridgeDirection(), HasBit(), INVALID_DIAGDIR, IsBayRoadStopTile(), IsDepotTypeTile(), IsTileType(), IsTunnel(), MP_TUNNELBRIDGE, ReverseDiagDir(), RoadVehicle::roadtype, TileAdd(), TileOffsByDiagDir(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::tiles_skipped, and TrackdirToExitdir().
Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow().
|
inlineprotected |
return true if we can leave old_tile in exitdir
Definition at line 253 of file follow_track.hpp.
References CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::exitdir, GetBayRoadStopDir(), GetRoadDepotDirection(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::GetSingleTramBit(), INVALID_DIAGDIR, IsBayRoadStopTile(), and IsDepotTypeTile().
Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow().
|
inlinestatic |
Definition at line 97 of file follow_track.hpp.
|
inline |
main follower routine.
Fills all members and return true on success. Otherwise returns false if track can't be followed.
Definition at line 121 of file follow_track.hpp.
References CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanExitOldTile(), DiagdirReachesTrackdirs(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::FollowTileExit(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::ForcedReverse(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::GetSingleTramBit(), GetTileRailType(), GetTileTrackStatus(), INVALID_DIAGDIR, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::old_td, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::old_tile, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::QueryNewTileTrackStatus(), Rail90DegTurnDisallowed(), TRACKDIR_BIT_NONE, TrackdirCrossesTrackdirs(), TrackdirToExitdir(), TrackdirToTrackdirBits(), TrackStatusToTrackdirBits(), and CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::TryReverse().
Referenced by CheckNextTrainTile(), ExtendTrainReservation(), FollowReservation(), WaterRegion::ForceUpdate(), FreeTrainTrackReservation(), IsSafeWaitingPosition(), IsWaitingPositionFree(), and CYapfCostRailT< Types >::PfCalcCost().
|
inlineprotected |
Follow the exitdir from old_tile and fill new_tile and tiles_skipped.
Definition at line 203 of file follow_track.hpp.
References GetOtherBridgeEnd(), GetOtherTunnelEnd(), GetTunnelBridgeDirection(), GetTunnelBridgeLength(), HasStationTileRail(), IsStationRoadStopTile(), IsTileType(), IsTunnel(), MP_TUNNELBRIDGE, ReverseDiagDir(), and TileAddByDiagDir().
Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow().
|
inlineprotected |
return true if we must reverse (in depots and single tram bits)
Definition at line 393 of file follow_track.hpp.
References CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::exitdir, GetBayRoadStopDir(), GetRailDepotDirection(), GetRoadDepotDirection(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::GetSingleTramBit(), IsBayRoadStopTile(), IsDepotTypeTile(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::old_tile, ReverseDiagDir(), ReverseTrackdir(), and TrackdirToTrackdirBits().
Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow().
|
inline |
Tests if a tile is a road tile with a single tramtrack (tram can reverse)
Definition at line 100 of file follow_track.hpp.
References DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, GetRoadBits(), INVALID_DIAGDIR, IsNormalRoadTile(), ROAD_NE, ROAD_NW, ROAD_SE, and ROAD_SW.
Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanExitOldTile(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), and CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::ForcedReverse().
|
inline |
Helper for pathfinders - get min/max speed on the old_tile/old_td.
Definition at line 450 of file follow_track.hpp.
References SpecializedVehicle< T, Type >::From(), GetBridgeSpec(), GetBridgeType(), GetRailType(), GetRailTypeInfo(), GetRoadTypeInfo(), IsBridgeTile(), RailTypeInfo::max_speed, RoadTypeInfo::max_speed, and BridgeSpec::speed.
|
inline |
Definition at line 65 of file follow_track.hpp.
|
inline |
Definition at line 72 of file follow_track.hpp.
|
inlinestatic |
Definition at line 93 of file follow_track.hpp.
|
inlinestatic |
Definition at line 95 of file follow_track.hpp.
|
inline |
Definition at line 94 of file follow_track.hpp.
|
inlinestatic |
Definition at line 92 of file follow_track.hpp.
|
inline |
Definition at line 171 of file follow_track.hpp.
|
inlineprotected |
stores track status (available trackdirs) for the new tile into new_td_bits
Definition at line 240 of file follow_track.hpp.
References GetTileTrackStatus(), GetTrackBits(), GetTrackdirBitsForRoad(), IsPlainRailTile(), TRACKDIR_BIT_NONE, and TrackStatusToTrackdirBits().
Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), and CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::TryReverse().
|
inlineprotected |
return true if we successfully reversed at end of road/track
Definition at line 429 of file follow_track.hpp.
References DiagdirReachesTrackdirs(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::old_tile, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::QueryNewTileTrackStatus(), ReverseDiagDir(), and TRACKDIR_BIT_NONE.
Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow().
|
inlinestatic |
Definition at line 91 of file follow_track.hpp.
ErrorCode CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::err |
Definition at line 50 of file follow_track.hpp.
DiagDirection CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::exitdir |
exit direction (leaving the old tile)
Definition at line 45 of file follow_track.hpp.
Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanExitOldTile(), CheckNextTrainTile(), ExtendTrainReservation(), FollowReservation(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::ForcedReverse(), IsSafeWaitingPosition(), and IsWaitingPositionFree().
bool CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::is_bridge |
last turn passed bridge ramp
Definition at line 47 of file follow_track.hpp.
Referenced by WaterRegion::ForceUpdate(), and FreeTrainTrackReservation().
bool CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::is_station |
last turn passed station
Definition at line 48 of file follow_track.hpp.
Referenced by ExtendTrainReservation(), FollowReservation(), and FreeTrainTrackReservation().
bool CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::is_tunnel |
last turn passed tunnel
Definition at line 46 of file follow_track.hpp.
Referenced by FreeTrainTrackReservation().
TrackdirBits CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::new_td_bits |
the new set of available trackdirs
Definition at line 44 of file follow_track.hpp.
Referenced by CheckNextTrainTile(), ExtendTrainReservation(), FollowReservation(), FreeTrainTrackReservation(), IsSafeWaitingPosition(), IsWaitingPositionFree(), and CYapfCostRailT< Types >::PfCalcCost().
TileIndex CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::new_tile |
the new tile (the vehicle has entered)
Definition at line 43 of file follow_track.hpp.
Referenced by CheckNextTrainTile(), ExtendTrainReservation(), FollowReservation(), WaterRegion::ForceUpdate(), FreeTrainTrackReservation(), IsSafeWaitingPosition(), IsWaitingPositionFree(), and CYapfCostRailT< Types >::PfCalcCost().
Trackdir CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::old_td |
the trackdir (the vehicle was on) before move
Definition at line 42 of file follow_track.hpp.
Referenced by CheckNextTrainTile(), ExtendTrainReservation(), and CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow().
TileIndex CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::old_tile |
the origin (vehicle moved from) before move
Definition at line 41 of file follow_track.hpp.
Referenced by CheckNextTrainTile(), ExtendTrainReservation(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::ForcedReverse(), IsSafeWaitingPosition(), IsWaitingPositionFree(), and CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::TryReverse().
RailTypes CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::railtypes |
Definition at line 51 of file follow_track.hpp.
int CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::tiles_skipped |
number of skipped tunnel or station tiles
Definition at line 49 of file follow_track.hpp.
Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), ExtendTrainReservation(), and FollowReservation().
const VehicleType* CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::veh |
moving vehicle
Definition at line 39 of file follow_track.hpp.
Owner CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::veh_owner |
owner of the vehicle
Definition at line 40 of file follow_track.hpp.