| 2096 | } |
| 2097 | |
| 2098 | static bool AircraftEventHandler(Aircraft *v, int loop) |
| 2099 | { |
| 2100 | if (v->vehstatus.Test(VehState::Crashed)) { |
| 2101 | return HandleCrashedAircraft(v); |
| 2102 | } |
| 2103 | |
| 2104 | if (v->vehstatus.Test(VehState::Stopped)) return true; |
| 2105 | |
| 2106 | v->HandleBreakdown(); |
| 2107 | |
| 2108 | HandleAircraftSmoke(v, loop != 0); |
| 2109 | ProcessOrders(v); |
| 2110 | v->HandleLoading(loop != 0); |
| 2111 | |
| 2112 | if (v->current_order.IsType(OT_LOADING) || v->current_order.IsType(OT_LEAVESTATION)) return true; |
| 2113 | |
| 2114 | if (v->state >= ENDTAKEOFF && v->state <= HELIENDLANDING) { |
| 2115 | /* If we are flying, unconditionally clear the 'dest too far' state. */ |
| 2116 | AircraftHandleDestTooFar(v, false); |
| 2117 | } else if (v->acache.cached_max_range_sqr != 0) { |
| 2118 | /* Check the distance to the next destination. This code works because the target |
| 2119 | * airport is only updated after take off and not on the ground. */ |
| 2120 | Station *cur_st = Station::GetIfValid(v->targetairport); |
| 2121 | Station *next_st = v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_DEPOT) ? Station::GetIfValid(v->current_order.GetDestination().ToStationID()) : nullptr; |
| 2122 | |
| 2123 | if (cur_st != nullptr && cur_st->airport.tile != INVALID_TILE && next_st != nullptr && next_st->airport.tile != INVALID_TILE) { |
| 2124 | uint dist = DistanceSquare(cur_st->airport.tile, next_st->airport.tile); |
| 2125 | AircraftHandleDestTooFar(v, dist > v->acache.cached_max_range_sqr); |
| 2126 | } |
| 2127 | } |
| 2128 | |
| 2129 | if (!HasBit(v->flags, VAF_DEST_TOO_FAR)) AirportGoToNextPosition(v); |
| 2130 | |
| 2131 | return true; |
| 2132 | } |
| 2133 | |
| 2134 | bool Aircraft::Tick() |
| 2135 | { |
no test coverage detected