]> git.mxchange.org Git - flightgear.git/blob - src/ATC/atc_mgr.cxx
Assigned an ATC controller to the user's Aircraft and change the comm1 radio frequenc...
[flightgear.git] / src / ATC / atc_mgr.cxx
1 /******************************************************************************
2  * atc_mgr.cxx
3  * Written by Durk Talsma, started August 1, 2010.
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  *
20  **************************************************************************/
21
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <iostream>
28
29 #include <simgear/math/SGMath.hxx>
30 #include <Airports/dynamics.hxx>
31 #include <Airports/simple.hxx>
32
33 #include "atc_mgr.hxx"
34
35
36 FGATCManager::FGATCManager() {
37
38 }
39
40 FGATCManager::~FGATCManager() {
41
42 }
43
44 void FGATCManager::init() {
45     SGSubsystem::init();
46     currentATCDialog = new FGATCDialogNew;
47     currentATCDialog->init();
48
49     // find a reasonable controller for our user's aircraft..
50     // Let's start by working out the following three scenarios: 
51     // Starting on ground at a parking position
52     // Starting on ground at the runway.
53     // Starting in the Air
54     bool onGround  = fgGetBool("/sim/presets/onground");
55     string runway  = fgGetString("/sim/atc/runway");
56     string airport = fgGetString("/sim/presets/airport-id");
57     string parking = fgGetString("/sim/presets/parkpos");
58
59     FGAirport *apt = FGAirport::findByIdent(airport); 
60     cerr << "found information: " << runway << " " << airport << ": parking = " << parking << endl;
61      if (onGround) {
62         if (parking.empty()) {
63             controller = apt->getDynamics()->getTowerController();
64             int stationFreq = apt->getDynamics()->getTowerFrequency(2);
65             cerr << "Setting radio frequency to in airfrequency: " << stationFreq << endl;
66             fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
67
68         } else {
69             controller = apt->getDynamics()->getGroundNetwork();
70             int stationFreq = apt->getDynamics()->getGroundFrequency(2);
71             cerr << "Setting radio frequency to : " << stationFreq << endl;
72             fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
73
74         }
75      } else {
76         controller = 0;
77      }
78     //controller = 
79
80     //dialog.init();
81 }
82
83 void FGATCManager::addController(FGATCController *controller) {
84     activeStations.push_back(controller);
85 }
86
87 void FGATCManager::update ( double time ) {
88     //cerr << "ATC update code is running at time: " << time << endl;
89    currentATCDialog->update(time);
90 }