src/yapf/follow_track.hpp
author celestar
Wed, 13 Jun 2007 12:05:56 +0000
branchgamebalance
changeset 9912 1ac8aac92385
parent 9895 7bd07f43b0e3
child 6720 35756db7e577
child 7533 f43efe7a2b23
permissions -rw-r--r--
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
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
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    10
/** 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
    11
 *  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
    12
 *  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
    13
template <TransportType Ttr_type_, bool T90deg_turns_allowed_ = true>
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    14
struct CFollowTrackT : public FollowTrack_t
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    15
{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    16
	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
    17
3915
281c7ebd27e0 (svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents: 3912
diff changeset
    18
	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
    19
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    20
		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
    21
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    22
3915
281c7ebd27e0 (svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents: 3912
diff changeset
    23
	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
    24
	{
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6480
diff changeset
    25
		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
    26
		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
    27
		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
    28
		// 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
    29
		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
    30
		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
    31
		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
    32
		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
    33
		m_tiles_skipped = 0;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    34
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    35
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    36
	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
    37
	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
    38
	FORCEINLINE static bool IsRailTT() {return TT() == TRANSPORT_RAIL;}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    39
	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
    40
	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
    41
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    42
	/** 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
    43
	 *  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
    44
	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
    45
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    46
		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
    47
		m_old_td = old_td;
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9895
diff changeset
    48
		assert((GetTileTrackStatus(m_old_tile, TT(), m_veh->u.road.compatible_roadtypes) & TrackdirToTrackdirBits(m_old_td)) != 0);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    49
		m_exitdir = TrackdirToExitdir(m_old_td);
3976
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
    50
		if (EnteredDepot()) 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
    51
		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
    52
		FollowTileExit();
3976
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
    53
		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
    54
		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
    55
		m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    56
		if (!Allow90degTurns())
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    57
			m_new_td_bits &= (TrackdirBits)~(int)TrackdirCrossesTrackdirs(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
    58
		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
    59
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    60
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    61
protected:
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
    62
	/** 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
    63
	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
    64
	{
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    65
		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
    66
		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
    67
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    68
		// extra handling for tunnels in our direction
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    69
		if (IsTunnelTile(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
    70
			DiagDirection tunnel_enterdir = GetTunnelDirection(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
    71
			if (tunnel_enterdir == m_exitdir) {
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    72
				// we are entering the tunnel
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    73
				FindLengthOfTunnelResult flotr = FindLengthOfTunnel(m_old_tile, m_exitdir);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    74
				m_new_tile = flotr.tile;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    75
				m_is_tunnel = true;
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
    76
				m_tiles_skipped = flotr.length - 1;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    77
				return;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    78
			}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    79
			assert(ReverseDiagDir(tunnel_enterdir) == m_exitdir);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    80
		}
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
    81
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    82
		// extra handling for bridge ramp in our direction
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    83
		if (IsBridgeTile(m_old_tile)) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    84
			DiagDirection bridge_enterdir = GetBridgeRampDirection(m_old_tile);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    85
			if (bridge_enterdir == m_exitdir) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    86
				// we are entering the bridge ramp
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    87
				m_new_tile = GetOtherBridgeEnd(m_old_tile);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    88
				uint32 bridge_length = GetBridgeLength(m_old_tile, m_new_tile);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    89
				m_tiles_skipped = bridge_length;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    90
				m_is_bridge = true;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    91
				return;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    92
			}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    93
			assert(ReverseDiagDir(bridge_enterdir) == m_exitdir);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    94
		}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    95
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    96
		// normal or station tile, do one step
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
    97
		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
    98
		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
    99
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   100
		// special handling for stations
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   101
		if (IsRailTT() && IsRailwayStationTile(m_new_tile)) {
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   102
			m_is_station = true;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   103
		} 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
   104
			m_is_station = true;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   105
		} else {
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   106
			m_is_station = false;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   107
		}
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
	/** 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
   111
	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
   112
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   113
		CPerfStart perf(*m_pPerf);
3912
76e7f798cb88 (svn r5013) -Fix: [YAPF] RVs trying to plan route through railway.
KUDr
parents: 3900
diff changeset
   114
		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
   115
			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
   116
		} else {
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9895
diff changeset
   117
			uint32 ts = GetTileTrackStatus(m_new_tile, TT(), m_veh->u.road.compatible_roadtypes);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   118
			m_new_td_bits = (TrackdirBits)(ts & TRACKDIR_BIT_MASK);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   119
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   120
		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
   121
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   122
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   123
	/** 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
   124
	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
   125
	{
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6324
diff changeset
   126
		// 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
   127
		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
   128
			DiagDirection exitdir = GetRoadStopDir(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
   129
			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
   130
				return false;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   131
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   132
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   133
		// 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
   134
		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
   135
			DiagDirection exitdir = GetRoadDepotDirection(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
   136
			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
   137
				return false;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   138
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   139
		return true;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   140
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   141
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   142
	/** 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
   143
	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
   144
	{
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6324
diff changeset
   145
		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
   146
			// 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
   147
			DiagDirection exitdir = GetRoadStopDir(m_new_tile);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   148
			if (ReverseDiagDir(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
   149
				return false;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   150
		}
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
		// 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
   153
		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
   154
			DiagDirection exitdir = GetRoadDepotDirection(m_new_tile);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   155
			if (ReverseDiagDir(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
   156
				return false;
4407
d639dd97eff0 (svn r6160) -Fix [ 1519167 ] Bus trying to service in depot of other company (mart3p)
KUDr
parents: 3977
diff changeset
   157
			// 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
   158
			if (GetTileOwner(m_new_tile) != m_veh->owner) {
d639dd97eff0 (svn r6160) -Fix [ 1519167 ] Bus trying to service in depot of other company (mart3p)
KUDr
parents: 3977
diff changeset
   159
				return false;
d639dd97eff0 (svn r6160) -Fix [ 1519167 ] Bus trying to service in depot of other company (mart3p)
KUDr
parents: 3977
diff changeset
   160
			}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   161
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   162
		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
   163
			DiagDirection exitdir = GetRailDepotDirection(m_new_tile);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   164
			if (ReverseDiagDir(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
   165
				return false;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   166
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   167
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   168
		// 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
   169
		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
   170
			// different owner
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   171
			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
   172
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   173
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   174
		// 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
   175
		if (IsRailTT()) {
6480
767cfeae4dbf (svn r8899) -Fix
tron
parents: 6447
diff changeset
   176
			RailType rail_type = GetTileRailType(m_new_tile);
6077
90883fe77472 (svn r8392) -Fix
tron
parents: 5838
diff changeset
   177
			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
   178
				// incompatible rail type
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   179
				return false;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   180
			}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   181
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   182
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
   183
		// 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
   184
		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
   185
			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
   186
				if (!m_is_tunnel) {
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
   187
					DiagDirection tunnel_enterdir = GetTunnelDirection(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
   188
					if (tunnel_enterdir != m_exitdir) return false;
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
   189
				}
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
   190
			} else if (IsBridge(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
   191
				if (!m_is_bridge) {
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
   192
					DiagDirection ramp_enderdir = GetBridgeRampDirection(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
   193
					if (ramp_enderdir != m_exitdir) return false;
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
   194
				}
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
   195
			}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   196
		}
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   197
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   198
		// 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
   199
		if (IsRailTT() && m_is_station) {
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   200
			// entered railway station
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   201
			// 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
   202
			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
   203
			// 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
   204
			m_tiles_skipped = length - 1;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   205
			// move to the platform end
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
   206
			TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   207
			diff *= m_tiles_skipped;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   208
			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
   209
			return true;
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   210
		}
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   211
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   212
		return true;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   213
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   214
3976
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   215
	/** return true if we entered depot and reversed inside */
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   216
	FORCEINLINE bool EnteredDepot()
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   217
	{
3976
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   218
		// 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
   219
		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
   220
			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
   221
			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
   222
				// reverse
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   223
				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
   224
				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
   225
				m_exitdir = exitdir;
3931
ca6abd14504a (svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents: 3915
diff changeset
   226
				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
   227
				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
   228
				return true;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   229
			}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   230
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   231
		return false;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   232
	}
3976
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   233
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   234
	/** 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
   235
	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
   236
	{
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   237
		if (IsRoadTT()) {
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   238
			// 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
   239
			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
   240
			// 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
   241
			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
   242
			// 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
   243
			QueryNewTileTrackStatus();
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   244
			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
   245
			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
   246
				// 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
   247
				return true;
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   248
			}
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   249
		}
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   250
		return false;
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   251
	}
b52d2c1acc5c (svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
KUDr
parents: 3933
diff changeset
   252
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   253
public:
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   254
	/** Helper for pathfinders - get min/max speed on the m_old_tile/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
   255
	int GetSpeedLimit(int *pmin_speed = NULL)
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   256
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   257
		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
   258
		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
   259
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   260
		// 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
   261
		if (!IsWaterTT() && IsBridgeTile(m_old_tile)) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   262
			int spd = _bridge[GetBridgeType(m_old_tile)].speed;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
   263
			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
   264
			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
   265
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   266
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   267
		// 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
   268
		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
   269
		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
   270
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   271
};
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   272
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   273
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
   274
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
   275
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
   276
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   277
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
   278
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
   279
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
   280
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   281
#endif /* FOLLOW_TRACK_HPP */