+void FGAIFlightPlan::createWaypoints(FGAIAircraft *ac,
+ double course,
+ time_t start,
+ FGAirport *dep,
+ FGAirport *arr,
+ bool firstLeg,
+ double radius,
+ double alt,
+ double lat,
+ double lon,
+ double speed,
+ const string& fltType,
+ const string& acType,
+ const string& airline)
+{
+ time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+ time_t timeDiff = now-start;
+ leg = 1;
+
+ if ((timeDiff > 60) && (timeDiff < 1500))
+ leg = 2;
+ //else if ((timeDiff >= 1200) && (timeDiff < 1500)) {
+ //leg = 3;
+ //ac->setTakeOffStatus(2);
+ //}
+ else if ((timeDiff >= 1500) && (timeDiff < 2000))
+ leg = 4;
+ else if (timeDiff >= 2000)
+ leg = 5;
+ /*
+ if (timeDiff >= 2000)
+ leg = 5;
+ */
+ SG_LOG(SG_AI, SG_INFO, "Route from " << dep->getId() << " to " << arr->getId() << ". Set leg to : " << leg << " " << ac->getTrafficRef()->getCallSign());
+ wpt_iterator = waypoints.begin();
+ bool dist = 0;
+ isValid = create(ac, dep, arr, leg, alt, speed, lat, lon,
+ firstLeg, radius, fltType, acType, airline, dist);
+ wpt_iterator = waypoints.begin();
+}
+
+bool FGAIFlightPlan::parseProperties(const std::string& filename)
+{
+ SGPath path( globals->get_fg_root() );
+ path.append( "/AI/FlightPlans/" + filename );
+ if (!path.exists()) {
+ return false;
+ }
+
+ SGPropertyNode root;
+ try {
+ readProperties(path.str(), &root);
+ } catch (const sg_exception &e) {
+ SG_LOG(SG_AI, SG_ALERT, "Error reading AI flight plan: " << path.str()
+ << "message:" << e.getFormattedMessage());
+ return false;
+ }
+
+ SGPropertyNode * node = root.getNode("flightplan");
+ for (int i = 0; i < node->nChildren(); i++) {
+ FGAIWaypoint* wpt = new FGAIWaypoint;
+ SGPropertyNode * wpt_node = node->getChild(i);
+ wpt->setName (wpt_node->getStringValue("name", "END" ));
+ wpt->setLatitude (wpt_node->getDoubleValue("lat", 0 ));
+ wpt->setLongitude (wpt_node->getDoubleValue("lon", 0 ));
+ wpt->setAltitude (wpt_node->getDoubleValue("alt", 0 ));
+ wpt->setSpeed (wpt_node->getDoubleValue("ktas", 0 ));
+ wpt->setCrossat (wpt_node->getDoubleValue("crossat", -10000 ));
+ wpt->setGear_down (wpt_node->getBoolValue("gear-down", false ));
+ wpt->setFlaps_down (wpt_node->getBoolValue("flaps-down", false ));
+ wpt->setOn_ground (wpt_node->getBoolValue("on-ground", false ));
+ wpt->setTime_sec (wpt_node->getDoubleValue("time-sec", 0 ));
+ wpt->setTime (wpt_node->getStringValue("time", "" ));
+ wpt->setFinished ((wpt->getName() == "END"));
+ pushBackWaypoint( wpt );
+ }
+
+ wpt_iterator = waypoints.begin();
+ return true;
+}