From: Durk Talsma Date: Mon, 11 Apr 2011 20:23:53 +0000 (+0200) Subject: Small step forward: Ensure that traffic information is appropriately updated. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=493661a2dcd89403559af50d7e1b5004da1b49e4;p=flightgear.git Small step forward: Ensure that traffic information is appropriately updated. --- diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 2f8362331..fa6807401 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -304,6 +304,8 @@ public: SGPropertyNode *prop_root); static bool _isNight(); + + string & getCallSign(); }; inline void FGAIBase::setManager(FGAIManager* mgr, SGPropertyNode* p) { @@ -364,6 +366,10 @@ inline void FGAIBase::setLatitude ( double latitude ) { inline void FGAIBase::setCallSign(const string& s) { _callsign = s; } +inline string& FGAIBase::getCallSign() { + return _callsign; +} + inline void FGAIBase::setXoffset(double x) { _x_offset = x; } diff --git a/src/ATC/atc_mgr.cxx b/src/ATC/atc_mgr.cxx index 828431674..d8203552a 100644 --- a/src/ATC/atc_mgr.cxx +++ b/src/ATC/atc_mgr.cxx @@ -77,6 +77,8 @@ void FGATCManager::init() { ai_ac.setAltitude ( altitude ); ai_ac.setPerformance("jet_transport"); + // NEXT UP: Create a traffic Schedule and fill that with appropriate information. This we can use to flight plannign. + FGAIFlightPlan *fp = new FGAIFlightPlan; string flightPlanName = airport + "-" + airport + ".xml"; @@ -105,7 +107,7 @@ void FGATCManager::init() { string fltType = "ga"; fp->createTakeOff(&ai_ac, false, apt, 0, fltType); } else { - controller = apt->getDynamics()->getGroundNetwork(); + controller = apt->getDynamics()->getStartupController(); int stationFreq = apt->getDynamics()->getGroundFrequency(2); cerr << "Setting radio frequency to : " << stationFreq << endl; fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0)); @@ -151,11 +153,22 @@ void FGATCManager::addController(FGATCController *controller) { activeStations.push_back(controller); } - - void FGATCManager::update ( double time ) { //cerr << "ATC update code is running at time: " << time << endl; - currentATCDialog->update(time); - - + currentATCDialog->update(time); + if (controller) { + double longitude = fgGetDouble("/position/longitude-deg"); + double latitude = fgGetDouble("/position/latitude-deg"); + double heading = fgGetDouble("/orientation/heading-deg"); + double speed = fgGetDouble("/velocities/groundspeed-kt"); + double altitude = fgGetDouble("/position/altitude-ft"); + + cerr << "Running FGATCManager::update()" << endl; + controller->updateAircraftInformation(ai_ac.getID(), + latitude, + longitude, + heading, + speed, + altitude, time); + } } diff --git a/src/ATC/trafficcontrol.cxx b/src/ATC/trafficcontrol.cxx index b4bfb7efd..aab81538f 100644 --- a/src/ATC/trafficcontrol.cxx +++ b/src/ATC/trafficcontrol.cxx @@ -465,6 +465,11 @@ string FGATCController::getGateName(FGAIAircraft * ref) return ref->atGate(); } +bool FGATCController::isUserAircraft(FGAIAircraft* ac) +{ + return (ac->getCallSign() == fgGetString("/sim/multiplay/callsign")) ? true : false; +}; + void FGATCController::transmit(FGTrafficRecord * rec, AtcMsgId msgId, AtcMsgDir msgDir) { @@ -1015,6 +1020,7 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l } } // // update position of the current aircraft + if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { SG_LOG(SG_GENERAL, SG_ALERT, "AI error: updating aircraft without traffic record"); @@ -1025,8 +1031,17 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l setDt(getDt() + dt); int state = i->getState(); - time_t startTime = - i->getAircraft()->getTrafficRef()->getDepartureTime(); + + // The user controlled aircraft should have crased here, because it doesn't have a traffic reference. + // NOTE: if we create a traffic schedule for the user aircraft, we can use this to plan a flight. + time_t startTime = 0; + if (isUserAircraft(i->getAircraft())) { + cerr << i->getAircraft->getCallSign() << " is user aircraft " << endl; + } else { + time_t startTime = + i->getAircraft()->getTrafficRef()->getDepartureTime(); + + } time_t now = time(NULL) + fgGetLong("/sim/time/warp"); //cerr << i->getAircraft()->getTrafficRef()->getCallSign() // << " is scheduled to depart in " << startTime-now << " seconds. Available = " << available diff --git a/src/ATC/trafficcontrol.hxx b/src/ATC/trafficcontrol.hxx index 20ec9962e..378023340 100644 --- a/src/ATC/trafficcontrol.hxx +++ b/src/ATC/trafficcontrol.hxx @@ -34,8 +34,6 @@ #include #include - - #include #include @@ -227,6 +225,7 @@ class FGATCController { private: bool initialized; + protected: bool available; time_t lastTransmission; @@ -236,6 +235,7 @@ protected: string formatATCFrequency3_2(int ); string genTransponderCode(string fltRules); + bool isUserAircraft(FGAIAircraft*); public: typedef enum { @@ -278,6 +278,9 @@ public: void setDt(double dt) { dt_count = dt;}; void transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir); string getGateName(FGAIAircraft *aircraft); + +private: + AtcMsgDir lastTransmissionDirection; }; /******************************************************************************