Reactor Status 0/5 (5)

  1. const String PANEL_NAME = "Reactor Panel";  
  2. const String MULTIPLIERS = ".kMGTPEZY" ;  
  3. const int PANEL_LINES = 22;  
  4. int lineOffset = 0;  
  5.  
  6. void Main()  
  7. {  
  8.     List<IMyTerminalBlock> work = new List<IMyTerminalBlock>();  
  9.     List<IMyTerminalBlock> reactors = new List<IMyTerminalBlock>();  
  10.     GridTerminalSystem.GetBlocksOfType<IMyReactor>(reactors);    
  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.  
  21.     System.Text.RegularExpressions.Regex reactorRegex = new System.Text.RegularExpressions.Regex(  
  22.                     "Max Output: (\\d+\\.?\\d*) (\\w?)W.*Current Output: (\\d+\\.?\\d*) (\\w?)W",  
  23.                     System.Text.RegularExpressions.RegexOptions.Singleline);      
  24.     double maxOutput = 0.0f;  
  25.     double currentOutput = 0.0f;  
  26.     List<String> list = new List<String>();  
  27.     for (int i = 0; i < reactors.Count; i++)    
  28.     {    
  29.         System.Text.RegularExpressions.Match match = reactorRegex.Match(reactors&#91;i].DetailedInfo);  
  30.         double parsedDouble;  
  31.         if (match.Success) {  
  32.             if (Double.TryParse(match.Groups&#91;1].Value, out parsedDouble))  
  33.                 maxOutput = parsedDouble * Math.Pow(1000.0, MULTIPLIERS.IndexOf(match.Groups&#91;2].Value));  
  34.  
  35.             if (Double.TryParse(match.Groups&#91;3].Value, out parsedDouble))  
  36.                 currentOutput = parsedDouble * Math.Pow(1000.0, MULTIPLIERS.IndexOf(match.Groups&#91;4].Value));  
  37.         }  
  38.         list.Add("\"" + reactors&#91;i].CustomName + "\"");
  39.         list.Add("Power Output: " + powerFormatter(currentOutput) + " / " + powerFormatter(maxOutput));  
  40.         var reactorInvOwner = reactors&#91;i] as IMyInventoryOwner;        
  41.         var reactorInventory = reactorInvOwner.GetInventory(0);
  42.         var reactorItems = reactorInventory.GetItems();
  43.         float totalUranium = 0.0f;
  44.         for(int j = reactorItems.Count - 1; j >= 0; j--)    
  45.         {    
  46.             totalUranium += (float)reactorItems[j].Amount;
  47.         }  
  48.         list.Add("Uranium Inventory: " + amountFormatter(totalUranium));  
  49.  
  50.         list.Add("------------------------------------------------------");  
  51.     }  
  52.     list.Insert(0,"------------------------------------------------------");  
  53.     list.Insert(0,"Reactor Status");  
  54.     for (int o=0; o < lineOffset; o++) {  
  55.         String shiftedItem = list&#91;0];  
  56.         list.RemoveAt(0);  
  57.         list.Add(shiftedItem);  
  58.     }  
  59.     panel.WritePublicText(String.Join("\n",list.ToArray()), false);  
  60.    
  61.     panel.ShowTextureOnScreen();    
  62.     panel.ShowPublicTextOnScreen();  
  63.     if (list.Count > PANEL_LINES) {  
  64.         lineOffset++;  
  65.         if (list.Count - lineOffset < PANEL_LINES) {  
  66.            lineOffset = 0;  
  67.         }  
  68.     }  
  69. }  
  70.  
  71. String amountFormatter(float amt) {  
  72.     if (amt > 1000.0f) {
  73.       return "" + Math.Round((float)amt/1000,2).ToString("###,###,##0.00") + "K";  
  74.     } else {
  75.       return "" + Math.Round((float)amt,2).ToString("###,###,##0.00");  
  76.     }
  77.     return "" + Math.Round((float)amt,0).ToString("###,###,##0");  
  78. }  
  79.    
  80. String powerFormatter(double power) {  
  81.     int counter = 0;  
  82.     while (power > 1000.0) {  
  83.         power = power / 1000;  
  84.         counter++;  
  85.     }  
  86.     return "" + Math.Round((double)power,0).ToString("##0") + MULTIPLIERS.Substring(counter,1) + "W";  
  87. }

Please rate this post

2 Responses

  1. […] – Improved (showing Refined Ore) Consolidated Inventory – Improved (showing Components) Reactor Status Battery Status Solar […]

  2. Some brackets are broken in this one.
    Replace “[” with ‘[‘.

Leave a Reply