src/yapf/follow_track.hpp
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 9132 6256752d5e80
child 10213 23cfd330ccac
permissions -rw-r--r--
update tags
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     1
/* $Id$ */
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     2
6447
3b71e57fd22b (svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents: 6338
diff changeset
     3
/** @file follow_track.hpp Template function for track followers */
3b71e57fd22b (svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents: 6338
diff changeset
     4
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     5
#ifndef  FOLLOW_TRACK_HPP
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     6
#define  FOLLOW_TRACK_HPP
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     7
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     8
#include "yapf.hpp"
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     9
9132
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    10
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    11
/** Track follower helper template class (can serve pathfinders and vehicle
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4407
diff changeset
    12
 *  controllers). See 6 different typedefs below for 3 different transport
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4407
diff changeset
    13
 *  types w/ of w/o 90-deg turns allowed */
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    14
template <TransportType Ttr_type_, bool T90deg_turns_allowed_ = true>
9132
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    15
struct CFollowTrackT
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    16
{
9132
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    17
	enum ErrorCode {
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    18
		EC_NONE,
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    19
		EC_OWNER,
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    20
		EC_RAIL_TYPE,
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    21
		EC_90DEG,
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    22
		EC_NO_WAY,
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    23
	};
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    24
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    25
	const Vehicle*      m_veh;           ///< moving vehicle
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    26
	TileIndex           m_old_tile;      ///< the origin (vehicle moved from) before move
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    27
	Trackdir            m_old_td;        ///< the trackdir (the vehicle was on) before move
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    28
	TileIndex           m_new_tile;      ///< the new tile (the vehicle has entered)
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    29
	TrackdirBits        m_new_td_bits;   ///< the new set of available trackdirs
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    30
	DiagDirection       m_exitdir;       ///< exit direction (leaving the old tile)
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    31
	bool                m_is_tunnel;     ///< last turn passed tunnel
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    32
	bool                m_is_bridge;     ///< last turn passed bridge ramp
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    33
	bool                m_is_station;    ///< last turn passed station
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    34
	int                 m_tiles_skipped; ///< number of skipped tunnel or station tiles
6256752d5e80 (svn r12252) -Fix [FS#1801]: Broken FollowTrack_t related functions (thanks michi_cc).
KUDr
parents: 9112
diff changeset
    35
	ErrorCode           m_err;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    36
	CPerformanceTimer* m_pPerf;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    37
3915
281c7ebd27e0 (svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents: 3912
diff changeset
    38
	FORCEINLINE CFollowTrackT(const Vehicle* v = NULL, CPerformanceTimer* pPerf = NULL)
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    39
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    40
		Init(v, pPerf);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    41
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    42
3915
281c7ebd27e0 (svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents: 3912
diff changeset
    43
	FORCEINLINE void Init(const Vehicle* v, CPerformanceTimer* pPerf)
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    44
	{
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6480
diff changeset
    45
		assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN));
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    46
		m_veh = v;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    47
		m_pPerf = pPerf;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    48
		// don't worry, all is inlined so compiler should remove unnecessary initializations
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    49
		m_new_tile = INVALID_TILE;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    50
		m_new_td_bits = TRACKDIR_BIT_NONE;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    51
		m_exitdir = INVALID_DIAGDIR;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    52
		m_is_station = m_is_bridge = m_is_tunnel = false;
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
    53
		m_tiles_skipped = 0;
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
    54
		m_err = EC_NONE;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    55
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    56
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    57
	FORCEINLINE static TransportType TT() {return Ttr_type_;}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    58
	FORCEINLINE static bool IsWaterTT() {return TT() == TRANSPORT_WATER;}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    59
	FORCEINLINE static bool IsRailTT() {return TT() == TRANSPORT_RAIL;}
8961
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    60
	FORCEINLINE bool IsTram() {return IsRoadTT() && HasBit(m_veh->u.road.compatible_roadtypes, ROADTYPE_TRAM);}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    61
	FORCEINLINE static bool IsRoadTT() {return TT() == TRANSPORT_ROAD;}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    62
	FORCEINLINE static bool Allow90degTurns() {return T90deg_turns_allowed_;}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    63
8961
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    64
	/** Tests if a tile is a road tile with a single tramtrack (tram can reverse) */
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    65
	FORCEINLINE DiagDirection GetSingleTramBit(TileIndex tile)
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    66
	{
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8987
diff changeset
    67
		if (IsTram() && IsNormalRoadTile(tile)) {
8961
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    68
			RoadBits rb = GetRoadBits(tile, ROADTYPE_TRAM);
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    69
			switch (rb) {
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    70
				case ROAD_NW: return DIAGDIR_NW;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    71
				case ROAD_SW: return DIAGDIR_SW;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    72
				case ROAD_SE: return DIAGDIR_SE;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    73
				case ROAD_NE: return DIAGDIR_NE;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    74
				default: break;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    75
			}
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    76
		}
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    77
		return INVALID_DIAGDIR;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    78
	}
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    79
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    80
	/** main follower routine. Fills all members and return true on success.
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4407
diff changeset
    81
	 *  Otherwise returns false if track can't be followed. */
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    82
	FORCEINLINE bool Follow(TileIndex old_tile, Trackdir old_td)
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    83
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    84
		m_old_tile = old_tile;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    85
		m_old_td = old_td;
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
    86
		m_err = EC_NONE;
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9059
diff changeset
    87
		assert(((TrackStatusToTrackdirBits(GetTileTrackStatus(m_old_tile, TT(), m_veh->u.road.compatible_roadtypes)) & TrackdirToTrackdirBits(m_old_td)) != 0) ||
8961
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    88
		       (GetSingleTramBit(m_old_tile) != INVALID_DIAGDIR)); // Disable the assertion for single tram bits
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    89
		m_exitdir = TrackdirToExitdir(m_old_td);
8961
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
    90
		if (ForcedReverse()) return true;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    91
		if (!CanExitOldTile()) return false;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    92
		FollowTileExit();
3976
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
    93
		if (!QueryNewTileTrackStatus()) return TryReverse();
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    94
		if (!CanEnterNewTile()) return false;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    95
		m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
    96
		if (m_new_td_bits == TRACKDIR_BIT_NONE) {
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
    97
			m_err = EC_NO_WAY;
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
    98
			return false;
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
    99
		}
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   100
		if (!Allow90degTurns()) {
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   101
			m_new_td_bits &= (TrackdirBits)~(int)TrackdirCrossesTrackdirs(m_old_td);
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   102
			if (m_new_td_bits == TRACKDIR_BIT_NONE) {
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   103
				m_err = EC_90DEG;
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   104
				return false;
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   105
			}
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   106
		}
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   107
		return true;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   108
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   109
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   110
protected:
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   111
	/** Follow the m_exitdir from m_old_tile and fill m_new_tile and m_tiles_skipped */
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   112
	FORCEINLINE void FollowTileExit()
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   113
	{
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   114
		m_is_station = m_is_bridge = m_is_tunnel = false;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   115
		m_tiles_skipped = 0;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   116
8894
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   117
		// extra handling for tunnels and bridges in our direction
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   118
		if (IsTileType(m_old_tile, MP_TUNNELBRIDGE)) {
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   119
			DiagDirection enterdir = GetTunnelBridgeDirection(m_old_tile);
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   120
			if (enterdir == m_exitdir) {
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   121
				// we are entering the tunnel / bridge
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   122
				if (IsTunnel(m_old_tile)) {
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   123
					m_is_tunnel = true;
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   124
					m_new_tile = GetOtherTunnelEnd(m_old_tile);
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   125
				} else { // IsBridge(m_old_tile)
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   126
					m_is_bridge = true;
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   127
					m_new_tile = GetOtherBridgeEnd(m_old_tile);
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   128
				}
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   129
				m_tiles_skipped = GetTunnelBridgeLength(m_new_tile, m_old_tile);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   130
				return;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   131
			}
8894
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8886
diff changeset
   132
			assert(ReverseDiagDir(enterdir) == m_exitdir);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   133
		}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   134
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   135
		// normal or station tile, do one step
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
   136
		TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   137
		m_new_tile = TILE_ADD(m_old_tile, diff);
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   138
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   139
		// special handling for stations
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   140
		if (IsRailTT() && IsRailwayStationTile(m_new_tile)) {
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   141
			m_is_station = true;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   142
		} else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) {
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   143
			m_is_station = true;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   144
		} else {
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   145
			m_is_station = false;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   146
		}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   147
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   148
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   149
	/** stores track status (available trackdirs) for the new tile into m_new_td_bits */
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   150
	FORCEINLINE bool QueryNewTileTrackStatus()
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   151
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   152
		CPerfStart perf(*m_pPerf);
3912
76e7f798cb88 (svn r5013) -Fix: [YAPF] RVs trying to plan route through railway.
KUDr
parents: 3900
diff changeset
   153
		if (IsRailTT() && GetTileType(m_new_tile) == MP_RAILWAY && IsPlainRailTile(m_new_tile)) {
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   154
			m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   155
		} else {
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9059
diff changeset
   156
			m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), m_veh->u.road.compatible_roadtypes));
8961
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   157
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   158
			if (m_new_td_bits == 0) {
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   159
				/* GetTileTrackStatus() returns 0 for single tram bits.
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   160
				 * As we cannot change it there (easily) without breaking something, change it here */
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   161
				switch (GetSingleTramBit(m_new_tile)) {
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   162
					case DIAGDIR_NE:
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   163
					case DIAGDIR_SW:
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   164
						m_new_td_bits = TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   165
						break;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   166
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   167
					case DIAGDIR_NW:
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   168
					case DIAGDIR_SE:
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   169
						m_new_td_bits = TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_Y_SE;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   170
						break;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   171
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   172
					default: break;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   173
				}
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   174
			}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   175
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   176
		return (m_new_td_bits != TRACKDIR_BIT_NONE);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   177
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   178
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   179
	/** return true if we can leave m_old_tile in m_exitdir */
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   180
	FORCEINLINE bool CanExitOldTile()
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   181
	{
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6324
diff changeset
   182
		// road stop can be left at one direction only unless it's a drive-through stop
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6324
diff changeset
   183
		if (IsRoadTT() && IsStandardRoadStopTile(m_old_tile)) {
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   184
			DiagDirection exitdir = GetRoadStopDir(m_old_tile);
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   185
			if (exitdir != m_exitdir) {
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   186
				m_err = EC_NO_WAY;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   187
				return false;
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   188
			}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   189
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   190
8961
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   191
		/* single tram bits can only be left in one direction */
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   192
		DiagDirection single_tram = GetSingleTramBit(m_old_tile);
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   193
		if (single_tram != INVALID_DIAGDIR && single_tram != m_exitdir) {
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   194
			m_err = EC_NO_WAY;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   195
			return false;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   196
		}
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   197
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   198
		// road depots can be also left in one direction only
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   199
		if (IsRoadTT() && IsTileDepotType(m_old_tile, TT())) {
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   200
			DiagDirection exitdir = GetRoadDepotDirection(m_old_tile);
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   201
			if (exitdir != m_exitdir) {
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   202
				m_err = EC_NO_WAY;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   203
				return false;
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   204
			}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   205
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   206
		return true;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   207
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   208
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   209
	/** return true if we can enter m_new_tile from m_exitdir */
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   210
	FORCEINLINE bool CanEnterNewTile()
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   211
	{
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6324
diff changeset
   212
		if (IsRoadTT() && IsStandardRoadStopTile(m_new_tile)) {
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6324
diff changeset
   213
			// road stop can be entered from one direction only unless it's a drive-through stop
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   214
			DiagDirection exitdir = GetRoadStopDir(m_new_tile);
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   215
			if (ReverseDiagDir(exitdir) != m_exitdir) {
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   216
				m_err = EC_NO_WAY;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   217
				return false;
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   218
			}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   219
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   220
8961
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   221
		/* single tram bits can only be entered from one direction */
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   222
		DiagDirection single_tram = GetSingleTramBit(m_new_tile);
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   223
		if (single_tram != INVALID_DIAGDIR && single_tram != ReverseDiagDir(m_exitdir)) {
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   224
			m_err = EC_NO_WAY;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   225
			return false;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   226
		}
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   227
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   228
		// road and rail depots can also be entered from one direction only
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   229
		if (IsRoadTT() && IsTileDepotType(m_new_tile, TT())) {
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   230
			DiagDirection exitdir = GetRoadDepotDirection(m_new_tile);
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   231
			if (ReverseDiagDir(exitdir) != m_exitdir) {
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   232
				m_err = EC_NO_WAY;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   233
				return false;
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   234
			}
4407
d639dd97eff0 (svn r6160) -Fix [ 1519167 ] Bus trying to service in depot of other company (mart3p)
KUDr
parents: 3977
diff changeset
   235
			// don't try to enter other player's depots
d639dd97eff0 (svn r6160) -Fix [ 1519167 ] Bus trying to service in depot of other company (mart3p)
KUDr
parents: 3977
diff changeset
   236
			if (GetTileOwner(m_new_tile) != m_veh->owner) {
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   237
				m_err = EC_OWNER;
4407
d639dd97eff0 (svn r6160) -Fix [ 1519167 ] Bus trying to service in depot of other company (mart3p)
KUDr
parents: 3977
diff changeset
   238
				return false;
d639dd97eff0 (svn r6160) -Fix [ 1519167 ] Bus trying to service in depot of other company (mart3p)
KUDr
parents: 3977
diff changeset
   239
			}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   240
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   241
		if (IsRailTT() && IsTileDepotType(m_new_tile, TT())) {
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   242
			DiagDirection exitdir = GetRailDepotDirection(m_new_tile);
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   243
			if (ReverseDiagDir(exitdir) != m_exitdir) {
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   244
				m_err = EC_NO_WAY;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   245
				return false;
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   246
			}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   247
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   248
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   249
		// rail transport is possible only on tiles with the same owner as vehicle
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   250
		if (IsRailTT() && GetTileOwner(m_new_tile) != m_veh->owner) {
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   251
			// different owner
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   252
			m_err = EC_NO_WAY;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   253
			return false;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   254
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   255
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   256
		// rail transport is possible only on compatible rail types
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   257
		if (IsRailTT()) {
6480
767cfeae4dbf (svn r8899) -Fix
tron
parents: 6447
diff changeset
   258
			RailType rail_type = GetTileRailType(m_new_tile);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7710
diff changeset
   259
			if (!HasBit(m_veh->u.rail.compatible_railtypes, rail_type)) {
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   260
				// incompatible rail type
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   261
				m_err = EC_RAIL_TYPE;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   262
				return false;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   263
			}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   264
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   265
5671
4c249f1e0098 (svn r7623) - Fix: [YAPF] trains/roadvehs trying to enter the bridge ramp from under bridge rail/road (introduced by bridge merge r7573)
KUDr
parents: 5573
diff changeset
   266
		// tunnel holes and bridge ramps can be entered only from proper direction
4c249f1e0098 (svn r7623) - Fix: [YAPF] trains/roadvehs trying to enter the bridge ramp from under bridge rail/road (introduced by bridge merge r7573)
KUDr
parents: 5573
diff changeset
   267
		if (!IsWaterTT() && IsTileType(m_new_tile, MP_TUNNELBRIDGE)) {
4c249f1e0098 (svn r7623) - Fix: [YAPF] trains/roadvehs trying to enter the bridge ramp from under bridge rail/road (introduced by bridge merge r7573)
KUDr
parents: 5573
diff changeset
   268
			if (IsTunnel(m_new_tile)) {
4c249f1e0098 (svn r7623) - Fix: [YAPF] trains/roadvehs trying to enter the bridge ramp from under bridge rail/road (introduced by bridge merge r7573)
KUDr
parents: 5573
diff changeset
   269
				if (!m_is_tunnel) {
8579
3efbb430092e (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8424
diff changeset
   270
					DiagDirection tunnel_enterdir = GetTunnelBridgeDirection(m_new_tile);
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   271
					if (tunnel_enterdir != m_exitdir) {
7710
8925ffc8a981 (svn r10492) -Fix [YAPF, r10491]: commands with no effect (glx)
KUDr
parents: 7707
diff changeset
   272
						m_err = EC_NO_WAY;
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   273
						return false;
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   274
					}
5671
4c249f1e0098 (svn r7623) - Fix: [YAPF] trains/roadvehs trying to enter the bridge ramp from under bridge rail/road (introduced by bridge merge r7573)
KUDr
parents: 5573
diff changeset
   275
				}
8886
9f2c7ebc7fc9 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8579
diff changeset
   276
			} else { // IsBridge(m_new_tile)
5671
4c249f1e0098 (svn r7623) - Fix: [YAPF] trains/roadvehs trying to enter the bridge ramp from under bridge rail/road (introduced by bridge merge r7573)
KUDr
parents: 5573
diff changeset
   277
				if (!m_is_bridge) {
8579
3efbb430092e (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8424
diff changeset
   278
					DiagDirection ramp_enderdir = GetTunnelBridgeDirection(m_new_tile);
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   279
					if (ramp_enderdir != m_exitdir) {
7710
8925ffc8a981 (svn r10492) -Fix [YAPF, r10491]: commands with no effect (glx)
KUDr
parents: 7707
diff changeset
   280
						m_err = EC_NO_WAY;
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   281
						return false;
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   282
					}
5671
4c249f1e0098 (svn r7623) - Fix: [YAPF] trains/roadvehs trying to enter the bridge ramp from under bridge rail/road (introduced by bridge merge r7573)
KUDr
parents: 5573
diff changeset
   283
				}
4c249f1e0098 (svn r7623) - Fix: [YAPF] trains/roadvehs trying to enter the bridge ramp from under bridge rail/road (introduced by bridge merge r7573)
KUDr
parents: 5573
diff changeset
   284
			}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   285
		}
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   286
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   287
		// special handling for rail stations - get to the end of platform
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   288
		if (IsRailTT() && m_is_station) {
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   289
			// entered railway station
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   290
			// get platform length
6324
ebf3649bd88f (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 6077
diff changeset
   291
			uint length = GetStationByTile(m_new_tile)->GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td));
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   292
			// how big step we must do to get to the last platform tile;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   293
			m_tiles_skipped = length - 1;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   294
			// move to the platform end
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
   295
			TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   296
			diff *= m_tiles_skipped;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   297
			m_new_tile = TILE_ADD(m_new_tile, diff);
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   298
			return true;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   299
		}
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   300
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   301
		return true;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   302
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   303
8961
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   304
	/** return true if we must reverse (in depots and single tram bits) */
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   305
	FORCEINLINE bool ForcedReverse()
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   306
	{
3976
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   307
		// rail and road depots cause reversing
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   308
		if (!IsWaterTT() && IsTileDepotType(m_old_tile, TT())) {
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   309
			DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(m_old_tile) : GetRoadDepotDirection(m_old_tile);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   310
			if (exitdir != m_exitdir) {
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   311
				// reverse
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   312
				m_new_tile = m_old_tile;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   313
				m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   314
				m_exitdir = exitdir;
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   315
				m_tiles_skipped = 0;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   316
				m_is_tunnel = m_is_bridge = m_is_station = false;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   317
				return true;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   318
			}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   319
		}
8961
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   320
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   321
		// single tram bits cause reversing
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   322
		if (GetSingleTramBit(m_old_tile) == ReverseDiagDir(m_exitdir)) {
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   323
			// reverse
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   324
			m_new_tile = m_old_tile;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   325
			m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   326
			m_exitdir = ReverseDiagDir(m_exitdir);
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   327
			m_tiles_skipped = 0;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   328
			m_is_tunnel = m_is_bridge = m_is_station = false;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   329
			return true;
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   330
		}
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   331
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   332
		return false;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   333
	}
3976
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   334
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   335
	/** return true if we successfully reversed at end of road/track */
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   336
	FORCEINLINE bool TryReverse()
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   337
	{
8961
0be32f48afb4 (svn r12035) -Fix [FS#1702]: Teach YAPF where trams can reverse, and where not.
frosch
parents: 8894
diff changeset
   338
		if (IsRoadTT() && !IsTram()) {
3976
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   339
			// if we reached the end of road, we can reverse the RV and continue moving
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   340
			m_exitdir = ReverseDiagDir(m_exitdir);
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   341
			// new tile will be the same as old one
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   342
			m_new_tile = m_old_tile;
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   343
			// set new trackdir bits to all reachable trackdirs
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   344
			QueryNewTileTrackStatus();
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   345
			m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   346
			if (m_new_td_bits != TRACKDIR_BIT_NONE) {
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   347
				// we have some trackdirs reachable after reversal
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   348
				return true;
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   349
			}
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   350
		}
7707
55106bc34d8f (svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents: 7533
diff changeset
   351
		m_err = EC_NO_WAY;
3976
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   352
		return false;
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   353
	}
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   354
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   355
public:
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   356
	/** Helper for pathfinders - get min/max speed on the m_old_tile/m_old_td */
7533
f43efe7a2b23 (svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents: 7179
diff changeset
   357
	int GetSpeedLimit(int *pmin_speed = NULL) const
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   358
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   359
		int min_speed = 0;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   360
		int max_speed = INT_MAX; // no limit
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   361
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   362
		// for now we handle only on-bridge speed limit
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   363
		if (!IsWaterTT() && IsBridgeTile(m_old_tile)) {
8987
782be613237b (svn r12066) -Codechange: Rename GetBridge for the more common GetBridgeSpec
belugas
parents: 8961
diff changeset
   364
			int spd = GetBridgeSpec(GetBridgeType(m_old_tile))->speed;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   365
			if (IsRoadTT()) spd *= 2;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   366
			if (max_speed > spd) max_speed = spd;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   367
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   368
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   369
		// if min speed was requested, return it
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   370
		if (pmin_speed) *pmin_speed = min_speed;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   371
		return max_speed;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   372
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   373
};
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   374
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   375
typedef CFollowTrackT<TRANSPORT_WATER, true > CFollowTrackWater;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   376
typedef CFollowTrackT<TRANSPORT_ROAD , true > CFollowTrackRoad;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   377
typedef CFollowTrackT<TRANSPORT_RAIL , true > CFollowTrackRail;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   378
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   379
typedef CFollowTrackT<TRANSPORT_WATER, false> CFollowTrackWaterNo90;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   380
typedef CFollowTrackT<TRANSPORT_ROAD , false> CFollowTrackRoadNo90;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   381
typedef CFollowTrackT<TRANSPORT_RAIL , false> CFollowTrackRailNo90;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   382
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   383
#endif /* FOLLOW_TRACK_HPP */