/// <summary> /// Module re-start logic. OnStart will be called usually once for each scene, editor included. /// Put your custom start logic in DI_Start(): if you need to act on other part's /// variable, this is the place to do it, not DI_Reset() /// </summary> public override void OnStart(PartModule.StartState state) { try { if (HighLogic.LoadedSceneIsFlight) // nothing to do in editor { this.Log("Starting in flight: last reset " + TimeOfLastReset + ", now " + DangIt.Now()); if (!DangIt.Instance.CurrentSettings.EnabledForSave) //Disable if we've disabled DangIt { foreach (var e in this.Events) { e.guiActive = false; } } // Reset the internal state at the beginning of the flight // this condition also catches a revert to launch (+1 second for safety) if (DangIt.Now() < (this.TimeOfLastReset + 1)) { this.Reset(); } // If the part was saved when it was failed, // re-run the failure logic to disable it // ONLY THE DISABLING PART IS RUN! if (this.HasFailed) { this.DI_Disable(); } DangIt.ResetShipGlow(this.part.vessel); } if (DangIt.Instance.CurrentSettings.EnabledForSave) { this.DI_Start(state); this.StartCoroutine("RuntimeFetch"); } } catch (Exception e) { OnError(e); } }
protected override void DI_OnLoad(ConfigNode node) { this.ignorePitch = DangIt.Parse <bool>(node.GetValue("ignorePitch"), defaultTo: false); this.ignoreRoll = DangIt.Parse <bool>(node.GetValue("ignoreRoll"), defaultTo: false); this.ignoreYaw = DangIt.Parse <bool>(node.GetValue("ignoreYaw"), defaultTo: false); }
public int GetSoundLoopsForPriority(string priority) { return(GetSoundLoopsForPriority(DangIt.PriorityIntFromString(priority))); }
void SettingsWindowFcn(int windowID) { if (waitingForConfirm) { GUILayout.BeginVertical(); GUILayout.Label("WARNING! Changing the state of DangIt! while ships are in flight is not supported."); GUILayout.Label("There is no gaurentee that ships will remain in a stable state after toggle, ESPECIALLY if they currently have failed parts."); GUILayout.Label("It is reccomended that this option is only changed immediatley after the start of a game AND while no ships are in flight"); GUILayout.Label("You currently have " + (FlightGlobals.Vessels.Count - 1).ToString() + " vessels in flight. Are you sure you want to proceed?"); GUILayout.Space(50); GUILayout.BeginHorizontal(); if (GUILayout.Button("Yes")) { lastEnabledValue = newSettings.EnabledForSave; waitingForConfirm = false; DangIt.Instance.CurrentSettings = this.newSettings; } if (GUILayout.Button("No")) { newSettings.EnabledForSave = lastEnabledValue; waitingForConfirm = false; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); } else { // Display the toggles and controls to read the new settings newSettings.EnabledForSave = GUILayout.Toggle(newSettings.EnabledForSave, "Enable"); if (newSettings.EnabledForSave != this.lastEnabledValue) { waitingForConfirm = true; } if (newSettings.EnabledForSave) { newSettings.ManualFailures = GUILayout.Toggle(newSettings.ManualFailures, "Manual failures"); newSettings.DebugStats = GUILayout.Toggle(newSettings.DebugStats, "Show Debug Stats"); newSettings.Glow = GUILayout.Toggle(newSettings.Glow, "Glow"); newSettings.RequireExperience = GUILayout.Toggle(newSettings.RequireExperience, "Check Experience"); newSettings.Messages = GUILayout.Toggle(newSettings.Messages, "Messages"); GUILayout.BeginHorizontal(); GUILayout.Label("Max EVA distance: "); evaDistanceString = GUILayout.TextField(evaDistanceString); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Alarm Volume (0-100): "); SoundVolumeString = GUILayout.TextField(SoundVolumeString); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("# Times to beep for Priorities (-1=>Inf) of Failures"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("LOW: "); SoundLoopsString_Low = GUILayout.TextField(SoundLoopsString_Low); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("MEDIUM: "); SoundLoopsString_Medium = GUILayout.TextField(SoundLoopsString_Medium); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("HIGH: "); SoundLoopsString_High = GUILayout.TextField(SoundLoopsString_High); GUILayout.EndHorizontal(); } else { GUILayout.Label("DangIt! is disabled"); } // Creates the button and returns true when it is pressed if (GUILayout.Button("Apply")) { // Parse the strings this.newSettings.MaxDistance = DangIt.Parse <float>(evaDistanceString, defaultTo: 2f); this.newSettings.Pri_Low_SoundLoops = DangIt.Parse <int>(SoundLoopsString_Low, defaultTo: 0); this.newSettings.Pri_Medium_SoundLoops = DangIt.Parse <int>(SoundLoopsString_Medium, defaultTo: 2); this.newSettings.Pri_High_SoundLoops = DangIt.Parse <int>(SoundLoopsString_High, defaultTo: -1); int av = DangIt.Parse <int>(SoundVolumeString, defaultTo: 100); //av = (av < 0) ? 0 : (av > 100) ? 100 : av; //This clamps it between 0 and 100 (or not) if (av < 1) { av = 1; } else if (av > 100) { av = 100; } this.newSettings.AlarmVolume = av; DangIt.Instance.CurrentSettings = this.newSettings; ReInitilize(); //Reinit string data in case you entered a invalid value (or went over cap in volume) } } // This call allows the user to drag the window around the screen GUI.DragWindow(); }
private float InspectionMultiplier() { float elapsed = (DangIt.Now() - this.TimeOfLastInspection); return Math.Max(0f, Math.Min(elapsed / this.InspectionBonus, 1f)); }
/// <summary> /// Update logic on every physics frame update. /// Place your custom update logic in DI_Update() /// </summary> public void FixedUpdate() { try { // Only update the module during flight and after the re-initialization has run if (HighLogic.LoadedSceneIsFlight && this.HasInitted) { // Highlighting the part, which contains this updating FailureModule if it is in a 'failed' state, // it is not in 'silent' state and 'glow' is globally enabled // Actually, there is not any place in a code of the whole mod where that 'silent' state is turning on // (maybe some FailureModules can be defined as 'silent' by editing files) if (this.HasFailed && !this.Silent && (DangIt.Instance.CurrentSettings.Glow && (AlarmManager.visibleUI || !DangIt.Instance.CurrentSettings.DisableGlowOnF2))) { this.part.SetHighlightDefault(); this.part.SetHighlightColor(Color.red); this.part.SetHighlightType(Part.HighlightType.AlwaysOn); this.part.highlighter.ConstantOn(Color.red); this.part.highlighter.SeeThroughOn(); this.part.SetHighlight(true, false); } else // Turning off the highlighting of the part, which contains this updating FailureModule // if it is not in a 'failed' state, or it is in 'silent' state, or if 'glow' is globally disabled // if (!this.HasFailed || this.Silent || !DangIt.Instance.CurrentSettings.Glow || (!visibleUI && DangIt.Instance.CurrentSettings.DisableGlowOnF2)) { if (!AlarmManager.partFailures.ContainsKey(this.part)) this.part.SetHighlightDefault(); } float now = DangIt.Now(); float dt = now - LastFixedUpdate; this.LastFixedUpdate = now; // The temperature aging is independent from the use of the part this.Age += (dt * this.TemperatureMultiplier()); if (!PartIsActive() || !DangIt.Instance.CurrentSettings.EnabledForSave) return; else { this.Age += dt; this.CurrentMTBF = this.MTBF * HighLogic.CurrentGame.Parameters.CustomParams<DangItCustomParams1>().MTBF_Multiplier * this.ExponentialDecay(); // If the part has not already failed, toss the dice if (!this.HasFailed) { float f = this.Lambda(); #if DEBUG // if (printChances) // Logger.Debug("this.Lambda: " + f.ToString()); #endif if (UnityEngine.Random.Range(0f, 1f) < f) { this.Fail(); } } // Run custom update logic this.DI_Update(); } } } catch (Exception e) { OnError(e); } }