// Failure methods public override void DoFailure() { base.DoFailure(); if (!TestFlightEnabled) { return; } Log(String.Format("IgnitionFail: Failing {0} engine(s)", engines.Count)); for (int i = 0; i < engines.Count; i++) { EngineHandler engine = engines[i]; if (engine.failEngine) { engine.engine.Shutdown(); // For some reason, need to disable GUI as well engine.engine.Events["Activate"].active = false; engine.engine.Events["Shutdown"].active = false; engine.engine.Events["Activate"].guiActive = false; engine.engine.Events["Shutdown"].guiActive = false; if ((restoreIgnitionCharge) || (this.vessel.situation == Vessel.Situations.PRELAUNCH)) { RestoreIgnitor(); } engines[i].failEngine = false; } } }
//register with function public void RegisterForEngineEvents(EngineHandler value) { if (value != null) { engHandle += value; } }
public void RemoveEngineEvent(EngineHandler value) { if (value != null) { engHandle -= value; } }
// Failure methods public override void DoFailure() { if (!TestFlightEnabled) { return; } Failed = true; float multiplier = 0; ITestFlightCore core = TestFlightUtil.GetCore(this.part, Configuration); if (core != null) { core.ModifyFlightData(duFail, true); string met = KSPUtil.PrintTimeCompact((int)Math.Floor(this.vessel.missionTime), false); if (dynPressurePenalties) { multiplier = pressureCurve.Evaluate((float)(part.dynamicPressurekPa * 1000d)); if (multiplier <= 0f) { multiplier = 1f; } } if (multiplier > float.Epsilon) { FlightLogger.eventLog.Add($"[{met}] {core.Title} failed: Ignition Failure. {(float)(part.dynamicPressurekPa * 1000d)}Pa dynamic pressure cased a {(1f-multiplier) * 100f}% reduction in normal ignition reliability."); } else { FlightLogger.eventLog.Add($"[{met}] {core.Title} failed: Ignition Failure."); } } Log(String.Format("IgnitionFail: Failing {0} engine(s)", engines.Count)); for (int i = 0; i < engines.Count; i++) { EngineHandler engine = engines[i]; if (engine.failEngine) { engine.engine.Shutdown(); if (severity.ToLowerInvariant() == "major") { // For some reason, need to disable GUI as well engine.engine.Events["Activate"].active = false; engine.engine.Events["Shutdown"].active = false; engine.engine.Events["Activate"].guiActive = false; engine.engine.Events["Shutdown"].guiActive = false; } if ((restoreIgnitionCharge) || (this.vessel.situation == Vessel.Situations.PRELAUNCH)) { RestoreIgnitor(); } engines[i].failEngine = false; } } }
public virtual void Startup() { engines = new List <EngineHandler>(); if (!String.IsNullOrEmpty(engineID)) { if (engineID.ToLower() == "all") { List <ModuleEngines> engineMods = this.part.Modules.GetModules <ModuleEngines>(); foreach (ModuleEngines eng in engineMods) { string id = eng.engineID; EngineModuleWrapper engine = new EngineModuleWrapper(); engine.InitWithEngine(this.part, id); EngineHandler engineHandler = new EngineHandler(); engineHandler.engine = engine; engineHandler.ignitionState = engine.IgnitionState; engines.Add(engineHandler); } } else if (engineID.Contains(",")) { string[] sEngineIndices = engineID.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string sEngineIndex in sEngineIndices) { EngineModuleWrapper engine = new EngineModuleWrapper(); engine.InitWithEngine(this.part, sEngineIndex); EngineHandler engineHandler = new EngineHandler(); engineHandler.engine = engine; engineHandler.ignitionState = engine.IgnitionState; engines.Add(engineHandler); } } else { EngineModuleWrapper engine = new EngineModuleWrapper(); engine.InitWithEngine(this.part, engineID); EngineHandler engineHandler = new EngineHandler(); engineHandler.engine = engine; engineHandler.ignitionState = engine.IgnitionState; engines.Add(engineHandler); } } else { EngineModuleWrapper engine = new EngineModuleWrapper(); engine.Init(this.part); EngineHandler engineHandler = new EngineHandler(); engineHandler.engine = engine; engineHandler.ignitionState = engine.IgnitionState; engines.Add(engineHandler); } }
public virtual void Startup() { engines = new List<EngineHandler>(); if (!String.IsNullOrEmpty(engineID)) { if (engineID.ToLower() == "all") { List<ModuleEnginesFX> enginesFX = this.part.Modules.OfType<ModuleEnginesFX>().ToList(); foreach (ModuleEnginesFX fx in enginesFX) { string id = fx.engineID; EngineModuleWrapper engine = new EngineModuleWrapper(this.part, id); EngineHandler engineHandler = new EngineHandler(); engineHandler.engine = engine; engineHandler.ignitionState = engine.IgnitionState; engines.Add(engineHandler); } } else if (engineID.Contains(",")) { string[] sEngineIndices = engineID.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string sEngineIndex in sEngineIndices) { EngineModuleWrapper engine = new EngineModuleWrapper(this.part, sEngineIndex); EngineHandler engineHandler = new EngineHandler(); engineHandler.engine = engine; engineHandler.ignitionState = engine.IgnitionState; engines.Add(engineHandler); } } else { EngineModuleWrapper engine = new EngineModuleWrapper(this.part, engineID); EngineHandler engineHandler = new EngineHandler(); engineHandler.engine = engine; engineHandler.ignitionState = engine.IgnitionState; engines.Add(engineHandler); } } else { EngineModuleWrapper engine = new EngineModuleWrapper(this.part); EngineHandler engineHandler = new EngineHandler(); engineHandler.engine = engine; engineHandler.ignitionState = engine.IgnitionState; engines.Add(engineHandler); } }
public override float DoRepair() { base.DoRepair(); for (int i = 0; i < engines.Count; i++) { EngineHandler engine = engines[i]; { engine.engine.Shutdown(); if (restoreIgnitionCharge || this.vessel.situation == Vessel.Situations.PRELAUNCH) { RestoreIgnitor(); } engines[i].failEngine = false; } } return(0); }
public override float DoRepair() { base.DoRepair(); for (int i = 0; i < engines.Count; i++) { EngineHandler engine = engines[i]; { // Prevent auto-ignition on repair engine.engine.Shutdown(); engine.engine.Events["Activate"].active = true; engine.engine.Events["Activate"].guiActive = true; engine.engine.Events["Shutdown"].guiActive = true; if (restoreIgnitionCharge || this.vessel.situation == Vessel.Situations.PRELAUNCH) { RestoreIgnitor(); } engines[i].failEngine = false; } } return(0); }
// Failure methods public override void DoFailure() { base.DoFailure(); if (!TestFlightEnabled) { return; } Log(String.Format("IgnitionFail: Failing {0} engine(s)", engines.Count)); for (int i = 0; i < engines.Count; i++) { EngineHandler engine = engines[i]; if (engine.failEngine) { engine.engine.Shutdown(); if ((restoreIgnitionCharge) || (this.vessel.situation == Vessel.Situations.PRELAUNCH)) { RestoreIgnitor(); } engines[i].failEngine = false; } } }
public override void OnUpdate() { if (!TestFlightEnabled) { return; } // For each engine we are tracking, compare its current ignition state to our last known ignition state for (int i = 0; i < engines.Count; i++) { EngineHandler engine = engines[i]; EngineModuleWrapper.EngineIgnitionState currentIgnitionState = engine.engine.IgnitionState; // If we are transitioning from not ignited to ignited, we do our check // The ignitionFailureRate defines the failure rate per flight data if (currentIgnitionState == EngineModuleWrapper.EngineIgnitionState.IGNITED) { if (engine.ignitionState == EngineModuleWrapper.EngineIgnitionState.NOT_IGNITED || engine.ignitionState == EngineModuleWrapper.EngineIgnitionState.UNKNOWN) { double failureRoll = 0d; if (verboseDebugging) { 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; float multiplier = 1f; // Check to see if the vessel has not launched and if the player disabled pad failures if (this.vessel.situation == Vessel.Situations.PRELAUNCH && !preLaunchFailures) { ignitionChance = 1.0f; } else { ignitionChance = baseIgnitionChance.Evaluate((float)initialFlightData); if (ignitionChance <= 0) { ignitionChance = 1f; } } if (dynPressurePenalties) { multiplier = pressureCurve.Evaluate((float)(part.dynamicPressurekPa * 1000d)); if (multiplier <= 0f) { multiplier = 1f; } } float minValue, maxValue = -1f; baseIgnitionChance.FindMinMaxValue(out minValue, out maxValue); if (verboseDebugging) { Log(String.Format("TestFlightFailure_IgnitionFail: IgnitionChance Curve, Min Value {0:F2}:{1:F6}, Max Value {2:F2}:{3:F6}", baseIgnitionChance.minTime, minValue, baseIgnitionChance.maxTime, maxValue)); } if (this.vessel.situation != Vessel.Situations.PRELAUNCH) { ignitionChance = ignitionChance * multiplier * ignitionUseMultiplier.Evaluate(numIgnitions); } failureRoll = core.RandomGenerator.NextDouble(); if (verboseDebugging) { 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(); } } } } engine.ignitionState = currentIgnitionState; } }
public override void OnUpdate() { if (!TestFlightEnabled) { return; } // For each engine we are tracking, compare its current ignition state to our last known ignition state for (int i = 0; i < engines.Count; i++) { EngineHandler engine = engines[i]; EngineModuleWrapper.EngineIgnitionState currentIgnitionState = engine.engine.IgnitionState; // If we are transitioning from not ignited to ignited, we do our check // The ignitionFailueRate defines the failure rate per flight data if (currentIgnitionState == EngineModuleWrapper.EngineIgnitionState.IGNITED) { if (engine.ignitionState == EngineModuleWrapper.EngineIgnitionState.NOT_IGNITED || engine.ignitionState == EngineModuleWrapper.EngineIgnitionState.UNKNOWN) { Log(String.Format("IgnitionFail: Engine {0} transitioning to INGITED state", engine.engine.Module.GetInstanceID())); Log(String.Format("IgnitionFail: Checking curves...")); if (baseIgnitionChance != null) { Log("IgnitionFail: baseIgnitionChance is valid"); } else { Log("IgnitionFail: baseIgnitionChance is NULL"); } if (pressureCurve != null) { Log("IgnitionFail: pressureCurve is valid"); } else { Log("IgnitionFail: pressureCurve is NULL"); } double initialFlightData = core.GetInitialFlightData(); float ignitionChance = 1f; float multiplier = 1f; ignitionChance = baseIgnitionChance.Evaluate((float)initialFlightData); if (ignitionChance <= 0) { ignitionChance = 1f; } if (pressureCurve != null) { multiplier = pressureCurve.Evaluate((float)DynamicPressure); } if (multiplier <= 0f) { multiplier = 1f; } if (this.vessel.situation != Vessel.Situations.PRELAUNCH) { ignitionChance *= multiplier; } double 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"); } } } engine.ignitionState = currentIgnitionState; } }