1 // trafficrecord.cxx - Implementation of AIModels ATC code.
3 // Written by Durk Talsma, started September 2006.
5 // Copyright (C) 2006 Durk Talsma.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include "trafficcontrol.hxx"
28 #include <AIModel/AIAircraft.hxx>
29 #include <AIModel/AIFlightPlan.hxx>
30 #include <Traffic/TrafficMgr.hxx>
31 #include <Airports/groundnetwork.hxx>
32 #include <Airports/dynamics.hxx>
34 /***************************************************************************
36 **************************************************************************/
37 FGTrafficRecord::FGTrafficRecord() :
50 void FGTrafficRecord::setPositionAndIntentions(int pos, FGAIFlightPlan *route)
54 if (intentions.size()) {
55 intVecIterator i = intentions.begin();
57 SG_LOG(SG_GENERAL, SG_ALERT, "Error in FGTrafficRecord::setPositionAndIntentions");
58 //cerr << "Pos : " << pos << " Curr " << *(intentions.begin()) << endl;
59 for (intVecIterator i = intentions.begin(); i != intentions.end() ; i++) {
60 //cerr << (*i) << " ";
67 //FGAIFlightPlan::waypoint* const wpt= route->getCurrentWaypoint();
68 int size = route->getNrOfWayPoints();
69 //cerr << "Setting pos" << pos << " ";
70 //cerr << "setting intentions ";
71 for (int i = 0; i < size; i++) {
72 int val = route->getRouteIndex(i);
74 if ((val) && (val != pos))
76 intentions.push_back(val);
81 //while (route->next(&legNr, &routeNr)) {
82 //intentions.push_back(routeNr);
84 //route->rewind(currentPos);
89 bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord &other)
92 //cerr << "Start check 1" << endl;
93 if (currentPos == other.currentPos)
95 //cerr << callsign << ": Check Position and intentions: we are on the same taxiway" << other.callsign << "Index = " << currentPos << endl;
98 // else if (other.intentions.size())
100 // cerr << "Start check 2" << endl;
101 // intVecIterator i = other.intentions.begin();
102 // while (!((i == other.intentions.end()) || ((*i) == currentPos)))
104 // if (i != other.intentions.end()) {
105 // cerr << "Check Position and intentions: current matches other.intentions" << endl;
108 else if (intentions.size()) {
109 //cerr << "Start check 3" << endl;
110 intVecIterator i = intentions.begin();
111 //while (!((i == intentions.end()) || ((*i) == other.currentPos)))
112 while (i != intentions.end()) {
113 if ((*i) == other.currentPos) {
118 if (i != intentions.end()) {
119 //cerr << callsign << ": Check Position and intentions: .other.current matches" << other.callsign << "Index = " << (*i) << endl;
123 //cerr << "Done !!" << endl;
127 void FGTrafficRecord::setPositionAndHeading(double lat, double lon, double hdg,
128 double spd, double alt)
137 int FGTrafficRecord::crosses(FGGroundNetwork *net, FGTrafficRecord &other)
139 if (checkPositionAndIntentions(other) || (other.checkPositionAndIntentions(*this)))
142 int currentTargetNode = 0, otherTargetNode = 0;
144 currentTargetNode = net->findSegment(currentPos )->getEnd()->getIndex(); // OKAY,...
145 if (other.currentPos > 0)
146 otherTargetNode = net->findSegment(other.currentPos)->getEnd()->getIndex(); // OKAY,...
147 if ((currentTargetNode == otherTargetNode) && currentTargetNode > 0)
148 return currentTargetNode;
149 if (intentions.size())
151 for (i = intentions.begin(); i != intentions.end(); i++)
154 if ((currentTargetNode == net->findSegment(*i)->getEnd()->getIndex()))
156 //cerr << "Current crosses at " << currentTargetNode <<endl;
157 return currentTargetNode;
162 if (other.intentions.size())
164 for (i = other.intentions.begin(); i != other.intentions.end(); i++)
167 if (otherTargetNode == net->findSegment(*i)->getEnd()->getIndex())
169 //cerr << "Other crosses at " << currentTargetNode <<endl;
170 return otherTargetNode;
175 if (intentions.size() && other.intentions.size())
177 for (i = intentions.begin(); i != intentions.end(); i++)
179 for (j = other.intentions.begin(); j != other.intentions.end(); j++)
181 //cerr << "finding segment " << *i << " and " << *j << endl;
182 if (((*i) > 0) && ((*j) > 0)) {
183 currentTargetNode = net->findSegment(*i)->getEnd()->getIndex();
184 otherTargetNode = net->findSegment(*j)->getEnd()->getIndex();
185 if (currentTargetNode == otherTargetNode)
187 //cerr << "Routes will cross at " << currentTargetNode << endl;
188 return currentTargetNode;
197 bool FGTrafficRecord::onRoute(FGGroundNetwork *net, FGTrafficRecord &other)
199 int node = -1, othernode = -1;
201 node = net->findSegment(currentPos)->getEnd()->getIndex();
202 if (other.currentPos > 0)
203 othernode = net->findSegment(other.currentPos)->getEnd()->getIndex();
204 if ((node == othernode) && (node != -1))
206 if (other.intentions.size())
208 for (intVecIterator i = other.intentions.begin(); i != other.intentions.end(); i++)
212 othernode = net->findSegment(*i)->getEnd()->getIndex();
213 if ((node == othernode) && (node > -1))
218 //if (other.currentPos > 0)
219 // othernode = net->findSegment(other.currentPos)->getEnd()->getIndex();
220 //if (intentions.size())
222 // for (intVecIterator i = intentions.begin(); i != intentions.end(); i++)
226 // node = net->findSegment(*i)->getEnd()->getIndex();
227 // if ((node == othernode) && (node > -1))
236 bool FGTrafficRecord::isOpposing (FGGroundNetwork *net, FGTrafficRecord &other, int node)
238 // Check if current segment is the reverse segment for the other aircraft
240 //cerr << "Current segment " << currentPos << endl;
241 if ((currentPos > 0) && (other.currentPos > 0))
243 opp = net->findSegment(currentPos)->opposite();
245 if (opp->getIndex() == other.currentPos)
249 for (intVecIterator i = intentions.begin(); i != intentions.end(); i++)
251 if ((opp = net->findSegment(other.currentPos)->opposite()))
254 if (opp->getIndex() == net->findSegment(*i)->getIndex())
256 if (net->findSegment(*i)->getStart()->getIndex() == node) {
258 //cerr << "Found the node " << node << endl;
264 if (other.intentions.size())
266 for (intVecIterator j = other.intentions.begin(); j != other.intentions.end(); j++)
268 // cerr << "Current segment 1 " << (*i) << endl;
270 if ((opp = net->findSegment(*i)->opposite()))
272 if (opp->getIndex() ==
273 net->findSegment(*j)->getIndex())
275 //cerr << "Nodes " << net->findSegment(*i)->getIndex()
276 // << " and " << net->findSegment(*j)->getIndex()
277 // << " are opposites " << endl;
278 if (net->findSegment(*i)->getStart()->getIndex() == node) {
280 //cerr << "Found the node " << node << endl;
294 void FGTrafficRecord::setSpeedAdjustment(double spd)
296 instruction.setChangeSpeed(true);
297 instruction.setSpeed(spd);
300 void FGTrafficRecord::setHeadingAdjustment(double heading)
302 instruction.setChangeHeading(true);
303 instruction.setHeading(heading);
308 /***************************************************************************
311 **************************************************************************/
312 FGATCInstruction::FGATCInstruction()
315 holdPosition = false;
317 changeHeading = false;
318 changeAltitude = false;
319 resolveCircularWait = false;
326 bool FGATCInstruction::hasInstruction()
328 return (holdPattern || holdPosition || changeSpeed || changeHeading || changeAltitude || resolveCircularWait);
331 string FGATCController::getGateName(FGAIAircraft *ref)
333 return ref->atGate();
336 void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir)
338 string sender, receiver;
341 string atisInformation;
344 case ATC_AIR_TO_GROUND:
345 sender = rec->getAircraft()->getTrafficRef()->getCallSign();
346 switch (rec->getLeg()) {
350 rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getGroundFrequency(rec->getLeg());
352 rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getGroundFrequency(3);
353 receiver = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getName() + "-Ground";
354 atisInformation = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getAtisInformation();
357 receiver = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getName() + "-Tower";
361 case ATC_GROUND_TO_AIR:
362 receiver = rec->getAircraft()->getTrafficRef()->getCallSign();
363 switch (rec->getLeg()) {
367 rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getGroundFrequency(rec->getLeg());
369 rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getGroundFrequency(3);
370 sender = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getName() + "-Ground";
371 atisInformation = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getAtisInformation();
375 sender = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getName() + "-Tower";
387 string transponderCode;
391 case MSG_ANNOUNCE_ENGINE_START:
392 text = sender + ". Ready to Start up";
394 case MSG_REQUEST_ENGINE_START:
395 text = receiver + ", This is " + sender + ". Position " +getGateName(rec->getAircraft()) +
396 ". Information " + atisInformation + ". " +
397 rec->getAircraft()->getTrafficRef()->getFlightRules() + " to " +
398 rec->getAircraft()->getTrafficRef()->getArrivalAirport()->getName() + ". Request start-up";
400 // Acknowledge engine startup permission
401 // Assign departure runway
402 // Assign SID, if necessery (TODO)
403 case MSG_PERMIT_ENGINE_START:
404 taxiFreqStr = formatATCFrequency3_2(taxiFreq);
406 heading = rec->getAircraft()->getTrafficRef()->getCourse();
407 fltType = rec->getAircraft()->getTrafficRef()->getFlightType();
408 rwyClass= rec->getAircraft()->GetFlightPlan()->getRunwayClassFromTrafficType(fltType);
410 rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway, heading);
411 rec->getAircraft()->GetFlightPlan()->setRunway(activeRunway);
412 fp = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getSID(activeRunway, heading);
413 rec->getAircraft()->GetFlightPlan()->setSID(fp);
415 SID = fp->getName() + " departure";
417 SID = "fly runway heading ";
419 //snprintf(buffer, 7, "%3.2f", heading);
420 fltRules = rec->getAircraft()->getTrafficRef()->getFlightRules();
421 transponderCode = genTransponderCode(fltRules);
422 rec->getAircraft()->SetTransponderCode(transponderCode);
423 text = receiver + ". Start-up approved. " + atisInformation + " correct, runway " + activeRunway
424 + ", " + SID + ", squawk " + transponderCode + ". " +
425 "For push-back and taxi clearance call " + taxiFreqStr + ". " + sender + " control.";
427 case MSG_DENY_ENGINE_START:
428 text = receiver + ". Standby";
430 case MSG_ACKNOWLEDGE_ENGINE_START:
431 fp = rec->getAircraft()->GetFlightPlan()->getSID();
433 SID = rec->getAircraft()->GetFlightPlan()->getSID()->getName() + " departure";
435 SID = "fly runway heading ";
437 taxiFreqStr = formatATCFrequency3_2(taxiFreq);
438 activeRunway = rec->getAircraft()->GetFlightPlan()->getRunway();
439 transponderCode = rec->getAircraft()->GetTransponderCode();
440 text = receiver + ". Start-up approved. " + atisInformation + " correct, runway " +
441 activeRunway + ", " + SID + ", squawk " + transponderCode + ". " +
442 "For push-back and taxi clearance call " + taxiFreqStr + ". " + sender;
447 double onBoardRadioFreq0 = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
448 double onBoardRadioFreq1 = fgGetDouble("/instrumentation/comm[1]/frequencies/selected-mhz");
449 int onBoardRadioFreqI0 = (int) floor(onBoardRadioFreq0 * 100 + 0.5);
450 int onBoardRadioFreqI1 = (int) floor(onBoardRadioFreq1 * 100 + 0.5);
451 //cerr << "Using " << onBoardRadioFreq0 << ", " << onBoardRadioFreq1 << " and " << stationFreq << endl;
453 // Display ATC message only when one of the radios is tuned
454 // the relevant frequency.
455 // Note that distance attenuation is currently not yet implemented
456 //cerr << "Transmitting " << text << " at " << stationFreq;
457 if ((onBoardRadioFreqI0 == stationFreq) || (onBoardRadioFreqI1 == stationFreq)) {
458 fgSetString("/sim/messages/atc", text.c_str());
459 //cerr << "Printing Message: " << endl;
463 string FGATCController::formatATCFrequency3_2(int freq) {
465 snprintf(buffer, 7, "%3.2f", ( (float) freq / 100.0) );
466 return string(buffer);
469 string FGATCController::genTransponderCode(string fltRules) {
470 if (fltRules == "VFR") {
471 return string("1200");
474 snprintf(buffer, 5, "%d%d%d%d", rand() % 8, rand() % 8,rand() % 8, rand() % 8);
475 return string(buffer);
479 /***************************************************************************
480 * class FGTowerController
482 **************************************************************************/
483 FGTowerController::FGTowerController() :
489 void FGTowerController::announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentPosition,
490 double lat, double lon, double heading,
491 double speed, double alt, double radius, int leg,
494 TrafficVectorIterator i = activeTraffic.begin();
495 // Search whether the current id alread has an entry
496 // This might be faster using a map instead of a vector, but let's start by taking a safe route
497 if (activeTraffic.size()) {
498 //while ((i->getId() != id) && i != activeTraffic.end()) {
499 while (i != activeTraffic.end()) {
500 if (i->getId() == id) {
507 // Add a new TrafficRecord if no one exsists for this aircraft.
508 if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
512 rec.setPositionAndHeading(lat, lon, heading, speed, alt);
513 rec.setRunway(intendedRoute->getRunway());
515 //rec.setCallSign(callsign);
516 rec.setAircraft(ref);
517 activeTraffic.push_back(rec);
519 i->setPositionAndHeading(lat, lon, heading, speed, alt);
523 void FGTowerController::update(int id, double lat, double lon, double heading, double speed, double alt,
526 TrafficVectorIterator i = activeTraffic.begin();
527 // Search search if the current id has an entry
528 // This might be faster using a map instead of a vector, but let's start by taking a safe route
529 TrafficVectorIterator current, closest;
530 if (activeTraffic.size()) {
531 //while ((i->getId() != id) && i != activeTraffic.end()) {
532 while (i != activeTraffic.end()) {
533 if (i->getId() == id) {
540 // // update position of the current aircraft
541 if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
542 SG_LOG(SG_GENERAL, SG_ALERT, "AI error: updating aircraft without traffic record");
544 i->setPositionAndHeading(lat, lon, heading, speed, alt);
549 // // see if we already have a clearance record for the currently active runway
550 ActiveRunwayVecIterator rwy = activeRunways.begin();
551 // again, a map might be more efficient here
552 if (activeRunways.size()) {
553 //while ((rwy->getRunwayName() != current->getRunway()) && (rwy != activeRunways.end())) {
554 while (rwy != activeRunways.end()) {
555 if (rwy->getRunwayName() == current->getRunway()) {
561 if (rwy == activeRunways.end()) {
562 ActiveRunway aRwy(current->getRunway(), id);
563 activeRunways.push_back(aRwy); // Since there are no clearance records for this runway yet
564 current->setHoldPosition(false); // Clear the current aircraft to continue
567 // Okay, we have a clearance record for this runway, so check
568 // whether the clearence ID matches that of the current aircraft
569 if (id == rwy->getCleared()) {
570 current->setHoldPosition(false);
572 current->setHoldPosition(true);
578 void FGTowerController::signOff(int id)
580 TrafficVectorIterator i = activeTraffic.begin();
581 // Search search if the current id alread has an entry
582 // This might be faster using a map instead of a vector, but let's start by taking a safe route
583 if (activeTraffic.size()) {
584 //while ((i->getId() != id) && i != activeTraffic.end()) {
585 while (i != activeTraffic.end()) {
586 if (i->getId() == id) {
592 // If this aircraft has left the runway, we can clear the departure record for this runway
593 ActiveRunwayVecIterator rwy = activeRunways.begin();
594 if (activeRunways.size()) {
595 //while ((rwy->getRunwayName() != i->getRunway()) && (rwy != activeRunways.end())) {
596 while (rwy != activeRunways.end()) {
597 if (rwy->getRunwayName() == i->getRunway()) {
602 if (rwy != activeRunways.end()) {
603 rwy = activeRunways.erase(rwy);
605 SG_LOG(SG_GENERAL, SG_ALERT, "AI error: Attempting to erase non-existing runway clearance record in FGTowerController::signoff");
608 if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
609 SG_LOG(SG_GENERAL, SG_ALERT, "AI error: Aircraft without traffic record is signing off from tower");
611 i = activeTraffic.erase(i);
616 // IF WE MAKE TRAFFICRECORD A MEMBER OF THE BASE CLASS
617 // THE FOLLOWING THREE FUNCTIONS: SIGNOFF, HAS INSTRUCTION AND GETINSTRUCTION CAN
618 // BECOME DEVIRTUALIZED AND BE A MEMBER OF THE BASE ATCCONTROLLER CLASS
619 // WHICH WOULD SIMPLIFY CODE MAINTENANCE.
620 // Note that this function is probably obsolete
621 bool FGTowerController::hasInstruction(int id)
623 TrafficVectorIterator i = activeTraffic.begin();
624 // Search search if the current id has an entry
625 // This might be faster using a map instead of a vector, but let's start by taking a safe route
626 if (activeTraffic.size())
628 //while ((i->getId() != id) && i != activeTraffic.end()) {
629 while (i != activeTraffic.end()) {
630 if (i->getId() == id) {
636 if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
637 SG_LOG(SG_GENERAL, SG_ALERT, "AI error: checking ATC instruction for aircraft without traffic record");
639 return i->hasInstruction();
645 FGATCInstruction FGTowerController::getInstruction(int id)
647 TrafficVectorIterator i = activeTraffic.begin();
648 // Search search if the current id has an entry
649 // This might be faster using a map instead of a vector, but let's start by taking a safe route
650 if (activeTraffic.size()) {
651 //while ((i->getId() != id) && i != activeTraffic.end()) {
652 while (i != activeTraffic.end()) {
653 if (i->getId() == id) {
659 if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
660 SG_LOG(SG_GENERAL, SG_ALERT, "AI error: requesting ATC instruction for aircraft without traffic record");
662 return i->getInstruction();
664 return FGATCInstruction();
667 /***************************************************************************
668 * class FGStartupController
670 **************************************************************************/
671 FGStartupController::FGStartupController() :
675 lastTransmission = 0;
678 void FGStartupController::announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentPosition,
679 double lat, double lon, double heading,
680 double speed, double alt, double radius, int leg,
683 TrafficVectorIterator i = activeTraffic.begin();
684 // Search whether the current id alread has an entry
685 // This might be faster using a map instead of a vector, but let's start by taking a safe route
686 if (activeTraffic.size()) {
687 //while ((i->getId() != id) && i != activeTraffic.end()) {
688 while (i != activeTraffic.end()) {
689 if (i->getId() == id) {
696 // Add a new TrafficRecord if no one exsists for this aircraft.
697 if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
701 rec.setPositionAndHeading(lat, lon, heading, speed, alt);
702 rec.setRunway(intendedRoute->getRunway());
704 //rec.setCallSign(callsign);
705 rec.setAircraft(ref);
706 rec.setHoldPosition(true);
707 activeTraffic.push_back(rec);
709 i->setPositionAndHeading(lat, lon, heading, speed, alt);
715 // IF WE MAKE TRAFFICRECORD A MEMBER OF THE BASE CLASS
716 // THE FOLLOWING THREE FUNCTIONS: SIGNOFF, HAS INSTRUCTION AND GETINSTRUCTION CAN
717 // BECOME DEVIRTUALIZED AND BE A MEMBER OF THE BASE ATCCONTROLLER CLASS
718 // WHICH WOULD SIMPLIFY CODE MAINTENANCE.
719 // Note that this function is probably obsolete
720 bool FGStartupController::hasInstruction(int id)
722 TrafficVectorIterator i = activeTraffic.begin();
723 // Search search if the current id has an entry
724 // This might be faster using a map instead of a vector, but let's start by taking a safe route
725 if (activeTraffic.size())
727 //while ((i->getId() != id) && i != activeTraffic.end()) {
728 while (i != activeTraffic.end()) {
729 if (i->getId() == id) {
735 if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
736 SG_LOG(SG_GENERAL, SG_ALERT, "AI error: checking ATC instruction for aircraft without traffic record");
738 return i->hasInstruction();
744 FGATCInstruction FGStartupController::getInstruction(int id)
746 TrafficVectorIterator i = activeTraffic.begin();
747 // Search search if the current id has an entry
748 // This might be faster using a map instead of a vector, but let's start by taking a safe route
749 if (activeTraffic.size()) {
750 //while ((i->getId() != id) && i != activeTraffic.end()) {
751 while (i != activeTraffic.end()) {
752 if (i->getId() == id) {
758 if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
759 SG_LOG(SG_GENERAL, SG_ALERT, "AI error: requesting ATC instruction for aircraft without traffic record");
761 return i->getInstruction();
763 return FGATCInstruction();
766 void FGStartupController::signOff(int id)
768 TrafficVectorIterator i = activeTraffic.begin();
769 // Search search if the current id alread has an entry
770 // This might be faster using a map instead of a vector, but let's start by taking a safe route
771 if (activeTraffic.size()) {
772 //while ((i->getId() != id) && i != activeTraffic.end()) {
773 while (i != activeTraffic.end()) {
774 if (i->getId() == id) {
780 if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
781 SG_LOG(SG_GENERAL, SG_ALERT, "AI error: Aircraft without traffic record is signing off from tower");
783 i = activeTraffic.erase(i);
787 void FGStartupController::update(int id, double lat, double lon, double heading, double speed, double alt,
790 TrafficVectorIterator i = activeTraffic.begin();
791 // Search search if the current id has an entry
792 // This might be faster using a map instead of a vector, but let's start by taking a safe route
793 TrafficVectorIterator current, closest;
794 if (activeTraffic.size()) {
795 //while ((i->getId() != id) && i != activeTraffic.end()) {
796 while (i != activeTraffic.end()) {
797 if (i->getId() == id) {
804 // // update position of the current aircraft
805 if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
806 SG_LOG(SG_GENERAL, SG_ALERT, "AI error: updating aircraft without traffic record");
808 i->setPositionAndHeading(lat, lon, heading, speed, alt);
813 int state = i->getState();
814 time_t startTime = i->getAircraft()->getTrafficRef()->getDepartureTime();
815 time_t now = time(NULL) + fgGetLong("/sim/time/warp");
816 //cerr << i->getAircraft()->getTrafficRef()->getCallSign()
817 // << " is scheduled to depart in " << startTime-now << " seconds. Available = " << available
818 // << " at parking " << getGateName(i->getAircraft()) << endl;
820 if ((now - lastTransmission) > 3 + (rand() % 15)) {
824 if ((state == 0) && available) {
825 if (now > startTime) {
826 //cerr << "Transmitting startup msg" << endl;
827 transmit(&(*i), MSG_ANNOUNCE_ENGINE_START, ATC_AIR_TO_GROUND);
829 lastTransmission = now;
833 if ((state == 1) && available) {
834 if (now > startTime+60) {
835 transmit(&(*i), MSG_REQUEST_ENGINE_START, ATC_AIR_TO_GROUND);
837 lastTransmission = now;
841 if ((state == 2) && available) {
842 if (now > startTime+80) {
843 transmit(&(*i), MSG_PERMIT_ENGINE_START, ATC_GROUND_TO_AIR);
845 lastTransmission = now;
849 if ((state == 3) && available){
850 if (now > startTime+100) {
851 transmit(&(*i), MSG_ACKNOWLEDGE_ENGINE_START, ATC_AIR_TO_GROUND);
853 lastTransmission = now;
857 // TODO: Switch to APRON control and request pushback Clearance.
858 // Get Push back clearance
859 if ((state == 4) && available){
860 i->setHoldPosition(false);