summaryrefslogtreecommitdiff
path: root/vehicle.c
diff options
context:
space:
mode:
authormatthijs <matthijs@openttd.org>2005-05-03 20:45:23 +0000
committermatthijs <matthijs@openttd.org>2005-05-03 20:45:23 +0000
commit0699c54c455970a228d6ba2a93b8ea7eaf941c2b (patch)
tree7bc7501d9478e3e45c2b4d8d2bea5cbc5d3deb9c /vehicle.c
parent24943a4759d290b2b01cc5d2607f6317b7ccfcb9 (diff)
downloadopenttd-0699c54c455970a228d6ba2a93b8ea7eaf941c2b.tar.xz
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
GetVehicleTrackdir now tries to get a valid trackdir as much as possibly, by assuming that a vehicle is facing outwards in a depot or road station, for example. - Codechange: [Multistop] Multistop now also tries to find a slot for road vehicles that are in stations, since the pathfinder now properly handles that.
Diffstat (limited to 'vehicle.c')
-rw-r--r--vehicle.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/vehicle.c b/vehicle.c
index 4cd4b7b3a..0f83dbe83 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -17,6 +17,8 @@
#include "debug.h"
#include "npf.h"
#include "vehicle_gui.h"
+#include "depot.h"
+#include "station.h"
#define INVALID_COORD (-0x8000)
#define GEN_HASH(x,y) (((x & 0x1F80)>>7) + ((y & 0xFC0)))
@@ -1714,11 +1716,15 @@ byte GetDirectionTowards(Vehicle *v, int x, int y)
byte GetVehicleTrackdir(const Vehicle* v)
{
+ if (v->vehstatus & VS_CRASHED)
+ return 0xff;
+
switch(v->type)
{
case VEH_Train:
if (v->u.rail.track == 0x80)
- return 0xFF; /* Train in depot */
+ /* We'll assume the train is facing outwards */
+ return _dir_to_diag_trackdir[GetDepotDirection(v->tile, TRANSPORT_RAIL)]; /* Train in depot */
else if (v->u.rail.track == 0x40)
/* train in tunnel, so just use his direction and assume a diagonal track */
return _dir_to_diag_trackdir[(v->direction>>1)&3];
@@ -1726,12 +1732,17 @@ byte GetVehicleTrackdir(const Vehicle* v)
return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.rail.track)][v->direction];
case VEH_Ship:
if (v->u.ship.state == 0x80)
- return 0xFF; /* Ship in depot */
+ /* We'll assume the ship is facing outwards */
+ return _dir_to_diag_trackdir[GetDepotDirection(v->tile, TRANSPORT_WATER)]; /* Ship in depot */
else
return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.ship.state)][v->direction];
case VEH_Road:
if (v->u.road.state == 254)
- return 0xFF; /* Road vehicle in depot */
+ /* We'll assume the road vehicle is facing outwards */
+ return _dir_to_diag_trackdir[GetDepotDirection(v->tile, TRANSPORT_ROAD)]; /* Road vehicle in depot */
+ else if (IsRoadStationTile(v->tile))
+ /* We'll assume the road vehicle is facing outwards */
+ return _dir_to_diag_trackdir[GetRoadStationDir(v->tile)]; /* Road vehicle in a station */
else
return _dir_to_diag_trackdir[(v->direction>>1)&3];
case VEH_Aircraft: