lego11

Missili Delta IV

Aug 3rd, 2021 (edited)
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shell.run("rm startup")
  2. shell.run("pastebin get gK6n0SVt startup")
  3.  
  4. subCoordX = 2531
  5. subCoordY = 70
  6. subCoordZ = 724
  7. maxDist = 10000000
  8. remMissile = 16
  9. salvoNumber = 1
  10.  
  11. function clear()
  12.     term.clear()
  13.     term.setCursorPos(1, 1)
  14.     term.write("        Raketnym kompleksom \"D-9RM\"")
  15. end
  16.  
  17. function updateSalvo()
  18.     salvoNumber = salvoNumber + 1
  19.     if salvoNumber > 16 then
  20.         salvoNumber = 1
  21.     end
  22. end
  23.  
  24. function insertCoords()
  25.     while true do
  26.         clear()
  27.         print("\n\nVstavit' koordinaty:")
  28.         term.setCursorPos(1, 6)
  29.         term.write("X: ")
  30.         term.setCursorPos(1, 8)
  31.         term.write("Z: ")
  32.         term.setCursorPos(1, 10)
  33.         term.write("Radius: ")
  34.         term.setCursorPos(4, 6)
  35.         x = read()
  36.         term.setCursorPos(4, 8)
  37.         z = read()
  38.         term.setCursorPos(9, 10)
  39.         radius = read()
  40.         radius = math.max(1, radius)
  41.         radius = math.min(4, radius)
  42.  
  43.         term.setCursorPos(1, 12)
  44.  
  45.         if tonumber(x) ~= nil and tonumber(z) ~= nil and tonumber(radius) ~= nil then
  46.             print("Sokhranennyye koordinaty.")
  47.             break
  48.         end
  49.     end
  50.  
  51.     sleep(1)
  52.     clear()
  53. end
  54.  
  55. function drawRosace()
  56.     term.setCursorPos(21, 6)
  57.     term.write("    |    ")
  58.     term.setCursorPos(21, 7)
  59.     term.write("    |    ")
  60.     term.setCursorPos(21, 8)
  61.     term.write("   /|\\   ")
  62.     term.setCursorPos(21, 9)
  63.     term.write("  / | \\  ")
  64.     term.setCursorPos(21, 10)
  65.     term.write("----O----")
  66.     term.setCursorPos(21, 11)
  67.     term.write("  \\ | /  ")
  68.     term.setCursorPos(21, 12)
  69.     term.write("   \\|/   ")
  70.     term.setCursorPos(21, 13)
  71.     term.write("    |    ")
  72.     term.setCursorPos(21, 14)
  73.     term.write("    |    ")
  74. end
  75.  
  76. function getRemainingMissile()
  77.     term.setCursorPos(1, 19)
  78.     term.write("Raketa:  "..remMissile.. " - Raketnyy zalp:  " .. salvoNumber.."     ")
  79. end
  80.  
  81. function launchMissile(coordx, coordz, radius)
  82.     coordx=tonumber(coordx)
  83.     coordz=tonumber(coordz)
  84.     p = peripheral.wrap("bottom")
  85.     w = p.getWorld(0)
  86.     y = 128
  87.     id = 0
  88.     while id == 0 or id == 8 or id == 9 or id == 221 or id == 231 or id == 49 or id == 57 or id == 10 or id == 11 do
  89.         id = w.getBlockID(coordx, y, coordz)
  90.         y = y-1
  91.         if y < 10 then
  92.             clear()
  93.             print("\n\nZapusk rakety ne udaslya!!!!")
  94.             sleep(1)
  95.             os.reboot()
  96.         end
  97.     end
  98.     clear()
  99.     w.playSound("AdvJetpacks_startup", coordx, y, coordz, 1, 0.2)
  100.     print("\n\nZapusk krylatyye rakety!")
  101.     rs.setOutput("back", true)
  102.     sleep(0.5)
  103.     rs.setOutput("back", false)
  104.     sleep(1)
  105.     w.explode(subCoordX, subCoordY, subCoordZ, 1, false, false)  
  106.     sleep(2)
  107.    
  108.     spawnMissile(coordx, coordz, radius)
  109. end
  110.  
  111. function spawnMissile(coordX, coordZ, size)
  112.     p = peripheral.wrap("bottom")
  113.     w = p.getWorld(0)
  114.     abort = false
  115.     xt = 0 -- current position; x
  116.     zt = 0 -- / current position; y
  117.     d = 0 --  current direction; 0=RIGHT, 1=DOWN, 2=LEFT, 3=UP
  118.     s = 1 --  chain size
  119.  
  120.     k=1
  121.     while k <= size-1 do
  122.         k = k+1
  123.         m = 0
  124.         if k < size-1 then
  125.             m = 2
  126.         else
  127.             m = 3
  128.         end
  129.         j = 0
  130.         while j<m do
  131.             j=j+1
  132.             i=0
  133.             while i<s do
  134.                 i=i+1
  135.                 --std::cout << matrix[x][y] << " ";
  136.                 --print("X: " .. coordX+xt .. " Z: " .. coordZ+zt)
  137.                 id = w.getBlockID(coordX+xt, y, coordZ+zt)
  138.                 if id == 8 or id == 9 then
  139.                     abort = true
  140.                     break
  141.                 end
  142.                
  143.                 spawnGas(coordX+xt, coordZ+zt)
  144.  
  145.                 if d == 0 then zt = zt + 2
  146.                 elseif d == 1 then xt = xt + 2
  147.                 elseif d == 2 then zt = zt - 2
  148.                 elseif d == 3 then xt = xt - 2
  149.                 end
  150.             end
  151.             if abort == true then
  152.                 break
  153.             end
  154.             d = (d+1)%4
  155.         end
  156.         if abort == true then
  157.             break
  158.         end
  159.         s = s + 1
  160.     end
  161.    
  162.     w.setBlock(coordX, y+1, coordZ, 76, 0)
  163. end
  164.  
  165. function spawnGas(x, z)
  166.     w.setBlock(x, y, z, 1, 0)
  167.     w.setBlock(x, y+2, z, 929, 0)
  168.     --w.setBlock(x, y+1, z, 76, 0)
  169. end
  170.  
  171. function validateCodes()
  172.     while true do
  173.         error = 0
  174.         clear()
  175.         print("\n\nKod autentifikatsii:")
  176.         term.setCursorPos(1, 6)
  177.         term.write("CDR:")
  178.         term.setCursorPos(1, 8)
  179.         term.write("XO:")
  180.         term.setCursorPos(6, 6)
  181.         code1 = read()
  182.         term.setCursorPos(6, 8)
  183.         code2 = read()
  184.         term.setCursorPos(1, 10)
  185.  
  186.        
  187.         if tonumber(code1) ~= nil and tonumber(code2) ~= nil then
  188.             rest = http.get("http://172.16.20.220/luanet/servlets/ssg/k77.php?code1="..code1.."&code2="..code2)
  189.             reply = rest.readAll()
  190.             rest.close()
  191.  
  192.             if reply == "OK" then
  193.                 print("Zapusk razreshen.")
  194.                 launchMissile(x, z, radius)
  195.                 break
  196.             else
  197.                 term.setCursorPos(1,15)
  198.                 term.write("Oshibka! Nevernyy kod!")
  199.                 error = error + 1
  200.                 if error > 3 then
  201.                     os.reboot()
  202.                 end
  203.                 sleep(1)
  204.                 term.setCursorPos(1,15)
  205.                 term.write("                      ")
  206.             end
  207.         end
  208.     end
  209.  
  210.     sleep(1)
  211.     clear()
  212. end
  213.  
  214. function shootMissile()
  215.     if remMissile > 0 then
  216.         validateCodes()
  217.         launchMissile(tonumber(x), tonumber(z), tonumber(radius))
  218.         remMissile = remMissile - 1
  219.         return true
  220.     else
  221.         return false
  222.     end
  223. end
  224.  
  225. function shootMissileSalvo(nOfSalvo)
  226.     if remMissile >= nOfSalvo then
  227.         validateCodes()
  228.         for i = nOfSalvo,0,-1 do
  229.             launchMissile(tonumber(x), tonumber(z), tonumber(radius))
  230.             sleep(5)
  231.         end
  232.         remMissile = remMissile - nOfSalvo
  233.         return true
  234.     else
  235.         return false
  236.     end
  237. end
  238.  
  239. function autoAcquire()
  240.     p = peripheral.wrap("bottom")
  241.    
  242.     while true do
  243.         clear()
  244.         print("\n\nTsel:'")
  245.         term.setCursorPos(1, 6)
  246.         term.write("Imya pol'zovatelya: ")
  247.         term.setCursorPos(1, 9)
  248.         term.write("Sila: ")
  249.        
  250.         term.setCursorPos(1, 7)
  251.         user = read()
  252.         term.setCursorPos(7, 9)
  253.         radius = read()
  254.         radius = math.max(1, radius)
  255.         radius = math.min(8, radius)
  256.        
  257.         pl = p.getPlayerByName(user)
  258.         term.setCursorPos(1, 12)
  259.  
  260.         if pl ~= nil and tonumber(radius) ~= nil then
  261.             ent = pl.asEntity()
  262.             x, ignoredY, z = ent.getPosition()
  263.             print("Tsel' dostignuta.")
  264.             break
  265.         end
  266.     end
  267.  
  268.     sleep(1)
  269.     clear()
  270. end
  271.  
  272.  
  273.  
  274. x = 291
  275. z = 289
  276. radius = 10
  277.  
  278. clear()
  279. while true do
  280.     clear()
  281.     getRemainingMissile()
  282.     drawRosace()
  283.     term.setCursorPos(1, 3)
  284.     term.write("         ")
  285.     term.setCursorPos(1, 3)
  286.     term.write("X: " .. x)
  287.     term.setCursorPos(1, 4)
  288.     term.write("          ")
  289.     term.setCursorPos(1, 4)
  290.     term.write("Z: " .. z)
  291.     term.setCursorPos(1, 5)
  292.  
  293.     d = math.floor(math.sqrt(((x - subCoordX) ^ 2) + ((z - subCoordZ) ^ 2))) / 1000
  294.  
  295.     term.write("d: " .. d .. " km               ")
  296.     local event, key = os.pullEvent("key")
  297.     if key == 200 then
  298.         z = z + 1
  299.     elseif key == 208 then
  300.         z = z - 1
  301.     elseif key == 203 then
  302.         x = x - 1
  303.     elseif key == 205 then
  304.         x = x + 1
  305.     elseif key == 31 then
  306.         updateSalvo()
  307.     elseif key == 211 then
  308.         if d < maxDist then
  309.             if salvoNumber == 1 then
  310.                 shootMissile()
  311.             else
  312.                 shootMissileSalvo(salvoNumber)
  313.             end
  314.         else
  315.             clear()
  316.             term.setCursorPos(1, 12)
  317.             print("Tsel' slishkom daleko.")
  318.             sleep(2)
  319.             clear()
  320.         end
  321.     elseif key == 210 then
  322.         insertCoords()
  323.     elseif key == 199 then
  324.         autoAcquire()
  325.     end
  326. end
Add Comment
Please, Sign In to add comment