summaryrefslogtreecommitdiff
path: root/yapf
diff options
context:
space:
mode:
authorKUDr <KUDr@openttd.org>2006-05-30 15:04:59 +0000
committerKUDr <KUDr@openttd.org>2006-05-30 15:04:59 +0000
commit325a1d88f7fc11fc97deef10fe7fe8f09db3a203 (patch)
tree8d432ddfaba5f45fe44bc6b081f640664e84520e /yapf
parent55fb73394d1dc0c292dd0c5291a0bba2df10ba88 (diff)
downloadopenttd-325a1d88f7fc11fc97deef10fe7fe8f09db3a203.tar.xz
(svn r5037) -Fix: assert when GetVehicleTrackdir() returns wrong trackdir - introduced by r5033 (thanks yanek)
Diffstat (limited to 'yapf')
-rw-r--r--yapf/yapf_road.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/yapf/yapf_road.cpp b/yapf/yapf_road.cpp
index 3d44288c0..3cedb6719 100644
--- a/yapf/yapf_road.cpp
+++ b/yapf/yapf_road.cpp
@@ -301,10 +301,7 @@ public:
return 0;
}
- // set origin (tile, trackdir)
- TileIndex src_tile = v->tile;
- Trackdir src_td = GetVehicleTrackdir(v);
- Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
+ if (!SetOriginFromVehiclePos(v)) return UINT_MAX;
// set destination tile, trackdir
// get available trackdirs on the destination tile
@@ -327,6 +324,21 @@ public:
return dist;
}
+ /** Return true if the valid origin (tile/trackdir) was set from the current vehicle position. */
+ FORCEINLINE bool SetOriginFromVehiclePos(const Vehicle *v)
+ {
+ // set origin (tile, trackdir)
+ TileIndex src_tile = v->tile;
+ Trackdir src_td = GetVehicleTrackdir(v);
+ if ((GetTileTrackStatus(src_tile, TRANSPORT_ROAD) & TrackdirToTrackdirBits(src_td)) == 0) {
+ // sometimes the roadveh is not on the road (it resides on non-existing track)
+ // how should we handle that situation?
+ return false;
+ }
+ Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
+ return true;
+ }
+
static Depot* stFindNearestDepot(Vehicle* v, TileIndex tile, Trackdir td)
{
Tpf pf;