public void updateGeneratorPower() { hotBathTemp = myAttachedReactor.getCoreTemp(); 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.getThermalPower() * heat_exchanger_thrust_divisor; maxChargedPower = myAttachedReactor.getChargedPower() * heat_exchanger_thrust_divisor; coldBathTemp = (float)FNRadiator.getAverageRadiatorTemperatureForVessel(vessel); }
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; } part.temperature = (float)Math.Max((Math.Sqrt(vessel.srf_velocity.magnitude) * 20.0 / GameConstants.atmospheric_non_precooled_limit) * part.maxTemp * proportion, 1); } 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; }