Created
March 6, 2020 12:41
-
-
Save grongor/07acdcccf3e09b3df45603d4cab2ba7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Program() | |
{ | |
Runtime.UpdateFrequency = UpdateFrequency.Update100; | |
} | |
void Main(string arg) | |
{ | |
var oreQuantities = new Dictionary<string, int>() { | |
{"Stone", 0}, | |
{"Iron", 0}, | |
{"Nickel", 0}, | |
{"Cobalt", 0}, | |
{"Magnesium", 0}, | |
{"Silicon", 0}, | |
{"Silver", 0}, | |
{"Gold", 0}, | |
{"Platinum", 0}, | |
{"Uranium", 0}, | |
{"Ice", 0}, | |
}; | |
var ingotQuantities = new Dictionary<string, int>() { | |
{"Stone", 0}, | |
{"Cobalt", 0}, | |
{"Gold", 0}, | |
{"Iron", 0}, | |
{"Magnesium", 0}, | |
{"Nickel", 0}, | |
{"Platinum", 0}, | |
{"Silicon", 0}, | |
{"Silver", 0}, | |
{"Uranium", 0}, | |
}; | |
var inventoryBlocks = new List<IMyTerminalBlock>(); | |
GridTerminalSystem.SearchBlocksOfName( | |
"[BASE]", | |
inventoryBlocks, | |
block => (block is IMyCargoContainer || block is IMyProductionBlock) | |
); | |
var columnLengths = new Dictionary<int, int>(); | |
foreach (var block in inventoryBlocks.Where(block => block.InventoryCount != 0)) { | |
var items = new List<MyInventoryItem>(); | |
if (block is IMyProductionBlock) { | |
var inputItems = new List<MyInventoryItem>(); | |
((IMyProductionBlock) block).InputInventory.GetItems(inputItems); | |
var outputItems = new List<MyInventoryItem>(); | |
((IMyProductionBlock) block).OutputInventory.GetItems(outputItems); | |
items = inputItems.Concat(outputItems).ToList(); | |
} else { | |
block.GetInventory().GetItems(items); | |
} | |
foreach (var item in items) { | |
Dictionary<string, int> quantities; | |
int column; | |
var subtype = item.Type.TypeId.Split('_')[1]; | |
if (subtype == "Ore") { | |
quantities = oreQuantities; | |
column = 0; | |
} else if (subtype == "Ingot") { | |
quantities = ingotQuantities; | |
column = 2; | |
} else { | |
continue; | |
} | |
var itemName = item.Type.SubtypeId; | |
quantities[itemName] = quantities.GetValueOrDefault(itemName) + (int) item.Amount; | |
var columnMaxLength = columnLengths.GetValueOrDefault(column); | |
if (itemName.Length > columnMaxLength) { | |
columnLengths[column] = itemName.Length; | |
} | |
} | |
} | |
ingotQuantities["Gravel"] = ingotQuantities["Stone"]; | |
ingotQuantities.Remove("Stone"); | |
var ores = oreQuantities.OrderByDescending(pair => pair.Value).ToList(); | |
var ingots = ingotQuantities.OrderByDescending(pair => pair.Value).ToList(); | |
var text = new StringBuilder($"{"Ores",-17} | Ingots\n{new string('-', 18)}|{new string('-', 20)}\n"); | |
for (int i = 0; i < ores.Count; i++) { | |
var ore = ores[i].Key; | |
var quantity = ores[i].Value; | |
var oreCount = $"{((float) quantity / 1000):0.#}k"; | |
text.Append($"{ore,-10} {oreCount,6} |"); | |
if (i >= ingots.Count) { | |
text.Append("\n"); | |
continue; | |
} | |
var ingot = ingots[i].Key; | |
quantity = ingots[i].Value; | |
var ingotCount = $"{((float) quantity / 1000):0.#}k"; | |
text.Append($" {ingot,-10} {ingotCount,6}\n"); | |
} | |
if (ingots.Count > ores.Count) { | |
for (int i = ores.Count; i < ingots.Count; i++) { | |
var ingot = ingots[i].Key; | |
var quantity = ingots[i].Value; | |
var ingotCount = $"{((float) quantity / 1000):0.#}k"; | |
text.Append($"{new string(' ', 19)} {ingot,-10} {ingotCount,6}\n"); | |
} | |
} | |
((IMyTextPanel) GridTerminalSystem.GetBlockWithName("LCD Ore Quantities")).WriteText(text.ToString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment