Inheritance: NearFutureElectrical.FissionConsumer
        // Refuel from this module
        public void RefuelReactorFromContainer(FissionGenerator reactor, double amt)
        {
            double fuelAvailable       = this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(fuelName).id).amount;
            double wasteSpaceAvailable = this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(depletedName).id).maxAmount - this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(depletedName).id).amount;

            double adjAmt = amt;

            if (wasteSpaceAvailable < fuelAvailable)
            {
                // waste limited
                adjAmt = (double)Mathf.Clamp((float)amt, 0f, (float)wasteSpaceAvailable);
            }
            else
            {
                // fuel limited
                adjAmt = (double)Mathf.Clamp((float)amt, 0f, (float)fuelAvailable);
            }

            //Debug.Log("NFPP: FissionContainer has enough fuel and waste space");
            this.part.RequestResource(fuelName, adjAmt);
            this.part.RequestResource(depletedName, -adjAmt);

            reactor.part.RequestResource(fuelName, -adjAmt);
            reactor.part.RequestResource(depletedName, adjAmt);

            if (this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(fuelName).id).amount <= 0 ||
                ((this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(depletedName).id).maxAmount - this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(depletedName).id).amount) <= 0))
            {
                Expended = true;
                Debug.Log("NFPP: FissionContainer is now expended");
            }
        }
示例#2
0
        // Refuel from this module
        public void RefuelReactorFromContainer(FissionGenerator reactor, double amt)
        {
            // The reactor fuel max. Total contents of reactor should never exceed this number
            double reactorFuelMax = reactor.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(fuelName).id).maxAmount;

            // Reactor resource counts
            double reactorFuelAvailable  = reactor.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(fuelName).id).amount;
            double reactorWasteAvailable = reactor.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(fuelName).id).amount;

            // Container resource counts
            double fuelAvailable       = this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(fuelName).id).amount;
            double wasteSpaceAvailable = this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(depletedName).id).maxAmount - this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(depletedName).id).amount;

            //Transfer only the waste that will "fit"

            double wasteToTransfer = Mathf.Clamp((float)reactorWasteAvailable, 0f, (float)wasteSpaceAvailable);

            // Remove the waste
            this.part.RequestResource(depletedName, -wasteToTransfer);
            reactor.part.RequestResource(depletedName, wasteToTransfer);

            // Space for fuel  after waste removed
            double fuelSpace = reactorFuelMax - reactor.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(fuelName).id).amount
                               - reactorWasteAvailable + reactor.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(fuelName).id).amount;

            // Add that amount of fuel if possible
            double thisAmt = this.part.RequestResource(fuelName, fuelSpace);

            reactor.part.RequestResource(fuelName, -thisAmt);


            if (this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(fuelName).id).amount <= 0 ||
                ((this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(depletedName).id).maxAmount - this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(depletedName).id).amount) <= 0))
            {
                Expended = true;
                Utils.Log("FissionContainer is now expended");
            }
        }
        private void DrawReactor(FissionGenerator gen)
        {
            GUI.enabled = true;

            GUILayout.BeginVertical(gui_bg);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(Resources.gui_show, GUILayout.MaxWidth(32f), GUILayout.MinWidth(32f), GUILayout.MaxHeight(32f), GUILayout.MinHeight(32f)))
            {
                gen.ToggleHighlight();
            }

            GUILayout.Label(gen.part.partInfo.title, gui_header, GUILayout.MaxHeight(32f), GUILayout.MinHeight(32f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical(GUILayout.MinWidth(150f), GUILayout.MaxWidth(150f));

            gen.Enabled     = GUILayout.Toggle(gen.Enabled, "Reactor Enabled");
            gen.SafetyLimit = GUILayout.Toggle(gen.SafetyLimit, "Safety Limit");

            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal(GUILayout.MinWidth(250f), GUILayout.MaxWidth(250f));
            GUILayout.Label("Reactor Power", gui_text, GUILayout.MaxWidth(150f), GUILayout.MinWidth(150f));
            gen.CurrentPowerPercent = GUILayout.HorizontalSlider(gen.CurrentPowerPercent, gen.MinPowerPercent, 1.0f, GUILayout.MaxWidth(100f), GUILayout.MinWidth(100f));
            GUILayout.Label(String.Format("{0:F0}%", gen.CurrentPowerPercent * 100f), gui_text);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal(GUILayout.MinWidth(250f), GUILayout.MaxWidth(250f));
            GUILayout.Label("Thermal Power", gui_text, GUILayout.MaxWidth(150f), GUILayout.MinWidth(150f));
            GUILayout.Box("", HighLogic.Skin.horizontalSlider, GUILayout.MaxWidth(100f), GUILayout.MinWidth(100f));
            Rect last = GUILayoutUtility.GetLastRect();

            last.xMin   = last.xMin + last.width * 0.05f;
            last.width  = last.width * 0.9f * (gen.currentThermalPower / gen.ThermalPower);
            last.yMin   = last.yMin + last.height * 0.05f;
            last.height = last.height * 0.8f;
            GUI.color   = XKCDColors.Orangeish;
            GUI.DrawTexture(last, Resources.gui_progressbar);
            GUI.color = Color.white;
            GUILayout.Label(String.Format("{0:F0} kW", gen.currentThermalPower), gui_text);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal(GUILayout.MinWidth(250f), GUILayout.MaxWidth(250f));
            GUILayout.Label("Core Temperature", gui_text, GUILayout.MaxWidth(150f), GUILayout.MinWidth(150f));
            GUILayout.Box("", HighLogic.Skin.horizontalSlider, GUILayout.MaxWidth(100f), GUILayout.MinWidth(100f));
            last        = GUILayoutUtility.GetLastRect();
            last.xMin   = last.xMin + last.width * 0.05f;
            last.width  = last.width * 0.9f * (gen.CurrentCoreTemperature / gen.MeltdownCoreTemperature);
            last.yMin   = last.yMin + last.height * 0.05f;
            last.height = last.height * 0.8f;
            GUI.color   = Color.Lerp(XKCDColors.Green, XKCDColors.RedOrange, gen.CurrentCoreTemperature / gen.MeltdownCoreTemperature);
            GUI.DrawTexture(last, Resources.gui_progressbar);
            GUI.color = Color.white;
            GUILayout.Label(String.Format("{0:F0} K", gen.CurrentCoreTemperature), gui_text);


            GUILayout.EndHorizontal();

            GUILayout.EndVertical();


            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Core Lifetime (Current): " + gen.FindTimeRemaining(gen.BurnRate * gen.CoreTemperatureRatio), gui_text);
            GUILayout.Label("Core Lifetime (Full Power): " + gen.FindTimeRemaining(gen.BurnRate), gui_text);
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
 public void SetupRadiator(FissionGenerator reactor)
 {
     attachedReactor = reactor;
 }
        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();
        }