public void Update()
        {
            if (!JUtil.IsActiveVessel(vessel))
            {
                return;
            }

            if (!JUtil.VesselIsInIVA(vessel))
            {
                for (int unit = 0; unit < variableSets.Count; ++unit)
                {
                    variableSets[unit].MuteSoundWhileOutOfIVA();
                }
            }

            if ((!alwaysActive && !JUtil.VesselIsInIVA(vessel)) || !UpdateCheck())
            {
                return;
            }

            RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);

            for (int unit = 0; unit < variableSets.Count; ++unit)
            {
                variableSets[unit].Update(comp, persistence);
            }
        }
Пример #2
0
        public override void OnUpdate()
        {
            if (!JUtil.IsActiveVessel(vessel))
            {
                return;
            }

            if (!JUtil.VesselIsInIVA(vessel))
            {
                foreach (VariableAnimationSet unit in variableSets)
                {
                    unit.MuteSoundWhileOutOfIVA();
                }
            }

            if ((!alwaysActive && !JUtil.VesselIsInIVA(vessel)) || !UpdateCheck())
            {
                return;
            }

            foreach (VariableAnimationSet unit in variableSets)
            {
                unit.Update();
            }
        }
Пример #3
0
 private void UndockCallback(EventReport report)
 {
     if (JUtil.IsActiveVessel(vessel))
     {
         UpdateMethods();
     }
 }
        /// <summary>
        /// Check if it's time to update.
        /// </summary>
        public void Update()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                // well, it looks sometimes it might become null..
                string s = EditorLogic.fetch != null && EditorLogic.fetch.shipDescriptionField != null
                                        ? EditorLogic.fetch.shipDescriptionField.text
                                        : string.Empty;

                if (s != lastVesselDescription)
                {
                    lastVesselDescription = s;
                    // For some unclear reason, the newline in this case is always 0A, rather than Environment.NewLine.
                    vesselDescription = s.Replace(editorNewline, "$$$");
                }
            }
            else if (JUtil.IsActiveVessel(vessel))
            {
                if (--dataUpdateCountdown < 0)
                {
                    dataUpdateCountdown = refreshDataRate;
                    timeToUpdate        = true;
                }
            }
        }
Пример #5
0
 private void UndockCallback(EventReport report)
 {
     if (JUtil.IsActiveVessel(vessel))
     {
         RasterPropMonitorComputer rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);
         UpdateMethods(rpmComp);
     }
 }
Пример #6
0
 public void LateUpdate()
 {
     if (JUtil.IsActiveVessel(vessel) && !startupComplete)
     {
         JUtil.AnnoyUser(this);
         // And disable ourselves.
         enabled = false;
     }
 }
Пример #7
0
        public void FixedUpdate()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            if (!JUtil.IsActiveVessel(vessel))
            {
                return;
            }
        }
        public void Update()
        {
            if (!JUtil.IsActiveVessel(vessel))
            {
                return;
            }

            if (!JUtil.VesselIsInIVA(vessel))
            {
                if (!muted)
                {
                    for (int unit = 0; unit < variableSets.Count; ++unit)
                    {
                        variableSets[unit].MuteSoundWhileOutOfIVA();
                    }
                }
                muted = true;
            }
            else if (muted)
            {
                for (int unit = 0; unit < variableSets.Count; ++unit)
                {
                    variableSets[unit].UnmuteSoundWhileInIVA();
                }
                muted = false;
            }

            if ((!alwaysActive && !JUtil.RasterPropMonitorShouldUpdate(vessel)) || !UpdateCheck())
            {
                return;
            }

            RPMVesselComputer comp          = RPMVesselComputer.Instance(vessel);
            double            universalTime = Planetarium.GetUniversalTime();

            for (int unit = 0; unit < variableSets.Count; ++unit)
            {
                variableSets[unit].Update(comp, universalTime);
            }
        }
Пример #9
0
        public override void OnUpdate()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            if (!startupComplete)
            {
                return;
            }

            if (!JUtil.IsActiveVessel(vessel))
            {
                if (loopingOutput != null && currentState == true)
                {
                    loopingOutput.audio.volume = 0.0f;
                }
                return;
            }
            else if (loopingOutput != null && currentState == true && loopingOutput.Active)
            {
                loopingOutput.audio.volume = loopingSoundVolume * GameSettings.SHIP_VOLUME;
            }

            if (consumingWhileActive && currentState && !forcedShutdown)
            {
                float requesting = (consumeWhileActiveAmount * TimeWarp.deltaTime);
                float extracted  = part.RequestResource(consumeWhileActiveName, requesting);
                if (Math.Abs(extracted - requesting) > Math.Abs(requesting / 2))
                {
                    // We don't have enough of the resource or can't produce more negative resource, so we should shut down...
                    forcedShutdown = true;
                    JUtil.LogMessage(this, "Could not consume {0}, asked for {1}, got {2} shutting switch down.", consumeWhileActiveName, requesting, extracted);
                }
            }

            // Bizarre, but looks like I need to animate things offscreen if I want them in the right condition when camera comes back.
            // So there's no check for internal cameras.

            bool newState;

            if (isPluginAction && !string.IsNullOrEmpty(stateVariable))
            {
                try
                {
                    RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);
                    newState = (comp.ProcessVariable(stateVariable, -1).MassageToInt()) > 0;
                }
                catch
                {
                    newState = currentState;
                }
            }
            else if (isCustomAction)
            {
                if (string.IsNullOrEmpty(switchTransform) && !string.IsNullOrEmpty(perPodPersistenceName))
                {
                    if (switchGroupIdentifier >= 0)
                    {
                        int activeGroupId = rpmComp.GetVar(persistentVarName, 0);
                        newState         = (switchGroupIdentifier == activeGroupId);
                        customGroupState = newState;
                    }
                    else
                    {
                        // If the switch transform is not given, and the global comp.Persistence value is, this means this is a slave module.
                        newState = rpmComp.GetBool(persistentVarName, false);
                    }
                }
                else
                {
                    // Otherwise it's a master module. But it still might have to follow the clicks on other copies of the same prop...
                    if (!string.IsNullOrEmpty(perPodPersistenceName))
                    {
                        if (switchGroupIdentifier >= 0)
                        {
                            int activeGroupId = rpmComp.GetVar(persistentVarName, 0);
                            newState         = (switchGroupIdentifier == activeGroupId);
                            customGroupState = newState;
                        }
                        else
                        {
                            newState = rpmComp.GetBool(persistentVarName, customGroupState);
                        }
                    }
                    else
                    {
                        newState = customGroupState;
                    }
                }
            }
            else
            {
                newState = vessel.ActionGroups[kspAction];
            }

            // If needsElectricCharge is true and there is no charge, the state value is overridden to false and the click action is reexecuted.
            if (needsElectricChargeValue)
            {
                lightCheckCountdown--;
                if (lightCheckCountdown <= 0)
                {
                    RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);
                    lightCheckCountdown = refreshRate;
                    forcedShutdown     |= currentState && comp.ProcessVariable(resourceName).MassageToFloat() < 0.01f;
                }
            }

            if (!string.IsNullOrEmpty(perPodMasterSwitchName))
            {
                bool switchEnabled = rpmComp.GetBool(perPodMasterSwitchName, false);
                if (!switchEnabled)
                {
                    // If the master switch is 'off', this switch needs to turn off
                    newState       = false;
                    forcedShutdown = true;
                }
            }

            if (masterVariable != null)
            {
                RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);
                if (!masterVariable.IsInRange(comp))
                {
                    newState       = false;
                    forcedShutdown = true;
                }
            }

            if (forcedShutdown)
            {
                if (currentState)
                {
                    Click();
                }
                newState       = false;
                forcedShutdown = false;
            }

            if (newState != currentState)
            {
                // If we're consuming resources on toggle, do that now.
                if ((consumingOnToggleUp && newState) || (consumingOnToggleDown && !newState))
                {
                    float extracted = part.RequestResource(consumeOnToggleName, consumeOnToggleAmount);
                    if (Math.Abs(extracted - consumeOnToggleAmount) > Math.Abs(consumeOnToggleAmount / 2))
                    {
                        // We don't have enough of the resource, so we force a shutdown on the next loop.
                        // This ensures the animations will play at least once.
                        forcedShutdown = true;
                    }
                }

                if (audioOutput != null && (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA ||
                                            CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.Internal))
                {
                    audioOutput.audio.Play();
                }

                if (loopingOutput != null && (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA ||
                                              CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.Internal))
                {
                    if (newState)
                    {
                        loopingOutput.audio.Play();
                    }
                    else
                    {
                        loopingOutput.audio.Stop();
                    }
                }

                if (anim != null)
                {
                    if (newState ^ reverse)
                    {
                        anim[animationName].normalizedTime = 0;
                        anim[animationName].speed          = 1f * customSpeed;
                        anim.Play(animationName);
                    }
                    else
                    {
                        anim[animationName].normalizedTime = 1;
                        anim[animationName].speed          = -1f * customSpeed;
                        anim.Play(animationName);
                    }
                }
                else if (colorShiftMaterial != null)
                {
                    colorShiftMaterial.SetColor(colorName, (newState ^ reverse ? enabledColorValue : disabledColorValue));
                }
                currentState = newState;
            }
        }
