Skip to content

Commit 4867c11

Browse files
committed
Merge branch 'dev'
2 parents 23ad469 + 41d6802 commit 4867c11

File tree

15 files changed

+270
-64
lines changed

15 files changed

+270
-64
lines changed
1 KB
Binary file not shown.
512 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

TestFlightAPI/TestFlightAPI/FlightDataRecorder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public override void OnUpdate()
7676
double flightData = (currentMet - lastRecordedMet) * flightDataMultiplier;
7777
double engineerBonus = core.GetEngineerDataBonus(flightDataEngineerModifier);
7878
flightData *= engineerBonus;
79-
80-
core.ModifyFlightDataForScope(flightData, scope, true);
79+
if (flightData >= 0)
80+
core.ModifyFlightDataForScope(flightData, scope, true);
8181
}
8282

8383
core.ModifyFlightTimeForScope(currentMet - lastRecordedMet, scope, true);

TestFlightAPI/TestFlightAPI/TestFlightAPI.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ string Configuration
237237
get;
238238
set;
239239
}
240+
bool OneShot
241+
{
242+
get;
243+
}
240244
/// <summary>
241245
/// Gets the details of the failure encapsulated by this module. In most cases you can let the base class take care of this unless oyu need to do somethign special
242246
/// </summary>

TestFlightAPI/TestFlightAPI/TestFlightFailure.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ public class TestFlightFailureBase : PartModule, ITestFlightFailure
134134
public string failureTitle = "Failure";
135135
[KSPField(isPersistant=true)]
136136
public string configuration = "";
137+
[KSPField(isPersistant = true)]
138+
public double duFail = 0;
139+
[KSPField(isPersistant = true)]
140+
public double duRepair = 0;
141+
[KSPField(isPersistant = true)]
142+
public bool oneShot = false;
143+
144+
public RepairConfig repairConfig;
145+
137146

138147
public bool Failed
139148
{
@@ -164,8 +173,10 @@ public string Configuration
164173
set { configuration = value; }
165174
}
166175

167-
168-
public RepairConfig repairConfig;
176+
public bool OneShot
177+
{
178+
get { return oneShot; }
179+
}
169180

170181
/// <summary>
171182
/// Gets the details of the failure encapsulated by this module. In most cases you can let the base class take care of this unless oyu need to do somethign special
@@ -314,6 +325,9 @@ internal float GetOptionalRepairBonus()
314325
public virtual void DoFailure()
315326
{
316327
Failed = true;
328+
ITestFlightCore core = TestFlightUtil.GetCore(this.part);
329+
if (core != null)
330+
core.ModifyFlightData(duFail, true);
317331
}
318332

319333
/// <summary>
@@ -365,6 +379,9 @@ public virtual double ForceRepair()
365379
public virtual double DoRepair()
366380
{
367381
Failed = false;
382+
ITestFlightCore core = TestFlightUtil.GetCore(this.part);
383+
if (core != null)
384+
core.ModifyFlightData(duRepair, true);
368385
return 0;
369386
}
370387

TestFlightAPI/TestFlightAPI/TestFlightReliability.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public string Configuration
7878
// If this Reliability module's purpose is to supply Momentary Fialure Rates, then it MUST return 0 when asked for the Base Failure Rate
7979
// If it dosn't, then the Base Failure Rate of the part will not be correct.
8080
//
81-
public double GetBaseFailureRateForScope(double flightData, String scope)
81+
public virtual double GetBaseFailureRateForScope(double flightData, String scope)
8282
{
8383
if (!TestFlightEnabled)
8484
return 0;
@@ -116,7 +116,10 @@ private ReliabilityBodyConfig GetConfigForScope(String scope)
116116
if (reliabilityBodies == null)
117117
return null;
118118

119-
return reliabilityBodies.Find(s => s.scope == scope);
119+
ReliabilityBodyConfig returnBody = reliabilityBodies.Find(s => s.scope == scope);
120+
if (returnBody == null)
121+
returnBody = reliabilityBodies.Find(s => s.scope == "default");
122+
return returnBody;
120123
}
121124

