// adds heat to receiver core, not engine core
        // which is why the temp limits are so low
        private void AddHeatToReceiverCore()
        {
            CoreTemp = (float)(Math.Round(coreHeat.CoreTemperature, 1));
            SkinTemp = (float)(Math.Round(this.part.skinTemperature, 1));

            if (CoreTemp > maxCoreTemp | SkinTemp > maxSkinTemp)
            {
                State = ExceedTempLimit;
                engine.Shutdown(); PowerLimiter = 0;
            }
            if (State == ExceedTempLimit & (CoreTemp >= maxCoreTemp * 0.7 | SkinTemp >= maxSkinTemp * 0.7))
            {
                engine.Shutdown(); PowerLimiter = 0;
            }
            else if (CoreTemp < maxCoreTemp * 0.7 & SkinTemp < maxSkinTemp * 0.7)
            {
                State = operational;
            }
            double heatModifier = (double)HighLogic.CurrentGame.Parameters.CustomParams <BPSettings>().PercentHeat / 100;
            double heatExcess   = (ReceivedPower * (1f / recvEfficiency - thermalEfficiency)) * heatModifier;

            WasteHeat = (float)Math.Round(heatExcess, 1);
            coreHeat.AddEnergyToCore(heatExcess * 0.5 * TimeWarp.fixedDeltaTime); // first converted to kJ
            this.part.AddSkinThermalFlux(heatExcess * 0.4);                       // waste heat from receiver + waste heat from engine
        }
