Advertisement
Whiplash141

Whip's Missile Status Screens v2

Sep 7th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.60 KB | None | 0 0
  1.  
  2. /*
  3. Whip's Missile Status Screen Code v2 - revision 05/25/16
  4. */
  5.  
  6. void Main()
  7. {
  8.     MissileStatusScreens();
  9. }
  10.  
  11.     int numberOfMissiles = 4; // from 1 to 10
  12.     string missileTag = "Missile";
  13.     string textPanelName = "Missile Status";
  14.     double speedSafetyThreshold = 15; // in meters per second
  15.     bool checkSafetySpeed = true;
  16.     bool searchWithPrefixZero = false;
  17.  
  18. //No touch below this
  19.  
  20.     string statusEmpty = "> Empty <";
  21.     string statusReady = "< Ready >";
  22.     string statusSafe = "[ Safe ]";
  23.     string spacer = " . . . . . . ";
  24.  
  25. void MissileStatusScreens()
  26. {
  27.     bool safety = false;
  28.     string finalReadout = "Missile   |   Status";
  29.     var shipControllerList = new List< IMyTerminalBlock >();
  30.     GridTerminalSystem.GetBlocksOfType< IMyShipController >( shipControllerList );
  31.     if( shipControllerList.Count != 0 && checkSafetySpeed )
  32.     {
  33.         var thisController = shipControllerList[0] as IMyShipController;
  34.         double shipVelocity = thisController.GetShipSpeed();
  35.         if( shipVelocity > speedSafetyThreshold )
  36.         {
  37.             safety = true;
  38.         }
  39.     }
  40.  
  41.     for( int i = 1; (i - 1) < numberOfMissiles; i++ )
  42.     {
  43.         var missileList = new List< IMyTerminalBlock >();
  44.         string missileStatus = "";
  45.        
  46.     // get status of the selected missile
  47.         if( searchWithPrefixZero && i < 10)
  48.         {
  49.             GridTerminalSystem.SearchBlocksOfName( missileTag + " 0" + i.ToString(), missileList );
  50.         }else{
  51.             GridTerminalSystem.SearchBlocksOfName( missileTag + " " + i.ToString(), missileList );
  52.         }
  53.  
  54.         if( safety )
  55.         {
  56.             missileStatus = statusSafe;
  57.         }
  58.         else if( missileList.Count == 0 )
  59.         {
  60.             missileStatus = statusEmpty;
  61.         }else{
  62.             missileStatus = statusReady;
  63.         }
  64.        
  65.     // get number of missile to print
  66.         string missileNumber = "";
  67.         if ( i < 10 )
  68.         {
  69.             missileNumber = "0" + i.ToString();
  70.         }else{
  71.             missileNumber = i.ToString();
  72.         }
  73.        
  74.         if( missileNumber.Contains("1") )
  75.         {
  76.             missileNumber = missileNumber.Replace( "1", " 1" );
  77.         }
  78.        
  79.     // build final missile status string
  80.         finalReadout += "\n  " + missileNumber + spacer + missileStatus;
  81.     }
  82.    
  83. // write final missile status screen to text panel
  84.     WriteToTextPanel( textPanelName, finalReadout );
  85. }
  86.  
  87. void WriteToTextPanel(string textPanelName, string textToWrite)  
  88. {  
  89.     var listScreens = new List<IMyTerminalBlock>();
  90.     GridTerminalSystem.SearchBlocksOfName(textPanelName, listScreens, isTextPanel);  
  91.     if(listScreens.Count == 0)  
  92.     {  
  93.         Echo("[ALERT]: No text panel with name tag '" + textPanelName + "' was found");  
  94.         return;  
  95.     }else{  
  96.         for(int i = 0; i < listScreens.Count; i++)  
  97.         {  
  98.             var thisScreen = listScreens[i] as IMyTextPanel;  
  99.             if(thisScreen != null)  
  100.             {  
  101.                 thisScreen.WritePublicText(textToWrite);  
  102.                 thisScreen.ShowTextureOnScreen();
  103.                 thisScreen.ShowPublicTextOnScreen();
  104.             }  
  105.         }  
  106.     }  
  107. }
  108.  
  109. bool isTextPanel( IMyTerminalBlock block )
  110. {
  111.     var testScreen = block as IMyTextPanel;
  112.     return testScreen != null;
  113. }
  114.  
  115.  
  116. /*
  117. Missile   |   Status
  118.   0 1 . . . . . . [Unloaded]
  119.   02 . . . . . . [Ready]
  120.   03 . . . . . . [Ready]
  121.   04 . . . . . . [Ready]
  122.   05 . . . . . . [Ready]  
  123.   06 . . . . . . [Ready]
  124.   07 . . . . . . [Ready]
  125.   08 . . . . . . [Ready]
  126. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement