summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Nelson <peter1138@openttd.org>2018-05-23 17:34:39 +0100
committerCharles Pigott <charlespigott@googlemail.com>2019-01-14 19:57:07 +0000
commit8b6420441814e95ca32ffd4c601e3646f840c58c (patch)
treec04d80a835349991c4746277ebdf96ff28a6d225 /src
parent7af53d7588a97bc4b02dbfa456a0e2a9ab598864 (diff)
downloadopenttd-8b6420441814e95ca32ffd4c601e3646f840c58c.tar.xz
Codechange: Replace trackbit lookup table with existing functions.
Diffstat (limited to 'src')
-rw-r--r--src/ship_cmd.cpp21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 79560be04..88e2392e0 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -461,23 +461,10 @@ static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, Tr
if (v->dest_tile == 0 || DistanceManhattan(tile, v->dest_tile) > SHIP_MAX_ORDER_DISTANCE + 5) {
/* No destination or destination too far, don't invoke pathfinder. */
- static const TrackBits direction_to_trackbits[DIR_END] = {
- TRACK_BIT_LEFT | TRACK_BIT_RIGHT, // DIR_N
- TRACK_BIT_X, // DIR_NE
- TRACK_BIT_UPPER | TRACK_BIT_LOWER, // DIR_E
- TRACK_BIT_Y, // DIR_SE
- TRACK_BIT_LEFT | TRACK_BIT_RIGHT, // DIR_S
- TRACK_BIT_X, // DIR_SW
- TRACK_BIT_UPPER | TRACK_BIT_LOWER, // DIR_W
- TRACK_BIT_Y, // DIR_NW
- };
-
- TrackBits next_tracks = direction_to_trackbits[v->direction] & tracks;
- if (next_tracks != TRACK_BIT_NONE) {
- /* Continue in same direction when possible. */
- track = (Track)FindFirstBit(next_tracks);
- } else {
- /* Pick a random track. */
+ track = TrackBitsToTrack(v->state);
+ if (track != TRACK_X && track != TRACK_Y) track = TrackToOppositeTrack(track);
+ if (!HasBit(tracks, track)) {
+ /* Can't continue in same direction so pick a random available track. */
do {
track = (Track)RandomRange(TRACK_END);
} while ((TrackToTrackBits(track) & tracks) == TRACK_BIT_NONE);