Пример #1
0
        public override void AddTo(SharedObjects shared)
        {
            Shared = shared;

            if (Shared.Vessel == null)
            {
                SafeHouse.Logger.LogWarning("FlightControlManager.AddTo Skipped: shared.Vessel== null");
                return;
            }

            if (Shared.Vessel.rootPart == null)
            {
                SafeHouse.Logger.LogWarning("FlightControlManager.AddTo Skipped: shared.Vessel.rootPart == null");
                return;
            }

            SafeHouse.Logger.Log("FlightControlManager.AddTo " + Shared.Vessel.id);

            currentVessel = shared.Vessel;
            ConnectivityManager.AddAutopilotHook(currentVessel, OnFlyByWire);

            AddNewFlightParam("throttle", Shared);
            AddNewFlightParam("steering", Shared);
            AddNewFlightParam("wheelthrottle", Shared);
            AddNewFlightParam("wheelsteering", Shared);

            shared.BindingMgr.AddSetter("SASMODE", value => SelectAutopilotMode(value));
            shared.BindingMgr.AddGetter("SASMODE", () => GetAutopilotModeName());
            shared.BindingMgr.AddSetter("NAVMODE", value => SetNavMode(value));
            shared.BindingMgr.AddGetter("NAVMODE", () => GetNavModeName());
        }
Пример #2
0
        private void Bind()
        {
            if (bound && !ConnectivityManager.NeedAutopilotResubscribe)
            {
                return;
            }
            SafeHouse.Logger.Log("FlightControl Binding");

            ConnectivityManager.AddAutopilotHook(Vessel, OnFlyByWire);
            bound = true;
            SafeHouse.Logger.Log("FlightControl Bound");
        }
        /// <summary>
        /// Hook up to any vessel/game events that might be needed.
        /// </summary>
        private void HookEvents()
        {
            ConnectivityManager.AddAutopilotHook(parentVessel, UpdateAutopilot);

            // HACK: The following events and their methods are a hack to work around KSP's limitation that
            // blocks our autopilot from having control of the vessel if out of signal and the setting
            // "Require Signal for Control" is enabled.  It's very hacky, and my have unexpected results.
            if (Vessel.vesselType != VesselType.Unknown && Vessel.vesselType != VesselType.SpaceObject)
            {
                TimingManager.FixedUpdateAdd(TimingManager.TimingStage.ObscenelyEarly, cacheControllable);
                TimingManager.FixedUpdateAdd(TimingManager.TimingStage.BetterLateThanNever, resetControllable);
            }
        }
 /// <summary>
 /// A race condition exists where KSP can load the kOS module onto the vessel
 /// before it loaded the RemoteTech module.  That makes it so that kOS may not
 /// see the existence of RT yet when kOS is first initialized.<br/>
 /// <br/>
 /// This fixes that case by continually re-querying for RT post-loading, and
 /// re-initializing kOS's RT-related behaviors if it seems that the RT module
 /// now exists when it didn't before (or visa versa).
 /// <br/>
 /// With the update for KSP 1.2, this function was renamed and made more generic
 /// so that it may support future autopilot connectivity configurations.
 /// </summary>
 private void CheckRehookAutopilot()
 {
     if (ConnectivityManager.NeedAutopilotResubscribe)
     {
         if (++autopilotRehookCounter > autopilotRehookPeriod)
         {
             ConnectivityManager.AddAutopilotHook(parentVessel, UpdateAutopilot);
         }
     }
     else
     {
         autopilotRehookCounter = autopilotRehookPeriod - 2;
     }
 }
Пример #5
0
        public override void Update()
        {
            UnbindUnloaded();

            // Why the "currentVessel != null checks?
            //   Because of a timing issue where it can still be set to null during the span of one single
            //   update if the new vessel isn't valid and set up yet when the old vessel connection got
            //   broken off.
            //
            if (currentVessel != null && currentVessel.id == Shared.Vessel.id)
            {
                if (ConnectivityManager.NeedAutopilotResubscribe)
                {
                    if (++counterRemoteTechRefresh > RemoteTechRehookPeriod)
                    {
                        ConnectivityManager.AddAutopilotHook(currentVessel, OnFlyByWire);
                    }
                }
                else
                {
                    counterRemoteTechRefresh = RemoteTechRehookPeriod - 2;
                }
                return;
            }

            // If it gets this far, that means the part the kOSProcessor module is inside of
            // got disconnected from its original vessel and became a member
            // of a new child vessel, either due to undocking, decoupling, or breakage.

            // currentVessel is now a stale reference to the vessel this manager used to be a member of,
            // while Shared.Vessel is the new vessel it is now contained in.

            // Before updating currentVessel, use it to break connection from the old vessel,
            // so this this stops trying to pilot the vessel it's not attached to anymore:
            if (currentVessel != null && VesselIsValid(currentVessel))
            {
                ConnectivityManager.RemoveAutopilotHook(currentVessel, OnFlyByWire);
                currentVessel = null;
            }

            // If the new vessel isn't ready for it, then don't attach to it yet (wait for a future update):
            if (!VesselIsValid(Shared.Vessel))
            {
                return;
            }

            // Now attach to the new vessel:
            currentVessel = Shared.Vessel;
            ConnectivityManager.AddAutopilotHook(currentVessel, OnFlyByWire);

            foreach (var param in flightParameters.Values)
            {
                param.UpdateFlightControl(currentVessel);
            }

            // If any paramers were removed in UnbindUnloaded, add them back here
            AddMissingFlightParam("throttle", Shared);
            AddMissingFlightParam("steering", Shared);
            AddMissingFlightParam("wheelthrottle", Shared);
            AddMissingFlightParam("wheelsteering", Shared);
        }