* Find the entry point to an airport depending on direction which * the airport is being approached from. Each airport can have up to * four entry points for its approach system so that approaching * aircraft do not fly through each other or are forced to do 180 * degree turns during the approach. The arrivals are grouped into * four sectors dependent on the DiagDirection from which the airpo
| 822 | * @return The index of the entry point |
| 823 | */ |
| 824 | static uint8_t AircraftGetEntryPoint(const Aircraft *v, const AirportFTAClass *apc, Direction rotation) |
| 825 | { |
| 826 | assert(v != nullptr); |
| 827 | assert(apc != nullptr); |
| 828 | |
| 829 | /* In the case the station doesn't exit anymore, set target tile 0. |
| 830 | * It doesn't hurt much, aircraft will go to next order, nearest hangar |
| 831 | * or it will simply crash in next tick */ |
| 832 | TileIndex tile{}; |
| 833 | |
| 834 | const Station *st = Station::GetIfValid(v->targetairport); |
| 835 | if (st != nullptr) { |
| 836 | /* Make sure we don't go to INVALID_TILE if the airport has been removed. */ |
| 837 | tile = (st->airport.tile != INVALID_TILE) ? st->airport.tile : st->xy; |
| 838 | } |
| 839 | |
| 840 | int delta_x = v->x_pos - TileX(tile) * TILE_SIZE; |
| 841 | int delta_y = v->y_pos - TileY(tile) * TILE_SIZE; |
| 842 | |
| 843 | DiagDirection dir; |
| 844 | if (abs(delta_y) < abs(delta_x)) { |
| 845 | /* We are northeast or southwest of the airport */ |
| 846 | dir = delta_x < 0 ? DIAGDIR_NE : DIAGDIR_SW; |
| 847 | } else { |
| 848 | /* We are northwest or southeast of the airport */ |
| 849 | dir = delta_y < 0 ? DIAGDIR_NW : DIAGDIR_SE; |
| 850 | } |
| 851 | dir = ChangeDiagDir(dir, DiagDirDifference(DIAGDIR_NE, DirToDiagDir(rotation))); |
| 852 | return apc->entry_points[dir]; |
| 853 | } |
| 854 | |
| 855 | |
| 856 | static void MaybeCrashAirplane(Aircraft *v); |
no test coverage detected