X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FTraffic%2FSchedFlight.cxx;h=56db6204cba1cba31b04cd9b3c1462584190046a;hb=157eb857ef36636a316947fe1eb3d9a8bea1959b;hp=245d3db0c87efbea91631239811e3cd0cbad9ad8;hpb=222446df29724aa496da85ea334788f59276b922;p=flightgear.git diff --git a/src/Traffic/SchedFlight.cxx b/src/Traffic/SchedFlight.cxx index 245d3db0c..56db6204c 100644 --- a/src/Traffic/SchedFlight.cxx +++ b/src/Traffic/SchedFlight.cxx @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * **************************************************************************/ @@ -36,6 +36,11 @@ * - Find an alternative for the depricated Point3D class * *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include @@ -74,37 +79,48 @@ FGScheduledFlight::FGScheduledFlight() { + initialized = false; + available = true; } FGScheduledFlight::FGScheduledFlight(const FGScheduledFlight &other) { - callsign = other.callsign; - fltRules = other.fltRules; - departurePort = other.departurePort; - departureTime = other.departureTime; - cruiseAltitude = other.cruiseAltitude; - arrivalPort = other.arrivalPort; - arrivalTime = other.arrivalTime; - repeatPeriod = other.repeatPeriod; - initialized = other.initialized; + callsign = other.callsign; + fltRules = other.fltRules; + departurePort = other.departurePort; + depId = other.depId; + arrId = other.arrId; + departureTime = other.departureTime; + cruiseAltitude = other.cruiseAltitude; + arrivalPort = other.arrivalPort; + arrivalTime = other.arrivalTime; + repeatPeriod = other.repeatPeriod; + initialized = other.initialized; + requiredAircraft = other.requiredAircraft; + available = other.available; } -FGScheduledFlight::FGScheduledFlight(string cs, - string fr, - string depPrt, - string arrPrt, +FGScheduledFlight::FGScheduledFlight(const string& cs, + const string& fr, + const string& depPrt, + const string& arrPrt, int cruiseAlt, - string deptime, - string arrtime, - string rep) + const string& deptime, + const string& arrtime, + const string& rep, + const string& reqAC) { callsign = cs; fltRules = fr; - departurePort._id = depPrt; - arrivalPort._id = arrPrt; + //departurePort.setId(depPrt); + //arrivalPort.setId(arrPrt); + depId = depPrt; + arrId = arrPrt; + //cerr << "Constructor: departure " << depId << ". arrival " << arrId << endl; //departureTime = processTimeString(deptime); //arrivalTime = processTimeString(arrtime); cruiseAltitude = cruiseAlt; + requiredAircraft = reqAC; // Process the repeat period string if (rep.find("WEEK",0) != string::npos) @@ -117,19 +133,22 @@ FGScheduledFlight::FGScheduledFlight(string cs, } else { - cerr << "Unknown repeat period" << endl; - exit(1); + repeatPeriod = 365*24*60*60; + SG_LOG( SG_GENERAL, SG_ALERT, "Unknown repeat period in flight plan " + "of flight '" << cs << "': " << rep ); } // What we still need to do is preprocess the departure and // arrival times. departureTime = processTimeString(deptime); arrivalTime = processTimeString(arrtime); + //departureTime += rand() % 300; // Make sure departure times are not limited to 5 minute increments. if (departureTime > arrivalTime) { departureTime -= repeatPeriod; } initialized = false; + available = true; } @@ -137,11 +156,10 @@ FGScheduledFlight:: ~FGScheduledFlight() { } -time_t FGScheduledFlight::processTimeString(string theTime) +time_t FGScheduledFlight::processTimeString(const string& theTime) { int weekday; int timeOffsetInDays; - int targetDate; int targetHour; int targetMinute; int targetSecond; @@ -165,6 +183,7 @@ time_t FGScheduledFlight::processTimeString(string theTime) { timeOffsetInDays = 0; } + // TODO: verify status of each token. targetHour = atoi(timeCopy.substr(0,2).c_str()); targetMinute = atoi(timeCopy.substr(3,5).c_str()); targetSecond = atoi(timeCopy.substr(6,8).c_str()); @@ -225,7 +244,10 @@ FGAirport *FGScheduledFlight::getDepartureAirport() { initializeAirports(); } - return &departurePort; + if (initialized) + return departurePort; + else + return 0; } FGAirport * FGScheduledFlight::getArrivalAirport () { @@ -233,7 +255,10 @@ FGAirport * FGScheduledFlight::getArrivalAirport () { initializeAirports(); } - return &arrivalPort; + if (initialized) + return arrivalPort; + else + return 0; } // Upon the first time of requesting airport information @@ -243,15 +268,30 @@ FGAirport * FGScheduledFlight::getArrivalAirport () // but we should improve that. The best idea is probably to cancel // this flight entirely by removing it from the schedule, if one // of the airports cannot be found. -void FGScheduledFlight::initializeAirports() +bool FGScheduledFlight::initializeAirports() { - if(!(fgFindAirportID(arrivalPort._id, &arrivalPort ))) + //cerr << "Initializing using : " << depId << " " << arrId << endl; + departurePort = FGAirport::findByIdent(depId); + if(departurePort == NULL) { - //cerr << ": Could not find " << arrivalPort.id << endl; + SG_LOG( SG_GENERAL, SG_WARN, "Traffic manager could not find departure airport : " << depId); + return false; } - if(!(fgFindAirportID(departurePort._id, &departurePort))) + arrivalPort = FGAirport::findByIdent(arrId); + if(arrivalPort == NULL) { - //cerr << ": Could not find " << departurePort.id << endl; + SG_LOG( SG_GENERAL, SG_WARN, "Traffic manager could not find arrival airport : " << arrId); + return false; } + + //cerr << "Found : " << departurePort->getId() << endl; + //cerr << "Found : " << arrivalPort->getId() << endl; initialized = true; + return true; } + + +bool compareScheduledFlights(FGScheduledFlight *a, FGScheduledFlight *b) +{ + return (*a) < (*b); +};