コード例 #1
0
        public double consumeFNResourcePerSecondBuffered(double requestedPowerPerSecond, String resourcename, double limitBarRatio = 0.1, ResourceManager manager = null)
        {
            if (requestedPowerPerSecond.IsInfinityOrNaN() || String.IsNullOrEmpty(resourcename))
            {
                Debug.Log("[KSPI]: consumeFNResourcePerSecondBuffered was called with illegal value");
                return(0);
            }

            requestedPowerPerSecond = Math.Max(requestedPowerPerSecond, 0);

            if (manager == null)
            {
                manager = getManagerForVessel(resourcename);
            }
            if (manager == null)
            {
                return(0);
            }

            double availablePower;

            if (!fnresource_supplied.TryGetValue(resourcename, out availablePower))
            {
                fnresource_supplied[resourcename] = 0;
            }

            var power_taken_per_second = Math.Max(Math.Min(requestedPowerPerSecond, availablePower), 0);

            fnresource_supplied[resourcename] -= power_taken_per_second;

            // supplement with buffer power if needed and available
            var powerShortage = requestedPowerPerSecond - availablePower;

            if (powerShortage > 0)
            {
                var currentCapacity    = manager.getTotalResourceCapacity();
                var currentAmount      = currentCapacity * manager.ResourceBarRatioBegin;
                var fixedPowerShortage = powerShortage * timeWarpFixedDeltaTime;

                if (currentAmount - fixedPowerShortage > currentCapacity * limitBarRatio)
                {
                    power_taken_per_second += (part.RequestResource(resourcename, fixedPowerShortage) / timeWarpFixedDeltaTime);
                }
            }

            manager.powerDrawPerSecond(this, requestedPowerPerSecond, power_taken_per_second);

            return(power_taken_per_second);
        }
コード例 #2
0
        public double getTotalResourceCapacity(String resourcename)
        {
            if (String.IsNullOrEmpty(resourcename))
            {
                Debug.LogError("[KSPI]: getTotalResourceCapacity resourcename is null or empty");
                return(0);
            }

            ResourceManager manager = getManagerForVessel(resourcename);

            if (manager == null)
            {
                return(0);
            }

            return(manager.getTotalResourceCapacity());
        }
コード例 #3
0
        public double getTotalResourceCapacity(String resourcename)
        {
            if (String.IsNullOrEmpty(resourcename))
            {
                Debug.Log("[KSPI] - getTotalResourceCapacity illegal values.");
                return(0);
            }

            ResourceManager manager = getManagerForVessel(resourcename);

            if (manager == null)
            {
                return(0);
            }

            return(manager.getTotalResourceCapacity());
        }