]> git.mxchange.org Git - flightgear.git/blob - src/Airports/runways.cxx
fa92e91d5539d86b7e248fd97af464c781188260
[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 FGRunway::FGRunway()
46 {
47 }
48
49 FGRunway::FGRunway( const string& id, const string& rwy_no,
50                         const double longitude, const double latitude,
51                         const double heading, const double length,
52                         const double width,
53                         const double displ_thresh1, const double displ_thresh2,
54                         const double stopway1, const double stopway2,
55                         const string& lighting_flags, const int surface_code,
56                         const string& shoulder_code, const int marking_code,
57                         const double smoothness, const bool dist_remaining )
58 {
59   _rwy_no = rwy_no;
60   if (rwy_no[0] == 'x') {
61     _type = "taxiway";
62   } else {
63     _type = "runway";
64     
65   // canonicalise runway ident
66     if ((rwy_no.size() == 1) || !isdigit(rwy_no[1])) {
67           _rwy_no = "0" + rwy_no;
68     }
69
70     if ((_rwy_no.size() > 2) && (_rwy_no[2] == 'x')) {
71       _rwy_no = _rwy_no.substr(0, 2);
72     }
73   }
74
75   _id = id;
76   _lon = longitude;
77   _lat = latitude;
78   _heading = heading;
79   _length = length;
80   _width = width;
81   _displ_thresh1 = displ_thresh1;
82   _displ_thresh2 = displ_thresh2;
83   _stopway1 = stopway1;
84   _stopway2 = stopway2;
85
86   _lighting_flags = lighting_flags;
87   _surface_code = surface_code;
88   _shoulder_code = shoulder_code;
89   _marking_code = marking_code;
90   _smoothness = smoothness;
91   _dist_remaining = dist_remaining;
92 }
93
94 string FGRunway::reverseIdent(const string& aRunwayIdent)
95 {
96   // Helipads don't have a seperate number per end
97   if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
98     return aRunwayIdent;
99   }
100
101   std::string ident(aRunwayIdent);
102     
103   char buf[4];
104   int rn = atoi(ident.substr(0,2).c_str());
105   rn += 18;
106   while(rn > 36) {
107           rn -= 36;
108   }
109   
110   sprintf(buf, "%02i", rn);
111   if(ident.size() == 3) {
112     if(ident.substr(2,1) == "L") {
113         buf[2] = 'R';
114         buf[3] = '\0';
115     } else if (ident.substr(2,1) == "R") {
116         buf[2] = 'L';
117         buf[3] = '\0';
118     } else if (ident.substr(2,1) == "C") {
119         buf[2] = 'C';
120         buf[3] = '\0';
121     } else if (ident.substr(2,1) == "T") {
122         buf[2] = 'T';
123         buf[3] = '\0';
124     } else {
125         SG_LOG(SG_GENERAL, SG_ALERT, "Unknown runway code "
126         << aRunwayIdent << " passed to FGRunway::reverseIdent");
127     }
128   }
129   
130   return buf;
131 }
132
133 double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
134 {
135   int surface = 1;
136   if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
137     surface = 2;
138   else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
139     surface = 3;
140     
141   return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
142 }
143
144 bool FGRunway::isTaxiway() const
145 {
146   return (_rwy_no[0] == 'x');
147 }