예제 #1
0
        /// <summary>
        /// Runs before <see cref="ModuleDeployableSolarPanel.FixedUpdate"/>.
        /// </summary>
        void FixedUpdate()
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                // Start from the target body
                if (SP != null)
                {
                    KopernicusStar star = KopernicusStar.CelestialBodies[SP.trackingBody];
                    star.shifter.ApplyPhysics();

                    vessel.solarFlux = star.CalculateFluxAt(vessel) * PhysicsGlobals.SolarLuminosityAtHome / 1360;
                }
            }
        }
예제 #2
0
        public override void FixedUpdate()
        {
            base.FixedUpdate();
            frameTimer++;
            if (HighLogic.LoadedSceneIsFlight)
            {
                if ((deployState == ModuleDeployablePart.DeployState.EXTENDED))
                {
                    if (frameTimer > (50 * Kopernicus.RuntimeUtility.RuntimeUtility.KopernicusConfig.SolarRefreshRate))
                    {
                        CelestialBody trackingStar = trackingBody;
                        frameTimer = 0;
                        KopernicusStar bestStar  = KopernicusStar.CelestialBodies[trackingStar];
                        Double         totalFlux = 0;
                        Double         totalFlow = 0;
                        flowRate  = 0;
                        _flowRate = 0;
                        Double bestFlux = 0;
                        for (Int32 s = 0; s < KopernicusStar.Stars.Count; s++)
                        {
                            KopernicusStar star = KopernicusStar.Stars[s];
                            // Use this star
                            star.shifter.ApplyPhysics();

                            // Set Tracking Speed to zero
                            Single oldTrackingSpeed = trackingSpeed;
                            trackingSpeed = 0;

                            // Change the tracking body
                            trackingBody = star.sun;
                            GetTrackingBodyTransforms();
                            CalculateTracking();

                            //Calculate flux
                            double starFlux = star.CalculateFluxAt(vessel) * 1360 / PhysicsGlobals.SolarLuminosityAtHome;

                            //Check if star has better flux
                            if (bestFlux < starFlux)
                            {
                                bestFlux = starFlux;
                                bestStar = star;
                            }

                            // Add to TotalFlux and EC tally
                            totalFlux += starFlux;
                            float panelEffectivness = 0;
                            //Now for some fancy atmospheric math
                            float    atmoDensityMult = 1;
                            float    atmoAngleMult   = 1;
                            float    tempMult        = 1;
                            Vector3d localSpace      = ScaledSpace.ScaledToLocalSpace(star.target.position);
                            if (this.vessel.atmDensity > 0)
                            {
                                float   horizonAngle      = (float)Math.Acos(FlightGlobals.currentMainBody.Radius / (FlightGlobals.currentMainBody.Radius + FlightGlobals.ship_altitude));
                                Vector3 horizonVector     = new Vector3(0, Mathf.Sin(Mathf.Deg2Rad * horizonAngle), Mathf.Cos(Mathf.Deg2Rad * horizonAngle));
                                float   sunZenithAngleDeg = Vector3.Angle(FlightGlobals.upAxis, star.sun.position);

                                Double gravAccelParameter = (vessel.mainBody.gravParameter / Math.Pow(vessel.mainBody.Radius + FlightGlobals.ship_altitude, 2));
                                float  massOfAirColumn    = (float)(FlightGlobals.getStaticPressure() / gravAccelParameter);

                                tempMult        = this.temperatureEfficCurve.Evaluate((float)this.vessel.atmosphericTemperature);
                                atmoDensityMult = AtmosphericAttenutationAirMassMultiplier.Evaluate(massOfAirColumn);
                                atmoAngleMult   = AtmosphericAttenutationSolarAngleMultiplier.Evaluate(sunZenithAngleDeg);
                            }

                            panelEffectivness = (chargeRate / 24.4f) / 56.37091313591871f * sunAOA * tempMult * atmoAngleMult * atmoDensityMult;  //56.blabla is a weird constant we use to turn flux into EC
                            totalFlow        += (starFlux * panelEffectivness) / (1360 / PhysicsGlobals.SolarLuminosityAtHome);
                            // Restore Tracking Speed
                            trackingSpeed = oldTrackingSpeed;
                        }
                        // Restore the starting star
                        trackingBody = trackingStar;
                        KopernicusStar.CelestialBodies[trackingStar].shifter.ApplyPhysics();
                        GetTrackingBodyTransforms();
                        CalculateTracking();
                        vessel.solarFlux = totalFlux;
                        //Add to new output
                        flowRate  = (float)totalFlow;
                        _flowRate = totalFlow / chargeRate;
                        resHandler.UpdateModuleResourceOutputs(_flowRate);
                        //caching logic
                        cachedFlowRate  = flowRate;
                        _cachedFlowRate = _flowRate;
                        // Setup next tracking body
                        if ((bestStar != null && bestStar != trackingBody) && (!_manualTracking))
                        {
                            trackingBody = bestStar.sun;
                            GetTrackingBodyTransforms();
                            CalculateTracking();
                        }
                    }
                    else
                    {
                        //inbetween timings logic
                        flowRate  = cachedFlowRate;
                        _flowRate = _cachedFlowRate;
                        resHandler.UpdateModuleResourceOutputs(_flowRate);
                    }

                    //see if tracked star is blocked or not
                    if (sunAOA > 0)
                    {
                        //this ensures the "blocked" GUI option is set right, if we're exposed to you we're not blocked
                        vessel.directSunlight = true;
                    }
                    // Restore The Current Star
                    KopernicusStar.Current.shifter.ApplyPhysics();
                }
            }
            else
            {
                //Packed logic
                flowRate  = cachedFlowRate;
                _flowRate = _cachedFlowRate;
                resHandler.UpdateModuleResourceOutputs(_flowRate);
            }
        }
예제 #3
0
        /// <summary>
        /// Runs before <see cref="ModuleDeployableSolarPanel.FixedUpdate"/>.
        /// </summary>
        void FixedUpdate()
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                for (Int32 n = 0; n < SPs.Length; n++)
                {
                    ModuleDeployableSolarPanel SP = SPs[n];

                    if (SP.deployState == ModuleDeployablePart.DeployState.EXTENDED)
                    {
                        KopernicusStar trackingStar = KopernicusStar.CelestialBodies[SP.trackingBody];

                        Double         bestFlux   = vessel.solarFlux * 1360 / PhysicsGlobals.SolarLuminosityAtHome;
                        KopernicusStar bestStar   = trackingStar;
                        Double         totalFlux  = 0;
                        Single         totalAoA   = SP.sunAOA;
                        Double         _totalFlow = SP._flowRate;
                        Single         totalFlow  = SP.flowRate;

                        for (Int32 s = 0; s < KopernicusStar.Stars.Count; s++)
                        {
                            KopernicusStar star = KopernicusStar.Stars[s];

                            if (star != trackingStar)
                            {
                                // Use this star
                                star.shifter.ApplyPhysics();
                                double flux = star.CalculateFluxAt(vessel);
                                vessel.solarFlux += flux * PhysicsGlobals.SolarLuminosityAtHome / 1360;

                                // Change the tracking body
                                SP.trackingBody = star.sun;
                                SP.GetTrackingBodyTransforms();

                                // Set Tracking Speed to zero
                                Single trackingSpeed = SP.trackingSpeed;
                                SP.trackingSpeed = 0;

                                // Run The MDSP CalculateTracking
                                SP.CalculateTracking();

                                // Add to TotalFlux and TotalAoA
                                totalFlux  += vessel.solarFlux;
                                totalAoA   += SP.sunAOA;
                                _totalFlow += SP._flowRate;
                                totalFlow  += SP.flowRate;

                                if (bestFlux < flux)
                                {
                                    bestFlux = flux;
                                    bestStar = star;
                                }

                                // Restore Tracking Speed
                                SP.trackingSpeed = trackingSpeed;
                            }
                        }

                        // Restore the tracking body
                        SP.trackingBody = trackingStar.sun;
                        SP.GetTrackingBodyTransforms();

                        // Restore the starting star
                        trackingStar.shifter.ApplyPhysics();

                        totalFlux += trackingStar.CalculateFluxAt(vessel) * PhysicsGlobals.SolarLuminosityAtHome / 1360;

                        vessel.solarFlux = totalFlux;
                        SP.sunAOA        = totalAoA;
                        SP.sunAOA       /= _relativeSunAoa ? KopernicusStar.Stars.Count : 1;
                        SP._flowRate     = _totalFlow;
                        SP.flowRate      = totalFlow;

                        // We got the best star to use
                        if (bestStar != null && bestStar.sun != SP.trackingBody)
                        {
                            if (!_manualTracking)
                            {
                                SP.trackingBody = bestStar.sun;
                                SP.GetTrackingBodyTransforms();
                                continue;
                            }
                        }
                    }
                }

                // Restore The Current Star
                KopernicusStar.Current.shifter.ApplyPhysics();
            }
        }