-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGlobals.cs
144 lines (120 loc) · 4.83 KB
/
Globals.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
// Globals.cs
//
// Author:
// Allis Tauri <[email protected]>
//
// Copyright (c) 2016 Allis Tauri
using System.Collections.Generic;
using AT_Utils;
namespace GroundConstruction
{
public class Globals : PluginGlobals<Globals>
{
public UIBundle AssetBundle = UIBundle.Create("GroundConstruction/gc_ui.bundle");
#region Resources
[Persistent] public ResourceUsageInfo AssemblyResource = new ResourceUsageInfo("SpecializedParts");
[Persistent] public ResourceUsageInfo ConstructionResource = new ResourceUsageInfo("MaterialKits");
public ResourceIdSet KeepResources = new ResourceIdSet("GC_KEEP_RESOURCES");
public ResourceIdSet AssembleResources = new ResourceIdSet("GC_ASSEMBLE_RESOURCES");
public ResourceIdSet ConstructResources = new ResourceIdSet("GC_CONSTRUCT_RESOURCES");
#endregion
public ModuleNamesSet IgnoreModules = new ModuleNamesSet("GC_IGNORE_MODULES");
[Persistent] public bool UseStockAppLauncher = true;
[Persistent] public float WorkshopShutdownThreshold = 0.99f;
[Persistent] public float MaxDistanceToWorkshop = 300f;
[Persistent] public float MinDistanceToWorkshop = 50f;
[Persistent] public float MaxDistanceEfficiency = 0.2f;
[Persistent] public float VolumePerKerbal = 3;
[Persistent] public float PartVolumeFactor = 0.3f;
[Persistent] public float MinGenericEfficiency = 0.05f;
[Persistent] public float MaxGenericEfficiency = 0.5f;
[Persistent] public float ComplexityFactor = 1e-4f;
[Persistent] public float FinalizationWorkPerMass = 0.5f;
[Persistent] public float VesselKitDensity = 0.5f; //t/m3
[Persistent] public float MinKitVolume = 0.02f; //m3
[Persistent] public float DeployMaxSpeed = 0.5f; //m/s
[Persistent] public float DeployMaxAV = 5e-6f; //(rad/s)2
[Persistent] public float MaxDeploymentMomentum = 1; //t*m/s
[Persistent] public float MinDeploymentTime = 3; //s
[Persistent] public int EasingFrames = 120;
[Persistent] public float MaxDockingCos = 0.999f;
[Persistent] public float MaxDockingDist = 0.2f;
[Persistent] public float RecycleRate = 1f;
[Persistent] public float RecycleEnergyRatio = 0.1f;
}
public class ResourceUsageInfo : ResourceInfo
{
[Persistent] public float ComplexityWork = 0;
[Persistent] public float EnergyPerMass = 0;
[Persistent] public float WorkPerMass = 0;
[Persistent] public float MaxRecycleRatio = 0;
public ResourceUsageInfo(string name = "") : base(name) { }
}
public abstract class ConfigValueSet<T>
{
protected string node_name = string.Empty;
HashSet<T> values;
protected abstract bool transform_value(ConfigNode.Value val, out T value);
protected ConfigValueSet(string nodeName)
{
node_name = nodeName;
}
public HashSet<T> Values
{
get
{
if(values == null)
{
values = new HashSet<T>();
T value;
var nodes = GameDatabase.Instance.GetConfigNodes(node_name);
foreach(var node in nodes)
{
foreach(ConfigNode.Value val in node.values)
{
if(transform_value(val, out value))
values.Add(value);
}
}
}
return values;
}
}
public static implicit operator HashSet<T>(ConfigValueSet<T> configValueSet)
=> configValueSet.Values;
}
public class ModuleNamesSet : ConfigValueSet<string>
{
public ModuleNamesSet(string nodeName) : base(nodeName) { }
protected override bool transform_value(ConfigNode.Value val, out string value)
{
value = val.value;
return true;
}
public int SizeOfDifference(PartModuleList modules)
{
int size = 0;
for(int i = 0, modulesCount = modules.Count; i < modulesCount; i++)
{
if(!Values.Contains(modules[i].ClassName))
size++;
}
return size;
}
}
public class ResourceIdSet : ConfigValueSet<int>
{
public ResourceIdSet(string nodeName) : base(nodeName) { }
protected override bool transform_value(ConfigNode.Value val, out int value)
{
value = 0;
var res = PartResourceLibrary.Instance.GetDefinition(val.value);
if(res != null)
{
value = res.id;
return true;
}
return false;
}
}
}