private string getDaysRemaining() { if (handler == null) { return("Error..."); } float next = getNextCompletion(handler.completion); if (handler.completion >= next) { return("Complete"); } if (handler.calibration <= 0) { return("∞"); } if (!handler.experimentRunning) { return(""); } float calib = handler.calibration; if (SEP_Controller.Instance.UsingCommNet) { if (vessel.Connection != null) { float signal = (float)vessel.Connection.SignalStrength - 0.5f; if (signal < 0) { signal /= 2; } float bonus = calib * signal; calib += bonus; } } float time = handler.experimentTime / calib; time *= 21600; time *= next; float nowTime = 0; if (handler.completion > 0) { nowTime = (handler.completion / next) * time; } float f = time - nowTime; return(KSPUtil.PrintTime(f, 2, false)); }
private void updateVesselData() { var vessel = this.currentVessel; bool hasNextNode = false; var nextNodeTime = Vessel.GetNextManeuverTime(vessel, out hasNextNode); // some stuff doesn't need to be updated if it's not changing var shouldUpdate = vessel.isActiveVessel || vessel.loaded || !this.vesselData.Id.Equals(vessel.id); var vesselData = new VesselData { Id = vessel.id, OrbitData = OrbitData.FromOrbit(vessel.orbit), Resources = shouldUpdate ? updateVesselResourceData(vessel) : this.vesselData.Resources, CrewData = shouldUpdate ? this.updateVesselCrewData(vessel) : this.vesselData.CrewData, MET = Converters.Duration(Math.Abs(vessel.missionTime)), HasNextNode = hasNextNode, NextNodeIn = "T " + KSPUtil.PrintTime(Planetarium.GetUniversalTime() - nextNodeTime, 3, true), NextNodeTime = KSPUtil.PrintDateCompact(nextNodeTime, true, true), Situation = Vessel.GetSituationString(vessel), }; this.vesselData = vesselData; }
void DrawRecyclingProgress() { // Currently build item if (_processedItem != null) { if (_processedItem.Icon == null) { _processedItem.EnableIcon(64); } GUI.Box(new Rect(190, 620, 50, 50), _processedItem.Icon.texture); } else { GUI.Box(new Rect(190, 620, 50, 50), ""); } // Progressbar GUI.Box(new Rect(250, 620, 260, 50), ""); if (progress >= 1) { var color = GUI.color; GUI.color = new Color(0, 1, 0, 1); GUI.Box(new Rect(250, 620, 260 * progress / 100, 50), ""); GUI.color = color; } string progressText = ""; if (_processedBlueprint != null) { progressText = string.Format("Progress: {0:n1}%, T- ", progress) + KSPUtil.PrintTime(_processedBlueprint.GetBuildTime(WorkshopUtils.ProductivityType.recycler, adjustedProductivity), 5, false); } Log.Info("DrawRecyclingProgress, adjustedProductivity: " + adjustedProductivity); GUI.Label(new Rect(250, 620, 260, 50), " " + progressText); // Toolbar if (recyclingPaused) { if (GUI.Button(new Rect(520, 620, 50, 50), _playTexture)) { recyclingPaused = false; } } else { if (GUI.Button(new Rect(520, 620, 50, 50), _pauseTexture)) { recyclingPaused = true; } } if (GUI.Button(new Rect(580, 620, 50, 50), _binTexture)) { CancelManufacturing(); } }
private void OnGUI() { if (!_mouseOver) { return; } GUI.skin = HighLogic.Skin; Orbit orbit = _hitOrbit; Vector3d deltaPos = orbit.getPositionAtUT(_hitUT) - orbit.referenceBody.position; double altitude = deltaPos.magnitude - orbit.referenceBody.Radius; double speed = orbit.getOrbitalSpeedAt(orbit.getObtAtUT(_hitUT)); string labelText = ""; if (HighLogic.CurrentGame.Parameters.CustomParams <ABCORSSettings>().showTime) { labelText += "T: " + KSPUtil.PrintTime((int)(Planetarium.GetUniversalTime() - _hitUT), 5, true) + "\n"; } if (HighLogic.CurrentGame.Parameters.CustomParams <ABCORSSettings>().showAltitude) { labelText += "Alt: " + altitude.ToString("N0", CultureInfo.CurrentCulture) + "m\n"; } if (HighLogic.CurrentGame.Parameters.CustomParams <ABCORSSettings>().showSpeed) { labelText += "Vel: " + speed.ToString("N0", CultureInfo.CurrentCulture) + "m/s\n"; } if (HighLogic.CurrentGame.Parameters.CustomParams <ABCORSSettings>().showAngleToPrograde&& orbit.referenceBody.orbit != null) { Vector3d bodyVel = orbit.referenceBody.orbit.getOrbitalVelocityAtUT(_hitUT); Vector3d shipPos = orbit.getRelativePositionAtUT(_hitUT); double angle = Vector3d.Angle(shipPos, bodyVel); Vector3d rotatedBodyVel = QuaternionD.AngleAxis(90.0, Vector3d.forward) * bodyVel; if (Vector3d.Dot(rotatedBodyVel, shipPos) > 0) { angle = 360 - angle; } labelText += "\u03B1P: " + angle.ToString("N1", CultureInfo.CurrentCulture) + "\u00B0\n"; } GUILayout.BeginArea(GUIUtility.ScreenToGUIRect(_popup)); GUIStyle labelStyle = new GUIStyle(GUI.skin.GetStyle("Label")); if (_isTarget) { labelStyle.normal.textColor = Color.cyan; } GUILayout.Label(labelText, labelStyle); GUILayout.EndArea(); }
private void drawRevertWarning() { GUILayout.Label("Reverting will set the game back to an earlier state. Are you sure you want to continue?"); if (GUILayout.Button("Revert to Launch (" + KSPUtil.PrintTime((int)(Planetarium.GetUniversalTime() - FlightDriver.PostInitState.UniversalTime), 3, false) + " ago)")) { Close(); Close(); FlightDriver.RevertToLaunch(); } if (GUILayout.Button("Cancel")) { Close(); } }
private string getTimeRemaining() { if (handler == null) { return(Localizer.Format("#LOC_SurfaceExperimentPack_ModuleSEPScienceExperiment_statusError")); } float next = getNextCompletion(handler.completion); if (calibration <= 0) { return("∞"); } float calib = calibration; if (SEP_Controller.Instance.UsingCommNet) { if (vessel.Connection != null) { float signal = (float)vessel.Connection.SignalStrength - 0.5f; if (signal < 0) { signal /= 2; } float bonus = calib * signal; calib += bonus; } } float time = experimentTime / calib; time *= 21600; time *= next; float nowTime = 0; if (handler.completion > 0) { nowTime = (handler.completion / next) * time; } float f = time - nowTime; return(KSPUtil.PrintTime(f, 2, false)); }
private void drawAbortWarning() { string revertTarget; GUILayout.Label("Reverting will set the game back to an earlier state. Are you sure you want to continue?"); switch (HoloDeckShelter.lastScene) { case GameScenes.EDITOR: switch (HoloDeckShelter.lastEditor) { case EditorFacility.SPH: revertTarget = "Spaceplane Hangar"; break; case EditorFacility.VAB: revertTarget = "Vehicle Assembly Building"; break; // This should never happen. If it does, just go to the SC default: revertTarget = "Space Center"; HoloDeckShelter.lastScene = GameScenes.SPACECENTER; break; } break; case GameScenes.SPACECENTER: revertTarget = "Space Center"; break; default: revertTarget = "Pre-Simulation"; break; } if (GUILayout.Button("Revert to " + revertTarget + " (" + KSPUtil.PrintTime((int)(Planetarium.GetUniversalTime() - FlightDriver.PostInitState.UniversalTime), 3, false) + " ago)")) { Close(); Close(); HoloDeck.Deactivate(HoloDeckShelter.lastScene); } if (GUILayout.Button("Cancel")) { Close(); } }
private void drawRevert(int id) { GUILayout.BeginVertical(); GUILayout.Label(Localizer.Format("#SOS_020")); if (FlightDriver.CanRevertToPostInit && HighLogic.CurrentGame.Parameters.Flight.CanRestart) { if (GUILayout.Button(Localizer.Format("#autoLOC_418666", KSPUtil.PrintTime(Planetarium.GetUniversalTime() - FlightDriver.PostInitState.UniversalTime, 3, false)))) { revertMenu = false; CloseWindow(); FlightDriver.RevertToLaunch(); } } if (HighLogic.CurrentGame.Parameters.Flight.CanLeaveToEditor && FlightDriver.CanRevertToPrelaunch && ShipConstruction.ShipConfig != null) { EditorFacility shipType = ShipConstruction.ShipType; if (shipType != EditorFacility.VAB) { if (shipType == EditorFacility.SPH) { if (GUILayout.Button(Localizer.Format("#autoLOC_418687", KSPUtil.PrintTime(Planetarium.GetUniversalTime() - FlightDriver.PostInitState.UniversalTime, 3, false)))) { revertMenu = false; FlightDriver.RevertToPrelaunch(EditorFacility.SPH); } ; } } else { if (GUILayout.Button(Localizer.Format("#autoLOC_418682", KSPUtil.PrintTime(Planetarium.GetUniversalTime() - FlightDriver.PostInitState.UniversalTime, 3, false)))) { revertMenu = false; FlightDriver.RevertToPrelaunch(EditorFacility.VAB); } } } if (GUILayout.Button(Localizer.Format("#autoLOC_455882"))) { revertMenu = false; } GUILayout.EndVertical(); GUI.DragWindow(); }
protected void FixedUpdate() { int pC; if (HighLogic.LoadedSceneIsFlight && part.CrewCapacity > 0 && (pC = part.protoModuleCrew.Count) > 0) { double UT = Planetarium.GetUniversalTime(); if (nextCheck < 0d) { nextCheck = UT + checkInterval; } else if (UT > nextCheck) { if (pressureAtKillAltitude == default) { pressureAtKillAltitude = FlightGlobals.GetHomeBody().GetPressureAtm(crewDeathAltitude); } nextCheck = UT + checkInterval; if (part.staticPressureAtm < pressureAtKillAltitude) { ScreenMessages.PostScreenMessage($"Cockpit is above the safe altitude which will lead to crew death", 1f, ScreenMessageStyle.UPPER_CENTER, XKCDColors.Red); bool killed = false; for (int i = pC; i-- > 0;) { ProtoCrewMember pcm = part.protoModuleCrew[i]; pcm.gExperienced += (0.5d + rnd.NextDouble()) * gDamageAdder; if (rnd.NextDouble() < crewDeathChance) { killed = true; ScreenMessages.PostScreenMessage($"{vessel.vesselName}: Crewmember {pcm.name} has died from exposure to near-vacuum.", 30.0f, ScreenMessageStyle.UPPER_CENTER, XKCDColors.Red); FlightLogger.fetch.LogEvent($"[{KSPUtil.PrintTime(vessel.missionTime, 3, false)}] {pcm.name} died from exposure to near-vacuum."); part.RemoveCrewmember(pcm); pcm.Die(); } } if (killed && CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA) { CameraManager.Instance.SetCameraFlight(); } } } } }
public string Print(double productivity) { var sb = new StringBuilder(); foreach (var res in this) { sb.AppendLine(res.Name + " : " + res.Units.ToString("N1")); } if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER && WorkshopOptions.PrintingCostsFunds) { sb.AppendLine("Resource costs: " + ResourceCosts().ToString("N1")); sb.AppendLine("Funds: " + Funds); } var duration = this.Sum(r => r.Units) / productivity; sb.Append(KSPUtil.PrintTime(duration, 5, false)); return sb.ToString(); }
protected void FixedUpdate() { int pC; if (HighLogic.LoadedSceneIsFlight && part.CrewCapacity > 0 && (pC = part.protoModuleCrew.Count) > 0) { double UT = Planetarium.GetUniversalTime(); if (nextCheck < 0d) { nextCheck = UT + checkInterval; } else if (UT > nextCheck) { nextCheck = UT + checkInterval; if (part.staticPressureAtm * 101.325d < 1.2d) { bool kill = false; for (int i = pC; i-- > 0;) { ProtoCrewMember pcm = part.protoModuleCrew[i]; pcm.gExperienced += (0.5d + rnd.NextDouble()) * gDamageAdder; if (rnd.NextDouble() < crewDeathChance) { kill = true; ScreenMessages.PostScreenMessage(vessel.vesselName + ": Crewmember " + pcm.name + " from exposure to near-vacuum.", 30.0f, ScreenMessageStyle.UPPER_CENTER); FlightLogger.fetch.LogEvent("[" + KSPUtil.PrintTime(vessel.missionTime, 3, false) + "] " + pcm.name + " died from exposure to near-vacuum."); part.RemoveCrewmember(pcm); pcm.Die(); } } if (kill) { if (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA) { CameraManager.Instance.SetCameraFlight(); } } } } } }
public string Print(WorkshopUtils.ProductivityType type, double productivity) { var sb = new StringBuilder(); foreach (var res in this) { sb.AppendLine(res.Name + " : " + res.Units.ToString("N1")); } if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER && WorkshopOptions.PrintingCostsFunds) { sb.AppendLine("Resource costs: " + ResourceCosts().ToString("N1")); sb.AppendLine("Funds: " + Funds); } if (HighLogic.CurrentGame.Parameters.CustomParams <Workshop_Settings>().useComplexity&& type == WorkshopUtils.ProductivityType.printer) { sb.AppendLine("Complexity: " + Complexity); } var duration = this.Sum(r => r.Units) / (productivity); sb.AppendLine("Base duration: " + KSPUtil.PrintTime(duration, 5, false)); if (type == WorkshopUtils.ProductivityType.printer) { duration = this.Sum(r => r.Units) / (productivity / Complexity); } else { duration = this.Sum(r => r.Units) / (productivity); } if (HighLogic.CurrentGame.Parameters.CustomParams <Workshop_Settings>().useComplexity&& type == WorkshopUtils.ProductivityType.printer) { sb.Append("Complexity duration: " + KSPUtil.PrintTime(duration, 5, false)); } return(sb.ToString()); }
protected void FixedUpdate() { int pC; if (HighLogic.LoadedSceneIsFlight && part.CrewCapacity > 0 && (pC = part.protoModuleCrew.Count) > 0) { double UT = Planetarium.GetUniversalTime(); if (nextCheck < 0d) { nextCheck = UT + checkInterval; } else if (UT > nextCheck) { if (pressureAtKillAltitude == default) { pressureAtKillAltitude = FlightGlobals.GetHomeBody().GetPressureAtm(crewDeathAltitude); _origDoStockGCalcs = ProtoCrewMember.doStockGCalcs; } nextCheck = UT + checkInterval; if (part.staticPressureAtm < pressureAtKillAltitude) { ScreenMessages.PostScreenMessage($"Cockpit is above the safe altitude which will lead to crew incapacitation and eventually to death", 1f, ScreenMessageStyle.UPPER_CENTER, XKCDColors.Red); if (!_origDoStockGCalcs.HasValue) { _origDoStockGCalcs = ProtoCrewMember.doStockGCalcs; } ProtoCrewMember.doStockGCalcs = false; bool killed = false; for (int i = pC; i-- > 0;) { ProtoCrewMember pcm = part.protoModuleCrew[i]; double highGPenalty = vessel.geeForce > 3 ? vessel.geeForce : 1; pcm.gExperienced += (0.5d + rnd.NextDouble()) * gDamageAdder * highGPenalty; double gMult = ProtoCrewMember.GToleranceMult(pcm) * HighLogic.CurrentGame.Parameters.CustomParams <GameParameters.AdvancedParams>().KerbalGToleranceMult; _anyCrewAboveWarnThreshold = pcm.gExperienced > PhysicsGlobals.KerbalGThresholdWarn * gMult; double locThreshold = PhysicsGlobals.KerbalGThresholdLOC * gMult; if (!pcm.outDueToG && pcm.gExperienced > locThreshold) { // Just passed out ScreenMessages.PostScreenMessage($"<color=red>{pcm.name} has lost consciousness due to hypoxia!</color>", 5.5f, ScreenMessageStyle.UPPER_CENTER); } // There's at least one cycle of delay after passing out before the death chance rolls start if (pcm.outDueToG && rnd.NextDouble() < crewDeathChance) { killed = true; ScreenMessages.PostScreenMessage($"{vessel.vesselName}: Crewmember {pcm.name} has died from exposure to near-vacuum.", 30.0f, ScreenMessageStyle.UPPER_CENTER, XKCDColors.Red); FlightLogger.fetch.LogEvent($"[{KSPUtil.PrintTime(vessel.missionTime, 3, false)}] {pcm.name} died from exposure to near-vacuum."); part.RemoveCrewmember(pcm); pcm.Die(); } } if (killed && CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA) { CameraManager.Instance.SetCameraFlight(); } } else { if (_origDoStockGCalcs.HasValue) { ProtoCrewMember.doStockGCalcs = _origDoStockGCalcs.Value; _origDoStockGCalcs = null; } } } } }
private void DrawPrintProgress() { // Currently build item if (_processedItem != null) { if (_processedItem.Icon == null) { _processedItem.EnableIcon(64); } GUI.Box(new Rect(190, 620, 50, 50), _processedItem.Icon.texture); } else { GUI.Box(new Rect(190, 620, 50, 50), ""); } // Progressbar GUI.Box(new Rect(250, 620, 280, 50), ""); if (progress >= 1) { var color = GUI.color; GUI.color = new Color(0, 1, 0, 1); GUI.Box(new Rect(250, 620, 280 * progress / 100, 50), ""); GUI.color = color; } string progressText = ""; if (_processedBlueprint != null) { progressText = string.Format("Progress: {0:n1}%, T- ", progress) + KSPUtil.PrintTime(_processedBlueprint.GetBuildTime(WorkshopUtils.ProductivityType.printer, adjustedProductivity), 5, false); } GUI.Label(new Rect(250, 620, 280, 50), " " + progressText); //Pause/resume production Texture2D buttonTexture = _pauseTexture; if (manufacturingPaused || _processedItem == null) { buttonTexture = _playTexture; } if (GUI.Button(new Rect(530, 620, 50, 50), buttonTexture) && _processedItem != null) { manufacturingPaused = !manufacturingPaused; } //Cancel production if (_processedItem == null) { GUI.enabled = false; } if (GUI.Button(new Rect(580, 620, 50, 50), _binTexture)) { if (_confirmDelete) { _processedItem.DisableIcon(); _processedItem = null; _processedBlueprint = null; progress = 0; manufacturingPaused = false; Status = "Online"; if (Animate && _heatAnimation != null && _workAnimation != null) { StartCoroutine(StopAnimations()); } _confirmDelete = false; } else { _confirmDelete = true; ScreenMessages.PostScreenMessage("Click the cancel button again to confirm cancelling current production", 5.0f, ScreenMessageStyle.UPPER_CENTER); } } GUI.enabled = true; }
private void UpdateTimers() { if (_snapTab == null || _manager.SelectedManeuverNode == null) { return; } if (_patch == null) { SetFields(); } double UT = Planetarium.GetUniversalTime(); //_snapTab.CurrentTime.OnTextUpdate.Invoke(string.Format("Maneuver Node #{0}: T {1}", _index + 1, KSPUtil.PrintTime(UT - _manager.SelectedManeuverNode.UT, 3, true))); double periods = 0; if (!double.IsNaN(_patch.period) && !double.IsInfinity(_patch.period)) { periods = (_orbitsAdded * _patch.period); } if (_snapTab.ApoButton.gameObject.activeSelf) { _snapTab.ApoTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime((apoUT + periods) - UT, 3, false))); } if (_snapTab.PeriButton.gameObject.activeSelf) { _snapTab.PeriTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime((periUT + periods) - UT, 3, false))); } if (_snapTab.NextOrbitButton.gameObject.activeSelf) { _snapTab.NOTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime(nextOUT - UT, 3, false))); } if (_snapTab.PreviousOrbitButton.gameObject.activeSelf) { _snapTab.POTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime(prevOUT - UT, 3, false))); } if (_snapTab.NextPatchButton.gameObject.activeSelf) { _snapTab.NPTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime(nextPUT - UT, 3, false))); } if (_snapTab.PreviousPatchButton.gameObject.activeSelf) { _snapTab.PPTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime(prevPUT - UT, 3, false))); } if (_snapTab.EqAscButton.gameObject.activeSelf) { _snapTab.EqAscTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime((eqAscUT + periods) - UT, 3, false))); } if (_snapTab.EqDescButton.gameObject.activeSelf) { _snapTab.EqDescTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime((eqDescUT + periods) - UT, 3, false))); } if (_snapTab.RelAscButton.gameObject.activeSelf) { _snapTab.RelAscTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime((relAscUT + periods) - UT, 3, false))); } if (_snapTab.RelDescButton.gameObject.activeSelf) { _snapTab.RelDescTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime((relDescUT + periods) - UT, 3, false))); } if (_snapTab.ClAppButton.gameObject.activeSelf) { _snapTab.ApproachTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime(clAppUT - UT, 3, false))); } //_snapTab.CurrentTime.OnTextUpdate.Invoke(string.Format("Maneuver Node #{0}: T {1}", _index + 1, KSPUtil.PrintTime(UT - _manager.SelectedManeuverNode.UT, 3, true))); _snapTab.ResetTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime(_startUT - UT, 3, false))); }
private void checkOrbit() { if (_manager.SelectedManeuverNode == null || _snapTab == null) { return; } if (_patch == null) { SetFields(); } double UT = Planetarium.GetUniversalTime(); //_snapTab.CurrentTime.OnTextUpdate.Invoke(string.Format("Maneuver Node #{0}: T {1}", _index + 1, KSPUtil.PrintTime(UT - _manager.SelectedManeuverNode.UT, 3, true))); _snapTab.ResetTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime(_startUT - UT, 3, false))); if (_patch.eccentricity >= 1) { if (_manager.SelectedManeuverNode.attachedGizmo != null) { _manager.SelectedManeuverNode.attachedGizmo.orbitsAdded = 0; } _orbitsAdded = 0; _snapTab.NextOrbitButton.gameObject.SetActive(false); _snapTab.PreviousOrbitButton.gameObject.SetActive(false); _snapTab.ApoButton.gameObject.SetActive(false); if (_patch.timeToPe < 0) { _snapTab.PeriButton.gameObject.SetActive(false); } else if (_patch.PeR < 0) { _snapTab.PeriButton.gameObject.SetActive(false); } else if (_patch.UTsoi > 0 && _patch.timeToPe + _patch.StartUT > _patch.UTsoi) { _snapTab.PeriButton.gameObject.SetActive(false); } else { _snapTab.PeriButton.gameObject.SetActive(true); periUT = _patch.StartUT + _patch.timeToPe; } if ((_patch.patchEndTransition == Orbit.PatchTransitionType.ENCOUNTER || _patch.patchEndTransition == Orbit.PatchTransitionType.ESCAPE || _patch.patchEndTransition == Orbit.PatchTransitionType.MANEUVER) && (_patch.nextPatch.patchEndTransition == Orbit.PatchTransitionType.ENCOUNTER || _patch.nextPatch.patchEndTransition == Orbit.PatchTransitionType.ESCAPE)) { _snapTab.NextPatchButton.gameObject.SetActive(true); if (_patch.nextPatch.nextPatch.UTsoi > 0) { nextPUT = _patch.nextPatch.nextPatch.StartUT + ((_patch.nextPatch.nextPatch.UTsoi - _patch.nextPatch.nextPatch.StartUT) / 2); } else if (_patch.nextPatch.nextPatch.eccentricity < 1 && !double.IsNaN(_patch.nextPatch.nextPatch.period) && !double.IsInfinity(_patch.nextPatch.nextPatch.period)) { nextPUT = _patch.nextPatch.nextPatch.StartUT + (_patch.nextPatch.nextPatch.period / 2); } else { nextPUT = _patch.nextPatch.nextPatch.StartUT + ((_patch.nextPatch.nextPatch.EndUT - _patch.nextPatch.nextPatch.StartUT) / 2); } } else { _snapTab.NextPatchButton.gameObject.SetActive(false); } if (_patch.patchStartTransition == Orbit.PatchTransitionType.INITIAL || _patch.patchStartTransition == Orbit.PatchTransitionType.MANEUVER) { _snapTab.PreviousPatchButton.gameObject.SetActive(false); } else { _snapTab.PreviousPatchButton.gameObject.SetActive(true); if (_patch.previousPatch.UTsoi > 0) { prevPUT = _patch.previousPatch.StartUT + ((_patch.previousPatch.UTsoi - _patch.previousPatch.StartUT) / 2); } else if (_patch.previousPatch.eccentricity < 1 && !double.IsNaN(_patch.previousPatch.period) && !double.IsInfinity(_patch.previousPatch.period)) { prevPUT = _patch.previousPatch.StartUT + (_patch.previousPatch.period / 2); } else { prevPUT = _patch.previousPatch.StartUT + ((_patch.previousPatch.EndUT - _patch.previousPatch.StartUT) / 2); } } eqAscUT = ManeuverUtilities.EqAscTime(_patch); if (_patch.UTsoi > 0 && eqAscUT > _patch.UTsoi) { _snapTab.EqAscButton.gameObject.SetActive(false); } else if (eqAscUT < UT) { _snapTab.EqAscButton.gameObject.SetActive(false); } else { _snapTab.EqAscButton.gameObject.SetActive(true); } eqDescUT = ManeuverUtilities.EqDescTime(_patch); if (_patch.UTsoi > 0 && eqDescUT > _patch.UTsoi) { _snapTab.EqDescButton.gameObject.SetActive(false); } else if (eqDescUT < UT) { _snapTab.EqDescButton.gameObject.SetActive(false); } else { _snapTab.EqDescButton.gameObject.SetActive(true); } ITargetable target = FlightGlobals.fetch.VesselTarget; if (target == null) { _snapTab.RelAscButton.gameObject.SetActive(false); _snapTab.RelDescButton.gameObject.SetActive(false); _snapTab.ClAppButton.gameObject.SetActive(false); } else { Orbit tgtPatch = target.GetOrbit(); if (tgtPatch.referenceBody != _patch.referenceBody) { _snapTab.RelAscButton.gameObject.SetActive(false); _snapTab.RelDescButton.gameObject.SetActive(false); _snapTab.ClAppButton.gameObject.SetActive(false); } else { relAscUT = ManeuverUtilities.RelAscTime(_patch, target); if (_patch.UTsoi > 0 && relAscUT > _patch.UTsoi) { _snapTab.RelAscButton.gameObject.SetActive(false); } else if (relAscUT < UT) { _snapTab.RelAscButton.gameObject.SetActive(false); } else { _snapTab.RelAscButton.gameObject.SetActive(true); } relDescUT = ManeuverUtilities.RelDescTime(_patch, target); if (_patch.UTsoi > 0 && relDescUT > _patch.UTsoi) { _snapTab.RelDescButton.gameObject.SetActive(false); } else if (relDescUT < UT) { _snapTab.RelDescButton.gameObject.SetActive(false); } else { _snapTab.RelDescButton.gameObject.SetActive(true); } if (target.GetVessel() == null) { clAppUT = _patch.closestTgtApprUT; } else { clAppUT = ManeuverUtilities.closestVessel(0, _patch, tgtPatch, true, 0, 0); } if (clAppUT <= 0) { _snapTab.ClAppButton.gameObject.SetActive(false); } else if (_patch.UTsoi > 0 && clAppUT > _patch.UTsoi) { _snapTab.ClAppButton.gameObject.SetActive(false); } else if (clAppUT < UT) { _snapTab.ClAppButton.gameObject.SetActive(false); } else { _snapTab.ClAppButton.gameObject.SetActive(true); } } } } else { if (_patch.patchEndTransition == Orbit.PatchTransitionType.FINAL) { if (!double.IsNaN(_patch.period) && !double.IsInfinity(_patch.period)) { _snapTab.NextOrbitButton.gameObject.SetActive(true); nextOUT = _manager.SelectedManeuverNode.UT + _patch.period; } else { _snapTab.NextOrbitButton.gameObject.SetActive(false); } if (double.IsNaN(_patch.period) || double.IsInfinity(_patch.period) || _manager.SelectedManeuverNode.UT - _patch.period < UT) { _snapTab.PreviousOrbitButton.gameObject.SetActive(false); } else { _snapTab.PreviousOrbitButton.gameObject.SetActive(true); prevOUT = _manager.SelectedManeuverNode.UT - _patch.period; } _snapTab.ApoButton.gameObject.SetActive(true); apoUT = _patch.StartUT + _patch.timeToAp; _snapTab.PeriButton.gameObject.SetActive(true); periUT = _patch.StartUT + _patch.timeToPe; _snapTab.NextPatchButton.gameObject.SetActive(false); if (_patch.patchStartTransition == Orbit.PatchTransitionType.INITIAL || _patch.patchStartTransition == Orbit.PatchTransitionType.MANEUVER) { _snapTab.PreviousPatchButton.gameObject.SetActive(false); } else { _snapTab.PreviousPatchButton.gameObject.SetActive(true); if (_patch.previousPatch.UTsoi > 0) { prevPUT = _patch.previousPatch.StartUT + ((_patch.previousPatch.UTsoi - _patch.previousPatch.StartUT) / 2); } else if (_patch.previousPatch.eccentricity < 1 && !double.IsNaN(_patch.previousPatch.period) && !double.IsInfinity(_patch.previousPatch.period)) { prevPUT = _patch.previousPatch.StartUT + (_patch.previousPatch.period / 2); } else { prevPUT = _patch.previousPatch.StartUT + ((_patch.previousPatch.EndUT - _patch.previousPatch.StartUT) / 2); } } _snapTab.EqAscButton.gameObject.SetActive(true); eqAscUT = ManeuverUtilities.EqAscTime(_patch); _snapTab.EqDescButton.gameObject.SetActive(true); eqDescUT = ManeuverUtilities.EqDescTime(_patch); ITargetable target = FlightGlobals.fetch.VesselTarget; if (target == null) { _snapTab.RelAscButton.gameObject.SetActive(false); _snapTab.RelDescButton.gameObject.SetActive(false); _snapTab.ClAppButton.gameObject.SetActive(false); } else { Orbit tgtPatch = target.GetOrbit(); if (tgtPatch.referenceBody != _patch.referenceBody) { _snapTab.RelAscButton.gameObject.SetActive(false); _snapTab.RelDescButton.gameObject.SetActive(false); _snapTab.ClAppButton.gameObject.SetActive(false); } else { _snapTab.RelAscButton.gameObject.SetActive(true); relAscUT = ManeuverUtilities.RelAscTime(_patch, target); _snapTab.RelDescButton.gameObject.SetActive(true); relDescUT = ManeuverUtilities.RelDescTime(_patch, target); if (target.GetVessel() == null) { clAppUT = _patch.closestTgtApprUT; } else { clAppUT = ManeuverUtilities.closestVessel(0, _patch, tgtPatch, true, 0, 0); } if (clAppUT <= 0) { _snapTab.ClAppButton.gameObject.SetActive(false); } else { _snapTab.ClAppButton.gameObject.SetActive(true); } } } } else { if (_manager.SelectedManeuverNode.attachedGizmo != null) { _manager.SelectedManeuverNode.attachedGizmo.orbitsAdded = 0; } _orbitsAdded = 0; _snapTab.NextOrbitButton.gameObject.SetActive(false); _snapTab.PreviousOrbitButton.gameObject.SetActive(false); if (_patch.timeToAp < 0) { _snapTab.ApoButton.gameObject.SetActive(false); } if (_patch.UTsoi > 0 && _patch.timeToAp + _patch.StartUT > _patch.UTsoi) { _snapTab.ApoButton.gameObject.SetActive(false); } if (_patch.ApA > _patch.referenceBody.sphereOfInfluence) { _snapTab.ApoButton.gameObject.SetActive(false); } else { _snapTab.ApoButton.gameObject.SetActive(true); apoUT = _patch.StartUT + _patch.timeToAp; } if (_patch.timeToPe < 0) { _snapTab.PeriButton.gameObject.SetActive(false); } else if (_patch.PeR < 0) { _snapTab.PeriButton.gameObject.SetActive(false); } else if (_patch.UTsoi > 0 && _patch.timeToPe + _patch.StartUT > _patch.UTsoi) { _snapTab.PeriButton.gameObject.SetActive(false); } else { _snapTab.PeriButton.gameObject.SetActive(true); periUT = _patch.StartUT + _patch.timeToPe; } if ((_patch.patchEndTransition == Orbit.PatchTransitionType.ENCOUNTER || _patch.patchEndTransition == Orbit.PatchTransitionType.ESCAPE || _patch.patchEndTransition == Orbit.PatchTransitionType.MANEUVER) && (_patch.nextPatch.patchEndTransition == Orbit.PatchTransitionType.ENCOUNTER || _patch.nextPatch.patchEndTransition == Orbit.PatchTransitionType.ESCAPE)) { _snapTab.NextPatchButton.gameObject.SetActive(true); if (_patch.nextPatch.nextPatch.UTsoi > 0) { nextPUT = _patch.nextPatch.nextPatch.StartUT + ((_patch.nextPatch.nextPatch.UTsoi - _patch.nextPatch.nextPatch.StartUT) / 2); } else if (_patch.nextPatch.nextPatch.eccentricity < 1 && !double.IsNaN(_patch.nextPatch.nextPatch.period) && !double.IsInfinity(_patch.nextPatch.nextPatch.period)) { nextPUT = _patch.nextPatch.nextPatch.StartUT + (_patch.nextPatch.nextPatch.period / 2); } else { nextPUT = _patch.nextPatch.nextPatch.StartUT + ((_patch.nextPatch.nextPatch.EndUT - _patch.nextPatch.nextPatch.StartUT) / 2); } } else { _snapTab.NextPatchButton.gameObject.SetActive(false); } if (_patch.patchStartTransition == Orbit.PatchTransitionType.INITIAL || _patch.patchStartTransition == Orbit.PatchTransitionType.MANEUVER) { _snapTab.PreviousPatchButton.gameObject.SetActive(false); } else { _snapTab.PreviousPatchButton.gameObject.SetActive(true); if (_patch.previousPatch.UTsoi > 0) { prevPUT = _patch.previousPatch.StartUT + ((_patch.previousPatch.UTsoi - _patch.previousPatch.StartUT) / 2); } else if (_patch.previousPatch.eccentricity < 1 && !double.IsNaN(_patch.previousPatch.period) && !double.IsInfinity(_patch.previousPatch.period)) { prevPUT = _patch.previousPatch.StartUT + (_patch.previousPatch.period / 2); } else { prevPUT = _patch.previousPatch.StartUT + ((_patch.previousPatch.EndUT - _patch.previousPatch.StartUT) / 2); } } eqAscUT = ManeuverUtilities.EqAscTime(_patch); if (_patch.UTsoi > 0 && eqAscUT > _patch.UTsoi) { _snapTab.EqAscButton.gameObject.SetActive(false); } else if (eqAscUT < UT) { _snapTab.EqAscButton.gameObject.SetActive(false); } else { _snapTab.EqAscButton.gameObject.SetActive(true); } eqDescUT = ManeuverUtilities.EqDescTime(_patch); if (_patch.UTsoi > 0 && eqDescUT > _patch.UTsoi) { _snapTab.EqDescButton.gameObject.SetActive(false); } else if (eqDescUT < UT) { _snapTab.EqDescButton.gameObject.SetActive(false); } else { _snapTab.EqDescButton.gameObject.SetActive(true); } ITargetable target = FlightGlobals.fetch.VesselTarget; if (target == null) { _snapTab.RelAscButton.gameObject.SetActive(false); _snapTab.RelDescButton.gameObject.SetActive(false); _snapTab.ClAppButton.gameObject.SetActive(false); } else { Orbit tgtPatch = target.GetOrbit(); if (tgtPatch.referenceBody != _patch.referenceBody) { _snapTab.RelAscButton.gameObject.SetActive(false); _snapTab.RelDescButton.gameObject.SetActive(false); _snapTab.ClAppButton.gameObject.SetActive(false); } else { relAscUT = ManeuverUtilities.RelAscTime(_patch, target); if (_patch.UTsoi > 0 && relAscUT > _patch.UTsoi) { _snapTab.RelAscButton.gameObject.SetActive(false); } else if (relAscUT < UT) { _snapTab.RelAscButton.gameObject.SetActive(false); } else { _snapTab.RelAscButton.gameObject.SetActive(true); } relDescUT = ManeuverUtilities.RelDescTime(_patch, target); if (_patch.UTsoi > 0 && relDescUT > _patch.UTsoi) { _snapTab.RelDescButton.gameObject.SetActive(false); } else if (relDescUT < UT) { _snapTab.RelDescButton.gameObject.SetActive(false); } else { _snapTab.RelDescButton.gameObject.SetActive(true); } if (target.GetVessel() == null) { clAppUT = _patch.closestTgtApprUT; } else { clAppUT = ManeuverUtilities.closestVessel(0, _patch, tgtPatch, true, 0, 0); } if (clAppUT <= 0) { _snapTab.ClAppButton.gameObject.SetActive(false); } else if (_patch.UTsoi > 0 && clAppUT > _patch.UTsoi) { _snapTab.ClAppButton.gameObject.SetActive(false); } else if (clAppUT < UT) { _snapTab.ClAppButton.gameObject.SetActive(false); } else { _snapTab.ClAppButton.gameObject.SetActive(true); } } } } } }
protected void FixedUpdate() { int pC; if (HighLogic.LoadedSceneIsFlight && part.CrewCapacity > 0 && (pC = part.protoModuleCrew.Count) > 0) { double UT = KSPUtils.GetUT(); if (lastCheck < 0d) { lastCheck = UT; } double deltaTime = UT - lastCheck; if (deltaTime > checkInterval) { if (!_origDoStockGCalcs.HasValue) { _origDoStockGCalcs = ProtoCrewMember.doStockGCalcs; } lastCheck = UT; double curAltitute = part.vessel.altitude; if (curAltitute > crewDeathAltitude) { // Assume the standard atmosphere if (referenceDensity < 0d) { referenceDensity = Planetarium.fetch.Home.GetDensity(Planetarium.fetch.Home.GetPressure(crewDeathAltitude), Planetarium.fetch.Home.GetTemperature(crewDeathAltitude)); referenceDensityMin = referenceDensity * 0.02d; } timeSinceHypoxiaStarted += deltaTime; ScreenMessages.PostScreenMessage($"Cockpit is above the safe altitude which will lead to crew incapacitation and eventually to death", 1f, ScreenMessageStyle.UPPER_CENTER, XKCDColors.Red); if (!_origDoStockGCalcs.HasValue) { _origDoStockGCalcs = ProtoCrewMember.doStockGCalcs; } ProtoCrewMember.doStockGCalcs = false; bool killed = false; for (int i = pC; i-- > 0;) { ProtoCrewMember pcm = part.protoModuleCrew[i]; double highGPenalty = vessel.geeForce > 3d ? System.Math.Pow(vessel.geeForce - 2d, 2d) : 1; double curDensity = part.atmDensity; if (curDensity < referenceDensityMin) { curDensity = referenceDensityMin; } double altitudeMult = (curAltitute - crewDeathAltitude) / crewDeathAltitude * 10d + referenceDensity / curDensity - 1d; double timeMult = System.Math.Pow(timeSinceHypoxiaStarted, 1.5d) * 0.01d; pcm.gExperienced += (0.5d + rnd.NextDouble()) * gDamageAdder * highGPenalty * altitudeMult * timeMult; double gMult = ProtoCrewMember.GToleranceMult(pcm) * HighLogic.CurrentGame.Parameters.CustomParams <GameParameters.AdvancedParams>().KerbalGToleranceMult; _anyCrewAboveWarnThreshold = pcm.gExperienced > PhysicsGlobals.KerbalGThresholdWarn * gMult; double locThreshold = PhysicsGlobals.KerbalGThresholdLOC * gMult; if (!pcm.outDueToG && pcm.gExperienced > locThreshold) { // Just passed out ScreenMessages.PostScreenMessage($"<color=red>{pcm.name} has lost consciousness due to hypoxia!</color>", 5.5f, ScreenMessageStyle.UPPER_CENTER); } // There's at least one cycle of delay after passing out before the death chance rolls start if (pcm.outDueToG && rnd.NextDouble() < crewDeathChance * altitudeMult * timeMult) { killed = true; ScreenMessages.PostScreenMessage($"{vessel.vesselName}: Crewmember {pcm.name} has died from exposure to near-vacuum.", 30.0f, ScreenMessageStyle.UPPER_CENTER, XKCDColors.Red); FlightLogger.fetch.LogEvent($"[{KSPUtil.PrintTime(vessel.missionTime, 3, false)}] {pcm.name} died from exposure to near-vacuum."); part.RemoveCrewmember(pcm); pcm.Die(); } } if (killed && CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA) { CameraManager.Instance.SetCameraFlight(); } } else { timeSinceHypoxiaStarted = 0d; if (_origDoStockGCalcs.HasValue) { ProtoCrewMember.doStockGCalcs = _origDoStockGCalcs.Value; _origDoStockGCalcs = null; } } } } }