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