Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<IMyTerminalBlock> containers = new List<IMyTerminalBlock>();
- Dictionary<string,int[]> RequiredItems = new Dictionary<string,int[]>(){
- {"SteelPlate", new int[] {0,5000}},
- {"BulletproofGlass", new int[] {0,1000}},
- {"Computer", new int[] {0,1000}},
- {"Construction", new int[] {0,5000}},
- {"Detector", new int[] {0,100}},
- {"Display", new int[] {0,1000}},
- {"Girder", new int[] {0,1000}},
- {"InteriorPlate", new int[] {0,5000}},
- {"LargeTube", new int[] {0,1000}},
- {"MetalGrid", new int[] {0,1000}},
- {"Motor", new int[] {0,1000}},
- {"PowerCell", new int[] {0,500}},
- {"RadioCommunication", new int[] {0,100}},
- {"SmallTube", new int[] {0,1000}},
- {"SolarCell", new int[] {0,1000}}
- };
- IMyTextPanel lcd;
- IMyAssembler assembler;
- void Main()
- {
- assembler = GridTerminalSystem.GetBlockWithName("Assembler 1 [Master]") as IMyAssembler;
- lcd = GridTerminalSystem.GetBlockWithName("LCD Panel") as IMyTextPanel;
- GridTerminalSystem.SearchBlocksOfName("[Base]", containers, container => container is IMyCargoContainer);
- double rate = RateFilling();
- CalculateMissingItems();
- WriteLCD();
- }
- double RateFilling() {
- double maxFilling = 0.0d;
- double currentFilling = 0.0d;
- //DATA : take all the containers, see how they are filled (currentFilling), see what is their max filling (maxFilling)
- for (int i = 0; i < containers.Count; i++)
- {
- var inventory = ((IMyEntity)containers[i]).GetInventory(0);
- List<MyInventoryItem> inventoryItems = new List<MyInventoryItem>();
- inventory.GetItems(inventoryItems);
- foreach (var item in inventoryItems)
- {
- string itemString = item.Type.ToString();
- string outputString = itemString.Substring(itemString.IndexOf("/")+1);
- int[] value = new int[] {};
- if (RequiredItems.TryGetValue(outputString,out value)) {
- int[] array = RequiredItems[outputString];
- array[0] += item.Amount.ToIntSafe();
- }
- }
- currentFilling += Convert.ToDouble(inventory.CurrentVolume.RawValue);
- maxFilling += Convert.ToDouble(inventory.MaxVolume.RawValue);
- }
- return Math.Round(100 * (currentFilling / maxFilling), 2);
- }
- void CalculateMissingItems() {
- foreach (var item in RequiredItems)
- {
- Echo(item.Key);
- MyDefinitionId blueprint = new MyDefinitionId();
- if(MyDefinitionId.TryParse("MyObjectBuilder_BlueprintDefinition/"+ item.Key, out blueprint)) {
- if(item.Value[0] < item.Value[1]) {
- assembler.AddQueueItem(blueprint, (double)item.Value[1]-item.Value[0]);
- }
- }
- else if(MyDefinitionId.TryParse("MyObjectBuilder_BlueprintDefinition/"+ item.Key + "Component",out blueprint)){
- if(item.Value[0] < item.Value[1]) {
- assembler.AddQueueItem(blueprint, (double)item.Value[1]-item.Value[0]);
- }
- }
- }
- }
- void WriteLCD() {
- string outputString = "";
- foreach (var item in RequiredItems)
- {
- outputString += "Amount of: " + item.Key+ " " + item.Value[0] + "/" + item.Value[1] + "\n";
- }
- lcd.WriteText(outputString);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement