-
Notifications
You must be signed in to change notification settings - Fork 13
/
PlanetHealthConfig.cs
59 lines (51 loc) · 2.1 KB
/
PlanetHealthConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
namespace KerbalHealth
{
/// <summary>
/// Used for custom configuration of celestial bodies' radiation shielding & emission
/// </summary>
public class PlanetHealthConfig
{
/// <summary>
/// Celestial body name (non-localized)
/// </summary>
public string Name { get; set; }
/// <summary>
/// Returns a reference to CelestialBody
/// </summary>
public CelestialBody CelestialBody => FlightGlobals.GetBodyByName(Name);
/// <summary>
/// Exponential coefficient of amount of radiation blocked by magnetosphere (default = 1)
/// </summary>
public double Magnetosphere { get; set; } = 1;
/// <summary>
/// Exponential coefficient of amount of radiation blocked by the atmosphere (default = 1)
/// </summary>
public double AtmosphericAbsorption { get; set; } = 1;
/// <summary>
/// Natural radiation level at sea level
/// </summary>
public double Radioactivity { get; set; } = 0;
public void Load(ConfigNode node)
{
Name = node.GetString("name");
if (Name == null)
{
Core.Log("Missing 'name' key in body properties definition.", LogLevel.Error);
return;
}
if (CelestialBody == null)
Core.Log($"Body '{Name}' not found.", LogLevel.Important);
Magnetosphere = node.GetDouble("magnetosphere", Magnetosphere);
AtmosphericAbsorption = node.GetDouble("atmosphericAbsorption", AtmosphericAbsorption);
Radioactivity = node.GetDouble("radioactivity", Radioactivity);
}
public PlanetHealthConfig(CelestialBody body)
{
Name = body.bodyName;
Magnetosphere = body.IsPlanet() ? 1 : 0;
}
public PlanetHealthConfig(ConfigNode node) => Load(node);
public override string ToString() =>
$"{Name}\r\nMagnetosphere: {Magnetosphere:F2}\r\nAtmospheric Absorption: {AtmosphericAbsorption:F2}\r\nRadioactivity: {Radioactivity:F0}";
}
}