Ejemplo n.º 1
0
        public void UpdateStockpileEstimates(Refinery refinery, Blueprint blueprint, double workTowardsDeadline)
        {
            for (var i = 0; i < blueprint.Outputs.Length; i++)
            {
                var output = blueprint.Outputs[i];

                IngotStockpile stockpile;
                if (!stockpilesByIngotType.TryGetValue(output.ItemType, out stockpile))
                {
                    continue;
                }

                stockpile.AssignedWork(workTowardsDeadline, refinery.GetActualIngotProductionRate(output, blueprint.Duration));
            }
            if (preferredIndex.HasValue)
            {
                var s = candidateStockpiles[preferredIndex.Value];
                if (s.IsSatisfied)
                {
                    candidateStockpiles.RemoveAtFast(preferredIndex.Value);
                    preferredIndex = null;
                }
                else if (s.QuotaFraction > sortThreshold)
                {
                    preferredIndex = null;
                }
            }
        }
Ejemplo n.º 2
0
            private bool TrySelectRefinery(Refinery refinery)
            {
                var secondsToClear = refinery.GetSecondsToClear(worklist.oreTypes);

                RequiredWorkSeconds  = Constants.TARGET_INTERVAL_SECONDS - secondsToClear;
                PreferredWorkSeconds = RequiredWorkSeconds + Constants.OVERLAP_INTERVAL_SECONDS;
                return(PreferredWorkSeconds > 0);
            }
Ejemplo n.º 3
0
        public Refinery TryResolveRefinery(IMyRefinery block, double refinerySpeedFactor)
        {
            RefineryType type;

            if (refineryTypesByBlockDefinitionString.TryGetValue(block.BlockDefinition.ToString(), out type))
            {
                return(Refinery.Get(block, type, refinerySpeedFactor));
            }
            return(null);
        }
Ejemplo n.º 4
0
 private void ScanRefineriesIfNecessary(IMyGridTerminalSystem gts)
 {
     if (rescanRefineries)
     {
         Debug.Write(Debug.Level.Debug, "Scanning for refineries...");
         refineries.Clear();
         Refinery.ReleaseAll();
         blockCollector.CollectParticipatingRefineries(state, gts, refineries);
         rescanRefineries = false;
     }
 }
Ejemplo n.º 5
0
        private static Refinery GetOrCreate()
        {
            if (available.Count == 0)
            {
                var item = new Refinery();
                pool.Add(item);
                return(item);
            }
            var last = available[available.Count - 1];

            available.RemoveAt(available.Count - 1);
            return(last);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Try to use the specified refinery to process the specified blueprint, up to
        /// the refinery's current work target.
        /// </summary>
        /// <param name="refinery"></param>
        /// <param name="blueprint"></param>
        /// <param name="workRequiredSeconds">Amount of work (in seconds) this refinery needs to keep it busy until the next iteration.</param>
        /// <returns>Amount of work (in seconds) provided to this refinery.</returns>
        private double TryFillRefinery(Refinery refinery, Blueprint blueprint, double workRequiredSeconds)
        {
            // How much of this type of ore is required to meet the refinery's work target?
            var oreRate             = refinery.OreConsumptionRate * (blueprint.Input.Quantity / blueprint.Duration);
            var oreQuantityRequired = oreRate * workRequiredSeconds;

            var sources = new OreDonorsIterator(oreDonors[blueprint.Input.ItemType]);

            double workProvidedSeconds = 0;

            // Iterate over available stacks until we run out or satisfy the quota.
            while (sources.Next())
            {
                var donor = sources.Current;
                var item  = donor.GetItem();
                if (item == null || item.Value.Amount == 0)
                {
                    // Donor stack is empty. Remove it.
                    sources.Remove();
                    continue;
                }

                if (!donor.Inventory.IsConnectedTo(refinery.GetOreInventory()))
                {
                    Debug.Write(Debug.Level.All, "Inventory not connected");
                    // Donor inventory can't reach this refinery. Skip it.
                    continue;
                }

                // Don't try to transfer more ore than the donor stack has.
                var transfer = Math.Min(oreQuantityRequired, (double)item.Value.Amount);
                if (donor.TransferTo(refinery.GetOreInventory(), transfer))
                {
                    // Update our estimates based on the transfer succeeding.
                    // ASSUMPTION: success means the entire requested amount was transferred.
                    oreQuantityRequired -= transfer;
                    workProvidedSeconds += transfer / oreRate;

                    // If we've provided enough work, return.
                    if (workProvidedSeconds >= workRequiredSeconds)
                    {
                        break;
                    }
                }
            }
            return(workProvidedSeconds);
        }