diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/default/default.cpp | 4 | ||||
-rw-r--r-- | src/pathfind.cpp | 29 | ||||
-rw-r--r-- | src/pathfind.h | 11 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 4 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 2 |
5 files changed, 26 insertions, 24 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp index cd081973a..7829fa7bf 100644 --- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -1922,7 +1922,7 @@ static bool AiDoFollowTrack(const Player* p) arpfd.tile2 = _players_ai[p->index].cur_tile_a; arpfd.flag = false; arpfd.count = 0; - FollowTrack(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(_players_ai[p->index].cur_dir_a), TRANSPORT_RAIL, 0, ReverseDiagDir(_players_ai[p->index].cur_dir_a), + FollowTrack(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(_players_ai[p->index].cur_dir_a), PATHFIND_FLAGS_NONE, TRANSPORT_RAIL, 0, ReverseDiagDir(_players_ai[p->index].cur_dir_a), (TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd); return arpfd.count > 8; } @@ -2897,7 +2897,7 @@ static bool AiCheckRoadFinished(Player *p) while (bits != TRACKDIR_BIT_NONE) { Trackdir trackdir = RemoveFirstTrackdir(&bits); - FollowTrack(tile, 0x1000 | TRANSPORT_ROAD, ROADTYPES_ROAD, TrackdirToExitdir(trackdir), (TPFEnumProc*)AiEnumFollowRoad, NULL, &are); + FollowTrack(tile, PATHFIND_FLAGS_DISABLE_TILE_HASH, TRANSPORT_ROAD, ROADTYPES_ROAD, TrackdirToExitdir(trackdir), (TPFEnumProc*)AiEnumFollowRoad, NULL, &are); } if (DistanceManhattan(tile, are.dest) <= are.best_dist) return false; diff --git a/src/pathfind.cpp b/src/pathfind.cpp index c6f171dab..9a25ab8cc 100644 --- a/src/pathfind.cpp +++ b/src/pathfind.cpp @@ -139,7 +139,7 @@ static const byte _otherdir_mask[4] = { 0x2A, }; -static void TPFMode2(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) +static void TPFModeShip(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) { RememberData rd; @@ -177,7 +177,7 @@ static void TPFMode2(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi tpf->the_dir = (Trackdir)(track + (HasBit(_otherdir_mask[direction], track) ? 8 : 0)); if (!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length)) { - TPFMode2(tpf, tile, _tpf_new_direction[tpf->the_dir]); + TPFModeShip(tpf, tile, _tpf_new_direction[tpf->the_dir]); } tpf->rd = rd; @@ -211,7 +211,7 @@ static inline bool CanAccessTileInDir(TileIndex tile, DiagDirection side, Transp static const uint16 _tpfmode1_and[4] = { 0x1009, 0x16, 0x520, 0x2A00 }; -static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) +static void TPFModeNormal(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) { const TileIndex tile_org = tile; @@ -264,10 +264,8 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi tpf->rd.cur_length++; - if ((byte)bits != tpf->var2) { - bits &= _tpfmode1_and[direction]; - bits |= bits >> 8; - } + bits &= _tpfmode1_and[direction]; + bits |= bits >> 8; bits &= 0xBF; if (bits != 0) { @@ -282,7 +280,7 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi /* make sure we are not leaving from invalid side */ if (TPFSetTileBit(tpf, tile, tpf->the_dir) && CanAccessTileInDir(tile, TrackdirToExitdir(tpf->the_dir), tpf->tracktype) && !tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length) ) { - TPFMode1(tpf, tile, _tpf_new_direction[tpf->the_dir]); + TPFModeNormal(tpf, tile, _tpf_new_direction[tpf->the_dir]); } tpf->rd = rd; } while (bits != 0); @@ -290,7 +288,7 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi } } -void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data) +void FollowTrack(TileIndex tile, PathfindFlags flags, TransportType tt, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data) { assert(IsValidDiagDirection(direction)); @@ -306,21 +304,18 @@ void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection dire tpf->rd.depth = 0; tpf->rd.last_choosen_track = INVALID_TRACK; - tpf->var2 = HasBit(flags, 15) ? 0x43 : 0xFF; // 0x8000 - - tpf->disable_tile_hash = HasBit(flags, 12); // 0x1000 - + tpf->disable_tile_hash = (flags & PATHFIND_FLAGS_DISABLE_TILE_HASH) != 0; - tpf->tracktype = (TransportType)(flags & 0xFF); + tpf->tracktype = tt; tpf->sub_type = sub_type; - if (HasBit(flags, 11)) { + if ((flags & PATHFIND_FLAGS_SHIP_MODE) != 0) { tpf->enum_proc(tile, data, INVALID_TRACKDIR, 0); - TPFMode2(tpf, tile, direction); + TPFModeShip(tpf, tile, direction); } else { /* clear the hash_heads */ memset(tpf->hash_head, 0, sizeof(tpf->hash_head)); - TPFMode1(tpf, tile, direction); + TPFModeNormal(tpf, tile, direction); } if (after_proc != NULL) after_proc(tpf); diff --git a/src/pathfind.h b/src/pathfind.h index e63c750c5..11f9bff90 100644 --- a/src/pathfind.h +++ b/src/pathfind.h @@ -58,7 +58,6 @@ struct TrackPathFinder { TransportType tracktype; uint sub_type; - byte var2; bool disable_tile_hash; uint16 hash_head[0x400]; @@ -67,7 +66,15 @@ struct TrackPathFinder { TrackPathFinderLink links[0x400]; ///< hopefully, this is enough. }; -void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection direction, TPFEnumProc* enum_proc, TPFAfterProc* after_proc, void* data); +/** Some flags to modify the behaviour of original pathfinder */ +enum PathfindFlags { + PATHFIND_FLAGS_NONE = 0, + PATHFIND_FLAGS_SHIP_MODE = 0x0800, ///< pathfinder with some optimizations for ships, but does not work for other types. + PATHFIND_FLAGS_DISABLE_TILE_HASH = 0x1000, ///< do not check for searching in circles +}; +DECLARE_ENUM_AS_BIT_SET(PathfindFlags) + +void FollowTrack(TileIndex tile, PathfindFlags flags, TransportType tt, uint sub_type, DiagDirection direction, TPFEnumProc* enum_proc, TPFAfterProc* after_proc, void* data); void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc* enum_proc, void* data); #endif /* PATHFIND_H */ diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 2311287ad..6353bbbef 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -437,7 +437,7 @@ static const Depot* FindClosestRoadDepot(const Vehicle* v) /* search in all directions */ for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) { - FollowTrack(v->tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, d, EnumRoadSignalFindDepot, NULL, &rfdd); + FollowTrack(v->tile, PATHFIND_FLAGS_NONE, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, d, EnumRoadSignalFindDepot, NULL, &rfdd); } if (rfdd.best_length != UINT_MAX) return GetDepotByTile(rfdd.tile); @@ -1283,7 +1283,7 @@ do_it:; if (best_track == INVALID_TRACKDIR) best_track = (Trackdir)i; // in case we don't find the path, just pick a track frd.maxtracklen = UINT_MAX; frd.mindist = UINT_MAX; - FollowTrack(tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, _road_pf_directions[i], EnumRoadTrackFindDist, NULL, &frd); + FollowTrack(tile, PATHFIND_FLAGS_NONE, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, _road_pf_directions[i], EnumRoadTrackFindDist, NULL, &frd); if (frd.mindist < best_dist || (frd.mindist == best_dist && frd.maxtracklen < best_maxlen)) { best_dist = frd.mindist; diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index a3e460a29..baac1285b 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -474,7 +474,7 @@ static uint FindShipTrack(Vehicle *v, TileIndex tile, DiagDirection dir, TrackBi pfs.best_bird_dist = (uint)-1; pfs.best_length = (uint)-1; - FollowTrack(tile, 0x1800 | TRANSPORT_WATER, 0, (DiagDirection)_ship_search_directions[i][dir], (TPFEnumProc*)ShipTrackFollower, NULL, &pfs); + FollowTrack(tile, PATHFIND_FLAGS_SHIP_MODE | PATHFIND_FLAGS_DISABLE_TILE_HASH, TRANSPORT_WATER, 0, (DiagDirection)_ship_search_directions[i][dir], (TPFEnumProc*)ShipTrackFollower, NULL, &pfs); if (best_track != INVALID_TRACK) { if (pfs.best_bird_dist != 0) { |