Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dictionary<string, int> missing = new Dictionary<string, int>();
- Dictionary<string, int> available = new Dictionary<string, int>();
- InventoryManager.GetAvailableComponents(ref available);
- GetMissingComponentsPotentialTargets<NaniteConstructionTargets>(missing, available);
- GetMissingComponentsPotentialTargets<NaniteProjectionTargets>(missing, available);
- foreach (var item in missing)
- {
- var def = MyDefinitionManager.Static.TryGetBlueprintDefinitionByResultId(new MyDefinitionId(typeof(MyObjectBuilder_Component), item.Key));
- if (def == null)
- continue;
- // If this is some sort of weird modded definition, then we need to find the vanilla definition (ug)
- if (def.Results != null && def.Results[0].Amount > 1)
- {
- if (m_defCache.ContainsKey(new MyDefinitionId(typeof(MyObjectBuilder_Component), item.Key)))
- {
- def = m_defCache[new MyDefinitionId(typeof(MyObjectBuilder_Component), item.Key)];
- }
- else
- {
- foreach (var defTest in MyDefinitionManager.Static.GetBlueprintDefinitions())
- {
- if (defTest.Results != null && defTest.Results[0].Amount == 1 && defTest.Results[0].Id == new MyDefinitionId(typeof(MyObjectBuilder_Component), item.Key))
- {
- def = defTest;
- m_defCache.Add(new MyDefinitionId(typeof(MyObjectBuilder_Component), item.Key), def);
- break;
- }
- }
- }
- }
- bool found = false;
- foreach (var assemblerTest in assemblerList)
- {
- foreach (var queueItem in assemblerTest.GetQueue())
- {
- if (queueItem.Blueprint == def && (int)queueItem.Amount >= item.Value)
- {
- found = true;
- break;
- }
- }
- }
- if (found)
- continue;
- int blueprintCount = assemblerList.Sum(x => x.GetQueue().Sum(y => y.Blueprint == def ? (int)y.Amount : 0));
- int availableCount = 0;
- if (available.ContainsKey(item.Key))
- availableCount = available[item.Key];
- if (blueprintCount >= item.Value - availableCount)
- {
- continue;
- }
- var assemblers = assemblerList.Where(x => NaniteConstructionManager.AssemblerSettings.ContainsKey(x.EntityId) && NaniteConstructionManager.AssemblerSettings[x.EntityId].AllowFactoryUsage);
- foreach (var target in assemblers)
- {
- //if (!NaniteConstructionManager.AssemblerSettings.ContainsKey(target.EntityId))
- // continue;
- //if (!NaniteConstructionManager.AssemblerSettings[target.EntityId].AllowFactoryUsage)
- // continue;
- int amount = (int)Math.Max(((float)(item.Value - blueprintCount) / (float)assemblers.Count()), 1f);
- Logging.Instance.WriteLine(string.Format("ASSEMBLER Queuing {0} {1} for factory {2} ({3})", amount, def.Id, m_constructionBlock.CustomName, blueprintCount));
- //Logging.Instance.WriteLine("Value of target: " + target.ToString());
- //Logging.Instance.WriteLine("Can target make this blueprint? (Def.ID value): " + target.CanUseBlueprint(def.Id));
- target.InsertQueueItem(0, def, amount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement