* Handle aircraft movement/decision making in an airport hangar. * @param v Aircraft in the hangar. * @param apc Airport description containing the hangar. */
| 1529 | * @param apc Airport description containing the hangar. |
| 1530 | */ |
| 1531 | static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *apc) |
| 1532 | { |
| 1533 | /* if we just arrived, execute EnterHangar first */ |
| 1534 | if (v->previous_pos != v->pos) { |
| 1535 | AircraftEventHandler_EnterHangar(v, apc); |
| 1536 | return; |
| 1537 | } |
| 1538 | |
| 1539 | /* if we were sent to the depot, stay there */ |
| 1540 | if (v->current_order.IsType(OT_GOTO_DEPOT) && v->vehstatus.Test(VehState::Stopped)) { |
| 1541 | v->current_order.Free(); |
| 1542 | return; |
| 1543 | } |
| 1544 | |
| 1545 | /* Check if we should wait here for unbunching. */ |
| 1546 | if (v->IsWaitingForUnbunching()) return; |
| 1547 | |
| 1548 | if (!v->current_order.IsType(OT_GOTO_STATION) && |
| 1549 | !v->current_order.IsType(OT_GOTO_DEPOT)) |
| 1550 | return; |
| 1551 | |
| 1552 | /* We are leaving a hangar, but have to go to the exact same one; re-enter */ |
| 1553 | if (v->current_order.IsType(OT_GOTO_DEPOT) && v->current_order.GetDestination() == v->targetairport) { |
| 1554 | VehicleEnterDepot(v); |
| 1555 | return; |
| 1556 | } |
| 1557 | |
| 1558 | /* if the block of the next position is busy, stay put */ |
| 1559 | if (AirportHasBlock(v, &apc->layout[v->pos], apc)) return; |
| 1560 | |
| 1561 | /* We are already at the target airport, we need to find a terminal */ |
| 1562 | if (v->current_order.GetDestination() == v->targetairport) { |
| 1563 | /* FindFreeTerminal: |
| 1564 | * 1. Find a free terminal, 2. Occupy it, 3. Set the vehicle's state to that terminal */ |
| 1565 | if (v->subtype == AIR_HELICOPTER) { |
| 1566 | if (!AirportFindFreeHelipad(v, apc)) return; // helicopter |
| 1567 | } else { |
| 1568 | if (!AirportFindFreeTerminal(v, apc)) return; // airplane |
| 1569 | } |
| 1570 | } else { // Else prepare for launch. |
| 1571 | /* airplane goto state takeoff, helicopter to helitakeoff */ |
| 1572 | v->state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF; |
| 1573 | } |
| 1574 | const Station *st = Station::GetByTile(v->tile); |
| 1575 | AircraftLeaveHangar(v, st->airport.GetHangarExitDirection(v->tile)); |
| 1576 | AirportMove(v, apc); |
| 1577 | } |
| 1578 | |
| 1579 | /** At one of the Airport's Terminals */ |
| 1580 | static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *apc) |
nothing calls this directly
no test coverage detected