Skip to content

Commit bf4225b

Browse files
committed
NEW: Crew condition checks for a minimum and maximum crew on the vessel
1 parent 65570bc commit bf4225b

3 files changed

Lines changed: 140 additions & 0 deletions

File tree

1.5 KB
Binary file not shown.
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using System;
2+
3+
using UnityEngine;
4+
5+
namespace RealScience.Conditions
6+
{
7+
class RealScienceCondition_Crew : RealScienceCondition
8+
{
9+
// common properties
10+
public string conditionType = "Crew";
11+
public bool restriction = false;
12+
public string exclusion = "";
13+
public float dataRateModifier = 1f;
14+
public float maximumDataModifier = 1f;
15+
public float maximumDataBonus = 0f;
16+
17+
// specific properties
18+
public int minimumCrew = 1;
19+
public int maximumCrew = 20;
20+
21+
public override float DataRateModifier
22+
{
23+
get { return dataRateModifier; }
24+
}
25+
public override float MaximumDataModifier
26+
{
27+
get { return maximumDataModifier; }
28+
}
29+
public override float MaximumDataBonus
30+
{
31+
get { return maximumDataBonus; }
32+
}
33+
public override bool IsRestriction
34+
{
35+
get { return restriction; }
36+
}
37+
public override string Exclusion
38+
{
39+
get { return exclusion; }
40+
}
41+
protected string tooltip;
42+
public override string Tooltip
43+
{
44+
get { return tooltip; }
45+
}
46+
public override string Name
47+
{
48+
get { return conditionType; }
49+
}
50+
51+
public override EvalState Evaluate(Part part, float deltaTime, ExperimentState state)
52+
{
53+
bool valid = false;
54+
tooltip = "\nCrewed Condition";
55+
if (restriction)
56+
{
57+
if (exclusion.ToLower() == "reset")
58+
tooltip += "\nThe following condition must <b>not</b> be met. If they are the experiment will be <b>reset</b>.";
59+
else if (exclusion.ToLower() == "fail")
60+
tooltip += "\nThe following condition must <b>not</b> be met. If they are, the experiment will <b>fail</b>.";
61+
else
62+
tooltip += "\nThe following condition must <b>not</b> be met.";
63+
}
64+
else
65+
tooltip += "\nThe following condition must be met.";
66+
67+
int currentCrew = part.vessel.GetCrewCount();
68+
if (currentCrew >= minimumCrew && currentCrew <= maximumCrew)
69+
valid = true;
70+
71+
if (!restriction)
72+
{
73+
if (valid)
74+
return EvalState.VALID;
75+
else
76+
return EvalState.INVALID;
77+
}
78+
else
79+
{
80+
if (!valid)
81+
return EvalState.VALID;
82+
else
83+
{
84+
if (exclusion.ToLower() == "reset")
85+
return EvalState.RESET;
86+
else if (exclusion.ToLower() == "fail")
87+
return EvalState.FAILED;
88+
else
89+
return EvalState.INVALID;
90+
}
91+
}
92+
}
93+
public override void Load(ConfigNode node)
94+
{
95+
// Load common properties
96+
if (node.HasValue("conditionType"))
97+
conditionType = node.GetValue("conditionType");
98+
if (node.HasValue("exclusion"))
99+
exclusion = node.GetValue("exclusion");
100+
if (node.HasValue("restriction"))
101+
{
102+
try
103+
{
104+
restriction = bool.Parse(node.GetValue("restriction"));
105+
}
106+
catch (FormatException)
107+
{
108+
restriction = false;
109+
}
110+
}
111+
if (node.HasValue("dataRateModifier"))
112+
{
113+
try
114+
{
115+
dataRateModifier = float.Parse(node.GetValue("dataRateModifier"));
116+
}
117+
catch (FormatException)
118+
{
119+
dataRateModifier = 1f;
120+
}
121+
}
122+
// Load specific properties
123+
if (node.HasValue("minimumCrew"))
124+
minimumCrew = int.Parse(node.GetValue("minimumCrew"));
125+
if (node.HasValue("maximumCrew"))
126+
maximumCrew = int.Parse(node.GetValue("maximumCrew"));
127+
}
128+
public override void Save(ConfigNode node)
129+
{
130+
// Save common properties
131+
node.AddValue("conditionType", conditionType);
132+
node.AddValue("restriction", restriction);
133+
node.AddValue("exclusion", exclusion);
134+
node.AddValue("dataRateModifier", dataRateModifier);
135+
node.AddValue("minimumCrew", minimumCrew);
136+
node.AddValue("maximumCrew", maximumCrew);
137+
}
138+
}
139+
}

source/RealScience.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
<Compile Include="Resources.cs" />
8787
<Compile Include="StylesAndSkins.cs" />
8888
<Compile Include="UserSettings.cs" />
89+
<Compile Include="Conditions\RealScienceCondition_Crew.cs" />
8990
</ItemGroup>
9091
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
9192
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

0 commit comments

Comments
 (0)