1
0
Fork 0
flightgear/src/Airports/runways.cxx

140 lines
3.7 KiB
C++
Raw Normal View History

// runways.cxx -- a simple class to manage airport runway info
2000-08-16 01:28:33 +00:00
//
// Written by Curtis Olson, started August 2000.
//
// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
2000-08-16 01:28:33 +00:00
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
2006-02-21 01:16:04 +00:00
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2000-08-16 01:28:33 +00:00
//
// $Id$
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <cmath> // fabs()
#include <cstdio> // sprintf()
#include <cstdlib> // atoi()
2000-08-16 01:28:33 +00:00
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
#include <Main/fg_props.hxx>
2000-08-16 01:28:33 +00:00
#include <string>
#include <map>
2000-08-16 01:28:33 +00:00
#include "runways.hxx"
using std::istream;
using std::multimap;
using std::string;
2000-08-16 01:28:33 +00:00
FGRunway::FGRunway()
{
}
2000-08-16 01:28:33 +00:00
FGRunway::FGRunway(const string& rwy_no,
const double longitude, const double latitude,
const double heading, const double length,
const double width,
const double displ_thresh1, const double displ_thresh2,
const double stopway1, const double stopway2,
const int surface_code)
{
_rwy_no = rwy_no;
if (rwy_no[0] == 'x') {
_type = "taxiway";
} else {
_type = "runway";
// canonicalise runway ident
if ((rwy_no.size() == 1) || !isdigit(rwy_no[1])) {
_rwy_no = "0" + rwy_no;
2000-08-16 01:28:33 +00:00
}
if ((_rwy_no.size() > 2) && (_rwy_no[2] == 'x')) {
_rwy_no = _rwy_no.substr(0, 2);
}
}
_lon = longitude;
_lat = latitude;
_heading = heading;
_length = length;
_width = width;
_displ_thresh1 = displ_thresh1;
_displ_thresh2 = displ_thresh2;
_stopway1 = stopway1;
_stopway2 = stopway2;
_surface_code = surface_code;
2000-08-16 01:28:33 +00:00
}
string FGRunway::reverseIdent(const string& aRunwayIdent)
{
// Helipads don't have a seperate number per end
if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
return aRunwayIdent;
}
2000-08-16 01:28:33 +00:00
std::string ident(aRunwayIdent);
char buf[4];
int rn = atoi(ident.substr(0,2).c_str());
rn += 18;
while(rn > 36) {
rn -= 36;
}
sprintf(buf, "%02i", rn);
if(ident.size() == 3) {
if(ident.substr(2,1) == "L") {
buf[2] = 'R';
buf[3] = '\0';
} else if (ident.substr(2,1) == "R") {
buf[2] = 'L';
buf[3] = '\0';
} else if (ident.substr(2,1) == "C") {
buf[2] = 'C';
buf[3] = '\0';
} else if (ident.substr(2,1) == "T") {
buf[2] = 'T';
buf[3] = '\0';
} else {
SG_LOG(SG_GENERAL, SG_ALERT, "Unknown runway code "
<< aRunwayIdent << " passed to FGRunway::reverseIdent");
}
}
return buf;
2000-08-16 01:28:33 +00:00
}
double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
{
int surface = 1;
if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
surface = 2;
else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
surface = 3;
return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
2000-08-16 01:28:33 +00:00
}
bool FGRunway::isTaxiway() const
{
return (_rwy_no[0] == 'x');
2000-08-16 01:28:33 +00:00
}