internal void GetSolarPanels()
 {
     _solarPanels.Clear();
     try
     {
         foreach (Part pPart in SMAddon.vessel.Parts)
         {
             foreach (PartModule pModule in pPart.Modules)
             {
                 if (pModule.moduleName == "ModuleDeployableSolarPanel")
                 {
                     ModuleDeployableSolarPanel iModule = (ModuleDeployableSolarPanel)pModule;
                     if (iModule.Events["Extend"].active || iModule.Events["Retract"].active)
                     {
                         ModSolarPanel pPanel = new ModSolarPanel();
                         pPanel.PanelModule = pModule;
                         pPanel.SPart       = pPart;
                         _solarPanels.Add(pPanel);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Utilities.LogMessage(string.Format("Error in GetSolarPanels().\r\nError:  {0}", ex.ToString()), "Error", true);
     }
 }
 protected override void Overrides()
 {
     Fields["displayChance"].guiName = "Chance of Solar Panel Failure";
     Fields["safetyRating"].guiName  = "Solar Panel Safety Rating";
     remoteRepairable = true;
     panel            = part.FindModuleImplementing <ModuleDeployableSolarPanel>();
 }
示例#3
0
        private double CalculateSolarPower()
        {
            double solarPower    = 0;
            double distanceToSun = this.vessel.distanceToSun;
            double solarFlux     = PhysicsGlobals.SolarLuminosity / (12.566370614359172 * distanceToSun * distanceToSun);
            float  multiplier    = 1;

            for (int i = 0; i < this.vessel.parts.Count; ++i)
            {
                ModuleDeployableSolarPanel solarPanel = this.vessel.parts[i].FindModuleImplementing <ModuleDeployableSolarPanel>();
                if (solarPanel == null)
                {
                    continue;
                }
                if (solarPanel.deployState != ModuleDeployableSolarPanel.DeployState.BROKEN &&
                    solarPanel.deployState != ModuleDeployableSolarPanel.DeployState.RETRACTED &&
                    solarPanel.deployState != ModuleDeployableSolarPanel.DeployState.RETRACTING)
                {
                    if (solarPanel.useCurve)
                    {
                        multiplier = solarPanel.powerCurve.Evaluate((float)distanceToSun);
                    }
                    else
                    {
                        multiplier = (float)(solarFlux / PhysicsGlobals.SolarLuminosityAtHome);
                    }
                    solarPower += solarPanel.chargeRate * multiplier;
                }
            }
            return(solarPower);
        }
        public override void OnStart(PartModule.StartState state)
        {
            base.OnStart(state);

            transformsA       = part.FindModelTransforms(transformNameA);
            transformsB       = part.FindModelTransforms(transformNameB);
            raycastTransformA = part.FindModelTransforms(raycastTransformNameA).FirstOrDefault();
            raycastTransformB = part.FindModelTransforms(raycastTransformNameB).FirstOrDefault();
            if (raycastTransformA == null)
            {
                Debug.Log("[ModuleBdbSymmetricalPart]: OnStart() raycastTransformA is null");
            }
            if (raycastTransformB == null)
            {
                Debug.Log("[ModuleBdbSymmetricalPart]: OnStart() raycastTransformB is null");
            }
            if (raycastTransformA != null && raycastTransformB != null)
            {
                solarPanel  = this.GetComponents <ModuleDeployableSolarPanel>().FirstOrDefault <ModuleDeployableSolarPanel>();
                updateSolar = solarPanel != null;
                if (solarPanel == null)
                {
                    Debug.Log("[ModuleBdbSymmetricalPart]: OnStart() solarPanel is null");
                }
            }

            UpdateTransforms();
            if (state == StartState.Editor)
            {
                this.part.OnEditorAttach += OnEditorAttach;
            }
        }
示例#5
0
        /// <summary>
        /// Calculate available power from solar panels
        /// </summary>
        /// <returns></returns>
        private double GetAvailablePower_Solar()
        {
            // Kopernicus sets the right values for PhysicsGlobals.SolarLuminosity and PhysicsGlobals.SolarLuminosityAtHome so we can use them in all cases
            double solarPower    = 0;
            double distanceToSun = Vector3d.Distance(vessel.GetWorldPos3D(), FlightGlobals.Bodies[mainStarIndex].position);
            double solarFlux     = PhysicsGlobals.SolarLuminosity / (4 * Math.PI * distanceToSun * distanceToSun); // f = L / SA = L / 4π r2 (Wm-2)
            float  multiplier    = 1;

            for (int i = 0; i < vessel.parts.Count; ++i)
            {
                ModuleDeployableSolarPanel solarPanel = vessel.parts[i].FindModuleImplementing <ModuleDeployableSolarPanel>();
                if (solarPanel == null)
                {
                    continue;
                }

                if ((solarPanel.deployState != ModuleDeployablePart.DeployState.BROKEN) && (solarPanel.deployState != ModuleDeployablePart.DeployState.RETRACTED) && (solarPanel.deployState != ModuleDeployablePart.DeployState.RETRACTING))
                {
                    if (solarPanel.useCurve) // Power curve
                    {
                        multiplier = solarPanel.powerCurve.Evaluate((float)distanceToSun);
                    }
                    else // solar flux at current distance / solar flux at 1AU (Kerbin in stock, other value in Kopernicus)
                    {
                        multiplier = (float)(solarFlux / PhysicsGlobals.SolarLuminosityAtHome);
                    }
                    solarPower += solarPanel.chargeRate * multiplier;
                }
            }

            return(solarPower);
        }
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            megaJouleSolarPowerSupplyField = Fields["megaJouleSolarPowerSupply"];
            solarMaxSupplyField            = Fields["solarMaxSupply"];

            // calculate Astronomical unit on homeworld semiMajorAxis when missing
            if (astronomicalUnit == 0)
            {
                astronomicalUnit = FlightGlobals.GetHomeBody().orbit.semiMajorAxis;
            }

            _microwavePowerReceiver = part.FindModuleImplementing <BeamedPowerReceiver>();

            _solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>();
            if (_solarPanel == null)
            {
                return;
            }

            if (this.part.FindModuleImplementing <ModuleJettison>() == null)
            {
                UnityEngine.Debug.Log("[KSPI]: FNSolarPanelWasteHeatModule Force Activated  " + part.name);
                part.force_activate();
            }

            String[] resources_to_supply = { ResourceManager.FNRESOURCE_MEGAJOULES };
            this.resources_to_supply = resources_to_supply;
            base.OnStart(state);

            if (_solarPanel.resourceName == ResourceManager.FNRESOURCE_MEGAJOULES)
            {
                _outputType = ResourceType.megajoule;
            }
            else if (_solarPanel.resourceName == ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE)
            {
                _outputType = ResourceType.electricCharge;
            }
            else
            {
                _outputType = ResourceType.other;
            }

            // only manage power buffer when microwave receiver is not available
            if (_outputType != ResourceType.other && _microwavePowerReceiver == null)
            {
                _resourceBuffers = new ResourceBuffers();
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_MEGAJOULES));
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE));
                _resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_MEGAJOULES, (double)(decimal)(_outputType == ResourceType.electricCharge ? _solarPanel.chargeRate * 0.001f : _solarPanel.chargeRate));
                _resourceBuffers.UpdateVariable(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE, (double)(decimal)(_outputType == ResourceType.electricCharge ? _solarPanel.chargeRate : _solarPanel.chargeRate * 1000));
                _resourceBuffers.Init(part);
            }

            _stars = KopernicusHelper.Stars;
        }
示例#7
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            List <ModuleDeployableSolarPanel> solarModules = this.part.FindModulesImplementing <ModuleDeployableSolarPanel>();

            if (solarModules.Count > 0)
            {
                if (rotationModuleIndex >= 0 && rotationModuleIndex < solarModules.Count - 1)
                {
                    rotationModule = solarModules[rotationModuleIndex];
                }
            }

            if (rotationModule != null)
            {
                foreach (BaseField field in rotationModule.Fields)
                {
                    field.guiActive       = false;
                    field.guiActiveEditor = false;
                }

                foreach (BaseEvent baseEvent in rotationModule.Events)
                {
                    baseEvent.guiActive          = false;
                    baseEvent.guiActiveEditor    = false;
                    baseEvent.guiActiveUnfocused = false;
                }
            }
        }
 public override void OnStart(StartState state)
 {
     if (HighLogic.LoadedSceneIsFlight)
     {
         SP = GetComponent <ModuleDeployableSolarPanel>();
     }
 }
        [KSPEvent(active = true, guiActive = false, guiName = "#Kopernicus_UI_SelectBody")]//Select Tracking Body
        public void ManualTracking()
        {
            // Assemble the buttons
            Int32 stars = KopernicusStar.Stars.Count;

            DialogGUIBase[] options = new DialogGUIBase[stars + 1];
            options[0] = new DialogGUIButton(button_Auto, () => { _manualTracking = false; }, true);//Auto
            for (Int32 i = 0; i < stars; i++)
            {
                CelestialBody body = KopernicusStar.Stars[i].sun;
                options[i + 1] = new DialogGUIButton
                                 (
                    body.bodyDisplayName.Replace("^N", ""),
                    () =>
                {
                    for (int n = SPs?.Length ?? 0; n > 0; n--)
                    {
                        ModuleDeployableSolarPanel SP = SPs[n - 1];
                        _manualTracking = true;
                        SP.trackingBody = body;
                        SP.GetTrackingBodyTransforms();
                    }
                },
                    true
                                 );
            }

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog(
                                             "SelectTrackingBody",
                                             SelectBody_Msg, //Please select the Body you want to track with this Solar Panel.
                                             SelectBody,     //Select Tracking Body
                                             UISkinManager.GetSkin("MainMenuSkin"),
                                             options), false, UISkinManager.GetSkin("MainMenuSkin"));
        }
		public override void OnStart(PartModule.StartState state) {
			String[] resources_to_supply = {FNResourceManager.FNRESOURCE_WASTEHEAT, FNResourceManager.FNRESOURCE_MEGAJOULES};
			this.resources_to_supply = resources_to_supply;
			base.OnStart (state);
			if (state == StartState.Editor) { return; }
			solarPanel = (ModuleDeployableSolarPanel)this.part.Modules["ModuleDeployableSolarPanel"];
		}
示例#11
0
        private void CalculateRates()
        {
            double currentPeMeters, currentApMeters, theOrbit = 0.0;

            ModuleDeployableSolarPanel pm = part.Modules.GetModule <ModuleDeployableSolarPanel>();
            float timeEfficEvaluated      = pm.timeEfficCurve.Evaluate(daysElapsed);

            solarEfficiency = timeEfficEvaluated * 100;
            double currentOutput = pm.chargeRate * timeEfficEvaluated;

            if (HighLogic.LoadedSceneIsEditor)
            {
                currentPeMeters = _getAU(FlightGlobals.GetBodyByName(selectedBody).orbit.PeA);
                currentApMeters = _getAU(FlightGlobals.GetBodyByName(selectedBody).orbit.ApA);
                solarOutputPe   = Math.Round(_getModifier(currentPeMeters) * currentOutput * 1000, 2).ToString() + " Watts";
                solarOutputAp   = Math.Round(_getModifier(currentApMeters) * currentOutput * 1000, 2).ToString() + " Watts";

                //solarOutputPe = currentPe.ToString() + " Watts";
                //solarOutputAp = currentAp.ToString() + " Watts";
            }

            if (HighLogic.LoadedSceneIsFlight)
            {
                double mod = _getModifier(currentOrbit);
                theOrbit     = Math.Round(mod * currentOutput * 1000, 2);
                futureOutput = theOrbit.ToString() + " Watts";
            }
        }
