Ejemplo n.º 1
0
        public override void OnUpdate()
        {
            if (!isChargingForJumpstart && !isSwappingFuelMode && getCurrentResourceDemand(FNResourceManager.FNRESOURCE_MEGAJOULES) > getStableResourceSupply(FNResourceManager.FNRESOURCE_MEGAJOULES) && getResourceBarRatio(FNResourceManager.FNRESOURCE_MEGAJOULES) < 0.1 && IsEnabled && !fusion_alert)
            {
                ScreenMessages.PostScreenMessage("Warning: Fusion Reactor plasma heating cannot be guaranteed, reducing power requirements is recommended.", 10.0f, ScreenMessageStyle.UPPER_CENTER);
                fusion_alert = true;
            }
            else
            {
                fusion_alert = false;
            }

            if (isChargingField.guiActive)
            {
                accumulatedChargeStr = FNGenerator.getPowerFormatString(accumulatedElectricChargeInMW) + " / " + FNGenerator.getPowerFormatString(StartupPower);
            }
            else if (part.vessel.geeForce > startupMaximumGeforce)
            {
                accumulatedChargeStr = part.vessel.geeForce.ToString("0.000") + "g > " + startupMaximumGeforce + "g";
            }
            else
            {
                accumulatedChargeStr = String.Empty;
            }

            Fields["accumulatedChargeStr"].guiActive = plasma_ratio < 1;

            //powerPercentageField.guiActive = !IsEnabled && !isChargingForJumpstart;

            electricPowerMaintenance = PluginHelper.getFormattedPowerString(power_consumed) + " / " + PluginHelper.getFormattedPowerString(LaserPowerRequirements);

            // call base class
            base.OnUpdate();
        }
Ejemplo n.º 2
0
        public override void OnFixedUpdate()
        {
            base.OnFixedUpdate();

            if (!IsEnabled)
            {
                return;
            }

            if (isChargingForJumpstart)
            {
                var neededPower = LaserPowerRequirements - accumulatedElectricChargeInMW;
                if (neededPower > 0)
                {
                    accumulatedElectricChargeInMW += part.RequestResource("ElectricCharge", neededPower * 1000) / 1000;
                }

                if (accumulatedElectricChargeInMW >= LaserPowerRequirements)
                {
                    isChargingForJumpstart = false;
                }
            }

            accumulatedChargeStr = FNGenerator.getPowerFormatString(accumulatedElectricChargeInMW) + " / " + FNGenerator.getPowerFormatString(LaserPowerRequirements);

            if (!IsEnabled)
            {
                plasma_ratio   = 0;
                power_consumed = 0;
                return;
            }

            //power_consumed = part.RequestResource(FNResourceManager.FNRESOURCE_MEGAJOULES, LaserPowerRequirements * TimeWarp.fixedDeltaTime) / TimeWarp.fixedDeltaTime;
            power_consumed = consumeFNResource(LaserPowerRequirements * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES) / TimeWarp.fixedDeltaTime;

            if (TimeWarp.fixedDeltaTime <= 0.1 && accumulatedElectricChargeInMW > 0 && power_consumed < LaserPowerRequirements && (accumulatedElectricChargeInMW + power_consumed) >= LaserPowerRequirements)
            {
                var shortage = LaserPowerRequirements - power_consumed;
                if (shortage <= accumulatedElectricChargeInMW)
                {
                    ScreenMessages.PostScreenMessage("Attempting to Jump start", 5.0f, ScreenMessageStyle.LOWER_CENTER);
                    power_consumed += (float)accumulatedElectricChargeInMW;
                }
            }

            //plasma_ratio = power_consumed / LaserPowerRequirements;
            if (isSwappingFuelMode)
            {
                plasma_ratio       = 1;
                isSwappingFuelMode = false;
            }
            else if (jumpstartPowerTime > 0)
            {
                plasma_ratio = 1;
                jumpstartPowerTime--;
            }
            else
            {
                plasma_ratio   = (float)Math.Round(LaserPowerRequirements != 0.0f ? power_consumed / LaserPowerRequirements : 1.0f, 4);
                allowJumpStart = plasma_ratio == 1;
            }


            if (plasma_ratio >= 0.99)
            {
                plasma_ratio           = 1;
                isChargingForJumpstart = false;
                framesPlasmaRatioIsGood++;
                if (framesPlasmaRatioIsGood > 10)
                {
                    accumulatedElectricChargeInMW = 0;
                }
            }
            else
            {
                framesPlasmaRatioIsGood = 0;

                if (plasma_ratio < 0.001)
                {
                    plasma_ratio = 0;
                }
            }
        }
        public override void OnUpdate()
        {
            if (!CheatOptions.InfiniteElectricity && !isChargingForJumpstart && !isSwappingFuelMode && getCurrentResourceDemand(FNResourceManager.FNRESOURCE_MEGAJOULES) > getStableResourceSupply(FNResourceManager.FNRESOURCE_MEGAJOULES) && getResourceBarRatio(FNResourceManager.FNRESOURCE_MEGAJOULES) < 0.1 && IsEnabled && !fusion_alert)
            {
                ScreenMessages.PostScreenMessage("Warning: Fusion Reactor plasma heating cannot be guaranteed, reducing power requirements is recommended.", 10.0f, ScreenMessageStyle.UPPER_CENTER);
                fusion_alert = true;
            }
            else
            {
                fusion_alert = false;
            }

            if (isChargingField.guiActive)
            {
                accumulatedChargeStr = FNGenerator.getPowerFormatString(accumulatedElectricChargeInMW) + " / " + FNGenerator.getPowerFormatString(StartupPower);
            }
            else if (part.vessel.geeForce > startupMaximumGeforce)
            {
                accumulatedChargeStr = part.vessel.geeForce.ToString("0.000") + "g > " + startupMaximumGeforce + "g";
            }
            else
            {
                accumulatedChargeStr = String.Empty;
            }

            Fields["accumulatedChargeStr"].guiActive = plasma_ratio < 1;

            electricPowerMaintenance = PluginHelper.getFormattedPowerString(power_consumed) + " / " + PluginHelper.getFormattedPowerString(LaserPowerRequirements);

            if (startupAnimation != null && !initialized)
            {
                if (IsEnabled)
                {
                    //animationScalar = startupAnimation.GetScalar;
                    if (animationStarted == 0)
                    {
                        startupAnimation.ToggleAction(new KSPActionParam(KSPActionGroup.Custom01, KSPActionType.Activate));
                        animationStarted = Planetarium.GetUniversalTime();
                    }
                    else if (!startupAnimation.IsMoving())
                    {
                        startupAnimation.ToggleAction(new KSPActionParam(KSPActionGroup.Custom01, KSPActionType.Deactivate));
                        animationStarted = 0;
                        initialized      = true;
                        isDeployed       = true;
                    }
                }
                else // Not Enabled
                {
                    // continiously start
                    startupAnimation.ToggleAction(new KSPActionParam(KSPActionGroup.Custom01, KSPActionType.Activate));
                    startupAnimation.ToggleAction(new KSPActionParam(KSPActionGroup.Custom01, KSPActionType.Deactivate));
                }
            }
            else if (startupAnimation == null)
            {
                isDeployed = true;
            }

            // call base class
            base.OnUpdate();
        }