Skip to content

Commit 9112694

Browse files
authored
Merge pull request #69 from GarwelGarwel/dev
1.3.1 update
2 parents c7884c1 + 3e5441c commit 9112694

10 files changed

Lines changed: 80 additions & 14 deletions

Core.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,24 @@ public static bool GetBool(ConfigNode n, string key, bool defaultValue = false)
496496
/// <returns></returns>
497497
public static string SignValue(double v, string format) => ((v > 0) ? "+" : "") + v.ToString(format);
498498

499+
static string[] prefixes = { "", "K", "M", "G", "T" };
500+
501+
/// <summary>
502+
/// Converts a number into a string with a multiplicative character (K, M, G or T), if applicable
503+
/// </summary>
504+
/// <param name="value">The value to convert</param>
505+
/// <param name="allowedDigits">Max number of digits to allow before the prefix (must be 3 or more)</param>
506+
/// <returns></returns>
507+
public static string PrefixFormat(double value, int allowedDigits = 3, bool mandatorySign = false)
508+
{
509+
double v = Math.Abs(value);
510+
if (v < 0.5) return "0";
511+
int n, m = (int)Math.Pow(10, allowedDigits);
512+
for (n = 0; (v >= m) && (n < prefixes.Length - 1); n++)
513+
v /= 1000;
514+
return (value < 0 ? "-" : (mandatorySign ? "+" : "")) + v.ToString("N0") + prefixes[n];
515+
}
516+
499517
/// <summary>
500518
/// Returns the number of occurences of a character in a string
501519
/// </summary>

GameData/KerbalHealth/KerbalHealth.cfg

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// Do NOT delete the two conditions below (Exhausted and Frozen). They are hard-coded and needed for Kerbal Health to function
1+
//// HEALTH CONDITIONS ////
2+
3+
// Do NOT delete the two conditions below (Exhausted and Frozen). They are hard-coded and needed for Kerbal Health to function
24

35
HEALTH_CONDITION
46
{
@@ -261,6 +263,8 @@ HEALTH_CONDITION
261263
}
262264
}
263265
266+
//// RADIATION SHIELDING ////
267+
264268
RESOURCE_SHIELDING
265269
{
266270
name = RadiationShielding
@@ -297,6 +301,8 @@ RESOURCE_SHIELDING
297301
shielding = 0.5
298302
}
299303
304+
//// QUIRKS ////
305+
300306
HEALTH_QUIRK
301307
{
302308
name = Acrobat
@@ -539,6 +545,8 @@ HEALTH_QUIRK
539545
}
540546
}
541547

548+
//// CUSTOM COFIGS FOR CELESTIAL BODIES ////
549+
542550
PLANET_HEALTH_CONFIG
543551
{
544552
name = Eve
@@ -577,16 +585,37 @@ PLANET_HEALTH_CONFIG
577585
magnetosphere = 0.2
578586
}
579587

588+
// OPM configs
589+
580590
PLANET_HEALTH_CONFIG
581591
{
582592
name = Sarnus
583593
magnetosphere = 2
584594
}
585595

596+
PLANET_HEALTH_CONFIG
597+
{
598+
name = Hale
599+
magnetosphere = 0.2
600+
}
601+
586602
PLANET_HEALTH_CONFIG
587603
{
588604
name = Slate
589-
magnetosphere = 0.25
605+
magnetosphere = 0.5
606+
}
607+
608+
PLANET_HEALTH_CONFIG
609+
{
610+
name = Tekto
611+
atmosphericAbsorption = 1.5
612+
}
613+
614+
PLANET_HEALTH_CONFIG
615+
{
616+
name = Thatmo
617+
atmosphericAbsorption = 0.25
618+
radioactivity = 1000
590619
}
591620

592621
PLANET_HEALTH_CONFIG
512 Bytes
Binary file not shown.

GameData/KerbalHealth/KerbalHealth.version

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
"VERSION": {
66
"MAJOR": 1,
77
"MINOR": 3,
8-
"PATCH": 0,
8+
"PATCH": 1,
99
"BUILD": 0
1010
},
1111
"KSP_VERSION": {
1212
"MAJOR": 1,
13-
"MINOR": 4,
14-
"PATCH": 5
13+
"MINOR": 5,
14+
"PATCH": 0
1515
},
1616
"KSP_VERSION_MIN": {
1717
"MAJOR": 1,
18-
"MINOR": 4,
18+
"MINOR": 5,
1919
"PATCH": 0
2020
},
2121
"GITHUB": {

GameData/KerbalHealth/Patches/General.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@PART[*]:HAS[#CrewCapacity[>0],!MODULE[ModuleKerbalHealth],!MODULE[KerbalSeat]]:AFTER[KerbalHealth]
1+
@PART[*]:HAS[#CrewCapacity[>0],!MODULE[ModuleKerbalHealth],!MODULE[KerbalSeat]]:FINAL
22
{
33
MODULE
44
{
@@ -7,7 +7,7 @@
77
}
88
}
99

10-
@PART[*]:HAS[#CrewCapacity[>0],~name[*Cockpit*],~name[Cockpit*],~name[*Cockpit],~name[*cupola*],~name[cupola*],~name[*cupola],~name[cupola],!RESOURCE[RadiationShielding],!MODULE[KerbalSeat]]:AFTER[KerbalHealth]
10+
@PART[*]:HAS[#CrewCapacity[>0],~name[*Cockpit*],~name[Cockpit*],~name[*Cockpit],~name[*cupola*],~name[cupola*],~name[*cupola],~name[cupola],!RESOURCE[RadiationShielding],!MODULE[KerbalSeat]]:FINAL
1111
{
1212
RESOURCE
1313
{

KerbalHealthScenario.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ public void Update()
491491
gridContents[(i + 1) * colNumMain + 3].SetOptionText(formatTag + (100 * khs.Health).ToString("F2") + "% (" + khs.HP.ToString("F2") + ")" + formatUntag);
492492
gridContents[(i + 1) * colNumMain + 4].SetOptionText(formatTag + ((frozen || (khs.Health >= 1)) ? "—" : (((ch > 0) ? "+" : "") + ch.ToString("F2"))) + formatUntag);
493493
gridContents[(i + 1) * colNumMain + 5].SetOptionText(formatTag + s + formatUntag);
494-
gridContents[(i + 1) * colNumMain + 6].SetOptionText(formatTag + khs.Dose.ToString("N0") + (khs.Radiation != 0 ? " (+" + khs.Radiation.ToString("N0") + "/day)" : "") + formatUntag);
494+
gridContents[(i + 1) * colNumMain + 6].SetOptionText(formatTag + Core.PrefixFormat(khs.Dose, 5) + (khs.Radiation != 0 ? " (" + Core.PrefixFormat(khs.Radiation, 4, true) + "/day)" : "") + formatUntag);
495+
//gridContents[(i + 1) * colNumMain + 6].SetOptionText(formatTag + khs.Dose.ToString("N0") + (khs.Radiation != 0 ? " (+" + khs.Radiation.ToString("N0") + "/day)" : "") + formatUntag);
495496
}
496497
}
497498
else // Showing details for one particular kerbal

KerbalHealthStatus.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,22 @@ public static double GetCosmicRadiation(Vessel v)
582582
cosmicRadiationRate *= occlusionCoefficient;
583583
}
584584
else distanceToSun = v.altitude + Sun.Instance.sun.Radius;
585+
double naturalRadiation = Core.PlanetConfigs[v.mainBody].Radioactivity * Core.Sqr(v.mainBody.Radius / (v.mainBody.Radius + v.altitude));
585586
Core.Log("Solar Radiation Quoficient = " + cosmicRadiationRate);
586587
Core.Log("Distance to Sun = " + distanceToSun + " (" + (distanceToSun / FlightGlobals.GetHomeBody().orbit.radius) + " AU)");
587588
Core.Log("Nominal Solar Radiation @ Vessel's Location = " + GetSolarRadiationAtDistance(distanceToSun));
588589
Core.Log("Nominal Galactic Radiation = " + Core.GalacticRadiation);
589-
return cosmicRadiationRate * (GetSolarRadiationAtDistance(distanceToSun) + Core.GalacticRadiation);
590+
Core.Log("Body's natural radiation = " + naturalRadiation);
591+
return cosmicRadiationRate * (GetSolarRadiationAtDistance(distanceToSun) + Core.GalacticRadiation) + naturalRadiation;
590592
}
591593

594+
/// <summary>
595+
/// Body-emitted radiation reaching the given vessel
596+
/// </summary>
597+
/// <param name="v"></param>
598+
/// <returns></returns>
599+
public static double GetNaturalRadiation(Vessel v) => Core.PlanetConfigs[v.mainBody].Radioactivity * Core.Sqr(v.mainBody.Radius / (v.mainBody.Radius + v.altitude));
600+
592601
#endregion
593602
#region HEALTH UPDATE
594603

ModuleHealthEnvironmentSensor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public override void OnStart(StartState state)
1717
case "radiation":
1818
Fields["displayData"].guiName = "Radiation";
1919
Fields["displayData"].guiUnits = "/day";
20-
Fields["displayData"].guiFormat = "F0";
20+
Fields["displayData"].guiFormat = "N0";
2121
break;
2222
case "magnetosphere":
2323
Fields["displayData"].guiName = "Magnetosphere Shielding";

PlanetHealthConfig.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
namespace KerbalHealth
22
{
3+
/// <summary>
4+
/// Used for custom configuration of celestial bodies' radiation shielding & emission
5+
/// </summary>
36
public class PlanetHealthConfig
47
{
58
/// <summary>
@@ -22,6 +25,11 @@ public class PlanetHealthConfig
2225
/// </summary>
2326
public double AtmosphericAbsorption { get; set; } = 1;
2427

28+
/// <summary>
29+
/// Natural radiation level at sea level
30+
/// </summary>
31+
public double Radioactivity { get; set; } = 0;
32+
2533
public ConfigNode ConfigNode
2634
{
2735
set
@@ -35,10 +43,11 @@ public ConfigNode ConfigNode
3543
if (Body == null) Core.Log("Body '" + Name + "' not found.", Core.LogLevel.Important);
3644
Magnetosphere = Core.GetDouble(value, "magnetosphere", Magnetosphere);
3745
AtmosphericAbsorption = Core.GetDouble(value, "atmosphericAbsorption", AtmosphericAbsorption);
46+
Radioactivity = Core.GetDouble(value, "radioactivity", Radioactivity);
3847
}
3948
}
4049

41-
public override string ToString() => Name + "\r\nMagnetosphere: " + Magnetosphere.ToString("F2") + "\r\nAtmospheric Absorption: " + AtmosphericAbsorption.ToString("F2");
50+
public override string ToString() => Name + "\r\nMagnetosphere: " + Magnetosphere.ToString("F2") + "\r\nAtmospheric Absorption: " + AtmosphericAbsorption.ToString("F2") + "\r\nRadioactivity: " + Radioactivity.ToString("F0");
4251

4352
public PlanetHealthConfig(CelestialBody body)
4453
{

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
// You can specify all the values or you can default the Build and Revision Numbers
3434
// by using the '*' as shown below:
3535
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("1.3.0.0")]
37-
[assembly: AssemblyFileVersion("1.3.0.0")]
36+
[assembly: AssemblyVersion("1.3.1.0")]
37+
[assembly: AssemblyFileVersion("1.3.1.0")]
3838
[assembly: NeutralResourcesLanguage("en")]
3939

0 commit comments

Comments
 (0)