OpenTTD
yapf_rail.cpp
Go to the documentation of this file.
1 /* $Id: yapf_rail.cpp 27845 2017-04-03 22:02:28Z peter1138 $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #include "../../stdafx.h"
13 
14 #include "yapf.hpp"
15 #include "yapf_cache.h"
16 #include "yapf_node_rail.hpp"
17 #include "yapf_costrail.hpp"
18 #include "yapf_destrail.hpp"
19 #include "../../viewport_func.h"
20 #include "../../newgrf_station.h"
21 
22 #include "../../safeguards.h"
23 
24 template <typename Tpf> void DumpState(Tpf &pf1, Tpf &pf2)
25 {
26  DumpTarget dmp1, dmp2;
27  pf1.DumpBase(dmp1);
28  pf2.DumpBase(dmp2);
29  FILE *f1 = fopen("yapf1.txt", "wt");
30  FILE *f2 = fopen("yapf2.txt", "wt");
31  fwrite(dmp1.m_out.Data(), 1, dmp1.m_out.Size(), f1);
32  fwrite(dmp2.m_out.Data(), 1, dmp2.m_out.Size(), f2);
33  fclose(f1);
34  fclose(f2);
35 }
36 
37 int _total_pf_time_us = 0;
38 
39 template <class Types>
41 {
42 public:
43  typedef typename Types::Tpf Tpf;
44  typedef typename Types::TrackFollower TrackFollower;
45  typedef typename Types::NodeList::Titem Node;
46 
47 protected:
49  inline Tpf& Yapf()
50  {
51  return *static_cast<Tpf *>(this);
52  }
53 
54 private:
61 
62  bool FindSafePositionProc(TileIndex tile, Trackdir td)
63  {
64  if (IsSafeWaitingPosition(Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns())) {
65  m_res_dest = tile;
66  m_res_dest_td = td;
67  return false; // Stop iterating segment
68  }
69  return true;
70  }
71 
74  {
75  TileIndex start = tile;
76  TileIndexDiff diff = TileOffsByDiagDir(dir);
77 
78  do {
79  if (HasStationReservation(tile)) return false;
80  SetRailStationReservation(tile, true);
81  MarkTileDirtyByTile(tile);
82  tile = TILE_ADD(tile, diff);
83  } while (IsCompatibleTrainStationTile(tile, start) && tile != m_origin_tile);
84 
86 
87  return true;
88  }
89 
92  {
93  if (IsRailStationTile(tile)) {
95  /* Platform could not be reserved, undo. */
96  m_res_fail_tile = tile;
97  m_res_fail_td = td;
98  }
99  } else {
100  if (!TryReserveRailTrack(tile, TrackdirToTrack(td))) {
101  /* Tile couldn't be reserved, undo. */
102  m_res_fail_tile = tile;
103  m_res_fail_td = td;
104  return false;
105  }
106  }
107 
108  return tile != m_res_dest || td != m_res_dest_td;
109  }
110 
113  {
114  if (IsRailStationTile(tile)) {
115  TileIndex start = tile;
117  while ((tile != m_res_fail_tile || td != m_res_fail_td) && IsCompatibleTrainStationTile(tile, start)) {
118  SetRailStationReservation(tile, false);
119  tile = TILE_ADD(tile, diff);
120  }
121  } else if (tile != m_res_fail_tile || td != m_res_fail_td) {
123  }
124  return (tile != m_res_dest || td != m_res_dest_td) && (tile != m_res_fail_tile || td != m_res_fail_td);
125  }
126 
127 public:
129  inline void SetReservationTarget(Node *node, TileIndex tile, Trackdir td)
130  {
131  m_res_node = node;
132  m_res_dest = tile;
133  m_res_dest_td = td;
134  }
135 
137  inline void FindSafePositionOnNode(Node *node)
138  {
139  assert(node->m_parent != NULL);
140 
141  /* We will never pass more than two signals, no need to check for a safe tile. */
142  if (node->m_parent->m_num_signals_passed >= 2) return;
143 
144  if (!node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::FindSafePositionProc)) {
145  m_res_node = node;
146  }
147  }
148 
150  bool TryReservePath(PBSTileInfo *target, TileIndex origin)
151  {
153  m_origin_tile = origin;
154 
155  if (target != NULL) {
156  target->tile = m_res_dest;
157  target->trackdir = m_res_dest_td;
158  target->okay = false;
159  }
160 
161  /* Don't bother if the target is reserved. */
162  if (!IsWaitingPositionFree(Yapf().GetVehicle(), m_res_dest, m_res_dest_td)) return false;
163 
164  for (Node *node = m_res_node; node->m_parent != NULL; node = node->m_parent) {
165  node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::ReserveSingleTrack);
166  if (m_res_fail_tile != INVALID_TILE) {
167  /* Reservation failed, undo. */
168  Node *fail_node = m_res_node;
169  TileIndex stop_tile = m_res_fail_tile;
170  do {
171  /* If this is the node that failed, stop at the failed tile. */
172  m_res_fail_tile = fail_node == node ? stop_tile : INVALID_TILE;
173  fail_node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::UnreserveSingleTrack);
174  } while (fail_node != node && (fail_node = fail_node->m_parent) != NULL);
175 
176  return false;
177  }
178  }
179 
180  if (target != NULL) target->okay = true;
181 
182  if (Yapf().CanUseGlobalCache(*m_res_node)) {
184  }
185 
186  return true;
187  }
188 };
189 
190 template <class Types>
192 {
193 public:
194  typedef typename Types::Tpf Tpf;
195  typedef typename Types::TrackFollower TrackFollower;
196  typedef typename Types::NodeList::Titem Node;
197  typedef typename Node::Key Key;
198 
199 protected:
201  inline Tpf& Yapf()
202  {
203  return *static_cast<Tpf *>(this);
204  }
205 
206 public:
212  inline void PfFollowNode(Node &old_node)
213  {
214  TrackFollower F(Yapf().GetVehicle());
215  if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
216  Yapf().AddMultipleNodes(&old_node, F);
217  }
218  }
219 
221  inline char TransportTypeChar() const
222  {
223  return 't';
224  }
225 
226  static FindDepotData stFindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_penalty, int reverse_penalty)
227  {
228  Tpf pf1;
229  /*
230  * With caching enabled it simply cannot get a reliable result when you
231  * have limited the distance a train may travel. This means that the
232  * cached result does not match uncached result in all cases and that
233  * causes desyncs. So disable caching when finding for a depot that is
234  * nearby. This only happens with automatic servicing of vehicles,
235  * so it will only impact performance when you do not manually set
236  * depot orders and you do not disable automatic servicing.
237  */
238  if (max_penalty != 0) pf1.DisableCache(true);
239  FindDepotData result1 = pf1.FindNearestDepotTwoWay(v, t1, td1, t2, td2, max_penalty, reverse_penalty);
240 
241  if (_debug_desync_level >= 2) {
242  Tpf pf2;
243  pf2.DisableCache(true);
244  FindDepotData result2 = pf2.FindNearestDepotTwoWay(v, t1, td1, t2, td2, max_penalty, reverse_penalty);
245  if (result1.tile != result2.tile || (result1.reverse != result2.reverse)) {
246  DEBUG(desync, 2, "CACHE ERROR: FindNearestDepotTwoWay() = [%s, %s]",
247  result1.tile != INVALID_TILE ? "T" : "F",
248  result2.tile != INVALID_TILE ? "T" : "F");
249  DumpState(pf1, pf2);
250  }
251  }
252 
253  return result1;
254  }
255 
256  inline FindDepotData FindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_penalty, int reverse_penalty)
257  {
258  /* set origin and destination nodes */
259  Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true);
260  Yapf().SetDestination(v);
261  Yapf().SetMaxCost(max_penalty);
262 
263  /* find the best path */
264  if (!Yapf().FindPath(v)) return FindDepotData();
265 
266  /* Some path found. */
267  Node *n = Yapf().GetBestNode();
268 
269  /* walk through the path back to the origin */
270  Node *pNode = n;
271  while (pNode->m_parent != NULL) {
272  pNode = pNode->m_parent;
273  }
274 
275  /* if the origin node is our front vehicle tile/Trackdir then we didn't reverse
276  * but we can also look at the cost (== 0 -> not reversed, == reverse_penalty -> reversed) */
277  return FindDepotData(n->GetLastTile(), n->m_cost, pNode->m_cost != 0);
278  }
279 };
280 
281 template <class Types>
283 {
284 public:
285  typedef typename Types::Tpf Tpf;
286  typedef typename Types::TrackFollower TrackFollower;
287  typedef typename Types::NodeList::Titem Node;
288  typedef typename Node::Key Key;
289 
290 protected:
292  inline Tpf& Yapf()
293  {
294  return *static_cast<Tpf *>(this);
295  }
296 
297 public:
303  inline void PfFollowNode(Node &old_node)
304  {
305  TrackFollower F(Yapf().GetVehicle(), Yapf().GetCompatibleRailTypes());
306  if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir()) && F.MaskReservedTracks()) {
307  Yapf().AddMultipleNodes(&old_node, F);
308  }
309  }
310 
312  inline char TransportTypeChar() const
313  {
314  return 't';
315  }
316 
317  static bool stFindNearestSafeTile(const Train *v, TileIndex t1, Trackdir td, bool override_railtype)
318  {
319  /* Create pathfinder instance */
320  Tpf pf1;
321  bool result1;
322  if (_debug_desync_level < 2) {
323  result1 = pf1.FindNearestSafeTile(v, t1, td, override_railtype, false);
324  } else {
325  bool result2 = pf1.FindNearestSafeTile(v, t1, td, override_railtype, true);
326  Tpf pf2;
327  pf2.DisableCache(true);
328  result1 = pf2.FindNearestSafeTile(v, t1, td, override_railtype, false);
329  if (result1 != result2) {
330  DEBUG(desync, 2, "CACHE ERROR: FindSafeTile() = [%s, %s]", result2 ? "T" : "F", result1 ? "T" : "F");
331  DumpState(pf1, pf2);
332  }
333  }
334 
335  return result1;
336  }
337 
338  bool FindNearestSafeTile(const Train *v, TileIndex t1, Trackdir td, bool override_railtype, bool dont_reserve)
339  {
340  /* Set origin and destination. */
341  Yapf().SetOrigin(t1, td);
342  Yapf().SetDestination(v, override_railtype);
343 
344  bool bFound = Yapf().FindPath(v);
345  if (!bFound) return false;
346 
347  /* Found a destination, set as reservation target. */
348  Node *pNode = Yapf().GetBestNode();
349  this->SetReservationTarget(pNode, pNode->GetLastTile(), pNode->GetLastTrackdir());
350 
351  /* Walk through the path back to the origin. */
352  Node *pPrev = NULL;
353  while (pNode->m_parent != NULL) {
354  pPrev = pNode;
355  pNode = pNode->m_parent;
356 
357  this->FindSafePositionOnNode(pPrev);
358  }
359 
360  return dont_reserve || this->TryReservePath(NULL, pNode->GetLastTile());
361  }
362 };
363 
364 template <class Types>
365 class CYapfFollowRailT : public CYapfReserveTrack<Types>
366 {
367 public:
368  typedef typename Types::Tpf Tpf;
369  typedef typename Types::TrackFollower TrackFollower;
370  typedef typename Types::NodeList::Titem Node;
371  typedef typename Node::Key Key;
372 
373 protected:
375  inline Tpf& Yapf()
376  {
377  return *static_cast<Tpf *>(this);
378  }
379 
380 public:
386  inline void PfFollowNode(Node &old_node)
387  {
388  TrackFollower F(Yapf().GetVehicle());
389  if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
390  Yapf().AddMultipleNodes(&old_node, F);
391  }
392  }
393 
395  inline char TransportTypeChar() const
396  {
397  return 't';
398  }
399 
400  static Trackdir stChooseRailTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, PBSTileInfo *target)
401  {
402  /* create pathfinder instance */
403  Tpf pf1;
404  Trackdir result1;
405 
406  if (_debug_desync_level < 2) {
407  result1 = pf1.ChooseRailTrack(v, tile, enterdir, tracks, path_found, reserve_track, target);
408  } else {
409  result1 = pf1.ChooseRailTrack(v, tile, enterdir, tracks, path_found, false, NULL);
410  Tpf pf2;
411  pf2.DisableCache(true);
412  Trackdir result2 = pf2.ChooseRailTrack(v, tile, enterdir, tracks, path_found, reserve_track, target);
413  if (result1 != result2) {
414  DEBUG(desync, 2, "CACHE ERROR: ChooseRailTrack() = [%d, %d]", result1, result2);
415  DumpState(pf1, pf2);
416  }
417  }
418 
419  return result1;
420  }
421 
422  inline Trackdir ChooseRailTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, PBSTileInfo *target)
423  {
424  if (target != NULL) target->tile = INVALID_TILE;
425 
426  /* set origin and destination nodes */
428  Yapf().SetOrigin(origin.tile, origin.trackdir, INVALID_TILE, INVALID_TRACKDIR, 1, true);
429  Yapf().SetDestination(v);
430 
431  /* find the best path */
432  path_found = Yapf().FindPath(v);
433 
434  /* if path not found - return INVALID_TRACKDIR */
435  Trackdir next_trackdir = INVALID_TRACKDIR;
436  Node *pNode = Yapf().GetBestNode();
437  if (pNode != NULL) {
438  /* reserve till end of path */
439  this->SetReservationTarget(pNode, pNode->GetLastTile(), pNode->GetLastTrackdir());
440 
441  /* path was found or at least suggested
442  * walk through the path back to the origin */
443  Node *pPrev = NULL;
444  while (pNode->m_parent != NULL) {
445  pPrev = pNode;
446  pNode = pNode->m_parent;
447 
448  this->FindSafePositionOnNode(pPrev);
449  }
450  /* return trackdir from the best origin node (one of start nodes) */
451  Node &best_next_node = *pPrev;
452  next_trackdir = best_next_node.GetTrackdir();
453 
454  if (reserve_track && path_found) this->TryReservePath(target, pNode->GetLastTile());
455  }
456 
457  /* Treat the path as found if stopped on the first two way signal(s). */
458  path_found |= Yapf().m_stopped_on_first_two_way_signal;
459  return next_trackdir;
460  }
461 
462  static bool stCheckReverseTrain(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty)
463  {
464  Tpf pf1;
465  bool result1 = pf1.CheckReverseTrain(v, t1, td1, t2, td2, reverse_penalty);
466 
467  if (_debug_desync_level >= 2) {
468  Tpf pf2;
469  pf2.DisableCache(true);
470  bool result2 = pf2.CheckReverseTrain(v, t1, td1, t2, td2, reverse_penalty);
471  if (result1 != result2) {
472  DEBUG(desync, 2, "CACHE ERROR: CheckReverseTrain() = [%s, %s]", result1 ? "T" : "F", result2 ? "T" : "F");
473  DumpState(pf1, pf2);
474  }
475  }
476 
477  return result1;
478  }
479 
480  inline bool CheckReverseTrain(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty)
481  {
482  /* create pathfinder instance
483  * set origin and destination nodes */
484  Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, false);
485  Yapf().SetDestination(v);
486 
487  /* find the best path */
488  bool bFound = Yapf().FindPath(v);
489 
490  if (!bFound) return false;
491 
492  /* path was found
493  * walk through the path back to the origin */
494  Node *pNode = Yapf().GetBestNode();
495  while (pNode->m_parent != NULL) {
496  pNode = pNode->m_parent;
497  }
498 
499  /* check if it was reversed origin */
500  Node &best_org_node = *pNode;
501  bool reversed = (best_org_node.m_cost != 0);
502  return reversed;
503  }
504 };
505 
506 template <class Tpf_, class Ttrack_follower, class Tnode_list, template <class Types> class TdestinationT, template <class Types> class TfollowT>
508 {
510 
511  typedef Tpf_ Tpf;
512  typedef Ttrack_follower TrackFollower;
513  typedef Tnode_list NodeList;
514  typedef Train VehicleType;
515  typedef CYapfBaseT<Types> PfBase;
516  typedef TfollowT<Types> PfFollow;
518  typedef TdestinationT<Types> PfDestination;
521 };
522 
523 struct CYapfRail1 : CYapfT<CYapfRail_TypesT<CYapfRail1 , CFollowTrackRail , CRailNodeListTrackDir, CYapfDestinationTileOrStationRailT, CYapfFollowRailT> > {};
524 struct CYapfRail2 : CYapfT<CYapfRail_TypesT<CYapfRail2 , CFollowTrackRailNo90, CRailNodeListTrackDir, CYapfDestinationTileOrStationRailT, CYapfFollowRailT> > {};
525 
526 struct CYapfAnyDepotRail1 : CYapfT<CYapfRail_TypesT<CYapfAnyDepotRail1, CFollowTrackRail , CRailNodeListTrackDir, CYapfDestinationAnyDepotRailT , CYapfFollowAnyDepotRailT> > {};
527 struct CYapfAnyDepotRail2 : CYapfT<CYapfRail_TypesT<CYapfAnyDepotRail2, CFollowTrackRailNo90, CRailNodeListTrackDir, CYapfDestinationAnyDepotRailT , CYapfFollowAnyDepotRailT> > {};
528 
529 struct CYapfAnySafeTileRail1 : CYapfT<CYapfRail_TypesT<CYapfAnySafeTileRail1, CFollowTrackFreeRail , CRailNodeListTrackDir, CYapfDestinationAnySafeTileRailT , CYapfFollowAnySafeTileRailT> > {};
530 struct CYapfAnySafeTileRail2 : CYapfT<CYapfRail_TypesT<CYapfAnySafeTileRail2, CFollowTrackFreeRailNo90, CRailNodeListTrackDir, CYapfDestinationAnySafeTileRailT , CYapfFollowAnySafeTileRailT> > {};
531 
532 
533 Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, PBSTileInfo *target)
534 {
535  /* default is YAPF type 2 */
536  typedef Trackdir (*PfnChooseRailTrack)(const Train*, TileIndex, DiagDirection, TrackBits, bool&, bool, PBSTileInfo*);
537  PfnChooseRailTrack pfnChooseRailTrack = &CYapfRail1::stChooseRailTrack;
538 
539  /* check if non-default YAPF type needed */
541  pfnChooseRailTrack = &CYapfRail2::stChooseRailTrack; // Trackdir, forbid 90-deg
542  }
543 
544  Trackdir td_ret = pfnChooseRailTrack(v, tile, enterdir, tracks, path_found, reserve_track, target);
545  return (td_ret != INVALID_TRACKDIR) ? TrackdirToTrack(td_ret) : FindFirstTrack(tracks);
546 }
547 
549 {
550  const Train *last_veh = v->Last();
551 
552  /* get trackdirs of both ends */
553  Trackdir td = v->GetVehicleTrackdir();
554  Trackdir td_rev = ReverseTrackdir(last_veh->GetVehicleTrackdir());
555 
556  /* tiles where front and back are */
557  TileIndex tile = v->tile;
558  TileIndex tile_rev = last_veh->tile;
559 
560  int reverse_penalty = 0;
561 
562  if (v->track == TRACK_BIT_WORMHOLE) {
563  /* front in tunnel / on bridge */
564  DiagDirection dir_into_wormhole = GetTunnelBridgeDirection(tile);
565 
566  if (TrackdirToExitdir(td) == dir_into_wormhole) tile = GetOtherTunnelBridgeEnd(tile);
567  /* Now 'tile' is the tunnel entry/bridge ramp the train will reach when driving forward */
568 
569  /* Current position of the train in the wormhole */
570  TileIndex cur_tile = TileVirtXY(v->x_pos, v->y_pos);
571 
572  /* Add distance to drive in the wormhole as penalty for the forward path, i.e. bonus for the reverse path
573  * Note: Negative penalties are ok for the start tile. */
574  reverse_penalty -= DistanceManhattan(cur_tile, tile) * YAPF_TILE_LENGTH;
575  }
576 
577  if (last_veh->track == TRACK_BIT_WORMHOLE) {
578  /* back in tunnel / on bridge */
579  DiagDirection dir_into_wormhole = GetTunnelBridgeDirection(tile_rev);
580 
581  if (TrackdirToExitdir(td_rev) == dir_into_wormhole) tile_rev = GetOtherTunnelBridgeEnd(tile_rev);
582  /* Now 'tile_rev' is the tunnel entry/bridge ramp the train will reach when reversing */
583 
584  /* Current position of the last wagon in the wormhole */
585  TileIndex cur_tile = TileVirtXY(last_veh->x_pos, last_veh->y_pos);
586 
587  /* Add distance to drive in the wormhole as penalty for the revere path. */
588  reverse_penalty += DistanceManhattan(cur_tile, tile_rev) * YAPF_TILE_LENGTH;
589  }
590 
591  typedef bool (*PfnCheckReverseTrain)(const Train*, TileIndex, Trackdir, TileIndex, Trackdir, int);
592  PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail1::stCheckReverseTrain;
593 
594  /* check if non-default YAPF type needed */
596  pfnCheckReverseTrain = &CYapfRail2::stCheckReverseTrain; // Trackdir, forbid 90-deg
597  }
598 
599  /* slightly hackish: If the pathfinders finds a path, the cost of the first node is tested to distinguish between forward- and reverse-path. */
600  if (reverse_penalty == 0) reverse_penalty = 1;
601 
602  bool reverse = pfnCheckReverseTrain(v, tile, td, tile_rev, td_rev, reverse_penalty);
603 
604  return reverse;
605 }
606 
608 {
609  const Train *last_veh = v->Last();
610 
612  TileIndex last_tile = last_veh->tile;
613  Trackdir td_rev = ReverseTrackdir(last_veh->GetVehicleTrackdir());
614 
615  typedef FindDepotData (*PfnFindNearestDepotTwoWay)(const Train*, TileIndex, Trackdir, TileIndex, Trackdir, int, int);
616  PfnFindNearestDepotTwoWay pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail1::stFindNearestDepotTwoWay;
617 
618  /* check if non-default YAPF type needed */
620  pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail2::stFindNearestDepotTwoWay; // Trackdir, forbid 90-deg
621  }
622 
623  return pfnFindNearestDepotTwoWay(v, origin.tile, origin.trackdir, last_tile, td_rev, max_penalty, YAPF_INFINITE_PENALTY);
624 }
625 
626 bool YapfTrainFindNearestSafeTile(const Train *v, TileIndex tile, Trackdir td, bool override_railtype)
627 {
628  typedef bool (*PfnFindNearestSafeTile)(const Train*, TileIndex, Trackdir, bool);
629  PfnFindNearestSafeTile pfnFindNearestSafeTile = CYapfAnySafeTileRail1::stFindNearestSafeTile;
630 
631  /* check if non-default YAPF type needed */
633  pfnFindNearestSafeTile = &CYapfAnySafeTileRail2::stFindNearestSafeTile;
634  }
635 
636  return pfnFindNearestSafeTile(v, tile, td, override_railtype);
637 }
638 
641 
643 {
644  CSegmentCostCacheBase::NotifyTrackLayoutChange(tile, track);
645 }