Whiplash141

Erebus Alpha's Modified GravDrive Code

Jan 26th, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.44 KB | None | 0 0
  1.  
  2. //Configurable variables
  3. //  the word "const" tells the compiler that this variable will never change
  4. const string gravGenGroupName = "Gravdrive Coils";
  5. const string artMassGroupName = "Gravdrive AMUs";
  6.  
  7.  
  8. //dont touch this :P
  9. string GravDriveState = "Off"; //this makes a GLOBAL variable that is stored outside any code.
  10.     //it can be accessed/written to from anywhere in the code
  11.  
  12. public void Main(string argument)
  13. {
  14.    
  15.     switch (argument) //this begins comparing the argument to out accepted cases
  16.     {
  17.         case "fwdmax":
  18.            
  19.             if ( GravDriveState == "FMax" ) //there is no semicolon after if statenemts
  20.             {
  21.                 SetGravityDriveStrength(gravGenGroupName, artMassGroupName, false);
  22.                 GravDriveState = "Off";
  23.             }
  24.             else
  25.             {
  26.                 SetGravityDriveStrength(gravGenGroupName, artMassGroupName, true, -1f);
  27.                 GravDriveState = "FMax";
  28.             }
  29.            
  30.             break;  
  31.  
  32.         case "revmax":  
  33.            
  34.             if (GravDriveState == "RMax")
  35.             {
  36.                 SetGravityDriveStrength(gravGenGroupName, artMassGroupName, false);
  37.                 GravDriveState = "Off";
  38.             }
  39.             else
  40.             {
  41.                 SetGravityDriveStrength(gravGenGroupName, artMassGroupName, true, 1f);
  42.                 GravDriveState = "RMax";
  43.             }
  44.            
  45.             break;
  46.  
  47.         case "fwdlow":  
  48.            
  49.             if (GravDriveState == "FLow")
  50.             {
  51.                 SetGravityDriveStrength(gravGenGroupName, artMassGroupName, false);
  52.                 GravDriveState = "Off";
  53.             }
  54.             else
  55.             {
  56.                 SetGravityDriveStrength(gravGenGroupName, artMassGroupName, true, -0.35f);
  57.                 GravDriveState = "FLow";
  58.             }
  59.            
  60.             break;
  61.  
  62.         case "revlow":  
  63.            
  64.             if (GravDriveState == "RLow")
  65.             {
  66.                 SetGravityDriveStrength(gravGenGroupName, artMassGroupName, false);
  67.                 GravDriveState = "Off";
  68.             }
  69.             else
  70.             {
  71.                 SetGravityDriveStrength(gravGenGroupName, artMassGroupName, true, 0.35f);
  72.                 GravDriveState = "RLow";
  73.             }
  74.            
  75.             break;
  76.  
  77.         default:
  78.             break;
  79.     }
  80. }
  81.  
  82. void SetGravityDriveStrength(string gravityGenGroupName, string artMassGroupName, bool turnOn, float gravityRatio = 0f)
  83. {
  84.     var GravCoils = GridTerminalSystem.GetBlockGroupWithName(gravityGenGroupName);
  85.     var GravDrive = new List<IMyGravityGenerator>();
  86.     GravCoils.GetBlocksOfType(GravDrive);
  87.  
  88.     var GravAMU = GridTerminalSystem.GetBlockGroupWithName(artMassGroupName);
  89.     var GravMass = new List<IMyGravityGenerator>();
  90.     GravAMU.GetBlocksOfType(GravMass);
  91.    
  92.     if (!turnOn)
  93.     {
  94.         foreach (var ThisGrav in GravDrive)
  95.         {
  96.             ThisGrav.ApplyAction("OnOff_Off");
  97.         }
  98.        
  99.         foreach (var ThisMass in GravMass)
  100.         {
  101.             ThisMass.ApplyAction("OnOff_Off");
  102.         }
  103.     }
  104.     else
  105.     {
  106.         foreach (var ThisGrav in GravDrive)
  107.         {
  108.             ThisGrav.SetValue("Gravity", gravityRatio * 9.81f);
  109.             ThisGrav.ApplyAction("OnOff_On");
  110.         }
  111.  
  112.         foreach (var ThisMass in GravMass)
  113.         {
  114.             ThisMass.ApplyAction("OnOff_On");
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment