From 6a10a276cd1ad45b92f588da6ecc24f4a38bb99a Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 20 Dec 2009 10:05:20 +0100 Subject: [PATCH] atc - Fix bug related to delayed command and altitude change When playing atc, if a plane has a delayed turn command, and you issue an altitude command that would send the plane to the same altitude to which it is already going, the delay is disabled and the plane turns immediately. Fix is from OpenBSD (PR 3448). Discussed-with: swildner@ Provided-by: 26c3 --- games/atc/input.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/games/atc/input.c b/games/atc/input.c index dbe85745e7..18cd41944a 100644 --- a/games/atc/input.c +++ b/games/atc/input.c @@ -525,6 +525,8 @@ setalt(int c) { if ((p.altitude == c - '0') && (p.new_altitude == p.altitude)) return ("Already at that altitude"); + if (p.new_altitude == c - '0') + return ("Already going to that altitude"); p.new_altitude = c - '0'; return (NULL); } @@ -532,24 +534,30 @@ setalt(int c) static const char * setrelalt(int c) { + int new_altitude; + if (c == 0) return ("altitude not changed"); switch (dir) { case D_UP: - p.new_altitude = p.altitude + c - '0'; + new_altitude = p.altitude + c - '0'; break; case D_DOWN: - p.new_altitude = p.altitude - (c - '0'); + new_altitude = p.altitude - (c - '0'); break; default: return ("Unknown case in setrelalt! Get help!"); break; } - if (p.new_altitude < 0) + if (new_altitude < 0) return ("Altitude would be too low"); - else if (p.new_altitude > 9) + else if (new_altitude > 9) return ("Altitude would be too high"); + else if (new_altitude == p.new_altitude) + return ("Already going to that altitude"); + + p.new_altitude = new_altitude; return (NULL); } -- 2.41.0