Last active
February 24, 2018 08:01
-
-
Save Keridos/c5ce2e3aa06a8005fdc0 to your computer and use it in GitHub Desktop.
Space Engineers Solar/Battery Code
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(" 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(" ","") + "W"); | |
} | |
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; | |
float batteryInput = 0.0F; | |
float batteryOutput = 0; | |
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"; | |
solarPower += float.Parse(System.Text.RegularExpressions.Regex.Match(panel.DetailedInfo, solarPanelSearch).Groups["output"].Value); | |
if (i == 0 && System.Text.RegularExpressions.Regex.Match(panel.DetailedInfo, solarPanelSearch).Groups["scale"].Value != "") { | |
scales += System.Text.RegularExpressions.Regex.Match(panel.DetailedInfo, solarPanelSearch).Groups["scale"].Value; | |
} 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); | |
if (i == 0 && System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryInputSearch).Groups["scale"].Value != "") { | |
scales += System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryInputSearch).Groups["scale"].Value; | |
} else if (i == 0) { | |
scales += " "; | |
} | |
batteryOutput += float.Parse(System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryOutputSearch).Groups["output"].Value); | |
if (i == 0 && System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryOutputSearch).Groups["scale"].Value != "") { | |
scales += System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryOutputSearch).Groups["scale"].Value; | |
} else if (i == 0) { | |
scales += " "; | |
} | |
batteryEnergy += float.Parse(System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryPowerSearch).Groups["power"].Value); | |
if (i == 0 && System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryPowerSearch).Groups["scale"].Value != "") { | |
scales += System.Text.RegularExpressions.Regex.Match(battery.DetailedInfo, batteryPowerSearch).Groups["scale"].Value; | |
} 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