Пример #10
0
        public override void OnUpdate()
        {
            if (!JUtil.IsActiveVessel(vessel))
            {
                return;
            }

            if (!startupComplete)
            {
                return;
            }

            // Bizarre, but looks like I need to animate things offscreen if I want them in the right condition when camera comes back.
            // So there's no check for internal cameras.

            bool state;

            if (isPluginAction && stateHandler != null)
            {
                state = stateHandler();
            }
            else if (isCustomAction)
            {
                if (string.IsNullOrEmpty(switchTransform) && !string.IsNullOrEmpty(perPodPersistenceName))
                {
                    // If the switch transform is not given, and the global persistence value is, this means this is a slave module.
                    state = persistence.GetBool(persistentVarName) ?? false;
                }
                else
                {
                    // Otherwise it's a master module. But it still might have to follow the clicks on other copies of the same prop...
                    if (!string.IsNullOrEmpty(perPodPersistenceName))
                    {
                        state = persistence.GetBool(persistentVarName) ?? customGroupList[actionName];
                    }
                    else
                    {
                        state = customGroupList[actionName];
                    }
                }
            }
            else
            {
                state = vessel.ActionGroups[groupList[actionName]];
            }

            // If needsElectricCharge is true and there is no charge, the state value is overridden to false and the click action is reexecuted.
            if (needsElectricChargeValue)
            {
                lightCheckCountdown--;
                if (lightCheckCountdown <= 0)
                {
                    lightCheckCountdown = lightCheckRate;
                    if (state && comp.ProcessVariable("ELECTRIC").MassageToDouble() < 0.01d)
                    {
                        Click();
                        state = false;
                    }
                }
            }

            if (state != oldState)
            {
                if (audioOutput != null && (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA ||
                                            CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.Internal))
                {
                    audioOutput.audio.Play();
                }
                if (anim != null)
                {
                    if (state ^ reverse)
                    {
                        anim[animationName].normalizedTime = 0;
                        anim[animationName].speed          = 1f * customSpeed;
                        anim.Play(animationName);
                    }
                    else
                    {
                        anim[animationName].normalizedTime = 1;
                        anim[animationName].speed          = -1f * customSpeed;
                        anim.Play(animationName);
                    }
                }
                else if (colorShiftRenderer != null)
                {
                    colorShiftRenderer.material.SetColor(colorName, (state ^ reverse ? enabledColorValue : disabledColorValue));
                }
                oldState = state;
            }
        }
