public void  UpdateISP()
        {
            FloatCurve newIsp = new FloatCurve();

            Altitude = vessel.atmDensity;
            float OrigISP = OrigFloatCurve.Evaluate((float)Altitude);

            if (Altitude != lastAltitude)
            {
                FCsetup(); lastAltitude = Altitude;
            }                                                                  // save resources when it's out of the atmoshpere.
            newIsp.Add((float)Altitude, SelectedIsp);
            curEngineT.atmosphereCurve = newIsp;
            MinIsp = OrigISP;
        }
        public void FCsetup()
        {
            try
            {
                if (vessel.loaded)
                {
                    BaseField IspField = Fields["localIsp"];

                    UI_FloatRange[] IspController = { IspField.uiControlFlight as UI_FloatRange, IspField.uiControlEditor as UI_FloatRange };



                    for (int I = 0; I < IspController.Length; I++)
                    {
                        float akIsp         = SelectedIsp;
                        float akMinIsp      = IspController[I].minValue;
                        float akMaxIsp      = IspController[I].maxValue;
                        float StepIncrement = IspController[I].stepIncrement;

                        float StepNumb = (akIsp - akMinIsp) / StepIncrement;
                        akMinIsp = (float)Math.Round(OrigFloatCurve.Evaluate((float)Altitude));
                        if (akMinIsp < 1)
                        {
                            akMinIsp = 1;
                        }
                        akMaxIsp      = (float)Math.Round(akMinIsp / MaxMin);
                        StepIncrement = (akMaxIsp - akMinIsp) / 100;

                        IspController[I].minValue      = akMinIsp;
                        IspController[I].maxValue      = akMaxIsp;
                        IspController[I].stepIncrement = StepIncrement;

                        SelectedIsp = akMinIsp + StepIncrement * StepNumb;
                        I++;
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI]: FusionEngine FCsetup exception: " + e.Message);
            }
        }
        public override void OnFixedUpdate()
        {
            temperatureStr = part.temperature.ToString("0.00") + "K / " + part.maxTemp.ToString("0.00") + "K";
            MinIsp         = OrigFloatCurve.Evaluate((float)Altitude);

            // part.ona

            if (curEngineT == null)
            {
                return;
            }

            throttle = curEngineT.currentThrottle > MinThrottleRatio ? curEngineT.currentThrottle : 0;

            if (throttle > 0)
            {
                if (vessel.atmDensity > maxAtmosphereDensity)
                {
                    ShutDown("Inertial Fusion cannot operate in atmosphere!");
                }

                if (radhazard && rad_safety_features)
                {
                    ShutDown("Engines throttled down as they presently pose a radiation hazard");
                }

                if (SelectedIsp <= 10)
                {
                    ShutDown("Engine Stall");
                }
            }

            KillKerbalsWithRadiation(throttle);

            resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_WASTEHEAT, this.part.mass);
            resourceBuffers.UpdateBuffers();

            if (throttle > 0)
            {
                // Calculate Fusion Ratio
                enginePowerRequirement = CurrentPowerRequirement;

                var recievedPowerFixed = CheatOptions.InfiniteElectricity
                    ? enginePowerRequirement
                    : consumeFNResourcePerSecond(enginePowerRequirement, ResourceManager.FNRESOURCE_MEGAJOULES);

                var plasma_ratio = recievedPowerFixed / enginePowerRequirement;
                fusionRatio = plasma_ratio >= 1 ? 1 : plasma_ratio > 0.75f ? Mathf.Pow((float)plasma_ratio, 6) : 0;

                laserWasteheat = recievedPowerFixed * (1 - LaserEfficiency);

                // Lasers produce Wasteheat
                if (!CheatOptions.IgnoreMaxTemperature)
                {
                    supplyFNResourcePerSecond(enginePowerRequirement, ResourceManager.FNRESOURCE_WASTEHEAT);
                }

                // The Absorbed wasteheat from Fusion
                var rateMultplier        = MinIsp / SelectedIsp;
                var neutronbsorbionBonus = 1 - NeutronAbsorptionFractionAtMinIsp * (1 - ((SelectedIsp - MinIsp) / (MaxIsp - MinIsp)));
                absorbedWasteheat = FusionWasteHeat * wasteHeatMultiplier * fusionRatio * throttle * neutronbsorbionBonus;
                supplyFNResourcePerSecond(absorbedWasteheat, ResourceManager.FNRESOURCE_WASTEHEAT);

                // change ratio propellants Hydrogen/Fusion
                curEngineT.propellants.FirstOrDefault(pr => pr.name == InterstellarResourcesConfiguration.Instance.LqdDeuterium).ratio = (float)standard_deuterium_rate / rateMultplier;
                curEngineT.propellants.FirstOrDefault(pr => pr.name == InterstellarResourcesConfiguration.Instance.LqdTritium).ratio   = (float)standard_tritium_rate / rateMultplier;

                // Update ISP
                var currentIsp = SelectedIsp;
                UpdateISP();

                // Update FuelFlow
                var maxFuelFlow = fusionRatio * MaximumThrust / currentIsp / GameConstants.STANDARD_GRAVITY;
                maximumThrust = (float)MaximumThrust;

                curEngineT.maxFuelFlow = (float)maxFuelFlow;
                curEngineT.maxThrust   = maximumThrust;


                if (!curEngineT.getFlameoutState && plasma_ratio < 0.75 && recievedPowerFixed > 0)
                {
                    curEngineT.status = "Insufficient Electricity";
                }
            }
            else
            {
                enginePowerRequirement = 0;
                absorbedWasteheat      = 0;
                laserWasteheat         = 0;
                fusionRatio            = 0;
                var currentIsp = SelectedIsp;

                UpdateISP();
                curEngineT.maxThrust = (float)MaximumThrust;
                var rateMultplier = MinIsp / SelectedIsp;

                var maxFuelFlow = MaximumThrust / currentIsp / GameConstants.STANDARD_GRAVITY;
                curEngineT.maxFuelFlow = (float)maxFuelFlow;
                curEngineT.propellants.FirstOrDefault(pr => pr.name == InterstellarResourcesConfiguration.Instance.LqdDeuterium).ratio = (float)(standard_deuterium_rate) / rateMultplier;
                curEngineT.propellants.FirstOrDefault(pr => pr.name == InterstellarResourcesConfiguration.Instance.LqdTritium).ratio   = (float)(standard_tritium_rate) / rateMultplier;
            }

            coldBathTemp          = (float)FNRadiator.getAverageRadiatorTemperatureForVessel(vessel);
            maxTempatureRadiators = (float)FNRadiator.getAverageMaximumRadiatorTemperatureForVessel(vessel);
            radiatorPerformance   = Mathf.Max(1 - (coldBathTemp / maxTempatureRadiators), 0.000001f);
            partEmissiveConstant  = (float)part.emissiveConstant;
        }