1 // FGTower - a class to provide tower control at towered airports.
3 // Written by David Luff, started March 2002.
5 // Copyright (C) 2002 David C. Luff - david.luff@nottingham.ac.uk
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <Main/globals.hxx>
24 #include "ATCdisplay.hxx"
31 TowerPlaneRec::TowerPlaneRec() :
34 clearedToDepart(false),
35 longFinalReported(false),
36 longFinalAcknowledged(false),
38 finalAcknowledged(false)
42 TowerPlaneRec::TowerPlaneRec(string ID) :
44 clearedToDepart(false),
45 longFinalReported(false),
46 longFinalAcknowledged(false),
48 finalAcknowledged(false)
53 TowerPlaneRec::TowerPlaneRec(Point3D pt) :
56 clearedToDepart(false),
57 longFinalReported(false),
58 longFinalAcknowledged(false),
60 finalAcknowledged(false)
65 TowerPlaneRec::TowerPlaneRec(string ID, Point3D pt) :
67 clearedToDepart(false),
68 longFinalReported(false),
69 longFinalAcknowledged(false),
71 finalAcknowledged(false)
81 ATCmgr = globals->get_ATC_mgr();
90 void FGTower::Init() {
93 // Need some way to initialise rwyOccupied flag correctly if the user is on the runway and to know its the user.
94 // I'll punt the startup issue for now though!!!
97 // Setup the ground control at this airport
99 if(ATCmgr->GetAirportATCDetails(ident, &a)) {
100 if(a.ground_freq) { // Ground control
101 ground = (FGGround*)ATCmgr->GetATCPointer(ident, GROUND);
102 separateGround = true;
104 // Something has gone wrong :-(
105 cout << "ERROR - ground has frequency but can't get ground pointer :-(\n";
106 ground = new FGGround(ident);
107 separateGround = false;
110 ground->SetDisplay();
112 ground->SetNoDisplay();
116 // Initialise ground anyway to do the shortest path stuff!
117 // Note that we're now responsible for updating and deleting this - NOT the ATCMgr.
118 ground = new FGGround(ident);
119 separateGround = false;
122 ground->SetDisplay();
124 ground->SetNoDisplay();
128 cout << "Unable to find airport details for " << ident << " in FGTower::Init()\n";
129 // Initialise ground anyway to avoid segfault later
130 ground = new FGGround(ident);
131 separateGround = false;
134 ground->SetDisplay();
136 ground->SetNoDisplay();
141 void FGTower::Update() {
142 // Each time step, what do we need to do?
143 // We need to go through the list of outstanding requests and acknowedgements
144 // and process at least one of them.
145 // We need to go through the list of planes under our control and check if
146 // any need to be addressed.
147 // We need to check for planes not under our control coming within our
148 // control area and address if necessary.
150 // TODO - a lot of the below probably doesn't need to be called every frame and should be staggered.
152 // Sort the arriving planes
154 // Calculate the eta of each plane to the threshold.
155 // For ground traffic this is the fastest they can get there.
156 // For air traffic this is the middle approximation.
157 doThresholdETACalc();
159 // Order the list of traffic as per expected threshold use and flag any conflicts
160 bool conflicts = doThresholdUseOrder();
162 // sortConficts() !!!
166 if(!separateGround) {
167 // The display stuff might have to get more clever than this when not separate
168 // since the tower and ground might try communicating simultaneously even though
169 // they're mean't to be the same contoller/frequency!!
171 ground->SetDisplay();
173 ground->SetNoDisplay();
179 // Calculate the eta of each plane to the threshold.
180 // For ground traffic this is the fastest they can get there.
181 // For air traffic this is the middle approximation.
182 void FGTower::doThresholdETACalc() {
183 // For now we'll be very crude and hardwire expected speeds to C172-like values
184 double app_ias = 100.0; // Speed during straight-in approach
185 double circuit_ias = 80.0; // Speed around circuit
186 double final_ias = 70.0; // Speed during final approach
188 tower_plane_rec_list_iterator twrItr;
190 for(twrItr = trafficList.begin(); twrItr != trafficList.end(); twrItr++) {
195 bool FGTower::doThresholdUseOrder() {
199 void FGTower::doCommunication() {
203 void FGTower::RequestLandingClearance(string ID) {
204 cout << "Request Landing Clearance called...\n";
206 void FGTower::RequestDepartureClearance(string ID) {
207 cout << "Request Departure Clearance called...\n";
209 //void FGTower::ReportFinal(string ID);
210 //void FGTower::ReportLongFinal(string ID);
211 //void FGTower::ReportOuterMarker(string ID);
212 //void FGTower::ReportMiddleMarker(string ID);
213 //void FGTower::ReportInnerMarker(string ID);
214 //void FGTower::ReportGoingAround(string ID);
215 void FGTower::ReportRunwayVacated(string ID) {
216 cout << "Report Runway Vacated Called...\n";