Inheritance: ModuleResourceConverter
Exemple #1
0
        private void AttemptTransfer()
        {
            Part targetPart = GetPartClicked();

            // No part was clicked
            if (targetPart == null)
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_NFElectrical_ModuleRadioactiveStorageContainer_Message_AbortNoPartSelected"), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                EndTransfer();
            }
            else
            {
                // part cannot be on another vessel
                if (!VesselConnected(targetPart))
                {
                    ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_NFElectrical_ModuleRadioactiveStorageContainer_Message_AbortUnconnected"), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                    EndTransfer();
                    return;
                }

                RadioactiveStorageContainer container = targetPart.GetComponent <RadioactiveStorageContainer>();
                if (container == null)
                {
                    ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_NFElectrical_ModuleRadioactiveStorageContainer_Message_AbortNoRadStorage"), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                    EndTransfer();
                }
                else
                {
                    ModuleResourceConverter converter = container.GetComponent <ModuleResourceConverter>();
                    FissionReactor          reactor   = container.GetComponent <FissionReactor>();

                    if (core != null && core.CoreTemperature > container.MaxTempForTransfer)
                    {
                        ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_NFElectrical_ModuleRadioactiveStorageContainer_Message_AbortTooHot", container.MaxTempForTransfer.ToString("F0")), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                    }
                    else if (converter != null && converter.ModuleIsActive())
                    {
                        ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_NFElectrical_ModuleRadioactiveStorageContainer_Message_AbortToRunningConverter"), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                    }
                    else if (reactor != null && reactor.ModuleIsActive())
                    {
                        ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_NFElectrical_ModuleRadioactiveStorageContainer_Message_AbortToRunningReactor"), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                    }
                    else
                    {
                        // get available space in the target container
                        double availableSpace    = container.GetResourceAmount(curTransferType, true) - container.GetResourceAmount(curTransferType);
                        double availableResource = this.GetResourceAmount(curTransferType);
                        // transfer as much as possible
                        double amount = this.part.RequestResource(curTransferType, availableSpace);
                        container.part.RequestResource(curTransferType, -amount);
                        ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_NFElectrical_ModuleRadioactiveStorageContainer_Message_Success", amount.ToString("F1"), curTransferType.ToString()), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                        transferring    = false;
                        curTransferType = "";
                    }
                }
            }
        }
        public void FindReactors()
        {
            //Debug.Log("NFE: Capacitor Manager: Finding Capcitors");
            List <FissionReactor> unsortedReactorList = new List <FissionReactor>();
            // Get all parts
            List <Part> allParts = vessel.parts;

            for (int i = 0; i < vessel.parts.Count; i++)
            {
                FissionReactor toAdd = allParts[i].GetComponent <FissionReactor>();
                if (toAdd != null)
                {
                    unsortedReactorList.Add(toAdd);
                }
            }

            //sort
            reactors = unsortedReactorList.OrderByDescending(x => x.HeatGeneration).ToList();
            reactors = unsortedReactorList;
        }
Exemple #3
0
        public bool PartCanTransferResource(string nm)
        {
            // Some modules need to be off.
            ModuleResourceConverter converter = GetComponent <ModuleResourceConverter>();
            FissionReactor          reactor   = GetComponent <FissionReactor>();

            if (converter != null && converter.ModuleIsActive())
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_NFElectrical_ModuleRadioactiveStorageContainer_Message_AbortFromRunningConverter"), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                return(false);
            }
            if (reactor != null && reactor.ModuleIsActive())
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_NFElectrical_ModuleRadioactiveStorageContainer_Message_AbortFromRunningReactor"), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                return(false);
            }

            // Fail if the part is too hot
            if (core != null && core.CoreTemperature > MaxTempForTransfer)
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_NFElectrical_ModuleRadioactiveStorageContainer_Message_AbortTooHot", MaxTempForTransfer.ToString("F0")), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                return(false);
            }
            // Fail if that part can't contain this resource
            if ((GetResourceAmount(nm, true) <= 0d))
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_NFElectrical_ModuleRadioactiveStorageContainer_Message_AbortNoResource", nm), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                return(false);
            }
            // Fail if this part has no resource
            if (GetResourceAmount(nm) <= 0d)
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_NFElectrical_ModuleRadioactiveStorageContainer_Message_AbortNoResource", nm), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                return(false);
            }

            return(true);
        }
Exemple #4
0
        public bool PartCanTransferResource(string nm)
        {
            // Some modules need to be off.
            ModuleResourceConverter converter = GetComponent <ModuleResourceConverter>();
            FissionReactor          reactor   = GetComponent <FissionReactor>();

            if (converter != null && converter.ModuleIsActive())
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage("Cannot transfer from a running converter!", 5.0f, ScreenMessageStyle.UPPER_CENTER));
                return(false);
            }
            if (reactor != null && reactor.ModuleIsActive())
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage("Cannot transfer from a running reactor! Seriously a bad idea!", 5.0f, ScreenMessageStyle.UPPER_CENTER));
                return(false);
            }

            // Fail if the part is too hot
            if (part.temperature > MaxTempForTransfer)
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage(String.Format("This part must be below {0:F0} K to transfer!", MaxTempForTransfer), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                return(false);
            }
            // Fail if that part can't contain this resource
            if ((GetResourceAmount(nm, true) <= 0d))
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage("This part has no " + nm + " to transfer!", 5.0f, ScreenMessageStyle.UPPER_CENTER));
                return(false);
            }
            // Fail if this part has no resource
            if (GetResourceAmount(nm) <= 0d)
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage("This part has no " + nm + " to transfer!", 5.0f, ScreenMessageStyle.UPPER_CENTER));
                return(false);
            }

            return(true);
        }
 private void SetupReactor()
 {
     reactor      = this.GetComponent <FissionReactor>();
     flowRadiator = this.GetComponent <FissionFlowRadiator>();
     core         = this.GetComponent <ModuleCoreHeat>();
 }
 private void SetupReactor()
 {
     reactor = this.GetComponent<FissionReactor>();
     flowRadiator = this.GetComponent<FissionFlowRadiator>();
     core = this.GetComponent<ModuleCoreHeat>();
 }
        private void DrawReactor(FissionReactor reactor)
        {
            FissionGenerator gen = reactor.GetComponent<FissionGenerator>();

            GUILayout.BeginHorizontal(gui_bg);
            GUILayout.BeginVertical();
            // Capacitor Name Field
            GUILayout.Label(reactor.part.partInfo.title, gui_header, GUILayout.MaxHeight(32f), GUILayout.MinHeight(32f), GUILayout.MaxWidth(150f), GUILayout.MinWidth(150f));
            GUILayout.Space(10f);
            GUILayout.BeginHorizontal();
            bool y = reactor.ModuleIsActive();
            bool x = GUILayout.Toggle(reactor.ModuleIsActive(),"Active",gui_toggle);
            if (x != y)
            {
                reactor.ToggleResourceConverterAction( new KSPActionParam(0,KSPActionType.Activate) );
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            // Changeables

            GUILayout.BeginVertical();

            //GUILayout.Label("Core Temperature", gui_text, GUILayout.MaxWidth(150f), GUILayout.MinWidth(150f));
            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical();
            GUILayout.Label("Reactor Status", gui_header2, GUILayout.MaxWidth(110f), GUILayout.MinWidth(110f));
            if (reactor.FollowThrottle)
            {
                GUILayout.Label(String.Format("Actual: {0:F0}%", reactor.ActualPowerPercent), gui_text);
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            reactor.CurrentPowerPercent = GUILayout.HorizontalSlider(reactor.CurrentPowerPercent, 0f, 100f, GUILayout.MinWidth(150f));
            GUILayout.Label(String.Format("{0:F0}%", reactor.CurrentPowerPercent), gui_text);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(String.Format("Heat Output: {0:F1} kW", reactor.AvailablePower), gui_text, GUILayout.MaxWidth(120f), GUILayout.MinWidth(120f));
            if (gen != null)
            {
                GUILayout.Label(String.Format("Power Output: {0:F1} Ec/s", gen.CurrentGeneration), gui_text, GUILayout.MaxWidth(140f), GUILayout.MinWidth(140f));
            }
            else
            {
                GUILayout.Label(String.Format("Power Output: No Generator"), gui_text, GUILayout.MaxWidth(100f), GUILayout.MinWidth(100f));
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Core Status", gui_header2, GUILayout.MaxWidth(110f), GUILayout.MinWidth(110f));
            float coreTemp = (float)reactor.GetCoreTemperature();
            float meltdownTemp = reactor.MaximumTemperature;
            float nominalTemp = reactor.NominalTemperature;
            float criticalTemp = reactor.CriticalTemperature;

            float tempAreaWidth = 250f;
            float tempBarWidth = 210f;
            Rect tempArea = GUILayoutUtility.GetRect(tempAreaWidth, 60f);
            Rect barArea = new Rect(20f, 20f, tempBarWidth, 40f);

            float nominalXLoc = nominalTemp / meltdownTemp * tempBarWidth;
            float criticalXLoc = criticalTemp / meltdownTemp * tempBarWidth;
            float tempBarFGSize = tempBarWidth*(coreTemp/meltdownTemp);

            Color barColor = new Color();
            if (coreTemp <= nominalTemp)
                barColor = Color.green;
            else if (coreTemp <= criticalTemp)
                barColor = Color.Lerp(Color.green, new Color(1.0f, 102f / 255f, 0f), (coreTemp - nominalTemp) / (criticalTemp - nominalTemp));
            else
                barColor = Color.Lerp(new Color(1.0f, 102f / 255f, 0f), Color.red, (coreTemp - criticalTemp) / (meltdownTemp - criticalTemp));

                GUI.BeginGroup(tempArea);
                GUI.Box(new Rect(0f,10f,tempBarWidth,10f),"", progressBarBG);
                GUI.color = barColor;
                GUI.Box(new Rect(0f, 11f, tempBarFGSize, 7f), "", progressBarFG);
                GUI.color = Color.white;
                GUI.Label(new Rect(tempBarWidth+7f, 8f, 40f, 20f), String.Format("{0:F0} K", coreTemp), gui_text);

                GUI.Label(new Rect(0f + nominalXLoc - 13f, 16f, 22f, 25f), notchTexture);
                GUI.Label(new Rect(0f + criticalXLoc - 13f, 16f, 22f, 25f), notchTexture);

                GUI.Label(new Rect(nominalXLoc - 46f, 25f, 40f, 20f), String.Format("{0:F0} K", nominalTemp), gui_text);
                GUI.Label(new Rect(9f + criticalXLoc, 25f, 40f, 20f), String.Format("{0:F0} K", criticalTemp), gui_text);

               // GUI.Label(new Rect(20f+tempBarWidth, 30f, 40f, 20f), String.Format("{0:F0} K", meltdownTemp), gui_text);
             GUI.EndGroup();
             GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Safety Status", gui_header2, GUILayout.MaxWidth(110f), GUILayout.MinWidth(110f));
            reactor.CurrentSafetyOverride = GUILayout.HorizontalSlider(reactor.CurrentSafetyOverride, 700f, reactor.MaximumTemperature, GUILayout.MinWidth(150f));
            GUILayout.Label(String.Format("{0:F0} K", reactor.CurrentSafetyOverride), gui_text);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
                GUILayout.Label("Fuel Status", gui_header2, GUILayout.MaxWidth(110f), GUILayout.MinWidth(110f));
                GUILayout.Label(reactor.FuelStatus, gui_text);
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            GUILayout.EndHorizontal();
        }
Exemple #8
0
        private void AttemptTransfer()
        {
            Part targetPart = GetPartClicked();

            // No part was clicked
            if (targetPart == null)
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage("No part selected, exiting transfer mode...", 5.0f, ScreenMessageStyle.UPPER_CENTER));
                EndTransfer();
            }
            else
            {
                // part cannot be on another vessel
                if (!VesselConnected(targetPart))
                {
                    ScreenMessages.PostScreenMessage(new ScreenMessage("Cannot transfer to an unconnected vessel, exiting transfer mode...", 5.0f, ScreenMessageStyle.UPPER_CENTER));
                    EndTransfer();
                    return;
                }

                RadioactiveStorageContainer container = targetPart.GetComponent <RadioactiveStorageContainer>();
                if (container == null)
                {
                    ScreenMessages.PostScreenMessage(new ScreenMessage("Selected part can't handle radioactive storage, exiting transfer mode...", 5.0f, ScreenMessageStyle.UPPER_CENTER));
                    EndTransfer();
                }
                else
                {
                    Debug.Log("A");
                    ModuleResourceConverter converter = container.GetComponent <ModuleResourceConverter>();
                    FissionReactor          reactor   = container.GetComponent <FissionReactor>();
                    Debug.Log("B");
                    if (part.temperature > container.MaxTempForTransfer)
                    {
                        ScreenMessages.PostScreenMessage(new ScreenMessage(String.Format("Selected part must be below {0:F0} K to transfer!", container.MaxTempForTransfer), 5.0f, ScreenMessageStyle.UPPER_CENTER));
                    }

                    else if (converter != null && converter.ModuleIsActive())
                    {
                        ScreenMessages.PostScreenMessage(new ScreenMessage("Cannot transfer into a running converter!", 5.0f, ScreenMessageStyle.UPPER_CENTER));
                    }
                    else if (reactor != null && reactor.ModuleIsActive())
                    {
                        ScreenMessages.PostScreenMessage(new ScreenMessage("Cannot transfer into a running reactor! Seriously a bad idea!", 5.0f, ScreenMessageStyle.UPPER_CENTER));
                    }
                    else
                    {
                        Debug.Log("s");
                        // get available space in the target container
                        double availableSpace    = container.GetResourceAmount(curTransferType, true) - container.GetResourceAmount(curTransferType);
                        double availableResource = this.GetResourceAmount(curTransferType);
                        Debug.Log("1");
                        // transfer as much as possible
                        double amount = this.part.RequestResource(curTransferType, availableSpace);
                        container.part.RequestResource(curTransferType, -amount);
                        Debug.Log("2");
                        ScreenMessages.PostScreenMessage(new ScreenMessage(String.Format("Transferred {0:F0} ", amount) + curTransferType + " to container!", 5.0f, ScreenMessageStyle.UPPER_CENTER));
                    }
                }
            }
        }
        private void DrawReactor(FissionReactor reactor)
        {
            FissionGenerator gen = reactor.GetComponent <FissionGenerator>();

            GUILayout.BeginHorizontal(gui_bg);
            GUILayout.BeginVertical();
            // Capacitor Name Field
            GUILayout.Label(reactor.part.partInfo.title, gui_header, GUILayout.MaxHeight(32f), GUILayout.MinHeight(32f), GUILayout.MaxWidth(150f), GUILayout.MinWidth(150f));
            GUILayout.Space(10f);
            GUILayout.BeginHorizontal();
            bool y = reactor.ModuleIsActive();
            bool x = GUILayout.Toggle(reactor.ModuleIsActive(), "Active", gui_toggle);

            if (x != y)
            {
                reactor.ToggleResourceConverterAction(new KSPActionParam(0, KSPActionType.Activate));
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            // Changeables

            GUILayout.BeginVertical();

            //GUILayout.Label("Core Temperature", gui_text, GUILayout.MaxWidth(150f), GUILayout.MinWidth(150f));
            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical();
            GUILayout.Label("Reactor Status", gui_header2, GUILayout.MaxWidth(110f), GUILayout.MinWidth(110f));
            if (reactor.FollowThrottle)
            {
                GUILayout.Label(String.Format("Actual: {0:F0}%", reactor.ActualPowerPercent), gui_text);
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            reactor.CurrentPowerPercent = GUILayout.HorizontalSlider(reactor.CurrentPowerPercent, 0f, 100f, GUILayout.MinWidth(150f));
            GUILayout.Label(String.Format("{0:F0}%", reactor.CurrentPowerPercent), gui_text);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(String.Format("Heat Output: {0:F1} kW", reactor.AvailablePower), gui_text, GUILayout.MaxWidth(120f), GUILayout.MinWidth(120f));
            if (gen != null)
            {
                GUILayout.Label(String.Format("Power Output: {0:F1} Ec/s", gen.CurrentGeneration), gui_text, GUILayout.MaxWidth(140f), GUILayout.MinWidth(140f));
            }
            else
            {
                GUILayout.Label(String.Format("Power Output: No Generator"), gui_text, GUILayout.MaxWidth(100f), GUILayout.MinWidth(100f));
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Core Status", gui_header2, GUILayout.MaxWidth(110f), GUILayout.MinWidth(110f));
            float coreTemp     = (float)reactor.GetCoreTemperature();
            float meltdownTemp = reactor.MaximumTemperature;
            float nominalTemp  = reactor.NominalTemperature;
            float criticalTemp = reactor.CriticalTemperature;

            float tempAreaWidth = 250f;
            float tempBarWidth  = 210f;
            Rect  tempArea      = GUILayoutUtility.GetRect(tempAreaWidth, 60f);
            Rect  barArea       = new Rect(20f, 20f, tempBarWidth, 40f);

            float nominalXLoc   = nominalTemp / meltdownTemp * tempBarWidth;
            float criticalXLoc  = criticalTemp / meltdownTemp * tempBarWidth;
            float tempBarFGSize = tempBarWidth * (coreTemp / meltdownTemp);

            Color barColor = new Color();

            if (coreTemp <= nominalTemp)
            {
                barColor = Color.green;
            }
            else if (coreTemp <= criticalTemp)
            {
                barColor = Color.Lerp(Color.green, new Color(1.0f, 102f / 255f, 0f), (coreTemp - nominalTemp) / (criticalTemp - nominalTemp));
            }
            else
            {
                barColor = Color.Lerp(new Color(1.0f, 102f / 255f, 0f), Color.red, (coreTemp - criticalTemp) / (meltdownTemp - criticalTemp));
            }

            GUI.BeginGroup(tempArea);
            GUI.Box(new Rect(0f, 10f, tempBarWidth, 10f), "", progressBarBG);
            GUI.color = barColor;
            GUI.Box(new Rect(0f, 11f, tempBarFGSize, 7f), "", progressBarFG);
            GUI.color = Color.white;
            GUI.Label(new Rect(tempBarWidth + 7f, 8f, 40f, 20f), String.Format("{0:F0} K", coreTemp), gui_text);

            GUI.Label(new Rect(0f + nominalXLoc - 13f, 16f, 22f, 25f), notchTexture);
            GUI.Label(new Rect(0f + criticalXLoc - 13f, 16f, 22f, 25f), notchTexture);

            GUI.Label(new Rect(nominalXLoc - 46f, 25f, 40f, 20f), String.Format("{0:F0} K", nominalTemp), gui_text);
            GUI.Label(new Rect(9f + criticalXLoc, 25f, 40f, 20f), String.Format("{0:F0} K", criticalTemp), gui_text);

            // GUI.Label(new Rect(20f+tempBarWidth, 30f, 40f, 20f), String.Format("{0:F0} K", meltdownTemp), gui_text);
            GUI.EndGroup();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Safety Status", gui_header2, GUILayout.MaxWidth(110f), GUILayout.MinWidth(110f));
            reactor.CurrentSafetyOverride = GUILayout.HorizontalSlider(reactor.CurrentSafetyOverride, 700f, reactor.MaximumTemperature, GUILayout.MinWidth(150f));
            GUILayout.Label(String.Format("{0:F0} K", reactor.CurrentSafetyOverride), gui_text);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Fuel Status", gui_header2, GUILayout.MaxWidth(110f), GUILayout.MinWidth(110f));
            GUILayout.Label(reactor.FuelStatus, gui_text);
            GUILayout.EndHorizontal();


            GUILayout.EndVertical();

            GUILayout.EndHorizontal();
        }