Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Laser-Guided Warp System (“ztc”) with H/I/O prompts and O-key to run otc
- -- 1) Wrap terminal + any attached monitors
- local screens = {}
- -- Terminal wrapper
- table.insert(screens, {
- clear = function() term.clear(); term.setCursorPos(1,1) end,
- getSize = function() return term.getSize() end,
- setTextColor = term.setTextColor,
- setBackgroundColor = term.setBackgroundColor,
- setCursorPos = term.setCursorPos,
- write = term.write,
- })
- -- Monitor wrappers
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "monitor" then
- local m = peripheral.wrap(side)
- table.insert(screens, {
- clear = function() m.clear(); m.setCursorPos(1,1) end,
- getSize = function() return m.getSize() end,
- setTextColor = function(c) m.setTextColor(c) end,
- setBackgroundColor = function(c) m.setBackgroundColor(c) end,
- setCursorPos = function(x,y) m.setCursorPos(x,y) end,
- write = function(txt) m.write(txt) end,
- monitor = m,
- })
- end
- end
- -- 2) Auto-scale monitors so at least 7 lines will fit
- for _, s in ipairs(screens) do
- if s.monitor then
- local best = 0.5
- for _, scale in ipairs({1, 0.5}) do
- s.monitor.setTextScale(scale)
- local w,h = s.getSize()
- if w >= 40 and h >= 7 then
- best = scale
- break
- end
- end
- s.monitor.setTextScale(best)
- end
- end
- -- 3) Helpers
- local function forAll(fn) for _,s in ipairs(screens) do fn(s) end end
- -- Clear every screen to lightGray
- local function clearAll()
- forAll(function(s)
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.clear()
- end)
- end
- -- 4) Static texts
- local titleText = "Horizontal Mining System"
- local subtitleText = "Emit Scanning Laser to Mine Target"
- local offsetText = "Guided Mining System ( I ): "
- local promptH = "Press H for Main Menu"
- local promptI = "Press J to Switch to Laser Guided Jump"
- local promptO = "Press T to Toggle Miner"
- -- track offset state
- local isOffsetOn = false
- -- Draw title, subtitle, and offset-state line (now on line 5)
- local function drawStatic()
- forAll(function(s)
- local w,_ = s.getSize()
- -- Title (line 1): white on black
- local xT = math.floor((w - #titleText)/2) + 1
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.black)
- s.setCursorPos(xT,1)
- s.write(titleText)
- -- Subtitle (line 3): black on lightGray
- local xS = math.floor((w - #subtitleText)/2) + 1
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(xS,3)
- s.write(subtitleText)
- -- (line 4 is intentionally left blank)
- -- Mining Laser Offset (line 5)
- local statusText = isOffsetOn and "ON" or "OFF"
- local fullOffset = offsetText .. statusText
- local xO = math.floor((w - #fullOffset)/2) + 1
- -- background bar
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(1,5)
- s.write(string.rep(" ", w))
- -- label
- s.setCursorPos(xO,5)
- s.write(offsetText)
- -- ON vs OFF coloring
- s.setTextColor(colors.white)
- s.setBackgroundColor(isOffsetOn and colors.lime or colors.red)
- s.write(statusText)
- end)
- end
- -- Draw prompts on the bottom three rows
- local function drawPrompt()
- forAll(function(s)
- local w,h = s.getSize()
- -- line h-2: O prompt
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.blue)
- s.setCursorPos(1,h-2)
- s.write(string.rep(" ", w))
- local xO = math.floor((w - #promptO)/2) + 1
- s.setCursorPos(xO,h-2)
- s.write(promptO)
- -- line h-1: H prompt
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.blue)
- s.setCursorPos(1,h-1)
- s.write(string.rep(" ", w))
- local xH = math.floor((w - #promptH)/2) + 1
- s.setCursorPos(xH,h-1)
- s.write(promptH)
- -- line h: I prompt
- s.setBackgroundColor(colors.blue)
- s.setCursorPos(1,h)
- s.write(string.rep(" ", w))
- local xI = math.floor((w - #promptI)/2) + 1
- s.setCursorPos(xI,h)
- s.write(promptI)
- end)
- end
- -- 5) Set up all modems for rednet, then broadcast a startup check
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "modem" then
- rednet.open(side)
- end
- end
- rednet.broadcast("check", "SMiner")
- -- now set up warpdriveLaserCamera peripherals
- local cams = peripheral.getNames()
- for i=#cams,1,-1 do
- if peripheral.getType(cams[i]) ~= "warpdriveLaserCamera" then
- table.remove(cams,i)
- else
- peripheral.wrap(cams[i]).beamFrequency(1420)
- end
- end
- -- 6) Initial draw (blank coords)
- clearAll()
- drawStatic()
- drawPrompt()
- -- 7) Coords line, accepts nil → blanks before first scan (on line 6)
- local function updateCoords(x,y,z)
- local sx = x and tostring(x) or " "
- local sy = y and tostring(y) or " "
- local sz = z and tostring(z) or " "
- local coordLine = string.format("Target: X:%s Y:%s Z:%s", sx, sy, sz)
- forAll(function(s)
- local w,_ = s.getSize()
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(1,6)
- s.write(string.rep(" ", w))
- local cx = math.floor((w - #coordLine)/2) + 1
- s.setCursorPos(cx,6)
- s.write(coordLine)
- end)
- end
- -- draw initial blanks (on line 6)
- updateCoords(nil,nil,nil)
- -- keep last coords around for redraws
- local lastX, lastY, lastZ = nil, nil, nil
- -- 8) Main loop: scan + key handling + status listener
- while true do
- -- 8a) non-blocking check for SMiner status messages
- local sender, msg, proto = rednet.receive("SMiner", 0)
- if msg == "StatON" then
- isOffsetOn = true
- clearAll(); drawStatic(); updateCoords(lastX,lastY,lastZ); drawPrompt()
- elseif msg == "StatOFF" then
- isOffsetOn = false
- clearAll(); drawStatic(); updateCoords(lastX,lastY,lastZ); drawPrompt()
- end
- -- 8b) main events
- local ev,k,b,c,d = os.pullEventRaw()
- if ev == "laserScanning" then
- lastX = tonumber(b)
- lastY = tonumber(c)
- lastZ = tonumber(d)
- updateCoords(lastX,lastY,lastZ)
- rednet.broadcast({ x = lastX, y = lastY, z = lastZ }, "SMineBroadcast")
- elseif ev == "key" then
- if k == keys.h then
- os.reboot()
- elseif k == keys.j then
- shell.run("otc")
- clearAll(); drawStatic(); updateCoords(tx,ty,tz); drawPrompt()
- elseif k == keys.t then
- rednet.broadcast("Toggle","SMiner")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment