Skip to content

Commit 291af6e

Browse files
authored
Merge pull request #127 from GarwelGarwel/dev
Fixed error when calculating training level
2 parents 611d997 + f9780cb commit 291af6e

4 files changed

Lines changed: 6 additions & 9 deletions

File tree

Core.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public static string GetString(this ConfigNode n, string key, string defaultValu
321321
n.HasValue(key) ? n.GetValue(key) : defaultValue;
322322

323323
public static double GetDouble(this ConfigNode n, string key, double defaultValue = 0) =>
324-
double.TryParse(n.GetValue(key), out double res) ? res : defaultValue;
324+
double.TryParse(n.GetValue(key), out double res) && !double.IsNaN(res) ? res : defaultValue;
325325

326326
public static int GetInt(this ConfigNode n, string key, int defaultValue = 0) =>
327327
int.TryParse(n.GetValue(key), out int res) ? res : defaultValue;

Factors/ConditionsFactor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public override double ChangePerDay(ProtoCrewMember pcm)
2525
double res = 0;
2626
foreach (HealthCondition hc in khs.Conditions)
2727
res += hc.HPChangePerDay * KerbalHealthQuirkSettings.Instance.ConditionsEffect;
28-
Core.Log($"Conditions HP chande per day: {res}");
28+
Core.Log($"Conditions HP change per day: {res}");
2929
return Core.IsInEditor ? (IsEnabledInEditor() ? res : 0) : res;
3030
}
3131
}
0 Bytes
Binary file not shown.

KerbalHealthStatus.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ public double TrainingLevel
466466
{
467467
double totalTraining = TrainingFor.Sum(tp => TrainingLevels[tp.Id] * tp.Complexity);
468468
double totalComplexity = TrainingFor.Sum(tp => tp.Complexity);
469-
totalTraining = Math.Min(totalTraining / totalComplexity, Core.TrainingCap);
469+
totalTraining = (totalComplexity != 0) ? totalTraining / totalComplexity : Core.TrainingCap;
470470
if (TrainingVessel != null)
471471
TrainedVessels[TrainingVessel] = totalTraining;
472472
return totalTraining;
@@ -960,12 +960,9 @@ public double HealthChangePerDay()
960960
int crewCount = Core.GetCrewCount(pcm);
961961
foreach (HealthFactor f in Core.Factors.Where(f => recalculateCache || !f.Cachable))
962962
{
963-
double c = f.ChangePerDay(pcm) * mods.GetMultiplier(f.Name, crewCount) * mods.GetMultiplier("All", crewCount);
964-
if (Core.IsLogging())
965-
{
966-
Core.Log($"Multiplier for {f.Name} is {mods.GetMultiplier(f.Name, crewCount)} * {mods.FreeMultipliers[f.Name]} (bonus sum: {mods.BonusSums[f.Name]}; multipliers: {mods.MinMultipliers[f.Name]}..{mods.MaxMultipliers[f.Name]})");
967-
Core.Log($"{f.Name}'s effect on {Name} is {c} HP/day.");
968-
}
963+
double baseChange = f.ChangePerDay(pcm), factorMultiplier = mods.GetMultiplier(f.Name, crewCount), freeMultiplier = mods.GetMultiplier("All", crewCount);
964+
double c = baseChange * factorMultiplier * freeMultiplier;
965+
Core.Log($"{f.Name}'s effect on {Name}: {c:D2} = {baseChange:D2} * {factorMultiplier} * {freeMultiplier}");
969966
Factors[f.Name] = c;
970967
if (f.Cachable)
971968
CachedChange += c;

0 commit comments

Comments
 (0)