122125
IEnumerator Attach()

TestFlightCore/TestFlightCore/TestFlight.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ internal override void Update()
375375
VerifyMasterStatus();
376376
}
377377
// process vessels
378-
string configuration = "";
379378
foreach (var entry in knownVessels)
380379
{
381380
Vessel vessel = FlightGlobals.Vessels.Find(v => v.id == entry.Key);

TestFlightCore/TestFlightCore/TestFlightCore.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,21 @@ public ITestFlightFailure TriggerFailure()
679679
int totalWeight = 0;
680680
int currentWeight = 0;
681681
int chosenWeight = 0;
682-
List<ITestFlightFailure> failureModules;
682+
List<ITestFlightFailure> failureModules = null;
683683

684-
failureModules = TestFlightUtil.GetFailureModules(this.part);
684+
// Get all failure modules on the part
685+
// Then filter only the ones that are not disabled
686+
List<ITestFlightFailure> allFailureModules = TestFlightUtil.GetFailureModules(this.part);
687+
foreach (ITestFlightFailure fm in allFailureModules)
688+
{
689+
PartModule pm = fm as PartModule;
690+
if (!disabledFailures.Contains(pm.moduleName))
691+
{
692+
if (failureModules == null)
693+
failureModules = new List<ITestFlightFailure>();
694+
failureModules.Add(fm);
695+
}
696+
}
685697

686698
foreach(ITestFlightFailure fm in failureModules)
687699
{
@@ -730,11 +742,14 @@ public ITestFlightFailure TriggerNamedFailure(String failureModuleName, bool fal
730742
else
731743
{
732744
LogFormatted_DebugOnly("TestFlightCore: Triggering Failure: " + pm.moduleName);
733-
activeFailure = fm;
734-
failureAcknowledged = false;
735-
fm.DoFailure();
736-
operatingTime = -1;
737-
return fm;
745+
if (!fm.OneShot)
746+
{
747+
activeFailure = fm;
748+
failureAcknowledged = false;
749+
fm.DoFailure();
750+
operatingTime = -1;
751+
return fm;
752+
}
738753
}
739754
}
740755
}

TestFlightFailure_IgnitionFail.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ namespace TestFlight
1111
{
1212
public class TestFlightFailure_IgnitionFail : TestFlightFailureBase
1313
{
14+
[KSPField(isPersistant=true)]
15+
public bool restoreIgnitionCharge = false;
16+
1417
public FloatCurve ignitionFailureRate;
1518
public int engineIndex = 0;
1619

@@ -125,6 +128,25 @@ public override void DoFailure()
125128
return;
126129

127130
engine.Shutdown();
131+
132+
if (OneShot && restoreIgnitionCharge)
133+
RestoreIgnitor();
134+
}
135+
public override double DoRepair()
136+
{
137+
base.DoRepair();
138+
if (restoreIgnitionCharge)
139+
RestoreIgnitor();
140+
return 0;
141+
}
142+
public void RestoreIgnitor()
143+
{
144+
// part.Modules["ModuleEngineIgnitor"].GetType().GetField("ignitionsRemained").GetValue(part.Modules["ModuleEngineIgnitor"]));
145+
if (this.part.Modules.Contains("ModuleEngineIgnitor"))
146+
{
147+
int currentIgnitions = (int)part.Modules["ModuleEngineIgnitor"].GetType().GetField("ignitionsRemained").GetValue(part.Modules["ModuleEngineIgnitor"]);
148+
part.Modules["ModuleEngineIgnitor"].GetType().GetField("ignitionsRemained").SetValue(part.Modules["ModuleEngineIgnitor"], currentIgnitions + 1);
149+
}
128150
}
129151

130152
public override void OnLoad(ConfigNode node)

0 commit comments

Comments
 (0)