Beispiel #1
0
 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);
                     }
                 }
             }
         }
     }
 }
        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));
        }
        public static String GetScopeForSituationAndBody(Vessel.Situations situation, String body)
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                return("none");
            }
            String situationStr = situation.ToString();

            return(TestFlightInterface.GetScopeForSituationAndBody(situationStr, body));
        }
        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 List <String> GetAvailableFailures(Part part, string alias)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part, alias);

            if (core == null)
            {
                return(null);
            }
            return(core.GetAvailableFailures());
        }
        public static String GetScopeForSituationAndBody(String situation, CelestialBody body)
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                return("none");
            }
            String bodyStr = body.GetName();

            return(TestFlightInterface.GetScopeForSituationAndBody(situation, bodyStr));
        }
        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));
        }
        // 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 double GetEngineerDataBonus(Part part, double partEngineerBonus)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part);

            if (core == null)
            {
                return(1);
            }

            return(core.GetEngineerDataBonus(partEngineerBonus));
        }
        public static bool AddInteropValue(Part part, string name, bool value, string owner)
        {
            ITestFlightInterop op = TestFlightInterface.GetInterop(part);

            if (op == null)
            {
                return(false);
            }

            return(op.AddInteropValue(name, value, owner));
        }
        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));
        }
        public static void DisableFailure(Part part, string alias, String failureModuleName)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part, alias);

            if (core == null)
            {
                return;
            }

            core.DisableFailure(failureModuleName);
        }
        // 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));
        }
        /// <summary>
        /// 0 = OK, 1 = Minor Failure, 2 = Failure, 3 = Major Failure, -1 = Could not find TestFlight Core on Part
        /// </summary>
        /// <returns>The part status.</returns>
        public static int GetPartStatus(Part part, string alias)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part, alias);

            if (core == null)
            {
                return(-1);
            }

            return(core.GetPartStatus());
        }
        public static double ForceRepair(Part part)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part);

            if (core == null)
            {
                return(-1);
            }

            return(core.ForceRepair());
        }
        // 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 double GetOperatingTime(Part part)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part);

            if (core == null)
            {
                return(0);
            }

            return(core.GetOperatingTime());
        }
        public static void EnableFailure(Part part, String failureModuleName)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part);

            if (core == null)
            {
                return;
            }

            core.EnableFailure(failureModuleName);
        }
        public static String GetScopeForSituation(String situation)
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                return("none");
            }

            String body = FlightGlobals.ActiveVessel.mainBody.GetName();

            return(TestFlightInterface.GetScopeForSituationAndBody(situation, body));
        }
        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 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));
        }
        // Get the base or static failure rate
        public static double GetBaseFailureRate(Part part, string alias)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part, alias);

            if (core == null)
            {
                return(TestFlightUtil.MIN_FAILURE_RATE);
            }

            return(core.GetBaseFailureRate());
        }
        // 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();
        }
        // Get the Reliability Curve for the part
        public static FloatCurve GetBaseReliabilityCurve(Part part, string alias)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part, alias);

            if (core == null)
            {
                return(null);
            }

            return(core.GetBaseReliabilityCurve());
        }
        public static double GetMomentaryFailureRateForTrigger(Part part, string alias, String trigger)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part, alias);

            if (core == null)
            {
                return(TestFlightUtil.MIN_FAILURE_RATE);
            }

            return(core.GetMomentaryFailureRateForTrigger(trigger));
        }
        // The momentary failure rate is tracked per named "trigger" which allows multiple Reliability or FailureTrigger modules to cooperate
        // Returns the total modified failure rate back to the caller for convenience
        public static double SetTriggerMomentaryFailureModifier(Part part, string alias, String trigger, double multiplier, PartModule owner)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part, alias);

            if (core == null)
            {
                return(TestFlightUtil.MIN_FAILURE_RATE);
            }

            return(core.SetTriggerMomentaryFailureModifier(trigger, multiplier, owner));
        }
        // 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 double SetDataCap(Part part, double cap)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part);

            if (core == null)
            {
                return(double.MaxValue);
            }

            return(core.SetDataCap(cap));
        }
        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 GetMaximumFlightData(Part part, string alias)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part, alias);

            if (core == null)
            {
                return(0);
            }

            return(core.GetMaximumData());
        }
        public static double SetDataRateLimit(Part part, double limit)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part);

            if (core == null)
            {
                return(1);
            }

            return(core.SetDataRateLimit(limit));
        }
        public static double ModifyFlightTimeForScope(Part part, double modifier, String scope, bool additive)
        {
            ITestFlightCore core = TestFlightInterface.GetCore(part);

            if (core == null)
            {
                return(0);
            }

            return(core.ModifyFlightTimeForScope(modifier, scope, additive));
        }