Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Main(string argument)
- {
- bool error = false;
- int tankLevel = 0;
- String text = "";
- IMyTextPanel panel = (IMyTextPanel) GridTerminalSystem.GetBlockWithName("Panel");
- /*var tanks = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyOxygenTank>(tanks);*/
- var bats = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(bats);
- panel.WritePublicText(" -----------------------------------------\n meQa Planetary Station #01\n -----------------------------------------", false);
- /*if (tanks.Count == 0) error = true;
- else {
- float totalLevel = 0;
- for (int i = 0; i < tanks.Count; i++) {
- totalLevel += (tanks[i] as IMyOxygenTank).GetOxygenLevel();
- }
- tankLevel = (int) ((totalLevel/tanks.Count)*100);
- text += "\n - Hydrogen Level: " + tankLevel + "%";
- }*/
- if (bats.Count == 0) error = true;
- else {
- double totalPower = .0;
- double maxStoredPower = .0;
- for (int i = 0; i < bats.Count; i++) {
- BatteryInfo batInfo = new BatteryInfo((bats[i] as IMyBatteryBlock));
- totalPower += batInfo.GetPowerLevel();
- maxStoredPower += batInfo.GetMaxStoredPower();
- }
- text += "\n - Battery Level: " + BatteryInfo.PowerToStringUnit(totalPower) + " of max " + BatteryInfo.PowerToStringUnit(maxStoredPower);
- text += "\n - Number of Battteries: " + bats.Count;
- }
- if(error) panel.WritePublicText("ERROR - ERROR - ERROR", true);
- else panel.WritePublicText(text, true);
- }
- public class BatteryInfo
- {
- private String[] info;
- private double PowerLevel;
- private double PowerIn;
- private double PowerOut;
- private double MaxStoredPower;
- public BatteryInfo(IMyBatteryBlock bat)
- {
- info = bat.DetailedInfo.Split(new Char[]{'\n'}, StringSplitOptions.RemoveEmptyEntries);
- MaxStoredPower = findDoubleInLine(3);
- PowerOut = findDoubleInLine(4);
- PowerIn = findDoubleInLine(5);
- PowerLevel = findDoubleInLine(6);
- }
- private double findDoubleInLine(int n){
- System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"\d+(.\d+)?");
- System.Text.RegularExpressions.Match m = r.Match(info[n]);
- if (m.Success)
- {
- double v = (double) Convert.ToDecimal(m.Value);
- switch ( info[6].Substring( info[6].Length-3 )) {
- case " Wh": break;
- case "kWh": v = v*1000.0; break;
- case "MWh": v = v*1000000.0; break;
- }
- return v;
- }else{
- return .0;
- }
- }
- public static String PowerToStringUnit(double v){
- if( v >= 1000000.0){
- return Math.Round(v / 1000000.0 , 2)+ " MWh";
- } else if( v >= 1000.0 ){
- return Math.Round(v / 1000.0 , 2) + " kWh";
- } else {
- return Math.Round(v , 2) + " Wh";
- }
- }
- public double GetMaxStoredPower() { return this.MaxStoredPower; }
- public double GetPowerOut() { return this.PowerOut; }
- public double GetPowerIn() { return this.PowerIn; }
- public double GetPowerLevel() { return this.PowerLevel; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement