Example #1
0
        private void UpdateGridPower()
        {
            GridAvailablePower    = 0;
            GridMaxPower          = 0;
            GridCurrentPower      = 0;
            _batteryMaxPower      = 0;
            _batteryCurrentOutput = 0;
            _batteryCurrentInput  = 0;
            lock (SubLock)
            {
                if (MyResourceDist != null && FuncTask.IsComplete && !_functionalEvent)
                {
                    var noObjects = MyResourceDist.SourcesEnabled == MyMultipleEnabledEnum.NoObjects;
                    if (noObjects)
                    {
                        if (Session.Enforced.Debug >= 2)
                        {
                            Log.Line($"NoObjects: {MyGrid?.DebugName} - Max:{MyResourceDist?.MaxAvailableResourceByType(GId)} - Status:{MyResourceDist?.SourcesEnabled} - Sources:{_powerSources.Count}");
                        }
                        FallBackPowerCalc();
                        FunctionalChanged(true, true);
                    }
                    else
                    {
                        GridMaxPower     = MyResourceDist.MaxAvailableResourceByType(GId);
                        GridCurrentPower = MyResourceDist.TotalRequiredInputByType(GId);
                        if (!DsSet.Settings.UseBatteries && _batteryBlocks.Count != 0)
                        {
                            CalculateBatteryInput();
                        }
                    }
                }
                else
                {
                    FallBackPowerCalc();
                }
            }
            GridAvailablePower = GridMaxPower - GridCurrentPower;

            if (!DsSet.Settings.UseBatteries)
            {
                GridCurrentPower   += _batteryCurrentInput;
                GridAvailablePower -= _batteryCurrentInput;
            }

            var powerScale    = Session.Instance.GameLoaded ? DsSet.Settings.PowerScale : 0;
            var reserveScaler = ReserveScaler[powerScale];
            var userPowerCap  = DsSet.Settings.PowerWatts * reserveScaler;
            var shieldMax     = GridMaxPower > userPowerCap && reserveScaler > 0 ? userPowerCap : GridMaxPower;

            ShieldMaxPower       = shieldMax;
            ShieldAvailablePower = ShieldMaxPower - GridCurrentPower;

            _shieldPowered = ShieldMaxPower > 0;
        }
Example #2
0
        private void UpdateGridPower()
        {
            GridAvailablePower    = 0;
            GridMaxPower          = 0;
            GridCurrentPower      = 0;
            _batteryMaxPower      = 0;
            _batteryCurrentOutput = 0;
            _batteryCurrentInput  = 0;

            if (MyResourceDist == null || MyResourceDist.SourcesEnabled == MyMultipleEnabledEnum.NoObjects || _checkResourceDist)
            {
                ResetDistributor();
            }

            GridMaxPower     = MyResourceDist.MaxAvailableResourceByType(GId, MyGrid);
            GridCurrentPower = MyResourceDist.TotalRequiredInputByType(GId, MyGrid);
            if (!DsSet.Settings.UseBatteries)
            {
                CalculateBatteryInput();
            }

            GridAvailablePower = GridMaxPower - GridCurrentPower;

            if (!DsSet.Settings.UseBatteries)
            {
                GridCurrentPower   += _batteryCurrentInput;
                GridAvailablePower -= _batteryCurrentInput;
            }

            var powerScale    = Session.Instance.GameLoaded ? DsSet.Settings.PowerScale : 0;
            var reserveScaler = ReserveScaler[powerScale];
            var userPowerCap  = DsSet.Settings.PowerWatts * reserveScaler;
            var shieldMax     = GridMaxPower > userPowerCap && reserveScaler > 0 ? userPowerCap : GridMaxPower;

            if (shieldMax >= ShieldMaxPower || shieldMax <= 0 || _maxPowerTick++ > 100)
            {
                _maxPowerTick  = 0;
                ShieldMaxPower = shieldMax;
            }

            ShieldAvailablePower = shieldMax - GridCurrentPower;

            _shieldPowered = ShieldMaxPower > 0;
        }