/** * Locates all the Oxygen generator class blocks on the given grid, * then adds 2000 ice if there is room to do so. * * Only call on server. */ public static void FillOxygenGenerators(IMyCubeGrid targetGrid) { List <IMySlimBlock> blockList = new List <IMySlimBlock>(); targetGrid.GetBlocks(blockList, b => b.FatBlock is Sandbox.ModAPI.IMyGasGenerator); foreach (var block in blockList) { IMyGasGenerator gasGenerator = ((IMyGasGenerator)block.FatBlock); if (gasGenerator == null) { continue; } MyDefinitionId definitionId = new MyDefinitionId(typeof(MyObjectBuilder_Ore), "Ice"); MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem { Amount = AMOUNT_ICE_TO_ADD, Content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId) }; IMyInventory gasGeneratorInv = gasGenerator.GetInventory(0); if (!gasGeneratorInv.CanItemsBeAdded(AMOUNT_ICE_TO_ADD, definitionId)) { continue; } gasGeneratorInv.AddItems(AMOUNT_ICE_TO_ADD, inventoryItem.Content); } }
private void tryMoveIce(IMyGasGenerator target) { //show("Attempting to move ice into "+target.CustomName); FoundItem item = findItem(new ItemProfile("ore/ice")); if (item != null) { MyFixedPoint amt = min(item.item.Amount, 1000); moveItem(item.source, target.GetInventory(), item.item, amt); } else { //show("Not found."); } }
public void Main(string args) { var mainInventory = m_MainCargoContainer.GetInventory(0); var toolInventory = m_ToolsCargoContainer.GetInventory(0); //Сбор произведённого из ассемблеров и рефайнери foreach (var assembler in m_Assemblers) { var inventory = assembler.GetInventory(1); while (inventory.ItemCount != 0) { mainInventory.TransferItemFrom(inventory, 0, null, true); } } foreach (var refinery in m_Refineries) { var inventory = refinery.GetInventory(1); while (inventory.ItemCount != 0) { mainInventory.TransferItemFrom(inventory, 0, null, true); } } //Раздача слитков по ассемблерам AddIngotsToAssemblers(); //Отправка тулзов в контейнер с тулзами, а баллонов в водородник bool sorted = false; while (!sorted) { sorted = true; for (int i = mainInventory.ItemCount - 1; i >= 0; --i) { var item = mainInventory.GetItemAt(i); if (!item.HasValue) { Echo("!item.HasValue exception"); break; } if (item.Value.Type.TypeId != TypeIdOres && item.Value.Type.TypeId != TypeIdIngots && item.Value.Type.TypeId != TypeIdComponents) { if (item.Value.Type.SubtypeId == SubTypeIdHydrogenBottle || item.Value.Type.SubtypeId == SubTypeIdOxygenBottle) { m_MainGasGenerator.GetInventory(0).TransferItemFrom(mainInventory, item.Value); } else { toolInventory.TransferItemFrom(mainInventory, item.Value); } sorted = false; } else { MyInventoryItem?prevItem; if (i != 0 && (prevItem = mainInventory.GetItemAt(i - 1)).HasValue) { if (prevItem.Value.Type == item.Value.Type) { mainInventory.TransferItemFrom(mainInventory, i, i - 1, true); sorted = false; } else { var itemSortOrder = MyItemTypeComparer.GetTypeSortorder(item.Value.Type); var prevSortOrder = MyItemTypeComparer.GetTypeSortorder(prevItem.Value.Type); if (itemSortOrder < prevSortOrder) { mainInventory.TransferItemFrom(mainInventory, i, i - 1); sorted = false; } } } } } } //Подсчёт всех ресурсов на базе var resourcesOnFactory = new Dictionary <MyItemType, MyFixedPoint>(); SummaryItemsOnFactory(resourcesOnFactory); //Заказ в ассемблерах OrderInAssemblers(resourcesOnFactory); }