Esempio n. 1
0
        public override void OnFixedUpdate()
        {
            float atmosphere_height = vessel.mainBody.maxAtmosphereAltitude;
            float vessel_height     = (float)vessel.mainBody.GetAltitude(vessel.transform.position);
            float conv_power_dissip = 0;

            if (vessel.altitude <= PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody))
            {
                float pressure         = (float)FlightGlobals.getStaticPressure(vessel.transform.position);
                float dynamic_pressure = (float)(0.5 * pressure * 1.2041 * vessel.srf_velocity.sqrMagnitude / 101325.0);
                pressure += dynamic_pressure;
                float low_temp = FlightGlobals.getExternalTemperature(vessel.transform.position);

                float delta_temp = Mathf.Max(0, radiatorTemp - low_temp);
                conv_power_dissip = pressure * delta_temp * radiatorArea * rad_const_h / 1e6f * TimeWarp.fixedDeltaTime * convectiveBonus;
                if (!radiatorIsEnabled)
                {
                    conv_power_dissip = conv_power_dissip / 2.0f;
                }
                convectedThermalPower = consumeFNResource(conv_power_dissip, FNResourceManager.FNRESOURCE_WASTEHEAT) / TimeWarp.fixedDeltaTime;

                if (radiatorIsEnabled && dynamic_pressure > 1.4854428818159388107574636072046e-3 && isDeployable)
                {
                    part.deactivate();

                    //part.breakingForce = 1;
                    //part.breakingTorque = 1;
                    part.decouple(1);
                }
            }


            if (radiatorIsEnabled)
            {
                if (getResourceBarRatio(FNResourceManager.FNRESOURCE_WASTEHEAT) >= 1 && current_rad_temp >= radiatorTemp)
                {
                    explode_counter++;
                    if (explode_counter > 25)
                    {
                        part.explode();
                    }
                }
                else
                {
                    explode_counter = 0;
                }

                double radiator_temperature_temp_val = radiatorTemp * Math.Pow(getResourceBarRatio(FNResourceManager.FNRESOURCE_WASTEHEAT), 0.25);
                if (FNReactor.hasActiveReactors(vessel))
                {
                    radiator_temperature_temp_val = Math.Min(FNReactor.getTemperatureofColdestReactor(vessel) / 1.01, radiator_temperature_temp_val);
                }

                double thermal_power_dissip = (GameConstants.stefan_const * radiatorArea * Math.Pow(radiator_temperature_temp_val, 4) / 1e6) * TimeWarp.fixedDeltaTime;
                radiatedThermalPower = consumeFNResource(thermal_power_dissip, FNResourceManager.FNRESOURCE_WASTEHEAT) / TimeWarp.fixedDeltaTime;
                double instantaneous_rad_temp = (Math.Min(Math.Pow(radiatedThermalPower * 1e6 / (GameConstants.stefan_const * radiatorArea), 0.25), radiatorTemp));
                instantaneous_rad_temp = Math.Max(instantaneous_rad_temp, Math.Max(FlightGlobals.getExternalTemperature((float)vessel.altitude, vessel.mainBody) + 273.16, 2.7));
                if (current_rad_temp <= 0)
                {
                    current_rad_temp = instantaneous_rad_temp;
                }
                else
                {
                    current_rad_temp = instantaneous_rad_temp * alpha + (1.0 - alpha) * instantaneous_rad_temp;
                }

                if (isDeployable)
                {
                    Vector3 pivrot = pivot.rotation.eulerAngles;

                    pivot.Rotate(Vector3.up * 5f * TimeWarp.fixedDeltaTime * directionrotate);

                    Vector3 sunpos             = FlightGlobals.Bodies [0].transform.position;
                    Vector3 flatVectorToTarget = sunpos - transform.position;

                    flatVectorToTarget = flatVectorToTarget.normalized;
                    float dot = Mathf.Asin(Vector3.Dot(pivot.transform.right, flatVectorToTarget)) / Mathf.PI * 180.0f;

                    float anglediff = -dot;
                    oldangle = dot;
                    //print (dot);
                    directionrotate = anglediff / 5 / TimeWarp.fixedDeltaTime;
                    directionrotate = Mathf.Min(3, directionrotate);
                    directionrotate = Mathf.Max(-3, directionrotate);

                    part.maximum_drag = 0.8f;
                    part.minimum_drag = 0.8f;
                }
            }
            else
            {
                if (isDeployable)
                {
                    pivot.transform.localEulerAngles = original_eulers;
                }

                double radiator_temperature_temp_val = radiatorTemp * Math.Pow(getResourceBarRatio(FNResourceManager.FNRESOURCE_WASTEHEAT), 0.25);
                if (FNReactor.hasActiveReactors(vessel))
                {
                    radiator_temperature_temp_val = Math.Min(FNReactor.getTemperatureofColdestReactor(vessel) / 1.01, radiator_temperature_temp_val);
                }

                double thermal_power_dissip = (GameConstants.stefan_const * radiatorArea * Math.Pow(radiator_temperature_temp_val, 4) / 1e7) * TimeWarp.fixedDeltaTime;
                radiatedThermalPower = consumeFNResource(thermal_power_dissip, FNResourceManager.FNRESOURCE_WASTEHEAT) / TimeWarp.fixedDeltaTime;
                double instantaneous_rad_temp = (Math.Min(Math.Pow(radiatedThermalPower * 1e7 / (GameConstants.stefan_const * radiatorArea), 0.25), radiatorTemp));
                instantaneous_rad_temp = Math.Max(instantaneous_rad_temp, Math.Max(FlightGlobals.getExternalTemperature((float)vessel.altitude, vessel.mainBody) + 273.16, 2.7));
                if (current_rad_temp <= 0)
                {
                    current_rad_temp = instantaneous_rad_temp;
                }
                else
                {
                    current_rad_temp = instantaneous_rad_temp * alpha + (1.0 - alpha) * instantaneous_rad_temp;
                }

                part.maximum_drag = 0.2f;
                part.minimum_drag = 0.2f;
            }
        }
Esempio n. 2
0
        public void recalculatePower()
        {
            Part[] childParts = this.part.FindChildParts<Part>(false);
            PartModuleList childModules;

            foreach (Part childPart in childParts) {
                childModules = childPart.Modules;
                foreach (PartModule thisModule in childModules) {
                    var thisModule2 = thisModule as FNReactor;
                    if (thisModule2 != null) {
                        FNReactor fnr = (FNReactor)thisModule;
                        setHotBathTemp(fnr.getReactorTemp());
                        maxThermalPower = fnr.getReactorThermalPower();
                        myReactor = fnr;
                    }
                }
            }

            Part parent = this.part.parent;
            if (parent != null) {
                childModules = parent.Modules;
                foreach (PartModule thisModule in childModules) {
                    var thisModule2 = thisModule as FNReactor;
                    if (thisModule2 != null) {
                        FNReactor fnr = (FNReactor)thisModule;
                        setHotBathTemp(fnr.getReactorTemp());
                        maxThermalPower = fnr.getReactorThermalPower();
                        myReactor = fnr;
                    }
                }
            }
        }