diff --git a/Source/USILifeSupport/Converters/USILS_LifeSupportExtenderConverterAddon.cs b/Source/USILifeSupport/Converters/USILS_LifeSupportExtenderConverterAddon.cs index b4f3be8..2bf7069 100644 --- a/Source/USILifeSupport/Converters/USILS_LifeSupportExtenderConverterAddon.cs +++ b/Source/USILifeSupport/Converters/USILS_LifeSupportExtenderConverterAddon.cs @@ -38,17 +38,26 @@ public override void PostProcess(ConverterResults result, double deltaTime) base.PostProcess(result, deltaTime); var baseTime = TimeMultiplier * result.TimeFactor; - var kerbals = new List(); + var kerbals = new List(); var crew = Converter.vessel.GetVesselCrew(); if (AffectsPartOnly) crew = Converter.part.protoModuleCrew; + var moduleLifeSupportSystem = Converter.vessel.FindVesselModuleImplementing(); + var habTime = -1.0d; + if (moduleLifeSupportSystem != null) + habTime = LifeSupportManager.GetTotalHabTime(moduleLifeSupportSystem.VesselStatus, Converter.vessel); + + var now = Planetarium.GetUniversalTime(); var count = crew.Count; for (int i = 0; i < count; ++i) { var c = crew[i]; - if (string.IsNullOrEmpty(RestrictedToClass) || c.experienceTrait.Config.Name == RestrictedToClass) - kerbals.Add(c); + var lsKerbal = LifeSupportManager.Instance.FetchKerbal(c); + + // Kerbals get healed either when they are tourists or when their LastAtHome or TimeEnteredVessel lie in the past + if (string.IsNullOrEmpty(RestrictedToClass) || c.experienceTrait.Config.Name == RestrictedToClass || lsKerbal.LastAtHome < now || lsKerbal.TimeEnteredVessel < now) + kerbals.Add(lsKerbal); } if (kerbals.Count == 0) @@ -59,12 +68,35 @@ public override void PostProcess(ConverterResults result, double deltaTime) count = kerbals.Count; for (int i = 0; i < count; ++i) { - var k = kerbals[i]; - var lsKerbal = LifeSupportManager.Instance.FetchKerbal(k); + var lsKerbal = kerbals[i]; if (AffectsHomeTimer) - lsKerbal.MaxOffKerbinTime += timePerKerbal; + { + // Calculate time adjustment value + var delta = timePerKerbal; + if (now - lsKerbal.LastAtHome > 0 && now - lsKerbal.LastAtHome < delta) + delta = now - lsKerbal.LastAtHome; + + // Adjust both values, that are responsible for the home timer and keep their interval (TotalHabTime of vessel) the same + lsKerbal.MaxOffKerbinTime += delta; + lsKerbal.LastAtHome += delta; + + // make sure that LastAtHome is not in the future + if (lsKerbal.LastAtHome > now) + { + lsKerbal.MaxOffKerbinTime -= lsKerbal.LastAtHome - now; + lsKerbal.LastAtHome = now; + } + + // make sure that MaxOffKerbinTime is not too far in the future, but adjusted to the habTime of the current vessel + if (habTime > 0.0f && now + habTime < lsKerbal.MaxOffKerbinTime) + lsKerbal.MaxOffKerbinTime = now + habTime; + } if (AffectsHabTimer) + { lsKerbal.TimeEnteredVessel += timePerKerbal; + if (lsKerbal.TimeEnteredVessel > now) + lsKerbal.TimeEnteredVessel = now; + } LifeSupportManager.Instance.TrackKerbal(lsKerbal); } diff --git a/Source/USILifeSupport/LifeSupportMonitor.cs b/Source/USILifeSupport/LifeSupportMonitor.cs index 067b082..ce9f25b 100644 --- a/Source/USILifeSupport/LifeSupportMonitor.cs +++ b/Source/USILifeSupport/LifeSupportMonitor.cs @@ -435,7 +435,7 @@ internal void ComputeHab(double vesselHabTime, ProtoCrewMember c, LifeSupportSta else if (habTimeLeft < 0) { lblHab = "FF5E5E"; - crewHabString = "expired"; + crewHabString = "expired (" + LifeSupportUtilities.SmartDurationDisplay(-habTimeLeft) + ")"; } else { @@ -474,7 +474,7 @@ internal void ComputeHome(ProtoCrewMember c, LifeSupportStatus cls) else if (homeTimeLeft < 0) { lblHome = "FF5E5E"; - crewHomeString = "expired"; + crewHomeString = "expired (" + LifeSupportUtilities.SmartDurationDisplay(-homeTimeLeft) + ")"; } else {