17 FORCEINLINE void Set(const CYapfNodeKeyTrackDir& node_key) {m_value = (((int)node_key.m_tile) << 3) | node_key.m_td;} |
17 FORCEINLINE void Set(const CYapfNodeKeyTrackDir& node_key) {m_value = (((int)node_key.m_tile) << 3) | node_key.m_td;} |
18 |
18 |
19 FORCEINLINE int32 CalcHash() const {return m_value;} |
19 FORCEINLINE int32 CalcHash() const {return m_value;} |
20 FORCEINLINE TileIndex GetTile() const {return (TileIndex)(m_value >> 3);} |
20 FORCEINLINE TileIndex GetTile() const {return (TileIndex)(m_value >> 3);} |
21 FORCEINLINE bool operator == (const CYapfRailSegmentKey& other) const {return m_value == other.m_value;} |
21 FORCEINLINE bool operator == (const CYapfRailSegmentKey& other) const {return m_value == other.m_value;} |
|
22 |
|
23 void Dump(DumpTarget &dmp) const |
|
24 { |
|
25 dmp.WriteTile("tile", GetTile()); |
|
26 dmp.WriteEnumT("td", GetTrackdir()); |
|
27 } |
22 }; |
28 }; |
23 |
29 |
24 /* Enum used in PfCalcCost() to see why was the segment closed. */ |
30 /* Enum used in PfCalcCost() to see why was the segment closed. */ |
25 enum EndSegmentReason { |
31 enum EndSegmentReason { |
26 /* The following reasons can be saved into cached segment */ |
32 /* The following reasons can be saved into cached segment */ |
61 ESRB_LOOK_AHEAD_END = 1 << ESR_LOOK_AHEAD_END, |
67 ESRB_LOOK_AHEAD_END = 1 << ESR_LOOK_AHEAD_END, |
62 ESRB_TARGET_REACHED = 1 << ESR_TARGET_REACHED, |
68 ESRB_TARGET_REACHED = 1 << ESR_TARGET_REACHED, |
63 |
69 |
64 /* Additional (composite) values. */ |
70 /* Additional (composite) values. */ |
65 |
71 |
66 /* What reasons mean that the target can be fond and needs to be detected. */ |
72 /* What reasons mean that the target can be found and needs to be detected. */ |
67 ESRB_POSSIBLE_TARGET = ESRB_DEPOT | ESRB_WAYPOINT | ESRB_STATION, |
73 ESRB_POSSIBLE_TARGET = ESRB_DEPOT | ESRB_WAYPOINT | ESRB_STATION, |
68 |
74 |
69 /* What reasons can be stored back into cached segment. */ |
75 /* What reasons can be stored back into cached segment. */ |
70 ESRB_CACHED_MASK = ESRB_DEAD_END | ESRB_RAIL_TYPE | ESRB_INFINITE_LOOP | ESRB_SEGMENT_TOO_LONG | ESRB_CHOICE_FOLLOWS | ESRB_DEPOT | ESRB_WAYPOINT | ESRB_STATION, |
76 ESRB_CACHED_MASK = ESRB_DEAD_END | ESRB_RAIL_TYPE | ESRB_INFINITE_LOOP | ESRB_SEGMENT_TOO_LONG | ESRB_CHOICE_FOLLOWS | ESRB_DEPOT | ESRB_WAYPOINT | ESRB_STATION, |
71 |
77 |
72 /* Reasons to abort pathfinding in this direction. */ |
78 /* Reasons to abort pathfinding in this direction. */ |
73 ESRB_ABORT_PF_MASK = ESRB_DEAD_END | ESRB_PATH_TOO_LONG | ESRB_INFINITE_LOOP | ESRB_FIRST_TWO_WAY_RED, |
79 ESRB_ABORT_PF_MASK = ESRB_DEAD_END | ESRB_PATH_TOO_LONG | ESRB_INFINITE_LOOP | ESRB_FIRST_TWO_WAY_RED, |
74 }; |
80 }; |
75 |
81 |
76 DECLARE_ENUM_AS_BIT_SET(EndSegmentReasonBits); |
82 DECLARE_ENUM_AS_BIT_SET(EndSegmentReasonBits); |
|
83 |
|
84 inline CStrA ValueStr(EndSegmentReasonBits bits) |
|
85 { |
|
86 static const char* end_segment_reason_names[] = { |
|
87 "DEAD_END", "RAIL_TYPE", "INFINITE_LOOP", "SEGMENT_TOO_LONG", "CHOICE_FOLLOWS", |
|
88 "DEPOT", "WAYPOINT", "STATION", |
|
89 "PATH_TOO_LONG", "FIRST_TWO_WAY_RED", "LOOK_AHEAD_END", "TARGET_REACHED" |
|
90 }; |
|
91 |
|
92 CStrA out; |
|
93 out.Format("0x%04X (%s)", bits, ComposeNameT(bits, end_segment_reason_names, "UNK", ESRB_NONE, "NONE").Data()); |
|
94 return out.Transfer(); |
|
95 } |
77 |
96 |
78 /** cached segment cost for rail YAPF */ |
97 /** cached segment cost for rail YAPF */ |
79 struct CYapfRailSegment |
98 struct CYapfRailSegment |
80 { |
99 { |
81 typedef CYapfRailSegmentKey Key; |
100 typedef CYapfRailSegmentKey Key; |
102 |
121 |
103 FORCEINLINE const Key& GetKey() const {return m_key;} |
122 FORCEINLINE const Key& GetKey() const {return m_key;} |
104 FORCEINLINE TileIndex GetTile() const {return m_key.GetTile();} |
123 FORCEINLINE TileIndex GetTile() const {return m_key.GetTile();} |
105 FORCEINLINE CYapfRailSegment* GetHashNext() {return m_hash_next;} |
124 FORCEINLINE CYapfRailSegment* GetHashNext() {return m_hash_next;} |
106 FORCEINLINE void SetHashNext(CYapfRailSegment* next) {m_hash_next = next;} |
125 FORCEINLINE void SetHashNext(CYapfRailSegment* next) {m_hash_next = next;} |
|
126 |
|
127 void Dump(DumpTarget &dmp) const |
|
128 { |
|
129 dmp.WriteStructT("m_key", &m_key); |
|
130 dmp.WriteTile("m_last_tile", m_last_tile); |
|
131 dmp.WriteEnumT("m_last_td", m_last_td); |
|
132 dmp.WriteLine("m_cost = %d", m_cost); |
|
133 dmp.WriteTile("m_last_signal_tile", m_last_signal_tile); |
|
134 dmp.WriteEnumT("m_last_signal_td", m_last_signal_td); |
|
135 dmp.WriteEnumT("m_end_segment_reason", m_end_segment_reason); |
|
136 } |
107 }; |
137 }; |
108 |
138 |
109 /** Yapf Node for rail YAPF */ |
139 /** Yapf Node for rail YAPF */ |
110 template <class Tkey_> |
140 template <class Tkey_> |
111 struct CYapfRailNodeT |
141 struct CYapfRailNodeT |
143 } |
173 } |
144 |
174 |
145 FORCEINLINE TileIndex GetLastTile() const {assert(m_segment != NULL); return m_segment->m_last_tile;} |
175 FORCEINLINE TileIndex GetLastTile() const {assert(m_segment != NULL); return m_segment->m_last_tile;} |
146 FORCEINLINE Trackdir GetLastTrackdir() const {assert(m_segment != NULL); return m_segment->m_last_td;} |
176 FORCEINLINE Trackdir GetLastTrackdir() const {assert(m_segment != NULL); return m_segment->m_last_td;} |
147 FORCEINLINE void SetLastTileTrackdir(TileIndex tile, Trackdir td) {assert(m_segment != NULL); m_segment->m_last_tile = tile; m_segment->m_last_td = td;} |
177 FORCEINLINE void SetLastTileTrackdir(TileIndex tile, Trackdir td) {assert(m_segment != NULL); m_segment->m_last_tile = tile; m_segment->m_last_td = td;} |
|
178 |
|
179 void Dump(DumpTarget &dmp) const |
|
180 { |
|
181 base::Dump(dmp); |
|
182 dmp.WriteStructT("m_segment", m_segment); |
|
183 dmp.WriteLine("m_num_signals_passed = %d", m_num_signals_passed); |
|
184 dmp.WriteLine("m_targed_seen = %s", flags_u.flags_s.m_targed_seen ? "Yes" : "No"); |
|
185 dmp.WriteLine("m_choice_seen = %s", flags_u.flags_s.m_choice_seen ? "Yes" : "No"); |
|
186 dmp.WriteLine("m_last_signal_was_red = %s", flags_u.flags_s.m_last_signal_was_red ? "Yes" : "No"); |
|
187 dmp.WriteEnumT("m_last_red_signal_type", m_last_red_signal_type); |
|
188 } |
148 }; |
189 }; |
149 |
190 |
150 // now define two major node types (that differ by key type) |
191 // now define two major node types (that differ by key type) |
151 typedef CYapfRailNodeT<CYapfNodeKeyExitDir> CYapfRailNodeExitDir; |
192 typedef CYapfRailNodeT<CYapfNodeKeyExitDir> CYapfRailNodeExitDir; |
152 typedef CYapfRailNodeT<CYapfNodeKeyTrackDir> CYapfRailNodeTrackDir; |
193 typedef CYapfRailNodeT<CYapfNodeKeyTrackDir> CYapfRailNodeTrackDir; |