示例#12
0
        // TODO : this is to migrate pre-3.1 saves using WarpFixer to the new SolarPanelFixer. At some point in the future we can remove this code.
        static void MigrateWarpFixer(Vessel v, Part prefab, ProtoPartSnapshot p, ProtoPartModuleSnapshot m)
        {
            ModuleDeployableSolarPanel panelModule      = prefab.FindModuleImplementing <ModuleDeployableSolarPanel>();
            ProtoPartModuleSnapshot    protoPanelModule = p.modules.Find(pm => pm.moduleName == "ModuleDeployableSolarPanel");

            if (panelModule == null || protoPanelModule == null)
            {
                Lib.Log("Vessel " + v.name + " has solar panels that can't be converted automatically following Kerbalism 3.1 update. Load it to fix the issue.");
                return;
            }

            SolarPanelFixer.PanelState state = SolarPanelFixer.PanelState.Unknown;
            string panelStateStr             = Lib.Proto.GetString(protoPanelModule, "deployState");

            if (!Enum.IsDefined(typeof(ModuleDeployablePart.DeployState), panelStateStr))
            {
                return;
            }
            ModuleDeployablePart.DeployState panelState = (ModuleDeployablePart.DeployState)Enum.Parse(typeof(ModuleDeployablePart.DeployState), panelStateStr);

            if (panelState == ModuleDeployablePart.DeployState.BROKEN)
            {
                state = SolarPanelFixer.PanelState.Broken;
            }
            else if (!panelModule.isTracking)
            {
                state = SolarPanelFixer.PanelState.Static;
            }
            else
            {
                switch (panelState)
                {
                case ModuleDeployablePart.DeployState.EXTENDED:
                    if (!panelModule.retractable)
                    {
                        state = SolarPanelFixer.PanelState.ExtendedFixed;
                    }
                    else
                    {
                        state = SolarPanelFixer.PanelState.Extended;
                    }
                    break;

                case ModuleDeployablePart.DeployState.RETRACTED: state = SolarPanelFixer.PanelState.Retracted; break;

                case ModuleDeployablePart.DeployState.RETRACTING: state = SolarPanelFixer.PanelState.Retracting; break;

                case ModuleDeployablePart.DeployState.EXTENDING: state = SolarPanelFixer.PanelState.Extending; break;

                default: state = SolarPanelFixer.PanelState.Unknown; break;
                }
            }

            m.moduleName = "SolarPanelFixer";
            Lib.Proto.Set(m, "state", state);
            Lib.Proto.Set(m, "persistentFactor", 0.75);
            Lib.Proto.Set(m, "launchUT", Planetarium.GetUniversalTime());
            Lib.Proto.Set(m, "nominalRate", panelModule.chargeRate);
        }
        public override void OnStart(PartModule.StartState state)
        {
            try
            {
                if (state == StartState.Editor)
                {
                    return;
                }

                microwavePowerReceiver = part.FindModuleImplementing <MicrowavePowerReceiver>();
                if (microwavePowerReceiver != null)
                {
                    Fields["megaJouleSolarPowerSupply"].guiActive = false;
                    return;
                }

                if (part.Modules.Contains("WarpFixer"))
                {
                    warpfixer = part.Modules["WarpFixer"];
                    _field_kerbalism_output = warpfixer.Fields["field_output"];
                }

                part.force_activate();

                String[] resources_to_supply = { ResourceManager.FNRESOURCE_MEGAJOULES };
                this.resources_to_supply = resources_to_supply;
                base.OnStart(state);

                solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>();

                if (solarPanel == null)
                {
                    return;
                }

                resourceBuffers = new ResourceBuffers();
                if (solarPanel.resourceName == ResourceManager.FNRESOURCE_MEGAJOULES)
                {
                    resourceBuffers.AddConfiguration(new ResourceBuffers.MaxAmountConfig(ResourceManager.FNRESOURCE_MEGAJOULES, 50));
                    outputType = resourceType.megajoule;
                }
                else if (solarPanel.resourceName == ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE)
                {
                    resourceBuffers.AddConfiguration(new ResourceBuffers.MaxAmountConfig(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE, 50));
                    outputType = resourceType.electricCharge;
                }
                else
                {
                    outputType = resourceType.other;
                }

                resourceBuffers.Init(this.part);
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI] - Exception in FNSolarPanelWasteHeatModule.OnStart " + e.Message);
                throw;
            }
        }
示例#14
0
 protected override void FailPart()
 {
     //If the part can't retract will always get a sun tracking error, otherwise it will get a retraction or sun tracking at random.
     panel = part.FindModuleImplementing <ModuleDeployableSolarPanel>();
     if (panel == null)
     {
         return;
     }
     if (!panel.isTracking)
     {
         return;
     }
     if (!postMessage && !trackingSet)
     {
         if (Randomiser.instance.NextDouble() < 0.5)
         {
             trackingFailure = true;
         }
         else
         {
             trackingFailure = false;
         }
         trackingSet = true;
     }
     if (panel.isTracking && panel.retractable && panel.deployState == ModuleDeployablePart.DeployState.EXTENDED && !trackingFailure)
     {
         panel.retractable     = false;
         originallyRetractable = true;
         if (!postMessage)
         {
             failureType = "retraction error";
             if (vessel.vesselType != VesselType.Debris)
             {
                 ScreenMessages.PostScreenMessage(part.partInfo.title + " retraction mechanism jammed");
             }
             Debug.Log("[OhScrap]: " + SYP.ID + " retraction mechanism has jammed");
             postMessage = true;
         }
         if (OhScrap.highlight)
         {
             OhScrap.SetFailedHighlight();
         }
     }
     else if (panel.isTracking && panel.deployState == ModuleDeployablePart.DeployState.EXTENDED && !originallyRetractable)
     {
         panel.isTracking = false;
         if (!postMessage)
         {
             failureType = "sun tracking error";
             ScreenMessages.PostScreenMessage(part.partInfo.title + " sun tracking mechanism jammed");
             Debug.Log("[OhScrap]: " + SYP.ID + " sun tracking mechanism has jammed");
             postMessage = true;
         }
         if (OhScrap.highlight)
         {
             OhScrap.SetFailedHighlight();
         }
     }
 }
示例#15
0
 protected override void DI_Start(StartState state)
 {
     panel = this.part.Modules.OfType <ModuleDeployableSolarPanel>().First();
     if (!panel.isTracking)
     {
         this.enabled = false;                 //Disable this if it's not tracking
     }
 }
 public override void OnStart(PartModule.StartState state)
 {
     String[] resources_to_supply = {FNResourceManager.FNRESOURCE_WASTEHEAT, FNResourceManager.FNRESOURCE_MEGAJOULES};
     this.resources_to_supply = resources_to_supply;
     base.OnStart (state);
     if (state == StartState.Editor) { return; }
     solarPanel = (ModuleDeployableSolarPanel)this.part.Modules["ModuleDeployableSolarPanel"];
 }
示例#17
0
 public override void RepairPart()
 {
     panel = part.FindModuleImplementing <ModuleDeployableSolarPanel>();
     if (originallyRetractable)
     {
         panel.retractable = true;
     }
 }
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            // calculate Astronomical unit on homeworld semiMajorAxis when missing
            if (astronomicalUnit == 0)
            {
                astronomicalUnit = FlightGlobals.GetHomeBody().orbit.semiMajorAxis;
            }

            _microwavePowerReceiver = part.FindModuleImplementing <BeamedPowerReceiver>();

            _solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>();
            if (_solarPanel == null)
            {
                return;
            }

            part.force_activate();

            String[] resources_to_supply = { ResourceManager.FNRESOURCE_MEGAJOULES };
            this.resources_to_supply = resources_to_supply;
            base.OnStart(state);

            if (_solarPanel.resourceName == ResourceManager.FNRESOURCE_MEGAJOULES)
            {
                outputType = ResourceType.megajoule;
            }
            else if (_solarPanel.resourceName == ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE)
            {
                outputType = ResourceType.electricCharge;
            }
            else
            {
                outputType = ResourceType.other;
            }

            mockInputResource      = new ModuleResource();
            mockInputResource.name = _solarPanel.resourceName;
            mockInputResource.id   = _solarPanel.resourceName.GetHashCode();
            _solarPanel.resHandler.inputResources.Add(mockInputResource);

            // only manager power buffer when microwave receiver is not available
            if (outputType != ResourceType.other && _microwavePowerReceiver == null)
            {
                _resourceBuffers = new ResourceBuffers();
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_MEGAJOULES));
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE));
                _resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_MEGAJOULES, (double)(decimal)(outputType == ResourceType.electricCharge ? _solarPanel.chargeRate * 0.001f : _solarPanel.chargeRate));
                _resourceBuffers.UpdateVariable(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE, (double)(decimal)(outputType == ResourceType.electricCharge ? _solarPanel.chargeRate : _solarPanel.chargeRate * 1000));
                _resourceBuffers.Init(this.part);
            }

            stars = KopernicusHelper.Stars;
        }
示例#19
0
        // Since KSP 1.1 the info-text of solar panels is not updated correctly, so we have use this workaround-function
        // to create our own text.
        public static string GetSolarPanelInfo(ModuleDeployableSolarPanel solar_module)
        {
            var info          = solar_module.GetInfo();
            var charge_rate   = solar_module.chargeRate * solar_module.efficiencyMult;
            var charge_string = charge_rate.ToString("0.####/s");
            var prefix        = "<b>Electric Charge: </b>";

            return(Regex.Replace(info, prefix + "[0-9.]+/[A-Za-z.]+", prefix + charge_string));
        }
示例#20
0
 internal SolarPanel(Part part)
 {
     this.part = part;
     panel     = part.InternalPart.Module <ModuleDeployableSolarPanel> ();
     if (panel == null)
     {
         throw new ArgumentException("Part is not a solar panel");
     }
 }
示例#21
0
 public void SetTrackingBody(CelestialBody sun)
 {
     for (int n = 0; n < SPs.Length; n++)
     {
         ModuleDeployableSolarPanel SP = SPs[n];
         _manualTracking = true;
         SP.trackingBody = sun;
         SP.GetTrackingBodyTransforms();
     }
 }
示例#22
0
 protected override void FailPart()
 {
     panel = part.FindModuleImplementing <ModuleDeployableSolarPanel>();
     if (panel == null)
     {
         return;
     }
     if (!panel.isTracking)
     {
         return;
     }
     if (!postMessage && !trackingSet)
     {
         if (Randomiser.instance.NextDouble() < 0.5)
         {
             trackingFailure = true;
         }
         else
         {
             trackingFailure = false;
         }
         trackingSet = true;
     }
     if (panel.isTracking && panel.retractable && panel.deployState == ModuleDeployablePart.DeployState.EXTENDED && !trackingFailure)
     {
         panel.retractable     = false;
         originallyRetractable = true;
         if (!postMessage)
         {
             failureType = "retraction error";
             ScreenMessages.PostScreenMessage(part.name + " retraction mechanism jammed");
             Debug.Log("[UPFM]: " + SYP.ID + " retraction mechanism has jammed");
             postMessage = true;
         }
         if (UPFM.highlight)
         {
             UPFM.SetFailedHighlight();
         }
     }
     else if (panel.isTracking && panel.deployState == ModuleDeployablePart.DeployState.EXTENDED && !originallyRetractable)
     {
         panel.isTracking = false;
         if (!postMessage)
         {
             failureType = "sun tracking error";
             ScreenMessages.PostScreenMessage(part.name + " sun tracking mechanism jammed");
             Debug.Log("[UPFM]: " + SYP.ID + " sun tracking mechanism has jammed");
             postMessage = true;
         }
         if (UPFM.highlight)
         {
             UPFM.SetFailedHighlight();
         }
     }
 }
		public override void OnStart(PartModule.StartState state) {
			String[] resources_to_supply = {FNResourceManager.FNRESOURCE_WASTEHEAT};
			this.resources_to_supply = resources_to_supply;

			base.OnStart (state);

			if (state == StartState.Editor) { return; }
			this.part.force_activate();
            isEnabled = true;
			solarPanel = (ModuleDeployableSolarPanel)this.part.Modules["ModuleDeployableSolarPanel"];
		}
示例#24
0
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            microwavePowerReceiver = part.FindModuleImplementing <MicrowavePowerReceiver>();
            if (microwavePowerReceiver != null)
            {
                return;
            }

            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_MEGAJOULES };
            this.resources_to_supply = resources_to_supply;
            base.OnStart(state);

            previousDeltaTime = TimeWarp.fixedDeltaTime;

            solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>();

            if (solarPanel == null)
            {
                return;
            }

            if (solarPanel.resourceName == FNResourceManager.FNRESOURCE_MEGAJOULES)
            {
                outputType = resourceType.megajoule;

                megajoulePartResource = part.Resources[FNResourceManager.FNRESOURCE_MEGAJOULES];
                if (megajoulePartResource != null)
                {
                    fixedMegajouleBufferSize = megajoulePartResource.maxAmount * 50;
                }
            }
            else if (solarPanel.resourceName == FNResourceManager.STOCK_RESOURCE_ELECTRICCHARGE)
            {
                outputType = resourceType.electricCharge;

                electricChargePartResource = part.Resources[FNResourceManager.STOCK_RESOURCE_ELECTRICCHARGE];
                if (electricChargePartResource != null)
                {
                    fixedElectricChargeBufferSize = electricChargePartResource.maxAmount * 50;
                }
            }
            else
            {
                outputType = resourceType.other;
            }

            outputDefinition = PartResourceLibrary.Instance.GetDefinition(solarPanel.resourceName);
        }
 internal static void RetractAllPanels()
 {
     // iterate thru the hatch parts and open hatches
     // TODO: for realism, add a delay and a closing/opening sound
     foreach (ModSolarPanel iPanel in SMAddon.smController.SolarPanels)
     {
         ModuleDeployableSolarPanel iModule = (ModuleDeployableSolarPanel)iPanel.PanelModule;
         if (iModule.panelState == ModuleDeployableSolarPanel.panelStates.EXTENDED)
         {
             iModule.Retract();
         }
     }
 }
        private static bool GetLineOfSight(ModuleDeployableSolarPanel solarPanel, StarLight star, Vector3d trackDir)
        {
            CelestialBody old = solarPanel.trackingBody;

            solarPanel.trackingTransformLocal  = star.star.transform;
            solarPanel.trackingTransformScaled = star.star.scaledBody.transform;
            string blockingObject = "";
            var    trackingLOS    = solarPanel.CalculateTrackingLOS(trackDir, ref blockingObject);

            solarPanel.trackingTransformLocal  = old.transform;
            solarPanel.trackingTransformScaled = old.scaledBody.transform;
            return(trackingLOS);
        }
示例#27
0
        protected override void OnEnabled()
        {
            _solarPanel                     = (ModuleDeployableSolarPanel)part.GetComponent(typeof(ModuleDeployableSolarPanel));
            _originalBreakable              = _solarPanel.isBreakable;
            _originalChargeRate             = _solarPanel.chargeRate;
            _solarPanel.part.crashTolerance = 10000;
            _solarPanel.part.CanFail        = false;


            _solarPanel.isBreakable = false;

            DamageReceived += ModuleKerbalKrashEngine_DamageReceived;
            DamageRepaired += ModuleKerbalKrashEngine_DamageReceived;
        }
示例#28
0
        private void CalculateRates()
        {
            ModuleDeployableSolarPanel pm = part.Modules.GetModule <ModuleDeployableSolarPanel>();
            float timeEfficEvaluated      = pm.timeEfficCurve.Evaluate(daysElapsed);

            solarEfficiency = timeEfficEvaluated * 100;
            float currentOutputW = pm.chargeRate * timeEfficEvaluated * 1000;

            float currentPeAU = ConvertToAU(FlightGlobals.GetBodyByName(selectedBody).orbit.PeA);
            float currentApAU = ConvertToAU(FlightGlobals.GetBodyByName(selectedBody).orbit.ApA);

            solarOutputPe = DistanceScaling(currentPeAU) * currentOutputW;
            solarOutputAp = DistanceScaling(currentApAU) * currentOutputW;
        }
        public void LatePostCalculateTracking()
        {
            for (Int32 n = 0; n < SPs.Length; n++)
            {
                ModuleDeployableSolarPanel SP = SPs[n];

                if (SP?.deployState == ModuleDeployablePart.DeployState.EXTENDED)
                {
                    Vector3   normalized  = (SP.trackingTransformLocal.position - SP.panelRotationTransform.position).normalized;
                    FieldInfo trackingLOS = typeof(ModuleDeployableSolarPanel).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).FirstOrDefault(f => f.Name == "trackingLOS");
                    LatePostCalculateTracking((bool)trackingLOS.GetValue(SP), normalized, n);
                }
            }
        }
示例#30
0
        public override bool Initialize(PartModule pm)
        {
            base.Initialize(pm);
            try
            {
                panel = (ModuleDeployableSolarPanel)pm;
            }
            catch (InvalidCastException)
            {
                return(false);
            }

            return(true);
        }
示例#31
0
        public override void OnStart(PartModule.StartState state)
        {
            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT };
            this.resources_to_supply = resources_to_supply;

            base.OnStart(state);

            if (state == StartState.Editor)
            {
                return;
            }
            this.part.force_activate();
            isEnabled  = true;
            solarPanel = (ModuleDeployableSolarPanel)this.part.Modules["ModuleDeployableSolarPanel"];
        }
        public override void OnStart(StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            _mjSolarSupplyField = Fields[nameof(mjSolarSupply)];
            _mjMaxSupplyField   = Fields[nameof(mjMaxSupply)];

            if (part.Modules.Contains("SolarPanelFixer"))
            {
                _solarPanelFixer = part.Modules["SolarPanelFixer"];

                _fieldKerbalismNominalRate = _solarPanelFixer.Fields["nominalRate"];
                _fieldKerbalismPanelStatus = _solarPanelFixer.Fields["panelStatus"];
            }

            // calculate Astronomical unit on homeworld semiMajorAxis when missing
            if (astronomicalUnit <= 0)
            {
                astronomicalUnit = FlightGlobals.GetHomeBody().orbit.semiMajorAxis;
            }

            _microwavePowerReceiver = part.FindModuleImplementing <BeamedPowerReceiver>();

            _solarPanel = part.FindModuleImplementing <ModuleDeployableSolarPanel>();
            if (_solarPanel == null || _solarPanel.chargeRate <= 0)
            {
                return;
            }

            if (part.FindModuleImplementing <ModuleJettison>() == null)
            {
                Debug.Log("[KSPI]: FNSolarPanelWasteHeatModule Force Activated  " + part.name);
                part.force_activate();
            }

            // string[] resourcesToSupply = { ResourceSettings.Config.ElectricPowerInMegawatt };
            //this.resources_to_supply = resourcesToSupply;
            base.OnStart(state);

            _outputResource = _solarPanel.resHandler.outputResources.FirstOrDefault();

            resourceName = _solarPanel.resourceName;

            _stars = KopernicusHelper.Stars;
        }
 private void SetSolarPanelInfo()
 {
     moduleDeployableSolarPanel = selectedPart.GetModule<ModuleDeployableSolarPanel>();
     if (moduleDeployableSolarPanel != null)
     {
         infoItems.Add(PartInfoItem.Create("Charge Rate", moduleDeployableSolarPanel.chargeRate.ToRate()));
         if (moduleDeployableSolarPanel.isBreakable)
         {
             infoItems.Add(PartInfoItem.Create("Breakable"));
         }
         if (moduleDeployableSolarPanel.trackingBody == Sun.Instance)
         {
             infoItems.Add(PartInfoItem.Create("Sun Tracking"));
         }
     }
 }
 public override void OnStart(PartModule.StartState state)
 {
     base.OnStart(state);
     this.module = base.part.FindModuleImplementing<ModuleDeployableSolarPanel>();
 }
示例#35
0
 public void FixSP(ModuleDeployableSolarPanel sp, ConfigNode curveNode)
 {
     sp.powerCurve = new FloatCurve();
     sp.powerCurve.Load(curveNode);
 }
 private bool isDeployable(ModuleDeployableSolarPanel sa)
 {
     return sa.Events["Extend"].active || sa.Events["Retract"].active;
 }