コード例 #1
0
        public void FixedUpdate()
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (!active)
                {
                    base.OnFixedUpdate();
                }

                if (solarPanel != null)
                {
                    double     inv_square_mult = Math.Pow(Vector3d.Distance(FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBIN].transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2) / Math.Pow(Vector3d.Distance(vessel.transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2);
                    FloatCurve satcurve        = new FloatCurve();
                    satcurve.Add(0.0f, (float)inv_square_mult);
                    solarPanel.powerCurve = satcurve;

                    float solar_rate = solarPanel.flowRate * TimeWarp.fixedDeltaTime;
                    float clamper    = PluginHelper.isSolarPanelHeatingClamped() ?
                                       (float)Math.Min(Math.Max((Math.Sqrt(inv_square_mult) - 1.5), 0.0), 1.0) :
                                       1.0f;
                    float heat_rate = clamper * solar_rate * 0.5f / 1000.0f;

                    if (getResourceBarRatio(FNResourceManager.FNRESOURCE_WASTEHEAT) >= 0.98 && solarPanel.panelState == ModuleDeployableSolarPanel.panelStates.EXTENDED && solarPanel.sunTracking)
                    {
                        solarPanel.Retract();
                        if (FlightGlobals.ActiveVessel == vessel)
                        {
                            ScreenMessages.PostScreenMessage("Warning Dangerous Overheating Detected: Solar Panel retraction occuring NOW!", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                        }
                        return;
                    }

                    List <PartResource> prl = part.GetConnectedResources("ElectricCharge").ToList();
                    double current_charge   = prl.Sum(pr => pr.amount);
                    double max_charge       = prl.Sum(pr => pr.maxAmount);

                    supplyFNResourceFixedMax(current_charge >= max_charge ? solar_rate / 1000.0f : 0, solar_rate / 1000.0f, FNResourceManager.FNRESOURCE_MEGAJOULES);
                    wasteheat_production_f = supplyFNResource(heat_rate, FNResourceManager.FNRESOURCE_WASTEHEAT) / TimeWarp.fixedDeltaTime * 1000.0f;
                }
            }
        }