Advertisement
Whiplash141

Whip's Missile Renamer

Mar 25th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.15 KB | None | 0 0
  1.  
  2. //Whip's Missile Renamer v1 - 3/24/16
  3.  
  4. //You can change these variables
  5.     const int missileNumber = 1;
  6.     const string strMissileName = "Missile";
  7.  
  8.  
  9. //----------------------------------------------------
  10. //Dont touch below this
  11. //----------------------------------------------------
  12.  
  13.     string strMissileTag = strMissileName + " " + missileNumber;
  14.  
  15. void Main()
  16. {
  17.     var listBlocks = new List<IMyTerminalBlock>();
  18.     var listGyros = new List<IMyTerminalBlock>();
  19.     GridTerminalSystem.GetBlocks( listBlocks );
  20.     GridTerminalSystem.GetBlocksOfType<IMyGyro>( listGyros );
  21.  
  22.     bool referencePresent = listGyros.Count != 0;
  23.  
  24.     for( int i = 0; i < listBlocks.Count; i++ )
  25.     {
  26.         var thisBlock = listBlocks[i] as IMyTerminalBlock;
  27.         string strBlockType = "";
  28.         string strThrusterModifier = "";
  29.        
  30.        
  31.     //comb through all blocks and rename
  32.         if( thisBlock is IMyThrust )  
  33.         {
  34.         //check if small or large thruster
  35.             if( thisBlock.CustomName.ToLower().Contains( "small" ) )
  36.             {
  37.                 strBlockType = "Small Thruster";
  38.             }
  39.             else if( thisBlock.CustomName.ToLower().Contains( "large" ) )
  40.             {
  41.                 strBlockType = "Large Thruster";
  42.             }else{
  43.                 strBlockType = "Thruster";
  44.             }
  45.            
  46.         //check the orientation of the thruster and name it accordingly
  47.             if( referencePresent )
  48.             {
  49.                 var thrusterDirection = thisBlock.WorldMatrix.Backward; //because backward thrust = forward motion
  50.                 var referenceBlock = listGyros[0];
  51.                 var referenceDirection = referenceBlock.WorldMatrix.Forward;
  52.                 if( thrusterDirection == referenceDirection )                                                                                                                                       //w.H.i.p.l.a.s.H.1.4.1
  53.                 {
  54.                     strThrusterModifier = " Main";
  55.                 }else{
  56.                     strThrusterModifier = " Side";
  57.                 }
  58.             }
  59.            
  60.         }
  61.         else if( thisBlock is IMyVirtualMass )  
  62.         {
  63.             strBlockType = "Artificial Mass";
  64.         }
  65.         else if( thisBlock is IMyBatteryBlock )  
  66.         {
  67.             strBlockType = "Battery";
  68.         }
  69.         else if( thisBlock is IMyGyro )  
  70.         {
  71.             strBlockType = "Gyroscope";
  72.         }
  73.         else if( thisBlock is IMyShipMergeBlock )  
  74.         {
  75.             strBlockType = "Merge Block";
  76.         }
  77.         else if( thisBlock is IMyTimerBlock )  
  78.         {
  79.             strBlockType = "Gyroscope";
  80.         }
  81.         else if( thisBlock is IMyProgrammableBlock )  
  82.         {
  83.             strBlockType = "Program";
  84.         }
  85.         else if( thisBlock is IMyRemoteControl )
  86.         {
  87.             strBlockType = "Remote";
  88.         }else{
  89.             return;
  90.         }
  91.        
  92.     //apply new name to the block
  93.         string strBlockName = strBlockType + strThrusterModifier + " (" + strMissileTag + ")";
  94.         thisBlock.SetCustomName( strBlockName );
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement