Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Healing of Kerbals when their hab and home timers are expired #315

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProtoCrewMember>();
var kerbals = new List<LifeSupportStatus>();
var crew = Converter.vessel.GetVesselCrew();
if (AffectsPartOnly)
crew = Converter.part.protoModuleCrew;

var moduleLifeSupportSystem = Converter.vessel.FindVesselModuleImplementing<ModuleLifeSupportSystem>();
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)
Expand All @@ -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);
}
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