Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Whip's Missile Status Screen Code v2 - revision 05/25/16
- */
- void Main()
- {
- MissileStatusScreens();
- }
- int numberOfMissiles = 4; // from 1 to 10
- string missileTag = "Missile";
- string textPanelName = "Missile Status";
- double speedSafetyThreshold = 15; // in meters per second
- bool checkSafetySpeed = true;
- bool searchWithPrefixZero = false;
- //No touch below this
- string statusEmpty = "> Empty <";
- string statusReady = "< Ready >";
- string statusSafe = "[ Safe ]";
- string spacer = " . . . . . . ";
- void MissileStatusScreens()
- {
- bool safety = false;
- string finalReadout = "Missile | Status";
- var shipControllerList = new List< IMyTerminalBlock >();
- GridTerminalSystem.GetBlocksOfType< IMyShipController >( shipControllerList );
- if( shipControllerList.Count != 0 && checkSafetySpeed )
- {
- var thisController = shipControllerList[0] as IMyShipController;
- double shipVelocity = thisController.GetShipSpeed();
- if( shipVelocity > speedSafetyThreshold )
- {
- safety = true;
- }
- }
- for( int i = 1; (i - 1) < numberOfMissiles; i++ )
- {
- var missileList = new List< IMyTerminalBlock >();
- string missileStatus = "";
- // get status of the selected missile
- if( searchWithPrefixZero && i < 10)
- {
- GridTerminalSystem.SearchBlocksOfName( missileTag + " 0" + i.ToString(), missileList );
- }else{
- GridTerminalSystem.SearchBlocksOfName( missileTag + " " + i.ToString(), missileList );
- }
- if( safety )
- {
- missileStatus = statusSafe;
- }
- else if( missileList.Count == 0 )
- {
- missileStatus = statusEmpty;
- }else{
- missileStatus = statusReady;
- }
- // get number of missile to print
- string missileNumber = "";
- if ( i < 10 )
- {
- missileNumber = "0" + i.ToString();
- }else{
- missileNumber = i.ToString();
- }
- if( missileNumber.Contains("1") )
- {
- missileNumber = missileNumber.Replace( "1", " 1" );
- }
- // build final missile status string
- finalReadout += "\n " + missileNumber + spacer + missileStatus;
- }
- // write final missile status screen to text panel
- WriteToTextPanel( textPanelName, finalReadout );
- }
- void WriteToTextPanel(string textPanelName, string textToWrite)
- {
- var listScreens = new List<IMyTerminalBlock>();
- GridTerminalSystem.SearchBlocksOfName(textPanelName, listScreens, isTextPanel);
- if(listScreens.Count == 0)
- {
- Echo("[ALERT]: No text panel with name tag '" + textPanelName + "' was found");
- return;
- }else{
- for(int i = 0; i < listScreens.Count; i++)
- {
- var thisScreen = listScreens[i] as IMyTextPanel;
- if(thisScreen != null)
- {
- thisScreen.WritePublicText(textToWrite);
- thisScreen.ShowTextureOnScreen();
- thisScreen.ShowPublicTextOnScreen();
- }
- }
- }
- }
- bool isTextPanel( IMyTerminalBlock block )
- {
- var testScreen = block as IMyTextPanel;
- return testScreen != null;
- }
- /*
- Missile | Status
- 0 1 . . . . . . [Unloaded]
- 02 . . . . . . [Ready]
- 03 . . . . . . [Ready]
- 04 . . . . . . [Ready]
- 05 . . . . . . [Ready]
- 06 . . . . . . [Ready]
- 07 . . . . . . [Ready]
- 08 . . . . . . [Ready]
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement