Created
February 19, 2017 02:35
-
-
Save Keridos/f16786c4705eef3c7d3d7923140f9ab9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IMyTextPanel LCD = null; | |
void printLine(string message) { | |
LCD.WritePublicText(message + "\n", true); | |
} | |
void printAll(float solarPower, float batteryEnergy, float batteryInput, float batteryOutput, string scales) { | |
//LCD.WritePublicText("Main Base Energy System \n"); | |
printLine(""); | |
printLine(" Solar power (bugged): " + solarPower.ToString("F") + " " + scales[0].ToString().Replace(" ","") + "W"); | |
printLine(" Battery input (bugged): " + batteryInput.ToString("F") + " " + scales[1].ToString().Replace(" ","") + "W"); | |
printLine(" Battery output: " + batteryOutput.ToString("F") + " "+ scales[2].ToString().Replace(" ","") + "W"); | |
printLine(" Battery energy: " + batteryEnergy.ToString("F") + " " + scales[3].ToString().Replace(" ","") + "Wh"); | |
} | |
void Main(string argument) { | |
LCD = (IMyTextPanel) GridTerminalSystem.GetBlockWithName("LCD Panel"); | |
LCD.WritePublicTitle("MainBase"); | |
LCD.WritePublicText("Main Base Energy System \n"); | |
List<IMyTerminalBlock> batteries = new List<IMyTerminalBlock>{}; | |
List<IMyTerminalBlock> solarPanels = new List<IMyTerminalBlock>{}; | |
GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(batteries,null); | |
GridTerminalSystem.GetBlocksOfType<IMySolarPanel>(solarPanels,null); | |
float solarPower = 0.0F; | |
float batteryEnergy = 0.0F; | |
float batteryInput = 0.0F; | |
float batteryOutput = 0.0F; | |
string scales = ""; | |
for (int i = 0; i < solarPanels.Count; i++){ | |
IMySolarPanel panel = (IMySolarPanel) solarPanels[i]; | |
string solarPanelSearch = @"Current Output: (?<output>[0-9,.]*) (?<scale>[k,M]*)W"; | |
string scale = System.Text.RegularExpressions.Regex.Match(panel.DetailedInfo, solarPanelSearch).Groups["scale"].Value; | |
solarPower += float.Parse(System.Text.RegularExpressions.Regex.Match(panel.DetailedInfo, solarPanelSearch).Groups["output"].Value); | |
if (i == 0 && scale != "") { | |
scales += scale; | |
} else if (i == 0) { | |
scales += " "; | |
} | |
} | |
for (int i = 0; i < batteries.Count; i++) { | |
IMyBatteryBlock battery = (IMyBatteryBlock) batteries[i]; | |
string batteryInputSearch = @"Current Input: (?<input>[0-9,.]*) (?<scale>[k,M]*)W"; | |
string batteryOutputSearch = @"Current Output: (?<output>[0-9,.]*) (?<scale>[k,M]*)W"; | |
string batteryPowerSearch = @"Stored power: (?<power>[0-9,.]*) (?<scale>[k,M]*)Wh"; | |
batteryInput += float.Parse(System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryInputSearch).Groups["input"].Value); | |
string scaleInput = System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryInputSearch).Groups["scale"].Value; | |
string scaleOutput = System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryOutputSearch).Groups["scale"].Value; | |
string scaleEnergy = System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryPowerSearch).Groups["scale"].Value; | |
if (i == 0 && scaleInput != "") { | |
scales += scaleInput; | |
} else if (i == 0) { | |
scales += " "; | |
} | |
batteryOutput += float.Parse(System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryOutputSearch).Groups["output"].Value); | |
if (i == 0 && scaleOutput != "") { | |
scales += scaleOutput; | |
} else if (i == 0) { | |
scales += " "; | |
} | |
batteryEnergy += float.Parse(System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryPowerSearch).Groups["power"].Value); | |
if (i == 0 && scaleEnergy != "") { | |
scales += scaleEnergy; | |
} else if (i == 0) { | |
scales += " "; | |
} | |
} | |
printAll(solarPower, batteryEnergy, batteryInput, batteryOutput, scales); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment