1 // runways.cxx -- a simple class to manage airport runway info
3 // Written by Curtis Olson, started August 2000.
5 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
28 #include <cmath> // fabs()
29 #include <cstdio> // sprintf()
30 #include <cstdlib> // atoi()
32 #include <simgear/compiler.h>
33 #include <simgear/debug/logstream.hxx>
34 #include <Main/fg_props.hxx>
39 #include "runways.hxx"
49 FGRunway::FGRunway( const string& id, const string& rwy_no,
50 const double longitude, const double latitude,
51 const double heading, const double length,
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 )
60 if (rwy_no[0] == 'x') {
65 // canonicalise runway ident
66 if ((rwy_no.size() == 1) || !isdigit(rwy_no[1])) {
67 _rwy_no = "0" + rwy_no;
70 if ((_rwy_no.size() > 2) && (_rwy_no[2] == 'x')) {
71 _rwy_no = _rwy_no.substr(0, 2);
81 _displ_thresh1 = displ_thresh1;
82 _displ_thresh2 = displ_thresh2;
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;
94 string FGRunway::reverseIdent(const string& aRunwayIdent)
96 // Helipads don't have a seperate number per end
97 if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
101 std::string ident(aRunwayIdent);
104 int rn = atoi(ident.substr(0,2).c_str());
110 sprintf(buf, "%02i", rn);
111 if(ident.size() == 3) {
112 if(ident.substr(2,1) == "L") {
115 } else if (ident.substr(2,1) == "R") {
118 } else if (ident.substr(2,1) == "C") {
121 } else if (ident.substr(2,1) == "T") {
125 SG_LOG(SG_GENERAL, SG_ALERT, "Unknown runway code "
126 << aRunwayIdent << " passed to FGRunway::reverseIdent");
133 double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
136 if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
138 else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
141 return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
144 bool FGRunway::isTaxiway() const
146 return (_rwy_no[0] == 'x');