void QueueNewItems() { int total_reserve = LoadReserve.Sum(); MyDefinitionId bp; if (total_reserve > 0) { foreach (var kv in Order) { int load_left = kv.Value; if (Blueprints.TryGetValue(kv.Key, out bp)) { for (int i = Assemblers.Count - 1; (i >= 0) && (load_left >= 1); i--) { int part = Math.Min(load_left, kv.Value * LoadReserve[i] / total_reserve); if (part > 0 && Assemblers[i].CanUseBlueprint(bp)) { Assemblers[i].AddQueueItem(bp, (decimal)part); load_left -= part; } } } else { throw new ArgumentException($"No blueprint for {kv.Key.ToString()}"); } } } Order.Clear(); }
public int this[MyItemType type] { get { return(DesiredStock[type]); } set { if (!Blueprints.ContainsKey(type)) { MyDefinitionId?bp = CreateBlueprint(type.SubtypeId); if (!bp.HasValue) { throw new ArgumentException($"Failed to create blueprint for {type.ToString()}"); } Blueprints[type] = bp.Value; InverseBlueprints[bp.Value] = type; } DesiredStock[type] = value; } }
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 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); } }
private static IEnumerable <IngotType> PrepareIngotTypes(RequestedConfiguration configuration, Blueprints blueprints) { return(Constants.INGOT_TYPES .Select(new IngotConfigurer(configuration.Ingots).Configure) .Where(i => i.Enabled) .Select(blueprints.CalculateNormalisationFactor)); }