Esempio n. 1
0
        public void FixedUpdate() // FixedUpdate is also called when not activated
        {
            try
            {
                UpdateWasteheatBuffer();

                if (!HighLogic.LoadedSceneIsFlight)
                {
                    return;
                }

                if (!active)
                {
                    base.OnFixedUpdate();
                }

                effectiveRadiatorArea = EffectiveRadiatorArea;

                var external_temperature = FlightGlobals.getExternalTemperature(part.transform.position);

                wasteheatManager = getManagerForVessel(ResourceManager.FNRESOURCE_WASTEHEAT);

                // get resource bar ratio at start of frame
                wasteheatRatio = wasteheatManager.ResourceBarRatio;

                if (Double.IsNaN(wasteheatRatio))
                {
                    Debug.LogError("FNRadiator: FixedUpdate Single.IsNaN detected in wasteheatRatio");
                    return;
                }

                var normalized_atmosphere = Math.Min(vessel.atmDensity, 1);

                maxCurrentTemperature = maxAtmosphereTemperature * Math.Max(normalized_atmosphere, 0) + maxVacuumTemperature * Math.Max(Math.Min(1 - vessel.atmDensity, 1), 0);

                radiator_temperature_temp_val = external_temperature + Math.Min((maxRadiatorTemperature - external_temperature) * Math.Sqrt(wasteheatRatio), maxCurrentTemperature - external_temperature);

                var efficiency = 1 - Math.Pow(1 - wasteheatRatio, 400);
                var delta_temp = Math.Max(radiator_temperature_temp_val - Math.Max(external_temperature * normalized_atmosphere, 2.7), 0);

                if (radiatorIsEnabled)
                {
                    if (!CheatOptions.IgnoreMaxTemperature && wasteheatRatio >= 1 && CurrentRadiatorTemperature >= maxRadiatorTemperature)
                    {
                        explode_counter++;
                        if (explode_counter > 25)
                        {
                            part.explode();
                        }
                    }
                    else
                    {
                        explode_counter = 0;
                    }

                    var thermal_power_dissip_per_second = efficiency * Math.Pow(delta_temp, 4) * GameConstants.stefan_const * effectiveRadiatorArea / 1e6;

                    if (Double.IsNaN(thermal_power_dissip_per_second))
                    {
                        Debug.LogWarning("FNRadiator: FixedUpdate Single.IsNaN detected in fixed_thermal_power_dissip");
                    }

                    radiatedThermalPower = canRadiateHeat ? consumeWasteHeatPerSecond(thermal_power_dissip_per_second) : 0;

                    if (Double.IsNaN(radiatedThermalPower))
                    {
                        Debug.LogError("FNRadiator: FixedUpdate Single.IsNaN detected in radiatedThermalPower after call consumeWasteHeat (" + thermal_power_dissip_per_second + ")");
                    }

                    instantaneous_rad_temp = Math.Max(radiator_temperature_temp_val, Math.Max(FlightGlobals.getExternalTemperature(vessel.altitude, vessel.mainBody), 2.7));

                    if (Double.IsNaN(instantaneous_rad_temp))
                    {
                        Debug.LogError("FNRadiator: FixedUpdate Single.IsNaN detected in instantaneous_rad_temp after reading external temperature");
                    }

                    CurrentRadiatorTemperature = instantaneous_rad_temp;

                    if (_moduleDeployableRadiator)
                    {
                        _moduleDeployableRadiator.hasPivot = pivotEnabled;
                    }
                }
                else
                {
                    double thermal_power_dissip_per_second = efficiency * Math.Pow(Math.Max(delta_temp - external_temperature, 0), 4) * GameConstants.stefan_const * effectiveRadiatorArea / 0.5e7;

                    radiatedThermalPower = canRadiateHeat ? consumeWasteHeatPerSecond(thermal_power_dissip_per_second) : 0;

                    instantaneous_rad_temp = Math.Max(radiator_temperature_temp_val, Math.Max(FlightGlobals.getExternalTemperature(vessel.altitude, vessel.mainBody), 2.7));

                    CurrentRadiatorTemperature = instantaneous_rad_temp;
                }

                if (vessel.atmDensity > 0)
                {
                    var pressure = vessel.atmDensity;
                    dynamic_pressure = 0.60205 * pressure * vessel.srf_velocity.sqrMagnitude / 101325;
                    pressure        += dynamic_pressure;

                    var splashBonus           = Math.Max(part.submergedPortion * 10, 1);
                    var convection_delta_temp = Math.Max(0, CurrentRadiatorTemperature - external_temperature);
                    var conv_power_dissip     = efficiency * pressure * convection_delta_temp * effectiveRadiatorArea * 0.001 * convectiveBonus * splashBonus;

                    if (!radiatorIsEnabled)
                    {
                        conv_power_dissip = conv_power_dissip / 2;
                    }

                    convectedThermalPower = canRadiateHeat ? consumeWasteHeatPerSecond(conv_power_dissip) : 0;

                    if (update_count == 6)
                    {
                        DeployMentControl(dynamic_pressure);
                    }
                }
                else
                {
                    convectedThermalPower = 0;

                    if (!radiatorIsEnabled && isAutomated && canRadiateHeat && showControls && update_count == 6)
                    {
                        Debug.Log("[KSPI] - FixedUpdate Automated Deplotment ");
                        Deploy();
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI] - FNRadiator.FixedUpdate" + e.Message);
            }
        }