Example #1
0
        public void Update()
        {
            if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready)
            {
                InputLockManager.RemoveControlLock(lockID);
                return;
            }
            bool doLock = ShouldLock();

            if (doLock != wasLocked)
            {
                if (wasLocked)
                {
                    InputLockManager.RemoveControlLock(lockID);
                    message.message = "Avionics: Unlocking Controls";
                }
                else
                {
                    InputLockManager.SetControlLock(lockmask, lockID);
                    vessel.Autopilot.Disable();
                    message.message = "Insufficient Avionics, Locking Controls (supports "
                                      + maxMass.ToString("N3") + "t, vessel " + vesselMass.ToString("N3") + "t)";
                }
                ScreenMessages.PostScreenMessage(message, true);
                FlightLogger.eventLog.Add("[" + ControlLockerUtils.FormatTime(vessel.missionTime) + "] "
                                          + message.message);
                wasLocked = doLock;
            }
        }
Example #2
0
 private void OffRailsHandler(Vessel v)
 {
     onRails = false;
     if (!CheatOptions.InfiniteElectricity && ControlLockerUtils.ShouldLock(vessel.Parts, true, out float _, out float _))
     {
         DisableAutopilot();
     }
 }
Example #3
0
 private void OffRailsHandler(Vessel v)
 {
     onRails = false;
     if (ControlLockerUtils.ShouldLock(vessel.Parts, true, out float _, out float _))
     {
         DisableAutopilot();
     }
 }
Example #4
0
 private void OffRailsHandler(Vessel v)
 {
     _onRails = false;
     if (!CheatOptions.InfiniteElectricity && ControlLockerUtils.ShouldLock(Vessel.Parts, true, out _, out _, out _) != ControlLockerUtils.LockLevel.Unlocked)
     {
         DisableAutopilot();
     }
 }
Example #5
0
        private System.Collections.IEnumerator CheckLockCR()
        {
            while (HighLogic.LoadedSceneIsFlight)
            {
                yield return(new WaitForSeconds(updateFrequency));

                cachedLockResult = !CheatOptions.InfiniteElectricity && ControlLockerUtils.ShouldLock(vessel.Parts, true, out maxMass, out vesselMass);
            }
        }
Example #6
0
 public bool ShouldLock()
 {
     // if we have no active vessel, undo locks
     if (vessel is null)
     {
         return(cachedLockResult = false);
     }
     if (requested)
     {
         cachedLockResult = !CheatOptions.InfiniteElectricity && ControlLockerUtils.ShouldLock(vessel.Parts, true, out maxMass, out vesselMass);
     }
     requested = false;
     return(cachedLockResult);
 }
Example #7
0
 public void Update()
 {
     deltaTime += Time.deltaTime;
     if (deltaTime > UPDATEINTERVAL)
     {
         deltaTime       = 0;
         haveParts       = false;
         isControlLocked = false;
         if (EditorLogic.fetch.ship?.Parts is List <Part> parts && parts.Count > 0)
         {
             isControlLocked = ControlLockerUtils.ShouldLock(parts, false, out maxMass, out vesselMass);
             haveParts       = true;
         }
     }
 }
Example #8
0
 public void Update()
 {
     _deltaTime += Time.deltaTime;
     if (_deltaTime > UpdateInterval)
     {
         _deltaTime       = 0;
         _haveParts       = false;
         _isControlLocked = false;
         if (EditorLogic.fetch.ship?.Parts is List <Part> parts && parts.Count > 0)
         {
             _isControlLocked = ControlLockerUtils.ShouldLock(parts, false, out _maxMass, out _vesselMass);
             _haveParts       = true;
         }
     }
 }
Example #9
0
        public bool ShouldLock()
        {
            if (vessel != FlightGlobals.ActiveVessel)
            {
                vParts = -1;
                vessel = FlightGlobals.ActiveVessel;
            }
            // if we have no active vessel, undo locks
            if ((object)vessel == null)
            {
                return(false);
            }

            // Do we need to update?
            if (vessel.Parts.Count != vParts)
            {
                vParts = vessel.Parts.Count;
                return(ControlLockerUtils.ShouldLock(vessel.Parts, true, out maxMass, out vesselMass));
            }
            return(wasLocked);
        }
