]> git.mxchange.org Git - flightgear.git/blob - src/Airports/sidstar.cxx
e19ff192577548b868e48a372f5ce002c12e1eab
[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 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #include <iostream>
26 #include <stdlib.h>
27
28 #include <simgear/props/props.hxx>
29 #include <simgear/props/props_io.hxx>
30
31
32
33 #include <Airports/simple.hxx>
34
35
36 #include "sidstar.hxx"
37
38 using std::cerr;
39 using std::endl;
40
41 FGSidStar::FGSidStar(FGAirport *ap) {
42      id = ap->getId();
43      initialized = false;
44 }
45
46
47 FGSidStar::FGSidStar(const FGSidStar &other) {
48      cerr << "TODO" << endl;
49      exit(1);
50 }
51
52 void FGSidStar::load(SGPath filename) {
53   SGPropertyNode root;
54   string runway;
55   string name;
56   try {
57       readProperties(filename.str(), &root);
58   } catch (const sg_exception &) {
59       SG_LOG(SG_GENERAL, SG_ALERT,
60        "Error reading AI flight plan: " << filename.str());
61        // cout << path.str() << endl;
62      return;
63   }
64
65   SGPropertyNode * node = root.getNode("SIDS");
66   FGAIFlightPlan *fp;
67   for (int i = 0; i < node->nChildren(); i++) { 
68      fp = new FGAIFlightPlan;
69      SGPropertyNode * fpl_node = node->getChild(i);
70      name   =  fpl_node->getStringValue("name", "END");
71      runway =  fpl_node->getStringValue("runway", "27");
72      //cerr << "Runway = " << runway << endl;
73      fp->setName(name);
74      SGPropertyNode * wpts_node = fpl_node->getNode("wpts");
75      for (int j = 0; j < wpts_node->nChildren(); j++) { 
76           FGAIWaypoint* wpt = new FGAIWaypoint;
77           SGPropertyNode * wpt_node = wpts_node->getChild(j);
78           //cerr << "Reading waypoint " << j << wpt_node->getStringValue("name", "END") << endl;
79           wpt->setName        (wpt_node->getStringValue("name", "END"));
80           wpt->setLatitude    (wpt_node->getDoubleValue("lat", 0));
81           wpt->setLongitude   (wpt_node->getDoubleValue("lon", 0));
82           wpt->setAltitude    (wpt_node->getDoubleValue("alt", 0));
83           wpt->setSpeed       (wpt_node->getDoubleValue("ktas", 0));
84           wpt->setCrossat     (wpt_node->getDoubleValue("crossat", -10000));
85           wpt->setGear_down   (wpt_node->getBoolValue("gear-down", false));
86           wpt->setFlaps_down  (wpt_node->getBoolValue("flaps-down", false));
87           wpt->setOn_ground   (wpt_node->getBoolValue("on-ground", false));
88           wpt->setTime_sec    (wpt_node->getDoubleValue("time-sec", 0));
89           wpt->setTime        (wpt_node->getStringValue("time", ""));
90
91           if (wpt->contains("END")) 
92                 wpt->setFinished(true);
93           else 
94                 wpt->setFinished(false);
95
96           // 
97           fp->addWaypoint( wpt );
98      }
99      data[runway].push_back(fp);
100      //cerr << "Runway = " << runway << endl;
101    }
102
103
104   //wpt_iterator = waypoints.begin();
105   //cout << waypoints.size() << " waypoints read." << endl;
106 }
107
108
109 FGAIFlightPlan *FGSidStar::getBest(string activeRunway, double heading)
110 {
111     //cerr << "Getting best procedure for " << activeRunway << endl;
112     for (FlightPlanVecIterator i = data[activeRunway].begin(); i != data[activeRunway].end(); i++) {
113         //cerr << (*i)->getName() << endl;
114     }
115     int size = data[activeRunway].size();
116     //cerr << "size is " << size << endl;
117     if (size) {
118         return data[activeRunway][(rand() % size)];
119      } else {
120         return 0;
121     }
122 }