From 07a4c6afa8901a69eb54338c7070ab2ccb1b1d45 Mon Sep 17 00:00:00 2001 From: cirdan Date: Sat, 9 Sep 2017 17:42:44 +0200 Subject: [PATCH] Simplify transition search in AircraftEventHandler_Flying No FLYING node in any airport finite state machine has more than one LANDING or HELILANDING transition, so there is no point in searching for another one after the first one is found. --- src/aircraft_cmd.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 0ac9419fe..94017d96d 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -1555,27 +1555,27 @@ static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc) * it is possible to choose from multiple landing runways, so loop until a free one is found */ byte landingtype = (v->subtype == AIR_HELICOPTER) ? HELILANDING : LANDING; const AirportFTA *current = apc->layout[v->pos].next; - while (current != NULL) { - if (current->heading == landingtype) { - /* save speed before, since if AirportHasBlock is false, it resets them to 0 - * we don't want that for plane in air - * hack for speed thingie */ - uint16 tcur_speed = v->cur_speed; - uint16 tsubspeed = v->subspeed; - if (!AirportHasBlock(v, current, apc)) { - v->state = landingtype; // LANDING / HELILANDING - /* it's a bit dirty, but I need to set position to next position, otherwise - * if there are multiple runways, plane won't know which one it took (because - * they all have heading LANDING). And also occupy that block! */ - v->pos = current->next_position; - SETBITS(st->airport.flags, apc->layout[v->pos].block); - return; - } - v->cur_speed = tcur_speed; - v->subspeed = tsubspeed; - } + while (current != NULL && current->heading != landingtype) { current = current->next; } + if (current != NULL) { + /* save speed before, since if AirportHasBlock is false, it resets them to 0 + * we don't want that for plane in air + * hack for speed thingie */ + uint16 tcur_speed = v->cur_speed; + uint16 tsubspeed = v->subspeed; + if (!AirportHasBlock(v, current, apc)) { + v->state = landingtype; // LANDING / HELILANDING + /* it's a bit dirty, but I need to set position to next position, otherwise + * if there are multiple runways, plane won't know which one it took (because + * they all have heading LANDING). And also occupy that block! */ + v->pos = current->next_position; + SETBITS(st->airport.flags, apc->layout[v->pos].block); + return; + } + v->cur_speed = tcur_speed; + v->subspeed = tsubspeed; + } } v->state = FLYING; v->pos = apc->layout[v->pos].next_position; -- 2.11.4.GIT