Пример #11
0
        /// <summary>
        /// Update.  Mainly for objects that consume resources.
        /// </summary>
        public override void OnUpdate()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            if (!startupComplete)
            {
                return;
            }

            if (!JUtil.IsActiveVessel(vessel))
            {
                if (loopingAudio != null && currentState == true)
                {
                    loopingAudio.audio.volume = 0.0f;
                }
                return;
            }
            else if (loopingAudio != null && currentState == true && loopingAudio.Active)
            {
                loopingAudio.audio.volume = loopingSoundVolume * GameSettings.SHIP_VOLUME;
            }

            if (consumingWhileActive && currentState && !forcedShutdown)
            {
                float requesting = (consumeWhileActiveAmount * TimeWarp.deltaTime);
                float extracted  = part.RequestResource(consumeWhileActiveName, requesting);
                if (Mathf.Abs(extracted - requesting) > Mathf.Abs(requesting * 0.5f))
                {
                    // We don't have enough of the resource or can't produce more negative resource, so we should shut down...
                    forcedShutdown = true;
                    //JUtil.LogMessage(this, "Could not consume {0}, asked for {1}, got {2} shutting switch down.", consumeWhileActiveName, requesting, extracted);
                }
            }

            RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);
            bool newState          = action[masterActionIndex].CurrentState(vessel, comp);

            if (masterVariable != null)
            {
                if (!masterVariable.IsInRange(comp))
                {
                    forcedShutdown = true;
                }
            }

            if (forcedShutdown)
            {
                if (currentState == true)
                {
                    for (int i = 0; i < action.Count; ++i)
                    {
                        if (action[i].CurrentState(vessel, comp))
                        {
                            action[i].Click(false, vessel, comp);
                        }
                    }
                }

                newState       = false;
                forcedShutdown = false;
            }

            //for (int i = 0; i < action.Count; ++i)
            //{
            //    action[i].Update();
            //}

            if (newState != currentState)
            {
                // If we're consuming resources on toggle, do that now.
                if ((consumingOnToggleUp && newState) || (consumingOnToggleDown && !newState))
                {
                    float extracted = part.RequestResource(consumeOnToggleName, consumeOnToggleAmount);
                    if (Math.Abs(extracted - consumeOnToggleAmount) > Math.Abs(consumeOnToggleAmount / 2))
                    {
                        // We don't have enough of the resource, so we force a shutdown on the next loop.
                        // This ensures the animations will play at least once.
                        forcedShutdown = true;
                    }
                }

                if (switchAudio != null && (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA ||
                                            CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.Internal))
                {
                    switchAudio.audio.Play();
                }

                if (loopingAudio != null && (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA ||
                                             CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.Internal))
                {
                    if (newState)
                    {
                        loopingAudio.audio.Play();
                    }
                    else
                    {
                        loopingAudio.audio.Stop();
                    }
                }

                if (anim != null)
                {
                    if (newState ^ reverse)
                    {
                        anim[animationName].normalizedTime = 0.0f;
                        anim[animationName].speed          = customSpeed;
                        anim.Play(animationName);
                    }
                    else
                    {
                        anim[animationName].normalizedTime = 1.0f;
                        anim[animationName].speed          = -customSpeed;
                        anim.Play(animationName);
                    }
                }
                //else if (colorShiftMaterial != null)
                //{
                //    colorShiftMaterial.SetColor(colorName, (newState ^ reverse ? enabledColorValue : disabledColorValue));
                //}
                currentState = newState;
            }
        }
        public override void OnUpdate()
        {
            if (!startupComplete)
            {
                return;
            }

            if (consumingWhileActive && currentState && !forcedShutdown)
            {
                float requesting = (consumeWhileActiveAmount * TimeWarp.deltaTime);
                float extracted  = part.RequestResource(consumeWhileActiveName, requesting);
                if (Math.Abs(extracted - requesting) > Math.Abs(requesting / 2))
                {
                    // We don't have enough of the resource or can't produce more negative resource, so we should shut down...
                    forcedShutdown = true;
                    JUtil.LogMessage(this, "Could not consume {0}, asked for {1}, got {2} shutting switch down.", consumeWhileActiveName, requesting, extracted);
                }
            }

            if (!JUtil.IsActiveVessel(vessel))
            {
                return;
            }

            // Bizarre, but looks like I need to animate things offscreen if I want them in the right condition when camera comes back.
            // So there's no check for internal cameras.

            bool newState;

            if (isPluginAction && stateHandler != null)
            {
                newState = stateHandler();
            }
            else if (isCustomAction)
            {
                if (string.IsNullOrEmpty(switchTransform) && !string.IsNullOrEmpty(perPodPersistenceName))
                {
                    // If the switch transform is not given, and the global persistence value is, this means this is a slave module.
                    newState = persistence.GetBool(persistentVarName) ?? false;
                }
                else
                {
                    // Otherwise it's a master module. But it still might have to follow the clicks on other copies of the same prop...
                    if (!string.IsNullOrEmpty(perPodPersistenceName))
                    {
                        newState = persistence.GetBool(persistentVarName) ?? customGroupList[actionName];
                    }
                    else
                    {
                        newState = customGroupList[actionName];
                    }
                }
            }
            else
            {
                newState = vessel.ActionGroups[groupList[actionName]];
            }

            // If needsElectricCharge is true and there is no charge, the state value is overridden to false and the click action is reexecuted.
            if (needsElectricChargeValue)
            {
                lightCheckCountdown--;
                if (lightCheckCountdown <= 0)
                {
                    lightCheckCountdown = lightCheckRate;
                    forcedShutdown     |= currentState && comp.ProcessVariable("SYSR_ELECTRICCHARGE").MassageToDouble() < 0.01d;
                }
            }

            if (forcedShutdown)
            {
                if (currentState)
                {
                    Click();
                }
                newState       = false;
                forcedShutdown = false;
            }

            if (newState != currentState)
            {
                // If we're consuming resources on toggle, do that now.
                if ((consumingOnToggleUp && newState) || (consumingOnToggleDown && !newState))
                {
                    float extracted = part.RequestResource(consumeOnToggleName, consumeOnToggleAmount);
                    if (Math.Abs(extracted - consumeOnToggleAmount) > Math.Abs(consumeOnToggleAmount / 2))
                    {
                        // We don't have enough of the resource, so we force a shutdown on the next loop.
                        // This ensures the animations will play at least once.
                        forcedShutdown = true;
                    }
                }
                if (audioOutput != null && (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA ||
                                            CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.Internal))
                {
                    audioOutput.audio.Play();
                }
                if (anim != null)
                {
                    if (newState ^ reverse)
                    {
                        anim[animationName].normalizedTime = 0;
                        anim[animationName].speed          = 1f * customSpeed;
                        anim.Play(animationName);
                    }
                    else
                    {
                        anim[animationName].normalizedTime = 1;
                        anim[animationName].speed          = -1f * customSpeed;
                        anim.Play(animationName);
                    }
                }
                else if (colorShiftRenderer != null)
                {
                    colorShiftRenderer.material.SetColor(colorName, (newState ^ reverse ? enabledColorValue : disabledColorValue));
                }
                currentState = newState;
            }
        }
