1
0
Fork 0

(svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code

release/0.4.5
celestar 2005-04-18 05:42:59 +00:00
parent 51c56287f0
commit 0f08e83553
1 changed files with 13 additions and 37 deletions

View File

@ -652,8 +652,7 @@ static void ProcessRoadVehOrder(Vehicle *v)
st = GetStation(order->station); st = GetStation(order->station);
{ {
int32 *dist; uint mindist = 0xFFFFFFFF;
int32 mindist = 0xFFFFFFFF;
int num; int num;
RoadStopType type; RoadStopType type;
RoadStop *rs; RoadStop *rs;
@ -670,18 +669,12 @@ static void ProcessRoadVehOrder(Vehicle *v)
return; return;
} }
dist = malloc(num * sizeof(int32)); for (rs = GetPrimaryRoadStop(st, type); rs != NULL; rs = rs->next) {
if (DistanceManhattan(v->tile, rs->xy) < mindist) {
do {
*dist = DistanceSquare(v->tile, rs->xy);
if (*dist < mindist) {
v->dest_tile = rs->xy; v->dest_tile = rs->xy;
} }
rs = rs->next; }
} while ( rs != NULL );
free(dist);
dist = NULL;
} }
} else if (order->type == OT_GOTO_DEPOT) { } else if (order->type == OT_GOTO_DEPOT) {
v->dest_tile = GetDepot(order->station)->xy; v->dest_tile = GetDepot(order->station)->xy;
@ -1157,29 +1150,17 @@ found_best_track:;
return best_track; return best_track;
} }
static int RoadFindPathToStation(const Vehicle *v, TileIndex tile) static uint RoadFindPathToStation(const Vehicle *v, TileIndex tile)
{ {
FindRoadToChooseData frd; NPFFindStationOrTileData fstd;
int i, best_track = -1; byte trackdir = _dir_to_diag_trackdir[(v->direction >> 1) & 3];
uint best_dist = (uint) -1, best_maxlen = (uint) -1;
frd.dest = tile; fstd.dest_coords = tile;
frd.maxtracklen = (uint) -1; fstd.station_index = -1; // indicates that the destination is a tile, not a station
frd.mindist = (uint) -1;
for (i = 0; i < 4; i++) { return NPFRouteToStationOrTile(v->tile, trackdir, &fstd, TRANSPORT_ROAD, v->owner).best_path_dist;
FollowTrack(v->tile, 0x2000 | TRANSPORT_ROAD, i, (TPFEnumProc*)EnumRoadTrackFindDist, NULL, &frd);
if (frd.mindist < best_dist || (frd.mindist == best_dist && frd.maxtracklen < best_maxlen )) {
best_dist = frd.mindist;
best_maxlen = frd.maxtracklen;
best_track = i;
}
}
return best_maxlen;
} }
typedef struct RoadDriveEntry { typedef struct RoadDriveEntry {
byte x,y; byte x,y;
} RoadDriveEntry; } RoadDriveEntry;
@ -1672,17 +1653,12 @@ 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) { if (v->u.road.slot == NULL && rs != NULL && IsTileType(v->tile, MP_STREET)) {
//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);
do { do {
stop->dist = 0xFFFFFFFF; stop->dist = RoadFindPathToStation(v, rs->xy) / NPF_TILE_LENGTH;
//FIXME This doesn't fully work yet, as it only goes
//to one tile BEFORE the stop in question and doesn't
//regard the direction of the exit
stop->dist = RoadFindPathToStation(v, rs->xy);
DEBUG(ms, 3) ("Multistop: Distance to stop at 0x%x is %d", rs->xy, stop->dist); DEBUG(ms, 3) ("Multistop: Distance to stop at 0x%x is %d", rs->xy, stop->dist);
stop->rs = rs; stop->rs = rs;
@ -1694,7 +1670,7 @@ void OnNewDay_RoadVeh(Vehicle *v)
rs = rs->next; rs = rs->next;
} while (rs != NULL); } while (rs != NULL);
if (mindist < 120) { //if we're reasonably close, get us a slot if (mindist < 180) { //if we're reasonably close, get us a slot
int k; int k;
bubblesort(firststop, num, sizeof(StopStruct), dist_compare); bubblesort(firststop, num, sizeof(StopStruct), dist_compare);