Consolidated Refinery Status 5/5 (3)

The script below will consolidate the production queue of all of your refineries and display the information on an LCD Panel (named at the top of the script).

It list what is currently being refined and what is queued in separate sections on the panel.

It always shows you (at the top) how many refineries are included in the status.

  1. const string PANEL_NAME = "Refinery Panel";  
  2. const int PANEL_LINES = 22;
  3. int lineOffset = 0;
  4.  
  5. void Main()
  6. {
  7.     try {
  8.     List<IMyTerminalBlock> work = new List<IMyTerminalBlock>();
  9.     Dictionary<String,float> refining = new Dictionary<String,float>();
  10.     Dictionary<String,float> queued = new Dictionary<String,float>();
  11.     GridTerminalSystem.SearchBlocksOfName(PANEL_NAME, work);      
  12.     IMyTextPanel panel = null;
  13.     for (int i = 0; i < work.Count; i++)  
  14.     {  
  15.         if (work&#91;i] is IMyTextPanel) {
  16.            panel = (IMyTextPanel)work&#91;i];  
  17.            break;
  18.         }
  19.     }
  20.     if (panel == null)
  21.     {
  22.         return;
  23.     }
  24.     List<IMyTerminalBlock> refineryList = new List<IMyTerminalBlock>();
  25.     GridTerminalSystem.GetBlocksOfType<IMyRefinery>(refineryList);  
  26.  
  27.     for (int i = 0; i < refineryList.Count; i++)  
  28.     {  
  29.         var refineryInvOwner = refineryList&#91;i] as IMyInventoryOwner;
  30.         var refineryInventory = refineryInvOwner.GetInventory(0);
  31.         var refineryItems = refineryInventory.GetItems();  
  32.         for(int j = refineryItems.Count - 1; j >= 0; j--)    
  33.         {    
  34.             String itemName = decodeItemName(refineryItems[j].Content.SubtypeName,
  35.                               refineryItems[j].Content.TypeId.ToString()) + "|" +
  36.                               refineryItems[j].Content.TypeId.ToString();
  37.             float amount = (float)refineryItems[j].Amount;
  38.             if (j == 0) {
  39.                 if (!refining.ContainsKey(itemName)) {
  40.                    refining.Add(itemName, amount);
  41.                 } else {
  42.                    refining[itemName] += amount;
  43.                 }
  44.             } else {
  45.                 if (!queued.ContainsKey(itemName)) {
  46.                    queued.Add(itemName, amount);
  47.                 } else {
  48.                    queued[itemName] += amount;
  49.                 }
  50.             }
  51.         }  
  52.     }
  53.     List<String> refiningList = new List<String>();
  54.     var enumerator = refining.GetEnumerator();
  55.     while (enumerator.MoveNext())
  56.     {      
  57.         var pair = enumerator.Current;
  58.         String itemKey = pair.Key;
  59.         float itemValue = pair.Value;
  60.        
  61.         String txt = itemKey.Split('|')[0] + "  -  ";
  62.         String amt = amountFormatter(itemValue,itemKey.Split('|')[1]);
  63.         txt += amt;
  64.         refiningList.Add(txt);
  65.     }    
  66.     List<String> queuedList = new List<String>();
  67.     var enumerator2 = queued.GetEnumerator();
  68.     while (enumerator2.MoveNext())
  69.     {      
  70.         var pair = enumerator2.Current;
  71.         String itemKey = pair.Key;
  72.         float itemValue = pair.Value;
  73.        
  74.         String txt = itemKey.Split('|')[0] + "  -  ";
  75.         String amt = amountFormatter(itemValue,itemKey.Split('|')[1]);
  76.         txt += amt;
  77.         queuedList.Add(txt);
  78.     }    
  79.     refiningList.Sort();
  80.     queuedList.Sort();
  81.     List<String> list = new List<String>();
  82.     list.Add("Refinery Status (" + refineryList.Count + " refineries)");
  83.     list.Add("------------------------------------------------------");
  84.     list.Add("-------Refining-------");
  85.     list.AddRange(refiningList);
  86.     list.Add("------------------------------------------------------");
  87.     list.Add("--------Queued--------");
  88.     list.AddRange(queuedList);
  89.    
  90.     for (int o=0; o < lineOffset; o++) {
  91.         String shiftedItem = list&#91;0];
  92.         list.RemoveAt(0);
  93.         list.Add(shiftedItem);
  94.     }
  95.     panel.WritePublicText(String.Join("\n",list.ToArray()), false);
  96.  
  97.     panel.ShowTextureOnScreen();  
  98.     panel.ShowPublicTextOnScreen();
  99.     if (list.Count > PANEL_LINES) {
  100.         lineOffset++;
  101.         if (list.Count - lineOffset < PANEL_LINES) {
  102.            lineOffset = 0;
  103.         }
  104.     }
  105.     } catch (Exception ex) {
  106.         throw new Exception(ex.StackTrace);
  107.     }
  108. }
  109.  
  110. String amountFormatter(float amt, String typeId) {
  111.     if (typeId.EndsWith("_Ore") || typeId.EndsWith("_Ingot")) {
  112.         if (amt > 1000.0f) {
  113.           return "" + Math.Round((float)amt/1000,2).ToString("###,###,##0.00") + "K";
  114.         } else {
  115.           return "" + Math.Round((float)amt,2).ToString("###,###,##0.00");
  116.         }
  117.     }
  118.     return "" + Math.Round((float)amt,0).ToString("###,###,##0");
  119. }
  120.  
  121. String decodeItemName(String name, String typeId)  
  122. {
  123.     if (typeId.EndsWith("_Ore")) {
  124.         if (name.Equals("Stone")) {
  125.             return name;
  126.         }
  127.         return name + " Ore";
  128.     }
  129.     return name;
  130. }

Please rate this post

2 Responses

  1. […] Consolidated Refinery Status Assembler Status (unpublished, still tweaking) Consolidated Inventory – Improved (showing Raw Ore) Consolidated Inventory – Improved (showing Refined Ore) Consolidated Inventory – Improved (showing Components) Reactor Status Battery Status Solar Status […]

  2. SpookyHmmer

    Can you get the ingots out? not the ores but ONLY the ingots (and silicon waffles and such)

Leave a Reply