Пример #13
0
        public void FixedUpdate()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            if (!JUtil.IsActiveVessel(vessel))
            {
                return;
            }

            ITargetable target = FlightGlobals.fetch.VesselTarget;

            if (radarEnabled)
            {
                bool powered = true;
                // Resources check
                if (resourceAmount > 0.0f)
                {
                    double requested = resourceAmount * TimeWarp.fixedDeltaTime;
                    double supplied  = part.RequestResource(resourceId, requested);
                    if (supplied < requested * 0.5)
                    {
                        powered = false;
                    }
                }

                if (target == null)
                {
                    if (!powered)
                    {
                        JUtil.LogMessage(this, "Want to scan, but there's no power");
                        return;
                    }

                    // Scan
                    ScanForTargets();
                }
                else
                {
                    if (!trackWhileOff && !powered)
                    {
                        JUtil.LogMessage(this, "Radar ran out of power and trackWhileOff is false, so clearing target");
                        FlightGlobals.fetch.SetVesselTarget(null);
                        return;
                    }

                    // Target locked; tracking
                    if (restrictTracking)
                    {
                        Vector3 vectorToTarget = (target.GetTransform().position - scanTransform.position);
                        if (vectorToTarget.sqrMagnitude > maxRangeMetersSquared)
                        {
                            JUtil.LogMessage(this, "Target is out of range, losing lock");
                            FlightGlobals.fetch.SetVesselTarget(null);
                            return;
                        }
                        float angle = Vector3.Angle(vectorToTarget.normalized, (scanTransformIsDockingNode) ? scanTransform.forward : scanTransform.up);
                        if (angle > scanAngle)
                        {
                            JUtil.LogMessage(this, "Target is out of scan angle, losing lock");
                            FlightGlobals.fetch.SetVesselTarget(null);
                            return;
                        }
                    }

                    if (powered && targetDockingPorts && (target is Vessel) && !(target as Vessel).packed)
                    {
                        // Attempt to refine our target.
                        ModuleDockingNode closestNode     = null;
                        float             closestDistance = float.MaxValue;
                        var l = (target as Vessel).FindPartModulesImplementing <ModuleDockingNode>();
                        if (l != null)
                        {
                            for (int i = 0; i < l.Count; ++i)
                            {
                                if (l[i].state == "Ready" && (string.IsNullOrEmpty(nodeType) || nodeType == l[i].nodeType))
                                {
                                    Vector3 vectorToTarget = (l[i].part.transform.position - scanTransform.position);
                                    if (vectorToTarget.sqrMagnitude < closestDistance)
                                    {
                                        closestDistance = vectorToTarget.sqrMagnitude;
                                        closestNode     = l[i];
                                    }
                                }
                            }
                        }

                        if (closestNode != null)
                        {
                            // This seems to be triggering continuously for
                            // ranges > 0.2km.  How do I determine
                            // programmatically that I can target a docking
                            // port?
                            //JUtil.LogMessage(this, "Refining target to {1} at {0:0.000} km.", Mathf.Sqrt(closestDistance) * 0.001f, closestNode.vessel.vesselName);
                            FlightGlobals.fetch.SetVesselTarget(closestNode);
                        }
                    }
                }
            }
            else if (target != null)
            {
                if (!trackWhileOff)
                {
                    JUtil.LogMessage(this, "Radar is off and trackWhileOff is false, so clearing target");
                    FlightGlobals.fetch.SetVesselTarget(null);
                    return;
                }

                if (restrictTracking)
                {
                    Vector3 vectorToTarget = (target.GetTransform().position - scanTransform.position);
                    if (vectorToTarget.sqrMagnitude > maxRangeMetersSquared)
                    {
                        JUtil.LogMessage(this, "Target is out of range, losing lock");
                        FlightGlobals.fetch.SetVesselTarget(null);
                        return;
                    }
                    float angle = Vector3.Angle(vectorToTarget.normalized, (scanTransformIsDockingNode) ? scanTransform.forward : scanTransform.up);
                    if (angle > scanAngle)
                    {
                        JUtil.LogMessage(this, "Target is out of scan angle, losing lock");
                        FlightGlobals.fetch.SetVesselTarget(null);
                        return;
                    }
                }
            }
        }