yapf/yapf_destrail.hpp
author celestar
Fri, 29 Dec 2006 10:13:35 +0000
branchcustombridgeheads
changeset 5592 fd60d4ecc921
parent 4549 60410aa1aa88
permissions -rw-r--r--
(svn r7608) [cbh] - Merge with trunk r7593:7607 because I need 7607 here
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
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     3
#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
     4
#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
     5
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     6
class CYapfDestinationRailBase
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
protected:
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     9
	RailTypeMask m_compatible_railtypes;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    10
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    11
public:
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    12
	void SetDestination(Vehicle* v)
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    13
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    14
		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
    15
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    16
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    17
	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
    18
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    19
		return HASBIT(m_compatible_railtypes, rt);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    20
	}
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
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    23
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
    24
class CYapfDestinationAnyDepotRailT
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    25
	: public CYapfDestinationRailBase
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    26
{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    27
public:
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    28
	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
    29
	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
    30
	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
    31
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    32
	/// 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
    33
	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
    34
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    35
	/// 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
    36
	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
    37
	{
3930
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    38
		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
    39
	}
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    40
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    41
	/// 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
    42
	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
    43
	{
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
    44
		bool bDest = IsTileDepotType(tile, TRANSPORT_RAIL);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    45
		return bDest;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    46
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    47
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    48
	/** 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
    49
	 *  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
    50
	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
    51
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    52
		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
    53
		return true;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    54
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    55
};
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    56
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    57
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
    58
class CYapfDestinationTileOrStationRailT
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    59
	: public CYapfDestinationRailBase
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
public:
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    62
	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
    63
	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
    64
	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
    65
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    66
protected:
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    67
	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
    68
	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
    69
	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
    70
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    71
	/// 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
    72
	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
    73
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    74
	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
    75
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    76
		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
    77
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    78
		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
    79
		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
    80
		// 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
    81
		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
    82
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    83
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    84
public:
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    85
	void SetDestination(Vehicle* v)
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    86
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    87
		if (v->current_order.type == OT_GOTO_STATION) {
4527
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4389
diff changeset
    88
			m_destTile = CalcStationCenterTile(v->current_order.dest);
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4389
diff changeset
    89
			m_dest_station_id = v->current_order.dest;
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    90
			m_destTrackdirs = INVALID_TRACKDIR_BIT;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    91
		} else {
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    92
			m_destTile = v->dest_tile;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    93
			m_dest_station_id = INVALID_STATION;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    94
			m_destTrackdirs = (TrackdirBits)(GetTileTrackStatus(v->dest_tile, TRANSPORT_RAIL) & 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
    95
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    96
		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
    97
	}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    98
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
    99
	/// 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
   100
	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
   101
	{
3930
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   102
		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
   103
	}
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   104
635b28d85743 (svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents: 3914
diff changeset
   105
	/// 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
   106
	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
   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
		bool bDest;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   109
		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
   110
			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
   111
				&& (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
   112
				&& (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
   113
		} 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
   114
			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
   115
				&& ((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
   116
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   117
		return bDest;
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
3914
f5118020cd84 (svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents: 3900
diff changeset
   120
	/** 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
   121
	 *  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
   122
	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
   123
	{
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   124
		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
   125
		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
   126
		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
   127
			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
   128
			return true;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   129
		}
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   130
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   131
		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
   132
		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
   133
		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
   134
		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
   135
		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
   136
		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
   137
		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
   138
		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
   139
		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
   140
		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
   141
		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
   142
		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
   143
		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
   144
		return true;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   145
	}
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
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   148
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   149
#endif /* YAPF_DESTRAIL_HPP */