-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPropellantCombinationConfig.cs
More file actions
183 lines (160 loc) · 6.47 KB
/
PropellantCombinationConfig.cs
File metadata and controls
183 lines (160 loc) · 6.47 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
using System.Collections.Generic;
namespace Ignition
{
public class PropellantCombinationConfig : PropellantConfigBase
{
private double TotalPropellantRatio
{
get
{
var totalRatio = 0.0;
foreach (var propellant in Propellants)
{
if (propellant.ignoreForIsp) continue;
totalRatio += propellant.ratio;
}
return totalRatio;
}
}
private double _thrustMultiplier = 0;
public override double ThrustMultiplier
{
get
{
if (_thrustMultiplier == 0 && TotalPropellantRatio > 0)
{
_thrustMultiplier = 1;
foreach (var propellant in Propellants)
{
if (propellant.ignoreForIsp) continue;
_thrustMultiplier *= Math.Pow(PropellantConfigs[propellant.name].ThrustMultiplier, propellant.ratio / TotalPropellantRatio);
}
}
return _thrustMultiplier;
}
protected set
{
_thrustMultiplier = value;
}
}
private double _ispMultiplier = 0;
public override double IspMultiplier
{
get
{
if (_ispMultiplier == 0 && TotalPropellantRatio > 0)
{
_ispMultiplier = 1;
foreach (var propellant in Propellants)
{
if (propellant.ignoreForIsp) continue;
_ispMultiplier *= Math.Pow(PropellantConfigs[propellant.name].IspMultiplier, propellant.ratio / TotalPropellantRatio);
}
}
return _ispMultiplier;
}
protected set
{
_ispMultiplier = value;
}
}
private double _ignitionPotential = 0;
public override double IgnitionPotential
{
get
{
if (_ignitionPotential == 0 && TotalPropellantRatio > 0)
{
_ignitionPotential = 1;
foreach (var propellant in Propellants)
{
if (propellant.ignoreForIsp) continue;
_ignitionPotential *= Math.Pow(PropellantConfigs[propellant.name].IgnitionPotential, propellant.ratio / TotalPropellantRatio);
}
}
return _ignitionPotential;
}
protected set
{
_ignitionPotential = value;
}
}
private double _tankDensity = 0;
public override double TankDensity
{
get
{
if (_tankDensity == 0 && TotalPropellantRatio > 0)
{
_tankDensity = 0.0;
foreach (var propellant in Propellants)
{
if (propellant.ignoreForIsp) continue;
_tankDensity += PropellantConfigs[propellant.name].TankDensity * propellant.ratio / TotalPropellantRatio;
}
}
return _tankDensity;
}
protected set
{
_tankDensity = value;
}
}
private Dictionary<string, PropellantConfig> _propellantConfigs = null;
public Dictionary<string, PropellantConfig> PropellantConfigs
{
get
{
if (_propellantConfigs == null)
{
var allPropellantConfigNodes = GameDatabase.Instance.GetConfigNodes("IgnitionPropellantConfig");
var allPropellantConfigs = new Dictionary<string, PropellantConfig>();
foreach (var propellantConfigNode in allPropellantConfigNodes)
{
var propellantConfig = new PropellantConfig(propellantConfigNode);
allPropellantConfigs[propellantConfig.ResourceName] = propellantConfig;
}
_propellantConfigs = new Dictionary<string, PropellantConfig>();
foreach (var propellant in Propellants)
{
if (allPropellantConfigs.ContainsKey(propellant.name)) _propellantConfigs[propellant.name] = allPropellantConfigs[propellant.name];
else _propellantConfigs[propellant.name] = new PropellantConfig(propellant.name);
}
}
return _propellantConfigs;
}
}
public PropellantCombinationConfig(ConfigNode node) : base(node)
{
var propellantNodes = node.GetNodes("PROPELLANT");
foreach (var propellantNode in propellantNodes)
{
var propellant = new Propellant();
propellant.Load(propellantNode);
propellant.displayName = propellant.name;
propellant.drawStackGauge = propellantNode.HasValue("drawStackGauge") && propellantNode.GetValue("drawStackGauge").ToLower() == "true";
Propellants.Add(propellant);
}
}
public PropellantCombinationConfig(PropellantConfig monopropellantConfig) : base()
{
var monopropellant = monopropellantConfig.GetPropellant(1, true);
Propellants = new List<Propellant> { monopropellant };
}
public PropellantCombinationConfig(PropellantConfig fuelConfig, PropellantConfig oxidizerConfig)
{
var fuelFraction = fuelConfig.MixtureConstant / (double)(fuelConfig.MixtureConstant + oxidizerConfig.MixtureConstant);
var nearestTenth = Math.Round(fuelFraction * 10) / 10;
var nearestSixteenth = Math.Round(fuelFraction * 16) / 16;
var fuelFractionRounded = Math.Abs(fuelFraction - nearestTenth) < Math.Abs(fuelFraction - nearestSixteenth) ? nearestTenth : nearestSixteenth;
var fuel = fuelConfig.GetPropellant(fuelFractionRounded, true);
var oxidizer = oxidizerConfig.GetPropellant(1 - fuelFractionRounded);
Propellants = new List<Propellant> { fuel, oxidizer };
}
public PropellantCombinationConfig(List<Propellant> propellants)
{
Propellants = propellants;
}
}
}