This repository has been archived by the owner on Sep 17, 2018. It is now read-only.
/
CompSunlight.cs
74 lines (64 loc) · 2.36 KB
/
CompSunlight.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Verse;
namespace ExpandedPower {
/// <summary>
/// Handles sunlight based on weather
/// </summary>
public class CompSunlight : ThingComp {
private WeatherDef weatherDef; // Weather reference
private float sunStrength; // Strength of the sun multiplier, affected by weather
// Used for inspect string weather reporting
private WeatherLight wLight = WeatherLight.None;
/// <summary>
/// Used for determining if the weather is affecting the current sunlight
/// </summary>
public WeatherLight WeatherLight { get { return wLight; } }
/// <summary>
/// Returns 0.0f to 1.0f based on time and weather
/// <para>Requires GetSunlight() to have already been called</para>
/// </summary>
public float SimpleFactoredSunlight { // Final sunlight value based on time and weather, returns cached value
get { return parent.Map.skyManager.CurSkyGlow * sunStrength; }
}
/// <summary>
/// Gets the current sunlight, then returns 0.0f to 1.0f based on time and weather
/// </summary>
public float FactoredSunlight {
get { GetSunlight(); return parent.Map.skyManager.CurSkyGlow * sunStrength; }
}
/// <summary>
/// Updates the sunlight based on weather
/// </summary>
public virtual void GetSunlight() {
// Get the current weather
weatherDef = parent.Map.weatherManager.curWeather;
// Clear weather provides the maximum sunlight
if (weatherDef == ExpDefOf.Clear) {
wLight = WeatherLight.Bright;
sunStrength = 1f;
return;
}
// These weathers provide 60% sunlight
else if (weatherDef == ExpDefOf.Fog ||
weatherDef == ExpDefOf.Rain ||
weatherDef == ExpDefOf.SnowGentle) {
wLight = WeatherLight.Darkened;
sunStrength = 0.6f;
return;
}
// These weathers get only 25% sunlight
else if (weatherDef == ExpDefOf.FoggyRain ||
weatherDef == ExpDefOf.SnowHard ||
weatherDef == ExpDefOf.DryThunderstorm ||
weatherDef == ExpDefOf.RainyThunderstorm) {
wLight = WeatherLight.Dark;
sunStrength = 0.35f;
return;
}
// Default variable. Prevents issues when other mods add custom weather
else {
wLight = WeatherLight.Bright;
sunStrength = 1f;
}
}
}
}