-
Notifications
You must be signed in to change notification settings - Fork 131
/
FARSettingsScenarioModule.cs
369 lines (305 loc) · 15.3 KB
/
FARSettingsScenarioModule.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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*
Ferram Aerospace Research v0.15.9.1 "Liepmann"
=========================
Aerodynamics model for Kerbal Space Program
Copyright 2017, Michael Ferrara, aka Ferram4
This file is part of Ferram Aerospace Research.
Ferram Aerospace Research is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Ferram Aerospace Research is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Ferram Aerospace Research. If not, see <http://www.gnu.org/licenses/>.
Serious thanks: a.g., for tons of bugfixes and code-refactorings
stupid_chris, for the RealChuteLite implementation
Taverius, for correcting a ton of incorrect values
Tetryds, for finding lots of bugs and issues and not letting me get away with them, and work on example crafts
sarbian, for refactoring code for working with MechJeb, and the Module Manager updates
ialdabaoth (who is awesome), who originally created Module Manager
Regex, for adding RPM support
DaMichel, for some ferramGraph updates and some control surface-related features
Duxwing, for copy editing the readme
CompatibilityChecker by Majiir, BSD 2-clause http://opensource.org/licenses/BSD-2-Clause
Part.cfg changes powered by sarbian & ialdabaoth's ModuleManager plugin; used with permission
http://forum.kerbalspaceprogram.com/threads/55219
ModularFLightIntegrator by Sarbian, Starwaster and Ferram4, MIT: http://opensource.org/licenses/MIT
http://forum.kerbalspaceprogram.com/threads/118088
Toolbar integration powered by blizzy78's Toolbar plugin; used with permission
http://forum.kerbalspaceprogram.com/threads/60863
*/
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using KSP;
using FerramAerospaceResearch.FARGUI;
using FerramAerospaceResearch.FARGUI.FAREditorGUI;
using FerramAerospaceResearch.FARPartGeometry;
using ferram4;
namespace FerramAerospaceResearch
{
[KSPScenario(ScenarioCreationOptions.AddToAllGames, GameScenes.SPACECENTER, GameScenes.EDITOR, GameScenes.FLIGHT)]
public class FARSettingsScenarioModule : ScenarioModule
{
public bool newGame = false;
public FARDifficultyAndExactnessSettings settings;
public static FARDifficultyAndExactnessSettings Settings
{
get
{
return Instance.settings;
}
}
public FARDifficultyAndExactnessSettings customSettings;
public List<FARDifficultyAndExactnessSettings> presets;
public FARVoxelSettings voxelSettings;
public static FARVoxelSettings VoxelSettings
{
get
{
return Instance.voxelSettings;
}
}
public List<ConfigNode> flightGUISettings;
public static List<ConfigNode> FlightGUISettings
{
get
{
return Instance.flightGUISettings;
}
}
static List<string> presetNames;
public int currentIndex;
static FARSettingsScenarioModule instance;
public static FARSettingsScenarioModule Instance
{
get
{
return instance;
}
}
GUIDropDown<FARDifficultyAndExactnessSettings> dropdown;
public static void MainMenuBuildDefaultScenarioModule()
{
if (instance == null)
{
instance = new FARSettingsScenarioModule();
Debug.Log("Creating new setting module for tutorial/scenario");
instance.OnLoad(new ConfigNode());
instance.Start();
}
}
FARSettingsScenarioModule()
{
instance = this;
}
void Start()
{
if (!CompatibilityChecker.IsAllCompatible())
{
this.enabled = false;
return;
}
instance = this;
//if (newGame)
// PopupDialog.SpawnPopupDialog("Ferram Aerospace Research", "Welcome to KSP with FAR!\n\r\n\rThings will be much harder from here on out; the FAR button in the top-right corner will bring you to difficulty settings if you ever decide to change them. Have fun!", "OK", false, HighLogic.Skin);
Debug.Log("FAR Vehicle Voxel Setup started");
FerramAerospaceResearch.FARAeroComponents.FARAeroSection.GenerateCrossFlowDragCurve();
VehicleVoxel.VoxelSetup();
PhysicsGlobals.DragCubeMultiplier = 0;
Debug.Log("FAR Vehicle Voxel Setup complete");
//GameEvents.onGameStateSave.Add(OnSave);
newGame = false;
}
void OnDestroy()
{
//GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
//GameEvents.onGameStateSave.Remove(OnSave);
}
public override void OnSave(ConfigNode node)
{
Debug.Log("saved");
node.AddValue("newGame", newGame);
node.AddValue("fractionTransonicDrag", settings.fractionTransonicDrag);
node.AddValue("gaussianVehicleLengthFractionForSmoothing", settings.gaussianVehicleLengthFractionForSmoothing);
node.AddValue("numAreaSmoothingPasses", settings.numAreaSmoothingPasses);
node.AddValue("numDerivSmoothingPasses", settings.numDerivSmoothingPasses);
node.AddValue("numVoxelsControllableVessel", voxelSettings.numVoxelsControllableVessel);
node.AddValue("numVoxelsDebrisVessel", voxelSettings.numVoxelsDebrisVessel);
node.AddValue("minPhysTicksPerUpdate", voxelSettings.minPhysTicksPerUpdate);
node.AddValue("useHigherResVoxelPoints", voxelSettings.useHigherResVoxelPoints);
node.AddValue("index", settings.index);
FARGUI.FARFlightGUI.FlightGUI.SaveActiveData();
ConfigNode flightGUINode = new ConfigNode("FlightGUISettings");
Debug.Log("Saving FAR Data");
for (int i = 0; i < flightGUISettings.Count; i++)
{
flightGUINode.AddNode(flightGUISettings[i]);
}
node.AddNode(flightGUINode);
FARDebugAndSettings.SaveConfigs(node);
}
public override void OnLoad(ConfigNode node)
{
instance = this;
GeneratePresets();
int index = 4;
if (node.HasValue("newGame"))
newGame = bool.Parse(node.GetValue("newGame"));
if (node.HasValue("index"))
index = int.Parse(node.GetValue("index"));
dropdown = new GUIDropDown<FARDifficultyAndExactnessSettings>(presetNames.ToArray(), presets.ToArray(), index < 0 ? 2 : index);
voxelSettings = new FARVoxelSettings();
if (node.HasValue("numVoxelsControllableVessel"))
voxelSettings.numVoxelsControllableVessel = int.Parse(node.GetValue("numVoxelsControllableVessel"));
if (node.HasValue("numVoxelsDebrisVessel"))
voxelSettings.numVoxelsDebrisVessel = int.Parse(node.GetValue("numVoxelsDebrisVessel"));
if (node.HasValue("minPhysTicksPerUpdate"))
voxelSettings.minPhysTicksPerUpdate = int.Parse(node.GetValue("minPhysTicksPerUpdate"));
if (node.HasValue("useHigherResVoxelPoints"))
voxelSettings.useHigherResVoxelPoints = bool.Parse(node.GetValue("useHigherResVoxelPoints"));
if (index == -1)
{
settings = new FARDifficultyAndExactnessSettings(index);
if (node.HasValue("fractionTransonicDrag"))
settings.fractionTransonicDrag = double.Parse(node.GetValue("fractionTransonicDrag"));
if (node.HasValue("gaussianVehicleLengthFractionForSmoothing"))
settings.gaussianVehicleLengthFractionForSmoothing = double.Parse(node.GetValue("gaussianVehicleLengthFractionForSmoothing"));
if (node.HasValue("numAreaSmoothingPasses"))
settings.numAreaSmoothingPasses = int.Parse(node.GetValue("numAreaSmoothingPasses"));
if (node.HasValue("numDerivSmoothingPasses"))
settings.numDerivSmoothingPasses = int.Parse(node.GetValue("numDerivSmoothingPasses"));
customSettings = settings;
}
else
{
settings = presets[index];
customSettings = new FARDifficultyAndExactnessSettings(-1);
}
currentIndex = index;
Debug.Log("Loading FAR Data");
flightGUISettings = new List<ConfigNode>();
if(node.HasNode("FlightGUISettings"))
{
foreach (ConfigNode flightGUINode in node.GetNode("FlightGUISettings").nodes)
flightGUISettings.Add(flightGUINode);
}
FARDebugAndSettings.LoadConfigs(node);
}
private void GeneratePresets()
{
presets = new List<FARDifficultyAndExactnessSettings>();
presetNames = new List<string>();
FARDifficultyAndExactnessSettings tmp = new FARDifficultyAndExactnessSettings(0.6, 0.03, 2, 2, 0);
presets.Add(tmp);
presetNames.Add("Low Drag, Lenient Area Ruling");
tmp = new FARDifficultyAndExactnessSettings(0.7, 0.03, 2, 2, 1);
presets.Add(tmp);
presetNames.Add("Moderate Drag, Lenient Area Ruling");
tmp = new FARDifficultyAndExactnessSettings(0.7, 0.015, 2, 1, 2);
presets.Add(tmp);
presetNames.Add("Moderate Drag, Moderate Area Ruling");
tmp = new FARDifficultyAndExactnessSettings(0.85, 0.015, 2, 1, 3);
presets.Add(tmp);
presetNames.Add("High Drag, Moderate Area Ruling");
tmp = new FARDifficultyAndExactnessSettings(1, 0.015, 2, 1, 4);
presets.Add(tmp);
presetNames.Add("Full Drag, Moderate Area Ruling");
tmp = new FARDifficultyAndExactnessSettings(1, 0.010, 1, 1, 5);
presets.Add(tmp);
presetNames.Add("Full Drag, Strict Area Ruling");
}
public void DisplaySelection()
{
GUILayout.BeginVertical();
GUILayout.Label("Transonic Drag Settings");
GUILayout.Label("Absolute magnitude of drag can be scaled, as can how lenient FAR is about enforcing proper area ruling.");
GUILayout.BeginHorizontal();
if (currentIndex >= 0)
{
dropdown.GUIDropDownDisplay(GUILayout.Width(300));
settings = dropdown.ActiveSelection;
currentIndex = settings.index;
}
else
{
GUILayout.BeginVertical();
settings = customSettings;
settings.fractionTransonicDrag = GUIUtils.TextEntryForDouble("Frac Mach 1 Drag: ", 150, settings.fractionTransonicDrag);
GUILayout.Label("The below are used in controlling leniency of design. Higher values for all will result in more leniency");
settings.gaussianVehicleLengthFractionForSmoothing = GUIUtils.TextEntryForDouble("% Vehicle Length for Smoothing", 250, settings.gaussianVehicleLengthFractionForSmoothing);
settings.numAreaSmoothingPasses = GUIUtils.TextEntryForInt("Smoothing Passes, Cross-Sectional Area", 250, settings.numAreaSmoothingPasses);
if (settings.numAreaSmoothingPasses < 0)
settings.numAreaSmoothingPasses = 0;
settings.numDerivSmoothingPasses = GUIUtils.TextEntryForInt("Smoothing Passes, area 2nd deriv", 250, settings.numDerivSmoothingPasses);
if (settings.numDerivSmoothingPasses < 0)
settings.numDerivSmoothingPasses = 0;
customSettings = settings;
GUILayout.EndVertical();
}
if (GUILayout.Button(currentIndex < 0 ? "Switch Back To Presets" : "Choose Custom Settings"))
{
if (currentIndex >= 0)
currentIndex = -1;
else
currentIndex = 4;
}
GUILayout.EndHorizontal();
GUILayout.Label("Voxel Detail Settings; increasing these will improve accuracy at the cost of performance");
voxelSettings.numVoxelsControllableVessel = GUIUtils.TextEntryForInt("Voxels Controllable Vessel: ", 200, voxelSettings.numVoxelsControllableVessel);
if (voxelSettings.numVoxelsControllableVessel < 0)
voxelSettings.numVoxelsControllableVessel = 100000;
voxelSettings.numVoxelsDebrisVessel = GUIUtils.TextEntryForInt("Voxels Debris: ", 200, voxelSettings.numVoxelsDebrisVessel);
if (voxelSettings.numVoxelsDebrisVessel < 0)
voxelSettings.numVoxelsDebrisVessel = 5000;
voxelSettings.minPhysTicksPerUpdate = GUIUtils.TextEntryForInt("Min Phys Ticks per Voxel Update: ", 200, voxelSettings.minPhysTicksPerUpdate);
if (voxelSettings.minPhysTicksPerUpdate < 0)
voxelSettings.minPhysTicksPerUpdate = 80;
GUILayout.BeginHorizontal();
GUILayout.Label("Use Higher Res SubVoxels: ");
voxelSettings.useHigherResVoxelPoints = GUILayout.Toggle(voxelSettings.useHigherResVoxelPoints, voxelSettings.useHigherResVoxelPoints ? "High Res SubVoxels" : "Low Res SubVoxels");
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
}
public class FARDifficultyAndExactnessSettings
{
public double fractionTransonicDrag = 0.7;
public double gaussianVehicleLengthFractionForSmoothing = 0.015;
public int numAreaSmoothingPasses = 2;
public int numDerivSmoothingPasses = 1;
public int index;
public static bool customSettings = false;
public FARDifficultyAndExactnessSettings(int index)
{
this.index = index;
}
public FARDifficultyAndExactnessSettings(double transDrag, double gaussianLength, int areaPass, int derivPass, int index)
{
this.index = index;
fractionTransonicDrag = transDrag;
gaussianVehicleLengthFractionForSmoothing = gaussianLength;
numAreaSmoothingPasses = areaPass;
numDerivSmoothingPasses = derivPass;
}
}
public class FARVoxelSettings
{
public int numVoxelsControllableVessel;
public int numVoxelsDebrisVessel;
public int minPhysTicksPerUpdate;
public bool useHigherResVoxelPoints;
public FARVoxelSettings() : this(250000, 20000, 80, true) { }
public FARVoxelSettings(int vesselCount, int debrisCount, int minPhysTicks, bool higherResVoxPoints)
{
numVoxelsControllableVessel = vesselCount;
numVoxelsDebrisVessel = debrisCount;
minPhysTicksPerUpdate = minPhysTicks;
useHigherResVoxelPoints = higherResVoxPoints;
}
}
}