Advertisement
Whiplash141

Jump Drive Recharge Script

Nov 6th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.16 KB | None | 0 0
  1.  
  2. /*  
  3. /// Whip's Jump Drive Recharge Script v4 - 11/5/2015  
  4. /// DEV VERSION - STILL WIP ///  
  5. */  
  6.  
  7. void Main()  
  8. {  
  9.     List<IMyTerminalBlock> batteries = new List<IMyTerminalBlock>();  
  10.     List<IMyTerminalBlock> jumpDrives = new List<IMyTerminalBlock>();  
  11.     GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(batteries);  
  12.     GridTerminalSystem.GetBlocksOfType<IMyJumpDrive>(jumpDrives);  
  13.      
  14.     Echo("Jump Drives: " + jumpDrives.Count);  
  15.     Echo("Batteries: " + batteries.Count);  
  16.      
  17.     bool drivesRecharging = false;  
  18.     for(int i=0 ; i< jumpDrives.Count ; i++)  
  19.     {  
  20.         var thisDrive = jumpDrives[i] as IMyJumpDrive;  
  21.          
  22.         Echo("Drive Status: " + thisDrive.GetValueBool("Recharge").ToString());  
  23.         string jumpDriveInfo = thisDrive.DetailedInfo; //Echo(jumpDriveInfo);
  24.         string[] jumpDriveInfo_split = jumpDriveInfo.Split('\n');
  25.         string[] maxStoredPower_spilt = jumpDriveInfo_split[2].Split(' ');
  26.         string[] currentStoredPower_split = jumpDriveInfo_split[4].Split(' ');
  27.        
  28.         string currentPowerUnits = currentStoredPower_split[3];
  29.         double unitFactor;
  30.         if(currentPowerUnits == "kWh")
  31.         {
  32.             unitFactor = 1000;
  33.         }else{
  34.             unitFactor = 1000000;
  35.         }
  36.        
  37.         double maxStoredPower = Convert.ToDouble(maxStoredPower_spilt[3]) * 1000000;
  38.         double currentStoredPower = Convert.ToDouble(currentStoredPower_split[2]) * unitFactor;
  39.         Echo("Max: " + maxStoredPower + "\nCurr: " + currentStoredPower);
  40.          
  41.         if(thisDrive.GetValueBool("Recharge") == true && maxStoredPower != currentStoredPower)
  42.         {    
  43.             drivesRecharging = true;  
  44.         }
  45.     }  
  46.  
  47.     for(int i=0 ; i < batteries.Count ; i++)  
  48.     {  
  49.         var thisBattery = batteries[i] as IMyBatteryBlock;  
  50.         if(drivesRecharging)  
  51.         {  
  52.             thisBattery.SetValue("Recharge", false);  
  53.             thisBattery.SetValue("Discharge", true);  
  54.         }else{  
  55.             thisBattery.SetValue("Discharge", false);  
  56.         }  
  57.     }  
  58.     Echo("Drives Recharging?: " + drivesRecharging);  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement