Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const String PANEL_NAME = "Status Panel";
- const String MULTIPLIERS = ".kMGTPEZY" ;
- const int PANEL_LINES = 22;
- int lineOffset = 0;
- void Main()
- {
- List<IMyTerminalBlock> work = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> reactors = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyReactor>(reactors);
- GridTerminalSystem.SearchBlocksOfName(PANEL_NAME, work);
- IMyTextPanel panel = null;
- for (int i = 0; i < work.Count; i++)
- {
- if (work[i] is IMyTextPanel) {
- panel = (IMyTextPanel)work[i];
- break;
- }
- }
- System.Text.RegularExpressions.Regex reactorRegex = new System.Text.RegularExpressions.Regex(
- "Max Output: (\\d+\\.?\\d*) (\\w?)W.*Current Output: (\\d+\\.?\\d*) (\\w?)W",
- System.Text.RegularExpressions.RegexOptions.Singleline);
- double maxOutput = 0.0f;
- double currentOutput = 0.0f;
- List<String> list = new List<String>();
- for (int i = 0; i < reactors.Count; i++)
- {
- System.Text.RegularExpressions.Match match = reactorRegex.Match(reactors[i].DetailedInfo);
- double parsedDouble;
- if (match.Success) {
- if (Double.TryParse(match.Groups[1].Value, out parsedDouble))
- maxOutput += parsedDouble * Math.Pow(1000.0, MULTIPLIERS.IndexOf(match.Groups[2].Value));
- if (Double.TryParse(match.Groups[3].Value, out parsedDouble))
- currentOutput += parsedDouble * Math.Pow(1000.0, MULTIPLIERS.IndexOf(match.Groups[4].Value));
- }
- }
- list.Add("Power Output: " + powerFormatter(currentOutput) + " / " + powerFormatter(maxOutput));
- list.Insert(0,"------------------------------------------------------");
- list.Insert(0,"System Status");
- for (int o=0; o < lineOffset; o++) {
- String shiftedItem = list[0];
- list.RemoveAt(0);
- list.Add(shiftedItem);
- }
- panel.WritePublicText(String.Join("\n",list.ToArray()), false);
- panel.ShowTextureOnScreen();
- panel.ShowPublicTextOnScreen();
- if (list.Count > PANEL_LINES) {
- lineOffset++;
- if (list.Count - lineOffset < PANEL_LINES) {
- lineOffset = 0;
- }
- }
- }
- String powerFormatter(double power) {
- int counter = 0;
- while (power > 1000.0) {
- power = power / 1000;
- counter++;
- }
- return "" + Math.Round((double)power,0).ToString("##0") + MULTIPLIERS.Substring(counter,1) + "W";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement