Exemple #1
0
        private static void ProcessUnloadedSolarPanels(VesselData vesselData)
        {
            if (DetectKerbalism.Found)
            {
                return;
            }

            if (!vesselData.SolarPanels.Any())
            {
                return;
            }

            foreach (StarLight starlight in KopernicusHelper.Stars)
            {
                double starlightRelativeLuminosity = KopernicusHelper.GetSolarDistanceMultiplier(
                    vesselPosition: vesselData.Position,
                    star: starlight.star,
                    astronomicalUnit: KopernicusHelper.AstronomicalUnit);

                starlightRelativeLuminosity *= starlight.relativeLuminosity;

                // ignore stars that are too far away to give any meaningful energy
                if (starlightRelativeLuminosity < 0.001)
                {
                    continue;
                }

                // ignore if there is no line of sight between the star and the vessel
                if (!KopernicusHelper.LineOfSightToSun(vesselData.Position, starlight.star))
                {
                    continue;
                }

                foreach (KeyValuePair <uint, SolarPanelData> keyValuePair in vesselData.SolarPanels)
                {
                    SolarPanelData solarPanelData = keyValuePair.Value;

                    foreach (ModuleDeployableSolarPanel solarPanel in solarPanelData.ModuleDeployableSolarPanels)
                    {
                        if (solarPanel.chargeRate <= 0)
                        {
                            continue;
                        }

                        if (solarPanel.deployState != ModuleDeployablePart.DeployState.EXTENDED)
                        {
                            continue;
                        }

                        double trackingModifier = solarPanel.isTracking ? 1 : 0.25;
                        double powerChange      = trackingModifier * solarPanel.chargeRate * starlightRelativeLuminosity * solarPanel.efficiencyMult * solarPanelData.ChargeRateMultiplier;

                        vesselData.UpdateAvailableResource(solarPanel.resourceName, powerChange);
                        vesselData.ResourceChange(solarPanel.resourceName, powerChange);
                    }
                }
            }
        }