public void FixedUpdate()
        {
            currentPowerReq = 0;

            if (!HighLogic.LoadedSceneIsFlight || !refinery_is_enabled || currentActivity == null)
            {
                lastActivityName = string.Empty;
                return;
            }

            currentPowerReq = powerReqMult * currentActivity.PowerRequirements * baseProduction;

            var requestedPowerRatio = powerPercentage / 100;

            var powerRequest = currentPowerReq * requestedPowerRatio;

            consumedPowerMW = CheatOptions.InfiniteElectricity
                ? powerRequest
                : powerSupply.ConsumeMegajoulesPerSecond(powerRequest);

            var shortage = Math.Max(powerRequest - consumedPowerMW, 0);

            var fixedDeltaTime = (double)(decimal)Math.Round(TimeWarp.fixedDeltaTime, 7);

            var receivedElectricCharge = part.RequestResource(ResourceSettings.Config.ElectricPowerInKilowatt, shortage *
                                                              GameConstants.ecPerMJ * fixedDeltaTime) / fixedDeltaTime;

            consumedPowerMW += receivedElectricCharge / GameConstants.ecPerMJ;

            var receivedPowerRatio = currentPowerReq > 0 ? consumedPowerMW / currentPowerReq : 0;

            utilisationPercentage = receivedPowerRatio * 100;

            var productionModifier = productionMult * baseProduction;

            currentActivity.UpdateFrame(requestedPowerRatio * receivedPowerRatio * productionModifier, requestedPowerRatio * receivedPowerRatio, requestedPowerRatio * productionModifier, _overflowAllowed, fixedDeltaTime);

            lastPowerRatio       = receivedPowerRatio;           // save the current power ratio in case the vessel is unloaded
            lastOverflowSettings = _overflowAllowed;             // save the current overflow settings in case the vessel is unloaded
            lastActivityName     = currentActivity.ActivityName; // take the string with the name of the current activity, store it in persistent string
            lastClassName        = currentActivity.GetType().Name;
            lastActiveTime       = Planetarium.GetUniversalTime();
        }
Exemplo n.º 2
0
        public void FixedUpdate()
        {
            currentPowerReq = 0;

            if (!HighLogic.LoadedSceneIsFlight || !refinery_is_enabled || _current_activity == null)
            {
                lastActivityName = string.Empty;
                return;
            }

            currentPowerReq = powerReqMult * _current_activity.PowerRequirements * baseProduction;

            var powerRequest = currentPowerReq * (powerPercentage / 100);

            consumedPowerMW = CheatOptions.InfiniteElectricity
                ? powerRequest
                : powerSupply.ConsumeMegajoulesPerSecond(powerRequest);


            var shortage = Math.Max(currentPowerReq - consumedPowerMW, 0);

            var fixedDeltaTime = (double)(decimal)TimeWarp.fixedDeltaTime;

            var recievedElectricCharge = part.RequestResource("ElectricCharge", shortage * 1000 * fixedDeltaTime) / fixedDeltaTime;

            consumedPowerMW += recievedElectricCharge / 1000;

            var power_ratio = currentPowerReq > 0 ? consumedPowerMW / currentPowerReq : 0;

            utilisationPercentage = power_ratio * 100;

            var productionModifier = productionMult * baseProduction;

            _current_activity.UpdateFrame(power_ratio * productionModifier, power_ratio, productionModifier, overflowAllowed, fixedDeltaTime);

            lastPowerRatio       = power_ratio;                    // save the current power ratio in case the vessel is unloaded
            lastOverflowSettings = overflowAllowed;                // save the current overflow settings in case the vessel is unloaded
            lastActivityName     = _current_activity.ActivityName; // take the string with the name of the current activity, store it in persistent string
            lastActiveTime       = Planetarium.GetUniversalTime();
        }