author | translators |
Sun, 30 Nov 2008 18:46:32 +0000 | |
changeset 10395 | 6fe57f7c5d8d |
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:
7833
diff
changeset
|
3 |
/** @file yapf_costrail.hpp Cost determination for rails. */ |
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:
6040
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_COSTRAIL_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_COSTRAIL_HPP |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
7 |
|
9799
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
8 |
#include "../pbs.h" |
3900
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 |
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
|
11 |
class CYapfCostRailT |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
12 |
: public CYapfCostBase |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
13 |
, public CostRailSettings |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
14 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
15 |
public: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
16 |
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
|
17 |
typedef typename Types::TrackFollower TrackFollower; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
18 |
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
|
19 |
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
|
20 |
typedef typename Node::CachedData CachedData; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
21 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
22 |
protected: |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
23 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
24 |
/* Structure used inside PfCalcCost() to keep basic tile information. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
25 |
struct TILE { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
26 |
TileIndex tile; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
27 |
Trackdir td; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
28 |
TileType tile_type; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
29 |
RailType rail_type; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
30 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
31 |
TILE() |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
32 |
{ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
33 |
tile = INVALID_TILE; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
34 |
td = INVALID_TRACKDIR; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
35 |
tile_type = MP_VOID; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
36 |
rail_type = INVALID_RAILTYPE; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
37 |
} |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
38 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
39 |
TILE(TileIndex tile, Trackdir td) |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
40 |
{ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
41 |
this->tile = tile; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
42 |
this->td = td; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
43 |
this->tile_type = GetTileType(tile); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
44 |
this->rail_type = GetTileRailType(tile); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
45 |
} |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
46 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
47 |
TILE(const TILE &src) |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
48 |
{ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
49 |
tile = src.tile; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
50 |
td = src.td; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
51 |
tile_type = src.tile_type; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
52 |
rail_type = src.rail_type; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
53 |
} |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
54 |
}; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
55 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
56 |
protected: |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
57 |
int m_max_cost; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
58 |
CBlobT<int> m_sig_look_ahead_costs; |
7099
a1d7e197cb64
(svn r10366) -Codechange [YAPF]: added DEBUG_YAPF_CACHE macro that (when set to 1) allows to track YAPF "cache errors". They are probably responsible for current MP desyncs. (thanks Rubidium for this great idea!).
KUDr
parents:
7040
diff
changeset
|
59 |
bool m_disable_cache; |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
60 |
|
5424
34b624b01ae1
(svn r7628) -Fix: [YAPF] suppress 'Train is lost' message if pathfinding ended on the first two-way red signal due to yapf.rail_firstred_twoway_eol option.
KUDr
parents:
5095
diff
changeset
|
61 |
public: |
34b624b01ae1
(svn r7628) -Fix: [YAPF] suppress 'Train is lost' message if pathfinding ended on the first two-way red signal due to yapf.rail_firstred_twoway_eol option.
KUDr
parents:
5095
diff
changeset
|
62 |
bool m_stopped_on_first_two_way_signal; |
34b624b01ae1
(svn r7628) -Fix: [YAPF] suppress 'Train is lost' message if pathfinding ended on the first two-way red signal due to yapf.rail_firstred_twoway_eol option.
KUDr
parents:
5095
diff
changeset
|
63 |
protected: |
3900
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 |
static const int s_max_segment_cost = 10000; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
66 |
|
5424
34b624b01ae1
(svn r7628) -Fix: [YAPF] suppress 'Train is lost' message if pathfinding ended on the first two-way red signal due to yapf.rail_firstred_twoway_eol option.
KUDr
parents:
5095
diff
changeset
|
67 |
CYapfCostRailT() |
34b624b01ae1
(svn r7628) -Fix: [YAPF] suppress 'Train is lost' message if pathfinding ended on the first two-way red signal due to yapf.rail_firstred_twoway_eol option.
KUDr
parents:
5095
diff
changeset
|
68 |
: m_max_cost(0) |
7099
a1d7e197cb64
(svn r10366) -Codechange [YAPF]: added DEBUG_YAPF_CACHE macro that (when set to 1) allows to track YAPF "cache errors". They are probably responsible for current MP desyncs. (thanks Rubidium for this great idea!).
KUDr
parents:
7040
diff
changeset
|
69 |
, m_disable_cache(false) |
5424
34b624b01ae1
(svn r7628) -Fix: [YAPF] suppress 'Train is lost' message if pathfinding ended on the first two-way red signal due to yapf.rail_firstred_twoway_eol option.
KUDr
parents:
5095
diff
changeset
|
70 |
, m_stopped_on_first_two_way_signal(false) |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
71 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
72 |
// pre-compute look-ahead penalties into array |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
73 |
int p0 = Yapf().PfGetSettings().rail_look_ahead_signal_p0; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
74 |
int p1 = Yapf().PfGetSettings().rail_look_ahead_signal_p1; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
75 |
int p2 = Yapf().PfGetSettings().rail_look_ahead_signal_p2; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
76 |
int *pen = m_sig_look_ahead_costs.GrowSizeNC(Yapf().PfGetSettings().rail_look_ahead_max_signals); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
77 |
for (uint i = 0; i < Yapf().PfGetSettings().rail_look_ahead_max_signals; i++) |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
78 |
pen[i] = p0 + i * (p1 + i * p2); |
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 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
81 |
/// 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
|
82 |
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
|
83 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
84 |
public: |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
85 |
FORCEINLINE int SlopeCost(TileIndex tile, Trackdir td) |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
86 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
87 |
CPerfStart perf_cost(Yapf().m_perf_slope_cost); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
88 |
if (!stSlopeCost(tile, td)) return 0; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
89 |
return Yapf().PfGetSettings().rail_slope_penalty; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
90 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
91 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
92 |
FORCEINLINE int CurveCost(Trackdir td1, Trackdir td2) |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
93 |
{ |
7149
1be298a5cc08
(svn r10423) -Fix [YAPF, r10301]: INVALID_TRACKDIR causing buffer overrun leading to desync in MP game (many thanks Rubidium)
KUDr
parents:
7121
diff
changeset
|
94 |
assert(IsValidTrackdir(td1)); |
1be298a5cc08
(svn r10423) -Fix [YAPF, r10301]: INVALID_TRACKDIR causing buffer overrun leading to desync in MP game (many thanks Rubidium)
KUDr
parents:
7121
diff
changeset
|
95 |
assert(IsValidTrackdir(td2)); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
96 |
int cost = 0; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
97 |
if (TrackFollower::Allow90degTurns() |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
98 |
&& ((TrackdirToTrackdirBits(td2) & (TrackdirBits)TrackdirCrossesTrackdirs(td1)) != 0)) { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
99 |
// 90-deg curve penalty |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
100 |
cost += Yapf().PfGetSettings().rail_curve90_penalty; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
101 |
} else if (td2 != NextTrackdir(td1)) { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
102 |
// 45-deg curve penalty |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
103 |
cost += Yapf().PfGetSettings().rail_curve45_penalty; |
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 |
return cost; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
106 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
107 |
|
9800
a8cbb9206502
(svn r13942) -Codechange [YAPP]: Add a penalty for double slips to YAPF. (michi_cc)
rubidium
parents:
9799
diff
changeset
|
108 |
FORCEINLINE int SwitchCost(TileIndex tile1, TileIndex tile2, DiagDirection exitdir) |
a8cbb9206502
(svn r13942) -Codechange [YAPP]: Add a penalty for double slips to YAPF. (michi_cc)
rubidium
parents:
9799
diff
changeset
|
109 |
{ |
a8cbb9206502
(svn r13942) -Codechange [YAPP]: Add a penalty for double slips to YAPF. (michi_cc)
rubidium
parents:
9799
diff
changeset
|
110 |
if (IsTileType(tile1, MP_RAILWAY) && IsTileType(tile2, MP_RAILWAY)) { |
a8cbb9206502
(svn r13942) -Codechange [YAPP]: Add a penalty for double slips to YAPF. (michi_cc)
rubidium
parents:
9799
diff
changeset
|
111 |
bool t1 = KillFirstBit(GetTrackBits(tile1) & DiagdirReachesTracks(ReverseDiagDir(exitdir))) != TRACK_BIT_NONE; |
a8cbb9206502
(svn r13942) -Codechange [YAPP]: Add a penalty for double slips to YAPF. (michi_cc)
rubidium
parents:
9799
diff
changeset
|
112 |
bool t2 = KillFirstBit(GetTrackBits(tile2) & DiagdirReachesTracks(exitdir)) != TRACK_BIT_NONE; |
a8cbb9206502
(svn r13942) -Codechange [YAPP]: Add a penalty for double slips to YAPF. (michi_cc)
rubidium
parents:
9799
diff
changeset
|
113 |
if (t1 && t2) return Yapf().PfGetSettings().rail_doubleslip_penalty; |
a8cbb9206502
(svn r13942) -Codechange [YAPP]: Add a penalty for double slips to YAPF. (michi_cc)
rubidium
parents:
9799
diff
changeset
|
114 |
} |
a8cbb9206502
(svn r13942) -Codechange [YAPP]: Add a penalty for double slips to YAPF. (michi_cc)
rubidium
parents:
9799
diff
changeset
|
115 |
return 0; |
a8cbb9206502
(svn r13942) -Codechange [YAPP]: Add a penalty for double slips to YAPF. (michi_cc)
rubidium
parents:
9799
diff
changeset
|
116 |
} |
a8cbb9206502
(svn r13942) -Codechange [YAPP]: Add a penalty for double slips to YAPF. (michi_cc)
rubidium
parents:
9799
diff
changeset
|
117 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
118 |
/** Return one tile cost (base cost + level crossing penalty). */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
119 |
FORCEINLINE int OneTileCost(TileIndex& tile, Trackdir trackdir) |
3900
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 |
int cost = 0; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
122 |
// set base cost |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
123 |
if (IsDiagonalTrackdir(trackdir)) { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
124 |
cost += YAPF_TILE_LENGTH; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
125 |
switch (GetTileType(tile)) { |
7370
41adc721b1fa
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7213
diff
changeset
|
126 |
case MP_ROAD: |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
127 |
/* Increase the cost for level crossings */ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
128 |
if (IsLevelCrossing(tile)) |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
129 |
cost += Yapf().PfGetSettings().rail_crossing_penalty; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
130 |
break; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
131 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
132 |
default: |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
133 |
break; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
134 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
135 |
} else { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
136 |
// non-diagonal trackdir |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
137 |
cost = YAPF_TILE_CORNER_LENGTH; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
138 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
139 |
return cost; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
140 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
141 |
|
9873
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
142 |
/** Check for a reserved station platform. */ |
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
143 |
FORCEINLINE bool IsAnyStationTileReserved(TileIndex tile, Trackdir trackdir, int skipped) |
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
144 |
{ |
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
145 |
TileIndexDiff diff = TileOffsByDiagDir(TrackdirToExitdir(ReverseTrackdir(trackdir))); |
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
146 |
for (; skipped >= 0; skipped--, tile += diff) { |
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
147 |
if (GetRailwayStationReservation(tile)) return true; |
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
148 |
} |
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
149 |
return false; |
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
150 |
} |
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
151 |
|
9799
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
152 |
/** The cost for reserved tiles, including skipped ones. */ |
9873
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
153 |
FORCEINLINE int ReservationCost(Node& n, TileIndex tile, Trackdir trackdir, int skipped) |
9799
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
154 |
{ |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
155 |
if (n.m_num_signals_passed >= m_sig_look_ahead_costs.Size() / 2) return 0; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
156 |
|
9873
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
157 |
if (IsRailwayStationTile(tile) && IsAnyStationTileReserved(tile, trackdir, skipped)) { |
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
158 |
return Yapf().PfGetSettings().rail_pbs_station_penalty * (skipped + 1); |
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
159 |
} else if (TrackOverlapsTracks(GetReservedTrackbits(tile), TrackdirToTrack(trackdir))) { |
c09e1a4de035
(svn r14019) -Fix [FS#2205]: game crash after order skip while waiting for free path (michi_cc).
rubidium
parents:
9802
diff
changeset
|
160 |
int cost = Yapf().PfGetSettings().rail_pbs_cross_penalty; |
9799
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
161 |
if (!IsDiagonalTrackdir(trackdir)) cost = (cost * YAPF_TILE_CORNER_LENGTH) / YAPF_TILE_LENGTH; |
9877
202f912c4610
(svn r14024) -Fix (r14019) [YAPP]: YAPF also skips tunnels and bridges. Honor that in penalty calculations. (michi_cc)
smatz
parents:
9876
diff
changeset
|
162 |
return cost * (skipped + 1); |
9799
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
163 |
} |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
164 |
return 0; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
165 |
} |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
166 |
|
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
167 |
int SignalCost(Node& n, TileIndex tile, Trackdir trackdir) |
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 |
int cost = 0; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
170 |
// if there is one-way signal in the opposite direction, then it is not our way |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
171 |
CPerfStart perf_cost(Yapf().m_perf_other_cost); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
172 |
if (IsTileType(tile, MP_RAILWAY)) { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
173 |
bool has_signal_against = HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir)); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
174 |
bool has_signal_along = HasSignalOnTrackdir(tile, trackdir); |
9792
e6efb2eb4851
(svn r13934) -Codechange [YAPP]: Handle through signals in the pathfinders. (michi_cc)
rubidium
parents:
9439
diff
changeset
|
175 |
if (has_signal_against && !has_signal_along && IsOnewaySignal(tile, TrackdirToTrack(trackdir))) { |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
176 |
// one-way signal in opposite direction |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
177 |
n.m_segment->m_end_segment_reason |= ESRB_DEAD_END; |
9799
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
178 |
} else { |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
179 |
if (has_signal_along) { |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
180 |
SignalState sig_state = GetSignalStateByTrackdir(tile, trackdir); |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
181 |
// cache the look-ahead polynomial constant only if we didn't pass more signals than the look-ahead limit is |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
182 |
int look_ahead_cost = (n.m_num_signals_passed < m_sig_look_ahead_costs.Size()) ? m_sig_look_ahead_costs.Data()[n.m_num_signals_passed] : 0; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
183 |
if (sig_state != SIGNAL_STATE_RED) { |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
184 |
// green signal |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
185 |
n.flags_u.flags_s.m_last_signal_was_red = false; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
186 |
// negative look-ahead red-signal penalties would cause problems later, so use them as positive penalties for green signal |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
187 |
if (look_ahead_cost < 0) { |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
188 |
// add its negation to the cost |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
189 |
cost -= look_ahead_cost; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
190 |
} |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
191 |
} else { |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
192 |
SignalType sig_type = GetSignalType(tile, TrackdirToTrack(trackdir)); |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
193 |
// we have a red signal in our direction |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
194 |
// was it first signal which is two-way? |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
195 |
if (!IsPbsSignal(sig_type) && Yapf().TreatFirstRedTwoWaySignalAsEOL() && n.flags_u.flags_s.m_choice_seen && has_signal_against && n.m_num_signals_passed == 0) { |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
196 |
// yes, the first signal is two-way red signal => DEAD END |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
197 |
n.m_segment->m_end_segment_reason |= ESRB_DEAD_END; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
198 |
Yapf().m_stopped_on_first_two_way_signal = true; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
199 |
return -1; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
200 |
} |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
201 |
n.m_last_red_signal_type = sig_type; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
202 |
n.flags_u.flags_s.m_last_signal_was_red = true; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
203 |
|
9799
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
204 |
// look-ahead signal penalty |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
205 |
if (!IsPbsSignal(sig_type) && look_ahead_cost > 0) { |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
206 |
// add the look ahead penalty only if it is positive |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
207 |
cost += look_ahead_cost; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
208 |
} |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
209 |
|
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
210 |
// special signal penalties |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
211 |
if (n.m_num_signals_passed == 0) { |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
212 |
switch (sig_type) { |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
213 |
case SIGTYPE_COMBO: |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
214 |
case SIGTYPE_EXIT: cost += Yapf().PfGetSettings().rail_firstred_exit_penalty; break; // first signal is red pre-signal-exit |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
215 |
case SIGTYPE_NORMAL: |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
216 |
case SIGTYPE_ENTRY: cost += Yapf().PfGetSettings().rail_firstred_penalty; break; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
217 |
default: break; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
218 |
}; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
219 |
} |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
220 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
221 |
|
9799
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
222 |
n.m_num_signals_passed++; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
223 |
n.m_segment->m_last_signal_tile = tile; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
224 |
n.m_segment->m_last_signal_td = trackdir; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
225 |
} |
9799
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
226 |
|
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
227 |
if (has_signal_against && IsPbsSignal(GetSignalType(tile, TrackdirToTrack(trackdir)))) { |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
228 |
cost += n.m_num_signals_passed < Yapf().PfGetSettings().rail_look_ahead_max_signals ? Yapf().PfGetSettings().rail_pbs_signal_back_penalty : 0; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
229 |
} |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
230 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
231 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
232 |
return cost; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
233 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
234 |
|
3931
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
235 |
FORCEINLINE int PlatformLengthPenalty(int platform_length) |
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
236 |
{ |
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
237 |
int cost = 0; |
9439 | 238 |
const Vehicle *v = Yapf().GetVehicle(); |
3931
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
239 |
assert(v != NULL); |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6154
diff
changeset
|
240 |
assert(v->type == VEH_TRAIN); |
3931
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
241 |
assert(v->u.rail.cached_total_length != 0); |
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
242 |
int needed_platform_length = (v->u.rail.cached_total_length + TILE_SIZE - 1) / TILE_SIZE; |
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
243 |
if (platform_length > needed_platform_length) { |
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
244 |
// apply penalty for longer platform than needed |
3932
dfe10fa5ce4f
(svn r5067) -Codechange: [YAPF] Platform selection feature now applies penalty per platform instead of per tile (should give better results)
KUDr
parents:
3931
diff
changeset
|
245 |
cost += Yapf().PfGetSettings().rail_longer_platform_penalty; |
dfe10fa5ce4f
(svn r5067) -Codechange: [YAPF] Platform selection feature now applies penalty per platform instead of per tile (should give better results)
KUDr
parents:
3931
diff
changeset
|
246 |
} else if (needed_platform_length > platform_length) { |
3931
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
247 |
// apply penalty for shorter platform than needed |
3932
dfe10fa5ce4f
(svn r5067) -Codechange: [YAPF] Platform selection feature now applies penalty per platform instead of per tile (should give better results)
KUDr
parents:
3931
diff
changeset
|
248 |
cost += Yapf().PfGetSettings().rail_shorter_platform_penalty; |
3931
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
249 |
} |
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
250 |
return cost; |
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
251 |
} |
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
252 |
|
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
253 |
public: |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
254 |
FORCEINLINE void SetMaxCost(int max_cost) {m_max_cost = max_cost;} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
255 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
256 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
257 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
258 |
/** Called by YAPF to calculate the cost from the origin to the given node. |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
3979
diff
changeset
|
259 |
* Calculates only the cost of given node, adds it to the parent node cost |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
3979
diff
changeset
|
260 |
* and stores the result into Node::m_cost member */ |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
261 |
FORCEINLINE bool PfCalcCost(Node &n, const TrackFollower *tf) |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
262 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
263 |
assert(!n.flags_u.flags_s.m_targed_seen); |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
264 |
assert(tf->m_new_tile == n.m_key.m_tile); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
265 |
assert((TrackdirToTrackdirBits(n.m_key.m_td) & tf->m_new_td_bits) != TRACKDIR_BIT_NONE); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
266 |
|
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
267 |
CPerfStart perf_cost(Yapf().m_perf_cost); |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
268 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
269 |
/* Does the node have some parent node? */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
270 |
bool has_parent = (n.m_parent != NULL); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
271 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
272 |
/* Do we already have a cached segment? */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
273 |
CachedData &segment = *n.m_segment; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
274 |
bool is_cached_segment = (segment.m_cost >= 0); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
275 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
276 |
int parent_cost = has_parent ? n.m_parent->m_cost : 0; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
277 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
278 |
/* Each node cost contains 2 or 3 main components: |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
279 |
* 1. Transition cost - cost of the move from previous node (tile): |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
280 |
* - curve cost (or zero for straight move) |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
281 |
* 2. Tile cost: |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
282 |
* - base tile cost |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
283 |
* - YAPF_TILE_LENGTH for diagonal tiles |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
284 |
* - YAPF_TILE_CORNER_LENGTH for non-diagonal tiles |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
285 |
* - tile penalties |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
286 |
* - tile slope penalty (upward slopes) |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
287 |
* - red signal penalty |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
288 |
* - level crossing penalty |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
289 |
* - speed-limit penalty (bridges) |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
290 |
* - station platform penalty |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
291 |
* - penalty for reversing in the depot |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
292 |
* - etc. |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
293 |
* 3. Extra cost (applies to the last node only) |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
294 |
* - last red signal penalty |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
295 |
* - penalty for too long or too short platform on the destination station |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
296 |
*/ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
297 |
int transition_cost = 0; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
298 |
int extra_cost = 0; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
299 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
300 |
/* Segment: one or more tiles connected by contiguous tracks of the same type. |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
301 |
* Each segment cost includes 'Tile cost' for all its tiles (including the first |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
302 |
* and last), and the 'Transition cost' between its tiles. The first transition |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
303 |
* cost of segment entry (move from the 'parent' node) is not included! |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
304 |
*/ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
305 |
int segment_entry_cost = 0; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
306 |
int segment_cost = 0; |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
307 |
|
9439 | 308 |
const Vehicle *v = Yapf().GetVehicle(); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
309 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
310 |
// start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
311 |
TILE cur(n.m_key.m_tile, n.m_key.m_td); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
312 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
313 |
// the previous tile will be needed for transition cost calculations |
7149
1be298a5cc08
(svn r10423) -Fix [YAPF, r10301]: INVALID_TRACKDIR causing buffer overrun leading to desync in MP game (many thanks Rubidium)
KUDr
parents:
7121
diff
changeset
|
314 |
TILE prev = !has_parent ? TILE() : TILE(n.m_parent->GetLastTile(), n.m_parent->GetLastTrackdir()); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
315 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
316 |
EndSegmentReasonBits end_segment_reason = ESRB_NONE; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
317 |
|
9797
3b2e6f55e7d0
(svn r13939) -Add [YAPP]: Extend YAPF with the possibility to override the railtype info of the vehicle. (michi_cc)
rubidium
parents:
9792
diff
changeset
|
318 |
TrackFollower tf_local(v, Yapf().GetCompatibleRailTypes(), &Yapf().m_perf_ts_cost); |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
319 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
320 |
if (!has_parent) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
321 |
/* We will jump to the middle of the cost calculator assuming that segment cache is not used. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
322 |
assert(!is_cached_segment); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
323 |
/* Skip the first transition cost calculation. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
324 |
goto no_entry_cost; |
6132
8b4edf37c5ff
(svn r8869) [YAPF] -Fix: Large Train Stations/Trains makes OpenTTD crash (Jigsaw_Psyche)
KUDr
parents:
6130
diff
changeset
|
325 |
} |
8b4edf37c5ff
(svn r8869) [YAPF] -Fix: Large Train Stations/Trains makes OpenTTD crash (Jigsaw_Psyche)
KUDr
parents:
6130
diff
changeset
|
326 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
327 |
for (;;) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
328 |
/* Transition cost (cost of the move from previous tile) */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
329 |
transition_cost = Yapf().CurveCost(prev.td, cur.td); |
9800
a8cbb9206502
(svn r13942) -Codechange [YAPP]: Add a penalty for double slips to YAPF. (michi_cc)
rubidium
parents:
9799
diff
changeset
|
330 |
transition_cost += Yapf().SwitchCost(prev.tile, cur.tile, TrackdirToExitdir(prev.td)); |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
331 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
332 |
/* First transition cost counts against segment entry cost, other transitions |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
333 |
* inside segment will come to segment cost (and will be cached) */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
334 |
if (segment_cost == 0) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
335 |
/* We just entered the loop. First transition cost goes to segment entry cost)*/ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
336 |
segment_entry_cost = transition_cost; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
337 |
transition_cost = 0; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
338 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
339 |
/* It is the right time now to look if we can reuse the cached segment cost. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
340 |
if (is_cached_segment) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
341 |
/* Yes, we already know the segment cost. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
342 |
segment_cost = segment.m_cost; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
343 |
/* We know also the reason why the segment ends. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
344 |
end_segment_reason = segment.m_end_segment_reason; |
7121
ac2b3710f262
(svn r10394) -Fix [YAPF]: MP desync caused by incorrect last-red-signal penalties applied when cached segment was reused. Players that connected more recently (didn't have these segments cached yet) calculated those penalties correctly. This caused different YAPF results.
KUDr
parents:
7099
diff
changeset
|
345 |
/* We will need also some information about the last signal (if it was red). */ |
ac2b3710f262
(svn r10394) -Fix [YAPF]: MP desync caused by incorrect last-red-signal penalties applied when cached segment was reused. Players that connected more recently (didn't have these segments cached yet) calculated those penalties correctly. This caused different YAPF results.
KUDr
parents:
7099
diff
changeset
|
346 |
if (segment.m_last_signal_tile != INVALID_TILE) { |
ac2b3710f262
(svn r10394) -Fix [YAPF]: MP desync caused by incorrect last-red-signal penalties applied when cached segment was reused. Players that connected more recently (didn't have these segments cached yet) calculated those penalties correctly. This caused different YAPF results.
KUDr
parents:
7099
diff
changeset
|
347 |
assert(HasSignalOnTrackdir(segment.m_last_signal_tile, segment.m_last_signal_td)); |
ac2b3710f262
(svn r10394) -Fix [YAPF]: MP desync caused by incorrect last-red-signal penalties applied when cached segment was reused. Players that connected more recently (didn't have these segments cached yet) calculated those penalties correctly. This caused different YAPF results.
KUDr
parents:
7099
diff
changeset
|
348 |
SignalState sig_state = GetSignalStateByTrackdir(segment.m_last_signal_tile, segment.m_last_signal_td); |
ac2b3710f262
(svn r10394) -Fix [YAPF]: MP desync caused by incorrect last-red-signal penalties applied when cached segment was reused. Players that connected more recently (didn't have these segments cached yet) calculated those penalties correctly. This caused different YAPF results.
KUDr
parents:
7099
diff
changeset
|
349 |
bool is_red = (sig_state == SIGNAL_STATE_RED); |
ac2b3710f262
(svn r10394) -Fix [YAPF]: MP desync caused by incorrect last-red-signal penalties applied when cached segment was reused. Players that connected more recently (didn't have these segments cached yet) calculated those penalties correctly. This caused different YAPF results.
KUDr
parents:
7099
diff
changeset
|
350 |
n.flags_u.flags_s.m_last_signal_was_red = is_red; |
ac2b3710f262
(svn r10394) -Fix [YAPF]: MP desync caused by incorrect last-red-signal penalties applied when cached segment was reused. Players that connected more recently (didn't have these segments cached yet) calculated those penalties correctly. This caused different YAPF results.
KUDr
parents:
7099
diff
changeset
|
351 |
if (is_red) { |
ac2b3710f262
(svn r10394) -Fix [YAPF]: MP desync caused by incorrect last-red-signal penalties applied when cached segment was reused. Players that connected more recently (didn't have these segments cached yet) calculated those penalties correctly. This caused different YAPF results.
KUDr
parents:
7099
diff
changeset
|
352 |
n.m_last_red_signal_type = GetSignalType(segment.m_last_signal_tile, TrackdirToTrack(segment.m_last_signal_td)); |
ac2b3710f262
(svn r10394) -Fix [YAPF]: MP desync caused by incorrect last-red-signal penalties applied when cached segment was reused. Players that connected more recently (didn't have these segments cached yet) calculated those penalties correctly. This caused different YAPF results.
KUDr
parents:
7099
diff
changeset
|
353 |
} |
ac2b3710f262
(svn r10394) -Fix [YAPF]: MP desync caused by incorrect last-red-signal penalties applied when cached segment was reused. Players that connected more recently (didn't have these segments cached yet) calculated those penalties correctly. This caused different YAPF results.
KUDr
parents:
7099
diff
changeset
|
354 |
} |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
355 |
/* No further calculation needed. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
356 |
cur = TILE(n.GetLastTile(), n.GetLastTrackdir()); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
357 |
break; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
358 |
} |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
359 |
} else { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
360 |
/* Other than first transition cost count as the regular segment cost. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
361 |
segment_cost += transition_cost; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
362 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
363 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
364 |
no_entry_cost: // jump here at the beginning if the node has no parent (it is the first node) |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
365 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
366 |
/* All other tile costs will be calculated here. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
367 |
segment_cost += Yapf().OneTileCost(cur.tile, cur.td); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
368 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
369 |
/* If we skipped some tunnel/bridge/station tiles, add their base cost */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
370 |
segment_cost += YAPF_TILE_LENGTH * tf->m_tiles_skipped; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
371 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
372 |
/* Slope cost. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
373 |
segment_cost += Yapf().SlopeCost(cur.tile, cur.td); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
374 |
|
9799
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
375 |
/* Reserved tiles. */ |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
376 |
segment_cost += Yapf().ReservationCost(n, cur.tile, cur.td, tf->m_tiles_skipped); |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9797
diff
changeset
|
377 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
378 |
/* Signal cost (routine can modify segment data). */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
379 |
segment_cost += Yapf().SignalCost(n, cur.tile, cur.td); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
380 |
end_segment_reason = segment.m_end_segment_reason; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
381 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
382 |
/* Tests for 'potential target' reasons to close the segment. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
383 |
if (cur.tile == prev.tile) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
384 |
/* Penalty for reversing in a depot. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
385 |
assert(IsRailDepot(cur.tile)); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
386 |
segment_cost += Yapf().PfGetSettings().rail_depot_reverse_penalty; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
387 |
/* We will end in this pass (depot is possible target) */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
388 |
end_segment_reason |= ESRB_DEPOT; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
389 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
390 |
} else if (tf->m_is_station) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
391 |
/* Station penalties. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
392 |
uint platform_length = tf->m_tiles_skipped + 1; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
393 |
/* We don't know yet if the station is our target or not. Act like |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
394 |
* if it is pass-through station (not our destination). */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
395 |
segment_cost += Yapf().PfGetSettings().rail_station_penalty * platform_length; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
396 |
/* We will end in this pass (station is possible target) */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
397 |
end_segment_reason |= ESRB_STATION; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
398 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
399 |
} else if (cur.tile_type == MP_RAILWAY && IsRailWaypoint(cur.tile)) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
400 |
/* Waypoint is also a good reason to finish. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
401 |
end_segment_reason |= ESRB_WAYPOINT; |
9899
03a2d32a2c05
(svn r14048) -Fix (r14019) [FS#2222]: Redo the check for reserved tracks properly this time. (michi_cc)
rubidium
parents:
9877
diff
changeset
|
402 |
} else if (TrackFollower::DoTrackMasking() && cur.tile_type == MP_RAILWAY) { |
9802
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9801
diff
changeset
|
403 |
/* Searching for a safe tile? */ |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9801
diff
changeset
|
404 |
if (HasSignalOnTrackdir(cur.tile, cur.td) && !IsPbsSignal(GetSignalType(cur.tile, TrackdirToTrack(cur.td)))) { |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9801
diff
changeset
|
405 |
end_segment_reason |= ESRB_SAFE_TILE; |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9801
diff
changeset
|
406 |
} |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
407 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
408 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
409 |
/* Apply min/max speed penalties only when inside the look-ahead radius. Otherwise |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
410 |
* it would cause desync in MP. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
411 |
if (n.m_num_signals_passed < m_sig_look_ahead_costs.Size()) |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
412 |
{ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
413 |
int min_speed = 0; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
414 |
int max_speed = tf->GetSpeedLimit(&min_speed); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
415 |
if (max_speed < v->max_speed) |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
416 |
extra_cost += YAPF_TILE_LENGTH * (v->max_speed - max_speed) * (4 + tf->m_tiles_skipped) / v->max_speed; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
417 |
if (min_speed > v->max_speed) |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
418 |
extra_cost += YAPF_TILE_LENGTH * (min_speed - v->max_speed); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
419 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
420 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
421 |
/* Finish if we already exceeded the maximum path cost (i.e. when |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
422 |
* searching for the nearest depot). */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
423 |
if (m_max_cost > 0 && (parent_cost + segment_entry_cost + segment_cost) > m_max_cost) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
424 |
end_segment_reason |= ESRB_PATH_TOO_LONG; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
425 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
426 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
427 |
/* Move to the next tile/trackdir. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
428 |
tf = &tf_local; |
9797
3b2e6f55e7d0
(svn r13939) -Add [YAPP]: Extend YAPF with the possibility to override the railtype info of the vehicle. (michi_cc)
rubidium
parents:
9792
diff
changeset
|
429 |
tf_local.Init(v, Yapf().GetCompatibleRailTypes(), &Yapf().m_perf_ts_cost); |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
430 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
431 |
if (!tf_local.Follow(cur.tile, cur.td)) { |
7211
ebabbe55f70e
(svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
KUDr
parents:
7149
diff
changeset
|
432 |
assert(tf_local.m_err != TrackFollower::EC_NONE); |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
433 |
/* Can't move to the next tile (EOL?). */ |
7213
b3f3bc9fa6ab
(svn r10491) -Fix [FS#988, YAPF]: When rail segment was cached using electric engine and it ended with non-electric rail it was incorrectly cached with the end reason ESRB_DEAD_END instead of ESRB_RAIL_TYPE. (Eddi)
KUDr
parents:
7211
diff
changeset
|
434 |
if (tf_local.m_err == TrackFollower::EC_RAIL_TYPE) { |
b3f3bc9fa6ab
(svn r10491) -Fix [FS#988, YAPF]: When rail segment was cached using electric engine and it ended with non-electric rail it was incorrectly cached with the end reason ESRB_DEAD_END instead of ESRB_RAIL_TYPE. (Eddi)
KUDr
parents:
7211
diff
changeset
|
435 |
end_segment_reason |= ESRB_RAIL_TYPE; |
b3f3bc9fa6ab
(svn r10491) -Fix [FS#988, YAPF]: When rail segment was cached using electric engine and it ended with non-electric rail it was incorrectly cached with the end reason ESRB_DEAD_END instead of ESRB_RAIL_TYPE. (Eddi)
KUDr
parents:
7211
diff
changeset
|
436 |
} else { |
b3f3bc9fa6ab
(svn r10491) -Fix [FS#988, YAPF]: When rail segment was cached using electric engine and it ended with non-electric rail it was incorrectly cached with the end reason ESRB_DEAD_END instead of ESRB_RAIL_TYPE. (Eddi)
KUDr
parents:
7211
diff
changeset
|
437 |
end_segment_reason |= ESRB_DEAD_END; |
b3f3bc9fa6ab
(svn r10491) -Fix [FS#988, YAPF]: When rail segment was cached using electric engine and it ended with non-electric rail it was incorrectly cached with the end reason ESRB_DEAD_END instead of ESRB_RAIL_TYPE. (Eddi)
KUDr
parents:
7211
diff
changeset
|
438 |
} |
9802
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9801
diff
changeset
|
439 |
|
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:
9899
diff
changeset
|
440 |
if (TrackFollower::DoTrackMasking() && !HasOnewaySignalBlockingTrackdir(cur.tile, cur.td)) { |
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:
9899
diff
changeset
|
441 |
end_segment_reason |= ESRB_SAFE_TILE; |
9802
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9801
diff
changeset
|
442 |
} |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
443 |
break; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
444 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
445 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
446 |
/* Check if the next tile is not a choice. */ |
7833
ba402b153b79
(svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
truelight
parents:
7370
diff
changeset
|
447 |
if (KillFirstBit(tf_local.m_new_td_bits) != TRACKDIR_BIT_NONE) { |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
448 |
/* More than one segment will follow. Close this one. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
449 |
end_segment_reason |= ESRB_CHOICE_FOLLOWS; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
450 |
break; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
451 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
452 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
453 |
/* Gather the next tile/trackdir/tile_type/rail_type. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
454 |
TILE next(tf_local.m_new_tile, (Trackdir)FindFirstBit2x64(tf_local.m_new_td_bits)); |
3931
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
455 |
|
9899
03a2d32a2c05
(svn r14048) -Fix (r14019) [FS#2222]: Redo the check for reserved tracks properly this time. (michi_cc)
rubidium
parents:
9877
diff
changeset
|
456 |
if (TrackFollower::DoTrackMasking() && HasPbsSignalOnTrackdir(next.tile, next.td)) { |
9802
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9801
diff
changeset
|
457 |
/* Possible safe tile. */ |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9801
diff
changeset
|
458 |
end_segment_reason |= ESRB_SAFE_TILE; |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9801
diff
changeset
|
459 |
} |
6589c004f0d9
(svn r13944) -Add [YAPP]: Add YAPF provider to find a safe tile and reserve a path. (michi_cc)
rubidium
parents:
9801
diff
changeset
|
460 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
461 |
/* Check the next tile for the rail type. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
462 |
if (next.rail_type != cur.rail_type) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
463 |
/* Segment must consist from the same rail_type tiles. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
464 |
end_segment_reason |= ESRB_RAIL_TYPE; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
465 |
break; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
466 |
} |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
467 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
468 |
/* Avoid infinite looping. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
469 |
if (next.tile == n.m_key.m_tile && next.td == n.m_key.m_td) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
470 |
end_segment_reason |= ESRB_INFINITE_LOOP; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
471 |
break; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
472 |
} |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
473 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
474 |
if (segment_cost > s_max_segment_cost) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
475 |
/* Potentially in the infinite loop (or only very long segment?). We should |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
476 |
* not force it to finish prematurely unless we are on a regular tile. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
477 |
if (IsTileType(tf->m_new_tile, MP_RAILWAY)) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
478 |
end_segment_reason |= ESRB_SEGMENT_TOO_LONG; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
479 |
break; |
3931
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
480 |
} |
b946fc6e7188
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
KUDr
parents:
3930
diff
changeset
|
481 |
} |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
482 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
483 |
/* Any other reason bit set? */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
484 |
if (end_segment_reason != ESRB_NONE) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
485 |
break; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
486 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
487 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
488 |
/* For the next loop set new prev and cur tile info. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
489 |
prev = cur; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
490 |
cur = next; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
491 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
492 |
} // for (;;) |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
493 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
494 |
bool target_seen = false; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
495 |
if ((end_segment_reason & ESRB_POSSIBLE_TARGET) != ESRB_NONE) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
496 |
/* Depot, station or waypoint. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
497 |
if (Yapf().PfDetectDestination(cur.tile, cur.td)) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
498 |
/* Destination found. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
499 |
target_seen = true; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
500 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
501 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
502 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
503 |
/* Update the segment if needed. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
504 |
if (!is_cached_segment) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
505 |
/* Write back the segment information so it can be reused the next time. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
506 |
segment.m_cost = segment_cost; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
507 |
segment.m_end_segment_reason = end_segment_reason & ESRB_CACHED_MASK; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
508 |
/* Save end of segment back to the node. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
509 |
n.SetLastTileTrackdir(cur.tile, cur.td); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
510 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
511 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
512 |
/* Do we have an excuse why not to continue pathfinding in this direction? */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
513 |
if (!target_seen && (end_segment_reason & ESRB_ABORT_PF_MASK) != ESRB_NONE) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
514 |
/* Reason to not continue. Stop this PF branch. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
515 |
return false; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
516 |
} |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
517 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
518 |
/* Special costs for the case we have reached our target. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
519 |
if (target_seen) { |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
520 |
n.flags_u.flags_s.m_targed_seen = true; |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
521 |
/* Last-red and last-red-exit penalties. */ |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
522 |
if (n.flags_u.flags_s.m_last_signal_was_red) { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
523 |
if (n.m_last_red_signal_type == SIGTYPE_EXIT) { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
524 |
// last signal was red pre-signal-exit |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
525 |
extra_cost += Yapf().PfGetSettings().rail_lastred_exit_penalty; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
526 |
} else { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
527 |
// last signal was red, but not exit |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
528 |
extra_cost += Yapf().PfGetSettings().rail_lastred_penalty; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
529 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
530 |
} |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
531 |
|
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
532 |
/* Station platform-length penalty. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
533 |
if ((end_segment_reason & ESRB_STATION) != ESRB_NONE) { |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
534 |
Station *st = GetStationByTile(n.GetLastTile()); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
535 |
assert(st != NULL); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
536 |
uint platform_length = st->GetPlatformLength(n.GetLastTile(), ReverseDiagDir(TrackdirToExitdir(n.GetLastTrackdir()))); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
537 |
/* Reduce the extra cost caused by passing-station penalty (each station receives it in the segment cost). */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
538 |
extra_cost -= Yapf().PfGetSettings().rail_station_penalty * platform_length; |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
539 |
/* Add penalty for the inappropriate platform length. */ |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
540 |
extra_cost += PlatformLengthPenalty(platform_length); |
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
541 |
} |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
542 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
543 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
544 |
// total node cost |
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
545 |
n.m_cost = parent_cost + segment_entry_cost + segment_cost + extra_cost; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
546 |
|
7037
64249224bb74
(svn r10301) -Fix [FS#901, YAPF]: another assert violation in some special cases (immeR)
KUDr
parents:
6945
diff
changeset
|
547 |
return true; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
548 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
549 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
550 |
FORCEINLINE bool CanUseGlobalCache(Node& n) const |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
551 |
{ |
7099
a1d7e197cb64
(svn r10366) -Codechange [YAPF]: added DEBUG_YAPF_CACHE macro that (when set to 1) allows to track YAPF "cache errors". They are probably responsible for current MP desyncs. (thanks Rubidium for this great idea!).
KUDr
parents:
7040
diff
changeset
|
552 |
return !m_disable_cache |
a1d7e197cb64
(svn r10366) -Codechange [YAPF]: added DEBUG_YAPF_CACHE macro that (when set to 1) allows to track YAPF "cache errors". They are probably responsible for current MP desyncs. (thanks Rubidium for this great idea!).
KUDr
parents:
7040
diff
changeset
|
553 |
&& (n.m_parent != NULL) |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
554 |
&& (n.m_parent->m_num_signals_passed >= m_sig_look_ahead_costs.Size()); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
555 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
556 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
557 |
FORCEINLINE void ConnectNodeToCachedData(Node& n, CachedData& ci) |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
558 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
559 |
n.m_segment = &ci; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
560 |
if (n.m_segment->m_cost < 0) { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
561 |
n.m_segment->m_last_tile = n.m_key.m_tile; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
562 |
n.m_segment->m_last_td = n.m_key.m_td; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
563 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
564 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
565 |
|
7099
a1d7e197cb64
(svn r10366) -Codechange [YAPF]: added DEBUG_YAPF_CACHE macro that (when set to 1) allows to track YAPF "cache errors". They are probably responsible for current MP desyncs. (thanks Rubidium for this great idea!).
KUDr
parents:
7040
diff
changeset
|
566 |
void DisableCache(bool disable) |
a1d7e197cb64
(svn r10366) -Codechange [YAPF]: added DEBUG_YAPF_CACHE macro that (when set to 1) allows to track YAPF "cache errors". They are probably responsible for current MP desyncs. (thanks Rubidium for this great idea!).
KUDr
parents:
7040
diff
changeset
|
567 |
{ |
a1d7e197cb64
(svn r10366) -Codechange [YAPF]: added DEBUG_YAPF_CACHE macro that (when set to 1) allows to track YAPF "cache errors". They are probably responsible for current MP desyncs. (thanks Rubidium for this great idea!).
KUDr
parents:
7040
diff
changeset
|
568 |
m_disable_cache = disable; |
a1d7e197cb64
(svn r10366) -Codechange [YAPF]: added DEBUG_YAPF_CACHE macro that (when set to 1) allows to track YAPF "cache errors". They are probably responsible for current MP desyncs. (thanks Rubidium for this great idea!).
KUDr
parents:
7040
diff
changeset
|
569 |
} |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
570 |
}; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
571 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
572 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
573 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
574 |
#endif /* YAPF_COSTRAIL_HPP */ |