private void FcSetup() { if (!HighLogic.LoadedSceneIsFlight) { return; } try { Altitude = vessel.atmDensity; BaseField ispField = Fields["localIsp"]; UI_FloatRange[] ispController = { ispField.uiControlFlight as UI_FloatRange, ispField.uiControlEditor as UI_FloatRange }; ispField.OnValueModified += IspField_OnValueModified; 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 = stepIncrement > 0 ? (akIsp - akMinIsp) / stepIncrement : 0; if (stepNumb < 0) { stepNumb = 0; } else if (stepNumb > MaxSteps) { stepNumb = MaxSteps; } akMinIsp = (float)Math.Round(BaseFloatCurve.Evaluate((float)Altitude)); if (akMinIsp < 1) { akMinIsp = 1; } akMaxIsp = GearDivider > 0 ? (float)Math.Round(akMinIsp / GearDivider) : akMinIsp; stepIncrement = (akMaxIsp - akMinIsp) / 100; ispController[I].minValue = akMinIsp; ispController[I].maxValue = akMaxIsp; ispController[I].stepIncrement = stepIncrement; SelectedIsp = akMinIsp + stepIncrement * stepNumb; I++; } lastAltitude = Altitude; } catch (Exception e) { Debug.LogError("[KSPI]: FusionEngine FcSetup exception: " + e.Message); } }
private void UpdateAtmosphereCurveInVab() { altitude = HighLogic.LoadedSceneIsEditor ? 0 : vessel.atmDensity; FcUpdate(); curEngineT.atmosphereCurve = BaseFloatCurve; MinIsp = BaseFloatCurve.Evaluate((float)altitude); }
private void FcSetup() { if (HighLogic.LoadedSceneIsFlight) { Altitude = vessel.atmDensity; } else { Altitude = 0; } BaseField ispField = Fields["localIsp"]; UI_FloatRange[] ispController = { ispField.uiControlFlight as UI_FloatRange, ispField.uiControlEditor as UI_FloatRange }; ispField.OnValueModified += IspField_OnValueModified; 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 = stepIncrement > 0 ? (akIsp - akMinIsp) / stepIncrement : 0; if (stepNumb < 0) { stepNumb = 0; } else if (stepNumb > MaxSteps) { stepNumb = MaxSteps; } akMinIsp = (float)Math.Round(BaseFloatCurve.Evaluate((float)Altitude)); if (akMinIsp < 1) { akMinIsp = 1; } akMaxIsp = GearDivider > 0 ? (float)Math.Round(akMinIsp / GearDivider) : akMinIsp; stepIncrement = (akMaxIsp - akMinIsp) / 100; ispController[i].minValue = akMinIsp; ispController[i].maxValue = akMaxIsp; ispController[i].stepIncrement = stepIncrement; SelectedIsp = akMinIsp + stepIncrement * stepNumb; i++; } lastAltitude = Altitude; }
public void FCSetup() { try { Altitude = vessel.atmDensity; BaseField IspField = Fields["localIsp"]; UI_FloatRange[] IspController = { IspField.uiControlFlight as UI_FloatRange, IspField.uiControlEditor as UI_FloatRange }; IspField.OnValueModified += IspField_OnValueModified; 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; if (StepNumb < 0) { StepNumb = 0; } else if (StepNumb > MaxSteps) { StepNumb = MaxSteps; } akMinIsp = (float)Math.Round(BaseFloatCurve.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++; } lastAltitude = Altitude; } catch (Exception e) { Debug.LogError("FusionEngine FCUpdate exception: " + e.Message); } }
private void UpdateAtmosphereCurve(float isp) { altitude = HighLogic.LoadedSceneIsEditor ? 0 : vessel.atmDensity; FcUpdate(); var newIsp = new FloatCurve(); newIsp.Add((float)altitude, isp); curEngineT.atmosphereCurve = newIsp; MinIsp = BaseFloatCurve.Evaluate((float)altitude); }
private void UpdateAtmosphereCurve(float currentIsp) { var newIsp = new FloatCurve(); Altitude = vessel.atmDensity; var origIsp = BaseFloatCurve.Evaluate((float)Altitude); FcUpdate(); newIsp.Add((float)Altitude, currentIsp); curEngineT.atmosphereCurve = newIsp; MinIsp = origIsp; }
public void UpdateISP() { FloatCurve newIsp = new FloatCurve(); Altitude = vessel.atmDensity; float OrigISP = BaseFloatCurve.Evaluate((float)Altitude); FCUpdate(); newIsp.Add((float)Altitude, SelectedIsp); curEngineT.atmosphereCurve = newIsp; MinIsp = OrigISP; }
public override void OnFixedUpdate() { // base.OnFixedUpdate(); temperatureStr = part.temperature.ToString("0.00") + "K / " + part.maxTemp.ToString("0.00") + "K"; MinIsp = BaseFloatCurve.Evaluate((float)Altitude); // part.ona if (curEngineT == null || !curEngineT.isEnabled) { 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); if (throttle > 0) { // Calculate Fusion Ratio enginePowerRequirement = CurrentPowerRequirement; var requestedPowerPerSecond = enginePowerRequirement; var availablePower = getAvailableResourceSupply(ResourceManager.FNRESOURCE_MEGAJOULES); var resourceBarRatio = getResourceBarRatio(ResourceManager.FNRESOURCE_MEGAJOULES); var effectivePowerThrotling = resourceBarRatio > ResourceManager.ONE_THIRD ? 1 : resourceBarRatio * 3; var requestedPower = Math.Min(requestedPowerPerSecond, availablePower * effectivePowerThrotling); double recievedPowerPerSecond = CheatOptions.InfiniteElectricity ? requestedPowerPerSecond : consumeFNResourcePerSecond(requestedPower, ResourceManager.FNRESOURCE_MEGAJOULES); var plasma_ratio = recievedPowerPerSecond / requestedPowerPerSecond; fusionRatio = plasma_ratio; laserWasteheat = recievedPowerPerSecond * (1 - LaserEfficiency); // Lasers produce Wasteheat if (!CheatOptions.IgnoreMaxTemperature) { supplyFNResourcePerSecond(laserWasteheat, ResourceManager.FNRESOURCE_WASTEHEAT); } // The Aborbed 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 SetRatio(InterstellarResourcesConfiguration.Instance.LqdDeuterium, (float)standard_deuterium_rate / rateMultplier); SetRatio(InterstellarResourcesConfiguration.Instance.LqdTritium, (float)standard_tritium_rate / rateMultplier); // Update ISP var currentIsp = SelectedIsp; UpdateISP(); maximumThrust = MaximumThrust; // Update FuelFlow var maxFuelFlow = fusionRatio * maximumThrust / currentIsp / PluginHelper.GravityConstant; curEngineT.maxFuelFlow = (float)maxFuelFlow; curEngineT.maxThrust = (float)maximumThrust; if (!curEngineT.getFlameoutState && plasma_ratio < 0.75 && recievedPowerPerSecond > 0) { curEngineT.status = "Insufficient Electricity"; } } else { enginePowerRequirement = 0; absorbedWasteheat = 0; laserWasteheat = 0; fusionRatio = 0; var currentIsp = SelectedIsp; maximumThrust = MaximumThrust; UpdateISP(); curEngineT.maxThrust = (float)maximumThrust; var rateMultplier = MinIsp / SelectedIsp; var maxFuelFlow = maximumThrust / currentIsp / PluginHelper.GravityConstant; curEngineT.maxFuelFlow = (float)maxFuelFlow; SetRatio(InterstellarResourcesConfiguration.Instance.LqdDeuterium, (float)standard_deuterium_rate / rateMultplier); SetRatio(InterstellarResourcesConfiguration.Instance.LqdTritium, (float)standard_tritium_rate / rateMultplier); } coldBathTemp = FNRadiator.getAverageRadiatorTemperatureForVessel(vessel); maxTempatureRadiators = FNRadiator.getAverageMaximumRadiatorTemperatureForVessel(vessel); radiatorPerformance = Math.Max(1 - (coldBathTemp / maxTempatureRadiators), 0.000001); partEmissiveConstant = part.emissiveConstant; base.OnFixedUpdate(); }
public override void OnFixedUpdateResourceSuppliable(double fixedDeltaTime) { temperatureStr = part.temperature.ToString("0.00") + "K / " + part.maxTemp.ToString("0.00") + "K"; MinIsp = BaseFloatCurve.Evaluate((float)Altitude); resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_WASTEHEAT, this.part.mass); resourceBuffers.UpdateBuffers(); if (curEngineT == null || !curEngineT.isEnabled) { return; } if (curEngineT.requestedThrottle > 0) { //if (vessel.atmDensity > maxAtmosphereDensity || vessel.atmDensity > _currentActiveConfiguration.maxAtmosphereDensity) // ShutDown(Localizer.Format("#LOC_KSPIE_FusionECU2_PostMsg1"));//"Inertial Fusion cannot operate in atmosphere!" if (radhazard && rad_safety_features) { ShutDown(Localizer.Format("#LOC_KSPIE_FusionECU2_PostMsg2"));//"Engines throttled down as they presently pose a radiation hazard" } //if (MinIsp <= 100) // ShutDown(Localizer.Format("#LOC_KSPIE_FusionECU2_PostMsg3"));//"Engine Stall" } KillKerbalsWithRadiation(fusionRatio); hasIspThrottling = HasIspThrottling(); ShowIspThrottle = hasIspThrottling; availablePower = Math.Max(getResourceAvailability(ResourceManager.FNRESOURCE_MEGAJOULES), getAvailablePrioritisedStableSupply(ResourceManager.FNRESOURCE_MEGAJOULES)); currentMaximumPowerProduction = GetCurrentMaximumPowerProduction(); currentMaximumPowerRequirement = GetCurrentMaximumPowerRequirement(); requiredPowerPerSecond = curEngineT.currentThrottle * currentMaximumPowerRequirement; if (curEngineT.currentThrottle > 0) { requestedPowerPerSecond = Math.Min(requiredPowerPerSecond, availablePower); recievedPowerPerSecond = requestedPowerPerSecond <= 0 ? 0 : CheatOptions.InfiniteElectricity ? requiredPowerPerSecond : consumeFNResourcePerSecond(requestedPowerPerSecond, ResourceManager.FNRESOURCE_MEGAJOULES); fusionRatio = requiredPowerPerSecond > 0 ? Math.Min(1, recievedPowerPerSecond / requiredPowerPerSecond) : 1; var inefficiency = 1 - LaserEfficiency; laserWasteheat = recievedPowerPerSecond * inefficiency; producedPowerPerSecond = fusionRatio * currentMaximumPowerProduction; if (!CheatOptions.InfiniteElectricity && currentMaximumPowerProduction > 0) { supplyFNResourcePerSecondWithMax(producedPowerPerSecond, currentMaximumPowerProduction, ResourceManager.FNRESOURCE_MEGAJOULES); } // Lasers produce Wasteheat if (!CheatOptions.IgnoreMaxTemperature && laserWasteheat > 0) { supplyFNResourcePerSecondWithMax(laserWasteheat, currentMaximumPowerRequirement * inefficiency, ResourceManager.FNRESOURCE_WASTEHEAT); } // The Aborbed wasteheat from Fusion rateMultplier = hasIspThrottling ? Math.Pow(SelectedIsp / MinIsp, 2) : 1; neutronbsorbionBonus = hasIspThrottling ? 1 - NeutronAbsorptionFractionAtMinIsp * (1 - ((SelectedIsp - MinIsp) / (MaxIsp - MinIsp))) : 0.5; absorbedWasteheat = FusionWasteHeat * wasteHeatMultiplier * fusionRatio * curEngineT.currentThrottle * neutronbsorbionBonus; supplyFNResourcePerSecond(absorbedWasteheat, ResourceManager.FNRESOURCE_WASTEHEAT); SetRatios(); currentIsp = hasIspThrottling ? SelectedIsp : MinIsp; UpdateAtmosphereCurve(currentIsp); maximumThrust = hasIspThrottling ? MaximumThrust : FullTrustMaximum; // Update FuelFlow maxFuelFlow = fusionRatio * maximumThrust / currentIsp / GameConstants.STANDARD_GRAVITY; if ((maxAtmosphereDensity >= 0 && vessel.atmDensity > maxAtmosphereDensity) || (_currentActiveConfiguration.maxAtmosphereDensity >= 0 && vessel.atmDensity > _currentActiveConfiguration.maxAtmosphereDensity)) { ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_KSPIE_FusionECU2_PostMsg1"), 1.0f, ScreenMessageStyle.UPPER_CENTER); curEngineT.maxFuelFlow = 1e-10f; curEngineT.maxThrust = Mathf.Max((float)maximumThrust, 0.0001f); HideExhaust(); } else if (MinIsp < _currentActiveConfiguration.minIsp) { ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_KSPIE_FusionECU2_PostMsg3"), 1.0f, ScreenMessageStyle.UPPER_CENTER); curEngineT.maxFuelFlow = 1e-10f; curEngineT.maxThrust = Mathf.Max((float)maximumThrust, 0.0001f); HideExhaust(); } else { curEngineT.maxFuelFlow = Mathf.Max((float)maxFuelFlow, 1e-10f); curEngineT.maxThrust = Mathf.Max((float)maximumThrust, 0.0001f); } if (!curEngineT.getFlameoutState && fusionRatio < 0.9 && recievedPowerPerSecond > 0) { curEngineT.status = Localizer.Format("#LOC_KSPIE_FusionECU2_statu1");//"Insufficient Electricity" } } else { absorbedWasteheat = 0; laserWasteheat = 0; requestedPowerPerSecond = 0; recievedPowerPerSecond = 0; fusionRatio = requiredPowerPerSecond > 0 ? Math.Min(1, availablePower / requiredPowerPerSecond) : 1; currentIsp = hasIspThrottling ? SelectedIsp : MinIsp; maximumThrust = hasIspThrottling ? MaximumThrust : FullTrustMaximum; UpdateAtmosphereCurve(currentIsp); rateMultplier = hasIspThrottling ? Math.Pow(SelectedIsp / MinIsp, 2) : 1; maxFuelFlow = fusionRatio * maximumThrust / currentIsp / GameConstants.STANDARD_GRAVITY; if ((maxAtmosphereDensity >= 0 && vessel.atmDensity > maxAtmosphereDensity) || (_currentActiveConfiguration.maxAtmosphereDensity >= 0 && vessel.atmDensity > _currentActiveConfiguration.maxAtmosphereDensity)) { curEngineT.maxFuelFlow = 1e-10f; curEngineT.maxThrust = Mathf.Max((float)maximumThrust, 0.0001f); HideExhaust(); } else if (MinIsp < _currentActiveConfiguration.minIsp) { curEngineT.maxFuelFlow = 1e-10f; curEngineT.maxThrust = Mathf.Max((float)maximumThrust, 0.0001f); HideExhaust(); } else { curEngineT.maxFuelFlow = Mathf.Max((float)maxFuelFlow, 1e-10f); curEngineT.maxThrust = Mathf.Max((float)maximumThrust, 0.0001f); } SetRatios(); } coldBathTemp = FNRadiator.getAverageRadiatorTemperatureForVessel(vessel); maxTempatureRadiators = FNRadiator.getAverageMaximumRadiatorTemperatureForVessel(vessel); radiatorPerformance = Math.Max(1 - (coldBathTemp / maxTempatureRadiators), 0.000001); partEmissiveConstant = part.emissiveConstant; //base.OnFixedUpdate(); }
public override void OnFixedUpdate() { temperatureStr = part.temperature.ToString("0.00") + "K / " + part.maxTemp.ToString("0.00") + "K"; MinIsp = BaseFloatCurve.Evaluate((float)Altitude); resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_WASTEHEAT, this.part.mass); resourceBuffers.UpdateBuffers(); if (curEngineT == null || !curEngineT.isEnabled) { return; } throttle = curEngineT.currentThrottle > MinThrottleRatio ? curEngineT.currentThrottle : 0; if (throttle > 0) { if (maxAtmosphereDensity >= 0 && 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(fusionRatio); hasIspThrottling = HasIspThrottling(); ShowIspThrottle = hasIspThrottling; if (throttle > 0) { // Calculate Fusion Ratio enginePowerRequirement = CurrentPowerRequirement; var requestedPowerPerSecond = enginePowerRequirement; var availablePower = getAvailableStableSupply(ResourceManager.FNRESOURCE_MEGAJOULES); var resourceBarRatio = getResourceBarRatio(ResourceManager.FNRESOURCE_MEGAJOULES); var effectivePowerThrotling = resourceBarRatio > ResourceManager.ONE_THIRD ? 1 : resourceBarRatio * 3; var requestedPower = Math.Min(requestedPowerPerSecond, availablePower * effectivePowerThrotling); var recievedPowerPerSecond = CheatOptions.InfiniteElectricity || requestedPower <= 0 ? requestedPowerPerSecond : consumeFNResourcePerSecond(requestedPower, ResourceManager.FNRESOURCE_MEGAJOULES); fusionRatio = requestedPowerPerSecond > 0 ? recievedPowerPerSecond / requestedPowerPerSecond : 1; laserWasteheat = recievedPowerPerSecond * (1 - LaserEfficiency); // Lasers produce Wasteheat if (!CheatOptions.IgnoreMaxTemperature) { supplyFNResourcePerSecond(laserWasteheat, ResourceManager.FNRESOURCE_WASTEHEAT); } // The Aborbed wasteheat from Fusion rateMultplier = hasIspThrottling ? Math.Pow(SelectedIsp / MinIsp, 2) : 1; neutronbsorbionBonus = hasIspThrottling ? 1 - NeutronAbsorptionFractionAtMinIsp * (1 - ((SelectedIsp - MinIsp) / (MaxIsp - MinIsp))) : 0.5; absorbedWasteheat = FusionWasteHeat * wasteHeatMultiplier * fusionRatio * throttle * neutronbsorbionBonus; supplyFNResourcePerSecond(absorbedWasteheat, ResourceManager.FNRESOURCE_WASTEHEAT); SetRatios(); currentIsp = hasIspThrottling ? SelectedIsp : MinIsp; UpdateAtmosphereCurve(currentIsp); maximumThrust = hasIspThrottling ? MaximumThrust : FullTrustMaximum; // Update FuelFlow var maxFuelFlow = fusionRatio * maximumThrust / currentIsp / GameConstants.STANDARD_GRAVITY; curEngineT.maxFuelFlow = (float)maxFuelFlow; curEngineT.maxThrust = (float)maximumThrust; if (!curEngineT.getFlameoutState && fusionRatio < 0.75 && recievedPowerPerSecond > 0) { curEngineT.status = "Insufficient Electricity"; } } else { enginePowerRequirement = 0; absorbedWasteheat = 0; laserWasteheat = 0; fusionRatio = 0; currentIsp = hasIspThrottling ? SelectedIsp : MinIsp; maximumThrust = hasIspThrottling ? MaximumThrust : FullTrustMaximum; UpdateAtmosphereCurve(currentIsp); curEngineT.maxThrust = (float)maximumThrust; rateMultplier = hasIspThrottling ? Math.Pow(SelectedIsp / MinIsp, 2) : 1; var maxFuelFlow = maximumThrust / currentIsp / GameConstants.STANDARD_GRAVITY; curEngineT.maxFuelFlow = (float)maxFuelFlow; SetRatios(); } coldBathTemp = FNRadiator.getAverageRadiatorTemperatureForVessel(vessel); maxTempatureRadiators = FNRadiator.getAverageMaximumRadiatorTemperatureForVessel(vessel); radiatorPerformance = Math.Max(1 - (coldBathTemp / maxTempatureRadiators), 0.000001); partEmissiveConstant = part.emissiveConstant; base.OnFixedUpdate(); }