Example #10
0
 public void Update()
 {
     deltaTime += Time.deltaTime;
     if (deltaTime > UPDATEINTERVAL)
     {
         deltaTime       = 0;
         haveParts       = false;
         isControlLocked = false;
         List <Part> parts = null;
         if ((object)(EditorLogic.fetch.ship) != null)
         {
             parts = EditorLogic.fetch.ship.Parts;
         }
         if (parts != null)
         {
             if (parts.Count > 0)
             {
                 isControlLocked = ControlLockerUtils.ShouldLock(parts, false, out maxMass, out vesselMass);
                 haveParts       = true;
             }
         }
     }
 }
Example #11
0
        public bool ShouldLock()
        {
            if (vessel != FlightGlobals.ActiveVessel)
            {
                vParts = -1;
                vessel = FlightGlobals.ActiveVessel;
            }
            // if we have no active vessel, undo locks
            if ((object)vessel == null)
            {
                return(false);
            }

            // Do we need to update?
            double cTime = Planetarium.GetUniversalTime();

            if (vessel.Parts.Count != vParts || cTime > lastUT + updateFrequency)
            {
                lastUT = cTime;
                vParts = vessel.Parts.Count;
                return(ControlLockerUtils.ShouldLock(vessel.Parts, true, out maxMass, out vesselMass));
            }
            return(wasLocked);
        }
Example #12
0
        public void Update()
        {
            // toggle visibility
            if (GameSettings.MODIFIER_KEY.GetKey() && Input.GetKeyDown(key))
            {
                if (guiEnabled && showOnlyWarning && !isControlLocked)
                {
                    showOnlyWarning = false;
                }
                else
                {
                    guiEnabled = !guiEnabled;
                }
            }

            deltaTime += TimeWarp.deltaTime;
            if (deltaTime > UPDATEINTERVAL)
            {
                deltaTime       = 0;
                haveParts       = false;
                isControlLocked = false;
                List <Part> parts = null;
                if ((object)(EditorLogic.fetch.ship) != null)
                {
                    parts = EditorLogic.fetch.ship.Parts;
                }
                if (parts != null)
                {
                    if (parts.Count > 0)
                    {
                        isControlLocked = ControlLockerUtils.ShouldLock(parts, false, out maxMass, out vesselMass);
                        haveParts       = true;
                    }
                }
            }
        }
Example #13
0
        public bool ShouldLock()
        {
            if (vessel != FlightGlobals.ActiveVessel)
            {
                vessel        = FlightGlobals.ActiveVessel;
                masterMechJeb = null;
            }
            // if we have no active vessel, undo locks
            if (vessel is null)
            {
                return(false);
            }

            // Do we need to update?
            double cTime = Planetarium.GetUniversalTime();

            if (requested || cTime > lastUT + updateFrequency)
            {
                lastUT    = cTime;
                requested = false;
                return(ControlLockerUtils.ShouldLock(vessel.Parts, true, out maxMass, out vesselMass));
            }
            return(wasLocked);
        }
Example #14
0
        private IEnumerator CheckLockCR()
        {
            const int maxFramesWaited = 250;
            int       i = 0;

            do
            {
                yield return(new WaitForFixedUpdate());
            } while ((FlightGlobals.ActiveVessel == null || FlightGlobals.ActiveVessel.packed) && i++ < maxFramesWaited);

            while (HighLogic.LoadedSceneIsFlight)
            {
                yield return(new WaitForSeconds(UpdateFrequency));

                _cachedLockResult = CheatOptions.InfiniteElectricity ? ControlLockerUtils.LockLevel.Unlocked : ControlLockerUtils.ShouldLock(Vessel.Parts, true, out _maxMass, out _vesselMass, out _isLimitedByNonInterplanetary);
            }
        }
Example #15
0
 public ControlLockerUtils.LockLevel ShouldLock()
 {
     // if we have no active vessel, undo locks
     if (Vessel is null)
     {
         return(_cachedLockResult = ControlLockerUtils.LockLevel.Unlocked);
     }
     if (_requested)
     {
         _cachedLockResult = CheatOptions.InfiniteElectricity ? ControlLockerUtils.LockLevel.Unlocked : ControlLockerUtils.ShouldLock(Vessel.Parts, true, out _maxMass, out _vesselMass, out _isLimitedByNonInterplanetary);
     }
     _requested = false;
     return(_cachedLockResult);
 }