// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_STRINGS_H
+# include <strings.h> // bcopy()
+#else
+# include <string.h> // MSVC doesn't have strings.h
+#endif
+
#include <Main/globals.hxx>
#include <Airports/runways.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include "ATCdisplay.hxx"
#include "ATCmgr.hxx"
#include "ATCutils.hxx"
+#include "ATCDialog.hxx"
#include "commlist.hxx"
#include "AILocalTraffic.hxx"
// TowerPlaneRec
TowerPlaneRec::TowerPlaneRec() :
-clearedToLand(false),
-clearedToLineUp(false),
-clearedToTakeOff(false),
-holdShortReported(false),
-downwindReported(false),
-longFinalReported(false),
-longFinalAcknowledged(false),
-finalReported(false),
-finalAcknowledged(false),
-onRwy(false),
-nextOnRwy(false),
-opType(TTT_UNKNOWN),
-leg(LEG_UNKNOWN),
-landingType(AIP_LT_UNKNOWN),
-isUser(false)
+ clearedToLand(false),
+ clearedToLineUp(false),
+ clearedToTakeOff(false),
+ holdShortReported(false),
+ downwindReported(false),
+ longFinalReported(false),
+ longFinalAcknowledged(false),
+ finalReported(false),
+ finalAcknowledged(false),
+ rwyVacatedReported(false),
+ rwyVacatedAcknowledged(false),
+ instructedToGoAround(false),
+ onRwy(false),
+ nextOnRwy(false),
+ vfrArrivalReported(false),
+ vfrArrivalAcknowledged(false),
+ opType(TTT_UNKNOWN),
+ leg(LEG_UNKNOWN),
+ landingType(AIP_LT_UNKNOWN),
+ isUser(false)
{
plane.callsign = "UNKNOWN";
}
TowerPlaneRec::TowerPlaneRec(PlaneRec p) :
-clearedToLand(false),
-clearedToLineUp(false),
-clearedToTakeOff(false),
-holdShortReported(false),
-downwindReported(false),
-longFinalReported(false),
-longFinalAcknowledged(false),
-finalReported(false),
-finalAcknowledged(false),
-onRwy(false),
-nextOnRwy(false),
-opType(TTT_UNKNOWN),
-leg(LEG_UNKNOWN),
-landingType(AIP_LT_UNKNOWN),
-isUser(false)
+ clearedToLand(false),
+ clearedToLineUp(false),
+ clearedToTakeOff(false),
+ holdShortReported(false),
+ downwindReported(false),
+ longFinalReported(false),
+ longFinalAcknowledged(false),
+ finalReported(false),
+ finalAcknowledged(false),
+ rwyVacatedReported(false),
+ rwyVacatedAcknowledged(false),
+ instructedToGoAround(false),
+ onRwy(false),
+ nextOnRwy(false),
+ vfrArrivalReported(false),
+ vfrArrivalAcknowledged(false),
+ opType(TTT_UNKNOWN),
+ leg(LEG_UNKNOWN),
+ landingType(AIP_LT_UNKNOWN),
+ isUser(false)
{
plane = p;
}
TowerPlaneRec::TowerPlaneRec(Point3D pt) :
-clearedToLand(false),
-clearedToLineUp(false),
-clearedToTakeOff(false),
-holdShortReported(false),
-downwindReported(false),
-longFinalReported(false),
-longFinalAcknowledged(false),
-finalReported(false),
-finalAcknowledged(false),
-onRwy(false),
-nextOnRwy(false),
-opType(TTT_UNKNOWN),
-leg(LEG_UNKNOWN),
-landingType(AIP_LT_UNKNOWN),
-isUser(false)
+ clearedToLand(false),
+ clearedToLineUp(false),
+ clearedToTakeOff(false),
+ holdShortReported(false),
+ downwindReported(false),
+ longFinalReported(false),
+ longFinalAcknowledged(false),
+ finalReported(false),
+ finalAcknowledged(false),
+ rwyVacatedReported(false),
+ rwyVacatedAcknowledged(false),
+ instructedToGoAround(false),
+ onRwy(false),
+ nextOnRwy(false),
+ vfrArrivalReported(false),
+ vfrArrivalAcknowledged(false),
+ opType(TTT_UNKNOWN),
+ leg(LEG_UNKNOWN),
+ landingType(AIP_LT_UNKNOWN),
+ isUser(false)
{
plane.callsign = "UNKNOWN";
pos = pt;
}
TowerPlaneRec::TowerPlaneRec(PlaneRec p, Point3D pt) :
-clearedToLand(false),
-clearedToLineUp(false),
-clearedToTakeOff(false),
-holdShortReported(false),
-downwindReported(false),
-longFinalReported(false),
-longFinalAcknowledged(false),
-finalReported(false),
-finalAcknowledged(false),
-onRwy(false),
-nextOnRwy(false),
-opType(TTT_UNKNOWN),
-leg(LEG_UNKNOWN),
-landingType(AIP_LT_UNKNOWN),
-isUser(false)
+ clearedToLand(false),
+ clearedToLineUp(false),
+ clearedToTakeOff(false),
+ holdShortReported(false),
+ downwindReported(false),
+ longFinalReported(false),
+ longFinalAcknowledged(false),
+ finalReported(false),
+ finalAcknowledged(false),
+ rwyVacatedReported(false),
+ rwyVacatedAcknowledged(false),
+ instructedToGoAround(false),
+ onRwy(false),
+ nextOnRwy(false),
+ vfrArrivalReported(false),
+ vfrArrivalAcknowledged(false),
+ opType(TTT_UNKNOWN),
+ leg(LEG_UNKNOWN),
+ landingType(AIP_LT_UNKNOWN),
+ isUser(false)
{
plane = p;
pos = pt;
Currently user is assumed to have taken off again when leaving the runway - check speed/elev for taxiing-in.
-AI plane lands even when user on rwy - make it go-around instead.
-
Tell AI plane to contact ground when taxiing in.
Use track instead of heading to determine what leg of the circuit the user is flying.
timeSinceLastDeparture = 9999;
departed = false;
+
+ nominal_downwind_leg_pos = 1000.0;
+ nominal_base_leg_pos = -1000.0;
+ // TODO - set nominal crosswind leg pos based on minimum distance from takeoff end of rwy.
}
FGTower::~FGTower() {
if(rwyOccupied) {
// Assume the user is started at the threshold ready to take-off
TowerPlaneRec* t = new TowerPlaneRec;
- t->plane.callsign = "Charlie Foxtrot Sierra"; // C-FGFS !!! - fixme - this is a bit hardwired
- t->plane.type = GA_SINGLE;
+ t->plane.callsign = fgGetString("/sim/user/callsign");
+ t->plane.type = GA_SINGLE; // FIXME - hardwired!!
t->opType = TTT_UNKNOWN; // We don't know if the user wants to do circuits or a departure...
t->landingType = AIP_LT_UNKNOWN;
t->leg = TAKEOFF_ROLL;
t->clearedToTakeOff = true;
rwyList.push_back(t);
departed = false;
+ } else {
+ // For now assume that this means the user is not at the airport and is in the air.
+ // TODO FIXME - this will break when user starts on apron, at hold short, etc.
+ current_atcdialog->add_entry(ident, "@AP Tower @CS @MI miles @CD of the airport for full stop with the ATIS", "Contact tower for VFR arrival (full stop)", TOWER, (int)USER_REQUEST_VFR_ARRIVAL_FULL_STOP);
}
}
cout << update_count << "\ttL: " << trafficList.size() << " cL: " << circuitList.size() << " hL: " << holdList.size() << " aL: " << appList.size() << '\n';
}
*/
+ //if(ident == "EGNX") cout << display << '\n';
if(departed != false) {
timeSinceLastDeparture += dt;
// cout << " dt = " << dt << " timeSinceLastDeparture = " << timeSinceLastDeparture << '\n';
}
+ //cout << ident << " respond = " << respond << " responseReqd = " << responseReqd << '\n';
if(respond) {
if(!responseReqd) SG_LOG(SG_ATC, SG_ALERT, "ERROR - respond is true and responseReqd is false in FGTower::Update(...)");
Respond();
//cout << "Done T" << endl;
}
+void FGTower::ReceiveUserCallback(int code) {
+ if(code == (int)USER_REQUEST_VFR_DEPARTURE) {
+ cout << "User requested departure\n";
+ } else if(code == (int)USER_REQUEST_VFR_ARRIVAL) {
+ VFRArrivalContact("USER");
+ } else if(code == (int)USER_REQUEST_VFR_ARRIVAL_FULL_STOP) {
+ VFRArrivalContact("USER", FULL_STOP);
+ } else if(code == (int)USER_REQUEST_VFR_ARRIVAL_TOUCH_AND_GO) {
+ VFRArrivalContact("USER", TOUCH_AND_GO);
+ } else if(code == (int)USER_REPORT_DOWNWIND) {
+ ReportDownwind("USER");
+ } else if(code == (int)USER_REPORT_3_MILE_FINAL) {
+ // For now we'll just call report final instead of report long final to avoid having to alter the response code
+ ReportFinal("USER");
+ } else if(code == (int)USER_REPORT_RWY_VACATED) {
+ ReportRunwayVacated("USER");
+ }
+}
+
void FGTower::Respond() {
- //cout << "Entering Respond..." << endl;
+ cout << "Entering Respond, responseID = " << responseID << endl;
TowerPlaneRec* t = FindPlane(responseID);
if(t) {
// This will grow!!!
- if(t->downwindReported) {
+ if(t->vfrArrivalReported && !t->vfrArrivalAcknowledged) {
+ // Testing - hardwire straight in for now
+ string trns = t->plane.callsign;
+ trns += " ";
+ trns += name;
+ trns += " Tower";
+ // Should we clear staight in or for downwind entry?
+ // For now we'll clear straight in if greater than 1km from a line drawn through the threshold perpendicular to the rwy.
+ // Later on we might check the actual heading and direct some of those to enter on downwind or base.
+ Point3D op = ortho.ConvertToLocal(t->pos);
+ if(op.y() < -1000) {
+ trns += " Report three mile straight-in runway ";
+ current_atcdialog->add_entry(ident, "@AP Tower @CS @MI mile final Runway @RW", "Report Final", TOWER, (int)USER_REPORT_3_MILE_FINAL);
+ } else {
+ // For now we'll just request reporting downwind.
+ // TODO - In real life something like 'report 2 miles southwest right downwind rwy 19R' might be used
+ // but I'm not sure how to handle all permutations of which direction to tell to report from yet.
+ trns += " Report ";
+ trns += (rwy.patternDirection ? "right " : "left ");
+ trns += "downwind runway ";
+ current_atcdialog->add_entry(ident, "@AP Tower @CS Downwind @RW", "Report Downwind", TOWER, (int)USER_REPORT_DOWNWIND);
+ }
+ trns += ConvertRwyNumToSpokenString(activeRwy);
+ if(display) {
+ globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
+ } else {
+ cout << "Not displaying, trns was " << trns << '\n';
+ }
+ t->vfrArrivalAcknowledged = true;
+ } else if(t->downwindReported) {
t->downwindReported = false;
int i = 1;
for(tower_plane_rec_list_iterator twrItr = circuitList.begin(); twrItr != circuitList.end(); twrItr++) {
if((*twrItr)->plane.callsign == responseID) break;
++i;
- }
- string trns = "Number ";
+ }
+ string trns = t->plane.callsign;
+ trns += " Number ";
trns += ConvertNumToSpokenDigits(i);
trns += " ";
- trns += t->plane.callsign;
+ if(i == 1) {
+ trns += "Cleared to land";
+ t->clearedToLand = true;
+ }
if(display) {
- globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
+ globals->get_ATC_display()->RegisterSingleMessage(trns);
}
- if(t->isUser && t->opType == TTT_UNKNOWN) {
- t->opType = CIRCUIT;
+ if(t->isUser) {
+ if(t->opType == TTT_UNKNOWN) t->opType = CIRCUIT;
+ current_atcdialog->add_entry(ident, "@CS Clear of the runway", "Report runway vacated", TOWER, USER_REPORT_RWY_VACATED);
}
} else if(t->holdShortReported) {
if(t->nextOnRwy) {
}
t->holdShortReported = false;
} else if(t->finalReported && !(t->finalAcknowledged)) {
+ bool disp = true;
string trns = t->plane.callsign;
+ cout << (t->nextOnRwy ? "Next on rwy " : "Not next!! ");
+ cout << (rwyOccupied ? "RWY OCCUPIED!!\n" : "Rwy not occupied\n");
if(t->nextOnRwy && !rwyOccupied) {
if(t->landingType == FULL_STOP) {
trns += " cleared to land ";
}
// TODO - add winds
t->clearedToLand = true;
+ if(t->isUser) current_atcdialog->add_entry(ident, "@CS Clear of the runway", "Report runway vacated", TOWER, USER_REPORT_RWY_VACATED);
+ } else if(t->eta < 20) {
+ // Do nothing - we'll be telling it to go around in less than 10 seconds if the
+ // runway doesn't clear so no point in calling "continue approach".
+ disp = false;
} else {
trns += " continue approach";
t->clearedToLand = false;
}
- if(display) {
- globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
+ if(display && disp) {
+ globals->get_ATC_display()->RegisterSingleMessage(trns);
}
t->finalAcknowledged = true;
+ } else if(t->rwyVacatedReported && !(t->rwyVacatedAcknowledged)) {
+ string trns = t->plane.callsign;
+ if(separateGround) {
+ trns += " Contact ground on ";
+ double f = globals->get_ATC_mgr()->GetFrequency(ident, GROUND) / 100.0;
+ char buf[10];
+ sprintf(buf, "%.2f", f);
+ trns += buf;
+ trns += " Good Day";
+ } else {
+ // Cop-out!!
+ trns += " cleared for taxi to the GA parking";
+ }
+ if(display) {
+ globals->get_ATC_display()->RegisterSingleMessage(trns);
+ }
+ t->rwyVacatedAcknowledged = true;
+ // Maybe we should check that the plane really *has* vacated the runway!
}
}
freqClear = true; // FIXME - set this to come true after enough time to render the message
case CROSSWIND:
crosswind_leg_pos = tortho.y();
//cout << "crosswind_leg_pos = " << crosswind_leg_pos << '\n';
+ t->instructedToGoAround = false;
break;
case TURN1:
// Fall through to climbout
if(t->leg == FINAL) {
if(t->landingType == FULL_STOP) t->opType = INBOUND;
+ if(t->eta < 12 && rwyList.size() && !(t->instructedToGoAround)) {
+ // TODO - need to make this more sophisticated
+ // eg. is the plane accelerating down the runway taking off [OK],
+ // or stationary near the start [V. BAD!!].
+ // For now this should stop the AI plane landing on top of the user.
+ string trns = t->plane.callsign;
+ trns += " GO AROUND TRAFFIC ON RUNWAY I REPEAT GO AROUND";
+ if(display) {
+ globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
+ }
+ t->instructedToGoAround = true;
+ if(t->planePtr) {
+ cout << "Registering Go-around transmission with AI plane\n";
+ t->planePtr->RegisterTransmission(13);
+ }
+ }
} else if(t->leg == LANDING_ROLL) {
rwyList.push_front(t);
// TODO - if(!clearedToLand) shout something!!
}
}
bool FGTower::GetDownwindConstraint(double& dpos) {
- if(downwind_leg_pos != 0.0) {
+ if(fabs(downwind_leg_pos) > nominal_downwind_leg_pos) {
dpos = downwind_leg_pos;
return(true);
} else {
}
}
bool FGTower::GetBaseConstraint(double& bpos) {
- if(base_leg_pos != 0.0) {
+ if(base_leg_pos < nominal_base_leg_pos) {
bpos = base_leg_pos;
return(true);
} else {
- bpos = 0.0;
+ bpos = nominal_base_leg_pos;
return(false);
}
}
ortho.Init(rwy.threshold_pos, rwy.hdg);
rwy.end1ortho = ortho.ConvertToLocal(rwy.threshold_pos); // should come out as zero
rwy.end2ortho = ortho.ConvertToLocal(takeoff_end);
+
+ // Set the pattern direction
+ // TODO - we'll check for a facilities file with this in eventually - for now assume left traffic except
+ // for certain circumstances (RH parallel rwy).
+ rwy.patternDirection = -1; // Left
+ if(rwy.rwyID.size() == 3) {
+ rwy.patternDirection = (rwy.rwyID.substr(2,1) == "R" ? 1 : -1);
+ }
} else {
SG_LOG(SG_ATC, SG_ALERT, "Help - can't get good runway in FGTower!!");
activeRwy = "NN";
return(holding ? firstTime : conflict);
}
+// Add a tower plane rec with ETA to the circuit list in the correct position ETA-wise
+// Returns true if this might cause a separation conflict (based on ETA) with other traffic, false otherwise.
+bool FGTower::AddToCircuitList(TowerPlaneRec* t) {
+ //cout << "ADD: " << circuitList.size();
+ //cout << "AddToCircuitList called, currently size = " << circuitList.size() << endl;
+ double separation_time = 60.0; // seconds - this is currently a guess for light plane separation, and includes a few seconds for a holding plane to taxi onto the rwy.
+ bool conflict = false;
+ tower_plane_rec_list_iterator twrItr;
+ for(twrItr = circuitList.begin(); twrItr != circuitList.end(); twrItr++) {
+ TowerPlaneRec* tpr = *twrItr;
+
+ if(t->eta < tpr->eta) {
+ // Ugg - this one's tricky.
+ // It depends on what the two planes are doing and whether there's a conflict what we do.
+ if(tpr->eta - t->eta > separation_time) { // No probs, plane 2 can squeeze in before plane 1 with no apparent conflict
+ circuitList.insert(twrItr, t);
+ } else { // Ooops - this ones tricky - we have a potential conflict!
+ conflict = true;
+ // HACK - just add anyway for now and flag conflict.
+ circuitList.insert(twrItr, t);
+ }
+ //cout << "\tC\t" << circuitList.size() << '\n';
+ return(conflict);
+ }
+ }
+ // If we get here we must be at the end of the list, or maybe the list is empty.
+ circuitList.push_back(t); // TODO - check the separation with the preceding plane for the conflict flag.
+ //cout << "\tE\t" << circuitList.size() << endl;
+ return(conflict);
+}
+
// Calculate the eta of a plane to the threshold.
// For ground traffic this is the fastest they can get there.
Point3D op = ortho.ConvertToLocal(tpr->pos);
//if(printout) {
- // cout << "Orthopos is " << op.x() << ", " << op.y() << '\n';
+ //if(!tpr->isUser) cout << "Orthopos is " << op.x() << ", " << op.y() << ' ';
// cout << "opType is " << tpr->opType << '\n';
//}
double dist_out_m = op.y();
if(!GetBaseConstraint(current_base_dist_out_m)) {
current_base_dist_out_m = nominal_base_dist_out_m;
}
+ //cout << "current_base_dist_out_m = " << current_base_dist_out_m << '\n';
double nominal_dist_across_m = 1000; // Hardwired value from AILocalTraffic
double current_dist_across_m;
if(!GetDownwindConstraint(current_dist_across_m)) {
}
double nominal_cross_dist_out_m = 2000; // Bit of a guess - AI plane turns to crosswind at 600ft agl.
tpr->eta = fabs(current_base_dist_out_m) / final_ias; // final
- //if(printout) cout << "a = " << tpr->eta << '\n';
+ //cout << "a = " << tpr->eta << '\n';
if((tpr->leg == DOWNWIND) || (tpr->leg == TURN2)) {
tpr->eta += dist_across_m / circuit_ias;
- //if(printout) cout << "b = " << tpr->eta << '\n';
+ //cout << "b = " << tpr->eta << '\n';
tpr->eta += fabs(current_base_dist_out_m - dist_out_m) / circuit_ias;
- //if(printout) cout << "c = " << tpr->eta << '\n';
+ //cout << "c = " << tpr->eta << '\n';
} else if((tpr->leg == CROSSWIND) || (tpr->leg == TURN1)) {
if(dist_across_m > nominal_dist_across_m) {
tpr->eta += dist_across_m / circuit_ias;
//if(printout) {
// cout << "ETA = " << tpr->eta << '\n';
//}
+ //if(!tpr->isUser) cout << tpr->plane.callsign << '\t' << tpr->eta << '\n';
} else {
tpr->eta = 99999;
}
t->clearedToLineUp = false;
t->clearedToTakeOff = false;
t->opType = operation;
+ t->pos = requestee->GetPos();
//cout << "Hold Short reported by " << plane.callsign << '\n';
+ SG_LOG(SG_ATC, SG_BULK, "Hold Short reported by " << plane.callsign);
/*
bool next = AddToTrafficList(t, true);
responseReqd = true;
}
-void FGTower::RequestLandingClearance(string ID) {
- //cout << "Request Landing Clearance called...\n";
+// Register the presence of an AI plane at a point where contact would already have been made in real life
+// CAUTION - currently it is assumed that this plane's callsign is unique - it is up to AIMgr to generate unique callsigns.
+void FGTower::RegisterAIPlane(PlaneRec plane, FGAIPlane* ai, tower_traffic_type op, PatternLeg lg) {
+ // At the moment this is only going to be tested with inserting an AI plane on downwind
+ TowerPlaneRec* t = new TowerPlaneRec;
+ t->plane = plane;
+ t->planePtr = ai;
+ t->opType = op;
+ t->leg = lg;
+ t->pos = ai->GetPos();
- // Assume this comes from the user - have another function taking a pointer to the AIplane for the AI traffic.
- // For now we'll also assume that the user is a light plane and can get him/her to join the circuit if necessary.
+ CalcETA(t);
- TowerPlaneRec* t = new TowerPlaneRec;
- t->isUser = true;
- t->clearedToLand = false;
- t->pos.setlon(user_lon_node->getDoubleValue());
- t->pos.setlat(user_lat_node->getDoubleValue());
- t->pos.setelev(user_elev_node->getDoubleValue());
+ if(op == CIRCUIT && lg != LEG_UNKNOWN) {
+ AddToCircuitList(t);
+ } else {
+ // FLAG A WARNING
+ }
+
+ doThresholdUseOrder();
+}
+
+// Contact tower for VFR approach
+// eg "Cessna Charlie Foxtrot Golf Foxtrot Sierra eight miles South of the airport for full stop with Bravo"
+// This function probably only called via user interaction - AI planes will have an overloaded function taking a planerec.
+// opt defaults to AIP_LT_UNKNOWN
+void FGTower::VFRArrivalContact(string ID, LandingType opt) {
+ //cout << "Request Landing Clearance called...\n";
+
+ // For now we'll assume that the user is a light plane and can get him/her to join the circuit if necessary.
+
+ TowerPlaneRec* t;
+ string usercall = fgGetString("/sim/user/callsign");
+ if(ID == "USER" || ID == usercall) {
+ t = FindPlane(usercall);
+ if(!t) {
+ //cout << "NOT t\n";
+ t = new TowerPlaneRec;
+ t->isUser = true;
+ t->pos.setlon(user_lon_node->getDoubleValue());
+ t->pos.setlat(user_lat_node->getDoubleValue());
+ t->pos.setelev(user_elev_node->getDoubleValue());
+ } else {
+ //cout << "IS t\n";
+ // Oops - the plane is already registered with this tower - maybe we took off and flew a giant circuit without
+ // quite getting out of tower airspace - just ignore for now and treat as new arrival.
+ // TODO - Maybe should remove from departure and circuit list if in there though!!
+ }
+ } else {
+ // Oops - something has gone wrong - put out a warning
+ cout << "WARNING - FGTower::VFRContact(string ID, LandingType lt) called with ID " << ID << " which does not appear to be the user.\n";
+ return;
+ }
+
// TODO
- // Calculate where the user is in relation to the active runway and it's circuit
+ // Calculate where the plane is in relation to the active runway and it's circuit
// and set the op-type as appropriate.
// HACK - to get up and running I'm going to assume that the user contacts tower on a staight-in final for now.
t->opType = STRAIGHT_IN;
t->plane.type = GA_SINGLE; // FIXME - Another assumption!
- t->plane.callsign = ID;
+ t->plane.callsign = usercall;
+
+ t->vfrArrivalReported = true;
+ responseReqd = true;
appList.push_back(t); // Not necessarily permanent
AddToTrafficList(t);
+
+ current_atcdialog->remove_entry(ident, USER_REQUEST_VFR_ARRIVAL, TOWER);
+ current_atcdialog->remove_entry(ident, USER_REQUEST_VFR_ARRIVAL_FULL_STOP, TOWER);
+ current_atcdialog->remove_entry(ident, USER_REQUEST_VFR_ARRIVAL_TOUCH_AND_GO, TOWER);
}
void FGTower::RequestDepartureClearance(string ID) {
}
void FGTower::ReportFinal(string ID) {
+ if(ID == "USER") {
+ ID = fgGetString("/sim/user/callsign");
+ current_atcdialog->remove_entry(ident, USER_REPORT_3_MILE_FINAL, TOWER);
+ }
TowerPlaneRec* t = FindPlane(ID);
if(t) {
t->finalReported = true;
}
}
-//void FGTower::ReportLongFinal(string ID);
+void FGTower::ReportLongFinal(string ID) {
+ if(ID == "USER") {
+ ID = fgGetString("/sim/user/callsign");
+ current_atcdialog->remove_entry(ident, USER_REPORT_3_MILE_FINAL, TOWER);
+ }
+ TowerPlaneRec* t = FindPlane(ID);
+ if(t) {
+ t->longFinalReported = true;
+ t->longFinalAcknowledged = false;
+ if(!(t->clearedToLand)) {
+ responseReqd = true;
+ } // possibly respond with wind even if already cleared to land?
+ } else {
+ SG_LOG(SG_ATC, SG_WARN, "WARNING: Unable to find plane " << ID << " in FGTower::ReportLongFinal(...)");
+ }
+}
+
//void FGTower::ReportOuterMarker(string ID);
//void FGTower::ReportMiddleMarker(string ID);
//void FGTower::ReportInnerMarker(string ID);
void FGTower::ReportRunwayVacated(string ID) {
//cout << "Report Runway Vacated Called...\n";
+ if(ID == "USER") {
+ ID = fgGetString("/sim/user/callsign");
+ current_atcdialog->remove_entry(ident, USER_REPORT_RWY_VACATED, TOWER);
+ }
+ TowerPlaneRec* t = FindPlane(ID);
+ if(t) {
+ t->rwyVacatedReported = true;
+ responseReqd = true;
+ } else {
+ SG_LOG(SG_ATC, SG_WARN, "WARNING: Unable to find plane " << ID << " in FGTower::ReportRunwayVacated(...)");
+ }
}
TowerPlaneRec* FGTower::FindPlane(string ID) {
void FGTower::ReportDownwind(string ID) {
//cout << "ReportDownwind(...) called\n";
- // Tell the plane reporting what number she is in the circuit
+ if(ID == "USER") {
+ ID = fgGetString("/sim/user/callsign");
+ current_atcdialog->remove_entry(ident, USER_REPORT_DOWNWIND, TOWER);
+ }
TowerPlaneRec* t = FindPlane(ID);
if(t) {
t->downwindReported = true;
}
}
+string FGTower::GenText(const string& m, int c) {
+ const int cmax = 300;
+ //string message;
+ char tag[4];
+ char crej = '@';
+ char mes[cmax];
+ char dum[cmax];
+ //char buf[10];
+ char *pos;
+ int len;
+ //FGTransmission t;
+ string usercall = fgGetString("/sim/user/callsign");
+
+ //transmission_list_type tmissions = transmissionlist_station[station];
+ //transmission_list_iterator current = tmissions.begin();
+ //transmission_list_iterator last = tmissions.end();
+
+ //for ( ; current != last ; ++current ) {
+ // if ( current->get_code().c1 == code.c1 &&
+ // current->get_code().c2 == code.c2 &&
+ // current->get_code().c3 == code.c3 ) {
+
+ //if ( ttext ) message = current->get_transtext();
+ //else message = current->get_menutext();
+ strcpy( &mes[0], m.c_str() );
+
+ // Replace all the '@' parameters with the actual text.
+ int check = 0; // If mes gets overflowed the while loop can go infinite
+ while ( strchr(&mes[0], crej) != NULL ) { // ie. loop until no more occurances of crej ('@') found
+ pos = strchr( &mes[0], crej );
+ bcopy(pos, &tag[0], 3);
+ tag[3] = '\0';
+ int i;
+ len = 0;
+ for ( i=0; i<cmax; i++ ) {
+ if ( mes[i] == crej ) {
+ len = i;
+ break;
+ }
+ }
+ strncpy( &dum[0], &mes[0], len );
+ dum[len] = '\0';
+
+ if ( strcmp ( tag, "@ST" ) == 0 )
+ //strcat( &dum[0], tpars.station.c_str() );
+ strcat(&dum[0], ident.c_str());
+ else if ( strcmp ( tag, "@AP" ) == 0 )
+ //strcat( &dum[0], tpars.airport.c_str() );
+ strcat(&dum[0], name.c_str());
+ else if ( strcmp ( tag, "@CS" ) == 0 )
+ //strcat( &dum[0], tpars.callsign.c_str() );
+ strcat(&dum[0], usercall.c_str());
+ else if ( strcmp ( tag, "@TD" ) == 0 ) {
+ /*
+ if ( tpars.tdir == 1 ) {
+ char buf[] = "left";
+ strcat( &dum[0], &buf[0] );
+ }
+ else {
+ char buf[] = "right";
+ strcat( &dum[0], &buf[0] );
+ }
+ */
+ }
+ else if ( strcmp ( tag, "@HE" ) == 0 ) {
+ /*
+ char buf[10];
+ sprintf( buf, "%i", (int)(tpars.heading) );
+ strcat( &dum[0], &buf[0] );
+ */
+ }
+ else if ( strcmp ( tag, "@VD" ) == 0 ) {
+ /*
+ if ( tpars.VDir == 1 ) {
+ char buf[] = "Descend and maintain";
+ strcat( &dum[0], &buf[0] );
+ }
+ else if ( tpars.VDir == 2 ) {
+ char buf[] = "Maintain";
+ strcat( &dum[0], &buf[0] );
+ }
+ else if ( tpars.VDir == 3 ) {
+ char buf[] = "Climb and maintain";
+ strcat( &dum[0], &buf[0] );
+ }
+ */
+ }
+ else if ( strcmp ( tag, "@AL" ) == 0 ) {
+ /*
+ char buf[10];
+ sprintf( buf, "%i", (int)(tpars.alt) );
+ strcat( &dum[0], &buf[0] );
+ */
+ }
+ else if ( strcmp ( tag, "@MI" ) == 0 ) {
+ char buf[10];
+ //sprintf( buf, "%3.1f", tpars.miles );
+ int dist_miles = dclGetHorizontalSeparation(Point3D(lon, lat, elev), Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue())) / 1600;
+ sprintf(buf, "%i", dist_miles);
+ strcat( &dum[0], &buf[0] );
+ }
+ else if ( strcmp ( tag, "@FR" ) == 0 ) {
+ /*
+ char buf[10];
+ sprintf( buf, "%6.2f", tpars.freq );
+ strcat( &dum[0], &buf[0] );
+ */
+ }
+ else if ( strcmp ( tag, "@RW" ) == 0 ) {
+ strcat(&dum[0], ConvertRwyNumToSpokenString(activeRwy).c_str());
+ } else if(strcmp(tag, "@CD") == 0) { // @CD = compass direction
+ double h = GetHeadingFromTo(Point3D(lon, lat, elev), Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue()));
+ while(h < 0.0) h += 360.0;
+ while(h > 360.0) h -= 360.0;
+ if(h < 22.5 || h > 337.5) {
+ strcat(&dum[0], "North");
+ } else if(h < 67.5) {
+ strcat(&dum[0], "North-East");
+ } else if(h < 112.5) {
+ strcat(&dum[0], "East");
+ } else if(h < 157.5) {
+ strcat(&dum[0], "South-East");
+ } else if(h < 202.5) {
+ strcat(&dum[0], "South");
+ } else if(h < 247.5) {
+ strcat(&dum[0], "South-West");
+ } else if(h < 292.5) {
+ strcat(&dum[0], "West");
+ } else {
+ strcat(&dum[0], "North-West");
+ }
+ } else {
+ cout << "Tag " << tag << " not found" << endl;
+ break;
+ }
+ strcat( &dum[0], &mes[len+3] );
+ strcpy( &mes[0], &dum[0] );
+
+ ++check;
+ if(check > 10) {
+ SG_LOG(SG_ATC, SG_WARN, "WARNING: Possibly endless loop terminated in FGTransmissionlist::gen_text(...)");
+ break;
+ }
+ }
+
+ //cout << mes << endl;
+ //break;
+ //}
+ //}
+ if ( mes != "" ) return mes;
+ else return "No transmission found";
+}
+
ostream& operator << (ostream& os, tower_traffic_type ttt) {
switch(ttt) {
case(CIRCUIT): return(os << "CIRCUIT");