]> git.mxchange.org Git - flightgear.git/blob - src/Airports/runways.cxx
Add the alpha test back in so the instruments won't disappear after changing the...
[flightgear.git] / src / Airports / runways.cxx
1 // runways.cxx -- a simple class to manage airport runway info
2 //
3 // Written by Curtis Olson, started August 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <cmath>               // fabs()
29 #include <cstdio>              // sprintf()
30 #include <cstdlib>             // atoi()
31
32 #include <simgear/compiler.h>
33 #include <simgear/debug/logstream.hxx>
34 #include <Main/fg_props.hxx>
35
36 #include <string>
37 #include <map>
38
39 #include "runways.hxx"
40
41 using std::istream;
42 using std::multimap;
43 using std::string;
44
45 static FGPositioned::Type runwayTypeFromNumber(const std::string& aRwyNo)
46 {
47   return (aRwyNo[0] == 'x') ? FGPositioned::TAXIWAY : FGPositioned::RUNWAY;
48 }
49
50 static std::string cleanRunwayNo(const std::string& aRwyNo)
51 {
52   if (aRwyNo[0] == 'x') {
53     return std::string(); // no ident for taxiways
54   }
55   
56   string result(aRwyNo);
57   // canonicalise runway ident
58   if ((aRwyNo.size() == 1) || !isdigit(aRwyNo[1])) {
59           result = "0" + aRwyNo;
60   }
61
62   // trim off trailing garbage
63   if (result.size() > 2) {
64     char suffix = toupper(result[2]);
65     if (suffix == 'X') {
66        result = result.substr(0, 2);
67     }
68   }
69   
70   return result;
71 }
72
73 FGRunway::FGRunway(FGAirport* aAirport, const string& rwy_no,
74                         const double longitude, const double latitude,
75                         const double heading, const double length,
76                         const double width,
77                         const double displ_thresh,
78                         const double stopway,
79                         const int surface_code,
80                         bool reciprocal) :
81   FGPositioned(runwayTypeFromNumber(rwy_no), cleanRunwayNo(rwy_no), latitude, longitude, 0.0),
82   _airport(aAirport),
83   _reciprocal(reciprocal)
84 {
85   _rwy_no = ident();
86   
87   _lon = longitude;
88   _lat = latitude;
89   _heading = heading;
90   _length = length;
91   _width = width;
92   _displ_thresh = displ_thresh;
93   _stopway = stopway;
94
95   _surface_code = surface_code;
96 }
97
98 string FGRunway::reverseIdent(const string& aRunwayIdent)
99 {
100   // Helipads don't have a seperate number per end
101   if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
102     return aRunwayIdent;
103   }
104
105   std::string ident(aRunwayIdent);
106     
107   char buf[4];
108   int rn = atoi(ident.substr(0,2).c_str());
109   rn += 18;
110   while(rn > 36) {
111           rn -= 36;
112   }
113   
114   sprintf(buf, "%02i", rn);
115   if(ident.size() == 3) {
116     char suffix = toupper(ident[2]);
117     if(suffix == 'L') {
118       buf[2] = 'R';
119     } else if (suffix == 'R') {
120       buf[2] = 'L';
121     } else {
122       // something else, just copy
123       buf[2] = suffix;
124     }
125     
126     buf[3] = 0;
127   }
128   
129   return buf;
130 }
131
132 double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
133 {
134   int surface = 1;
135   if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
136     surface = 2;
137   else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
138     surface = 3;
139     
140   return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
141 }
142
143 bool FGRunway::isTaxiway() const
144 {
145   return (type() == TAXIWAY);
146 }
147
148 SGGeod FGRunway::threshold() const
149 {
150   return pointOnCenterline(0.0);
151 }
152
153 SGGeod FGRunway::reverseThreshold() const
154 {
155   return pointOnCenterline(lengthM());
156 }
157
158 SGGeod FGRunway::displacedThreshold() const
159 {
160   return pointOnCenterline(_displ_thresh * SG_FEET_TO_METER);
161 }
162
163 SGGeod FGRunway::pointOnCenterline(double aOffset) const
164 {
165   SGGeod result;
166   double dummyAz2;
167   double halfLengthMetres = lengthM() * 0.5;
168   
169   SGGeodesy::direct(mPosition, _heading, 
170     aOffset - halfLengthMetres,
171     result, dummyAz2);
172   return result;
173 }