]> git.mxchange.org Git - flightgear.git/blob - src/Airports/sidstar.cxx
A set of additions related to allow the use of SID and STAR procedures.
[flightgear.git] / src / Airports / sidstar.cxx
1 // sidstar.cxx - Code to manage departure / arrival procedures
2 // Written by Durk Talsma, started March 2009.
3 //
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 //
19 // $Id$
20
21 #include <iostream>
22 #include <stdlib.h>
23
24 #include <simgear/props/props.hxx>
25 #include <simgear/props/props_io.hxx>
26
27
28
29 #include <Airports/simple.hxx>
30
31
32 #include "sidstar.hxx"
33
34 using std::cerr;
35 using std::endl;
36
37 FGSidStar::FGSidStar(FGAirport *ap) {
38      id = ap->getId();
39      initialized = false;
40 }
41
42
43 FGSidStar::FGSidStar(const FGSidStar &other) {
44      cerr << "TODO" << endl;
45      exit(1);
46 }
47
48 void FGSidStar::load(SGPath filename) {
49   SGPropertyNode root;
50   string runway;
51   string name;
52   try {
53       readProperties(filename.str(), &root);
54   } catch (const sg_exception &e) {
55       SG_LOG(SG_GENERAL, SG_ALERT,
56        "Error reading AI flight plan: " << filename.str());
57        // cout << path.str() << endl;
58      return;
59   }
60
61   SGPropertyNode * node = root.getNode("SIDS");
62   FGAIFlightPlan *fp;
63   for (int i = 0; i < node->nChildren(); i++) { 
64      fp = new FGAIFlightPlan;
65      SGPropertyNode * fpl_node = node->getChild(i);
66      name   =  fpl_node->getStringValue("name", "END");
67      runway =  fpl_node->getStringValue("runway", "27");
68      //cerr << "Runway = " << runway << endl;
69      fp->setName(name);
70      SGPropertyNode * wpts_node = fpl_node->getNode("wpts");
71      for (int j = 0; j < wpts_node->nChildren(); j++) { 
72           FGAIFlightPlan::waypoint* wpt = new FGAIFlightPlan::waypoint;
73           SGPropertyNode * wpt_node = wpts_node->getChild(j);
74           //cerr << "Reading waypoint " << j << wpt_node->getStringValue("name", "END") << endl;
75           wpt->name      = wpt_node->getStringValue("name", "END");
76           wpt->latitude  = wpt_node->getDoubleValue("lat", 0);
77           wpt->longitude = wpt_node->getDoubleValue("lon", 0);
78           wpt->altitude  = wpt_node->getDoubleValue("alt", 0);
79           wpt->speed     = wpt_node->getDoubleValue("ktas", 0);
80           wpt->crossat   = wpt_node->getDoubleValue("crossat", -10000);
81           wpt->gear_down = wpt_node->getBoolValue("gear-down", false);
82           wpt->flaps_down= wpt_node->getBoolValue("flaps-down", false);
83           wpt->on_ground = wpt_node->getBoolValue("on-ground", false);
84           wpt->time_sec   = wpt_node->getDoubleValue("time-sec", 0);
85           wpt->time       = wpt_node->getStringValue("time", "");
86
87           if (wpt->name == "END") wpt->finished = true;
88           else wpt->finished = false;
89
90           // 
91           fp->addWaypoint( wpt );
92      }
93      data[runway].push_back(fp);
94      //cerr << "Runway = " << runway << endl;
95    }
96
97
98   //wpt_iterator = waypoints.begin();
99   //cout << waypoints.size() << " waypoints read." << endl;
100 }
101
102
103 FGAIFlightPlan *FGSidStar::getBest(string activeRunway, double heading)
104 {
105     //cerr << "Getting best procedure for " << activeRunway << endl;
106     for (FlightPlanVecIterator i = data[activeRunway].begin(); i != data[activeRunway].end(); i++) {
107         //cerr << (*i)->getName() << endl;
108     }
109     int size = data[activeRunway].size();
110     //cerr << "size is " << size << endl;
111     if (size) {
112         return data[activeRunway][(rand() % size)];
113      } else {
114         return 0;
115     }
116 }