Skip to content

Commit 737d7a3

Browse files
authored
Merge pull request #150 from GarwelGarwel/dev
v1.5.5
2 parents 222fc15 + 97a8230 commit 737d7a3

38 files changed

Lines changed: 517 additions & 481 deletions

ConditionalEffect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public ConditionalEffect(ConfigNode node)
1313
private ConditionalEffect()
1414
{ }
1515

16-
public bool IsApplicable(KerbalHealthStatus khs) => Logic.Test(khs.PCM);
16+
public bool IsApplicable(KerbalHealthStatus khs) => Logic.Test(khs.ProtoCrewMember);
1717

1818
public override string ToString()
1919
{

Core.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public static class Core
4141
/// <summary>
4242
/// Mod-wide random number generator
4343
/// </summary>
44-
internal static System.Random rand = new System.Random();
44+
internal static System.Random Rand = new System.Random();
45+
46+
static readonly string[] prefixes = { "", "K", "M", "G", "T" };
4547

4648
static List<HealthFactor> factors = new List<HealthFactor>()
4749
{
@@ -62,8 +64,6 @@ public static class Core
6264

6365
static List<double> trainingCaps;
6466

65-
static readonly string[] prefixes = { "", "K", "M", "G", "T" };
66-
6767
/// <summary>
6868
/// List of all tracked kerbals
6969
/// </summary>
@@ -81,7 +81,7 @@ public static List<HealthFactor> Factors
8181
/// <summary>
8282
/// Keeps data about all resources that provide Shielding. Key is resource id, value is amount of shielding provided by 1 unit
8383
/// </summary>
84-
public static Dictionary<int, double> ResourceShielding { get; set; } = new Dictionary<int, double>();
84+
public static Dictionary<int, double> ShieldingResources { get; set; } = new Dictionary<int, double>();
8585

8686
public static List<Quirk> Quirks { get; set; } = new List<Quirk>();
8787

@@ -131,7 +131,7 @@ public static void AddResourceShielding(string name, double shieldingPerTon)
131131
{
132132
PartResourceDefinition prd = PartResourceLibrary.Instance?.GetDefinition(name);
133133
if (prd != null)
134-
ResourceShielding.Add(prd.id, shieldingPerTon * prd.density);
134+
ShieldingResources.Add(prd.id, shieldingPerTon * prd.density);
135135
else Log($"Can't find ResourceDefinition for {name}.");
136136
}
137137

@@ -145,7 +145,7 @@ public static PlanetHealthConfig GetPlanetConfig(string name)
145145

146146
public static RadStormType GetRandomRadStormType()
147147
{
148-
double d = rand.NextDouble() * radStormTypesTotalWeight;
148+
double d = Rand.NextDouble() * radStormTypesTotalWeight;
149149
foreach (RadStormType rst in RadStormTypes)
150150
{
151151
d -= rst.Weight;
@@ -169,10 +169,10 @@ public static void LoadConfig()
169169
HealthConditions.Add(n.GetValue("name"), new HealthCondition(n));
170170
Log($"{HealthConditions.Count} health conditions loaded.", LogLevel.Important);
171171

172-
ResourceShielding = new Dictionary<int, double>();
172+
ShieldingResources = new Dictionary<int, double>();
173173
foreach (ConfigNode n in config.GetNodes("RESOURCE_SHIELDING"))
174174
AddResourceShielding(n.GetValue("name"), n.GetDouble("shielding"));
175-
Log($"{ResourceShielding.Count} resource shielding values loaded.", LogLevel.Important);
175+
Log($"{ShieldingResources.Count} shielding resource values loaded.", LogLevel.Important);
176176

177177
Quirks = new List<Quirk>(config.GetNodes("HEALTH_QUIRK").Select(n => new Quirk(n)));
178178
Log($"{Quirks.Count} quirks loaded.", LogLevel.Important);
@@ -209,9 +209,9 @@ public static void LoadConfig()
209209

210210
trainingCaps = new List<double>(3)
211211
{
212-
0.6,
213-
0.75,
214-
0.85
212+
0.6,
213+
0.75,
214+
0.85
215215
};
216216
foreach (ConfigNode n in config.GetNodes("TRAINING_CAPS"))
217217
{
@@ -226,11 +226,11 @@ public static void LoadConfig()
226226

227227
public static IList<ProtoCrewMember> GetCrew(ProtoCrewMember pcm, bool entireVessel)
228228
{
229+
Vessel vessel = pcm.GetVessel();
229230
if (!entireVessel && CLS.Enabled && pcm.rosterStatus == ProtoCrewMember.RosterStatus.Assigned)
230-
return pcm.GetCLSSpace().GetCrew().ToList();
231+
return pcm.GetCLSSpace(vessel).GetCrew().ToList();
231232
if (IsInEditor)
232233
return ShipConstruction.ShipManifest.GetAllCrew(false);
233-
Vessel vessel = pcm.GetVessel();
234234
return vessel != null ? vessel.GetVesselCrew() : new List<ProtoCrewMember>();
235235
}
236236

@@ -242,11 +242,11 @@ public static IList<ProtoCrewMember> GetCrew(ProtoCrewMember pcm, bool entireVes
242242
/// <returns></returns>
243243
public static int GetCrewCount(ProtoCrewMember pcm, bool entireVessel)
244244
{
245+
Vessel vessel = pcm.GetVessel();
245246
if (!entireVessel && CLS.Enabled)
246-
return pcm.GetCLSSpace().GetCrewCount();
247+
return pcm.GetCLSSpace(vessel).GetCrewCount();
247248
if (IsInEditor)
248249
return ShipConstruction.ShipManifest.CrewCount;
249-
Vessel vessel = pcm.GetVessel();
250250
return vessel != null ? vessel.GetCrewCount() : 1;
251251
}
252252

@@ -362,7 +362,7 @@ public static bool GetBool(this ConfigNode n, string key, bool defaultValue = fa
362362
/// <param name="stdDev"></param>
363363
/// <returns></returns>
364364
public static double GetGaussian(double stdDev = 1, double mean = 0) =>
365-
mean + stdDev * Math.Sqrt(-2 * Math.Log(1 - rand.NextDouble())) * Math.Sin(2 * Math.PI * (1 - rand.NextDouble()));
365+
mean + stdDev * Math.Sqrt(-2 * Math.Log(1 - Rand.NextDouble())) * Math.Sin(2 * Math.PI * (1 - Rand.NextDouble()));
366366

367367
/// <summary>
368368
/// Returns a string of a value with a mandatory sign (+ or -, unless v = 0)

Factors/ConfinementFactor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ public class ConfinementFactor : HealthFactor
1616
public override double ChangePerDay(KerbalHealthStatus khs)
1717
=> (Core.IsInEditor && !IsEnabledInEditor()) || (!Core.IsInEditor && khs.IsOnEVA)
1818
? 0
19-
: BaseChangePerDay * Core.GetCrewCount(khs.PCM, false) / Math.Max(khs.HealthEffects.Space, 0.1);
19+
: BaseChangePerDay * Core.GetCrewCount(khs.ProtoCrewMember, false) / Math.Max(khs.HealthEffects.Space, 0.1);
2020
}
2121
}

Factors/ConnectedFactor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public override double ChangePerDay(KerbalHealthStatus khs)
1414
{
1515
if (Core.IsInEditor)
1616
return IsEnabledInEditor() ? BaseChangePerDay : 0;
17-
Vessel v = khs.PCM.GetVessel();
17+
Vessel v = khs.ProtoCrewMember.GetVessel();
1818
return (v.loaded && v.Connection != null && v.Connection.IsConnectedHome)
1919
? BaseChangePerDay
2020
: 0;

Factors/HomeFactor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public override double ChangePerDay(KerbalHealthStatus khs)
1616
{
1717
if (Core.IsInEditor)
1818
return IsEnabledInEditor() ? BaseChangePerDay : 0;
19-
if (khs.PCM.rosterStatus != ProtoCrewMember.RosterStatus.Assigned)
19+
if (khs.ProtoCrewMember.rosterStatus != ProtoCrewMember.RosterStatus.Assigned)
2020
{
2121
Core.Log("Home factor is off when the kerbal is not assigned.");
2222
return 0;
2323
}
24-
Vessel vessel = khs.PCM.GetVessel();
24+
Vessel vessel = khs.ProtoCrewMember.GetVessel();
2525
CelestialBody body = vessel?.mainBody;
2626
if (body == null)
2727
{

Factors/KSCFactor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public override double ChangePerDay(KerbalHealthStatus khs)
1818
{
1919
if (Core.IsInEditor)
2020
return IsEnabledInEditor() ? BaseChangePerDay : 0;
21-
return (khs.PCM.rosterStatus == ProtoCrewMember.RosterStatus.Available) ? BaseChangePerDay : 0;
21+
return (khs.ProtoCrewMember.rosterStatus == ProtoCrewMember.RosterStatus.Available) ? BaseChangePerDay : 0;
2222
}
2323
}
2424
}

Factors/LonelinessFactor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public override double ChangePerDay(KerbalHealthStatus khs)
1414
{
1515
if (Core.IsInEditor && !IsEnabledInEditor())
1616
return 0;
17-
return Core.GetCrewCount(khs.PCM, true) == 1 && !khs.PCM.isBadass ? BaseChangePerDay : 0;
17+
return Core.GetCrewCount(khs.ProtoCrewMember, true) == 1 && !khs.ProtoCrewMember.isBadass ? BaseChangePerDay : 0;
1818
}
1919
}
2020
}

Factors/MicrogravityFactor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public override double ChangePerDay(KerbalHealthStatus khs)
1414
{
1515
if (Core.IsInEditor)
1616
return IsEnabledInEditor() ? BaseChangePerDay : 0;
17-
Vessel vessel = khs.PCM.GetVessel();
17+
Vessel vessel = khs.ProtoCrewMember.GetVessel();
1818
if (vessel == null)
1919
{
2020
Core.Log($"MicrogravityFactor.ChangePerDay: Core.GetVessel(pcm) is null for {khs.Name}! EVA is {khs.IsOnEVA}.", LogLevel.Error);
@@ -25,12 +25,12 @@ public override double ChangePerDay(KerbalHealthStatus khs)
2525
Core.Log($"Microgravity is on due to being in a {vessel.situation} situation.");
2626
return BaseChangePerDay;
2727
}
28-
if (khs.PCM.geeForce < 0.1)
28+
if (khs.ProtoCrewMember.geeForce < 0.1)
2929
{
30-
Core.Log($"Microgravity is on due to g = {khs.PCM.geeForce:F2}.");
30+
Core.Log($"Microgravity is on due to g = {khs.ProtoCrewMember.geeForce:F2}.");
3131
return BaseChangePerDay;
3232
}
33-
Core.Log($"Microgravity is off, g = {khs.PCM.geeForce:F2}.");
33+
Core.Log($"Microgravity is off, g = {khs.ProtoCrewMember.geeForce:F2}.");
3434
return 0;
3535
}
3636
}

Factors/StressFactor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override double ChangePerDay(KerbalHealthStatus khs)
2727
? BaseChangePerDay * (1 - Core.TrainingCap)
2828
: BaseChangePerDay;
2929
else return 0;
30-
return khs.PCM.rosterStatus == ProtoCrewMember.RosterStatus.Assigned ? ChangePerDayActual(khs) : 0;
30+
return khs.ProtoCrewMember.rosterStatus == ProtoCrewMember.RosterStatus.Assigned ? ChangePerDayActual(khs) : 0;
3131
}
3232
}
3333
}
1 KB
Binary file not shown.

0 commit comments

Comments
 (0)