summaryrefslogtreecommitdiff
path: root/src/ship_cmd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ship_cmd.cpp')
-rw-r--r--src/ship_cmd.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 0d8cd6c37..7f9dab0f1 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -335,13 +335,13 @@ static Vehicle *EnsureNoMovingShipProc(Vehicle *v, void *data)
return v->type == VEH_SHIP && (v->vehstatus & (VS_HIDDEN | VS_STOPPED)) == 0 ? v : nullptr;
}
-static bool CheckReverseShip(const Ship *v)
+static bool CheckReverseShip(const Ship *v, Trackdir *trackdir = nullptr)
{
/* Ask pathfinder for best direction */
bool reverse = false;
switch (_settings_game.pf.pathfinder_for_ships) {
- case VPF_NPF: reverse = NPFShipCheckReverse(v); break;
- case VPF_YAPF: reverse = YapfShipCheckReverse(v); break;
+ case VPF_NPF: reverse = NPFShipCheckReverse(v, trackdir); break;
+ case VPF_YAPF: reverse = YapfShipCheckReverse(v, trackdir); break;
default: NOT_REACHED();
}
return reverse;
@@ -725,7 +725,19 @@ static void ShipController(Ship *v)
DiagDirection diagdir = DiagdirBetweenTiles(gp.old_tile, gp.new_tile);
assert(diagdir != INVALID_DIAGDIR);
tracks = GetAvailShipTracks(gp.new_tile, diagdir);
- if (tracks == TRACK_BIT_NONE) goto reverse_direction;
+ if (tracks == TRACK_BIT_NONE) {
+ Trackdir trackdir = INVALID_TRACKDIR;
+ CheckReverseShip(v, &trackdir);
+ if (trackdir == INVALID_TRACKDIR) goto reverse_direction;
+ static const Direction _trackdir_to_direction[] = {
+ DIR_NE, DIR_SE, DIR_E, DIR_E, DIR_S, DIR_S, INVALID_DIR, INVALID_DIR,
+ DIR_SW, DIR_NW, DIR_W, DIR_W, DIR_N, DIR_N, INVALID_DIR, INVALID_DIR,
+ };
+ v->direction = _trackdir_to_direction[trackdir];
+ assert(v->direction != INVALID_DIR);
+ v->state = TrackdirBitsToTrackBits(TrackdirToTrackdirBits(trackdir));
+ goto direction_changed;
+ }
/* Choose a direction, and continue if we find one */
track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks);
@@ -796,6 +808,7 @@ getout:
reverse_direction:
v->direction = ReverseDir(v->direction);
+direction_changed:
/* Remember our current location to avoid movement glitch */
v->rotation_x_pos = v->x_pos;
v->rotation_y_pos = v->y_pos;