Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int DET_DELAY = 15;
- bool FIRST_RUN = true;
- int TIMER = 0;
- string BLOCK_NAME = "MISSILE_TIP";
- bool DEBUG = true;
- public Program(){
- Runtime.UpdateFrequency = UpdateFrequency.Once;
- }
- public void Main()
- {
- IMyTerminalBlock missileTip = null;
- missileTip = GridTerminalSystem.GetBlockWithName(BLOCK_NAME);
- if (DEBUG){
- Echo("----DEBUG MODE: ON----\n");
- Echo("TIMER: " + TIMER);
- Echo("FIRST RUN?: " + FIRST_RUN);
- Echo("DETONATION DELAY: " + DET_DELAY);
- }
- if (FIRST_RUN){
- if (missileTip == null){
- Echo("ERR: No missile tip found, restart program.");
- Runtime.UpdateFrequency = UpdateFrequency.None;
- return;
- }
- FIRST_RUN = false;
- Runtime.UpdateFrequency = UpdateFrequency.Update1;
- }
- if(((missileTip == null) || (CurrentDamage(missileTip)) < 1)){
- if (TIMER == DET_DELAY){
- ArmDetonate();
- } else {
- Wait(DET_DELAY);
- }
- }
- }
- public float CurrentDamage(IMyTerminalBlock block){
- IMySlimBlock slimblock = block.CubeGrid.GetCubeBlock(block.Position);
- float MaxIntegrity = slimblock.MaxIntegrity;
- float BuildIntegrity = slimblock.BuildIntegrity;
- float CurrentDamage = slimblock.CurrentDamage;
- float Damage = (BuildIntegrity - CurrentDamage) / MaxIntegrity;
- if (DEBUG){
- float Damage2 = Damage * 100;
- Echo("MISSILE HP:" + Damage2.ToString());
- }
- return Damage;
- }
- public void Wait(int DET_DELAY_W){
- if (TIMER == DET_DELAY_W){
- ArmDetonate();
- } else {
- TIMER++;
- }
- }
- public void ArmDetonate(){
- List<IMyWarhead> warheads = new List<IMyWarhead>();
- GridTerminalSystem.GetBlocksOfType(warheads);
- for (int i = 0; i < warheads.Count; i++){
- IMyWarhead warhead = warheads[i];
- warhead.ApplyAction("Safety");
- }
- for (int i = 0; i < warheads.Count; i++){
- IMyWarhead warhead = warheads[i];
- warhead.ApplyAction("Detonate");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement