public void updateGeneratorPower() { hotBathTemp = myAttachedReactor.CoreTemperature; 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; } maxThermalPower = myAttachedReactor.MaximumPower * heat_exchanger_thrust_divisor; if (myAttachedReactor is IChargedParticleSource) { maxChargedPower = (myAttachedReactor as IChargedParticleSource).MaximumChargedPower * heat_exchanger_thrust_divisor; } else { maxChargedPower = 0; } coldBathTemp = (float)FNRadiator.getAverageRadiatorTemperatureForVessel(vessel); }
//private void UpdateRadiusModifier() //{ // radiusModifier = (GetHeatExchangerThrustDivisor() * 100.0).ToString("0.00") + "%"; //} private double GetHeatExchangerThrustDivisor() { if (myAttachedReactor == null) { return(0); } if (myAttachedReactor.getRadius() == 0 || radius == 0) { return(1); } // scale down thrust if it's attached to the wrong sized reactor float heat_exchanger_thrust_divisor = radius > myAttachedReactor.getRadius() ? myAttachedReactor.getRadius() * myAttachedReactor.getRadius() / radius / radius //: radius * radius / myAttachedReactor.getRadius() / myAttachedReactor.getRadius(); : radius / myAttachedReactor.getRadius(); return(heat_exchanger_thrust_divisor); }
private void UpdateHeatExchangedThrustDivisor() { if (myAttachedReactor == null) { return; } if (myAttachedReactor.getRadius() <= 0 || radius <= 0) { heat_exchanger_thrust_divisor = 1; return; } heat_exchanger_thrust_divisor = radius > myAttachedReactor.getRadius() ? myAttachedReactor.getRadius() * myAttachedReactor.getRadius() / radius / radius : radius * radius / myAttachedReactor.getRadius() / myAttachedReactor.getRadius(); }
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; } //myAttachedEngine.DeactivateRunningFX(); } else { //myAttachedEngine.ActivateRunningFX(); } double thermal_consume_total = assThermalPower * TimeWarp.fixedDeltaTime * myAttachedEngine.currentThrottle * atmospheric_limit; double thermal_power_received = consumeFNResource(thermal_consume_total, FNResourceManager.FNRESOURCE_THERMALPOWER) / TimeWarp.fixedDeltaTime; if (thermal_power_received * TimeWarp.fixedDeltaTime < thermal_consume_total) { thermal_power_received += consumeFNResource(thermal_consume_total - thermal_power_received * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_CHARGED_PARTICLES) / 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)/ispratio; double engine_thrust = engineMaxThrust / myAttachedEngine.thrustPercentage * 100; // 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.2222 * 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 && myAttachedEngine.velocityCurve != null) { vcurve_at_current_velocity = myAttachedEngine.velocityCurve.Evaluate((float)vessel.srf_velocity.magnitude); } //if (!double.IsNaN(additional_thrust_compensator) && !double.IsInfinity(additional_thrust_compensator)) { //vcurve_at_current_velocity = additional_thrust_compensator; //} fuel_flow_rate = engine_thrust / current_isp / g0 / 0.005 * TimeWarp.fixedDeltaTime; if (vcurve_at_current_velocity > 0 && !double.IsInfinity(vcurve_at_current_velocity) && !double.IsNaN(vcurve_at_current_velocity)) { fuel_flow_rate = fuel_flow_rate / vcurve_at_current_velocity; } if (atmospheric_limit > 0 && !double.IsInfinity(atmospheric_limit) && !double.IsNaN(atmospheric_limit)) { fuel_flow_rate = fuel_flow_rate / atmospheric_limit; } } } 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; if (vcurve_at_current_velocity > 0 && !double.IsInfinity(vcurve_at_current_velocity) && !double.IsNaN(vcurve_at_current_velocity)) { fuel_flow_rate = fuel_flow_rate / 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; }