Skip to content

Commit

Permalink
Improve Healing of Kerbals when their hab and home timers are expired
Browse files Browse the repository at this point in the history
- In addition to healing tourists, Kerbals now also get healed when their LastAtHome or TimeEnteredVessel lie in the past (fix inability of healing Kerbals with expired timers)
- For adjusting the home-timer, additionally LastAtHome gets adjusted (to keep the difference between MaxOffKerbinTime and LastAtHome always the same at TotalHabTime of the vessel)
- Show the overtime in LifeSupportMonitor for expired hab and home timers, which helps with estimating the time needed for healing them (QoL improvement)
  • Loading branch information
mhoram-kerbin committed Sep 16, 2022
1 parent c842b85 commit a29f1f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,21 @@ public override void PostProcess(ConverterResults result, double deltaTime)

base.PostProcess(result, deltaTime);
var baseTime = TimeMultiplier * result.TimeFactor;
var kerbals = new List<ProtoCrewMember>();
var kerbals = new List<LifeSupportStatus>();
var crew = Converter.vessel.GetVesselCrew();
if (AffectsPartOnly)
crew = Converter.part.protoModuleCrew;

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)
Expand All @@ -59,12 +63,31 @@ 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;
}
}
if (AffectsHabTimer)
{
lsKerbal.TimeEnteredVessel += timePerKerbal;
if (lsKerbal.TimeEnteredVessel > now)
lsKerbal.TimeEnteredVessel = now;
}

LifeSupportManager.Instance.TrackKerbal(lsKerbal);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/USILifeSupport/LifeSupportMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit a29f1f1

Please sign in to comment.