Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- /// Whip's Jump Drive Recharge Script v4 - 11/5/2015
- /// DEV VERSION - STILL WIP ///
- */
- void Main()
- {
- List<IMyTerminalBlock> batteries = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> jumpDrives = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(batteries);
- GridTerminalSystem.GetBlocksOfType<IMyJumpDrive>(jumpDrives);
- Echo("Jump Drives: " + jumpDrives.Count);
- Echo("Batteries: " + batteries.Count);
- bool drivesRecharging = false;
- for(int i=0 ; i< jumpDrives.Count ; i++)
- {
- var thisDrive = jumpDrives[i] as IMyJumpDrive;
- Echo("Drive Status: " + thisDrive.GetValueBool("Recharge").ToString());
- string jumpDriveInfo = thisDrive.DetailedInfo; //Echo(jumpDriveInfo);
- string[] jumpDriveInfo_split = jumpDriveInfo.Split('\n');
- string[] maxStoredPower_spilt = jumpDriveInfo_split[2].Split(' ');
- string[] currentStoredPower_split = jumpDriveInfo_split[4].Split(' ');
- string currentPowerUnits = currentStoredPower_split[3];
- double unitFactor;
- if(currentPowerUnits == "kWh")
- {
- unitFactor = 1000;
- }else{
- unitFactor = 1000000;
- }
- double maxStoredPower = Convert.ToDouble(maxStoredPower_spilt[3]) * 1000000;
- double currentStoredPower = Convert.ToDouble(currentStoredPower_split[2]) * unitFactor;
- Echo("Max: " + maxStoredPower + "\nCurr: " + currentStoredPower);
- if(thisDrive.GetValueBool("Recharge") == true && maxStoredPower != currentStoredPower)
- {
- drivesRecharging = true;
- }
- }
- for(int i=0 ; i < batteries.Count ; i++)
- {
- var thisBattery = batteries[i] as IMyBatteryBlock;
- if(drivesRecharging)
- {
- thisBattery.SetValue("Recharge", false);
- thisBattery.SetValue("Discharge", true);
- }else{
- thisBattery.SetValue("Discharge", false);
- }
- }
- Echo("Drives Recharging?: " + drivesRecharging);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement