|
@@ -50,31 +50,31 @@ struct CFollowTrackT
|
|
|
bool m_is_station; ///< last turn passed station
|
|
|
int m_tiles_skipped; ///< number of skipped tunnel or station tiles
|
|
|
ErrorCode m_err;
|
|
|
CPerformanceTimer *m_pPerf;
|
|
|
RailTypes m_railtypes;
|
|
|
|
|
|
FORCEINLINE CFollowTrackT(const VehicleType *v = NULL, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL)
|
|
|
inline CFollowTrackT(const VehicleType *v = NULL, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL)
|
|
|
{
|
|
|
Init(v, railtype_override, pPerf);
|
|
|
}
|
|
|
|
|
|
FORCEINLINE CFollowTrackT(Owner o, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL)
|
|
|
inline CFollowTrackT(Owner o, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL)
|
|
|
{
|
|
|
m_veh = NULL;
|
|
|
Init(o, railtype_override, pPerf);
|
|
|
}
|
|
|
|
|
|
FORCEINLINE void Init(const VehicleType *v, RailTypes railtype_override, CPerformanceTimer *pPerf)
|
|
|
inline void Init(const VehicleType *v, RailTypes railtype_override, CPerformanceTimer *pPerf)
|
|
|
{
|
|
|
assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN));
|
|
|
m_veh = v;
|
|
|
Init(v != NULL ? v->owner : INVALID_OWNER, IsRailTT() && railtype_override == INVALID_RAILTYPES ? Train::From(v)->compatible_railtypes : railtype_override, pPerf);
|
|
|
}
|
|
|
|
|
|
FORCEINLINE void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf)
|
|
|
inline void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf)
|
|
|
{
|
|
|
assert((!IsRoadTT() || m_veh != NULL) && (!IsRailTT() || railtype_override != INVALID_RAILTYPES));
|
|
|
m_veh_owner = o;
|
|
|
m_pPerf = pPerf;
|
|
|
/* don't worry, all is inlined so compiler should remove unnecessary initializations */
|
|
|
m_new_tile = INVALID_TILE;
|
|
@@ -83,22 +83,22 @@ struct CFollowTrackT
|
|
|
m_is_station = m_is_bridge = m_is_tunnel = false;
|
|
|
m_tiles_skipped = 0;
|
|
|
m_err = EC_NONE;
|
|
|
m_railtypes = railtype_override;
|
|
|
}
|
|
|
|
|
|
FORCEINLINE static TransportType TT() {return Ttr_type_;}
|
|
|
FORCEINLINE static bool IsWaterTT() {return TT() == TRANSPORT_WATER;}
|
|
|
FORCEINLINE static bool IsRailTT() {return TT() == TRANSPORT_RAIL;}
|
|
|
FORCEINLINE bool IsTram() {return IsRoadTT() && HasBit(RoadVehicle::From(m_veh)->compatible_roadtypes, ROADTYPE_TRAM);}
|
|
|
FORCEINLINE static bool IsRoadTT() {return TT() == TRANSPORT_ROAD;}
|
|
|
FORCEINLINE static bool Allow90degTurns() {return T90deg_turns_allowed_;}
|
|
|
FORCEINLINE static bool DoTrackMasking() {return IsRailTT() && Tmask_reserved_tracks;}
|
|
|
inline static TransportType TT() {return Ttr_type_;}
|
|
|
inline static bool IsWaterTT() {return TT() == TRANSPORT_WATER;}
|
|
|
inline static bool IsRailTT() {return TT() == TRANSPORT_RAIL;}
|
|
|
inline bool IsTram() {return IsRoadTT() && HasBit(RoadVehicle::From(m_veh)->compatible_roadtypes, ROADTYPE_TRAM);}
|
|
|
inline static bool IsRoadTT() {return TT() == TRANSPORT_ROAD;}
|
|
|
inline static bool Allow90degTurns() {return T90deg_turns_allowed_;}
|
|
|
inline static bool DoTrackMasking() {return IsRailTT() && Tmask_reserved_tracks;}
|
|
|
|
|
|
/** Tests if a tile is a road tile with a single tramtrack (tram can reverse) */
|
|
|
FORCEINLINE DiagDirection GetSingleTramBit(TileIndex tile)
|
|
|
inline DiagDirection GetSingleTramBit(TileIndex tile)
|
|
|
{
|
|
|
assert(IsTram()); // this function shouldn't be called in other cases
|
|
|
|
|
|
if (IsNormalRoadTile(tile)) {
|
|
|
RoadBits rb = GetRoadBits(tile, ROADTYPE_TRAM);
|
|
|
switch (rb) {
|
|
@@ -186,13 +186,13 @@ struct CFollowTrackT
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
protected:
|
|
|
/** Follow the m_exitdir from m_old_tile and fill m_new_tile and m_tiles_skipped */
|
|
|
FORCEINLINE void FollowTileExit()
|
|
|
inline void FollowTileExit()
|
|
|
{
|
|
|
m_is_station = m_is_bridge = m_is_tunnel = false;
|
|
|
m_tiles_skipped = 0;
|
|
|
|
|
|
/* extra handling for tunnels and bridges in our direction */
|
|
|
if (IsTileType(m_old_tile, MP_TUNNELBRIDGE)) {
|
|
@@ -224,13 +224,13 @@ protected:
|
|
|
} else {
|
|
|
m_is_station = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/** stores track status (available trackdirs) for the new tile into m_new_td_bits */
|
|
|
FORCEINLINE bool QueryNewTileTrackStatus()
|
|
|
inline bool QueryNewTileTrackStatus()
|
|
|
{
|
|
|
CPerfStart perf(*m_pPerf);
|
|
|
if (IsRailTT() && IsPlainRailTile(m_new_tile)) {
|
|
|
m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
|
|
|
} else {
|
|
|
m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), IsRoadTT() && m_veh != NULL ? RoadVehicle::From(m_veh)->compatible_roadtypes : 0));
|
|
@@ -254,13 +254,13 @@ protected:
|
|
|
}
|
|
|
}
|
|
|
return (m_new_td_bits != TRACKDIR_BIT_NONE);
|
|
|
}
|
|
|
|
|
|
/** return true if we can leave m_old_tile in m_exitdir */
|
|
|
FORCEINLINE bool CanExitOldTile()
|
|
|
inline bool CanExitOldTile()
|
|
|
{
|
|
|
/* road stop can be left at one direction only unless it's a drive-through stop */
|
|
|
if (IsRoadTT() && IsStandardRoadStopTile(m_old_tile)) {
|
|
|
DiagDirection exitdir = GetRoadStopDir(m_old_tile);
|
|
|
if (exitdir != m_exitdir) {
|
|
|
m_err = EC_NO_WAY;
|
|
@@ -286,13 +286,13 @@ protected:
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/** return true if we can enter m_new_tile from m_exitdir */
|
|
|
FORCEINLINE bool CanEnterNewTile()
|
|
|
inline bool CanEnterNewTile()
|
|
|
{
|
|
|
if (IsRoadTT() && IsStandardRoadStopTile(m_new_tile)) {
|
|
|
/* road stop can be entered from one direction only unless it's a drive-through stop */
|
|
|
DiagDirection exitdir = GetRoadStopDir(m_new_tile);
|
|
|
if (ReverseDiagDir(exitdir) != m_exitdir) {
|
|
|
m_err = EC_NO_WAY;
|
|
@@ -383,13 +383,13 @@ protected:
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/** return true if we must reverse (in depots and single tram bits) */
|
|
|
FORCEINLINE bool ForcedReverse()
|
|
|
inline bool ForcedReverse()
|
|
|
{
|
|
|
/* rail and road depots cause reversing */
|
|
|
if (!IsWaterTT() && IsDepotTypeTile(m_old_tile, TT())) {
|
|
|
DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(m_old_tile) : GetRoadDepotDirection(m_old_tile);
|
|
|
if (exitdir != m_exitdir) {
|
|
|
/* reverse */
|
|
@@ -414,13 +414,13 @@ protected:
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/** return true if we successfully reversed at end of road/track */
|
|
|
FORCEINLINE bool TryReverse()
|
|
|
inline bool TryReverse()
|
|
|
{
|
|
|
if (IsRoadTT() && !IsTram()) {
|
|
|
/* if we reached the end of road, we can reverse the RV and continue moving */
|
|
|
m_exitdir = ReverseDiagDir(m_exitdir);
|
|
|
/* new tile will be the same as old one */
|
|
|
m_new_tile = m_old_tile;
|