forked from FractalUK/KSPInterstellar
-
Notifications
You must be signed in to change notification settings - Fork 13
/
FNResourceManager.cs
119 lines (106 loc) · 6.08 KB
/
FNResourceManager.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
////extern alias ORSv1_1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using OpenResourceSystem;
namespace InterstellarPlugin {
public class FNResourceManager : ORSResourceManager {
public FNResourceManager(PartModule pm, String resource_name) : base(pm, resource_name) {
windowPosition = new Rect(200, 200, 350, 100);
}
protected override void pluginSpecificImpl() {
if (resource_name == FNRESOURCE_CHARGED_PARTICLES) {
flow_type = FNRESOURCE_FLOWTYPE_EVEN;
}
if (String.Equals(this.resource_name, FNResourceManager.FNRESOURCE_WASTEHEAT)) { // passive dissip of waste heat - a little bit of this
double vessel_mass = my_vessel.GetTotalMass();
double passive_dissip = passive_temp_p4 * GameConstants.stefan_const * vessel_mass * 2.0;
internl_power_extract += passive_dissip * TimeWarp.fixedDeltaTime;
if (my_vessel.altitude <= PluginHelper.getMaxAtmosphericAltitude(my_vessel.mainBody)) { // passive convection - a lot of this
double pressure = FlightGlobals.getStaticPressure(my_vessel.transform.position);
double delta_temp = 20;
double conv_power_dissip = pressure * delta_temp * vessel_mass * 2.0 * GameConstants.rad_const_h / 1e6 * TimeWarp.fixedDeltaTime;
internl_power_extract += conv_power_dissip;
}
if (internl_power_extract < 0 && PluginHelper.isThermalDissipationDisabled()) { // set buildup/dissip of waste heat to 0 if waste heat is disabled
internl_power_extract = 0;
}
}
}
protected override void doWindow(int windowID) {
bold_label = new GUIStyle(GUI.skin.label);
bold_label.fontStyle = FontStyle.Bold;
green_label = new GUIStyle(GUI.skin.label);
green_label.normal.textColor = Color.green;
red_label = new GUIStyle(GUI.skin.label);
red_label.normal.textColor = Color.red;
//right_align = new GUIStyle(GUI.skin.label);
//right_align.alignment = TextAnchor.UpperRight;
GUIStyle net_style;
GUIStyle net_style2;
if (GUI.Button(new Rect(windowPosition.width - 20, 2, 18, 18), "x")) {
render_window = false;
}
GUILayout.Space(2);
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.Label("Theoretical Supply",bold_label, GUILayout.ExpandWidth(true));
GUILayout.Label(getPowerFormatString(stored_stable_supply), GUILayout.ExpandWidth(false), GUILayout.MinWidth(80));
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Current Supply", bold_label, GUILayout.ExpandWidth(true));
GUILayout.Label(getPowerFormatString(stored_supply), GUILayout.ExpandWidth(false), GUILayout.MinWidth(80));
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Power Demand", bold_label, GUILayout.ExpandWidth(true));
GUILayout.Label(getPowerFormatString(stored_resource_demand), GUILayout.ExpandWidth(false), GUILayout.MinWidth(80));
GUILayout.EndHorizontal();
double demand_supply = stored_supply - stored_resource_demand;
double demand_stable_supply = stored_resource_demand / stored_stable_supply;
if (demand_supply < -0.001) {
net_style = red_label;
} else {
net_style = green_label;
}
if (demand_stable_supply > 1) {
net_style2 = red_label;
} else {
net_style2 = green_label;
}
GUILayout.BeginHorizontal();
GUILayout.Label("Net Power", bold_label, GUILayout.ExpandWidth(true));
GUILayout.Label(getPowerFormatString(demand_supply), net_style, GUILayout.ExpandWidth(false), GUILayout.MinWidth(80));
GUILayout.EndHorizontal();
if (!double.IsNaN(demand_stable_supply) && !double.IsInfinity(demand_stable_supply)) {
GUILayout.BeginHorizontal();
GUILayout.Label("Utilisation", bold_label, GUILayout.ExpandWidth(true));
GUILayout.Label((demand_stable_supply).ToString("P3"), net_style2, GUILayout.ExpandWidth(false), GUILayout.MinWidth(80));
GUILayout.EndHorizontal();
}
GUILayout.Space(5);
GUILayout.BeginHorizontal();
GUILayout.Label("Component",bold_label, GUILayout.ExpandWidth(true));
GUILayout.Label("Demand", bold_label, GUILayout.ExpandWidth(false), GUILayout.MinWidth(80));
GUILayout.Label("Priority", bold_label, GUILayout.ExpandWidth(false), GUILayout.MinWidth(50));
GUILayout.EndHorizontal();
if (power_draw_list_archive != null) {
foreach (KeyValuePair<ORSResourceSuppliable, double> power_kvp in power_draw_list_archive) {
GUILayout.BeginHorizontal();
GUILayout.Label(power_kvp.Key.getResourceManagerDisplayName(), GUILayout.ExpandWidth(true));
GUILayout.Label(getPowerFormatString(power_kvp.Value), GUILayout.ExpandWidth(false),GUILayout.MinWidth(80));
GUILayout.Label(power_kvp.Key.getPowerPriority().ToString(), GUILayout.ExpandWidth(false), GUILayout.MinWidth(50));
GUILayout.EndHorizontal();
}
}
GUILayout.BeginHorizontal();
GUILayout.Label("DC Electrical System", GUILayout.ExpandWidth(true));
GUILayout.Label(getPowerFormatString(stored_charge_demand), GUILayout.ExpandWidth(false), GUILayout.MinWidth(80));
GUILayout.Label("0", GUILayout.ExpandWidth(false), GUILayout.MinWidth(50));
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUI.DragWindow();
}
}
}