Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. int DET_DELAY = 15;
  2. bool FIRST_RUN = true;
  3. int TIMER = 0;
  4. string BLOCK_NAME = "MISSILE_TIP";
  5. bool DEBUG = true;
  6.  
  7. public Program(){
  8.     Runtime.UpdateFrequency = UpdateFrequency.Once;
  9. }
  10.  
  11. public void Main()
  12. {
  13.     IMyTerminalBlock missileTip = null;
  14.     missileTip = GridTerminalSystem.GetBlockWithName(BLOCK_NAME);
  15.     if (DEBUG){
  16.         Echo("----DEBUG MODE: ON----\n");
  17.         Echo("TIMER: " + TIMER);
  18.         Echo("FIRST RUN?: " + FIRST_RUN);
  19.         Echo("DETONATION DELAY: " + DET_DELAY);
  20.     }
  21.     if (FIRST_RUN){
  22.         if (missileTip == null){
  23.             Echo("ERR: No missile tip found, restart program.");
  24.             Runtime.UpdateFrequency = UpdateFrequency.None;
  25.             return;
  26.         }
  27.         FIRST_RUN = false;
  28.         Runtime.UpdateFrequency = UpdateFrequency.Update1;
  29.     }
  30.    
  31.     if(((missileTip == null) || (CurrentDamage(missileTip)) < 1)){
  32.         if (TIMER == DET_DELAY){
  33.             ArmDetonate();
  34.         } else {
  35.             Wait(DET_DELAY);
  36.         }
  37.     }
  38. }
  39.    
  40. public float CurrentDamage(IMyTerminalBlock block){
  41.     IMySlimBlock slimblock = block.CubeGrid.GetCubeBlock(block.Position);
  42.     float MaxIntegrity = slimblock.MaxIntegrity;
  43.     float BuildIntegrity = slimblock.BuildIntegrity;
  44.     float CurrentDamage = slimblock.CurrentDamage;
  45.     float Damage = (BuildIntegrity - CurrentDamage) / MaxIntegrity;
  46.     if (DEBUG){
  47.         float Damage2 = Damage * 100;
  48.         Echo("MISSILE HP:" + Damage2.ToString());
  49.     }
  50.     return Damage;
  51. }
  52.  
  53. public void Wait(int DET_DELAY_W){
  54.     if (TIMER == DET_DELAY_W){
  55.         ArmDetonate();
  56.     } else {
  57.         TIMER++;
  58.     }
  59. }
  60.  
  61. public void ArmDetonate(){
  62.     List<IMyWarhead> warheads = new List<IMyWarhead>();
  63.     GridTerminalSystem.GetBlocksOfType(warheads);
  64.    
  65.     for (int i = 0; i < warheads.Count; i++){
  66.         IMyWarhead warhead = warheads[i];
  67.         warhead.ApplyAction("Safety");
  68.     }
  69.    
  70.     for (int i = 0; i < warheads.Count; i++){
  71.         IMyWarhead warhead = warheads[i];
  72.         warhead.ApplyAction("Detonate");
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement