src/yapf/yapf_destrail.hpp
author Tero Marttila <terom@fixme.fi>
Tue, 22 Jul 2008 23:11:26 +0300
changeset 11183 b8c8569d24fd
parent 10806 f3fc164fc538
permissions -rw-r--r--
added support for libcurl to configure
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
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10221
diff changeset
     3
/** @file yapf_destrail.hpp Determining the destination for rail vehicles. */
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: 5726
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  YAPF_DESTRAIL_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  YAPF_DESTRAIL_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
class CYapfDestinationRailBase
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
protected:
8732
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8424
diff changeset
    11
	RailTypes m_compatible_railtypes;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    12
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    13
public:
10806
f3fc164fc538 (svn r13357) -Codechange: add constness to YAPF.
rubidium
parents: 10429
diff changeset
    14
	void SetDestination(const Vehicle* v)
3900
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
		m_compatible_railtypes = v->u.rail.compatible_railtypes;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    17
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    18
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    19
	bool IsCompatibleRailType(RailType rt)
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    20
	{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7179
diff changeset
    21
		return HasBit(m_compatible_railtypes, rt);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    22
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    23
};
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    24
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    25
template <class Types>
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    26
class CYapfDestinationAnyDepotRailT
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    27
	: public CYapfDestinationRailBase
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    28
{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    29
public:
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    30
	typedef typename Types::Tpf Tpf;              ///< the pathfinder class (derived from THIS class)
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    31
	typedef typename Types::NodeList::Titem Node; ///< this will be our node type
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    32
	typedef typename Node::Key Key;               ///< key to hash tables
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    33
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    34
	/// to access inherited path finder
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    35
	Tpf& Yapf() {return *static_cast<Tpf*>(this);}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    36
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    37
	/// Called by YAPF to detect if node ends in the desired destination
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    38
	FORCEINLINE bool PfDetectDestination(Node& n)
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    39
	{
3930
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    40
		return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    41
	}
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    42
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    43
	/// Called by YAPF to detect if node ends in the desired destination
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    44
	FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    45
	{
10221
faef62283f5f (svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz
parents: 10213
diff changeset
    46
		bool bDest = IsRailDepotTile(tile);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    47
		return bDest;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    48
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    49
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    50
	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4527
diff changeset
    51
	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    52
	FORCEINLINE bool PfCalcEstimate(Node& n)
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    53
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    54
		n.m_estimate = n.m_cost;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    55
		return true;
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
};
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    58
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    59
template <class Types>
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    60
class CYapfDestinationTileOrStationRailT
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    61
	: public CYapfDestinationRailBase
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    62
{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    63
public:
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    64
	typedef typename Types::Tpf Tpf;              ///< the pathfinder class (derived from THIS class)
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    65
	typedef typename Types::NodeList::Titem Node; ///< this will be our node type
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    66
	typedef typename Node::Key Key;               ///< key to hash tables
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    67
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    68
protected:
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    69
	TileIndex    m_destTile;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    70
	TrackdirBits m_destTrackdirs;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    71
	StationID    m_dest_station_id;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    72
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    73
	/// to access inherited path finder
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    74
	Tpf& Yapf() {return *static_cast<Tpf*>(this);}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    75
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    76
	static TileIndex CalcStationCenterTile(StationID station)
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    77
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    78
		const Station* st = GetStation(station);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    79
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    80
		uint x = TileX(st->train_tile) + st->trainst_w / 2;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    81
		uint y = TileY(st->train_tile) + st->trainst_h / 2;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    82
		// return the tile of our target coordinates
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    83
		return TileXY(x, y);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    84
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    85
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    86
public:
10806
f3fc164fc538 (svn r13357) -Codechange: add constness to YAPF.
rubidium
parents: 10429
diff changeset
    87
	void SetDestination(const Vehicle* v)
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    88
	{
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9112
diff changeset
    89
		switch (v->current_order.GetType()) {
7044
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
    90
			case OT_GOTO_STATION:
9336
3f75a2c5e0d3 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 9332
diff changeset
    91
				m_destTile = CalcStationCenterTile(v->current_order.GetDestination());
3f75a2c5e0d3 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 9332
diff changeset
    92
				m_dest_station_id = v->current_order.GetDestination();
7044
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
    93
				m_destTrackdirs = INVALID_TRACKDIR_BIT;
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
    94
				break;
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
    95
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
    96
			case OT_GOTO_WAYPOINT: {
9336
3f75a2c5e0d3 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 9332
diff changeset
    97
				Waypoint *wp = GetWaypoint(v->current_order.GetDestination());
7045
8a2c1c2f8948 (svn r9746) -Codechange [YAPF]: added DEBUGs level 0 if the current train order is OT_GOTO_WAYPOINT and waypoint is invalid or v->dest_tile is wrong
KUDr
parents: 7044
diff changeset
    98
				if (wp == NULL) {
8a2c1c2f8948 (svn r9746) -Codechange [YAPF]: added DEBUGs level 0 if the current train order is OT_GOTO_WAYPOINT and waypoint is invalid or v->dest_tile is wrong
KUDr
parents: 7044
diff changeset
    99
					/* Invalid waypoint in orders! */
9336
3f75a2c5e0d3 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 9332
diff changeset
   100
					DEBUG(yapf, 0, "Invalid waypoint in orders == 0x%04X (train %d, player %d)", v->current_order.GetDestination(), v->unitnumber, (PlayerID)v->owner);
7045
8a2c1c2f8948 (svn r9746) -Codechange [YAPF]: added DEBUGs level 0 if the current train order is OT_GOTO_WAYPOINT and waypoint is invalid or v->dest_tile is wrong
KUDr
parents: 7044
diff changeset
   101
					break;
8a2c1c2f8948 (svn r9746) -Codechange [YAPF]: added DEBUGs level 0 if the current train order is OT_GOTO_WAYPOINT and waypoint is invalid or v->dest_tile is wrong
KUDr
parents: 7044
diff changeset
   102
				}
7044
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
   103
				m_destTile = wp->xy;
7045
8a2c1c2f8948 (svn r9746) -Codechange [YAPF]: added DEBUGs level 0 if the current train order is OT_GOTO_WAYPOINT and waypoint is invalid or v->dest_tile is wrong
KUDr
parents: 7044
diff changeset
   104
				if (m_destTile != v->dest_tile) {
8a2c1c2f8948 (svn r9746) -Codechange [YAPF]: added DEBUGs level 0 if the current train order is OT_GOTO_WAYPOINT and waypoint is invalid or v->dest_tile is wrong
KUDr
parents: 7044
diff changeset
   105
					/* Something is wrong with orders! */
8a2c1c2f8948 (svn r9746) -Codechange [YAPF]: added DEBUGs level 0 if the current train order is OT_GOTO_WAYPOINT and waypoint is invalid or v->dest_tile is wrong
KUDr
parents: 7044
diff changeset
   106
					DEBUG(yapf, 0, "Invalid v->dest_tile == 0x%04X (train %d, player %d)", v->dest_tile, v->unitnumber, (PlayerID)v->owner);
8a2c1c2f8948 (svn r9746) -Codechange [YAPF]: added DEBUGs level 0 if the current train order is OT_GOTO_WAYPOINT and waypoint is invalid or v->dest_tile is wrong
KUDr
parents: 7044
diff changeset
   107
				}
7044
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
   108
				m_dest_station_id = INVALID_STATION;
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
   109
				m_destTrackdirs = TrackToTrackdirBits(AxisToTrack(GetWaypointAxis(wp->xy)));
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
   110
				break;
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
   111
			}
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
   112
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
   113
			default:
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
   114
				m_destTile = v->dest_tile;
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
   115
				m_dest_station_id = INVALID_STATION;
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8732
diff changeset
   116
				m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_RAIL, 0));
7044
acc370bd15a0 (svn r9745) -Codechange [YAPF}: if destination is a waypoint then YAPF gets destination tile from that waypoint->xy instead of from v->dest_tile
KUDr
parents: 6447
diff changeset
   117
				break;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   118
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   119
		CYapfDestinationRailBase::SetDestination(v);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   120
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   121
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
   122
	/// Called by YAPF to detect if node ends in the desired destination
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   123
	FORCEINLINE bool PfDetectDestination(Node& n)
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   124
	{
3930
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   125
		return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   126
	}
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   127
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   128
	/// Called by YAPF to detect if node ends in the desired destination
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   129
	FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   130
	{
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   131
		bool bDest;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   132
		if (m_dest_station_id != INVALID_STATION) {
3930
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   133
			bDest = IsRailwayStationTile(tile)
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   134
				&& (GetStationIndex(tile) == m_dest_station_id)
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   135
				&& (GetRailStationTrack(tile) == TrackdirToTrack(td));
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   136
		} else {
3930
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   137
			bDest = (tile == m_destTile)
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   138
				&& ((m_destTrackdirs & TrackdirToTrackdirBits(td)) != TRACKDIR_BIT_NONE);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   139
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   140
		return bDest;
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
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
   143
	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4527
diff changeset
   144
	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   145
	FORCEINLINE bool PfCalcEstimate(Node& n)
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   146
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   147
		static int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   148
		static int dg_dir_to_y_offs[] = {0, 1, 0, -1};
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   149
		if (PfDetectDestination(n)) {
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   150
			n.m_estimate = n.m_cost;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   151
			return true;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   152
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   153
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   154
		TileIndex tile = n.GetLastTile();
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   155
		DiagDirection exitdir = TrackdirToExitdir(n.GetLastTrackdir());
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   156
		int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   157
		int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   158
		int x2 = 2 * TileX(m_destTile);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   159
		int y2 = 2 * TileY(m_destTile);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   160
		int dx = abs(x1 - x2);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   161
		int dy = abs(y1 - y2);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   162
		int dmin = min(dx, dy);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   163
		int dxy = abs(dx - dy);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   164
		int d = dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   165
		n.m_estimate = n.m_cost + d;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   166
		assert(n.m_estimate >= n.m_parent->m_estimate);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   167
		return true;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   168
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   169
};
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   170
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   171
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   172
#endif /* YAPF_DESTRAIL_HPP */