diff --git a/TestFlightAPI/TestFlightAPI/TestFlightAPI.cs b/TestFlightAPI/TestFlightAPI/TestFlightAPI.cs index e27fdb9..1c034f0 100644 --- a/TestFlightAPI/TestFlightAPI/TestFlightAPI.cs +++ b/TestFlightAPI/TestFlightAPI/TestFlightAPI.cs @@ -720,7 +720,13 @@ string Configuration /// /// The current burn time for scope or 0 if this module does not track burn time. float GetScopedRunTime(RatingScope ratingScope); - + + /// + /// Sets the current burn time for the given scope. + /// Does nothing if this module does not track burn time. + /// + void SetScopedRunTime(RatingScope ratingScope, float time); + /// /// Should return a string if the module wants to report any information to the user in the TestFlight Editor window. /// @@ -959,6 +965,8 @@ bool DebugEnabled float GetRunTime(RatingScope ratingScope); + void ResetRunTime(); + /// /// Called whenever an Interop value is added, changed, or removed to allow the modules on the part to update to the proper config /// diff --git a/TestFlightAPI/TestFlightAPI/TestFlightReliability.cs b/TestFlightAPI/TestFlightAPI/TestFlightReliability.cs index 0f0dfd2..cb1c263 100644 --- a/TestFlightAPI/TestFlightAPI/TestFlightReliability.cs +++ b/TestFlightAPI/TestFlightAPI/TestFlightReliability.cs @@ -256,6 +256,10 @@ public virtual float GetScopedRunTime(RatingScope ratingScope) { return 0f; } + + public virtual void SetScopedRunTime(RatingScope ratingScope, float time) + { + } } } diff --git a/TestFlightCore/TestFlightCore/TestFlightCore.cs b/TestFlightCore/TestFlightCore/TestFlightCore.cs index 1f5ce81..8d6e7a9 100644 --- a/TestFlightCore/TestFlightCore/TestFlightCore.cs +++ b/TestFlightCore/TestFlightCore/TestFlightCore.cs @@ -297,6 +297,17 @@ public float GetRunTime(RatingScope ratingScope) return burnTime; } + public void ResetRunTime() + { + List reliabilityModules = TestFlightUtil.GetReliabilityModules(this.part, Alias); + + foreach (ITestFlightReliability rm in reliabilityModules) + { + rm.SetScopedRunTime(RatingScope.Continuous, 0); + rm.SetScopedRunTime(RatingScope.Cumulative, 0); + } + } + // Get the momentary (IE current dynamic) failure rates (Can vary per reliability/failure modules) // These methods will let you get a list of all momentary rates or you can get the best (lowest chance of failure)/worst (highest chance of failure) rates public MomentaryFailureRate GetWorstMomentaryFailureRate() @@ -1020,6 +1031,7 @@ public float ForceRepair(ITestFlightFailure failure) return 0; failure.ForceRepair(); + failures.Remove(failure); // update our major failure flag in case this repair changes things hasMajorFailure = HasMajorFailure(); @@ -1033,7 +1045,7 @@ private bool HasMajorFailure() return true; return false; } - + private void PollExistingFailuresOnStart() { List m = TestFlightUtil.GetFailureModules(this.part, Alias); diff --git a/TestFlightCore/TestFlightCore/TestFlightInterface.cs b/TestFlightCore/TestFlightCore/TestFlightInterface.cs index 3ebac6b..fe49389 100644 --- a/TestFlightCore/TestFlightCore/TestFlightInterface.cs +++ b/TestFlightCore/TestFlightCore/TestFlightInterface.cs @@ -78,13 +78,61 @@ public static bool TestFlightAvailable(Part part) else return true; } + + public static void ResetAllFailuresOnVessel(Vessel vessel) + { + foreach (Part part in vessel.parts) + { + ITestFlightCore core = GetCore(part); + if (core == null) continue; + + List failures = core.GetActiveFailures(); + for (int i = failures.Count - 1; i >= 0; i--) + { + core.ForceRepair(failures[i]); + } + } + } + + public static void ResetAllRunTimesOnVessel(Vessel vessel) + { + foreach (Part part in vessel.parts) + { + ITestFlightCore core = GetCore(part); + if (core == null) continue; + + core.ResetRunTime(); + } + } + /// - /// 0 = OK, 1 = Minor Failure, 2 = Failure, 3 = Major Failure, -1 = Could not find TestFlight Core on Part + /// 0 = OK, 1 = Has failure, -1 = Could not find TestFlight Core on Part + /// + /// The part status. + public static int GetVesselStatus(Vessel vessel) + { + int retVal = -1; + foreach (Part part in vessel.parts) + { + int statusForPart; + ITestFlightCore core = GetCore(part); + if (core == null) + statusForPart = - 1; + else + statusForPart = core.GetPartStatus(); + retVal = Math.Max(retVal, statusForPart); + } + + return retVal; + } + + /// + /// 0 = OK, 1 = Has failure, -1 = Could not find TestFlight Core on Part /// /// The part status. public static int GetPartStatus(Part part, string alias) { - ITestFlightCore core = TestFlightInterface.GetCore(part, alias); + ITestFlightCore core = GetCore(part, alias); if (core == null) return -1; @@ -346,6 +394,11 @@ public static bool IsPartOperating(Part part, string alias) } // Methods for accessing the TestFlight modules on a given part + // Get the active Core Module - can only ever be one. + public static ITestFlightCore GetCore(Part part) + { + return TestFlightUtil.GetCore(part); + } // Get the active Core Modules that are bound to a given alias public static ITestFlightCore GetCore(Part part, string alias) { diff --git a/TestFlightReliability_EngineCycle.cs b/TestFlightReliability_EngineCycle.cs index f6f40d5..7a8d4c5 100644 --- a/TestFlightReliability_EngineCycle.cs +++ b/TestFlightReliability_EngineCycle.cs @@ -378,6 +378,21 @@ public override float GetScopedRunTime(RatingScope ratingScope) } } + public override void SetScopedRunTime(RatingScope ratingScope, float time) + { + switch (ratingScope) + { + case RatingScope.Cumulative: + engineOperatingTime = time; + break; + case RatingScope.Continuous: + currentRunTime = time; + break; + default: + break; + } + } + public override void OnAwake() { base.OnAwake();