MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / AircraftEventHandler

Function AircraftEventHandler

src/aircraft_cmd.cpp:2098–2132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2096}
2097
2098static 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
2134bool Aircraft::Tick()
2135{

Callers 1

TickMethod · 0.85

Calls 13

HandleCrashedAircraftFunction · 0.85
HandleAircraftSmokeFunction · 0.85
ProcessOrdersFunction · 0.85
AircraftHandleDestTooFarFunction · 0.85
DistanceSquareFunction · 0.85
HasBitFunction · 0.85
AirportGoToNextPositionFunction · 0.85
TestMethod · 0.80
HandleBreakdownMethod · 0.80
HandleLoadingMethod · 0.80
IsTypeMethod · 0.80
GetDestinationMethod · 0.80

Tested by

no test coverage detected