Power Output on LCD Panel 1/5 (1)

  1. const String PANEL_NAME = "Status 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.     }
  39.     list.Add("Power Output: " + powerFormatter(currentOutput) + " / " + powerFormatter(maxOutput));
  40.     list.Insert(0,"------------------------------------------------------");
  41.     list.Insert(0,"System Status");
  42.     for (int o=0; o < lineOffset; o++) {
  43.         String shiftedItem = list&#91;0];
  44.         list.RemoveAt(0);
  45.         list.Add(shiftedItem);
  46.     }
  47.     panel.WritePublicText(String.Join("\n",list.ToArray()), false);
  48.  
  49.     panel.ShowTextureOnScreen();  
  50.     panel.ShowPublicTextOnScreen();  
  51.     if (list.Count > PANEL_LINES) {
  52.         lineOffset++;
  53.         if (list.Count - lineOffset < PANEL_LINES) {
  54.            lineOffset = 0;
  55.         }
  56.     }
  57. }  
  58.  
  59. String powerFormatter(double power) {  
  60.     int counter = 0;
  61.     while (power > 1000.0) {
  62.         power = power / 1000;
  63.         counter++;
  64.     }
  65.     return "" + Math.Round((double)power,0).ToString("##0") + MULTIPLIERS.Substring(counter,1) + "W";  
  66. }

Please rate this post

4 Responses

  1. Bombredeemer (Steam)

    Hello, I recently came upon scripting blocks and their many uses and love this sites many useful scripts. However I have no idea what so ever, how to write code or even relatively use the script blocks haha.

    I was trying to use this code for my ship, which contains a single “Large Reactor” and several “batteries” that range in number from 1-6.

    I cannot get the script to show power out put from either the two sources.
    Is it possible to display information from the two combined?

    Would the script be able to display information from the Batteries, Solar Panels, and Reactor to a single display?

    I’d like it to display for the Reactor(s):
    “Reactor Name”
    Power Output:
    Uranium Inv:

    For the Batteries:
    Power Level:
    Power Output:
    Time Remaining:
    Recharge: True/False < This would depend upon the battery's "Semi-Auto" setting.

    For the Solar Panels:
    Current Power Output:
    Current Solar Cover: < This would reflect the green squares on the Solar Panel itself, ranging from 1-4 depending on the blocks current state. If possible, this is simply an idea.

    Finally, for general information of Ship Power Usage:
    Power Usage: < 0-100 depending on current use
    Reactors: < Current output from all reactors as a total output
    Number of Batteries in Use:
    Fuel Time:

    If this is possible please let me know!
    Or if you can help me use the above script properly, again, please let me know!

    -Bombredeemer

    • Pretty sure the power output one I have only does reactor info. I’ll look into writing something like you described and post it here.

  2. @Bombredeemer: Check out the “Reactor Status“, “Battery Status” and “Solar Status” scripts.

  3. Bombredeemer (Steam)

    They look awesome! Thank you! I cannot wait to use these! 😀

Leave a Reply