#endif
#include "kln89_page_apt.hxx"
-#include <ATC/commlist.hxx>
+#include <ATCDCL/commlist.hxx>
#include <Main/globals.hxx>
+#include <Airports/runways.hxx>
+#include <Airports/simple.hxx>
// This function is copied from Airports/runways.cxx
// TODO - Make the original properly available and remove this instance!!!!
2, 0, 0, _to_flag, (_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 5 ? true : false));
} else if(_subPage == 2) {
// Try and calculate a realistic difference from UTC based on longitude
- float degLonPerHr = 360.0 / 24.0; // 15 degrees per hour difference.
// Since 0 longitude is the middle of UTC, the boundaries will be at 7.5, 22.5, 37.5 etc.
int hrDiff = ((int)((fabs(ap->getLongitude())) + 7.5)) / 15;
_kln89->DrawText("UTC", 2, 0, 2);
// I guess we can make a heuristic guess as to fuel availability from the runway sizes
// For now assume that airports with asphalt or concrete runways will have at least 100L,
// and that runways over 4000ft will have JET.
- if(_aptRwys[0]._surface_code <= 2) {
- if(_aptRwys[0]._length >= 4000) {
+ if(_aptRwys[0]->surface() <= 2) {
+ if(_aptRwys[0]->lengthFt() >= 4000) {
_kln89->DrawText("JET 100L", 2, 0, 1);
} else {
_kln89->DrawText("100L", 2, 0, 1);
string s;
if(i < _aptRwys.size()) {
// Rwy No.
- string s = _aptRwys[i]._rwy_no;
+ string s = _aptRwys[i]->ident();
_kln89->DrawText(s, 2, 9, 3);
_kln89->DrawText("/", 2, 12, 3);
_kln89->DrawText(GetReverseRunwayNo(s), 2, 13, 3);
// Length
- s = GPSitoa(int(float(_aptRwys[i]._length) * (_kln89->_altUnits == GPS_ALT_UNITS_FT ? 1.0 : SG_FEET_TO_METER) + 0.5));
+ s = GPSitoa(int(float(_aptRwys[i]->lengthFt()) * (_kln89->_altUnits == GPS_ALT_UNITS_FT ? 1.0 : SG_FEET_TO_METER) + 0.5));
_kln89->DrawText(s, 2, 5 - s.size(), 2);
_kln89->DrawText((_kln89->_altUnits == GPS_ALT_UNITS_FT ? "ft" : "m"), 2, 5, 2);
// Surface
// TODO - why not store these strings as an array?
- switch(_aptRwys[i]._surface_code) {
+ switch(_aptRwys[i]->surface()) {
case 1:
// Asphalt - fall through
case 2:
i++;
if(i < _aptRwys.size()) {
// Rwy No.
- string s = _aptRwys[i]._rwy_no;
+ string s = _aptRwys[i]->ident();
_kln89->DrawText(s, 2, 9, 1);
_kln89->DrawText("/", 2, 12, 1);
_kln89->DrawText(GetReverseRunwayNo(s), 2, 13, 1);
// Length
- s = GPSitoa(int(float(_aptRwys[i]._length) * (_kln89->_altUnits == GPS_ALT_UNITS_FT ? 1.0 : SG_FEET_TO_METER) + 0.5));
+ s = GPSitoa(int(float(_aptRwys[i]->lengthFt()) * (_kln89->_altUnits == GPS_ALT_UNITS_FT ? 1.0 : SG_FEET_TO_METER) + 0.5));
_kln89->DrawText(s, 2, 5 - s.size(), 0);
_kln89->DrawText((_kln89->_altUnits == GPS_ALT_UNITS_FT ? "ft" : "m"), 2, 5, 0);
// Surface
// TODO - why not store these strings as an array?
- switch(_aptRwys[i]._surface_code) {
+ switch(_aptRwys[i]->surface()) {
case 1:
// Asphalt - fall through
case 2:
_kln89->DrawText(_iaps[_curIap]->_rwyStr, 2, 7, 3);
_kln89->DrawText(_iaps[_curIap]->_id, 2, 12, 3);
_kln89->DrawText("IAF", 2, 2, 2);
- int line = 0;
+ unsigned int line = 0;
for(unsigned int i=_iafStart; i<_IAF.size(); ++i) {
if(line == 2) {
i = _IAF.size() - 1;
// Runways
_aptRwys.clear();
- FGRunway r;
- bool haveRwy = globals->get_runways()->search(id, &r);
- while(haveRwy && r._id == id) {
- // Insert the runway with longest at the start of the array
- for(unsigned int i = 0; i <= _aptRwys.size(); ++i) {
- if(i == _aptRwys.size()) {
- _aptRwys.push_back(r);
- break;
- } else {
- if(r._length > _aptRwys[i]._length) {
- _aptRwys.insert(_aptRwys.begin() + i, r);
- break;
- }
- }
- }
- haveRwy = globals->get_runways()->next(&r);
- }
+ const FGAirport* apt = fgFindAirportID(id);
+ assert(apt);
+
+ // build local array, longest runway first
+ for (unsigned int r=0; r<apt->numRunways(); ++r) {
+ FGRunway* rwy(apt->getRunwayByIndex(r));
+ if ((r > 0) && (rwy->lengthFt() > _aptRwys.front()->lengthFt())) {
+ _aptRwys.insert(_aptRwys.begin(), rwy);
+ } else {
+ _aptRwys.push_back(rwy);
+ }
+ }
+
_nRwyPages = (_aptRwys.size() + 1) / 2; // 2 runways per page.
if(_nFreqPages < 1) _nFreqPages = 1;
if(_nRwyPages < 1) _nRwyPages = 1;
_iafDialog = true;
_maxULinePos = _IAF.size();
} else {
+ // There is only 1 IAF, so load the waypoints into the approach flightplan here.
+ // TODO - there is nasty code duplication loading the approach FP between the case here where we have only one
+ // IAF and the case where we must choose the IAF from a list. Try to tidy this after it is all working properly.
+ _kln89->_approachFP->waypoints.clear();
+ GPSWaypoint* wp = new GPSWaypoint;
+ *wp = *_IAF[0]; // Need to make copies here since we're going to alter ID and type sometimes
+ string iafid = wp->id;
+ _kln89->_approachFP->waypoints.push_back(wp);
+ for(unsigned int i=0; i<_IAP.size(); ++i) {
+ if(_IAP[i]->id != iafid) { // Don't duplicate waypoints that are part of the initial fix list and the approach procedure list.
+ // FIXME - allow the same waypoint to be both the IAF and the FAF in some
+ // approaches that have a procedure turn eg. KDLL
+ // Also allow MAF to be the same as IAF!
+ wp = new GPSWaypoint;
+ *wp = *_IAP[i];
+ _kln89->_approachFP->waypoints.push_back(wp);
+ }
+ }
+ // Only add 1 missed approach procedure waypoint for now. I think this might be standard always anyway.
+ wp = new GPSWaypoint;
+ *wp = *_MAP[0];
+ //wp->id += 'h';
+ _kln89->_approachFP->waypoints.push_back(wp);
+
_addDialog = true;
_maxULinePos = 1;
}