diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index ea99462d8..ff7afad3e 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -76,6 +76,7 @@ public: void setTaxiClearanceRequest(bool arg) { needsTaxiClearance = arg; }; bool getTaxiClearanceRequest() { return needsTaxiClearance; }; FGAISchedule * getTrafficRef() { return trafficRef; }; + void setTrafficRef(FGAISchedule *ref) { trafficRef = ref; }; virtual const char* getTypeString(void) const { return "aircraft"; } diff --git a/src/ATC/atc_mgr.cxx b/src/ATC/atc_mgr.cxx index d8203552a..88f527f32 100644 --- a/src/ATC/atc_mgr.cxx +++ b/src/ATC/atc_mgr.cxx @@ -29,7 +29,6 @@ #include #include #include - #include "atc_mgr.hxx" @@ -69,7 +68,6 @@ void FGATCManager::init() { double speed = fgGetDouble("/velocities/groundspeed-kt"); double aircraftRadius = 40; // note that this is currently hardcoded to a one-size-fits all JumboJet value. Should change later; - // Next, ai_ac.setCallSign ( callsign ); ai_ac.setLongitude( longitude ); @@ -78,8 +76,19 @@ void FGATCManager::init() { ai_ac.setPerformance("jet_transport"); // NEXT UP: Create a traffic Schedule and fill that with appropriate information. This we can use to flight plannign. + FGAISchedule *trafficRef = new FGAISchedule; + trafficRef->setFlightType("gate"); + FGScheduledFlight *flight = new FGScheduledFlight; + flight->setDepartureAirport(airport); + flight->setArrivalAirport(airport); + flight->initializeAirports(); + flight->setFlightRules("IFR"); + flight->setCallSign(callsign); + + trafficRef->assign(flight); FGAIFlightPlan *fp = new FGAIFlightPlan; + ai_ac.setTrafficRef(trafficRef); string flightPlanName = airport + "-" + airport + ".xml"; double cruiseAlt = 100; // Doesn't really matter right now. diff --git a/src/ATC/trafficcontrol.cxx b/src/ATC/trafficcontrol.cxx index aab81538f..e24444d13 100644 --- a/src/ATC/trafficcontrol.cxx +++ b/src/ATC/trafficcontrol.cxx @@ -1034,14 +1034,7 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l // 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 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/Traffic/SchedFlight.cxx b/src/Traffic/SchedFlight.cxx index 5575f6ee0..e4d491b4a 100644 --- a/src/Traffic/SchedFlight.cxx +++ b/src/Traffic/SchedFlight.cxx @@ -74,8 +74,12 @@ FGScheduledFlight::FGScheduledFlight() { - initialized = false; - available = true; + departureTime = 0; + arrivalTime = 0; + cruiseAltitude = 0; + repeatPeriod = 0; + initialized = false; + available = true; } FGScheduledFlight::FGScheduledFlight(const FGScheduledFlight &other) diff --git a/src/Traffic/SchedFlight.hxx b/src/Traffic/SchedFlight.hxx index 0ee3eb6bd..0567102fb 100644 --- a/src/Traffic/SchedFlight.hxx +++ b/src/Traffic/SchedFlight.hxx @@ -90,6 +90,8 @@ public: time_t getDepartureTime() { return departureTime; }; time_t getArrivalTime () { return arrivalTime; }; + void setDepartureAirport(string port) { depId = port; }; + void setArrivalAirport (string port) { arrId = port; }; FGAirport *getDepartureAirport(); FGAirport *getArrivalAirport (); @@ -109,6 +111,9 @@ public: void release() { available = true; }; bool isAvailable() { return available; }; + + void setCallSign(string val) { callsign = val; }; + void setFlightRules(string val) { fltRules = val; }; }; typedef vector FGScheduledFlightVec; diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx index cb7fafb3d..11d8d0abe 100644 --- a/src/Traffic/Schedule.cxx +++ b/src/Traffic/Schedule.cxx @@ -344,6 +344,12 @@ bool FGAISchedule::createAIAircraft(FGScheduledFlight* flight, double speedKnots return true; } +// Create an initial heading for user controlled aircraft. +void FGAISchedule::setHeading() +{ + courseToDest = SGGeodesy::courseDeg((*flights.begin())->getDepartureAirport()->geod(), (*flights.begin())->getArrivalAirport()->geod()); +} + void FGAISchedule::scheduleFlights() { if (!flights.empty()) { diff --git a/src/Traffic/Schedule.hxx b/src/Traffic/Schedule.hxx index cc80e4080..92b7e78aa 100644 --- a/src/Traffic/Schedule.hxx +++ b/src/Traffic/Schedule.hxx @@ -117,6 +117,9 @@ class FGAISchedule void setHits (unsigned int count) { hits = count; }; void setScore (); double getScore () { return score; }; + void setHeading (); + void assign (FGScheduledFlight *ref) { flights.push_back(ref); }; + void setFlightType (string val ) { flightType = val; }; FGScheduledFlight*findAvailableFlight (const string ¤tDestination, const string &req); // used to sort in decending order of score: I've probably found a better way to // decending order sorting, but still need to test that.