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& 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 int surface_code)
58 if (rwy_no[0] == 'x') {
63 // canonicalise runway ident
64 if ((rwy_no.size() == 1) || !isdigit(rwy_no[1])) {
65 _rwy_no = "0" + rwy_no;
68 if ((_rwy_no.size() > 2) && (_rwy_no[2] == 'x')) {
69 _rwy_no = _rwy_no.substr(0, 2);
78 _displ_thresh1 = displ_thresh1;
79 _displ_thresh2 = displ_thresh2;
83 _surface_code = surface_code;
86 string FGRunway::reverseIdent(const string& aRunwayIdent)
88 // Helipads don't have a seperate number per end
89 if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
93 std::string ident(aRunwayIdent);
96 int rn = atoi(ident.substr(0,2).c_str());
102 sprintf(buf, "%02i", rn);
103 if(ident.size() == 3) {
104 if(ident.substr(2,1) == "L") {
107 } else if (ident.substr(2,1) == "R") {
110 } else if (ident.substr(2,1) == "C") {
113 } else if (ident.substr(2,1) == "T") {
117 SG_LOG(SG_GENERAL, SG_ALERT, "Unknown runway code "
118 << aRunwayIdent << " passed to FGRunway::reverseIdent");
125 double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
128 if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
130 else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
133 return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
136 bool FGRunway::isTaxiway() const
138 return (_rwy_no[0] == 'x');