Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = peripheral.wrap("top")
- distributor = 3
- rednet.open("right")
- home = {}
- bayArm = {}
- warning = {}
- bay = {}
- bay[1] = {}
- bay[2] = {}
- bay[3] = {}
- bay[1][1] = 12
- bay[1][2] = 13
- bay[2][1] = 11
- bay[2][2] = 10
- bay[3][1] = 8
- bay[3][2] = 9
- function cText(text,centering)
- x,y = mon.getCursorPos()
- x2,y2 = mon.getSize()
- newX = math.ceil((x2*centering) - (text:len() / 2))
- newY = y2
- mon.setCursorPos(newX, newY)
- mon.write(text)
- end
- function advancedText(screen,text,yVal,height,cent,tColor,bColor,b2Color,func,a1,a2,a3)
- x,y = mon.getCursorPos()
- x2,y2 = mon.getSize()
- newX = math.ceil((x2*cent) - (text:len() / 2))
- newY = yVal
- mon.setCursorPos(newX,newY)
- curTableSize = table.getn(screen)
- writeNum = curTableSize + 1
- --print(writeNum)
- --print(text)
- screen[writeNum] = {}
- screen[writeNum]["text"] = text
- screen[writeNum]["x"] = newX
- screen[writeNum]["y"] = newY
- screen[writeNum]["x2"] = newX + text:len()
- screen[writeNum]["y2"] = newY + (height - 1)
- screen[writeNum]["color"] = tColor
- if bColor ~= nil then
- screen[writeNum]["bg1"] = bColor
- else
- screen[writeNum]["bg1"] = colors.black
- end
- if b2Color ~= nil then
- screen[writeNum]["bg2"] = b2Color
- else
- screen[writeNum]["bg2"] = bColor
- end
- screen[writeNum]["function"] = func
- screen[writeNum]["arg1"] = a1
- screen[writeNum]["arg2"] = a2
- screen[writeNum]["arg3"] = a3
- screen[writeNum]["curBG"] = bColor
- end
- function displayScreen(screen, bgColor)
- home = {}
- bayArm = {}
- curScreen = {}
- curScreen = screen
- mon.setBackgroundColor(bgColor)
- mon.clear()
- for k, v in ipairs(screen) do
- mon.setCursorPos(screen[k].x, screen[k].y)
- boxHeight = (screen[k].y2 + 1) - screen[k].y
- textLine = math.ceil(boxHeight/2)
- mon.setTextColor(screen[k].color)
- mon.setBackgroundColor(screen[k].curBG)
- for i = 1, boxHeight do
- curX,curY = mon.getCursorPos()
- if i == textLine then
- mon.write(screen[k].text)
- else
- for q = 1, screen[k].text:len() do
- mon.write(" ")
- end
- end
- mon.setCursorPos(screen[k].x,curY+1)
- end
- end
- curScreen = screen
- getTouch(curScreen)
- end
- function getTouch(screen)
- print("waiting on touch")
- event, monSide, xPos, yPos = os.pullEvent("monitor_touch")
- print("I WAS TOUCHED")
- for k,v in ipairs(screen) do
- if xPos >= screen[k].x and xPos <= screen[k].x2 and yPos >= screen[k].y and yPos <= screen[k].y2 then
- print(screen[k].text.." was touched")
- if screen[k]["function"] ~= nil then
- --print("Gonna be running: "..screen[k]["function"])
- if screen[k].arg1 ~= nil then
- if screen[k].arg2 ~= nil then
- if screen[k].arg3 ~= nil then
- print("Running 3 arg func")
- screen[k]["function"](screen[k].arg1,screen[k].arg2,screen[k].arg3)
- else
- print("Running 2 arg func")
- screen[k]["function"](screen[k].arg1,screen[k].arg2)
- end
- else
- print("Running 1 arg func")
- screen[k]["function"](screen[k].arg1)
- end
- else
- print("Running no arg func")
- screen[k]["function"]()
- end
- end
- end
- end
- displayScreen(curScreen, colors.black)
- end
- function getMissiles()
- rednet.send(distributor, "list")
- id,mes,dis = rednet.receive()
- if id == distributor then
- missileTable = mes
- myMissiles = {}
- for k,v in ipairs(missileTable) do
- writeValue = true
- curTableVal = table.getn(myMissiles)
- if curTableVal ~= 0 then
- print("checking duplicates for: "..v)
- writeValue = true
- for j,q in ipairs(myMissiles) do
- if v == q then
- print("found duplicate")
- writeValue = false
- end
- end
- if writeValue then
- curTableVal = table.getn(myMissiles)
- myMissiles[curTableVal + 1] = v
- end
- else
- print("Adding first missile")
- myMissiles[1] = v
- end
- end
- --for k,v in ipairs(myMissiles) do
- --print(k..": "..v)
- --end
- return myMissiles
- end
- end
- function getBays()
- loadedBay = {}
- loadedBay[1] = {}
- loadedBay[2] = {}
- loadedBay[3] = {}
- for k,v in ipairs(bay) do
- for l,q in ipairs(v) do
- rednet.send(q,"report")
- id, mes, dis = rednet.receive()
- if id == q then
- --print("K: "..k)
- --print("L: "..l)
- if mes == "EMPTY" then
- loadedBay[k][l] = "UNARMED"
- else
- loadedBay[k][l] = mes
- end
- end
- end
- end
- --for k,v in ipairs(loadedBay) do
- --for l,q in ipairs(v) do
- --print(l..": "..q)
- -- end
- --end
- return loadedBay
- end
- function armBay(bNum,lNum)
- print("arming bay")
- bayArm = {}
- availMissiles = getMissiles()
- mon.clear()
- mon.setCursorPos(1,1)
- mon.write("Loading...")
- bayNum = tonumber(bNum)
- launchNum = tonumber(lNum)
- advancedText(bayArm," Bay: "..bayNum.." Launcher: "..launchNum.." ",1,3,1/2,colors.white,colors.orange,colors.orange)
- rowNum = 5
- colNum = 1
- for k,v in ipairs(availMissiles) do
- --print(v.name)
- for token in string.gmatch(v,"[^%s]+") do
- if token ~= "Missile" then
- curText = token
- end
- end
- advancedText(bayArm,curText,rowNum,1,(colNum/5),colors.white,colors.blue,colors.blue,sendMissile,curText,bayNum,launchNum)
- if colNum == 4 then
- rowNum = rowNum + 2
- colNum = 1
- else
- colNum = colNum + 1
- end
- end
- displayScreen(bayArm,colors.black)
- end
- function sendMissile(name,bay,comp)
- local mesTable = {}
- mesTable[1] = name
- mesTable[2] = bay
- mesTable[3] = comp
- rednet.send(distributor,mesTable)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- mon.write("Loading...")
- sleep(7.25)
- mainMenu()
- end
- function disarmMessage(bayNum,comp)
- rednet.send(bay[bayNum][comp],"disarm")
- sleep(.5)
- mainMenu()
- end
- function launchMessage(bayNum,comp)
- rednet.send(bay[bayNum][comp],"launch")
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- cText("Launching",1/2)
- sleep(5)
- mainMenu()
- end
- function launchAll()
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- cText("Fucking shit up...",1/2)
- for k,v in ipairs(bay) do
- rednet.send(bay[k][1], "launch")
- rednet.send(bay[k][2], "launch")
- end
- sleep(10)
- mainMenu()
- end
- function mainMenu()
- --armedMissiles = getMissiles()
- print("Checking armed bays")
- armedBays = getBays()
- print("Bays checked")
- advancedText(home," Missile Controller V1 ",1,3,1/2,colors.white,colors.red,colors.red)
- numBays = table.getn(bay)
- launchNum = 1
- for k,v in ipairs(armedBays) do
- advancedText(home," Bay: "..k.." ",5,1,k/(numBays+1),colors.black,colors.orange,colors.orange)
- advancedText(home,"Launcher "..launchNum,7,1,k/(numBays+1),colors.white,colors.blue,colors.red)
- advancedText(home,"Launch All",1,1,7/8,colors.white,colors.magenta,colors.magenta,launchAll)
- if v[1] ~= "UNARMED" then
- for token in string.gmatch(v[1], "[^%s]+") do
- if token ~= "Missile" then
- curText = token
- end
- end
- advancedText(home,curText,8,1,k/(numBays+1),colors.black,colors.green,colors.green)
- advancedText(home," Launch ",10,1,k/(numBays+1),colors.black,colors.red,colors.red,launchMessage,k,launchNum)
- advancedText(home," Disarm ",12,1,k/(numBays+1),colors.red,colors.lightGray,colors.lightGray,disarmMessage,k,launchNum)
- else
- advancedText(home," UNARMED ",8,1,k/(numBays+1),colors.black,colors.red,colors.red)
- advancedText(home," Arm ",10,1,k/(numBays+1),colors.red,colors.lightGray,colors.lightGray,armBay,k,launchNum)
- end
- launchNum = launchNum + 1
- advancedText(home,"Launcher "..launchNum,14,1,k/(numBays+1),colors.white,colors.blue,colors.red)
- if v[2] ~= "UNARMED" then
- for token in string.gmatch(v[2], "[^%s]+") do
- if token ~= "Missile" then
- curText = token
- end
- end
- advancedText(home,curText,15,1,k/(numBays+1),colors.black,colors.green,colors.green)
- advancedText(home," Launch ",17,1,k/(numBays+1),colors.black,colors.red,colors.red,launchMessage,k,launchNum)
- advancedText(home," Disarm ",19,1,k/(numBays+1),colors.red,colors.lightGray,colors.lightGray,disarmMessage,k,launchNum)
- else
- advancedText(home," UNARMED ",15,1,k/(numBays+1),colors.black,colors.red,colors.red)
- advancedText(home," Arm ",17,1,k/(numBays+1),colors.red,colors.lightGray,colors.lightGray,armBay,k,launchNum)
- end
- if launchNum == 1 then
- launchNum = launchNum + 1
- else
- launchNum = 1
- end
- end
- displayScreen(home,colors.black)
- end
- --armBay(1,1)
- mainMenu()
- --advancedText(home," Missile Bays ",1,3,1/2,colors.black,colors.red,colors.red)
- --displayScreen(home,colors.black)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement