public RefineryWorklist(OreTypes oreTypes, IngotTypes ingotTypes, RefineryFactory refineryFactory, Blueprints blueprints) { this.oreTypes = oreTypes; iterators = new Dictionary <ItemType, IRefineryIterator>(ingotTypes.All.Count); blueprintsByIngotTypeAndBlockDefinition = new Dictionary <KeyValuePair <ItemType, string>, Blueprint[]>(refineryFactory.AllTypes.Count * ingotTypes.All.Count); blockDefinitionsByIngotType = new Dictionary <ItemType, string[]>(ingotTypes.All.Count); var blocks = new List <string>(refineryFactory.AllTypes.Count); foreach (var ingotType in ingotTypes.AllIngotItemTypes) { var bps = blueprints.GetBlueprintsProducing(ingotType); blocks.Clear(); foreach (var refineryType in refineryFactory.AllTypes) { var matchingBps = bps.Where(refineryType.Supports).ToArray(); var key = new KeyValuePair <ItemType, string>(ingotType, refineryType.BlockDefinitionName); blueprintsByIngotTypeAndBlockDefinition.Add(key, matchingBps); if (matchingBps.Length > 0) { blocks.Add(refineryType.BlockDefinitionName); } } blockDefinitionsByIngotType.Add(ingotType, blocks.ToArray()); iterators[ingotType] = new RefineryIterator(this, ingotType); } }
/// <summary> /// Calculate how long the specified refinery will take to run dry, taking into account /// refinery speed and ore type. /// </summary> public double GetSecondsToClear(OreTypes oreTypes) { var inventory = GetOreInventory(); double time = 0; for (var i = 0; i < inventory.ItemCount; i++) { var item = inventory.GetItemAt(i); if (item == null) { continue; } time += oreTypes.GetSecondsToClear(item.Value); } return(time / refineSpeed); // OreConsumptionRate; }
public StaticState(RequestedConfiguration configuration) { Blueprints = new Blueprints(Constants.BLUEPRINTS); RefineryFactory = new RefineryFactory(Constants.REFINERY_TYPES); var ores = Constants.BLUEPRINTS.Select(b => b.Input.ItemType).Distinct(); OreTypes = new OreTypes(ores, Constants.BLUEPRINTS); var ingotTypes = PrepareIngotTypes(configuration, Blueprints).ToArray(); IngotTypes = new IngotTypes(ingotTypes); RefinerySpeedFactor = configuration.RefinerySpeedFactor; AssemblerSpeedFactor = configuration.AssemblerSpeedFactor; IngotStatusDisplayName = configuration.IngotStatusDisplayName; OreStatusDisplayName = configuration.OreStatusDisplayName; InventoryBlockNames = configuration.InventoryBlockNames; }
public void UpdateOreDisplay(Dictionary <ItemType, List <OreDonor> > ore, OreTypes oreTypes, List <Refinery> refineries) { if (oreStatusScreen == null) { return; } // Clear previous state. local_UpdateOreDisplay_builder.Clear(); local_UpdateOreDisplay_builder.AppendFormat("Ore stockpiles {0}\n", Datestamp.Minutes); var totalConsumeSpeed = 0.0; var totalProduceSpeed = 0.0; foreach (var refinery in refineries) { totalConsumeSpeed += refinery.OreConsumptionRate; totalProduceSpeed += refinery.TheoreticalIngotProductionRate; } local_UpdateOreDisplay_builder.AppendFormat("Refineries: {0} Speed: {1:0.#} Efficiency: {2:0.#}\n", refineries.Count, totalConsumeSpeed, totalProduceSpeed / totalConsumeSpeed); var totalMass = 0.0; var totalVolume = 0.0; var secondsRemaining = 0.0; foreach (var slot in ore) { var perSecond = oreTypes.GetAmountConsumedPerSecond(slot.Key) * totalConsumeSpeed; var total = slot.Value.Sum(v => v.GetAmountAvailable()); secondsRemaining += total / perSecond; totalMass += total; totalVolume += total * 0.37; // All ore is currently 370 ml/kg local_UpdateOreDisplay_builder.AppendFormat(" {0}: {1} ({2}/s)", slot.Key.SubtypeId, Unit.Mass.FormatSI((float)total), Unit.Mass.FormatSI((float)perSecond)); var blueprint = oreTypes.GetBlueprint(slot.Key); if (blueprint != null) { local_UpdateOreDisplay_builder.AppendFormat(" -> "); if (blueprint.Value.Outputs.Length == 1) { var output = blueprint.Value.Outputs[0]; var outputPerSecond = output.Quantity * totalProduceSpeed / blueprint.Value.Duration; local_UpdateOreDisplay_builder.AppendFormat("{0}/s", Unit.Mass.FormatSI((float)outputPerSecond)); } else { foreach (var output in blueprint.Value.Outputs) { var outputPerSecond = output.Quantity * totalProduceSpeed / blueprint.Value.Duration; local_UpdateOreDisplay_builder.AppendFormat(" {0}: {1}/s ", output.ItemType.SubtypeId.Substring(0, 2), Unit.Mass.FormatSI((float)outputPerSecond)); } } } local_UpdateOreDisplay_builder.Append("\n"); } local_UpdateOreDisplay_builder.AppendFormat("Total: {0} ({1}) Time to clear: {2}", Unit.Mass.FormatSI((float)totalMass), Unit.Volume.FormatSI((float)totalVolume), TimeSpan.FromSeconds((int)secondsRemaining)); oreStatusScreen.WriteText(local_UpdateOreDisplay_builder.ToString()); }