+void finalizePosition()
+{
+ // first call to finalize after an initPosition call
+ if (global_finalizeTime.get_usec() == 0) {
+ global_finalizeTime = SGTimeStamp::now();
+ }
+
+ bool done = true;
+
+ /* Scenarios require Nasal, so FGAIManager loads the scenarios,
+ * including its models such as a/c carriers, in its 'postinit',
+ * which is the very last thing we do.
+ * flightgear::initPosition is called very early in main.cxx/fgIdleFunction,
+ * one of the first things we do, long before scenarios/carriers are
+ * loaded. => When requested "initial preset position" relates to a
+ * carrier, recalculate the 'initial' position here
+ */
+ std::string carrier = fgGetString("/sim/presets/carrier","");
+ if (!carrier.empty())
+ {
+ SG_LOG(SG_GENERAL, SG_INFO, "finalizePositioned: re-init-ing position on carrier");
+ // clear preset location and re-trigger position setup
+ fgSetDouble("/sim/presets/longitude-deg", 9999);
+ fgSetDouble("/sim/presets/latitude-deg", 9999);
+ initPosition();
+ } else {
+ done = finalizeMetar();
+ }
+
+ fgSetBool("/sim/position-finalized", done);
+ if (done) {
+ globals->get_event_mgr()->removeTask("finalizePosition");
+ global_callbackRegistered = false;
+ }
+}
+