diff options
author | Patric Stout <truebrain@openttd.org> | 2021-01-11 20:10:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-11 20:10:53 +0100 |
commit | fe86bf8bf66775201924d01b14e3de821ab81902 (patch) | |
tree | b1558021d8422e65d893b18d8b8d612bcce7152b /src | |
parent | eb23a6921bdb6f00ecd0f92b9feb3569d501ee85 (diff) | |
download | openttd-fe86bf8bf66775201924d01b14e3de821ab81902.tar.xz |
Fix #7619: nudge fast planes sooner towards their target (#8531)
For non-NewGRF planes, "count" is never above 1. So planes can
smoothly be guided to their destination. For NewGRF planes, they
can go as quick as "count" values of 20. This easily overshoots
the target. So, calculate if the plane will overshoot, and start
nudging him to the destination earlier. You won't notice this
either way, as it all happens within a single tick.
Diffstat (limited to 'src')
-rw-r--r-- | src/aircraft_cmd.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 475bd7b12..0495da0b2 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -856,8 +856,6 @@ static void MaybeCrashAirplane(Aircraft *v); */ static bool AircraftController(Aircraft *v) { - int count; - /* nullptr if station is invalid */ const Station *st = Station::GetIfValid(v->targetairport); /* INVALID_TILE if there is no station */ @@ -917,7 +915,7 @@ static bool AircraftController(Aircraft *v) } } else { u->cur_speed = 32; - count = UpdateAircraftSpeed(v); + int count = UpdateAircraftSpeed(v); if (count > 0) { v->tile = 0; @@ -972,7 +970,7 @@ static bool AircraftController(Aircraft *v) } u->cur_speed += 4; } else { - count = UpdateAircraftSpeed(v); + int count = UpdateAircraftSpeed(v); if (count > 0) { if (v->z_pos > z) { SetAircraftPosition(v, v->x_pos, v->y_pos, std::max(v->z_pos - count, z)); @@ -1023,16 +1021,23 @@ static bool AircraftController(Aircraft *v) if (amd.flag & AMED_LAND) { speed_limit = SPEED_LIMIT_APPROACH; hard_limit = false; } if (amd.flag & AMED_BRAKE) { speed_limit = SPEED_LIMIT_TAXI; hard_limit = false; } - count = UpdateAircraftSpeed(v, speed_limit, hard_limit); + int count = UpdateAircraftSpeed(v, speed_limit, hard_limit); if (count == 0) return false; + /* If the plane will be a few subpixels away from the destination after + * this movement loop, start nudging him towards the exact position for + * the whole loop. Otherwise, heavily depending on the speed of the plane, + * it is possible we totally overshoot the target, causing the plane to + * make a loop, and trying again, and again, and again .. */ + bool nudge_towards_target = static_cast<uint>(count) + 3 > dist; + if (v->turn_counter != 0) v->turn_counter--; do { GetNewVehiclePosResult gp; - if (dist < 4 || (amd.flag & AMED_LAND)) { + if (nudge_towards_target || (amd.flag & AMED_LAND)) { /* move vehicle one pixel towards target */ gp.x = (v->x_pos != (x + amd.x)) ? v->x_pos + ((x + amd.x > v->x_pos) ? 1 : -1) : |