| 1672 | } |
| 1673 | |
| 1674 | static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc) |
| 1675 | { |
| 1676 | Station *st = Station::Get(v->targetairport); |
| 1677 | |
| 1678 | /* Runway busy, not allowed to use this airstation or closed, circle. */ |
| 1679 | if (CanVehicleUseStation(v, st) && (st->owner == OWNER_NONE || st->owner == v->owner) && !st->airport.blocks.Test(AirportBlock::AirportClosed)) { |
| 1680 | /* {32,FLYING,AirportBlock::Nothing,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41}, |
| 1681 | * if it is an airplane, look for LANDING, for helicopter HELILANDING |
| 1682 | * it is possible to choose from multiple landing runways, so loop until a free one is found */ |
| 1683 | uint8_t landingtype = (v->subtype == AIR_HELICOPTER) ? HELILANDING : LANDING; |
| 1684 | const AirportFTA *current = apc->layout[v->pos].next.get(); |
| 1685 | while (current != nullptr) { |
| 1686 | if (current->heading == landingtype) { |
| 1687 | /* save speed before, since if AirportHasBlock is false, it resets them to 0 |
| 1688 | * we don't want that for plane in air |
| 1689 | * hack for speed thingy */ |
| 1690 | uint16_t tcur_speed = v->cur_speed; |
| 1691 | uint16_t tsubspeed = v->subspeed; |
| 1692 | if (!AirportHasBlock(v, current, apc)) { |
| 1693 | v->state = landingtype; // LANDING / HELILANDING |
| 1694 | if (v->state == HELILANDING) SetBit(v->flags, VAF_HELI_DIRECT_DESCENT); |
| 1695 | /* it's a bit dirty, but I need to set position to next position, otherwise |
| 1696 | * if there are multiple runways, plane won't know which one it took (because |
| 1697 | * they all have heading LANDING). And also occupy that block! */ |
| 1698 | v->pos = current->next_position; |
| 1699 | st->airport.blocks.Set(apc->layout[v->pos].blocks); |
| 1700 | return; |
| 1701 | } |
| 1702 | v->cur_speed = tcur_speed; |
| 1703 | v->subspeed = tsubspeed; |
| 1704 | } |
| 1705 | current = current->next.get(); |
| 1706 | } |
| 1707 | } |
| 1708 | v->state = FLYING; |
| 1709 | v->pos = apc->layout[v->pos].next_position; |
| 1710 | } |
| 1711 | |
| 1712 | static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *) |
| 1713 | { |
nothing calls this directly
no test coverage detected