| 1 | /* |
| 2 | * SPDX-FileCopyrightText: (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt |
| 3 | * SPDX_FileComment: represent a runway or taxiway |
| 4 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #include <config.h> |
| 8 | |
| 9 | #include <simgear/compiler.h> |
| 10 | #include <simgear/magvar/magvar.hxx> |
| 11 | #include <simgear/props/props.hxx> |
| 12 | #include <simgear/timing/sg_time.hxx> |
| 13 | |
| 14 | #include "runwaybase.hxx" |
| 15 | |
| 16 | #include <Airports/airport.hxx> |
| 17 | #include <Main/globals.hxx> |
| 18 | |
| 19 | using std::string; |
| 20 | |
| 21 | /* |
| 22 | * surface codes, defined here (as of Jan 2024) https://developer.x-plane.com/article/airport-data-apt-dat-12-00-file-format-specification/ |
| 23 | * 1,20-38 - asphalt |
| 24 | * 2,50-57 - concrete |
| 25 | * 3 - turf |
| 26 | * 4 - dirt |
| 27 | * 5 - gravel |
| 28 | * 12 - lakebed |
| 29 | * 13 - water runway |
| 30 | * 14 - snow or ice |
| 31 | * 15 - Transparent |
| 32 | */ |
| 33 | const char * FGRunwayBase::surfaceName( int surface_code ) |
| 34 | { |
| 35 | switch( surface_code ) { |
| 36 | case 1: |
| 37 | case 20: // Light colored asphalt |
| 38 | case 21: |
| 39 | case 22: |
| 40 | case 23: |
| 41 | case 24: // Asphalt |
| 42 | case 25: |
| 43 | case 26: |
| 44 | case 27: // Darker colored asphalt |
| 45 | case 28: |
| 46 | case 29: |
| 47 | case 30: |
| 48 | case 31: // Very dark colored asphalt |
| 49 | case 32: |
| 50 | case 33: |
| 51 | case 34: |
| 52 | case 35: // Near black, ‘new’ looking asphalt |
| 53 | case 36: |
| 54 | case 37: |
| 55 | case 38: |
| 56 | return "asphalt"; |
| 57 | case 2: |
| 58 | case 50: // Light “new” looking concrete |
| 59 | case 51: |
| 60 | case 52: |
| 61 | case 53: // Concrete |
| 62 | case 54: |
| 63 | case 55: // Dark concrete |
| 64 | case 56: |
| 65 | case 57: |
| 66 | return "concrete"; |
| 67 | case 3: return "turf"; |
| 68 | case 4: return "dirt"; |
| 69 | case 5: return "gravel"; |
| 70 | case 12: return "lakebed"; |
| 71 | case 13: return "water"; |
| 72 | case 14: return "ice"; |
| 73 | case 15: return "transparent"; |
| 74 | default: return "unknown"; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | FGRunwayBase::FGRunwayBase(PositionedID aGuid, Type aTy, const string& aIdent, |
| 79 | const SGGeod& aGeod, |
| 80 | const double heading, const double length, |
| 81 | const double width, |
| 82 | const int surface_code, |
| 83 | const PositionedID airportId) : FGPositioned(aGuid, aTy, aIdent, aGeod) |
| 84 | { |
| 85 | _heading = heading; |
| 86 | _length = length; |
| 87 | _width = width; |
| 88 | _surface_code = surface_code; |
| 89 | mAirport = airportId; |
| 90 | } |
| 91 | |
| 92 | FGAirportRef FGRunwayBase::airport() const |
| 93 | { |
| 94 | return FGPositioned::loadById<FGAirport>(mAirport); |
| 95 | } |
| 96 | |
| 97 | SGGeod FGRunwayBase::pointOnCenterline(double aOffset) const |
| 98 | { |
| 99 | SGGeod result = SGGeodesy::direct(geod(), _heading, aOffset); |
| 100 | result.setElevationM(geod().getElevationM()); |
| 101 | |
| 102 | return result; |
| 103 | } |
| 104 | |
| 105 | SGGeod FGRunwayBase::pointOffCenterline(double aOffset, double lateralOffset) const |
| 106 | { |
| 107 | SGGeod result = pointOnCenterline(aOffset); |
| 108 | return SGGeodesy::direct(result, SGMiscd::normalizePeriodic(0, 360,_heading+90.0), lateralOffset); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | bool FGRunwayBase::isHardSurface() const |
| 113 | { |
| 114 | return ((_surface_code == 1 || (_surface_code >= 20 && _surface_code <= 38)) || (_surface_code == 2 || (_surface_code >= 50 && _surface_code <= 57))); |
| 115 | } |
| 116 | |
| 117 | FGTaxiway::FGTaxiway(PositionedID aGuid, |
| 118 | const string& aIdent, |
| 119 | const SGGeod& aGeod, |
| 120 | const double heading, const double length, |
| 121 | const double width, |
| 122 | const int surface_code, |
| 123 | const PositionedID airportId) : FGRunwayBase(aGuid, TAXIWAY, aIdent, aGeod, heading, length, width, surface_code, airportId) |
| 124 | { |
| 125 | } |
| 126 | |
| 127 | double FGRunwayBase::magneticHeadingDeg() const |
| 128 | { |
| 129 | const double jd = globals->get_time_params()->getJD(); |
| 130 | const auto var = sgGetMagVar(geod(), jd) * SG_RADIANS_TO_DEGREES; |
| 131 | return SGMiscd::normalizePeriodic(0, 360, _heading - var); |
| 132 | } |