From f9d3e57dbddd1815eb157b08dfed6bd2c946cc68 Mon Sep 17 00:00:00 2001 From: arbsoup Date: Fri, 5 Jul 2024 11:54:22 -0600 Subject: [PATCH 1/9] hab timers for all crew are updated, not just first --- .../USILifeSupport/ModuleLifeSupportSystem.cs | 5 ++++- Source/USILifeSupport/USILifeSupport.csproj | 22 +++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Source/USILifeSupport/ModuleLifeSupportSystem.cs b/Source/USILifeSupport/ModuleLifeSupportSystem.cs index 48cc715..f41d59e 100644 --- a/Source/USILifeSupport/ModuleLifeSupportSystem.cs +++ b/Source/USILifeSupport/ModuleLifeSupportSystem.cs @@ -248,7 +248,6 @@ public void FixedUpdate() if (_isStatusRefreshRequired) { trackedKerbal.TimeEnteredVessel = now; - _isStatusRefreshRequired = false; LifeSupportManager.Instance.TrackKerbal(trackedKerbal); } @@ -332,6 +331,10 @@ public void FixedUpdate() LifeSupportManager.Instance.TrackKerbal(trackedKerbal); } + if (_isStatusRefreshRequired) + { + _isStatusRefreshRequired = false; + } } #endregion - Crew diff --git a/Source/USILifeSupport/USILifeSupport.csproj b/Source/USILifeSupport/USILifeSupport.csproj index eda6ce0..0dac672 100644 --- a/Source/USILifeSupport/USILifeSupport.csproj +++ b/Source/USILifeSupport/USILifeSupport.csproj @@ -32,7 +32,7 @@ - ..\..\..\..\KSP_DEV\KSP_x64_Data\Managed\Assembly-CSharp.dll + ..\..\..\..\Desktop\Kerbal Space Program\KSP_x64_Data\Managed\Assembly-CSharp.dll False @@ -42,31 +42,31 @@ - ..\..\..\..\KSP_DEV\KSP_x64_Data\Managed\UnityEngine.dll + ..\..\..\..\Desktop\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.dll False - ..\..\..\..\KSP_DEV\KSP_x64_Data\Managed\UnityEngine.AnimationModule.dll + ..\..\..\..\Desktop\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.AnimationModule.dll False - ..\..\..\..\KSP_DEV\KSP_x64_Data\Managed\UnityEngine.CoreModule.dll + ..\..\..\..\Desktop\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.CoreModule.dll False - ..\..\..\..\KSP_DEV\KSP_x64_Data\Managed\UnityEngine.ImageConversionModule.dll + ..\..\..\..\Desktop\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.ImageConversionModule.dll False - ..\..\..\..\KSP_DEV\KSP_x64_Data\Managed\UnityEngine.IMGUIModule.dll + ..\..\..\..\Desktop\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.IMGUIModule.dll False - ..\..\..\..\KSP_DEV\KSP_x64_Data\Managed\UnityEngine.UI.dll + ..\..\..\..\Desktop\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.UI.dll False - ..\..\..\..\KSP_DEV\GameData\000_USITools\USITools.dll + ..\..\..\..\Desktop\Kerbal Space Program\GameData\000_USITools\USITools.dll False @@ -95,7 +95,11 @@ - + + + + + "D:\Games\pdb2mdb\pdb2mdb.exe" "$(TargetFileName)" From 37808eb6b4895f9139011c709456b2a1e094c002 Mon Sep 17 00:00:00 2001 From: arbsoup Date: Fri, 5 Jul 2024 15:33:56 -0600 Subject: [PATCH 2/9] initial release of hab-cabin replacement for home-hab --- ...USILS_LifeSupportExtenderConverterAddon.cs | 9 +-- Source/USILifeSupport/LifeSupportManager.cs | 6 +- Source/USILifeSupport/LifeSupportMonitor.cs | 57 ++++++++++-------- .../LifeSupportMonitor_Editor.cs | 60 +++++++++++-------- .../USILifeSupport/LifeSupportPersistance.cs | 6 +- Source/USILifeSupport/LifeSupportStatus.cs | 1 + .../USILifeSupport/ModuleLifeSupportSystem.cs | 59 +++++++++++++----- 7 files changed, 119 insertions(+), 79 deletions(-) diff --git a/Source/USILifeSupport/Converters/USILS_LifeSupportExtenderConverterAddon.cs b/Source/USILifeSupport/Converters/USILS_LifeSupportExtenderConverterAddon.cs index b4f3be8..8537e0f 100644 --- a/Source/USILifeSupport/Converters/USILS_LifeSupportExtenderConverterAddon.cs +++ b/Source/USILifeSupport/Converters/USILS_LifeSupportExtenderConverterAddon.cs @@ -61,10 +61,11 @@ public override void PostProcess(ConverterResults result, double deltaTime) { var k = kerbals[i]; var lsKerbal = LifeSupportManager.Instance.FetchKerbal(k); - if (AffectsHomeTimer) - lsKerbal.MaxOffKerbinTime += timePerKerbal; - if (AffectsHabTimer) - lsKerbal.TimeEnteredVessel += timePerKerbal; + + // Experimental patch. + // I don't like changing LastAtHome but the alternative is that we add another variable... + if (AffectsHomeTimer || AffectsHabTimer) + lsKerbal.LastAtHome += timePerKerbal; LifeSupportManager.Instance.TrackKerbal(lsKerbal); } diff --git a/Source/USILifeSupport/LifeSupportManager.cs b/Source/USILifeSupport/LifeSupportManager.cs index 6f62fae..90f7bcc 100644 --- a/Source/USILifeSupport/LifeSupportManager.cs +++ b/Source/USILifeSupport/LifeSupportManager.cs @@ -112,10 +112,10 @@ public LifeSupportStatus FetchKerbal(ProtoCrewMember crew) k.LastEC = Planetarium.GetUniversalTime(); k.LastAtHome = Planetarium.GetUniversalTime(); k.LastSOIChange = Planetarium.GetUniversalTime(); - k.MaxOffKerbinTime = Planetarium.GetUniversalTime() + 648000; - k.TimeEnteredVessel = Planetarium.GetUniversalTime(); k.CurrentVesselId = "?UNKNOWN?"; k.PreviousVesselId = "??UNKNOWN??"; + k.RemainingCabinTime = LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime + * LifeSupportUtilities.SecondsPerMonth(); k.LastUpdate = Planetarium.GetUniversalTime(); k.IsGrouchy = false; k.OldTrait = crew.experienceTrait.Config.Name; @@ -391,7 +391,6 @@ internal static double GetHabChecksum(VesselSupplyStatus sourceVessel, Vessel vs double totHabSpace = sourceVessel.ExtraHabSpace; double totHabMult = CalculateVesselHabMultiplier(vsl, 1); - totHabSpace += (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime * totMaxCrew); var hCount = hList.Count; for (int i = 0; i < hCount; ++i) @@ -439,7 +438,6 @@ internal static double GetTotalHabTime(VesselSupplyStatus sourceVessel, Vessel v } double totHabSpace = sourceVessel.ExtraHabSpace; double totHabMult = CalculateVesselHabMultiplier(vessel,totCurCrew); - totHabSpace += (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime * totMaxCrew); var hCount = hList.Count; for (int i = 0; i < hCount; ++i) diff --git a/Source/USILifeSupport/LifeSupportMonitor.cs b/Source/USILifeSupport/LifeSupportMonitor.cs index 067b082..dad1f5c 100644 --- a/Source/USILifeSupport/LifeSupportMonitor.cs +++ b/Source/USILifeSupport/LifeSupportMonitor.cs @@ -118,7 +118,7 @@ private LifeSupportVesselDisplayStat GetEvaKerbalStats(Vessel kerbal) "{0}/{1} - {2} time remaining" , kerbal.mainBody.bodyName , sitString - , timeString.Substring(timeString.IndexOf(':') + 1)); + , timeString); } else { @@ -190,9 +190,11 @@ private LifeSupportVesselDisplayStat GetVesselStats(VesselSupplyStatus vsl) LifeSupportScenario.Instance.settings.GetSettings().HabRange); } + var numCrew = vsl.NumCrew; + var crewCap = vsl.CrewCap; foreach (var c in thisVessel.GetVesselCrew()) { - var crewStat = GetCrewStat(c, thisVessel, suppliesTimeLeft, ecTimeLeft, ecAmount, habTime); + var crewStat = GetCrewStat(c, thisVessel, suppliesTimeLeft, ecTimeLeft, ecAmount, habTime, numCrew, crewCap); vstat.crew.Add(crewStat); } vstat.crew = vstat.crew.OrderBy(crewStat => crewStat.EarliestExpiration).ToList(); @@ -284,8 +286,8 @@ private void DisplayCrewStats(LifeSupportCrewDisplayStat c) GUILayout.Label(c.ECLabel, _labelStyle, GUILayout.Width(145)); GUILayout.Label("hab:", _labelStyle, GUILayout.Width(40)); GUILayout.Label(c.HabLabel, _labelStyle, GUILayout.Width(145)); - GUILayout.Label("home:", _labelStyle, GUILayout.Width(40)); - GUILayout.Label(c.HomeLabel, _labelStyle, GUILayout.Width(145)); + GUILayout.Label("cabin:", _labelStyle, GUILayout.Width(40)); + GUILayout.Label(c.CabinLabel, _labelStyle, GUILayout.Width(145)); GUILayout.EndHorizontal(); } @@ -320,7 +322,7 @@ private string GetSituationString(Vessel vessel) return sitString; } - private LifeSupportCrewDisplayStat GetCrewStat(ProtoCrewMember c, Vessel vessel, double vesselSuppliesTimeLeft, double vesselEcTimeLeft, double vesselEcAmount, double vesselHabTime) + private LifeSupportCrewDisplayStat GetCrewStat(ProtoCrewMember c, Vessel vessel, double vesselSuppliesTimeLeft, double vesselEcTimeLeft, double vesselEcAmount, double vesselHabTime, int numCrew, int crewCap) { var cls = LifeSupportManager.Instance.FetchKerbal(c); //Guard clause in case we just changed vessels @@ -329,7 +331,6 @@ private LifeSupportCrewDisplayStat GetCrewStat(ProtoCrewMember c, Vessel vessel, { cls.PreviousVesselId = cls.CurrentVesselId; cls.CurrentVesselId = vessel.id.ToString(); - cls.TimeEnteredVessel = Planetarium.GetUniversalTime(); LifeSupportManager.Instance.TrackKerbal(cls); } @@ -345,7 +346,7 @@ private LifeSupportCrewDisplayStat GetCrewStat(ProtoCrewMember c, Vessel vessel, cStat.ComputeEc(ecTimeLeft, c); cStat.ComputeSupply(vesselSuppliesTimeLeft, c); cStat.ComputeHab(vesselHabTime, c, cls); - cStat.ComputeHome(c, cls); + cStat.ComputeCabin(c, cls, numCrew, crewCap); LifeSupportManager.Instance.TrackKerbal(cls); return cStat; @@ -399,7 +400,7 @@ public class LifeSupportCrewDisplayStat public string ECLabel { get; set; } public string SupplyLabel { get; set; } public string HabLabel { get; set; } - public string HomeLabel { get; set; } + public string CabinLabel { get; set; } public double EarliestExpiration { get; set; } public LifeSupportCrewDisplayStat() @@ -424,7 +425,7 @@ internal void ComputeHab(double vesselHabTime, ProtoCrewMember c, LifeSupportSta if (useHabPenalties) { UpdateEarliestExpiration(vesselHabTime); - var habTimeLeft = vesselHabTime - (Planetarium.GetUniversalTime() - cls.TimeEnteredVessel); + var habTimeLeft = vesselHabTime - (Planetarium.GetUniversalTime() - cls.LastAtHome); var isScout = c.HasEffect("ExplorerSkill") && habTimeLeft >= LifeSupportScenario.Instance.settings.GetSettings().ScoutHabTime; var isPermaHab = habTimeLeft >= LifeSupportScenario.Instance.settings.GetSettings().PermaHabTime; @@ -454,43 +455,47 @@ internal void ComputeHab(double vesselHabTime, ProtoCrewMember c, LifeSupportSta HabLabel = String.Format("{1}", lblHab, crewHabString); } - internal void ComputeHome(ProtoCrewMember c, LifeSupportStatus cls) + internal void ComputeCabin(ProtoCrewMember c, LifeSupportStatus cls, int numCrew, int crewCap) { - var crewHomeString = "indefinite"; - var lblHome = "6FFF00"; + var crewCabinString = "indefinite"; + var lblCabin = "6FFF00"; var useHabPenalties = LifeSupportManager.GetNoHomeEffect(c.name) > 0; if (useHabPenalties) { - var homeTimeLeft = cls.MaxOffKerbinTime - Planetarium.GetUniversalTime(); - UpdateEarliestExpiration(homeTimeLeft); + var cabinTimeLeft = cls.RemainingCabinTime; + UpdateEarliestExpiration(cabinTimeLeft); - var isScout = c.HasEffect("ExplorerSkill") && homeTimeLeft >= LifeSupportScenario.Instance.settings.GetSettings().ScoutHabTime; - var isPermaHab = homeTimeLeft >= LifeSupportScenario.Instance.settings.GetSettings().PermaHabTime; + // Debug.Log(String.Format("{0} has {1} remaining CabinTime", cls.KerbalName, cabinTimeLeft )); + + var isScout = c.HasEffect("ExplorerSkill") && cabinTimeLeft >= LifeSupportScenario.Instance.settings.GetSettings().ScoutHabTime; + var isPermaHab = cabinTimeLeft >= LifeSupportScenario.Instance.settings.GetSettings().PermaHabTime; if (isScout || isPermaHab) { - crewHomeString = "indefinite"; + crewCabinString = "indefinite"; } - else if (homeTimeLeft < 0) + else if (cabinTimeLeft < 0) { - lblHome = "FF5E5E"; - crewHomeString = "expired"; + lblCabin = "FF5E5E"; + crewCabinString = "expired"; } else { - crewHomeString = LifeSupportUtilities.SmartDurationDisplay(homeTimeLeft); + var adjustedCabinTimeLeft = cabinTimeLeft * ((double)crewCap / (double)numCrew); + + crewCabinString = LifeSupportUtilities.SmartDurationDisplay(adjustedCabinTimeLeft); var secondsPerDay = LifeSupportUtilities.SecondsPerDay(); - if (homeTimeLeft < secondsPerDay * 30) //15 days + if (adjustedCabinTimeLeft < secondsPerDay * 30) { - lblHome = "FFE100"; + lblCabin = "FFE100"; } - if (homeTimeLeft < secondsPerDay * 15) + if (adjustedCabinTimeLeft < secondsPerDay * 15) { - lblHome = "FFAE00"; + lblCabin = "FFAE00"; } } } - HomeLabel = String.Format("{1}", lblHome, crewHomeString); + CabinLabel = String.Format("{1}", lblCabin, crewCabinString); } private string GetRemainingTimeWithGraceLabel(double timeLeft, double graceTime, string graceTimeDisplay, string inGraceTimeMessage, int effectWhenExpires) diff --git a/Source/USILifeSupport/LifeSupportMonitor_Editor.cs b/Source/USILifeSupport/LifeSupportMonitor_Editor.cs index 2069853..a7283e2 100644 --- a/Source/USILifeSupport/LifeSupportMonitor_Editor.cs +++ b/Source/USILifeSupport/LifeSupportMonitor_Editor.cs @@ -127,6 +127,8 @@ private void ResetValues() private string hab_maxCrew = ""; private string supply_curCrew = ""; private string supply_maxCrew = ""; + private string cabin_curCrew = ""; + private string cabin_maxCrew = ""; private string habExt_curCrew = ""; private string habExt_maxCrew = ""; @@ -203,7 +205,7 @@ private void UpdateGUIInfo(ShipConstruct ship) } } - totalHabSpace = (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime * maxCrew) + extraHabTime; + totalHabSpace = extraHabTime; //A Kerbal month is 30 six-hour Kerbin days. totalHabMult = habMult * LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier * LifeSupportUtilities.SecondsPerMonth(); totalBatteryTime = batteryAmount / LifeSupportScenario.Instance.settings.GetSettings().ECAmount; @@ -247,6 +249,17 @@ private void UpdateGUIInfo(ShipConstruct ship) hab_curCrew = LifeSupportUtilities.DurationDisplay(totalHabSpace / Math.Max(1, curCrew) * totalHabMult); hab_maxCrew = LifeSupportUtilities.DurationDisplay(totalHabSpace / Math.Max(1, maxCrew) * totalHabMult); + cabin_curCrew = LifeSupportUtilities.DurationDisplay( + LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime * + LifeSupportUtilities.SecondsPerMonth() * + ((double)maxCrew / (double)Math.Max(1, curCrew)) + ); + cabin_maxCrew = LifeSupportUtilities.DurationDisplay( + LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime * + LifeSupportUtilities.SecondsPerMonth() * + ((double)maxCrew / (double)Math.Max(1, maxCrew)) + ); + supplyExt_curCrew = LifeSupportUtilities.DurationDisplay( (totalSupplyTime + totalFertilizerTime) / Math.Max(1, curCrew) / @@ -364,42 +377,39 @@ private void GenerateWindow() { // column widths const int c1 = 150; - const int c2 = 80; + const int c2 = 90; const int c3 = 80; - const int c4 = 90; - const int c5 = 80; - const int c6 = 50; - const int c7 = 50; + const int c4 = 50; + const int c5 = 50; + const int c6 = 120; GUILayout.BeginHorizontal(); GUILayout.Label("Habitation", _labelStyle, GUILayout.Width(c1 - 30)); - GUILayout.Label(CTag("= ( (", operColor), _labelStyle, GUILayout.Width(30)); - GUILayout.Label("BaseTime " + CTag("*", operColor), _labelStyle, GUILayout.Width(c2)); - GUILayout.Label("MaxCrew " + CTag(") +", operColor), _labelStyle, GUILayout.Width(c3)); - GUILayout.Label("ExtraTime " + CTag(") *", operColor), _labelStyle, GUILayout.Width(c4)); - GUILayout.Label("Multiplier " + CTag("/", operColor), _labelStyle, GUILayout.Width(c5)); - GUILayout.Label("Crew " + CTag("*", operColor), _labelStyle, GUILayout.Width(c6)); - GUILayout.Label("Months", _labelStyle, GUILayout.Width(c7)); + GUILayout.Label(CTag(" = ", operColor), _labelStyle, GUILayout.Width(30)); + GUILayout.Label("ExtraTime " + CTag("*", operColor), _labelStyle, GUILayout.Width(c2)); + GUILayout.Label("Multiplier " + CTag("/", operColor), _labelStyle, GUILayout.Width(c3)); + GUILayout.Label("Crew " + CTag("*", operColor), _labelStyle, GUILayout.Width(c4)); + GUILayout.Label("Months", _labelStyle, GUILayout.Width(c5)); + GUILayout.Label("+CabinTime", _labelStyle, GUILayout.Width(c6)); + GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(CTag(hab_curCrew, textColor), _labelStyle, GUILayout.Width(c1)); - GUILayout.Label(CTag(LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime.ToString(), fadeColor), _labelStyle, GUILayout.Width(c2)); - GUILayout.Label(CTag(maxCrew.ToString(), crewColor), _labelStyle, GUILayout.Width(c3)); - GUILayout.Label(CTag(extraHabTime.ToString(), textColor), _labelStyle, GUILayout.Width(c4)); - GUILayout.Label(CTag("(1+" + (habMult-1d) +")", textColor), _labelStyle, GUILayout.Width(c5)); - GUILayout.Label(CTag(Math.Max(1, curCrew).ToString(), crewColor), _labelStyle, GUILayout.Width(c6)); - GUILayout.Label(CTag(LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier.ToString(), fadeColor), _labelStyle, GUILayout.Width(c7)); + GUILayout.Label(CTag(extraHabTime.ToString(), textColor), _labelStyle, GUILayout.Width(c2)); + GUILayout.Label(CTag("(1+" + (habMult-1d) +")", textColor), _labelStyle, GUILayout.Width(c3)); + GUILayout.Label(CTag(Math.Max(1, curCrew).ToString(), crewColor), _labelStyle, GUILayout.Width(c4)); + GUILayout.Label(CTag(LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier.ToString(), fadeColor), _labelStyle, GUILayout.Width(c5)); + GUILayout.Label(CTag(cabin_curCrew, textColor), _labelStyle, GUILayout.Width(c6)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(CTag(hab_maxCrew, textColor), _labelStyle, GUILayout.Width(c1)); - GUILayout.Label(CTag(LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime.ToString(), fadeColor), _labelStyle, GUILayout.Width(c2)); - GUILayout.Label(CTag(maxCrew.ToString(), crewColor), _labelStyle, GUILayout.Width(c3)); - GUILayout.Label(CTag(extraHabTime.ToString(), textColor), _labelStyle, GUILayout.Width(c4)); - GUILayout.Label(CTag("(1+" + (habMult - 1d) + ")", textColor), _labelStyle, GUILayout.Width(c5)); - GUILayout.Label(CTag(Math.Max(1, maxCrew).ToString(), crewColor), _labelStyle, GUILayout.Width(c6)); - GUILayout.Label(CTag(LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier.ToString(), fadeColor), _labelStyle, GUILayout.Width(c7)); + GUILayout.Label(CTag(extraHabTime.ToString(), textColor), _labelStyle, GUILayout.Width(c2)); + GUILayout.Label(CTag("(1+" + (habMult - 1d) + ")", textColor), _labelStyle, GUILayout.Width(c3)); + GUILayout.Label(CTag(Math.Max(1, maxCrew).ToString(), crewColor), _labelStyle, GUILayout.Width(c4)); + GUILayout.Label(CTag(LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier.ToString(), fadeColor), _labelStyle, GUILayout.Width(c5)); + GUILayout.Label(CTag(cabin_maxCrew, textColor), _labelStyle, GUILayout.Width(c6)); GUILayout.EndHorizontal(); } diff --git a/Source/USILifeSupport/LifeSupportPersistance.cs b/Source/USILifeSupport/LifeSupportPersistance.cs index bf200d9..3e4b8f0 100644 --- a/Source/USILifeSupport/LifeSupportPersistance.cs +++ b/Source/USILifeSupport/LifeSupportPersistance.cs @@ -197,10 +197,9 @@ public void Save(ConfigNode node) rNode.AddValue("LastAtHome", r.LastAtHome); rNode.AddValue("LastSOIChange", r.LastSOIChange); rNode.AddValue("LastPlanet", r.LastPlanet); - rNode.AddValue("MaxOffKerbinTime", r.MaxOffKerbinTime); rNode.AddValue("CurrentVesselId", r.CurrentVesselId); rNode.AddValue("PreviousVesselId", r.PreviousVesselId); - rNode.AddValue("TimeEnteredVessel", r.TimeEnteredVessel); + rNode.AddValue("RemainingCabinTime", r.RemainingCabinTime); rNode.AddValue("IsGrouchy", r.IsGrouchy); rNode.AddValue("OldTrait", r.OldTrait); rNode.AddValue("LastUpdate", r.LastUpdate); @@ -429,10 +428,9 @@ public void SaveStatusNode(LifeSupportStatus status) kerbInfo.LastSOIChange = status.LastSOIChange; kerbInfo.HomeBodyId = status.HomeBodyId; kerbInfo.LastPlanet = status.LastPlanet; - kerbInfo.MaxOffKerbinTime = status.MaxOffKerbinTime; - kerbInfo.TimeEnteredVessel = status.TimeEnteredVessel; kerbInfo.CurrentVesselId = status.CurrentVesselId; kerbInfo.PreviousVesselId = status.PreviousVesselId; + kerbInfo.RemainingCabinTime = status.RemainingCabinTime; kerbInfo.IsGrouchy = status.IsGrouchy; kerbInfo.OldTrait = status.OldTrait; kerbInfo.LastUpdate = status.LastUpdate; diff --git a/Source/USILifeSupport/LifeSupportStatus.cs b/Source/USILifeSupport/LifeSupportStatus.cs index 65a10c1..37dcba0 100644 --- a/Source/USILifeSupport/LifeSupportStatus.cs +++ b/Source/USILifeSupport/LifeSupportStatus.cs @@ -16,5 +16,6 @@ public class LifeSupportStatus public double TimeEnteredVessel { get; set; } public string CurrentVesselId { get; set; } public string PreviousVesselId { get; set; } + public double RemainingCabinTime { get; set; } } } \ No newline at end of file diff --git a/Source/USILifeSupport/ModuleLifeSupportSystem.cs b/Source/USILifeSupport/ModuleLifeSupportSystem.cs index f41d59e..d12f289 100644 --- a/Source/USILifeSupport/ModuleLifeSupportSystem.cs +++ b/Source/USILifeSupport/ModuleLifeSupportSystem.cs @@ -247,29 +247,58 @@ public void FixedUpdate() // Update life support stats if (_isStatusRefreshRequired) { - trackedKerbal.TimeEnteredVessel = now; LifeSupportManager.Instance.TrackKerbal(trackedKerbal); } // Update Hab effects if (!offKerbin || isScout || isHomeWorld || isPermaHab) { - trackedKerbal.TimeEnteredVessel = now; trackedKerbal.LastAtHome = now; - trackedKerbal.MaxOffKerbinTime = habTime + trackedKerbal.LastAtHome; } else { if (vessel.id.ToString() != trackedKerbal.CurrentVesselId) { - if (vessel.id.ToString() != trackedKerbal.PreviousVesselId) - trackedKerbal.TimeEnteredVessel = now; - trackedKerbal.PreviousVesselId = trackedKerbal.CurrentVesselId; trackedKerbal.CurrentVesselId = vessel.id.ToString(); LifeSupportManager.Instance.TrackKerbal(trackedKerbal); } + // Handle cabin time consumption or regeneration... + + var timeSinceUpdate = now - trackedKerbal.LastUpdate; + var timePermittedWithinHab = Math.Max(0, VesselStatus.CachedHabTime - (now - trackedKerbal.LastAtHome)); + + // First regenerate based on the amount of hab time we had left. + if (timePermittedWithinHab > 0) + { + // Count just the remaining hab time if we don't have enough to span the full update + var habTimeCountingTowardsRegen = Math.Min(timeSinceUpdate, timePermittedWithinHab); + // Regenerate + trackedKerbal.RemainingCabinTime += (habTimeCountingTowardsRegen); //TODO: multiply by scaling setting? + // Now cap it before trying to remove any + if (trackedKerbal.RemainingCabinTime > LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime + * LifeSupportUtilities.SecondsPerMonth()) + { + trackedKerbal.RemainingCabinTime = LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime + * LifeSupportUtilities.SecondsPerMonth(); + } + } + + // If we ran out of hab time, any remaining time in the update consumes cabin time. + if (timePermittedWithinHab < timeSinceUpdate) + { + // Consume the remaining amount in cabin time, scaling by seat fraction filled. + // TODO: multiplier-based modifier? + trackedKerbal.RemainingCabinTime -= (timeSinceUpdate - timePermittedWithinHab) + * ((double)VesselStatus.NumCrew / (double)VesselStatus.CrewCap); + // Now cap it so we don't have cabin time going crazy negative when loading a vessel after a while + if (trackedKerbal.RemainingCabinTime < -2) + { + trackedKerbal.RemainingCabinTime = -2; + } + } + isGrouchyHab = CheckHabSideEffects(trackedKerbal); } @@ -377,6 +406,12 @@ private void CheckEVA(Vessel evaKerbal) var kerbal = evaKerbal.GetVesselCrew()[0]; //Check their status. var kerbalStatus = LifeSupportManager.Instance.FetchKerbal(kerbal); + + //Update cabin time while EVA - this won't cause any effects until they board something, which is fine for now + var now = Planetarium.GetUniversalTime(); + kerbalStatus.RemainingCabinTime -= now - kerbalStatus.LastUpdate; + kerbalStatus.LastUpdate = now; + if (evaKerbal.missionTime > LifeSupportScenario.Instance.settings.GetSettings().EVATime) { var effect = LifeSupportManager.GetEVAExcessEffect(kerbalStatus.KerbalName); @@ -707,17 +742,9 @@ private bool CheckIfHomeWorld() private bool CheckHabSideEffects(LifeSupportStatus trackedKerbal) { - var now = Planetarium.GetUniversalTime(); - var habTime = LifeSupportManager.GetTotalHabTime(VesselStatus, vessel); - - if (trackedKerbal.LastAtHome < 1) - trackedKerbal.LastAtHome = now; - if (habTime + trackedKerbal.LastAtHome > trackedKerbal.MaxOffKerbinTime) - trackedKerbal.MaxOffKerbinTime = habTime + trackedKerbal.LastAtHome; - LifeSupportManager.Instance.TrackKerbal(trackedKerbal); - return (now > trackedKerbal.MaxOffKerbinTime || (now - trackedKerbal.TimeEnteredVessel) > habTime); + return (trackedKerbal.RemainingCabinTime < 0); } private bool CheckSupplySideEffects(LifeSupportStatus trackedKerbal) @@ -788,7 +815,7 @@ private void ApplyEffect(LifeSupportStatus trackedKerbal, ProtoCrewMember crewMe case 0: // No effect return; // No need to print case 1: //Grouchy - msg = string.Format("{0} refuses to work {1}", crewMember.name, reason); + msg = string.Format("{0} refuses to work due to {1}", crewMember.name, reason); trackedKerbal.OldTrait = crewMember.experienceTrait.Config.Name; crewMember.type = ProtoCrewMember.KerbalType.Tourist; KerbalRoster.SetExperienceTrait(crewMember, "Tourist"); From 55c4ac09b582ccdd3742648cc9f5e71a5652e656 Mon Sep 17 00:00:00 2001 From: arbsoup Date: Sat, 6 Jul 2024 23:23:17 -0600 Subject: [PATCH 3/9] cabin-time recovery speed multiplier --- .../UmbraSpaceIndustries/LifeSupport/Settings.cfg | 1 + Source/USILifeSupport/LifeSupportConfig.cs | 1 + .../USILifeSupport/LifeSupportMonitor_SpaceCenter.cs | 12 ++++++++++-- Source/USILifeSupport/LifeSupportPersistance.cs | 4 ++++ Source/USILifeSupport/ModuleLifeSupportSystem.cs | 3 ++- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/FOR_RELEASE/GameData/UmbraSpaceIndustries/LifeSupport/Settings.cfg b/FOR_RELEASE/GameData/UmbraSpaceIndustries/LifeSupport/Settings.cfg index 2d4c8f1..6652875 100644 --- a/FOR_RELEASE/GameData/UmbraSpaceIndustries/LifeSupport/Settings.cfg +++ b/FOR_RELEASE/GameData/UmbraSpaceIndustries/LifeSupport/Settings.cfg @@ -20,6 +20,7 @@ LIFE_SUPPORT_SETTINGS BaseHabTime = 0.25 //How long can 1 crew capacity support 1 Kerbal, expressed in Kerbal Months ReplacementPartAmount = 0 //How fast life support equipment and habs 'wears out' HabRange = 150 //How close we need to be to use other vessel's habitation modules and recyclers. + RecoverySpeed = 1 //Rate at which Kerbals recover cabin time while in a habitat (seconds per second) EnableRecyclers = true //Use resource recyclers? Not the same as resource converteres like greenhouses! VetNames = Jebediah,Valentina,Bill,Bob ScoutHabTime = 9180000 diff --git a/Source/USILifeSupport/LifeSupportConfig.cs b/Source/USILifeSupport/LifeSupportConfig.cs index f40ed4d..d7b6590 100644 --- a/Source/USILifeSupport/LifeSupportConfig.cs +++ b/Source/USILifeSupport/LifeSupportConfig.cs @@ -23,6 +23,7 @@ public class LifeSupportConfig public double BaseHabTime { get; set; } public bool EnableRecyclers { get; set; } public double HabRange { get; set; } + public float RecoverySpeed { get; set; } public double ScoutHabTime { get; set; } public double PermaHabTime { get; set; } } diff --git a/Source/USILifeSupport/LifeSupportMonitor_SpaceCenter.cs b/Source/USILifeSupport/LifeSupportMonitor_SpaceCenter.cs index 2b323de..085e072 100644 --- a/Source/USILifeSupport/LifeSupportMonitor_SpaceCenter.cs +++ b/Source/USILifeSupport/LifeSupportMonitor_SpaceCenter.cs @@ -11,7 +11,7 @@ namespace LifeSupport public class LifeSupportMonitor_SpaceCenter : MonoBehaviour { private ApplicationLauncherButton orbLogButton; - private Rect _windowPosition = new Rect(300, 60, 500, 550); + private Rect _windowPosition = new Rect(300, 60, 500, 560); private GUIStyle _windowStyle; private GUIStyle _labelStyle; private GUIStyle _smButtonStyle; @@ -62,6 +62,7 @@ private void GuiOn() habRange = config.HabRange.ToString(); homeAltitude = config.HomeWorldAltitude.ToString(); baseHabTime = config.BaseHabTime.ToString(); + recoverySpeed = config.RecoverySpeed.ToString(); vetNames = config.VetNames; } @@ -123,6 +124,7 @@ private void OnWindow(int windowId) private string habRange; private string homeAltitude; private string baseHabTime; + private string recoverySpeed; private string vetNames; private void GenerateWindow() @@ -220,13 +222,18 @@ private void GenerateWindow() GUILayout.Label("Hab Multiplier:", _labelStyle, GUILayout.Width(c1)); habMulti = GUILayout.TextField(habMulti, 3, GUILayout.Width(c4)); GUILayout.Label("", _labelStyle, GUILayout.Width(c6)); - GUILayout.Label("Hab Months:", _labelStyle, GUILayout.Width(80)); + GUILayout.Label("Cabin Months:", _labelStyle, GUILayout.Width(90)); baseHabTime = GUILayout.TextField(baseHabTime, 10, GUILayout.Width(c4)); GUILayout.Label("", _labelStyle, GUILayout.Width(c6)); GUILayout.Label("Hab Range:", _labelStyle, GUILayout.Width(c7)); habRange = GUILayout.TextField(habRange, 4, GUILayout.Width(c4)); GUILayout.EndHorizontal(); + GUILayout.BeginHorizontal(); + GUILayout.Label("Recovery Speed:", _labelStyle, GUILayout.Width(c1)); + recoverySpeed = GUILayout.TextField(recoverySpeed, 4, GUILayout.Width(c4)); + GUILayout.EndHorizontal(); + GUILayout.BeginHorizontal(); GUILayout.Label("Homeworld Altitude:", _labelStyle, GUILayout.Width(130)); homeAltitude = GUILayout.TextField(homeAltitude, 8, GUILayout.Width(c7)); @@ -286,6 +293,7 @@ private void SaveSettings(LifeSupportConfig config) config.HabRange = SaveDouble(config.HabRange,habRange); config.HomeWorldAltitude = SaveInt(config.HomeWorldAltitude,homeAltitude); config.BaseHabTime = SaveDouble(config.BaseHabTime,baseHabTime); + config.RecoverySpeed = SaveFloat(config.RecoverySpeed,recoverySpeed); config.VetNames = vetNames; LifeSupportScenario.Instance.settings.SaveConfig(config); GuiOff(); diff --git a/Source/USILifeSupport/LifeSupportPersistance.cs b/Source/USILifeSupport/LifeSupportPersistance.cs index 3e4b8f0..ec2bf7c 100644 --- a/Source/USILifeSupport/LifeSupportPersistance.cs +++ b/Source/USILifeSupport/LifeSupportPersistance.cs @@ -88,6 +88,7 @@ private LifeSupportConfig LoadLifeSupportConfig() ScoutHabTime = 9180000, PermaHabTime = 459000000, HabRange = 2000, + RecoverySpeed = 1f, VetNames = "" }; @@ -125,6 +126,7 @@ private LifeSupportConfig LoadLifeSupportConfig() finalSettings.EVAEffectVets = Math.Max(settings.EVAEffectVets, finalSettings.EVAEffectVets); finalSettings.VetNames += settings.VetNames + ","; finalSettings.HabRange = Math.Min(settings.HabRange, finalSettings.HabRange); + finalSettings.RecoverySpeed = Math.Min(settings.RecoverySpeed, finalSettings.RecoverySpeed); if (settings.EnableRecyclers) finalSettings.EnableRecyclers = true; } @@ -257,6 +259,7 @@ public void Save(ConfigNode node) sNode.AddValue("ReplacementPartAmount", _Settings.ReplacementPartAmount); sNode.AddValue("EnableRecyclers", _Settings.EnableRecyclers); sNode.AddValue("HabRange", _Settings.HabRange); + sNode.AddValue("RecoverySpeed", _Settings.RecoverySpeed); sNode.AddValue("VetNames", _Settings.VetNames); SettingsNode.AddNode(sNode); } @@ -399,6 +402,7 @@ public void SaveConfig(LifeSupportConfig config) _Settings.ReplacementPartAmount = config.ReplacementPartAmount; _Settings.EnableRecyclers = config.EnableRecyclers; _Settings.HabRange = config.HabRange; + _Settings.RecoverySpeed = config.RecoverySpeed; _Settings.VetNames = config.VetNames; } diff --git a/Source/USILifeSupport/ModuleLifeSupportSystem.cs b/Source/USILifeSupport/ModuleLifeSupportSystem.cs index d12f289..0fe1f56 100644 --- a/Source/USILifeSupport/ModuleLifeSupportSystem.cs +++ b/Source/USILifeSupport/ModuleLifeSupportSystem.cs @@ -275,7 +275,8 @@ public void FixedUpdate() // Count just the remaining hab time if we don't have enough to span the full update var habTimeCountingTowardsRegen = Math.Min(timeSinceUpdate, timePermittedWithinHab); // Regenerate - trackedKerbal.RemainingCabinTime += (habTimeCountingTowardsRegen); //TODO: multiply by scaling setting? + trackedKerbal.RemainingCabinTime += (habTimeCountingTowardsRegen) * + LifeSupportScenario.Instance.settings.GetSettings().RecoverySpeed; // Now cap it before trying to remove any if (trackedKerbal.RemainingCabinTime > LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime * LifeSupportUtilities.SecondsPerMonth()) From 8c9d90e687033c52edd332e1d8792ddc9ba61adc Mon Sep 17 00:00:00 2001 From: arbsoup Date: Sun, 7 Jul 2024 09:32:50 -0600 Subject: [PATCH 4/9] actually very simple hab-multiplier factoring for cabin time --- Source/USILifeSupport/LifeSupportMonitor.cs | 20 +++++++++---------- .../LifeSupportMonitor_Editor.cs | 6 ++++-- .../USILifeSupport/ModuleLifeSupportSystem.cs | 3 ++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Source/USILifeSupport/LifeSupportMonitor.cs b/Source/USILifeSupport/LifeSupportMonitor.cs index dad1f5c..19a46ea 100644 --- a/Source/USILifeSupport/LifeSupportMonitor.cs +++ b/Source/USILifeSupport/LifeSupportMonitor.cs @@ -192,9 +192,10 @@ private LifeSupportVesselDisplayStat GetVesselStats(VesselSupplyStatus vsl) var numCrew = vsl.NumCrew; var crewCap = vsl.CrewCap; + var vesselHabMultiplier = vsl.VesselHabMultiplier; foreach (var c in thisVessel.GetVesselCrew()) { - var crewStat = GetCrewStat(c, thisVessel, suppliesTimeLeft, ecTimeLeft, ecAmount, habTime, numCrew, crewCap); + var crewStat = GetCrewStat(c, thisVessel, suppliesTimeLeft, ecTimeLeft, ecAmount, habTime, numCrew, crewCap, vesselHabMultiplier); vstat.crew.Add(crewStat); } vstat.crew = vstat.crew.OrderBy(crewStat => crewStat.EarliestExpiration).ToList(); @@ -322,7 +323,7 @@ private string GetSituationString(Vessel vessel) return sitString; } - private LifeSupportCrewDisplayStat GetCrewStat(ProtoCrewMember c, Vessel vessel, double vesselSuppliesTimeLeft, double vesselEcTimeLeft, double vesselEcAmount, double vesselHabTime, int numCrew, int crewCap) + private LifeSupportCrewDisplayStat GetCrewStat(ProtoCrewMember c, Vessel vessel, double vesselSuppliesTimeLeft, double vesselEcTimeLeft, double vesselEcAmount, double vesselHabTime, int numCrew, int crewCap, double vesselHabMultiplier) { var cls = LifeSupportManager.Instance.FetchKerbal(c); //Guard clause in case we just changed vessels @@ -346,7 +347,7 @@ private LifeSupportCrewDisplayStat GetCrewStat(ProtoCrewMember c, Vessel vessel, cStat.ComputeEc(ecTimeLeft, c); cStat.ComputeSupply(vesselSuppliesTimeLeft, c); cStat.ComputeHab(vesselHabTime, c, cls); - cStat.ComputeCabin(c, cls, numCrew, crewCap); + cStat.ComputeCabin(c, cls, numCrew, crewCap, vesselHabMultiplier); LifeSupportManager.Instance.TrackKerbal(cls); return cStat; @@ -455,33 +456,32 @@ internal void ComputeHab(double vesselHabTime, ProtoCrewMember c, LifeSupportSta HabLabel = String.Format("{1}", lblHab, crewHabString); } - internal void ComputeCabin(ProtoCrewMember c, LifeSupportStatus cls, int numCrew, int crewCap) + internal void ComputeCabin(ProtoCrewMember c, LifeSupportStatus cls, int numCrew, int crewCap, double vesselHabMultiplier) { var crewCabinString = "indefinite"; var lblCabin = "6FFF00"; var useHabPenalties = LifeSupportManager.GetNoHomeEffect(c.name) > 0; if (useHabPenalties) { - var cabinTimeLeft = cls.RemainingCabinTime; - UpdateEarliestExpiration(cabinTimeLeft); + var adjustedCabinTimeLeft = cls.RemainingCabinTime * ((double)crewCap / (double)numCrew) * (1 + vesselHabMultiplier); + UpdateEarliestExpiration(adjustedCabinTimeLeft); // Debug.Log(String.Format("{0} has {1} remaining CabinTime", cls.KerbalName, cabinTimeLeft )); - var isScout = c.HasEffect("ExplorerSkill") && cabinTimeLeft >= LifeSupportScenario.Instance.settings.GetSettings().ScoutHabTime; - var isPermaHab = cabinTimeLeft >= LifeSupportScenario.Instance.settings.GetSettings().PermaHabTime; + var isScout = c.HasEffect("ExplorerSkill") && adjustedCabinTimeLeft >= LifeSupportScenario.Instance.settings.GetSettings().ScoutHabTime; + var isPermaHab = adjustedCabinTimeLeft >= LifeSupportScenario.Instance.settings.GetSettings().PermaHabTime; if (isScout || isPermaHab) { crewCabinString = "indefinite"; } - else if (cabinTimeLeft < 0) + else if (adjustedCabinTimeLeft < 0) { lblCabin = "FF5E5E"; crewCabinString = "expired"; } else { - var adjustedCabinTimeLeft = cabinTimeLeft * ((double)crewCap / (double)numCrew); crewCabinString = LifeSupportUtilities.SmartDurationDisplay(adjustedCabinTimeLeft); var secondsPerDay = LifeSupportUtilities.SecondsPerDay(); diff --git a/Source/USILifeSupport/LifeSupportMonitor_Editor.cs b/Source/USILifeSupport/LifeSupportMonitor_Editor.cs index a7283e2..a8c8350 100644 --- a/Source/USILifeSupport/LifeSupportMonitor_Editor.cs +++ b/Source/USILifeSupport/LifeSupportMonitor_Editor.cs @@ -252,12 +252,14 @@ private void UpdateGUIInfo(ShipConstruct ship) cabin_curCrew = LifeSupportUtilities.DurationDisplay( LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime * LifeSupportUtilities.SecondsPerMonth() * - ((double)maxCrew / (double)Math.Max(1, curCrew)) + ((double)maxCrew / (double)Math.Max(1, curCrew)) * + habMult ); cabin_maxCrew = LifeSupportUtilities.DurationDisplay( LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime * LifeSupportUtilities.SecondsPerMonth() * - ((double)maxCrew / (double)Math.Max(1, maxCrew)) + ((double)maxCrew / (double)Math.Max(1, maxCrew)) * + habMult ); supplyExt_curCrew = LifeSupportUtilities.DurationDisplay( diff --git a/Source/USILifeSupport/ModuleLifeSupportSystem.cs b/Source/USILifeSupport/ModuleLifeSupportSystem.cs index 0fe1f56..1572a8d 100644 --- a/Source/USILifeSupport/ModuleLifeSupportSystem.cs +++ b/Source/USILifeSupport/ModuleLifeSupportSystem.cs @@ -292,7 +292,8 @@ public void FixedUpdate() // Consume the remaining amount in cabin time, scaling by seat fraction filled. // TODO: multiplier-based modifier? trackedKerbal.RemainingCabinTime -= (timeSinceUpdate - timePermittedWithinHab) - * ((double)VesselStatus.NumCrew / (double)VesselStatus.CrewCap); + * ((double)VesselStatus.NumCrew / (double)VesselStatus.CrewCap) + * (1.0 / (1 + VesselStatus.VesselHabMultiplier)); // Now cap it so we don't have cabin time going crazy negative when loading a vessel after a while if (trackedKerbal.RemainingCabinTime < -2) { From e65defb1d16402f578bb3657c482c4c1f8aec882 Mon Sep 17 00:00:00 2001 From: arbsoup Date: Sun, 7 Jul 2024 09:54:56 -0600 Subject: [PATCH 5/9] tiny bugfix --- Source/USILifeSupport/ModuleLifeSupportSystem.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/USILifeSupport/ModuleLifeSupportSystem.cs b/Source/USILifeSupport/ModuleLifeSupportSystem.cs index 1572a8d..9d5be00 100644 --- a/Source/USILifeSupport/ModuleLifeSupportSystem.cs +++ b/Source/USILifeSupport/ModuleLifeSupportSystem.cs @@ -289,8 +289,7 @@ public void FixedUpdate() // If we ran out of hab time, any remaining time in the update consumes cabin time. if (timePermittedWithinHab < timeSinceUpdate) { - // Consume the remaining amount in cabin time, scaling by seat fraction filled. - // TODO: multiplier-based modifier? + // Consume the remaining amount in cabin time, scaling by seat fraction filled and multiplier. trackedKerbal.RemainingCabinTime -= (timeSinceUpdate - timePermittedWithinHab) * ((double)VesselStatus.NumCrew / (double)VesselStatus.CrewCap) * (1.0 / (1 + VesselStatus.VesselHabMultiplier)); @@ -412,6 +411,10 @@ private void CheckEVA(Vessel evaKerbal) //Update cabin time while EVA - this won't cause any effects until they board something, which is fine for now var now = Planetarium.GetUniversalTime(); kerbalStatus.RemainingCabinTime -= now - kerbalStatus.LastUpdate; + if (kerbalStatus.RemainingCabinTime < -2) + { + kerbalStatus.RemainingCabinTime = -2; + } kerbalStatus.LastUpdate = now; if (evaKerbal.missionTime > LifeSupportScenario.Instance.settings.GetSettings().EVATime) From 41f3b0755a8eb8baf52a2f242c43d19a817473d2 Mon Sep 17 00:00:00 2001 From: arbsoup Date: Sun, 7 Jul 2024 18:27:59 -0600 Subject: [PATCH 6/9] EVA fully fixed, should be ready to go --- Source/USILifeSupport/LifeSupportMonitor.cs | 29 ++++++++++++++++--- .../USILifeSupport/ModuleLifeSupportSystem.cs | 19 +++++++----- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Source/USILifeSupport/LifeSupportMonitor.cs b/Source/USILifeSupport/LifeSupportMonitor.cs index 19a46ea..ab1c0fe 100644 --- a/Source/USILifeSupport/LifeSupportMonitor.cs +++ b/Source/USILifeSupport/LifeSupportMonitor.cs @@ -109,16 +109,37 @@ private LifeSupportVesselDisplayStat GetEvaKerbalStats(Vessel kerbal) vstat.LastUpdate = kerbal.missionTime; var sitString = "(EVA)"; + var evaKerbal = kerbal.GetVesselCrew()[0]; + var kerbalStatus = LifeSupportManager.Instance.FetchKerbal(evaKerbal); + var cabinTime = kerbalStatus.RemainingCabinTime; + var cabinTimeString = LifeSupportUtilities.SmartDurationDisplay(Math.Max(0, cabinTime)); + var remEVATime = LifeSupportScenario.Instance.settings.GetSettings().EVATime - kerbal.missionTime; var timeString = LifeSupportUtilities.SmartDurationDisplay(Math.Max(0, remEVATime)); + var secondsPerDay = LifeSupportUtilities.SecondsPerDay(); + + + var lblCabin = "6FFF00"; + if (cabinTime < secondsPerDay * 3) + { + lblCabin = "FFE100"; + } + if (cabinTime < secondsPerDay * 1) + { + lblCabin = "FFAE00"; + } + if (remEVATime > 0) { vstat.SummaryLabel = String.Format( - "{0}/{1} - {2} time remaining" + "{0}/{1} - {2} time remaining - " + + "{4} cabin time" , kerbal.mainBody.bodyName , sitString - , timeString); + , timeString + , lblCabin + , cabinTimeString); } else { @@ -485,11 +506,11 @@ internal void ComputeCabin(ProtoCrewMember c, LifeSupportStatus cls, int numCrew crewCabinString = LifeSupportUtilities.SmartDurationDisplay(adjustedCabinTimeLeft); var secondsPerDay = LifeSupportUtilities.SecondsPerDay(); - if (adjustedCabinTimeLeft < secondsPerDay * 30) + if (adjustedCabinTimeLeft < secondsPerDay * 3) { lblCabin = "FFE100"; } - if (adjustedCabinTimeLeft < secondsPerDay * 15) + if (adjustedCabinTimeLeft < secondsPerDay * 1) { lblCabin = "FFAE00"; } diff --git a/Source/USILifeSupport/ModuleLifeSupportSystem.cs b/Source/USILifeSupport/ModuleLifeSupportSystem.cs index 9d5be00..5cb2b3f 100644 --- a/Source/USILifeSupport/ModuleLifeSupportSystem.cs +++ b/Source/USILifeSupport/ModuleLifeSupportSystem.cs @@ -420,7 +420,12 @@ private void CheckEVA(Vessel evaKerbal) if (evaKerbal.missionTime > LifeSupportScenario.Instance.settings.GetSettings().EVATime) { var effect = LifeSupportManager.GetEVAExcessEffect(kerbalStatus.KerbalName); - ApplyEVAEffect(kerbalStatus, kerbal, evaKerbal, effect); + ApplyEVAEffect(kerbalStatus, kerbal, evaKerbal, effect, "excessive EVA time"); + } + else if (kerbalStatus.RemainingCabinTime < 0) + { + var effect = LifeSupportManager.GetNoHomeEffect(kerbalStatus.KerbalName); + ApplyEVAEffect(kerbalStatus, kerbal, evaKerbal, effect, "homesickness"); } } @@ -430,7 +435,7 @@ private bool IsAtHomeForEva(Vessel evaKerbal) (evaKerbal.altitude < LifeSupportScenario.Instance.settings.GetSettings().HomeWorldAltitude); } - private void ApplyEVAEffect(LifeSupportStatus trackedKerbal, ProtoCrewMember crewMember, Vessel vessel, int effectId) + private void ApplyEVAEffect(LifeSupportStatus trackedKerbal, ProtoCrewMember crewMember, Vessel vessel, int effectId, string reason) { if (crewMember.type == ProtoCrewMember.KerbalType.Tourist || crewMember.experienceTrait.Config.Name == "Tourist") return; @@ -452,7 +457,7 @@ private void ApplyEVAEffect(LifeSupportStatus trackedKerbal, ProtoCrewMember cre case 1: //Grouchy if (crewMember.type != ProtoCrewMember.KerbalType.Tourist) { - screenMessage = string.Format("{0} refuses to work", crewMember.name); + screenMessage = string.Format("{0} refuses to work due to {1}", crewMember.name, reason); trackedKerbal.OldTrait = crewMember.experienceTrait.Config.Name; crewMember.type = ProtoCrewMember.KerbalType.Tourist; KerbalRoster.SetExperienceTrait(crewMember, "Tourist"); @@ -462,7 +467,7 @@ private void ApplyEVAEffect(LifeSupportStatus trackedKerbal, ProtoCrewMember cre break; case 2: //Mutinous { - screenMessage = string.Format("{0} has become mutinous", crewMember.name); + screenMessage = string.Format("{0} has become mutinous due to {1}", crewMember.name, reason); trackedKerbal.OldTrait = crewMember.experienceTrait.Config.Name; crewMember.type = ProtoCrewMember.KerbalType.Tourist; KerbalRoster.SetExperienceTrait(crewMember, "Tourist"); @@ -472,19 +477,19 @@ private void ApplyEVAEffect(LifeSupportStatus trackedKerbal, ProtoCrewMember cre } break; case 3: //Return to KSC - screenMessage = string.Format("{0} gets fed up and wanders back to the KSC", crewMember.name); + screenMessage = string.Format("{0} gets fed up and wanders back to the KSC due to {1}", crewMember.name, reason); LifeSupportManager.Instance.UntrackKerbal(crewMember.name); crewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available; DestroyVessel(vessel); break; case 4: //Despawn - screenMessage = string.Format("{0} has gone missing", crewMember.name); + screenMessage = string.Format("{0} has gone missing due to {1}", crewMember.name, reason); LifeSupportManager.Instance.UntrackKerbal(crewMember.name); crewMember.rosterStatus = ProtoCrewMember.RosterStatus.Missing; DestroyVessel(vessel); break; case 5: //Kill - screenMessage = string.Format("{0} has died", crewMember.name); + screenMessage = string.Format("{0} has died due to {1}", crewMember.name, reason); LifeSupportManager.Instance.UntrackKerbal(crewMember.name); crewMember.rosterStatus = ProtoCrewMember.RosterStatus.Dead; DestroyVessel(vessel); From 846dba145c6762dc1f684a51e515907e38dc2807 Mon Sep 17 00:00:00 2001 From: arbsoup Date: Sun, 7 Jul 2024 19:10:06 -0600 Subject: [PATCH 7/9] fix softlock on EVA death --- Source/USILifeSupport/ModuleLifeSupportSystem.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/USILifeSupport/ModuleLifeSupportSystem.cs b/Source/USILifeSupport/ModuleLifeSupportSystem.cs index 5cb2b3f..7f480eb 100644 --- a/Source/USILifeSupport/ModuleLifeSupportSystem.cs +++ b/Source/USILifeSupport/ModuleLifeSupportSystem.cs @@ -473,26 +473,25 @@ private void ApplyEVAEffect(LifeSupportStatus trackedKerbal, ProtoCrewMember cre KerbalRoster.SetExperienceTrait(crewMember, "Tourist"); trackedKerbal.IsGrouchy = true; LifeSupportManager.Instance.TrackKerbal(trackedKerbal); - DestroyRandomPart(vessel); } break; case 3: //Return to KSC screenMessage = string.Format("{0} gets fed up and wanders back to the KSC due to {1}", crewMember.name, reason); LifeSupportManager.Instance.UntrackKerbal(crewMember.name); crewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available; - DestroyVessel(vessel); + vessel.Die(); break; case 4: //Despawn screenMessage = string.Format("{0} has gone missing due to {1}", crewMember.name, reason); LifeSupportManager.Instance.UntrackKerbal(crewMember.name); crewMember.rosterStatus = ProtoCrewMember.RosterStatus.Missing; - DestroyVessel(vessel); + vessel.Die(); break; case 5: //Kill screenMessage = string.Format("{0} has died due to {1}", crewMember.name, reason); LifeSupportManager.Instance.UntrackKerbal(crewMember.name); crewMember.rosterStatus = ProtoCrewMember.RosterStatus.Dead; - DestroyVessel(vessel); + vessel.Die(); break; } From 7d05f1ead51bdaf016fb8b536178b12023dc8d35 Mon Sep 17 00:00:00 2001 From: arbsoup Date: Tue, 16 Jul 2024 20:55:29 -0600 Subject: [PATCH 8/9] bugfix mainly for vessel launch --- Source/USILifeSupport/ModuleLifeSupportSystem.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Source/USILifeSupport/ModuleLifeSupportSystem.cs b/Source/USILifeSupport/ModuleLifeSupportSystem.cs index 7f480eb..b13f23d 100644 --- a/Source/USILifeSupport/ModuleLifeSupportSystem.cs +++ b/Source/USILifeSupport/ModuleLifeSupportSystem.cs @@ -251,6 +251,13 @@ public void FixedUpdate() } // Update Hab effects + + // I guess if you've colonized a planet, Kerbals starting there should get cabin time refills? + if (!offKerbin || isHomeWorld) + { + trackedKerbal.RemainingCabinTime = LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime + * LifeSupportUtilities.SecondsPerMonth(); + } if (!offKerbin || isScout || isHomeWorld || isPermaHab) { trackedKerbal.LastAtHome = now; From 5481815afe53ad97cce902854e89fc59af287f70 Mon Sep 17 00:00:00 2001 From: arbsoup Date: Tue, 16 Jul 2024 22:12:05 -0600 Subject: [PATCH 9/9] "kerbal-months" display fix --- Source/USILifeSupport/Converters/USILS_HabitationSwapOption.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/USILifeSupport/Converters/USILS_HabitationSwapOption.cs b/Source/USILifeSupport/Converters/USILS_HabitationSwapOption.cs index 9f5e21e..ebbe543 100644 --- a/Source/USILifeSupport/Converters/USILS_HabitationSwapOption.cs +++ b/Source/USILifeSupport/Converters/USILS_HabitationSwapOption.cs @@ -33,7 +33,7 @@ public override string GetInfo() var output = new StringBuilder(); output.AppendLine(); output.AppendLine(base.GetInfo()); - output.AppendLine(string.Format("Kerbal-Months: {0}", BaseKerbalMonths + part.CrewCapacity)); + output.AppendLine(string.Format("Kerbal-Months: {0}", BaseKerbalMonths)); output.AppendLine(string.Format("Crew Affected: {0}", CrewCapacity)); output.AppendLine(string.Format("Hab Multipler: {0}", BaseHabMultiplier));