Esempio n. 2
0
 public void RetractEngineEvent()
 {
     if (engineModule && engineModule.EngineIgnited)
     {
         engineModule.Shutdown();
     }
     animationModule.onRetractEvent();
 }
        public void ActionShutdown(KSPActionParam param)
        {
            if (currentModuleEngine.getIgnitionState)
            {
                currentModuleEngine.Shutdown();
            }

            currentEngineState = currentModuleEngine.getIgnitionState;
            //Debug.Log("Action currentModuleEngine.Shutdown(): " + ChooseOption + " new state is: " + currentEngineState);
        }
        public void retractEngineEvent()
        {
            AnimState state = animationControl.getAnimationState();

            if (state != AnimState.STOPPED_START)
            {
                setAnimationState(AnimState.PLAYING_BACKWARD);
                engineModule.Shutdown();
            }
            else
            {
                engineModule.Shutdown();
            }
            setupGuiFields(animationControl.getAnimationState(), engineModule.EngineIgnited);
        }
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            try
            {
                pre_coolers_active = vessel.FindPartModulesImplementing <FNModulePreecooler>().Where(prc => prc.functional).Sum(prc => prc.area);
                intakes_open_area  = vessel.FindPartModulesImplementing <AtmosphericIntake>().Where(mre => mre.intakeOpen).Sum(mre => mre.area);

                missingPrecoolerRatio = intakes_open_area > 0 ? Math.Min(1, Math.Max(0, Math.Pow((intakes_open_area - pre_coolers_active) / intakes_open_area, missingPrecoolerProportionExponent))) : 0;
                missingPrecoolerRatio = missingPrecoolerRatio.IsInfinityOrNaN() ? 1 : missingPrecoolerRatio;

                if (rapier_engine != null)
                {
                    if (rapier_engine.isOperational && rapier_engine.currentThrottle > 0 && rapier_engine.useVelCurve)
                    {
                        temp1 = Math.Max((Math.Sqrt(vessel.srf_velocity.magnitude) * 10.0 / GameConstants.atmospheric_non_precooled_limit) * part.maxTemp * missingPrecoolerRatio, 1);
                        if (temp1 >= (part.maxTemp - 10))
                        {
                            ScreenMessages.PostScreenMessage("Engine Shutdown: Catastrophic overheating was imminent!", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                            rapier_engine.Shutdown();
                            part.temperature = 1;
                            return;
                        }
                        part.temperature = temp1;
                    }
                    else
                    {
                        part.temperature = 1;
                    }
                }

                if (rapier_engine2 != null)
                {
                    if (rapier_engine2.isOperational && rapier_engine2.currentThrottle > 0 && rapier_engine2.useVelCurve)
                    {
                        temp2 = Math.Max((Math.Sqrt(vessel.srf_velocity.magnitude) * 20.0 / GameConstants.atmospheric_non_precooled_limit) * part.maxTemp * missingPrecoolerRatio, 1);
                        if (temp2 >= (part.maxTemp - 10))
                        {
                            ScreenMessages.PostScreenMessage("Engine Shutdown: Catastrophic overheating was imminent!", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                            rapier_engine2.Shutdown();
                            part.temperature = 1;
                            return;
                        }
                        part.temperature = temp2;
                    }
                    else
                    {
                        part.temperature = 1;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Log("[KSPI]: ModuleSabreHeating threw Exception in FixedUpdate(): " + ex);
            }
        }
Esempio n. 6
0
        public override void OnUpdate()
        {
            base.OnUpdate();

            if (Input.GetKeyDown(KeyCode.Z) && engineActivated == false)
            {
                engine.Activate();
                engine.currentThrottle = 1.0f;
                engineActivated        = true;
            }

            if (engineActivated)
            {
                engine.currentThrottle = 1.0f;
            }

            if (Input.GetKeyDown(KeyCode.X))
            {
                engine.currentThrottle = 0f;
                engine.Shutdown();
                engineActivated = false;
            }

            if (Input.GetKey(KeyCode.T))
            {
                part.vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true);
            }
        }
Esempio n. 7
0
        public void SetupEngine(int engineIndex, bool isInFlight)
        {
            ModuleEnginesFX previousEngine = currentEngine;

            //Get the new current engine
            currentEngineIndex = engineIndex;
            currentEngine      = engineList[currentEngineIndex];
            currentEngineID    = currentEngine.engineID;

            //In-flight stuff
            if (isInFlight)
            {
                currentEngine.Activate();
                currentEngine.currentThrottle = previousEngine.currentThrottle;
                previousEngine.Shutdown();
            }

            //Disable previous engine
            previousEngine.manuallyOverridden = true;
            previousEngine.isEnabled          = false;

            //Enable current engine
            currentEngine.manuallyOverridden = false;
            currentEngine.isEnabled          = true;
        }
Esempio n. 8
0
        public override void OnUpdate()
        {
            if (!engineIsFX)
            {
                engineIsOn = modEng.EngineIgnited;
            }
            else
            {
                engineIsOn = modEngFX.EngineIgnited;
            }


            foreach (var anim in engineStates)
            {
                if (engineIsOn && anim.normalizedTime < WaitForAnimation)
                {
                    anim.speed = 1;
                    if (engineIsFX)
                    {
                        modEngFX.Shutdown();
                    }
                    else
                    {
                        modEng.Shutdown();
                    }
                }


                if (anim.normalizedTime >= WaitForAnimation && anim.speed > 0)
                {
                    if (engineIsFX)
                    {
                        modEngFX.Activate();
                    }
                    else
                    {
                        modEng.Activate();
                    }
                }

                if (anim.normalizedTime >= 1)
                {
                    anim.speed          = 0;
                    anim.normalizedTime = 1;
                }

                if (anim.normalizedTime >= 1 && !engineIsOn)
                {
                    anim.speed = -1;
                }

                if (anim.normalizedTime < 0)
                {
                    anim.speed          = 0;
                    anim.normalizedTime = 0;
                }
            }
        }
Esempio n. 9
0
        public void FixedUpdate()
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                try
                {
                    pre_coolers_active = vessel.FindPartModulesImplementing <FNModulePreecooler>().Where(prc => prc.isFunctional()).Count();
                    intakes_open       = vessel.FindPartModulesImplementing <ModuleResourceIntake>().Where(mre => mre.intakeEnabled).Count();

                    double proportion = Math.Pow((double)(intakes_open - pre_coolers_active) / (double)intakes_open, 0.1);
                    proportion = (!double.IsNaN(proportion) && !double.IsInfinity(proportion)) ? proportion : 1;

                    if (rapier_engine != null)
                    {
                        if (rapier_engine.isOperational && rapier_engine.currentThrottle > 0 && rapier_engine.useVelCurve)
                        {
                            double temp = Math.Max((Math.Sqrt(vessel.srf_velocity.magnitude) * 10.0 / GameConstants.atmospheric_non_precooled_limit) * part.maxTemp * proportion, 1);
                            if (temp >= (part.maxTemp - 10.0f))
                            {
                                ScreenMessages.PostScreenMessage("Engine Shutdown: Catastrophic overheating was imminent!", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                                rapier_engine.Shutdown();
                                part.temperature = 1;
                                return;
                            }
                            part.temperature = temp;
                        }
                        else
                        {
                            part.temperature = 1;
                        }
                    }

                    if (rapier_engine2 != null)
                    {
                        if (rapier_engine2.isOperational && rapier_engine2.currentThrottle > 0 && rapier_engine2.useVelCurve)
                        {
                            double temp = Math.Max((Math.Sqrt(vessel.srf_velocity.magnitude) * 20.0 / GameConstants.atmospheric_non_precooled_limit) * part.maxTemp * proportion, 1);
                            if (temp >= (part.maxTemp - 10.0f))
                            {
                                ScreenMessages.PostScreenMessage("Engine Shutdown: Catastrophic overheating was imminent!", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                                rapier_engine2.Shutdown();
                                part.temperature = 1;
                                return;
                            }
                            part.temperature = temp;
                        }
                        else
                        {
                            part.temperature = 1;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log("[KSPI] - ModuleSabreHeating threw Exception in OnFixedUpdate(): " + ex);
                }
            }
        }
        /// <summary>
        /// Tells the hover controller to stop the engine.
        /// </summary>
        public virtual void StopEngine()
        {
            getCurrentEngine();
            if (engine == null)
            {
                return;
            }

            engine.Shutdown();
        }
Esempio n. 11
0
 public override void OnActive()
 {
     if (animationModule.animState == AnimState.STOPPED_END)
     {
         engineModule.Activate();
     }
     else
     {
         deployEngineEvent();
         if (engineModule.EngineIgnited)
         {
             engineModule.Shutdown();
         }
     }
 }
Esempio n. 12
0
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            if (engine != null)
            {
                vessel.checkSplashed();
                if (!vessel.Splashed && engine.EngineIgnited)
                {
                    engine.Shutdown();
                }
            }
        }
Esempio n. 13
0
        public void Shutdown()
        {
            switch (engineType)
            {
            case EngineType.Engine:
                engineModule.Shutdown();
                break;

            case EngineType.EngineFx:
                engineModuleFx.Shutdown();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 14
0
 public void Timelon(float tiempo)
 {
     timer += Time.deltaTime;
     if (timer < tiempo)
     {
         deployed = false;
         motor.Shutdown();
     }
     if (timer >= tiempo)
     {
         motor.Activate();
         deployed = true;
         sale     = true;
         enespera = false;
         timer    = 0;
     }
 }
Esempio n. 15
0
    public void Shutdown()
    {
        if (engineType == EngineModuleType.UNKNOWN)
        {
            return;
        }

        if (engineType == EngineModuleType.ENGINE)
        {
            engine.Shutdown();
            engine.DeactivateRunningFX();
            engine.DeactivatePowerFX();
        }
        else
        {
            engineFX.Shutdown();
            engineFX.DeactivateLoopingFX();
        }
    }
Esempio n. 16
0
        private bool SetEngineFxSuffix(string suffixName, object value, ModuleEnginesFX moduleEnginesFx)
        {
            switch (suffixName)
            {
            case "ACTIVE":
                var activate = Convert.ToBoolean(value);
                if (activate)
                {
                    moduleEnginesFx.Activate();
                }
                else
                {
                    moduleEnginesFx.Shutdown();
                }
                return(true);

            case "THRUSTLIMIT":
                var throttlePercent = (float)Convert.ToDouble(value);
                moduleEnginesFx.thrustPercentage = throttlePercent;
                return(true);
            }
            return(base.SetSuffix(suffixName, value));
        }
        public override void OnFixedUpdate()
        {
            if (myAttachedEngine.isOperational && myAttachedEngine.currentThrottle > 0 && myAttachedReactor != null)
            {
                if (!myAttachedReactor.IsActive)
                {
                    myAttachedReactor.enableIfPossible();
                }
                updateIspEngineParams();
                float  curve_eval_point = (float)Math.Min(FlightGlobals.getStaticPressure(vessel.transform.position), 1.0);
                float  currentIsp       = myAttachedEngine.atmosphereCurve.Evaluate(curve_eval_point);
                double ispratio         = currentIsp / maxISP;
                this.current_isp = currentIsp;
                // scale down thrust if it's attached to the wrong sized reactor
                float heat_exchanger_thrust_divisor = 1;
                if (radius > myAttachedReactor.getRadius())
                {
                    heat_exchanger_thrust_divisor = myAttachedReactor.getRadius() * myAttachedReactor.getRadius() / radius / radius;
                }
                else
                {
                    heat_exchanger_thrust_divisor = radius * radius / myAttachedReactor.getRadius() / myAttachedReactor.getRadius();
                }

                if (myAttachedReactor.getRadius() == 0 || radius == 0)
                {
                    heat_exchanger_thrust_divisor = 1;
                }
                // get the flameout safety limit
                atmospheric_limit = getAtmosphericLimit();
                double thrust_limit = myAttachedEngine.thrustPercentage / 100;
                if (currentpropellant_is_jet)
                {
                    int    pre_coolers_active = vessel.FindPartModulesImplementing <FNModulePreecooler>().Where(prc => prc.isFunctional()).Count();
                    int    intakes_open       = vessel.FindPartModulesImplementing <ModuleResourceIntake>().Where(mre => mre.intakeEnabled).Count();
                    double proportion         = Math.Pow((double)(intakes_open - pre_coolers_active) / (double)intakes_open, 0.1);
                    if (double.IsNaN(proportion) || double.IsInfinity(proportion))
                    {
                        proportion = 1;
                    }
                    float temp = (float)Math.Max((Math.Sqrt(vessel.srf_velocity.magnitude) * 20.0 / GameConstants.atmospheric_non_precooled_limit) * part.maxTemp * proportion, 1);
                    if (temp > part.maxTemp - 10.0f)
                    {
                        ScreenMessages.PostScreenMessage("Engine Shutdown: Catastrophic overheating was imminent!", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                        myAttachedEngine.Shutdown();
                        part.temperature = 1;
                    }
                    else
                    {
                        part.temperature = temp;
                    }
                }
                double thermal_power_received = consumeFNResource(assThermalPower * TimeWarp.fixedDeltaTime * myAttachedEngine.currentThrottle, FNResourceManager.FNRESOURCE_THERMALPOWER) / TimeWarp.fixedDeltaTime;
                consumeFNResource(thermal_power_received * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_WASTEHEAT);
                float  power_ratio     = 0.0f;
                double engineMaxThrust = 0.01;
                if (assThermalPower > 0)
                {
                    power_ratio     = (float)(thermal_power_received / assThermalPower);
                    engineMaxThrust = Math.Max(thrust_limit * 2000.0 * thermal_power_received / maxISP / g0 * heat_exchanger_thrust_divisor * ispratio / myAttachedEngine.currentThrottle, 0.01);
                }
                //print ("B: " + engineMaxThrust);
                // set up TWR limiter if on
                //double additional_thrust_compensator = myAttachedEngine.finalThrust / (myAttachedEngine.maxThrust * myAttachedEngine.currentThrottle);
                double engine_thrust = engineMaxThrust;
                // engine thrust fixed
                //print ("A: " + engine_thrust*myAttachedEngine.velocityCurve.Evaluate((float)vessel.srf_velocity.magnitude));
                if (!double.IsInfinity(engine_thrust) && !double.IsNaN(engine_thrust))
                {
                    if (isLFO)
                    {
                        myAttachedEngine.maxThrust = (float)(2.0 * engine_thrust);
                    }
                    else
                    {
                        myAttachedEngine.maxThrust = (float)engine_thrust;
                    }
                }
                else
                {
                    myAttachedEngine.maxThrust = 0.000001f;
                }

                // amount of fuel being used at max throttle with no atmospheric limits
                if (current_isp > 0)
                {
                    double vcurve_at_current_velocity = 1;
                    if (myAttachedEngine.useVelocityCurve)
                    {
                        vcurve_at_current_velocity = myAttachedEngine.velocityCurve.Evaluate((float)vessel.srf_velocity.magnitude);
                    }
                    fuel_flow_rate = engine_thrust / current_isp / g0 / 0.005 * TimeWarp.fixedDeltaTime;
                    if (vcurve_at_current_velocity > 0)
                    {
                        fuel_flow_rate = fuel_flow_rate / vcurve_at_current_velocity;
                    }
                }
            }
            else
            {
                if (myAttachedEngine.realIsp > 0)
                {
                    atmospheric_limit = getAtmosphericLimit();
                    double vcurve_at_current_velocity = 1;
                    if (myAttachedEngine.useVelocityCurve)
                    {
                        vcurve_at_current_velocity = myAttachedEngine.velocityCurve.Evaluate((float)vessel.srf_velocity.magnitude);
                    }
                    fuel_flow_rate = myAttachedEngine.maxThrust / myAttachedEngine.realIsp / g0 / 0.005 * TimeWarp.fixedDeltaTime / vcurve_at_current_velocity;
                }
                else
                {
                    fuel_flow_rate = 0;
                }

                if (currentpropellant_is_jet)
                {
                    part.temperature = 1;
                }

                if (myAttachedReactor == null && myAttachedEngine.isOperational && myAttachedEngine.currentThrottle > 0)
                {
                    myAttachedEngine.Events ["Shutdown"].Invoke();
                    ScreenMessages.PostScreenMessage("Engine Shutdown: No reactor attached!", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                }
            }
            //tell static helper methods we are currently updating things
            static_updating  = true;
            static_updating2 = true;
        }
Esempio n. 18
0
 public void ShutdownAction(KSPActionParam param)
 {
     currentEngine.Shutdown();
 }
Esempio n. 19
0
 private void disable(ModuleEnginesFX m)
 {
     m.Shutdown();
     m.DeactivateLoopingFX();
     m.enabled = false;
 }
Esempio n. 20
0
 private bool SetEngineFxSuffix(string suffixName, object value, ModuleEnginesFX moduleEnginesFx)
 {
     switch (suffixName)
     {
         case "ACTIVE":
             var activate = (bool) value;
             if (activate)
             {
                 moduleEnginesFx.Activate();
             }
             else
             {
                 moduleEnginesFx.Shutdown();
             }
             return true;
         case "THRUSTLIMIT":
             var throttlePercent = (float) value;
             moduleEnginesFx.thrustPercentage = throttlePercent;
             return false;
     }
     return base.SetSuffix(suffixName, value);
 }
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            try
            {
                var activePreCoolers = vessel.FindPartModulesImplementing <FNModulePreecooler>().Where(prc => prc.functional).ToList();
                _preCoolersActiveArea = activePreCoolers.Any() ? activePreCoolers.Sum(prc => prc.area) : 0;

                var openIntakes = vessel.FindPartModulesImplementing <AtmosphericIntake>().Where(mre => mre.intakeOpen).ToList();
                _openIntakesArea = openIntakes.Any()  ? openIntakes.Sum(mre => mre.area) : 0;

                missingPrecoolerRatio = _openIntakesArea > 0 ? Math.Min(1, Math.Max(0, Math.Pow(Math.Max(0, _openIntakesArea - _preCoolersActiveArea) / _openIntakesArea, missingPrecoolerProportionExponent))) : 0;
                missingPrecoolerRatio = missingPrecoolerRatio.IsInfinityOrNaN() ? 1 : missingPrecoolerRatio;

                if (rapier_engine != null && vessel.atmDensity > 0)
                {
                    if (rapier_engine.isOperational && rapier_engine.currentThrottle > 0 && rapier_engine.useVelCurve)
                    {
                        _temp1 = Math.Max((Math.Sqrt(vessel.srf_velocity.magnitude) * 10.0 / GameConstants.atmospheric_non_precooled_limit) * part.maxTemp * missingPrecoolerRatio, 1);
                        if (_temp1 >= (part.maxTemp - 10))
                        {
                            ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_KSPIE_ModuleSabreHeating_PostMsg"), 5.0f, ScreenMessageStyle.UPPER_CENTER);//"Engine Shutdown: Catastrophic overheating was imminent!"
                            rapier_engine.Shutdown();
                            part.temperature = 1;
                            return;
                        }
                        else
                        {
                            part.temperature = _temp1;
                        }
                    }
                    else
                    {
                        part.temperature = 1;
                    }
                }

                if (rapier_engine2 != null && vessel.atmDensity > 0)
                {
                    if (rapier_engine2.isOperational && rapier_engine2.currentThrottle > 0 && rapier_engine2.useVelCurve)
                    {
                        _temp2 = Math.Max((Math.Sqrt(vessel.srf_velocity.magnitude) * 20.0 / GameConstants.atmospheric_non_precooled_limit) * part.maxTemp * missingPrecoolerRatio, 1);
                        if (_temp2 >= (part.maxTemp - 10))
                        {
                            ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_KSPIE_ModuleSabreHeating_PostMsg"), 5.0f, ScreenMessageStyle.UPPER_CENTER);//"Engine Shutdown: Catastrophic overheating was imminent!"
                            rapier_engine2.Shutdown();
                            part.temperature = 1;
                        }
                        else
                        {
                            part.temperature = _temp2;
                        }
                    }
                    else
                    {
                        part.temperature = 1;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Log("[KSPI]: ModuleSabreHeating threw Exception in FixedUpdate(): " + ex);
            }
        }
Esempio n. 22
0
 private void disable(ModuleEnginesFX m)
 {
     m.Shutdown();
     m.DeactivateLoopingFX();
     m.enabled = false;
 }
Esempio n. 23
0
 public void FixedUpdate()
 {
     if (!HighLogic.LoadedSceneIsFlight)
     {
         return;
     }
     if (shutdownUnder == true) //shut down a submerged engine
     {
         if (this.part.WaterContact && MPFunctions.findAltitude(this.part.transform) <= -1)
         {
             for (int i = this.part.Modules.Count - 1; i >= 0; --i)
             {
                 PartModule M = this.part.Modules[i];
                 if (M.isActiveAndEnabled)
                 {
                     if (M is ModuleEnginesFX)
                     {
                         ModuleEnginesFX E = M as ModuleEnginesFX;
                         if (!E.flameout)
                         {
                             E.Flameout("Flooded");
                             E.Shutdown();
                         }
                     }
                     if (M is ModuleEngines)
                     {
                         ModuleEngines F = M as ModuleEngines;
                         if (!F.flameout)
                         {
                             F.Flameout("Flooded");
                             F.Shutdown();
                         }
                     }
                 }
             }
         }
     }
     else
     {
         if (!this.part.WaterContact)
         {
             for (int i = this.part.Modules.Count - 1; i >= 0; --i)
             {
                 PartModule M = this.part.Modules[i];
                 {
                     if (M is ModuleEnginesFX)
                     {
                         ModuleEnginesFX E = M as ModuleEnginesFX;
                         if (!E.flameout)
                         {
                             E.Flameout("Engine out of the water");
                             E.Shutdown();
                         }
                     }
                     if (M is ModuleEngines)
                     {
                         ModuleEngines F = M as ModuleEngines;
                         if (!F.flameout)
                         {
                             F.Flameout("Engine out of the water");
                             F.Shutdown();
                         }
                     }
                 }
             }
         }
     }
 }