public override void FailPart() { if (chute == null) { return; } if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } if (chute.vessel != FlightGlobals.ActiveVessel) { return; } if (hasFailed) { return; } if (ModWrapper.FerramWrapper.IsDeployed(chute)) { ModWrapper.FerramWrapper.CutChute(chute); chute.Events["GUIRepack"].active = false; } else { ModWrapper.FerramWrapper.DeployChute(chute); //Will deploy the chute right away, ignoring chutes min altitude/pressure. chute.Events["GUIDisarm"].active = false; chute.Events["GUIRepack"].active = false; } hasFailed = true; }
//turns the RCS off. protected override void FailPart() { if (rcs == null) { return; } if (rcs.vessel != FlightGlobals.ActiveVessel) { return; } rcs.rcsEnabled = false; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } if (message) { return; } message = true; postMessage = true; if (vessel.vesselType != VesselType.Debris) { ScreenMessages.PostScreenMessage("RCS Failure!"); } Debug.Log("[OhScrap]: " + SYP.ID + " RCS has failed"); }
// Reaction wheel stops working protected override void FailPart() { rw = part.FindModuleImplementing <ModuleReactionWheel>(); if (!rw.isEnabled && rw.wheelState != ModuleReactionWheel.WheelState.Active) { return; } rw.isEnabled = false; rw.wheelState = ModuleReactionWheel.WheelState.Broken; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } if (message) { return; } message = true; if (rw.wheelState != ModuleReactionWheel.WheelState.Broken) { Debug.Log("[OhScrap]: " + SYP.ID + "'s reaction wheels have failed"); } if (vessel.vesselType != VesselType.Debris) { ScreenMessages.PostScreenMessage("A reaction wheel has failed"); } }
//Assuming that part has a resource that is not on the blacklist, it will leak. protected override void FailPart() { if (leaking == null) { if (leakingName != "None") { leaking = part.Resources[leakingName]; failureType = leaking.resourceName + " leak"; return; } List <PartResource> potentialLeakCache = part.Resources.ToList(); List <PartResource> potentialLeaks = part.Resources.ToList(); if (potentialLeaks.Count == 0) { return; } ConfigNode[] blackListNode = GameDatabase.Instance.GetConfigNodes("OHSCRAP_RESOURCE_BLACKLIST"); if (blackListNode.Count() > 0) { for (int i = 0; i < blackListNode.Count(); i++) { ConfigNode node = blackListNode.ElementAt(i); #if DEBUG Debug.Log("[UPFM]: Checking " + node.GetValue("name") + " for blacklist"); #endif for (int p = 0; p < potentialLeakCache.Count(); p++) { PartResource pr = potentialLeakCache.ElementAt(p); if (pr.resourceName == node.GetValue("name")) { potentialLeaks.Remove(pr); } } } if (potentialLeaks.Count == 0) { leaking = null; leakingName = "None"; hasFailed = false; willFail = false; postMessage = false; Debug.Log("[OhScrap]: " + SYP.ID + "has no resources that could fail. Failure aborted"); return; } } leaking = potentialLeaks.ElementAt(Randomiser.instance.RandomInteger(0, potentialLeaks.Count())); leakingName = leaking.resourceName; Debug.Log("[OhScrap]: " + leaking.resourceName + " started leaking from " + SYP.ID); if (vessel.vesselType != VesselType.Debris) { ScreenMessages.PostScreenMessage("A tank of " + leaking.resourceName + " started to leak!"); } failureType = leaking.resourceName + " leak"; } leaking.amount = leaking.amount * 0.999f; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } }
//Cuts the chute if it's deployed protected override void FailPart() { if (chute == null) { return; } if (chute.vessel != FlightGlobals.ActiveVessel) { return; } if (chute.deploymentState == ModuleParachute.deploymentStates.SEMIDEPLOYED || chute.deploymentState == ModuleParachute.deploymentStates.DEPLOYED) { chute.CutParachute(); } if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } if (message) { return; } message = true; postMessage = true; if (vessel.vesselType != VesselType.Debris) { ScreenMessages.PostScreenMessage("Parachute Failure!"); } Debug.Log("[OhScrap]: " + SYP.ID + " parachute has failed"); }
protected override void FailPart() { //If the part can't retract will always get a sun tracking error, otherwise it will get a retraction or sun tracking at random. panel = part.FindModuleImplementing <ModuleDeployableSolarPanel>(); if (panel == null) { return; } if (!panel.isTracking) { return; } if (!postMessage && !trackingSet) { if (Randomiser.instance.NextDouble() < 0.5) { trackingFailure = true; } else { trackingFailure = false; } trackingSet = true; } if (panel.isTracking && panel.retractable && panel.deployState == ModuleDeployablePart.DeployState.EXTENDED && !trackingFailure) { panel.retractable = false; originallyRetractable = true; if (!postMessage) { failureType = "retraction error"; if (vessel.vesselType != VesselType.Debris) { ScreenMessages.PostScreenMessage(part.partInfo.title + " retraction mechanism jammed"); } Debug.Log("[OhScrap]: " + SYP.ID + " retraction mechanism has jammed"); postMessage = true; } if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } } else if (panel.isTracking && panel.deployState == ModuleDeployablePart.DeployState.EXTENDED && !originallyRetractable) { panel.isTracking = false; if (!postMessage) { failureType = "sun tracking error"; ScreenMessages.PostScreenMessage(part.partInfo.title + " sun tracking mechanism jammed"); Debug.Log("[OhScrap]: " + SYP.ID + " sun tracking mechanism has jammed"); postMessage = true; } if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } } }
// Reaction wheel stops working public override void FailPart() { if (!rw) return; rw.isEnabled = false; rw.wheelState = ModuleReactionWheel.WheelState.Broken; if (OhScrap.highlight) OhScrap.SetFailedHighlight(); hasFailed = true; }
// Failure will drain the battery and stop it from recharging. public override void FailPart() { battery.amount = 0; battery.flowState = false; if (OhScrap.highlight) OhScrap.SetFailedHighlight(); if (hasFailed) return; Debug.Log("[OhScrap]: " + SYP.ID + " has suffered a short circuit failure"); }
//This actually makes the failure happen public override void FailPart() { _alternator.enabled = false; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } }
// Reaction wheel stops working public override void FailPart() { rw = part.FindModuleImplementing <ModuleReactionWheel>(); rw.isEnabled = false; rw.wheelState = ModuleReactionWheel.WheelState.Broken; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } hasFailed = true; }
//turns the RCS off. public override void FailPart() { if (rcs == null) { return; } rcs.rcsEnabled = false; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } }
//Assuming that part has a resource that is not on the blacklist, it will leak. public override void FailPart() { if (leaking == null) { if (leakingName != "None") { leaking = part.Resources[leakingName]; failureType = leaking.resourceName + " leak"; return; } List <PartResource> potentialLeakCache = part.Resources.ToList(); List <PartResource> potentialLeaks = part.Resources.ToList(); if (potentialLeaks.Count == 0) { return; } ConfigNode[] blackListNode = GameDatabase.Instance.GetConfigNodes("OHSCRAP_RESOURCE_BLACKLIST"); if (blackListNode.Count() > 0) { for (int i = 0; i < blackListNode.Count(); i++) { ConfigNode node = blackListNode.ElementAt(i); #if DEBUG Debug.Log("[UPFM]: Checking " + node.GetValue("name") + " for blacklist"); #endif for (int p = 0; p < potentialLeakCache.Count(); p++) { PartResource pr = potentialLeakCache.ElementAt(p); if (pr.resourceName == node.GetValue("name")) { potentialLeaks.Remove(pr); } } } if (potentialLeaks.Count == 0) { leaking = null; leakingName = "None"; cantLeak = true; Debug.Log("[OhScrap]: " + SYP.ID + "has no resources that could fail. Failure aborted"); return; } } leaking = potentialLeaks.ElementAt(UPFMUtils.instance._randomiser.Next(0, potentialLeaks.Count())); leakingName = leaking.resourceName; failureType = leaking.resourceName + " leak"; } leaking.amount = leaking.amount * 0.999f; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } }
public override void FailPart() { if (!FARControlSurface) { return; } if (!hasFailed) { failMode = _randomizer.Next(1, weightTotal + 1); //failTimeBrakeRudder = ModWrapper.FerramWrapper.GetCtrlSurfBrakeRudder(FARControlSurface); resetScenario.failTimeYaw = ModWrapper.FerramWrapper.GetCtrlSurfYaw(FARControlSurface); resetScenario.failTimePitch = ModWrapper.FerramWrapper.GetCtrlSurfPitch(FARControlSurface); resetScenario.failTimeRoll = ModWrapper.FerramWrapper.GetCtrlSurfRoll(FARControlSurface); } if (failMode <= stuckWeight) //Stuck Surface. { if (!hasFailed) { Debug.Log("[OhScrap](FAR): " + SYP.ID + " has a stuck control surface"); hasFailed = true; } stuckScenario.Run(FARControlSurface); } else //Hinge Failure. { if (!hasFailed) { Debug.Log("[OhScrap](FAR): " + SYP.ID + " Control surface hinge failure."); hasFailed = true; } int adjustmentRoll = _randomizer.Next(1, hingeWeightTotal + 1); int counter = hingeFailureScenarios.Count - 1; Scenario s = null; while (counter >= 0) { s = hingeFailureScenarios.ElementAt(counter); if ((adjustmentRoll -= s.Weight) <= 0) { counter = 0; } counter--; } s.Run(FARControlSurface); if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } } }
public override void FailPart() { if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } ModWrapper.RemoteTechWrapper.SetRTBrokenStatus(antenna, true); if (hasFailed) { return; } Debug.Log("[OhScrap](RemoteTech): " + SYP.ID + " has stopped transmitting"); }
public override void FailPart() { //if this is the first time we've failed this antenna, we need to make a note of the original power for when it's repaired. if (!hasFailed) { originalPower = antenna.antennaPower; Debug.Log("[OhScrap]: " + SYP.ID + " has stopped transmitting"); } if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } antenna.antennaPower = 0; }
// Failure will drain the battery and stop it from recharging. public override void FailPart() { battery = part.Resources["ElectricCharge"]; battery.amount = 0; battery.flowState = false; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } if (hasFailed) { return; } Debug.Log("[OhScrap]: " + SYP.ID + " has suffered a short circuit failure"); }
//control surface will stick and not respond to input public override void FailPart() { controlSurface = part.FindModuleImplementing <ModuleControlSurface>(); controlSurface.ignorePitch = true; controlSurface.ignoreRoll = true; controlSurface.ignoreYaw = true; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } if (hasFailed) { return; } Debug.Log("[OhScrap]: " + SYP.ID + " has suffered a control surface failure"); }
//turns the RCS off. public override void FailPart() { rcs = part.FindModuleImplementing <ModuleRCS>(); if (rcs == null) { return; } rcs.rcsEnabled = false; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } if (hasFailed) { return; } }
//control surface will stick and not respond to input public override void FailPart() { if (!controlSurface) { return; } if (!hasFailed) { Debug.Log("[OhScrap]: " + SYP.ID + " has suffered a control surface failure"); } if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } controlSurface.ignorePitch = true; controlSurface.ignoreRoll = true; controlSurface.ignoreYaw = true; }
public override void FailPart() { //If the part can't retract will always get a sun tracking error, otherwise it will get a retraction or sun tracking at random. panel = part.FindModuleImplementing <ModuleDeployableSolarPanel>(); if (panel == null) { return; } if (!trackingSet) { if (UPFMUtils.instance._randomiser.NextDouble() < 0.5) { trackingFailure = true; } else { trackingFailure = false; } trackingSet = true; } if (panel.isTracking && panel.retractable && panel.deployState == ModuleDeployablePart.DeployState.EXTENDED && !trackingFailure) { panel.retractable = false; originallyRetractable = true; if (!hasFailed) { failureType = "Retraction Error"; } if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } } else if (panel.isTracking && panel.deployState == ModuleDeployablePart.DeployState.EXTENDED && !originallyRetractable) { panel.isTracking = false; failureType = "Sun Tracking Error"; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } } }
//Cuts the chute if it's deployed public override void FailPart() { if (chute == null) { return; } if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } if (chute.vessel != FlightGlobals.ActiveVessel) { return; } if (chute.deploymentState == ModuleParachute.deploymentStates.SEMIDEPLOYED || chute.deploymentState == ModuleParachute.deploymentStates.DEPLOYED) { chute.CutParachute(); } }
// Failure will drain the battery and stop it from recharging. protected override void FailPart() { battery = part.Resources["ElectricCharge"]; battery.amount = 0; battery.flowState = false; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } if (message) { return; } if (vessel.vesselType != VesselType.Debris) { ScreenMessages.PostScreenMessage("Battery short circuited!"); } Debug.Log("[OhScrap]: " + SYP.ID + " has suffered a short circuit failure"); message = true; }
//control surface will stick and not respond to input protected override void FailPart() { controlSurface = part.FindModuleImplementing <ModuleControlSurface>(); controlSurface.ignorePitch = true; controlSurface.ignoreRoll = true; controlSurface.ignoreYaw = true; if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } if (message) { return; } if (vessel.vesselType != VesselType.Debris) { ScreenMessages.PostScreenMessage("Control Surface Failure!"); } Debug.Log("[OhScrap]: " + SYP.ID + " has suffered a control surface failure"); message = true; }
//Part will just shutdown and not be restartable. public override void FailPart() { if (KRASHWrapper.simulationActive()) { return; } if (engine.currentThrottle == 0) { return; } engine.allowShutdown = true; engine.allowRestart = false; hasFailed = true; engine.Shutdown(); if (!message) { if (vessel.vesselType != VesselType.Debris) { ScreenMessages.PostScreenMessage(part.partInfo.title + " has failed to ignite"); } StringBuilder msg = new StringBuilder(); msg.AppendLine(part.vessel.vesselName); msg.AppendLine(""); msg.AppendLine(part.partInfo.title + " has suffered an " + failureType); msg.AppendLine(""); MessageSystem.Message m = new MessageSystem.Message("OhScrap", msg.ToString(), MessageSystemButton.MessageButtonColor.ORANGE, MessageSystemButton.ButtonIcons.ALERT); MessageSystem.Instance.AddMessage(m); message = true; } if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } CancelInvoke("FailPart"); Logger.instance.Log("[OhScrap]: " + part.partInfo.title + " has failed to ignite"); }
//Part will just shutdown and not be restartable. public override void FailPart() { if (engine.currentThrottle == 0) { return; } engine.allowShutdown = true; engine.allowRestart = false; hasFailed = true; engine.Shutdown(); if (!message) { if (vessel.vesselType != VesselType.Debris) { ScreenMessages.PostScreenMessage(part.partInfo.title + " has failed to ignite"); } message = true; } if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } CancelInvoke("FailPart"); }
public override void FailPart() { if (!engine) { return; } //In the event of a fuel line leak, the chance of explosion will be reset if the engine is shut down. if (engine.currentThrottle == 0) { fuelLineCounter = 5; return; } if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } //Randomly pick which failure we will give the player if (failureType == "none") { int i = UPFMUtils.instance._randomiser.Next(1, 7); switch (i) { case 1: failureType = "Fuel Flow Failure"; Debug.Log("[OhScrap]: attempted to perform Fuel Flow Failure on " + SYP.ID); break; case 2: failureType = "Fuel Line Leak"; Debug.Log("[OhScrap]: attempted to perform Fuel Line Leak on " + SYP.ID); InvokeRepeating("LeakFuel", 2.0f, 2.0f); break; case 3: failureType = "Underthrust"; Debug.Log("[OhScrap]: attempted to perform Underthrust on " + SYP.ID); break; case 4: if (gimbal == null) { return; } failureType = "Gimbal Failure"; Debug.Log("[OhScrap]: attempted to lock gimbal on " + SYP.ID); break; case 5: failureType = "Stable Underthrust"; Debug.Log("[OhScrap]: attempted to perform Stable Underthrust on " + SYP.ID); break; case 6: failureType = "Performance Loss"; Debug.Log("[OhScrap]: attempted to perform Performance Loss on " + SYP.ID); break; default: failureType = "none"; Debug.Log("[OhScrap]: " + SYP.ID + " decided not to fail after all"); break; } return; } switch (failureType) { //Engine shutdown case "Fuel Flow Failure": engine.Shutdown(); break; //Fuel line leaks will explode the engine after anywhere between 5 and 50 seconds. case "Fuel Line Leak": if (timeBetweenFailureEvents > Planetarium.GetUniversalTime()) { break; } if (fuelLineCounter < 0) { part.explode(); } else { fuelLineCounter--; } timeBetweenFailureEvents = Planetarium.GetUniversalTime() + UPFMUtils.instance._randomiser.Next(1, 5); break; //Engine will constantly lose thrust case "Underthrust": if (timeBetweenFailureEvents <= Planetarium.GetUniversalTime()) { fuelFlowMultiplier *= 0.9f; timeBetweenFailureEvents = Planetarium.GetUniversalTime() + UPFMUtils.instance._randomiser.Next(10, 30); } engineWrapper.SetFuelFlowMult(fuelFlowMultiplier); break; //lock gimbal case "Gimbal Failure": gimbal.gimbalLock = true; break; // Engine permanently has 50% max thrust case "Stable Underthrust": engineWrapper.SetFuelFlowMult(0.5f); break; // Isp and thrust both set to 50% of normal case "Performance Loss": engineWrapper.SetFuelIspMult(0.5f); break; default: return; } }
protected override void FailPart() { engine = part.FindModuleImplementing <ModuleEngines>(); gimbal = part.FindModuleImplementing <ModuleGimbal>(); if (engine != null) { //In the event of a fuel line leak, the chance of explosion will be reset if the engine is shut down. if (engine.currentThrottle == 0) { fuelLineCounter = 5; return; } } if (OhScrap.highlight) { OhScrap.SetFailedHighlight(); } //Randomly pick which failure we will give the player if (failureType == "none") { int i = Randomiser.instance.RandomInteger(1, 5); switch (i) { case 1: failureType = "Fuel Flow Failure"; Debug.Log("[OhScrap]: attempted to perform Fuel Flow Failure on " + SYP.ID); break; case 2: failureType = "Fuel Line Leak"; Debug.Log("[OhScrap]: attempted to perform Fuel Line Leak on " + SYP.ID); InvokeRepeating("LeakFuel", 2.0f, 2.0f); break; case 3: failureType = "Underthrust"; originalThrust = engine.thrustPercentage; Debug.Log("[OhScrap]: attempted to perform Underthrust on " + SYP.ID); break; case 4: if (gimbal == null) { return; } failureType = "Gimbal Failure"; Debug.Log("[OhScrap]: attempted to lock gimbal on" + SYP.ID); break; default: failureType = "none"; Debug.Log("[OhScrap]: " + SYP.ID + " decided not to fail after all"); break; } if (vessel.vesselType != VesselType.Debris) { ScreenMessages.PostScreenMessage(failureType + " detected on " + part.partInfo.title); } postMessage = true; return; } switch (failureType) { //Engine shutdown case "Fuel Flow Failure": engine.Shutdown(); break; //Fuel line leaks will explode the engine after anywhere between 5 and 50 seconds. case "Fuel Line Leak": if (timeBetweenFailureEvents > Planetarium.GetUniversalTime()) { break; } if (fuelLineCounter < 0) { part.explode(); } else { fuelLineCounter--; } timeBetweenFailureEvents = Planetarium.GetUniversalTime() + Randomiser.instance.RandomInteger(1, 10); break; //Engine will constantly lose thrust case "Underthrust": if (timeBetweenFailureEvents <= Planetarium.GetUniversalTime()) { engine.thrustPercentage = engine.thrustPercentage * 0.9f; timeBetweenFailureEvents = Planetarium.GetUniversalTime() + Randomiser.instance.RandomInteger(10, 30); staticThrust = engine.thrustPercentage; } engine.thrustPercentage = staticThrust; break; //lock gimbal case "Gimbal Failure": gimbal.gimbalLock = true; break; default: return; } }