Skip to content

Commit

Permalink
* **NEW**: TestFlightFailure_IgnitionFail can now apply an addition…
Browse files Browse the repository at this point in the history
…al modifier to the chance of ignition based on the number of previous ignitions used. Use the FloatCurve `ingitionUseMultiplier`. This is a straight multiplier and thus values below 1 will lower the chance of the engine igniting and values above 1 will increase the chances.

* **NEW**: `TestFlightFailure_IgnitionFail` can now cause an additional
failure to occur if the ignition fails.  The chance of this occurring
can be set in the property `additionalFailChance` and is a value 0-1f,
with  default of 0.  If this additional failure triggers then the
engine will receive one of the existing random failures assigned to the
part.
  • Loading branch information
jwvanderbeck committed Mar 17, 2016
1 parent 5280a3a commit bfa3d65
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions TestFlightFailure_IgnitionFail.cs
Expand Up @@ -21,6 +21,13 @@ public class TestFlightFailure_IgnitionFail : TestFlightFailure_Engine
public FloatCurve baseIgnitionChance = null;
[KSPField]
public FloatCurve pressureCurve = null;
[KSPField]
public FloatCurve ignitionUseMultiplier = null;
[KSPField]
public float additionalFailureChance = 0f;

[KSPField(isPersistant=true)]
public int numIgnitions = 0;

private ITestFlightCore core = null;

Expand Down Expand Up @@ -82,8 +89,10 @@ public override void OnUpdate()
{
if (engine.ignitionState == EngineModuleWrapper.EngineIgnitionState.NOT_IGNITED || engine.ignitionState == EngineModuleWrapper.EngineIgnitionState.UNKNOWN)
{
double failureRoll = 0d;
Log(String.Format("IgnitionFail: Engine {0} transitioning to INGITED state", engine.engine.Module.GetInstanceID()));
Log(String.Format("IgnitionFail: Checking curves..."));
numIgnitions++;

double initialFlightData = core.GetInitialFlightData();
float ignitionChance = 1f;
Expand All @@ -97,14 +106,19 @@ public override void OnUpdate()
multiplier = 1f;

if (this.vessel.situation != Vessel.Situations.PRELAUNCH)
ignitionChance *= multiplier;
ignitionChance = ignitionChance * multiplier * ignitionUseMultiplier.Evaluate(numIgnitions);

double failureRoll = core.RandomGenerator.NextDouble();
failureRoll = core.RandomGenerator.NextDouble();
Log(String.Format("IgnitionFail: Engine {0} ignition chance {1:F4}, roll {2:F4}", engine.engine.Module.GetInstanceID(), ignitionChance, failureRoll));
if (failureRoll > ignitionChance)
{
engine.failEngine = true;
core.TriggerNamedFailure("TestFlightFailure_IgnitionFail");
failureRoll = core.RandomGenerator.NextDouble();
if (failureRoll < additionalFailureChance)
{
core.TriggerFailure();
}
}
}
}
Expand Down Expand Up @@ -164,6 +178,8 @@ public override void OnAwake()
baseIgnitionChance.Add(0f, 1f);
pressureCurve = new FloatCurve();
pressureCurve.Add(0f, 1f);
ignitionUseMultiplier = new FloatCurve();
ignitionUseMultiplier.Add(0f, 1f);
}
}
}
Expand Down

0 comments on commit bfa3d65

Please sign in to comment.