Advertisement
Guest User

Untitled

a guest
May 30th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1.  
  2. const String PANEL_NAME = "Status Panel";
  3. const String MULTIPLIERS = ".kMGTPEZY" ;
  4. const int PANEL_LINES = 22;
  5. int lineOffset = 0;
  6.  
  7. void Main()
  8. {
  9. List<IMyTerminalBlock> work = new List<IMyTerminalBlock>();
  10. List<IMyTerminalBlock> reactors = new List<IMyTerminalBlock>();
  11. GridTerminalSystem.GetBlocksOfType<IMyReactor>(reactors);
  12. GridTerminalSystem.SearchBlocksOfName(PANEL_NAME, work);
  13. IMyTextPanel panel = null;
  14. for (int i = 0; i < work.Count; i++)
  15. {
  16. if (work[i] is IMyTextPanel) {
  17. panel = (IMyTextPanel)work[i];
  18. break;
  19. }
  20. }
  21.  
  22. System.Text.RegularExpressions.Regex reactorRegex = new System.Text.RegularExpressions.Regex(
  23. "Max Output: (\\d+\\.?\\d*) (\\w?)W.*Current Output: (\\d+\\.?\\d*) (\\w?)W",
  24. System.Text.RegularExpressions.RegexOptions.Singleline);
  25. double maxOutput = 0.0f;
  26. double currentOutput = 0.0f;
  27. List<String> list = new List<String>();
  28. for (int i = 0; i < reactors.Count; i++)
  29. {
  30. System.Text.RegularExpressions.Match match = reactorRegex.Match(reactors[i].DetailedInfo);
  31. double parsedDouble;
  32. if (match.Success) {
  33. if (Double.TryParse(match.Groups[1].Value, out parsedDouble))
  34. maxOutput += parsedDouble * Math.Pow(1000.0, MULTIPLIERS.IndexOf(match.Groups[2].Value));
  35.  
  36. if (Double.TryParse(match.Groups[3].Value, out parsedDouble))
  37. currentOutput += parsedDouble * Math.Pow(1000.0, MULTIPLIERS.IndexOf(match.Groups[4].Value));
  38. }
  39. }
  40. list.Add("Power Output: " + powerFormatter(currentOutput) + " / " + powerFormatter(maxOutput));
  41. list.Insert(0,"------------------------------------------------------");
  42. list.Insert(0,"System Status");
  43. for (int o=0; o < lineOffset; o++) {
  44. String shiftedItem = list[0];
  45. list.RemoveAt(0);
  46. list.Add(shiftedItem);
  47. }
  48. panel.WritePublicText(String.Join("\n",list.ToArray()), false);
  49.  
  50. panel.ShowTextureOnScreen();
  51. panel.ShowPublicTextOnScreen();
  52. if (list.Count > PANEL_LINES) {
  53. lineOffset++;
  54. if (list.Count - lineOffset < PANEL_LINES) {
  55. lineOffset = 0;
  56. }
  57. }
  58. }
  59.  
  60. String powerFormatter(double power) {
  61. int counter = 0;
  62. while (power > 1000.0) {
  63. power = power / 1000;
  64. counter++;
  65. }
  66. return "" + Math.Round((double)power,0).ToString("##0") + MULTIPLIERS.Substring(counter,1) + "W";
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement