summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ai/default/default.cpp4
-rw-r--r--src/pathfind.cpp120
-rw-r--r--src/pathfind.h1
-rw-r--r--src/roadveh_cmd.cpp4
-rw-r--r--src/ship_cmd.cpp2
5 files changed, 40 insertions, 91 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp
index e86199ed4..2ea82bcda 100644
--- a/src/ai/default/default.cpp
+++ b/src/ai/default/default.cpp
@@ -1898,7 +1898,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), 0x2000 | 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), TRANSPORT_RAIL, 0, ReverseDiagDir(_players_ai[p->index].cur_dir_a),
(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
return arpfd.count > 8;
}
@@ -2866,7 +2866,7 @@ static bool AiCheckRoadFinished(Player *p)
uint i;
FOR_EACH_SET_BIT(i, bits) {
- FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, ROADTYPES_ROAD, (DiagDirection)_dir_by_track[i], (TPFEnumProc*)AiEnumFollowRoad, NULL, &are);
+ FollowTrack(tile, 0x1000 | TRANSPORT_ROAD, ROADTYPES_ROAD, (DiagDirection)_dir_by_track[i], (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 1ecbce8b2..6b9e7ebb6 100644
--- a/src/pathfind.cpp
+++ b/src/pathfind.cpp
@@ -230,13 +230,42 @@ static uint SkipToEndOfTunnel(TrackPathFinder* tpf, TileIndex tile, DiagDirectio
return flotr.tile;
}
-static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction);
-
-/** Most code of the "Normal" case of TPF Mode 1; for signals special tricks
- * have to be done, but those happen in TPFMode1; this is just to prevent
- * gotos ;). */
-static inline void TPFMode1_NormalCase(TrackPathFinder* tpf, TileIndex tile, TileIndex tile_org, DiagDirection direction)
+static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
{
+ TileIndex tile_org = tile;
+
+ if (IsTileType(tile, MP_TUNNELBRIDGE)) {
+ if (IsTunnel(tile)) {
+ if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
+ return;
+ }
+ /* Only skip through the tunnel if heading inwards. We can
+ * be headed outwards if our starting position was in a
+ * tunnel and we're pathfinding backwards */
+ if (GetTunnelBridgeDirection(tile) == direction) {
+ tile = SkipToEndOfTunnel(tpf, tile, direction);
+ } else if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
+ /* We don't support moving through the sides of a tunnel
+ * entrance :-) */
+ return;
+ }
+ } else { // IsBridge(tile)
+ TileIndex tile_end;
+ if (GetTunnelBridgeDirection(tile) != direction ||
+ GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
+ return;
+ }
+ //fprintf(stderr, "%s: Planning over bridge\n", __func__);
+ // TODO doesn't work - WHAT doesn't work?
+ TPFSetTileBit(tpf, tile, 14);
+ tile_end = GetOtherBridgeEnd(tile);
+ tpf->rd.cur_length += DistanceManhattan(tile, tile_end);
+ tile = tile_end;
+ TPFSetTileBit(tpf, tile, 14);
+ }
+ }
+ tile += TileOffsByDiagDir(direction);
+
/* Check in case of rail if the owner is the same */
if (tpf->tracktype == TRANSPORT_RAIL) {
/* don't enter train depot from the back */
@@ -294,84 +323,6 @@ static inline void TPFMode1_NormalCase(TrackPathFinder* tpf, TileIndex tile, Til
}
}
-static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
-{
- TileIndex tile_org = tile;
-
- if (IsTileType(tile, MP_TUNNELBRIDGE)) {
- if (IsTunnel(tile)) {
- if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
- return;
- }
- /* Only skip through the tunnel if heading inwards. We can
- * be headed outwards if our starting position was in a
- * tunnel and we're pathfinding backwards */
- if (GetTunnelBridgeDirection(tile) == direction) {
- tile = SkipToEndOfTunnel(tpf, tile, direction);
- } else if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
- /* We don't support moving through the sides of a tunnel
- * entrance :-) */
- return;
- }
- } else { // IsBridge(tile)
- TileIndex tile_end;
- if (GetTunnelBridgeDirection(tile) != direction ||
- GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
- return;
- }
- //fprintf(stderr, "%s: Planning over bridge\n", __func__);
- // TODO doesn't work - WHAT doesn't work?
- TPFSetTileBit(tpf, tile, 14);
- tile_end = GetOtherBridgeEnd(tile);
- tpf->rd.cur_length += DistanceManhattan(tile, tile_end);
- tile = tile_end;
- TPFSetTileBit(tpf, tile, 14);
- }
- }
- tile += TileOffsByDiagDir(direction);
-
- TPFMode1_NormalCase(tpf, tile, tile_org, direction);
-
- /* the next is only used when signals are checked.
- * seems to go in 2 directions simultaneously */
-
- /* if i can get rid of this, tail end recursion can be used to minimize
- * stack space dramatically. */
-
- /* If we are doing signal setting, we must reverse at evere tile, so we
- * iterate all the tracks in a signal block, even when a normal train would
- * not reach it (for example, when two lines merge */
- if (tpf->hasbit_13)
- return;
-
- direction = ReverseDiagDir(direction);
- tile += TileOffsByDiagDir(direction);
-
- uint bits = GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type);
- bits |= (bits >> 8);
-
- if ( (byte)bits != tpf->var2) {
- bits &= _bits_mask[direction];
- }
-
- bits &= 0xBF;
- if (bits == 0)
- return;
-
- do {
- uint i = FIND_FIRST_BIT(bits);
- bits = KillFirstBit(bits);
-
- tpf->the_dir = (Trackdir)((_otherdir_mask[direction] & (byte)(1 << i)) ? (i + 8) : i);
- RememberData rd = tpf->rd;
- if (TPFSetTileBit(tpf, tile, tpf->the_dir) &&
- !tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length, &tpf->rd.pft_var6) ) {
- TPFMode1(tpf, tile, _tpf_new_direction[tpf->the_dir]);
- }
- tpf->rd = rd;
- } while (bits != 0);
-}
-
void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data)
{
TrackPathFinder tpf;
@@ -391,7 +342,6 @@ void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection dire
tpf.var2 = HasBit(flags, 15) ? 0x43 : 0xFF; // 0x8000
tpf.disable_tile_hash = HasBit(flags, 12); // 0x1000
- tpf.hasbit_13 = HasBit(flags, 13); // 0x2000
tpf.tracktype = (TransportType)(flags & 0xFF);
diff --git a/src/pathfind.h b/src/pathfind.h
index d381b45a4..53eb6062a 100644
--- a/src/pathfind.h
+++ b/src/pathfind.h
@@ -60,7 +60,6 @@ struct TrackPathFinder {
byte var2;
bool disable_tile_hash;
- bool hasbit_13;
uint16 hash_head[0x400];
TileIndex hash_tile[0x400]; ///< stores the link index when multi link.
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index eacfad673..ead635e48 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -439,7 +439,7 @@ static const Depot* FindClosestRoadDepot(const Vehicle* v)
/* search in all directions */
for (DiagDirection i = DIAGDIR_BEGIN; i != DIAGDIR_END; i++) {
- FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, v->u.road.compatible_roadtypes, i, EnumRoadSignalFindDepot, NULL, &rfdd);
+ FollowTrack(tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, i, EnumRoadSignalFindDepot, NULL, &rfdd);
}
if (rfdd.best_length == (uint)-1) return NULL;
@@ -1280,7 +1280,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)-1;
frd.mindist = (uint)-1;
- FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, v->u.road.compatible_roadtypes, _road_pf_directions[i], EnumRoadTrackFindDist, NULL, &frd);
+ FollowTrack(tile, 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 bddf94a94..11d7f572e 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -479,7 +479,7 @@ static uint FindShipTrack(Vehicle *v, TileIndex tile, DiagDirection dir, TrackBi
pfs.best_bird_dist = (uint)-1;
pfs.best_length = (uint)-1;
- FollowTrack(tile, 0x3800 | TRANSPORT_WATER, 0, (DiagDirection)_ship_search_directions[i][dir], (TPFEnumProc*)ShipTrackFollower, NULL, &pfs);
+ FollowTrack(tile, 0x1800 | TRANSPORT_WATER, 0, (DiagDirection)_ship_search_directions[i][dir], (TPFEnumProc*)ShipTrackFollower, NULL, &pfs);
if (best_track != INVALID_TRACK) {
if (pfs.best_bird_dist != 0) {