forked from GarwelGarwel/KerbalHealth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlanetHealthConfig.cs
60 lines (52 loc) · 2.23 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
60
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 Body => 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 ConfigNode ConfigNode
{
set
{
Name = Core.GetString(value, "name");
if (Name == null)
{
Core.Log("Missing 'name' key in body properties definition.", Core.LogLevel.Error);
return;
}
if (Body == null) Core.Log("Body '" + Name + "' not found.", Core.LogLevel.Important);
Magnetosphere = Core.GetDouble(value, "magnetosphere", Magnetosphere);
AtmosphericAbsorption = Core.GetDouble(value, "atmosphericAbsorption", AtmosphericAbsorption);
Radioactivity = Core.GetDouble(value, "radioactivity", Radioactivity);
}
}
public override string ToString() => Name + "\r\nMagnetosphere: " + Magnetosphere.ToString("F2") + "\r\nAtmospheric Absorption: " + AtmosphericAbsorption.ToString("F2") + "\r\nRadioactivity: " + Radioactivity.ToString("F0");
public PlanetHealthConfig(CelestialBody body)
{
Name = body.bodyName;
Magnetosphere = Core.IsPlanet(body) ? 1 : 0;
}
public PlanetHealthConfig(ConfigNode node) => ConfigNode = node;
}
}