author | translators |
Thu, 18 Dec 2008 18:47:39 +0000 | |
changeset 10437 | 6d64230b9fb9 |
parent 10210 | a542a6d595fc |
permissions | -rw-r--r-- |
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: |
9797
3b2e6f55e7d0
(svn r13939) -Add [YAPP]: Extend YAPF with the possibility to override the railtype info of the vehicle. (michi_cc)
rubidium
parents:
9439
diff
changeset
|
14 |
void SetDestination(const Vehicle *v, bool override_rail_type = false) |
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; |
9797
3b2e6f55e7d0
(svn r13939) -Add [YAPP]: Extend YAPF with the possibility to override the railtype info of the vehicle. (michi_cc)
rubidium
parents:
9439
diff
changeset
|
17 |
if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(v->u.rail.railtype)->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
|
18 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
19 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
20 |
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
|
21 |
{ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
6683
diff
changeset
|
22 |
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
|
23 |
} |
9797
3b2e6f55e7d0
(svn r13939) -Add [YAPP]: Extend YAPF with the possibility to override the railtype info of the vehicle. (michi_cc)
rubidium
parents:
9439
diff
changeset
|
24 |
|
3b2e6f55e7d0
(svn r13939) -Add [YAPP]: Extend YAPF with the possibility to override the railtype info of the vehicle. (michi_cc)
rubidium
parents:
9439
diff
changeset
|
25 |
RailTypes GetCompatibleRailTypes() const |
3b2e6f55e7d0
(svn r13939) -Add [YAPP]: Extend YAPF with the possibility to override the railtype info of the vehicle. (michi_cc)
rubidium
parents:
9439
diff
changeset
|
26 |
{ |
3b2e6f55e7d0
(svn r13939) -Add [YAPP]: Extend YAPF with the possibility to override the railtype info of the vehicle. (michi_cc)
rubidium
parents:
9439
diff
changeset
|
27 |
return m_compatible_railtypes; |
3b2e6f55e7d0
(svn r13939) -Add [YAPP]: Extend YAPF with the possibility to override the railtype info of the vehicle. (michi_cc)
rubidium
parents:
9439
diff
changeset
|
28 |
} |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
29 |
}; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
30 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
31 |
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
|
32 |
class CYapfDestinationAnyDepotRailT |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
33 |
: public CYapfDestinationRailBase |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
34 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
35 |
public: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
40 |
/// 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
|
41 |
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
|
42 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
43 |
/// 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
|
44 |
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
|
45 |
{ |
3930
1c293cf92ab5
(svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents:
3914
diff
changeset
|
46 |
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
|
47 |
} |
1c293cf92ab5
(svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents:
3914
diff
changeset
|
48 |
|
1c293cf92ab5
(svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents:
3914
diff
changeset
|
49 |
/// 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
|
50 |
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
|
51 |
{ |
8961
fb0848956387
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz
parents:
8954
diff
changeset
|
52 |
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
|
53 |
return bDest; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
54 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
55 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
56 |
/** 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
|
57 |
* 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
|
58 |
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
|
59 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
60 |
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
|
61 |
return true; |
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 |
}; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
64 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
65 |
template <class Types> |
9802
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
66 |
class CYapfDestinationAnySafeTileRailT |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
67 |
: public CYapfDestinationRailBase |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
68 |
{ |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
69 |
public: |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
70 |
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
71 |
typedef typename Types::NodeList::Titem Node; ///< this will be our node type |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
72 |
typedef typename Node::Key Key; ///< key to hash tables |
9842 | 73 |
typedef typename Types::TrackFollower TrackFollower; ///< TrackFollower. Need to typedef for gcc 2.95 |
9802
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
74 |
|
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
75 |
/// to access inherited path finder |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
76 |
Tpf& Yapf() {return *static_cast<Tpf*>(this);} |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
77 |
|
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
78 |
/// Called by YAPF to detect if node ends in the desired destination |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
79 |
FORCEINLINE bool PfDetectDestination(Node& n) |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
80 |
{ |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
81 |
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir()); |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
82 |
} |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
83 |
|
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
84 |
/// Called by YAPF to detect if node ends in the desired destination |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
85 |
FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td) |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
86 |
{ |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
87 |
return |
10210
a542a6d595fc
(svn r14428) -Fix [FS#2306]: A 90-degree curve can be a safe waiting position if they are forbidden for trains.
michi_cc
parents:
10207
diff
changeset
|
88 |
IsSafeWaitingPosition(Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns()) && |
a542a6d595fc
(svn r14428) -Fix [FS#2306]: A 90-degree curve can be a safe waiting position if they are forbidden for trains.
michi_cc
parents:
10207
diff
changeset
|
89 |
IsWaitingPositionFree(Yapf().GetVehicle(), tile, td, !TrackFollower::Allow90degTurns()); |
9802
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
90 |
} |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
91 |
|
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
92 |
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
93 |
* adds it to the actual cost from origin and stores the sum to the Node::m_estimate. */ |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
94 |
FORCEINLINE bool PfCalcEstimate(Node& n) |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
95 |
{ |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
96 |
n.m_estimate = n.m_cost; |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
97 |
return true; |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
98 |
} |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
99 |
}; |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
100 |
|
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
101 |
template <class Types> |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
102 |
class CYapfDestinationTileOrStationRailT |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
103 |
: public CYapfDestinationRailBase |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
104 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
105 |
public: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
110 |
protected: |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
115 |
/// 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
|
116 |
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
|
117 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
118 |
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
|
119 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
120 |
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
|
121 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
122 |
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
|
123 |
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
|
124 |
// 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
|
125 |
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
|
126 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
127 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
128 |
public: |
9439 | 129 |
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
|
130 |
{ |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8616
diff
changeset
|
131 |
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
|
132 |
case OT_GOTO_STATION: |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8836
diff
changeset
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
|
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
|
138 |
case OT_GOTO_WAYPOINT: { |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8836
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
/* Invalid waypoint in orders! */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
9842
diff
changeset
|
142 |
DEBUG(yapf, 0, "Invalid waypoint in orders == 0x%04X (train %d, company %d)", v->current_order.GetDestination(), v->unitnumber, (CompanyID)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
|
143 |
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
|
144 |
} |
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
|
145 |
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
|
146 |
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
|
147 |
/* Something is wrong with orders! */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
9842
diff
changeset
|
148 |
DEBUG(yapf, 0, "Invalid v->dest_tile == 0x%04X (train %d, company %d)", v->dest_tile, v->unitnumber, (CompanyID)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
|
149 |
} |
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
|
150 |
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
|
151 |
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
|
152 |
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
|
153 |
} |
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
|
154 |
|
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
|
155 |
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
|
156 |
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
|
157 |
m_dest_station_id = INVALID_STATION; |
8616
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8236
diff
changeset
|
158 |
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
|
159 |
break; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
160 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
161 |
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
|
162 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
163 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
164 |
/// 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
|
165 |
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
|
166 |
{ |
3930
1c293cf92ab5
(svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents:
3914
diff
changeset
|
167 |
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
|
168 |
} |
1c293cf92ab5
(svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents:
3914
diff
changeset
|
169 |
|
1c293cf92ab5
(svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
KUDr
parents:
3914
diff
changeset
|
170 |
/// 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
|
171 |
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
|
172 |
{ |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
173 |
bool bDest; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
174 |
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
|
175 |
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
|
176 |
&& (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
|
177 |
&& (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
|
178 |
} 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
|
179 |
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
|
180 |
&& ((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
|
181 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
182 |
return bDest; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
183 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
184 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
185 |
/** 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
|
186 |
* 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
|
187 |
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
|
188 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
189 |
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
|
190 |
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
|
191 |
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
|
192 |
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
|
193 |
return true; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
194 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
195 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
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
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
return true; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
210 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
211 |
}; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
212 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
213 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
214 |
#endif /* YAPF_DESTRAIL_HPP */ |