]> git.mxchange.org Git - flightgear.git/blob - src/ATC/tower.cxx
Further progress towards intelligent interaction between the AI plane and the user...
[flightgear.git] / src / ATC / tower.cxx
1 // FGTower - a class to provide tower control at towered airports.
2 //
3 // Written by David Luff, started March 2002.
4 //
5 // Copyright (C) 2002  David C. Luff - david.luff@nottingham.ac.uk
6 //
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.
11 //
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.
16 //
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.
20
21 #include <Main/globals.hxx>
22 #include <Airports/runways.hxx>
23 #include <simgear/math/sg_geodesy.hxx>
24 #include <simgear/debug/logstream.hxx>
25
26 #include "tower.hxx"
27 #include "ATCdisplay.hxx"
28 #include "ATCmgr.hxx"
29 #include "ATCutils.hxx"
30 #include "commlist.hxx"
31 #include "AILocalTraffic.hxx"
32
33 SG_USING_STD(cout);
34
35 // TowerPlaneRec
36
37 TowerPlaneRec::TowerPlaneRec() :
38 clearedToLand(false),
39 clearedToLineUp(false),
40 clearedToTakeOff(false),
41 holdShortReported(false),
42 longFinalReported(false),
43 longFinalAcknowledged(false),
44 finalReported(false),
45 finalAcknowledged(false),
46 opType(TTT_UNKNOWN),
47 isUser(false)
48 {
49         plane.callsign = "UNKNOWN";
50 }
51
52 TowerPlaneRec::TowerPlaneRec(PlaneRec p) :
53 clearedToLand(false),
54 clearedToLineUp(false),
55 clearedToTakeOff(false),
56 holdShortReported(false),
57 longFinalReported(false),
58 longFinalAcknowledged(false),
59 finalReported(false),
60 finalAcknowledged(false),
61 opType(TTT_UNKNOWN),
62 isUser(false)
63 {
64         plane = p;
65 }
66
67 TowerPlaneRec::TowerPlaneRec(Point3D pt) :
68 clearedToLand(false),
69 clearedToLineUp(false),
70 clearedToTakeOff(false),
71 holdShortReported(false),
72 longFinalReported(false),
73 longFinalAcknowledged(false),
74 finalReported(false),
75 finalAcknowledged(false),
76 opType(TTT_UNKNOWN),
77 isUser(false)
78 {
79         plane.callsign = "UNKNOWN";
80         pos = pt;
81 }
82
83 TowerPlaneRec::TowerPlaneRec(PlaneRec p, Point3D pt) :
84 clearedToLand(false),
85 clearedToLineUp(false),
86 clearedToTakeOff(false),
87 holdShortReported(false),
88 longFinalReported(false),
89 longFinalAcknowledged(false),
90 finalReported(false),
91 finalAcknowledged(false),
92 opType(TTT_UNKNOWN),
93 isUser(false)
94 {
95         plane = p;
96         pos = pt;
97 }
98
99
100 // FGTower
101
102 FGTower::FGTower() {
103         ATCmgr = globals->get_ATC_mgr();
104         
105         // Init the property nodes - TODO - need to make sure we're getting surface winds.
106         wind_from_hdg = fgGetNode("/environment/wind-from-heading-deg", true);
107         wind_speed_knots = fgGetNode("/environment/wind-speed-kts", true);
108         
109         holdListItr = holdList.begin();
110         appListItr = appList.begin();
111         depListItr = depList.begin();
112         rwyListItr = rwyList.begin();
113         circuitListItr = circuitList.begin();
114         trafficListItr = trafficList.begin();
115 }
116
117 FGTower::~FGTower() {
118         if(!separateGround) {
119                 delete ground;
120         }
121 }
122
123 void FGTower::Init() {
124     display = false;
125         
126         // Pointers to user's position
127         user_lon_node = fgGetNode("/position/longitude-deg", true);
128         user_lat_node = fgGetNode("/position/latitude-deg", true);
129         user_elev_node = fgGetNode("/position/altitude-ft", true);
130         user_hdg_node = fgGetNode("/orientation/heading-deg", true);
131         
132         // Need some way to initialise rwyOccupied flag correctly if the user is on the runway and to know its the user.
133         // I'll punt the startup issue for now though!!!
134         rwyOccupied = false;
135         
136         // Setup the ground control at this airport
137         AirportATC a;
138         //cout << "Tower ident = " << ident << '\n';
139         if(ATCmgr->GetAirportATCDetails(ident, &a)) {
140                 if(a.ground_freq) {             // Ground control
141                         ground = (FGGround*)ATCmgr->GetATCPointer(ident, GROUND);
142                         separateGround = true;
143                         if(ground == NULL) {
144                                 // Something has gone wrong :-(
145                                 SG_LOG(SG_ATC, SG_WARN, "ERROR - ground has frequency but can't get ground pointer :-(");
146                                 ground = new FGGround(ident);
147                                 separateGround = false;
148                                 ground->Init();
149                                 if(display) {
150                                         ground->SetDisplay();
151                                 } else {
152                                         ground->SetNoDisplay();
153                                 }
154                         }
155                 } else {
156                         // Initialise ground anyway to do the shortest path stuff!
157                         // Note that we're now responsible for updating and deleting this - NOT the ATCMgr.
158                         ground = new FGGround(ident);
159                         separateGround = false;
160                         ground->Init();
161                         if(display) {
162                                 ground->SetDisplay();
163                         } else {
164                                 ground->SetNoDisplay();
165                         }
166                 }
167         } else {
168                 SG_LOG(SG_ATC, SG_ALERT, "Unable to find airport details for " << ident << " in FGTower::Init()");
169                 // Initialise ground anyway to avoid segfault later
170                 ground = new FGGround(ident);
171                 separateGround = false;
172                 ground->Init();
173                 if(display) {
174                         ground->SetDisplay();
175                 } else {
176                         ground->SetNoDisplay();
177                 }
178         }
179         
180         // Get the airport elevation
181         aptElev = dclGetAirportElev(ident.c_str()) * SG_FEET_TO_METER;
182         
183         DoRwyDetails();
184         
185         // FIXME - this currently assumes use of the active rwy by the user.
186         rwyOccupied = OnAnyRunway(Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0));
187         if(rwyOccupied) {
188                 // Assume the user is started at the threshold ready to take-off
189                 TowerPlaneRec* t = new TowerPlaneRec;
190                 t->plane.callsign = "Charlie Foxtrot Sierra";   // C-FGFS !!! - fixme - this is a bit hardwired
191                 t->opType = TTT_UNKNOWN;        // We don't know if the user wants to do circuits or a departure...
192                 t->leg = TAKEOFF_ROLL;
193                 t->isUser = true;
194                 t->planePtr = NULL;
195                 t->clearedToTakeOff = true;
196                 rwyList.push_back(t);
197         }
198 }
199
200 void FGTower::Update(double dt) {
201         static int ii = 0;      // Counter for spreading the load
202         //cout << "T" << flush;
203         // Each time step, what do we need to do?
204         // We need to go through the list of outstanding requests and acknowedgements
205         // and process at least one of them.
206         // We need to go through the list of planes under our control and check if
207         // any need to be addressed.
208         // We need to check for planes not under our control coming within our 
209         // control area and address if necessary.
210         
211         // TODO - a lot of the below probably doesn't need to be called every frame and should be staggered.
212         
213         // Sort the arriving planes
214         
215         // Calculate the eta of each plane to the threshold.
216         // For ground traffic this is the fastest they can get there.
217         // For air traffic this is the middle approximation.
218         if(ii == 1) {
219                 doThresholdETACalc();
220         }
221         
222         // Order the list of traffic as per expected threshold use and flag any conflicts
223         if(ii == 2) {
224                 bool conflicts = doThresholdUseOrder();
225         }
226         
227         // sortConficts() !!!
228         
229         // Do one plane from the hold list
230         if(ii == 4) {
231                 if(holdList.size()) {
232                         //cout << "A" << endl;
233                         //cout << "*holdListItr = " << *holdListItr << endl;
234                         if(holdListItr == holdList.end()) {
235                                 holdListItr = holdList.begin();
236                         }
237                         //cout << "*holdListItr = " << *holdListItr << endl;
238                         //Process(*holdListItr);
239                         TowerPlaneRec* t = *holdListItr;
240                         //cout << "t = " << t << endl;
241                         if(t->holdShortReported) {
242                                 //cout << "B" << endl;
243                                 double responseTime = 10.0;             // seconds - this should get more sophisticated at some point
244                                 if(t->clearanceCounter > responseTime) {
245                                         //cout << "C" << endl;
246                                         if(t->nextOnRwy) {
247                                                 //cout << "D" << endl;
248                                                 if(rwyOccupied) {
249                                                         //cout << "E" << endl;
250                                                         // Do nothing for now - consider acknowloging hold short eventually
251                                                 } else {
252                                                         // Lets Roll !!!!
253                                                         string trns = t->plane.callsign;
254                                                         //if(departed plane < some threshold in time away) {
255                                                                 if(0) {         // FIXME
256                                                                         trns += " line up";
257                                                                         t->clearedToLineUp = true;
258                                                                         t->planePtr->RegisterTransmission(3);   // cleared to line-up
259                                                                         t->leg = TAKEOFF_ROLL;
260                                                         //} else if(arriving plane < some threshold away) {
261                                                                 } else if(0) {  // FIXME
262                                                                         trns += " cleared immediate take-off";
263                                                                         // TODO - add traffic is... ?
264                                                                         t->clearedToTakeOff = true;
265                                                                         t->planePtr->RegisterTransmission(4);   // cleared to take-off - TODO differentiate between immediate and normal take-off
266                                                                         t->leg = TAKEOFF_ROLL;
267                                                                 } else {
268                                                                         trns += " cleared for take-off";
269                                                                         // TODO - add traffic is... ?
270                                                                         t->clearedToTakeOff = true;
271                                                                         t->planePtr->RegisterTransmission(4);   // cleared to take-off
272                                                                         t->leg = TAKEOFF_ROLL;
273                                                                 }
274                                                                 if(display) {
275                                                                         globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
276                                                                 }
277                                                                 t->holdShortReported = false;
278                                                                 t->clearanceCounter = 0;
279                                                                 rwyList.push_back(t);
280                                                                 rwyOccupied = true;
281                                                                 holdList.erase(holdListItr);
282                                                                 holdListItr = holdList.begin();
283                                                 }
284                                         } else {
285                                                 // possibly tell him to hold and what position he is?
286                                         }
287                                 } else {
288                                         t->clearanceCounter += (dt * holdList.size());
289                                 }
290                         }                               
291                         ++holdListItr;
292                 }
293         }
294         
295         // Do the runway list - we'll do the whole runway list since it's important and there'll never be many planes on the rwy at once!!
296         if(ii == 5) {
297                 if(rwyOccupied) {
298                         if(!rwyList.size()) {
299                                 rwyOccupied = false;
300                         } else {
301                                 rwyListItr = rwyList.begin();
302                                 TowerPlaneRec* t = *rwyListItr;
303                                 if(t->isUser) {
304                                         bool on_rwy = OnActiveRunway(Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0));
305                                         // TODO - how do we find the position when it's not the user?
306                                         if(!on_rwy) {
307                                                 if((t->opType == INBOUND) || (t->opType == STRAIGHT_IN)) {
308                                                         rwyList.pop_front();
309                                                         delete t;
310                                                         // TODO - tell it to taxi / contact ground / don't delete it etc!
311                                                 } else if(t->opType == OUTBOUND) {
312                                                         depList.push_back(t);
313                                                         rwyList.pop_front();
314                                                 } else if(t->opType == CIRCUIT) {
315                                                         circuitList.push_back(t);
316                                                         rwyList.pop_front();
317                                                 } else if(t->opType == TTT_UNKNOWN) {
318                                                         depList.push_back(t);
319                                                         circuitList.push_back(t);
320                                                         rwyList.pop_front();
321                                                 } else {
322                                                         // HELP - we shouldn't ever get here!!!
323                                                 }
324                                         }
325                                 } // else TODO figure out what to do when it's not the user
326                         }
327                 }
328         }
329         
330         // do the ciruit list
331         if(ii == 6) {
332                 // Clear the constraints - we recalculate here.
333                 base_leg_pos = 0.0;
334                 downwind_leg_pos = 0.0;
335                 crosswind_leg_pos = 0.0;
336                 if(circuitList.size()) {
337                         circuitListItr = circuitList.begin();   // TODO - at the moment we're constraining plane 2 based on plane 1 - this won't work for 3 planes in the circuit!!
338                         TowerPlaneRec* t = *circuitListItr;
339                         Point3D tortho = ortho.ConvertToLocal(t->pos);
340                         if(t->isUser) {
341                                 // Need to figure out which leg he's on
342                                 double ho = GetAngleDiff_deg(user_hdg_node->getDoubleValue(), rwy.hdg);
343                                 // TODO FIXME - get the wind and convert this to track, or otherwise use track somehow!!!
344                                 // If it's gusty might need to filter the value, although we are leaving 30 degrees each way leeway!
345                                 if(abs(ho) < 30) {
346                                         // could be either takeoff, climbout or landing - check orthopos.y
347                                         if((tortho.y() < 0) || (t->leg == TURN4) || (t->leg == LANDING_ROLL)) {
348                                                 t->leg = LANDING_ROLL;
349                                                 //cout << "Landing_roll\n";
350                                         } else {
351                                                 t->leg = CLIMBOUT;      // TODO - check elev wrt. apt elev to differentiate takeoff roll and climbout
352                                                 //cout << "Climbout\n";
353                                         }
354                                 } else if(abs(ho) < 60) {
355                                         // turn1 or turn 4
356                                         // TODO - either fix or doublecheck this hack by looking at heading and pattern direction
357                                         if((t->leg == CLIMBOUT) || (t->leg == TURN1)) {
358                                                 t->leg = TURN1;
359                                                 //cout << "Turn1\n";
360                                         } else {
361                                                 t->leg = TURN4;
362                                                 //cout << "Turn4\n";
363                                         }
364                                 } else if(abs(ho) < 120) {
365                                         // crosswind or base
366                                         // TODO - either fix or doublecheck this hack by looking at heading and pattern direction
367                                         if((t->leg == TURN1) || (t->leg == CROSSWIND)) {
368                                                 t->leg = CROSSWIND;
369                                                 //cout << "Crosswind\n";
370                                         } else {
371                                                 t->leg = BASE;
372                                                 //cout << "Base\n";
373                                         }
374                                 } else if(abs(ho) < 150) {
375                                         // turn2 or turn 3
376                                         // TODO - either fix or doublecheck this hack by looking at heading and pattern direction
377                                         if((t->leg == CROSSWIND) || (t->leg == TURN2)) {
378                                                 t->leg = TURN2;
379                                                 //cout << "Turn2\n";
380                                         } else {
381                                                 t->leg = TURN3;
382                                                 //cout << "Turn3\n";
383                                         }
384                                 } else {
385                                         // downwind
386                                         t->leg = DOWNWIND;
387                                         //cout << "Downwind\n";
388                                 }
389                         } else {
390                                 t->leg = t->planePtr->GetLeg();
391                         }
392                         switch(t->leg) {
393                         case FINAL:
394                                 // Base leg must be at least as far out as the plane is - actually possibly not necessary for separation, but we'll use that for now.
395                                 base_leg_pos = tortho.y();
396                                 break;
397                         case TURN4:
398                                 // Fall through to base
399                         case BASE:
400                                 base_leg_pos = tortho.y();
401                                 break;
402                         case TURN3:
403                                 // Fall through to downwind
404                         case DOWNWIND:
405                                 // Only have the downwind leg pos as turn-to-base constraint if more negative than we already have.
406                                 base_leg_pos = (tortho.y() < base_leg_pos ? tortho.y() : base_leg_pos);
407                                 downwind_leg_pos = tortho.x();          // Assume that a following plane can simply be constrained by the immediately in front downwind plane
408                                 break;
409                         case TURN2:
410                                 // Fall through to crosswind
411                         case CROSSWIND:
412                                 crosswind_leg_pos = tortho.y();
413                                 break;
414                         case TURN1:
415                                 // Fall through to climbout
416                         case CLIMBOUT:
417                                 // Only use current by constraint as largest
418                                 crosswind_leg_pos = (tortho.y() > crosswind_leg_pos ? tortho.x() : crosswind_leg_pos);
419                                 break;
420                         case TAKEOFF_ROLL:
421                                 break;
422                         case LEG_UNKNOWN:
423                                 break;
424                         case LANDING_ROLL:
425                                 break;
426                         default:
427                                 break;
428                         }
429                 }
430         }
431         
432         doCommunication();
433         
434         if(!separateGround) {
435                 // The display stuff might have to get more clever than this when not separate 
436                 // since the tower and ground might try communicating simultaneously even though
437                 // they're mean't to be the same contoller/frequency!!
438                 if(display) {
439                         ground->SetDisplay();
440                 } else {
441                         ground->SetNoDisplay();
442                 }
443                 ground->Update(dt);
444         }
445         
446         ++ii;
447         // How big should ii get - ie how long should the update cycle interval stretch?
448         if(ii >= 15) {
449                 ii = 0;
450         }
451 }
452
453
454 // Figure out which runways are active.
455 // For now we'll just be simple and do one active runway - eventually this will get much more complex
456 // This is a private function - public interface to the results of this is through GetActiveRunway
457 void FGTower::DoRwyDetails() {
458         //cout << "GetRwyDetails called" << endl;
459         
460         // Based on the airport-id and wind get the active runway
461         SGPath path( globals->get_fg_root() );
462         path.append( "Airports" );
463         path.append( "runways.mk4" );
464         FGRunways runways( path.c_str() );
465         
466         //wind
467         double hdg = wind_from_hdg->getDoubleValue();
468         double speed = wind_speed_knots->getDoubleValue();
469         hdg = (speed == 0.0 ? 270.0 : hdg);
470         //cout << "Heading = " << hdg << '\n';
471         
472         FGRunway runway;
473         bool rwyGood = runways.search(ident, int(hdg), &runway);
474         if(rwyGood) {
475                 activeRwy = runway.rwy_no;
476                 rwy.rwyID = runway.rwy_no;
477                 SG_LOG(SG_ATC, SG_INFO, "Active runway for airport " << ident << " is " << activeRwy);
478                 
479                 // Get the threshold position
480                 double other_way = runway.heading - 180.0;
481                 while(other_way <= 0.0) {
482                         other_way += 360.0;
483                 }
484         // move to the +l end/center of the runway
485                 //cout << "Runway center is at " << runway.lon << ", " << runway.lat << '\n';
486         Point3D origin = Point3D(runway.lon, runway.lat, aptElev);
487                 Point3D ref = origin;
488         double tshlon, tshlat, tshr;
489                 double tolon, tolat, tor;
490                 rwy.length = runway.length * SG_FEET_TO_METER;
491                 rwy.width = runway.width * SG_FEET_TO_METER;
492         geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), other_way, 
493                                 rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr );
494         geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), runway.heading, 
495                                 rwy.length / 2.0 - 25.0, &tolat, &tolon, &tor );
496                 // Note - 25 meters in from the runway end is a bit of a hack to put the plane ahead of the user.
497                 // now copy what we need out of runway into rwy
498         rwy.threshold_pos = Point3D(tshlon, tshlat, aptElev);
499                 Point3D takeoff_end = Point3D(tolon, tolat, aptElev);
500                 //cout << "Threshold position = " << tshlon << ", " << tshlat << ", " << aptElev << '\n';
501                 //cout << "Takeoff position = " << tolon << ", " << tolat << ", " << aptElev << '\n';
502                 rwy.hdg = runway.heading;
503                 // Set the projection for the local area based on this active runway
504                 ortho.Init(rwy.threshold_pos, rwy.hdg); 
505                 rwy.end1ortho = ortho.ConvertToLocal(rwy.threshold_pos);        // should come out as zero
506                 rwy.end2ortho = ortho.ConvertToLocal(takeoff_end);
507         } else {
508                 SG_LOG(SG_ATC, SG_ALERT, "Help  - can't get good runway in FGTower!!");
509                 activeRwy = "NN";
510         }
511 }
512
513
514 // Figure out if a given position lies on the active runway
515 // Might have to change when we consider more than one active rwy.
516 bool FGTower::OnActiveRunway(Point3D pt) {
517         // TODO - check that the centre calculation below isn't confused by displaced thesholds etc.
518         Point3D xyc((rwy.end1ortho.x() + rwy.end2ortho.x())/2.0, (rwy.end1ortho.y() + rwy.end2ortho.y())/2.0, 0.0);
519         Point3D xyp = ortho.ConvertToLocal(pt);
520         
521         //cout << "Length offset = " << fabs(xyp.y() - xyc.y()) << '\n';
522         //cout << "Width offset = " << fabs(xyp.x() - xyc.x()) << '\n';
523
524         double rlen = rwy.length/2.0 + 5.0;
525         double rwidth = rwy.width/2.0;
526         double ldiff = fabs(xyp.y() - xyc.y());
527         double wdiff = fabs(xyp.x() - xyc.x());
528
529         return((ldiff < rlen) && (wdiff < rwidth));
530 }       
531
532
533 // Figure out if a given position lies on any runway or not
534 // Only call this at startup - reading the runways database is expensive and needs to be fixed!
535 bool FGTower::OnAnyRunway(Point3D pt) {
536         ATCData ad;
537         double dist = current_commlist->FindClosest(lon, lat, elev, ad, TOWER, 10.0);
538         if(dist < 0.0) {
539                 return(false);
540         }
541         // Based on the airport-id, go through all the runways and check for a point in them
542         SGPath spath( globals->get_fg_root() );
543         spath.append( "Airports" );
544         spath.append( "runways.mk4" );
545         FGRunways runways( spath.c_str() );
546         
547         // TODO - do we actually need to search for the airport - surely we already know our ident and
548         // can just search runways of our airport???
549         //cout << "Airport ident is " << ad.ident << '\n';
550         FGRunway runway;
551         bool rwyGood = runways.search(ad.ident, &runway);
552         if(!rwyGood) {
553                 SG_LOG(SG_ATC, SG_WARN, "Unable to find any runways for airport ID " << ad.ident << " in FGTower");
554         }
555         bool on = false;
556         while(runway.id == ad.ident) {          
557                 on = OnRunway(pt, runway);
558                 //cout << "Runway " << runway.rwy_no << ": On = " << (on ? "true\n" : "false\n");
559                 if(on) return(true);
560                 runways.next(&runway);          
561         }
562         return(on);
563 }
564
565
566 // Calculate the eta of each plane to the threshold.
567 // For ground traffic this is the fastest they can get there.
568 // For air traffic this is the middle approximation.
569 void FGTower::doThresholdETACalc() {
570         // For now we'll be very crude and hardwire expected speeds to C172-like values
571         // The speeds below are specified in knots IAS and then converted to m/s
572         double app_ias = 100.0 * 0.514444;                      // Speed during straight-in approach
573         double circuit_ias = 80.0 * 0.514444;           // Speed around circuit
574         double final_ias = 70.0 * 0.514444;             // Speed during final approach
575
576         tower_plane_rec_list_iterator twrItr;
577
578         // Sign convention - dist_out is -ve for approaching planes and +ve for departing planes
579         // dist_across is +ve in the pattern direction - ie a plane correctly on downwind will have a +ve dist_across
580         for(twrItr = trafficList.begin(); twrItr != trafficList.end(); twrItr++) {
581                 TowerPlaneRec* tpr = *twrItr;
582                 Point3D op = ortho.ConvertToLocal(tpr->pos);
583                 double dist_out_m = op.y();
584                 double dist_across_m = fabs(op.x());    // FIXME = the fabs is a hack to cope with the fact that we don't know the circuit direction yet
585                 //cout << "Doing ETA calc for " << tpr->plane.callsign << '\n';
586                 if(tpr->opType == CIRCUIT) {
587                         // It's complicated - depends on if base leg is delayed or not
588                         if(tpr->leg == LANDING_ROLL) {
589                                 tpr->eta = 0;
590                         } else if((tpr->leg == FINAL) || (tpr->leg == TURN4)) {
591                                 tpr->eta = fabs(dist_out_m) / final_ias;
592                         } else if((tpr->leg == BASE) || (tpr->leg == TURN3)) {
593                                 tpr->eta = (fabs(dist_out_m) / final_ias) + (dist_across_m / circuit_ias);
594                         } else {
595                                 // Need to calculate where base leg is likely to be
596                                 // FIXME - for now I'll hardwire it to 1000m which is what AILocalTraffic uses!!!
597                                 // TODO - as a matter of design - AILocalTraffic should get the nominal no-traffic base turn distance from Tower, since in real life the published pattern might differ from airport to airport
598                                 double nominal_base_dist_out_m = -1000;
599                                 double current_base_dist_out_m = nominal_base_dist_out_m;
600                                 double nominal_dist_across_m = 1000;    // Hardwired value from AILocalTraffic
601                                 double nominal_cross_dist_out_m = 1000; // Bit of a guess - AI plane turns to crosswind at 600ft agl.
602                                 tpr->eta = fabs(current_base_dist_out_m) / final_ias;   // final
603                                 if((tpr->leg == DOWNWIND) || (tpr->leg == TURN2)) {
604                                         tpr->eta += dist_across_m / circuit_ias;
605                                         tpr->eta += fabs(current_base_dist_out_m - dist_out_m) / circuit_ias;
606                                 } else if((tpr->leg == CROSSWIND) || (tpr->leg == TURN1)) {
607                                         tpr->eta += nominal_dist_across_m / circuit_ias;        // should we use the dist across of the previous plane if there is previous still on downwind?
608                                         tpr->eta += fabs(current_base_dist_out_m - nominal_cross_dist_out_m) / circuit_ias;
609                                         tpr->eta += (nominal_dist_across_m - dist_across_m) / circuit_ias;
610                                 } else {
611                                         // We've only just started - why not use a generic estimate?
612                                 }
613                         }
614                 } else if((tpr->opType == INBOUND) || (tpr->opType == STRAIGHT_IN)) {
615                         // It's simpler!
616                 } else {
617                         // Must be outbound - ignore it!
618                 }
619                 //cout << "ETA = " << tpr->eta << '\n';
620         }
621 }
622                 
623
624 bool FGTower::doThresholdUseOrder() {
625         return(true);
626 }
627
628 void FGTower::doCommunication() {
629 }
630
631 void FGTower::ContactAtHoldShort(PlaneRec plane, FGAIPlane* requestee, tower_traffic_type operation) {
632         // HACK - assume that anything contacting at hold short is new for now - FIXME LATER
633         TowerPlaneRec* t = new TowerPlaneRec;
634         t->plane = plane;
635         t->planePtr = requestee;
636         t->holdShortReported = true;
637         t->clearanceCounter = 0;
638         t->clearedToLineUp = false;
639         t->clearedToTakeOff = false;
640         t->opType = operation;
641         
642         // HACK ALERT - THIS IS HARDWIRED FOR TESTING - FIXME TODO ETC
643         t->nextOnRwy = true;
644         
645         //cout << "t = " << t << '\n';
646         
647         holdList.push_back(t);
648 }
649
650 void FGTower::RequestLandingClearance(string ID) {
651         //cout << "Request Landing Clearance called...\n";
652 }
653 void FGTower::RequestDepartureClearance(string ID) {
654         //cout << "Request Departure Clearance called...\n";
655 }       
656 //void FGTower::ReportFinal(string ID);
657 //void FGTower::ReportLongFinal(string ID);
658 //void FGTower::ReportOuterMarker(string ID);
659 //void FGTower::ReportMiddleMarker(string ID);
660 //void FGTower::ReportInnerMarker(string ID);
661 //void FGTower::ReportGoingAround(string ID);
662 void FGTower::ReportRunwayVacated(string ID) {
663         //cout << "Report Runway Vacated Called...\n";
664 }