21 #include "sound.h" |
21 #include "sound.h" |
22 #include "depot.h" |
22 #include "depot.h" |
23 #include "tunnel_map.h" |
23 #include "tunnel_map.h" |
24 #include "vehicle_gui.h" |
24 #include "vehicle_gui.h" |
25 #include "newgrf_engine.h" |
25 #include "newgrf_engine.h" |
|
26 #include "yapf/yapf.h" |
26 |
27 |
27 static const uint16 _roadveh_images[63] = { |
28 static const uint16 _roadveh_images[63] = { |
28 0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14, |
29 0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14, |
29 0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74, |
30 0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74, |
30 0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C, |
31 0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C, |
312 { |
313 { |
313 TileIndex tile = v->tile; |
314 TileIndex tile = v->tile; |
314 |
315 |
315 if (v->u.road.state == 255) tile = GetVehicleOutOfTunnelTile(v); |
316 if (v->u.road.state == 255) tile = GetVehicleOutOfTunnelTile(v); |
316 |
317 |
317 if (_patches.new_pathfinding_all) { |
318 if (_patches.yapf.road_use_yapf) { |
|
319 Depot* ret = YapfFindNearestRoadDepot(v); |
|
320 return ret; |
|
321 } else if (_patches.new_pathfinding_all) { |
318 NPFFoundTargetData ftd; |
322 NPFFoundTargetData ftd; |
319 /* See where we are now */ |
323 /* See where we are now */ |
320 Trackdir trackdir = GetVehicleTrackdir(v); |
324 Trackdir trackdir = GetVehicleTrackdir(v); |
321 |
325 |
322 ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); |
326 ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); |
981 frd->mindist = dist; |
985 frd->mindist = dist; |
982 } |
986 } |
983 return false; |
987 return false; |
984 } |
988 } |
985 |
989 |
|
990 static inline NPFFoundTargetData PerfNPFRouteToStationOrTile(TileIndex tile, Trackdir trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner, RailTypeMask railtypes) |
|
991 { |
|
992 |
|
993 void* perf = NpfBeginInterval(); |
|
994 NPFFoundTargetData ret = NPFRouteToStationOrTile(tile, trackdir, target, type, owner, railtypes); |
|
995 int t = NpfEndInterval(perf); |
|
996 DEBUG(yapf, 1)("[YAPF][NPFR] %d us - %d rounds - %d open - %d closed -- ", t, 0, _aystar_stats_open_size, _aystar_stats_closed_size); |
|
997 return ret; |
|
998 } |
|
999 |
986 // Returns direction to choose |
1000 // Returns direction to choose |
987 // or -1 if the direction is currently blocked |
1001 // or -1 if the direction is currently blocked |
988 static int RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection enterdir) |
1002 static int RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection enterdir) |
989 { |
1003 { |
990 #define return_track(x) {best_track = x; goto found_best_track; } |
1004 #define return_track(x) {best_track = x; goto found_best_track; } |
1051 // Only one track to choose between? |
1065 // Only one track to choose between? |
1052 if (!(KillFirstBit2x64(bitmask))) { |
1066 if (!(KillFirstBit2x64(bitmask))) { |
1053 return_track(FindFirstBit2x64(bitmask)); |
1067 return_track(FindFirstBit2x64(bitmask)); |
1054 } |
1068 } |
1055 |
1069 |
1056 if (_patches.new_pathfinding_all) { |
1070 if (_patches.yapf.road_use_yapf) { |
|
1071 Trackdir trackdir = YapfChooseRoadTrack(v, tile, enterdir); |
|
1072 if (trackdir != INVALID_TRACKDIR) return_track(trackdir); |
|
1073 return_track(PickRandomBit(bitmask)); |
|
1074 } else if (_patches.new_pathfinding_all) { |
1057 NPFFindStationOrTileData fstd; |
1075 NPFFindStationOrTileData fstd; |
1058 NPFFoundTargetData ftd; |
1076 NPFFoundTargetData ftd; |
1059 byte trackdir; |
1077 byte trackdir; |
1060 |
1078 |
1061 NPFFillWithOrderData(&fstd, v); |
1079 NPFFillWithOrderData(&fstd, v); |
1062 trackdir = DiagdirToDiagTrackdir(enterdir); |
1080 trackdir = DiagdirToDiagTrackdir(enterdir); |
1063 //debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir); |
1081 //debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir); |
1064 |
1082 |
1065 ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); |
1083 ftd = PerfNPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); |
1066 if (ftd.best_trackdir == 0xff) { |
1084 if (ftd.best_trackdir == 0xff) { |
1067 /* We are already at our target. Just do something */ |
1085 /* We are already at our target. Just do something */ |
1068 //TODO: maybe display error? |
1086 //TODO: maybe display error? |
1069 //TODO: go straight ahead if possible? |
1087 //TODO: go straight ahead if possible? |
1070 return_track(FindFirstBit2x64(bitmask)); |
1088 return_track(FindFirstBit2x64(bitmask)); |