예제 #1
0
        internal double MaxPumpAmt()
        {
            double maxPumpAmount = 0;

            if (FromParts == null || ToParts == null || FromParts.Count == 0 || ToParts.Count == 0)
            {
                return(maxPumpAmount);
            }
            List <Part> .Enumerator toList   = ToParts.GetEnumerator();
            List <Part> .Enumerator fromList = FromParts.GetEnumerator();
            double fromAmount          = 0;
            double toCapacityRemaining = 0;

            while (fromList.MoveNext())
            {
                if (fromList.Current == null)
                {
                    continue;
                }
                fromAmount += fromList.Current.Resources[Resource].amount;
            }
            fromList.Dispose();
            while (toList.MoveNext())
            {
                if (toList.Current == null)
                {
                    continue;
                }
                toCapacityRemaining += PartRemainingCapacity(toList.Current, Resource);
            }
            toList.Dispose();
            maxPumpAmount = toCapacityRemaining - fromAmount;
            maxPumpAmount = maxPumpAmount > fromAmount ? fromAmount : maxPumpAmount;
            maxPumpAmount = maxPumpAmount < SMSettings.Tolerance ? 0 : maxPumpAmount;
            return(maxPumpAmount);
        }
예제 #2
0
        internal void DrainParts(double cycleAmount)
        {
            //Utilities.LogMessage("Entering:  TransferPump.DrainParts.", Utilities.LogType.Info, SMSettings.VerboseLogging);
            // Lets account for any empty/full containers
            // now split up the xfer amount evenly across the number of tanks that can send/receive resources
            if (cycleAmount < SMSettings.Tolerance)
            {
                return;
            }

            double cycleBalance = cycleAmount;

            while (cycleBalance > SMSettings.Tolerance)
            {
                // calc average of parts in list.
                double fromPartAvgAmt = cycleAmount / FromParts.Count;

                // reduce to the smallest container.
                double minAmt = fromPartAvgAmt;
                int    remainingPartsCount         = 0;
                List <Part> .Enumerator theseParts = FromParts.GetEnumerator();
                while (theseParts.MoveNext())
                {
                    if (theseParts.Current == null)
                    {
                        continue;
                    }
                    if (theseParts.Current.Resources[Resource].amount <= SMSettings.Tolerance)
                    {
                        continue;
                    }
                    if (theseParts.Current.Resources[Resource].amount >= minAmt)
                    {
                        remainingPartsCount++;
                        continue;
                    }
                    minAmt = theseParts.Current.Resources[Resource].amount;
                    remainingPartsCount++;
                }
                theseParts.Dispose();

                //Utilities.LogMessage(string.Format("Inside:  TransferPump.DrainParts:  fromPartAmt = {0}, minAmt = {1}, PartsLeft = {2}, cycleBalance = {3}", fromPartAmt, minAmt, fromPartCount, cycleBalance), Utilities.LogType.Info, SMSettings.VerboseLogging);
                // Decrement.
                if (remainingPartsCount > 0)
                {
                    List <Part> .Enumerator fromParts = FromParts.GetEnumerator();
                    while (fromParts.MoveNext())
                    {
                        if (fromParts.Current == null)
                        {
                            continue;
                        }
                        if (fromParts.Current.Resources[Resource].amount <= SMSettings.Tolerance)
                        {
                            continue;
                        }
                        Part part = fromParts.Current;
                        part.Resources[Resource].amount -= minAmt;
                        cycleBalance -= minAmt;
                        AmtPumped    += minAmt;

                        // Ensure part is empty and does not contain less than 0.
                        if (part.Resources[Resource].amount <= SMSettings.Tolerance)
                        {
                            part.Resources[Resource].amount = 0;
                        }
                    }
                    fromParts.Dispose();
                }
                if (remainingPartsCount == 0 && cycleBalance > SMSettings.Tolerance)
                {
                    cycleBalance = 0;
                }
                //Utilities.LogMessage(string.Format("Inside:  TransferPump.DrainParts:  fromPartAmt = {0}, minAmt = {1}, PartsLeft = {2}, cycleBalance = {3}", fromPartAmt, minAmt, fromPartCount, cycleBalance), Utilities.LogType.Info, SMSettings.VerboseLogging);
            }
        }
예제 #3
0
        internal void DrainParts(double cycleAmount)
        {
            //Utilities.LogMessage("Entering:  TransferPump.DrainParts.", Utilities.LogType.Info, SMSettings.VerboseLogging);
            // Lets account for any empty/full containers
            // now split up the xfer amount evenly across the number of tanks that can send/receive resources
            if (cycleAmount < SMSettings.Tolerance)
            {
                return;
            }

            double cycleBalance = cycleAmount;

            while (cycleBalance > SMSettings.Tolerance)
            {
                // find least but positive amount of resource in single tank!
                double minAmt = Double.MaxValue;
                List <Part> .Enumerator theseParts    = FromParts.GetEnumerator();
                List <Part>             nonEmptyParts = new List <Part>();
                while (theseParts.MoveNext())
                {
                    Part part = theseParts.Current;
                    if (part == null)
                    {
                        continue;
                    }
                    if (part.Resources[Resource].amount <= SMSettings.Tolerance)
                    {
                        continue;
                    }
                    if (part.Resources[Resource].amount < minAmt)
                    {
                        minAmt = part.Resources[Resource].amount;
                    }
                    nonEmptyParts.Add(theseParts.Current);
                }
                theseParts.Dispose();

                //Utilities.LogMessage(string.Format("Inside:  TransferPump.DrainParts:  fromPartAmt = {0}, minAmt = {1}, PartsLeft = {2}, cycleBalance = {3}", fromPartAmt, minAmt, fromPartCount, cycleBalance), Utilities.LogType.Info, SMSettings.VerboseLogging);
                // Decrement.
                if (nonEmptyParts.Count > 0)
                {
                    double toTransfer = Math.Min(cycleBalance / nonEmptyParts.Count, minAmt);
                    List <Part> .Enumerator fromParts = nonEmptyParts.GetEnumerator();
                    while (fromParts.MoveNext())
                    {
                        Part part = fromParts.Current;
                        part.Resources[Resource].amount -= toTransfer;
                        cycleBalance -= toTransfer;
                        AmtPumped    += toTransfer;

                        // Ensure part is empty and does not contain less than 0.
                        if (part.Resources[Resource].amount <= SMSettings.Tolerance)
                        {
                            part.Resources[Resource].amount = 0;
                        }
                    }
                    fromParts.Dispose();
                }
                if (nonEmptyParts.Count == 0 && cycleBalance > SMSettings.Tolerance)
                {
                    cycleBalance = 0;
                }
                //Utilities.LogMessage(string.Format("Inside:  TransferPump.DrainParts:  fromPartAmt = {0}, minAmt = {1}, PartsLeft = {2}, cycleBalance = {3}", fromPartAmt, minAmt, fromPartCount, cycleBalance), Utilities.LogType.Info, SMSettings.VerboseLogging);
            }
        }