/// <summary>
        /// Determines the starting part in the failure.
        /// </summary>
        private void PrepareStartingPart()
        {
            Log.Info("PrepareStartingPart");
            // Find engines
            List <Part>         activeEngineParts  = activeVessel.GetActiveParts().Where(o => KLFUtils.PartIsActiveEngine(o)).ToList();
            List <Part>         radialDecouplers   = activeVessel.Parts.Where(o => KLFUtils.PartIsRadialDecoupler(o)).ToList();
            List <Part>         controlSurfaces    = activeVessel.Parts.Where(o => KLFUtils.PartIsControlSurface(o)).ToList();
            List <CompoundPart> strutsAndFuelLines = activeVessel.Parts.OfType <CompoundPart>().Where(o => KLFUtils.PartIsStrutOrFuelLine(o)).ToList();

            int cnt = activeEngineParts.Count + radialDecouplers.Count + controlSurfaces.Count + strutsAndFuelLines.Count;

            // If there are no active engines or radial decouplers, skip this attempt.
            if (cnt == 0)
            {
                return;
            }

            // Determine the starting part.
            int startingPartIndex = KLFUtils.RNG.Next(0, cnt);

            Log.Info("activeEngineParts.Count: " + activeEngineParts.Count.ToString() + "    radialDecouplers.Count: " + radialDecouplers.Count.ToString() +
                     "   controlSurfaces.Count: " + controlSurfaces.Count.ToString() + "   strutsAndFuelLines.Count: " + strutsAndFuelLines.Count);
            Log.Info("startingPartIndex: " + startingPartIndex.ToString());

            // for debugging only: startingPartIndex = activeEngineParts.Count;
            int offset = 0;

            if (startingPartIndex < activeEngineParts.Count)
            {
                startingPart = activeEngineParts[startingPartIndex];
                failureType  = FailureType.engine;

                // Get the engine module for the part.
                startingPartEngineModule = startingPart.Modules.OfType <ModuleEngines>().Single();
            }
            offset += activeEngineParts.Count;
            if (startingPartIndex >= offset && startingPartIndex < offset + radialDecouplers.Count)
            {
                startingPart = radialDecouplers[startingPartIndex - offset];

                failureType       = FailureType.radialDecoupler;
                decouplerForceCnt = 0;
            }
            offset += radialDecouplers.Count;
            if (startingPartIndex >= offset && startingPartIndex < offset + controlSurfaces.Count)
            {
                startingPart = controlSurfaces[startingPartIndex - offset];

                failureType       = FailureType.controlSurface;
                decouplerForceCnt = 0;
            }
            offset += controlSurfaces.Count;
            if (startingPartIndex >= offset && startingPartIndex < offset + strutsAndFuelLines.Count)
            {
                startingPart = strutsAndFuelLines[startingPartIndex - offset];

                failureType       = FailureType.strutOrFuelLine;
                decouplerForceCnt = 0;
            }



#if false
            if (startingPartIndex >= activeEngineParts.Count)
            {
                startingPart = radialDecouplers[startingPartIndex - activeEngineParts.Count];

                failureType       = FailureType.radialDecoupler;
                decouplerForceCnt = 0;
            }
            else
            {
                startingPart = activeEngineParts[startingPartIndex];
                failureType  = FailureType.engine;

                // Get the engine module for the part.
                startingPartEngineModule = startingPart.Modules.OfType <ModuleEngines>().Single();
            }
#endif
            // Setup tick information for the part explosion loop.
            ticksBetweenPartFailures = (int)(KLFUtils.GameTicksPerSecond * KLFSettings.Instance.DelayBetweenPartFailures);
            ticksSinceFailureStart   = 0;
            thrustOverload           = 0;
            underThrustStart         = 100f;
            underThrustEnd           = 100f;
        }
Esempio n. 2
0
        /// <summary>
        /// Determines the starting part in the failure.
        /// </summary>
        private void PrepareStartingPart()
        {
            Log.Info("PrepareStartingPart");
            // Find engines
            bool b = !experimentalPartFailure;

            List <Part>         activeEngineParts  = activeVessel.GetActiveParts().Where(o => KLFUtils.PartIsActiveEngine(o, b)).ToList();
            List <Part>         radialDecouplers   = activeVessel.Parts.Where(o => KLFUtils.PartIsRadialDecoupler(o, b)).ToList();
            List <Part>         controlSurfaces    = activeVessel.Parts.Where(o => KLFUtils.PartIsControlSurface(o, b)).ToList();
            List <CompoundPart> strutsAndFuelLines = activeVessel.Parts.OfType <CompoundPart>().Where(o => KLFUtils.PartIsStrutOrFuelLine(o, b)).ToList();

            int cnt = activeEngineParts.Count + radialDecouplers.Count + controlSurfaces.Count + strutsAndFuelLines.Count;

            // If there are no active engines or radial decouplers, skip this attempt.
            if (cnt == 0)
            {
                return;
            }

            // Determine the starting part.
            int startingPartIndex = KLFUtils.RNG.Next(0, cnt);

            Log.Info("activeEngineParts.Count: " + activeEngineParts.Count.ToString() + "    radialDecouplers.Count: " + radialDecouplers.Count.ToString() +
                     "   controlSurfaces.Count: " + controlSurfaces.Count.ToString() + "   strutsAndFuelLines.Count: " + strutsAndFuelLines.Count);
            Log.Info("startingPartIndex: " + startingPartIndex.ToString());

            // for debugging only: startingPartIndex = activeEngineParts.Count;
            int offset = 0;

            if (startingPartIndex < activeEngineParts.Count)
            {
                startingPart = activeEngineParts[startingPartIndex];
                failureType  = FailureType.engine;

                // Get the engine module for the part.
                foreach (ModuleEngines engineModule in startingPart.Modules.OfType <ModuleEngines>().ToList())
                {
                    if (engineModule.enabled && engineModule.currentThrottle > 0)
                    {
                        startingPartEngineModule = engineModule;
                    }
                }
            }
            offset += activeEngineParts.Count;
            if (startingPartIndex >= offset && startingPartIndex < offset + radialDecouplers.Count)
            {
                startingPart = radialDecouplers[startingPartIndex - offset];

                failureType       = FailureType.radialDecoupler;
                decouplerForceCnt = 0;
            }
            offset += radialDecouplers.Count;
            if (startingPartIndex >= offset && startingPartIndex < offset + controlSurfaces.Count)
            {
                startingPart = controlSurfaces[startingPartIndex - offset];

                failureType       = FailureType.controlSurface;
                decouplerForceCnt = 0;
            }
            offset += controlSurfaces.Count;
            if (startingPartIndex >= offset && startingPartIndex < offset + strutsAndFuelLines.Count)
            {
                startingPart = strutsAndFuelLines[startingPartIndex - offset];

                failureType       = FailureType.strutOrFuelLine;
                decouplerForceCnt = 0;
            }



#if false
            if (startingPartIndex >= activeEngineParts.Count)
            {
                startingPart = radialDecouplers[startingPartIndex - activeEngineParts.Count];

                failureType       = FailureType.radialDecoupler;
                decouplerForceCnt = 0;
            }
            else
            {
                startingPart = activeEngineParts[startingPartIndex];
                failureType  = FailureType.engine;

                // Get the engine module for the part.
                startingPartEngineModule = startingPart.Modules.OfType <ModuleEngines>().Single();
            }
#endif
            // Setup tick information for the part explosion loop.
            ticksBetweenPartFailures = (int)(KLFUtils.GameTicksPerSecond * KLFSettings.Instance.DelayBetweenPartFailures);
            if (ticksBetweenPartFailures == 0)
            {
                ticksBetweenPartFailures = (int)(KLFUtils.GameTicksPerSecond / 20f + 1f);
            }
            ticksSinceFailureStart = 0;
            thrustOverload         = 0;
            underThrustStart       = 100f;
            underThrustEnd         = 100f;
            scienceAfterFailure    = CalcScienceReward(activeVesselCost, activeVessel, startingPart);
            preFailureWarningTime  = KLFSettings.Instance.PreFailureWarningTime;
            if (KLFSettings.Instance.TimeRandomness > 0)
            {
                float f = UnityEngine.Random.Range(0, KLFSettings.Instance.TimeRandomness) - KLFSettings.Instance.TimeRandomness / 2f;
                preFailureWarningTime += f;
            }
        }
        public static bool ExperimentalPartsPresentAndActive()
        {
            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                return(false);
            }
            List <Part>         activeEngineParts  = FlightGlobals.ActiveVessel.GetActiveParts().Where(o => KLFUtils.PartIsActiveEngine(o, false)).ToList();
            List <Part>         radialDecouplers   = FlightGlobals.ActiveVessel.Parts.Where(o => KLFUtils.PartIsRadialDecoupler(o, false)).ToList();
            List <Part>         controlSurfaces    = FlightGlobals.ActiveVessel.Parts.Where(o => KLFUtils.PartIsControlSurface(o, false)).ToList();
            List <CompoundPart> strutsAndFuelLines = FlightGlobals.ActiveVessel.Parts.OfType <CompoundPart>().Where(o => KLFUtils.PartIsStrutOrFuelLine(o, false)).ToList();

            int i = activeEngineParts.Count + radialDecouplers.Count + controlSurfaces.Count + strutsAndFuelLines.Count;

            return(i > 0);
        }