src/yapf/yapf_destrail.hpp
author rubidium
Mon, 02 Jun 2008 06:44:06 +0000
changeset 9439 c4e61c3f1d50
parent 9111 48ce04029fe4
child 9797 3b2e6f55e7d0
permissions -rw-r--r--
(svn r13357) -Codechange: add constness to YAPF.
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     1
/* $Id$ */
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     2
9111
48ce04029fe4 (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: 8961
diff changeset
     3
/** @file yapf_destrail.hpp Determining the destination for rail vehicles. */
6121
2aae24b0881f (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: 5475
diff changeset
     4
3900
2c84ed52709d (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
2c84ed52709d (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
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     7
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     8
class CYapfDestinationRailBase
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     9
{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    10
protected:
8236
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 7928
diff changeset
    11
	RailTypes m_compatible_railtypes;
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    12
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    13
public:
9439
c4e61c3f1d50 (svn r13357) -Codechange: add constness to YAPF.
rubidium
parents: 9111
diff changeset
    14
	void SetDestination(const Vehicle* v)
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    15
	{
2c84ed52709d (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;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    17
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    18
2c84ed52709d (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)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    20
	{
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 6683
diff changeset
    21
		return HasBit(m_compatible_railtypes, rt);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    22
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    23
};
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    24
2c84ed52709d (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>
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    26
class CYapfDestinationAnyDepotRailT
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    27
	: public CYapfDestinationRailBase
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    28
{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    29
public:
3914
6bdd22b93698 (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
2c84ed52709d (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
6bdd22b93698 (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
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    33
3914
6bdd22b93698 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    34
	/// to access inherited path finder
3900
2c84ed52709d (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);}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    36
3914
6bdd22b93698 (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
2c84ed52709d (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)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    39
	{
3930
1c293cf92ab5 (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());
1c293cf92ab5 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    41
	}
1c293cf92ab5 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    42
1c293cf92ab5 (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
1c293cf92ab5 (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)
1c293cf92ab5 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    45
	{
8961
fb0848956387 (svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz
parents: 8954
diff changeset
    46
		bool bDest = IsRailDepotTile(tile);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    47
		return bDest;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    48
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    49
3914
6bdd22b93698 (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
106ed18a7675 (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
2c84ed52709d (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)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    53
	{
2c84ed52709d (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;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    55
		return true;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    56
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    57
};
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    58
2c84ed52709d (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>
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    60
class CYapfDestinationTileOrStationRailT
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    61
	: public CYapfDestinationRailBase
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    62
{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    63
public:
3914
6bdd22b93698 (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
2c84ed52709d (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
6bdd22b93698 (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
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    67
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    68
protected:
2c84ed52709d (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;
2c84ed52709d (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;
2c84ed52709d (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;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    72
3914
6bdd22b93698 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    73
	/// to access inherited path finder
3900
2c84ed52709d (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);}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    75
2c84ed52709d (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)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    77
	{
2c84ed52709d (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);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    79
2c84ed52709d (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;
2c84ed52709d (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;
2c84ed52709d (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
2c84ed52709d (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);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    84
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    85
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    86
public:
9439
c4e61c3f1d50 (svn r13357) -Codechange: add constness to YAPF.
rubidium
parents: 9111
diff changeset
    87
	void SetDestination(const Vehicle* v)
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    88
	{
8836
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8616
diff changeset
    89
		switch (v->current_order.GetType()) {
6548
8a9ea9bb12b0 (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: 6121
diff changeset
    90
			case OT_GOTO_STATION:
8840
332412c2e9c1 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 8836
diff changeset
    91
				m_destTile = CalcStationCenterTile(v->current_order.GetDestination());
332412c2e9c1 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 8836
diff changeset
    92
				m_dest_station_id = v->current_order.GetDestination();
6548
8a9ea9bb12b0 (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: 6121
diff changeset
    93
				m_destTrackdirs = INVALID_TRACKDIR_BIT;
8a9ea9bb12b0 (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: 6121
diff changeset
    94
				break;
8a9ea9bb12b0 (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: 6121
diff changeset
    95
8a9ea9bb12b0 (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: 6121
diff changeset
    96
			case OT_GOTO_WAYPOINT: {
8840
332412c2e9c1 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 8836
diff changeset
    97
				Waypoint *wp = GetWaypoint(v->current_order.GetDestination());
6549
8fca195512a9 (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: 6548
diff changeset
    98
				if (wp == NULL) {
8fca195512a9 (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: 6548
diff changeset
    99
					/* Invalid waypoint in orders! */
8840
332412c2e9c1 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 8836
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);
6549
8fca195512a9 (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: 6548
diff changeset
   101
					break;
8fca195512a9 (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: 6548
diff changeset
   102
				}
6548
8a9ea9bb12b0 (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: 6121
diff changeset
   103
				m_destTile = wp->xy;
6549
8fca195512a9 (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: 6548
diff changeset
   104
				if (m_destTile != v->dest_tile) {
8fca195512a9 (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: 6548
diff changeset
   105
					/* Something is wrong with orders! */
8fca195512a9 (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: 6548
diff changeset
   106
					DEBUG(yapf, 0, "Invalid v->dest_tile == 0x%04X (train %d, player %d)", v->dest_tile, v->unitnumber, (PlayerID)v->owner);
8fca195512a9 (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: 6548
diff changeset
   107
				}
6548
8a9ea9bb12b0 (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: 6121
diff changeset
   108
				m_dest_station_id = INVALID_STATION;
8a9ea9bb12b0 (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: 6121
diff changeset
   109
				m_destTrackdirs = TrackToTrackdirBits(AxisToTrack(GetWaypointAxis(wp->xy)));
8a9ea9bb12b0 (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: 6121
diff changeset
   110
				break;
8a9ea9bb12b0 (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: 6121
diff changeset
   111
			}
8a9ea9bb12b0 (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: 6121
diff changeset
   112
8a9ea9bb12b0 (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: 6121
diff changeset
   113
			default:
8a9ea9bb12b0 (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: 6121
diff changeset
   114
				m_destTile = v->dest_tile;
8a9ea9bb12b0 (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: 6121
diff changeset
   115
				m_dest_station_id = INVALID_STATION;
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8236
diff changeset
   116
				m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_RAIL, 0));
6548
8a9ea9bb12b0 (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: 6121
diff changeset
   117
				break;
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   118
		}
2c84ed52709d (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);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   120
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   121
3914
6bdd22b93698 (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
2c84ed52709d (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)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   124
	{
3930
1c293cf92ab5 (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());
1c293cf92ab5 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   126
	}
1c293cf92ab5 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   127
1c293cf92ab5 (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
1c293cf92ab5 (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)
1c293cf92ab5 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   130
	{
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   131
		bool bDest;
2c84ed52709d (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
1c293cf92ab5 (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)
1c293cf92ab5 (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)
1c293cf92ab5 (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
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   136
		} else {
3930
1c293cf92ab5 (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)
1c293cf92ab5 (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
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   139
		}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   140
		return bDest;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   141
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   142
3914
6bdd22b93698 (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
106ed18a7675 (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
2c84ed52709d (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)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   146
	{
2c84ed52709d (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};
2c84ed52709d (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};
2c84ed52709d (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)) {
2c84ed52709d (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;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   151
			return true;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   152
		}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   153
2c84ed52709d (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();
2c84ed52709d (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());
2c84ed52709d (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];
2c84ed52709d (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];
2c84ed52709d (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);
2c84ed52709d (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);
2c84ed52709d (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);
2c84ed52709d (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);
2c84ed52709d (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);
2c84ed52709d (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);
2c84ed52709d (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);
2c84ed52709d (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;
2c84ed52709d (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);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   167
		return true;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   168
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   169
};
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   170
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   171
2c84ed52709d (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 */