(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.
This commit is contained in:
matthijs 2005-05-03 20:45:23 +00:00
parent 24943a4759
commit 0699c54c45
3 changed files with 20 additions and 13 deletions

View File

@ -311,13 +311,7 @@ static Depot *FindClosestRoadDepot(Vehicle *v)
if (_patches.new_pathfinding_all) { if (_patches.new_pathfinding_all) {
NPFFoundTargetData ftd; NPFFoundTargetData ftd;
/* See where we are now */ /* See where we are now */
byte trackdir; byte trackdir = GetVehicleTrackdir(v);
if (IsRoadStationTile(tile))
/* if we are in a station, simulate leaving the station (since
* v->direction won't contain anything usefule than */
trackdir = _dir_to_diag_trackdir[GetRoadStationDir(tile)];
else
trackdir = GetVehicleTrackdir(v);
ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner); ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner);
if (ftd.best_bird_dist == 0) if (ftd.best_bird_dist == 0)
@ -1665,7 +1659,7 @@ void OnNewDay_RoadVeh(Vehicle *v)
} }
//We do not have a slot, so make one //We do not have a slot, so make one
if (v->u.road.slot == NULL && rs != NULL && IsTileType(v->tile, MP_STREET)) { if (v->u.road.slot == NULL && rs != NULL) {
//first we need to find out how far our stations are away. //first we need to find out how far our stations are away.
DEBUG(ms, 2) ("Multistop: Attempting to obtain a slot for vehicle %d at station %d (0x%x)", v->unitnumber, st->index, st->xy); DEBUG(ms, 2) ("Multistop: Attempting to obtain a slot for vehicle %d at station %d (0x%x)", v->unitnumber, st->index, st->xy);

View File

@ -1298,14 +1298,16 @@ static bool TrainFindDepotEnumProc(uint tile, TrainFindDepotData *tfdd, int trac
return length >= tfdd->best_length; return length >= tfdd->best_length;
} }
// returns the tile of a depot to goto to. The given vehicle must be on track, // returns the tile of a depot to goto to. The given vehicle must not be
// so not crashed, in a depot, etc. // crashed!
static TrainFindDepotData FindClosestTrainDepot(Vehicle *v) static TrainFindDepotData FindClosestTrainDepot(Vehicle *v)
{ {
int i; int i;
TrainFindDepotData tfdd; TrainFindDepotData tfdd;
uint tile = v->tile; uint tile = v->tile;
assert(!(v->vehstatus & VS_CRASHED));
tfdd.owner = v->owner; tfdd.owner = v->owner;
tfdd.best_length = (uint)-1; tfdd.best_length = (uint)-1;

View File

@ -17,6 +17,8 @@
#include "debug.h" #include "debug.h"
#include "npf.h" #include "npf.h"
#include "vehicle_gui.h" #include "vehicle_gui.h"
#include "depot.h"
#include "station.h"
#define INVALID_COORD (-0x8000) #define INVALID_COORD (-0x8000)
#define GEN_HASH(x,y) (((x & 0x1F80)>>7) + ((y & 0xFC0))) #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) byte GetVehicleTrackdir(const Vehicle* v)
{ {
if (v->vehstatus & VS_CRASHED)
return 0xff;
switch(v->type) switch(v->type)
{ {
case VEH_Train: case VEH_Train:
if (v->u.rail.track == 0x80) 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) else if (v->u.rail.track == 0x40)
/* train in tunnel, so just use his direction and assume a diagonal track */ /* train in tunnel, so just use his direction and assume a diagonal track */
return _dir_to_diag_trackdir[(v->direction>>1)&3]; 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]; return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.rail.track)][v->direction];
case VEH_Ship: case VEH_Ship:
if (v->u.ship.state == 0x80) 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 else
return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.ship.state)][v->direction]; return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.ship.state)][v->direction];
case VEH_Road: case VEH_Road:
if (v->u.road.state == 254) 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 else
return _dir_to_diag_trackdir[(v->direction>>1)&3]; return _dir_to_diag_trackdir[(v->direction>>1)&3];
case VEH_Aircraft: case VEH_Aircraft: