Advertisement
thatparadox

ICBMpanel

Dec 20th, 2013
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.98 KB | None | 0 0
  1. for k,v in pairs(rs.getSides()) do
  2.   if peripheral.getType(v)=='monitor' then
  3.    side = v
  4.    mon = peripheral.wrap(side)
  5.    break
  6.   end
  7. end
  8. for k,v in pairs(rs.getSides()) do
  9.   if peripheral.getType(v)=='modem' then
  10.    rednet.open(v)
  11.    break
  12.   end
  13. end
  14. monX, monY = mon.getSize()
  15.  
  16. launch = false
  17. update = false
  18. x = 0
  19. y = 0
  20. z = 0
  21.  
  22. local function coords()
  23.   mon.setTextScale(1)
  24.   mon.setTextColor(colors.yellow)
  25.   mon.setBackgroundColor(colors.black)
  26.   for i = 1, monX do
  27.     mon.setCursorPos(i,1)
  28.     mon.write(" ")
  29.   end
  30.   mon.setCursorPos(1,1)
  31.   mon.write("X: "..x)
  32.   mon.setCursorPos(monX/2-2,1)
  33.   mon.write("Y: "..y)
  34.   mon.setCursorPos(monX-8,1)
  35.   mon.write("Z: "..z)
  36.   dist = math.floor(math.sqrt( (x-locX)^2 + (y-locY)^2 + (z-locZ)^2 ))
  37.   for i = 1, monX do
  38.     mon.setCursorPos(i,monY/4)
  39.     mon.write(" ")
  40.   end
  41.   for i = 1, monX do
  42.     mon.setCursorPos(i,monY/4+1)
  43.     mon.write(" ")
  44.   end
  45.   mon.setCursorPos((monX/2)-(string.len("Distance: "..dist)/2), monY/4+1)   --fix
  46.   mon.write("Distance: "..dist)
  47. end
  48.  
  49. local function display()
  50.   mon.setTextScale(1)
  51.   mon.setTextColor(colors.yellow)
  52.   mon.setBackgroundColor(colors.black)
  53.   mon.clear()
  54.   mon.setCursorPos(1,1)
  55.   mon.write("X: "..x)
  56.   mon.setCursorPos(monX/2-2,1)
  57.   mon.write("Y: "..y)
  58.   mon.setCursorPos(monX-8,1)
  59.   mon.write("Z: "..z)
  60.   --Dist = SQRT( (X2-X1)^2 + (Y2-Y1)^2 + (Z2-Z1)^2 )
  61.   --where point A = (X1, Y1, Z1) , B = (X2, Y2, Z2 )
  62.   dist = math.floor(math.sqrt( (x-locX)^2 + (y-locY)^2 + (z-locZ)^2 ))
  63.   mon.setCursorPos(monX/2, monY/4)
  64.   mon.write(dist)
  65.   mon.setTextColor(colors.black)
  66.   mon.setBackgroundColor(colors.yellow)
  67.   for k = monY/2+1, monY do
  68.     for i = 1, monX/5*2 do
  69.       mon.setCursorPos(i, k)
  70.       mon.write(" ")
  71.     end
  72.   end
  73.   mon.setCursorPos(monX/10, monY/4*3+1)
  74.   mon.write("Bookmarks")
  75.   mon.setBackgroundColor(colors.red)
  76.   for k = monY/2+1, monY do
  77.     for i = monX/5*2+1, monX/5*3 do
  78.       mon.setCursorPos(i, k)
  79.       mon.write(" ")
  80.     end
  81.   end
  82.   mon.setCursorPos(monX/2-2, monY/4*3+1)
  83.   mon.setTextColor(colors.yellow)
  84.   mon.write("Launch")
  85.   mon.setBackgroundColor(colors.yellow)
  86.   for k = monY/2+1, monY do
  87.     for i = monX/5*3+1, monX do
  88.       mon.setCursorPos(i,k)
  89.       mon.write(" ")
  90.     end
  91.   end
  92.   mon.setCursorPos(monX/5*4-7, monY/4*3+1)
  93.   mon.setTextColor(colors.black)
  94.   mon.write(" Set Coordinates")
  95. end
  96.  
  97.  
  98. if fs.exists("location") then
  99.   file = fs.open("location","r")
  100.     loc = file.readAll()
  101.     file.close()
  102.     loc = textutils.unserialize(loc)
  103.     for key,value in pairs(loc) do
  104.         if tostring(key) == "x" then
  105.           locX = tonumber(value)
  106.         elseif tostring(key) == "y" then
  107.           locY = tonumber(value)
  108.         elseif tostring(key) == "z" then
  109.           locZ = tonumber(value)
  110.         end
  111.     end
  112.     file = fs.open("icbmCom", "r")
  113.     icbm = tonumber(file.readAll())
  114.     file.close()
  115. else
  116.   mon.clear()
  117.   mon.setCursorPos(x/2 - 16, y/2)
  118.   mon.write("Follow instructions on computer below")
  119.   term.clear()
  120.   term.setCursorPos(1,1)
  121.   write("Enter the Launcher's X coordinate: ")
  122.   locX = read()
  123.   write("Enter the Launcher's Y coordinate: ")
  124.   locY = read()
  125.   write("Enter the Launcher's Z coordinate: ")
  126.   locZ = read()
  127.   location = {x = locX, y = locY, z = locZ}
  128.   location = textutils.serialize(location)
  129.   file = fs.open("location", "w")
  130.   file.write(location)
  131.   file.close()
  132.   term.clear()
  133.   term.setCursorPos(1,1)
  134.   write("Enter the ID the ICBM launcher computer: ")
  135.   icbm = tonumber(read())
  136.   file = fs.open("icbmCom", "w")
  137.   file.write(icbm)
  138.   file.close()
  139. end
  140. display()
  141. while true do
  142.   event, param1, param2, param3, param4, param5 = os.pullEvent()
  143.   print(event)
  144.   if event == "modem_message" and param3 == icbm then
  145.     rednet.send(icbm, "ok1")
  146.     id, x = rednet.receive()
  147.     print("x: "..x)
  148.     rednet.send(icbm, "ok2")
  149.     id, y =rednet.receive()
  150.     print("y: "..y)
  151.     rednet.send(icbm, "ok3")
  152.     id, z = rednet.receive()
  153.     print("Z: "..z)
  154.     if launch == true then
  155.       rednet.send(icbm, "launch")
  156.       launch = false
  157.     elseif update == true then
  158.       print("sending update!")      
  159.       rednet.send(icbm, "coords")
  160.       rednet.receive()
  161.       rednet.send(icbm, setX)
  162.       rednet.receive()
  163.       rednet.send(icbm, setY)
  164.       rednet.receive()
  165.       rednet.send(icbm, setZ)
  166.       update = false
  167.     else
  168.       rednet.send(icbm, "dud")
  169.     end
  170.     coords()
  171.   elseif event == "monitor_touch" and param2 > monX/5*3+1 and param3 > monY/2 then
  172.     mon.setBackgroundColor(colors.black)
  173.     mon.clear()
  174.     coords()
  175.     mon.setCursorPos(monX/2- 14, monY/2)
  176.     mon.setTextColor(colors.red)
  177.     mon.write("ENTER COORDINATES INTO COMPUTER")
  178.     term.clear()
  179.     term.setCursorPos(1,1)
  180.     write("Enter X: ")
  181.     setX = read()
  182.     term.clear()
  183.     term.setCursorPos(1,1)
  184.     write("Enter Y: ")
  185.     setY = read()
  186.     term.clear()
  187.     term.setCursorPos(1,1)
  188.     write("Enter Z: ")
  189.     setZ = read()
  190.     term.clear()
  191.     term.setCursorPos(1,1)
  192.     print("Done!")
  193.     os.sleep(1)
  194.     term.clear()
  195.     update = true
  196.     display()
  197.   elseif event == "monitor_touch" and param2 > monX/5*2+1 and param2 < monX/5*3 and param3 > monY/2 then
  198.     mon.setBackgroundColor(colors.black)
  199.     mon.clear()
  200.     mon.setTextColor(colors.yellow)
  201.     mon.setCursorPos(monX/2 -8, 1)
  202.     mon.write("CONFIRM LAUNCH AT")
  203.     leng = string.len("X: "..tostring(x).." Y: "..tostring(y).." Z: "..tostring(z))
  204.     mon.setCursorPos((monX/2)-leng/2+1, 3)
  205.     mon.write("X: "..x.." Y: "..y.." Z: "..z)
  206.     mon.setTextColor(colors.black)
  207.     mon.setBackgroundColor(colors.red)
  208.     for k = monY/2+1, monY do
  209.         for i = 1, monX/5*2 do
  210.           mon.setCursorPos(i, k)
  211.           mon.write(" ")
  212.         end
  213.     end
  214.     mon.setCursorPos(monX/5-3, monY/4*3+1)
  215.     mon.write("Launch")
  216.     mon.setBackgroundColor(colors.green)
  217.     for k = monY/2+1, monY do
  218.         for i = monX/5*3+1, monX do
  219.           mon.setCursorPos(i,k)
  220.           mon.write(" ")
  221.         end
  222.     end
  223.     mon.setCursorPos(monX/5*4-7, monY/4*3+1)
  224.     mon.write("Abort Launch")
  225.     event, param1, param2, param3 = os.pullEvent("monitor_touch")
  226.     if param2 > monX/5*3 and param3 > monY/2 then
  227.         launch = false
  228.         print(launch)
  229.     elseif param2 < monX/5*2 and param3 > monY/2 then
  230.         launch = true
  231.     end
  232.     display()
  233.   elseif event == "monitor_touch" and param2 < monX/5*2 and param3 > monY/2 then
  234.     mon.setCursorPos(1,1)
  235.     mon.setBackgroundColor(colors.black)
  236.     mon.clear()
  237.     mon.setBackgroundColor(colors.green)
  238.     for i = 1,monY,2 do
  239.       mon.setCursorPos(1,i)
  240.       for k = 1,monX do
  241.         mon.write(" ")
  242.       end
  243.     end
  244.     mon.setBackgroundColor(colors.lime)
  245.     for i = 2,monY,2 do
  246.       mon.setCursorPos(1,i)
  247.       for k = 1,monX do
  248.         mon.write(" ")
  249.       end
  250.     end
  251.     for i = 2, monY,2 do
  252.       if fs.exists(tostring(i)) then
  253.         file = fs.open(tostring(i),"r")
  254.         data = file.readAll()
  255.         file.close()
  256.         data = textutils.unserialize(data)
  257.         for key,value in pairs(data) do
  258.             if tostring(key) == "name" then
  259.               mon.setCursorPos(monX/2-string.len(tostring(value))/2, i)
  260.               mon.write(tostring(value))
  261.             end
  262.         end
  263.       else
  264.         mon.setCursorPos(monX/2-5, i)
  265.         mon.write("Set Bookmark")
  266.       end
  267.     end
  268.     mon.setBackgroundColor(colors.red)
  269.     for i = 1,monY do
  270.       mon.setCursorPos(monX-3,i)
  271.       mon.write(" X ")
  272.     end
  273.     mon.setBackgroundColor(colors.green)
  274.     for i = 1, monY,2 do
  275.       if fs.exists(tostring(i)) then
  276.        
  277.         file = fs.open(tostring(i),"r")
  278.         data = file.readAll()
  279.         file.close()
  280.         data = textutils.unserialize(data)
  281.         for key,value in pairs(data) do
  282.             if tostring(key) == "name" then
  283.               mon.setCursorPos(monX/2-string.len(tostring(value))/2, i)
  284.               mon.write(tostring(value))
  285.             end
  286.         end
  287.       else
  288.         mon.setCursorPos(monX/2-5, i)
  289.         mon.write("Set Bookmark")
  290.       end
  291.     end
  292.     event, param1, param2, param3 = os.pullEvent("monitor_touch")
  293.     if param2 > monX-3 then
  294.       fs.delete(tostring(param3))
  295.     elseif fs.exists(tostring(param3)) then
  296.       file = fs.open(tostring(param3), "r")
  297.       info = file.readAll()
  298.       file.close()
  299.       info = textutils.unserialize(info)
  300.       for key, value in pairs(info) do
  301.         if key == "x" then
  302.           setX = value
  303.         elseif key == "y" then
  304.           setY = value
  305.         elseif key == "z" then
  306.           setZ = value
  307.         end
  308.       update = true
  309.       end
  310.       mon.clear()
  311.     else
  312.       mon.setBackgroundColor(colors.black)
  313.       mon.setTextColor(colors.green)
  314.       mon.clear()
  315.       mon.setCursorPos(monX/2-15, monY/2)
  316.       mon.write("Follow Prompts On The Computer Bellow")
  317.       term.clear()
  318.       term.setCursorPos(1,1)
  319.       write("Set the name for bookmark: ")
  320.       name = read()
  321.       term.clear()
  322.       term.setCursorPos(1,1)
  323.       write("Set the X coordinate: ")
  324.       wpX = read()term.clear()
  325.       term.setCursorPos(1,1)
  326.       write("Set the Y coordinate: ")
  327.       wpY = read()term.clear()
  328.       term.setCursorPos(1,1)
  329.       write("Set the Z coordinate: ")
  330.       wpZ = read()
  331.       term.clear()
  332.       term.setCursorPos(1,1)
  333.       write("Done!")
  334.       table = {name = name, x = wpX, y = wpY, z = wpZ}
  335.       table = textutils.serialize(table)
  336.       for i = 1, monY do
  337.         if fs.exists(tostring(i)) == false then
  338.           file = fs.open(tostring(i), "w")
  339.           file.write(table)
  340.           file.close()
  341.           break
  342.         end
  343.       end
  344.     end
  345.     display()
  346.   end
  347. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement