public void OnEnable() { if (core == null) { core = TestFlightUtil.GetCore(this.part, Configuration); } }
private void InitializeParts(Vessel vessel) { foreach (Part part in vessel.parts) { // Each KSP part can be composed of N virtual parts List <string> cores = TestFlightInterface.GetActiveCores(part); if (cores == null || cores.Count <= 0) { continue; } foreach (string activeCore in cores) { ITestFlightCore core = TestFlightUtil.GetCore(part, activeCore); if (core != null) { if (TestFlightManagerScenario.Instance.SettingsAlwaysMaxData) { core.InitializeFlightData(core.GetMaximumData()); } else { TestFlightPartData partData = tfScenario.GetPartDataForPart(activeCore); if (partData != null) { core.InitializeFlightData(partData.GetFloat("flightData")); } else { core.InitializeFlightData(0f); } } } } } }
// Methods for accessing the TestFlight modules on a given part public static string GetFullPartName(Part part) { string baseName = part.name; if (part.Modules == null) { return(baseName); } // New query system // Find the active core ITestFlightCore core = TestFlightUtil.GetCore(part); if (core == null) { return(baseName); } // Look if it has an alias and use that if present string query = core.Configuration; if (query.Contains(":")) { return(query.Split(new char[1] { ':' })[1]); } // Otherwise use part.name else { return(baseName); } }
internal ITestFlightCore GetCore() { if (SelectedPart == null) { return(null); } string configuration; if (SelectedPart.Modules.Contains("ModuleEngineConfigs")) { configuration = (string)(SelectedPart.Modules["ModuleEngineConfigs"].GetType().GetField("configuration").GetValue(SelectedPart.Modules["ModuleEngineConfigs"])); } else { configuration = ""; } ITestFlightCore core = null; foreach (PartModule pm in SelectedPart.Modules) { core = pm as ITestFlightCore; if (core != null && core.Configuration == configuration) { return(core); } } return(null); }
private void InitializeParts(Vessel vessel) { Log("TestFlightManager: Initializing parts for vessel " + vessel.GetName()); // Launch time is equal to current UT unless we have already chached this vessel's launch time double launchTime = Planetarium.GetUniversalTime(); if (knownVessels.ContainsKey(vessel.id)) { launchTime = knownVessels[vessel.id]; } foreach (Part part in vessel.parts) { ITestFlightCore core = TestFlightUtil.GetCore(part); if (core != null) { Log("TestFlightManager: Found core. Getting part data"); PartFlightData partData = tfScenario.GetFlightDataForPartName(TestFlightUtil.GetFullPartName(part)); if (partData == null) { Log("TestFlightManager: Unable to find part data. Starting fresh."); core.InitializeFlightData(null); } else { core.InitializeFlightData(partData.GetFlightData()); } } } }
public static string GetPartTitle(Part part) { string baseName = part.partInfo.title; if (part.Modules == null) { return(baseName); } // Find the active core ITestFlightCore core = TestFlightUtil.GetCore(part); if (core == null) { return(baseName); } if (String.IsNullOrEmpty(core.Title)) { return(baseName); } else { return(core.Title); } }
public void DrawWindow(int windowID) { if (selectedPart != null) { ITestFlightCore core = TestFlightUtil.GetCore(selectedPart); if (core != null) { GUILayout.Label(selectedPart.partInfo.title, Styles.styleEditorTitle); if (show) { List <string> infoParts = core.GetTestFlightInfo(); GUILayout.BeginVertical(); foreach (string info in infoParts) { GUILayout.Label(info, Styles.styleEditorText); } GUILayout.EndVertical(); } else { GUILayout.Space(2.0f); GUILayout.Label("Middle click to show TestFlight info...", Styles.styleEditorText); } } } }
void UpdateVesselInMasterStatusDisplay(Vessel vessel) { if (!masterStatus.ContainsKey(vessel.id)) { return; } var allPartsStatus = masterStatus[vessel.id].allPartsStatus; for (var i = 0; i < allPartsStatus.Count; i++) { var status = allPartsStatus[i]; ITestFlightCore core = status.flightCore; // Update the part status status.partStatus = core.GetPartStatus(); status.failures = core.GetActiveFailures(); status.flightData = core.GetFlightData(); double failureRate = core.GetBaseFailureRate(); MomentaryFailureRate momentaryFailureRate = core.GetWorstMomentaryFailureRate(); if (momentaryFailureRate.valid && momentaryFailureRate.failureRate > failureRate) { failureRate = momentaryFailureRate.failureRate; } status.momentaryFailureRate = failureRate; status.mtbfString = core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, 999); status.runningTime = TestFlightUtil.FormatTime(core.GetBurnTime(), TestFlightUtil.TIMEFORMAT.SHORT_IDENTIFIER, false); allPartsStatus[i] = status; } }
public override void OnStart(StartState state) { base.OnStart(state); if (core == null) { core = TestFlightUtil.GetCore(this.part, Configuration); } }
IEnumerator GetCore() { while (core == null) { core = TestFlightUtil.GetCore(this.part); yield return(null); } }
public virtual float DoRepair() { Failed = false; ITestFlightCore core = TestFlightUtil.GetCore(this.part, Configuration); if (core != null) core.ModifyFlightData(duRepair, true); return 0; }
// 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 static String FailureRateToMTBFString(Part part, string alias, double failureRate, int units, bool shortForm, int maximum) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return(""); } return(core.FailureRateToMTBFString(failureRate, (TestFlightUtil.MTBFUnits)units, shortForm, maximum)); }
/// <summary> /// Triggers the failure controlled by the failure module /// </summary> public virtual void DoFailure() { Failed = true; ITestFlightCore core = TestFlightUtil.GetCore(this.part, Configuration); if (core != null) { core.ModifyFlightData(duFail, true); FlightLogger.eventLog.Add(String.Format("[{0}] {1} failed: {2}", KSPUtil.PrintTimeCompact((int)Math.Floor(this.vessel.missionTime), false), core.Title, failureTitle)); } }
public static List <String> GetAvailableFailures(Part part, string alias) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return(null); } return(core.GetAvailableFailures()); }
/// <summary> /// Triggers the failure controlled by the failure module /// </summary> public virtual void DoFailure() { Failed = true; ITestFlightCore core = TestFlightUtil.GetCore(this.part, Configuration); if (core != null) { core.ModifyFlightData(duFail, true); } }
public static void TriggerNamedFailure(Part part, string alias, String failureModuleName, bool fallbackToRandom) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return; } core.TriggerNamedFailure(failureModuleName, fallbackToRandom); }
public static float ModifyFlightTime(Part part, string alias, float modifier, bool additive) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return(0); } return(core.ModifyFlightTime(modifier, additive)); }
// Returns the total engineer bonus for the current vessel's current crew based on the given part's desired per engineer level bonus public static float GetEngineerDataBonus(Part part, string alias, float partEngineerBonus) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return(1); } return(core.GetEngineerDataBonus(partEngineerBonus)); }
public static bool IsPartOperating(Part part, string alias) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return(false); } return(core.IsPartOperating()); }
public static float ForceRepair(Part part, string alias, ITestFlightFailure failure) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return(-1); } return(core.ForceRepair(failure)); }
// Returns the Operational Time or the time, in MET, since the last time the part was fully functional. // If a part is currently in a failure state, return will be -1 and the part should not fail again // This counts from mission start time until a failure, at which point it is reset to the time the // failure is repaired. It is important to understand this is NOT the total flight time of the part. public static float GetOperatingTime(Part part, string alias) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return(0); } return(core.GetOperatingTime()); }
public static void DisableFailure(Part part, string alias, String failureModuleName) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return; } core.DisableFailure(failureModuleName); }
public static float SetDataCap(Part part, string alias, float cap) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return(float.MaxValue); } return(core.SetDataCap(cap)); }
public static float SetDataRateLimit(Part part, string alias, float limit) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return(1); } return(core.SetDataRateLimit(limit)); }
// Cause a failure to occur, either a random failure or a specific one // If fallbackToRandom is true, then if the specified failure can't be found or can't be triggered, a random failure will be triggered instead public static void TriggerFailure(Part part, string alias) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return; } core.TriggerFailure(); }
/// <summary> /// Triggers the failure controlled by the failure module /// </summary> public virtual void DoFailure() { Failed = true; ITestFlightCore core = TestFlightUtil.GetCore(this.part); if (core != null) { core.ModifyFlightData(duFail, true); } FlightLogger.eventLog.Add(String.Format("[{0}] {1} failed: {2}", TestFlightUtil.FormatTime(this.vessel.missionTime), TestFlightUtil.GetPartTitle(this.part), failureTitle)); }
public virtual float DoRepair() { Failed = false; ITestFlightCore core = TestFlightUtil.GetCore(this.part); if (core != null) { core.ModifyFlightData(duRepair, true); } return(0); }
public static void Log(string message, Part loggingPart) { ITestFlightCore core = TestFlightUtil.GetCore(loggingPart); bool debug = false; if (core != null) { debug = core.DebugEnabled; } TestFlightUtil.Log(message, debug); }
public static float GetMaximumFlightData(Part part, string alias) { ITestFlightCore core = TestFlightInterface.GetCore(part, alias); if (core == null) { return(0); } return(core.GetMaximumData()); }
IEnumerator Attach() { while (this.part == null || this.part.partInfo == null || this.part.partInfo.partPrefab == null || this.part.Modules == null) yield return null; while (core == null) { core = TestFlightUtil.GetCore(this.part); yield return null; } Startup(); }
public override void OnStart(StartState state) { base.OnStart(state); core = TestFlightUtil.GetCore(this.part); if (core == null) StartCoroutine("GetCore"); }
IEnumerator Attach() { while (this.part == null || this.part.Modules == null) yield return null; while (core == null) { core = TestFlightUtil.GetCore(this.part, Configuration); yield return null; } Startup(); }
public void OnEnable() { if (core == null) core = TestFlightUtil.GetCore(this.part, Configuration); if (core != null) Startup(); }
public override void OnStart(StartState state) { base.OnStart(state); if (core == null) core = TestFlightUtil.GetCore(this.part, Configuration); if (core != null) Startup(); }
IEnumerator GetCore() { while (core == null) { core = TestFlightUtil.GetCore(this.part); yield return null; } }