Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local side = require("sides")
- local term = require("term")
- local red = {}
- local C = 1
- for add, n in component.list("redstone") do
- red[C] = component.proxy(add)
- C = C + 1
- end
- if (#red >= 1) then
- red = red[1]
- else
- red = nil
- end
- local X, Y, W, H, Xt, Yt, D, x0, y0, r0
- local matrix = {}
- local sites = {}
- local pads = {}
- local b_missile, can_missile, gud_missile, des_missile, ful_missile
- local b_launch
- local sides = {}
- sides.check = side.top
- sides.wait = side.north
- sides.silo = side.east
- sides.launch = side.west
- local n1 = {"Alpha", "Bravo", "Charlie", "Delta", "Echo"}
- local n2 = {"Romeo", "Tango", "Golf", "Oscar", "Foxtrot"}
- W, H = term.getViewport()
- -- Draws the circle
- local function Circle(mat, r, x, y, v)
- mat[r+x][r+y] = v
- mat[r-x][r+y] = v
- mat[r+x][r-y] = v
- mat[r-x][r-y] = v
- mat[r+y][r+x] = v
- mat[r-y][r+x] = v
- mat[r+y][r-x] = v
- mat[r-y][r-x] = v
- end
- -- Generates a random point on the circumference
- local function Bomba(mat, r, v)
- local x, y
- repeat
- x = math.random(2*r+1)
- y = math.random(2*r+1)
- until ((x-r-1)^2 + (y-r-1)^2 < r^2-1 and mat[y][x] ~= v)
- mat[y][x] = v
- return x, y
- end
- -- Resets redstone
- if (red ~= nil) then
- for i=0,#side-1,1 do
- red.setOutput(side[side[i]], 0)
- end
- end
- -- Components
- C = 1
- for add, n in component.list("ntm_launch_pad") do
- pads[C] = component.proxy(add)
- C = C + 1
- end
- for add, n in component.list("ntm_custom_launch_pad") do
- pads[C] = component.proxy(add)
- C = C + 1
- end
- local boom = #pads
- local length = math.floor(W / 7)
- local radius = math.floor(length / 2)
- if (boom <= 0) then
- error("cacati in culo")
- end
- -- Coordinates and target radius aquisition
- repeat
- term.clear()
- term.setCursor(1, 1)
- term.write("> Insert coordinate X(X): ")
- x0 = tonumber(io.read())
- term.write("> Insert coordinate Y(Z): ")
- y0 = tonumber(io.read())
- term.write("> Insert radius: ")
- r0 = tonumber(io.read())
- until (x0 ~= nil and y0 ~= nil and r0 ~= nil)
- r0 = math.abs(r0)
- print()
- Xt, Yt = term.getCursor()
- -- Creates lines
- for i=1,length+1,1 do
- matrix[i] = {}
- end
- -- Matrix initialization and reset
- for y=1,length+1,1 do
- for x=1,length+1,1 do
- matrix[y][x] = 0
- end
- end
- -- Circumference calculations
- X = 0
- Y = radius
- D = 3 - 2 * radius
- Circle(matrix, radius+1, X, Y, -1)
- while (Y >= X) do
- if (D > 0) then
- Y = Y - 1
- D = D + 4 * (X - Y) + 10
- else
- D = D + 4 * X + 6
- end
- X = X + 1
- Circle(matrix, radius+1, X, Y, -1)
- end
- math.randomseed(os.time())
- -- Bombardé!
- for i=1,boom,1 do
- sites[i] = {Bomba(matrix, radius+1, 1)}
- sites[i][1] = math.floor(x0 + (sites[i][1] - radius - 1) / radius * r0)
- sites[i][2] = math.floor(y0 + (sites[i][2] - radius - 1) / radius * r0)
- end
- -- Prints the matrix
- for y=1,length+1,1 do
- for x=1,length+1,1 do
- if (matrix[y][x] == -1) then
- C = "@"
- elseif (matrix[y][x] == 1) then
- C = "X"
- else
- C = " "
- end
- term.write(C .. " ")
- end
- print()
- end
- X, Y = term.getCursor()
- -- Prints the sites
- print()
- for i=1,#sites,1 do
- term.setCursor((length+1)*2+1, i+Yt)
- print(("> Site n. %2d [%15s] -> (X: %5d, Y: %5d)"):format(i, n1[math.random(#n1)].." "..n2[math.random(#n2)], sites[i][1], sites[i][2]))
- end
- -- Coordinates setting (custom pads)
- for i=1,#pads,1 do
- if (pads[i].type == "ntm_custom_launch_pad") then pads[i].setCoords(sites[i][1], sites[i][2]) end
- end
- -- Prints the pads and waits for the all clear
- if (red ~= nil) then
- red.setOutput(sides.check, 15)
- end
- repeat
- b_launch = true
- for i=1,#pads,1 do
- if (pads[i].type == "ntm_custom_launch_pad") then
- can_missile, gud_missile, des_missile, ful_missile = pads[i].getLaunchInfo()
- b_missile = can_missile and gud_missile and des_missile and ful_missile
- b_launch = b_launch and b_missile
- else
- b_missile = pads[i].canLaunch()
- b_launch = b_launch and b_missile
- end
- term.setCursor((length+1)*2+1, i+#sites+Yt+1)
- print(("> Pad n. %2d -> %s "):format(i, (b_missile) and "Ready" or "Pending"))
- end
- os.sleep(1.0)
- until (b_launch)
- -- Final phase
- if (red ~= nil) then
- red.setOutput(sides.check, 0)
- red.setOutput(sides.wait, 15)
- end
- term.setCursor(X, Y)
- term.write("\n> Opening silos... ")
- if (red ~= nil) then
- red.setOutput(sides.silo, 15)
- end
- Xt, Yt = term.getCursor()
- for i=5.0,0.0,-0.1 do
- term.setCursor(Xt, Yt)
- print(("%.1fs "):format(i))
- os.sleep(0.1)
- end
- print("> All clear!")
- term.write("> Launch? (y/n): ")
- if (io.read() ~= "y") then
- if (red ~= nil) then
- red.setOutput(sides.silo, 0)
- red.setOutput(sides.wait, 0)
- end
- error("exit")
- end
- if (red ~= nil) then
- red.setOutput(sides.wait, 0)
- red.setOutput(sides.launch, 15)
- end
- print("\n> LAUNCH SEQUENCE INITIATED")
- term.write("> MISSILES LAUNCHED IN T-")
- Xt, Yt = term.getCursor()
- for i=10,0,-1 do
- term.setCursor(Xt, Yt)
- print(i .. " ")
- os.sleep(1.0)
- end
- for i=1,#pads,1 do
- b_launch = (pads[i].type == "ntm_custom_launch_pad") and pads[i].launch() or pads[i].launch(sites[i][1], sites[i][2])
- print(("> Pad n. %d -> %s"):format(i, (b_launch) and "Success" or "Error"))
- os.sleep(1.0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement