Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- //// Whip's Komodo Launch System Script - revision 03 - 10/21/16 ////
- */
- //Name of missile
- const string missileName = "Missile";
- //Name of silo door
- const string missileSiloName = "Silo";
- //Total number of missiles
- int numberOfMissiles = 6; //must be greater or equal to one
- //---------------------------------------------------------------------------
- //NO TOUCH
- //---------------------------------------------------------------------------
- int currentMissileNumber = 1;
- bool retry = false;
- List<IMyProgrammableBlock> programs = new List<IMyProgrammableBlock>();
- void Main(string arg)
- {
- Echo("WMI Missile Fire System\n");
- if (numberOfMissiles < 1) // mainly for idiot proofing
- {
- Echo("Uhh you can't have less than one missile bro-nacho");
- }
- switch (arg.ToLower())
- {
- case "fire":
- FireNextMissile();
- break;
- case "reset":
- currentMissileNumber = 1;
- break;
- case "kill":
- KillMissile();
- break;
- default:
- break;
- }
- for (int i = 1; i < numberOfMissiles; i++)
- {
- if(retry) //keeps running until it finds a missile to fire
- FireNextMissile();
- }
- retry = false;
- }
- void FireNextMissile()
- {
- List<IMyTerminalBlock> missileTimerList = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> siloDoorList = new List<IMyTerminalBlock>();
- GridTerminalSystem.SearchBlocksOfName(missileName + " " + currentMissileNumber.ToString(), missileTimerList, IsTimer);
- GridTerminalSystem.SearchBlocksOfName(missileSiloName + " " + currentMissileNumber.ToString(), siloDoorList, IsDoor);
- if (missileTimerList.Count == 0) //aborts if no timers are found
- {
- Echo("Skipping: No missiles found with name '" + missileName + " " + currentMissileNumber.ToString() + "'");
- retry = true;
- }
- else {
- retry = false;
- //triggers missile timer
- for (int i = 0; i < missileTimerList.Count; i++)
- {
- var thisMissileTimer = missileTimerList[i] as IMyTimerBlock;
- if (thisMissileTimer != null)
- {
- thisMissileTimer.ApplyAction("TriggerNow"); //triggers it
- Echo(thisMissileTimer.CustomName + " was triggered");
- }
- }
- //opens our doors
- for (int i = 0; i < siloDoorList.Count; i++)
- {
- var thisSiloDoor = siloDoorList[i] as IMyDoor;
- if (thisSiloDoor != null)
- {
- thisSiloDoor.ApplyAction("OnOff_On"); //ensures it is on
- thisSiloDoor.ApplyAction("Open_On"); //triggers it
- }
- }
- //adds to active program list
- var tempList = new List<IMyTerminalBlock>();
- GridTerminalSystem.SearchBlocksOfName(missileName + " " + currentMissileNumber.ToString(), tempList, IsProgram);
- foreach(IMyProgrammableBlock thisProgram in tempList)
- {
- programs.Add(thisProgram as IMyProgrammableBlock);
- }
- }
- if (currentMissileNumber >= numberOfMissiles)
- {
- currentMissileNumber = 1;
- }
- else {
- currentMissileNumber++;
- }
- }
- void KillMissile()
- {
- Echo("Guidance Killed for " + programs.Count.ToString() + " missile(s)");
- foreach (IMyProgrammableBlock thisProgram in programs)
- {
- bool blockExists = DoesBlockExist( thisProgram );
- if ( blockExists )
- {
- thisProgram.TryRun("kill");
- }
- }
- programs.Clear();
- }
- bool DoesBlockExist( IMyTerminalBlock thisBlock )
- {
- Vector3I pos = thisBlock.Position;
- bool exists = thisBlock.CubeGrid.CubeExists( pos );
- return exists;
- }
- bool IsProgram(IMyTerminalBlock test_block) //checks if block is program
- {
- var cast_program = test_block as IMyProgrammableBlock;
- return cast_program != null;
- }
- bool IsTimer(IMyTerminalBlock test_block) //checks if block is timer
- {
- var cast_timer = test_block as IMyTimerBlock;
- return cast_timer != null;
- }
- bool IsDoor(IMyTerminalBlock test_block) //checks if block is timer
- {
- var cast_door = test_block as IMyDoor;
- return cast_door != null;
- }
Add Comment
Please, Sign In to add comment