Advertisement
Fredyman_95

Develop of JPB

Sep 23rd, 2022 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 39.96 KB | None | 0 0
  1. --[[
  2. Just Press Button Program
  3. v5.8.3.12
  4.  
  5. Created By: Fredyman_95
  6. Special Thanks To: Augur ShicKla
  7. ]]--
  8. -- User settings ----------------------------------------------------
  9.  ---- General Settings
  10.   infoTime = 3             -- min: 1, Period for infoScreen
  11.   ringsTheme = 0            -- 0 = Goauld, 1 = Ori, 2 = Ancients
  12.   rsSignal = east           -- Choose one of: east, west, south, north, top, bottom
  13.  
  14.  ---- Stargate General Settings
  15.   fastDial = true           -- Use DHD to dial
  16.   forceDial = false         -- Gate will dial even when invalid Address
  17.   gateAutoClose = false     -- Gate will automatically close after time chosen by player
  18.   minOpenTime = 10          -- Minimal time to keep gate open in seconds
  19.   maxOpenTime = 30          -- Period in s how long to keep gate open
  20.  
  21.  ---- Rings General Settings
  22.   pauseBetweenDials = 3     -- Period in s between program restart after rings finish transport
  23.  
  24.  ---- Iris Settings -------------------------------------------------
  25.   irisAutoClose = true      -- Close Iris with incoming wormhole
  26.   thisIDC = 55             -- Replace nil with YOUR gate IDC e.g 1234 -> IDC = 1234
  27.  
  28.  ---- IDC send Settings ---------------------------------------------
  29.   sendIDC = true            -- Dialing program send IDC after stargate establish connection
  30.   IDC = 1234                 -- Replace nil with IDC of DIALED gate e.g 1234 -> IDC = 1234
  31.  
  32.  ---- Stargate address - fill without PoO ---------------------------
  33.   stargateAddressMW = {"Microscopium", "Leo", "Lynx", "Norma", "Eridanus", "Centaurus", "Perseus"}   -- {"Serpens caput", "Leo", ... "Perseus"}
  34.   --stargateAddressMW = {"Canis Minor", "Lynx", "Sextans", "Microscopium", "Virgo", "Serpens Caput"}
  35.   stargateAddressPG = {"Illume", "Olavii", "Ecrumig", "Abrin", "Ramnon", "Sibbron"}   -- {"Illume", "Poco re", ... "Sibbron"}
  36.   stargateAddressUNI = {"G23", "G32", "G11", "G1", "G31", "G34", "G20", "G13"}   -- {"G1", "G2", ... "G8"}
  37.  
  38.  ---- Rings address -------------------------------------------------
  39.   ringsAddressGoauld = {"Amun", "Khepri", "Serket", "Felluca"}   -- {"Amun", "Khepri", ... "Felluca"}
  40.   ringsAddressOri = {}        -- Just Stargate Mod -> WIP
  41.   ringsAddressAncients = {}   -- Just Stargate Mod -> WIP
  42.  
  43. -- End of User settings----------------------------------------------
  44.  
  45. -- Declarations -----------------------------------------------------
  46.  local component = require("component")
  47.  local computer = require("computer")
  48.  local event = require("event")
  49.  local sides = require("sides")
  50.  local term = require("term")
  51.  local unicode = require("unicode")
  52.  local gpu = component.gpu
  53.  local screen = component.screen
  54.  local brokenBroadcastIDC = false
  55.  local brokenLocalIDC = false
  56.  local dial = false
  57.  local dialingFailed = false
  58.  local energyCancel = false
  59.  local errorBypass = false
  60.  local fatalError = false
  61.  local forceStop = false
  62.  local intruderDetector = false
  63.  local loop = false
  64.  local mainRSLoop = false
  65.  local offWorldActivation = false
  66.  local ringsFailed = false
  67.  local rsLockDialed = false
  68.  local standBy = false
  69.  local walterMes = false
  70.  local wasOpened = false
  71.  local wasPressed = false
  72.  local disconnected = false
  73.  local activeErrors = 0
  74.  local changelogTimer = 2
  75.  local colorBlue = 0x0092FF
  76.  local colorDefault = 0xFFFFFF
  77.  local colorGold = 0xFFDB00
  78.  local colorGray = 0x969696
  79.  local colorLightBlue = 0x00DBFF
  80.  local colorLightGray = 0xB4B4B4
  81.  local colorRed = 0xFF2100
  82.  local resultMessages = {
  83.    OK = "OK",
  84.    ACTIVATED = "Transport Rings Are Activated",
  85.    BUSY = "Local Transport Rings platform is Busy",
  86.    BUSY_TARGET = "Target Transport Rings platform is Busy",
  87.    OBSTRUCTED = "Local Transport Rings platform is Obstructed",
  88.    OBSTRUCTED_TARGET = "Target Transport Rings platform is Obstructed",
  89.    NOT_ENOUGH_POWER = "Not Enough Energy to Activate Transport Rings",
  90.    NO_SUCH_ADDRESS = "No Transport Ring Platform Detected on Provided Address"}
  91.  local changelog = [[ Changelog:
  92.  
  93.   - Removed autorestart when program wasn't closed properely
  94.  - Edited Events and events system
  95.  - Edited stargate check system
  96.  - Edited Error system and system messages
  97.  - Added new functions for Transport Rings
  98.  - Edited GUI + created new GUI elements
  99.  - Edited Iris/Shield functions
  100.  - Gate can be closed by reach time limit - with countdown]]
  101. local instructions = [[ Instructions:
  102.  
  103. 1. Edit and check out all settings in User settings
  104.    Lines 9 - 36
  105.    Default command: edit JPB
  106.  
  107. 2. Press CTRL + C or restart the computer to exit the program
  108.    properly
  109.  
  110. 3. Setup your RedstoneIO and connect to selected side BUTTON!
  111.    !!NO LEVER!! lever will cause instant repeat of program loop.
  112.  
  113. 4. You can reduce the time for which this message is displayed in
  114.    the User Settings - line 19]]
  115. local subLogo = ""
  116. local subColor = ""
  117. local posX = ""
  118. local dialed = ""
  119. local encodedChevron = ""
  120. local symbol = ""
  121. local lastSymbol = ""
  122. local rsInput = ""
  123. local ringType = ""
  124. local AunisVersion = ""
  125. local PoO = {}
  126. local stargateAddress = {}
  127. local ringsAddress = {}
  128. local errorsLog = {}
  129. local ActiveButtons = {}
  130. local buttons = {}
  131. -- End of Declarations ----------------------------------------------
  132.  
  133. -- HARD TO CODE => HARD TO READ!!!
  134.  
  135. -- Check of user Settings -------------------------------------------
  136.    if type(fastDial) ~= "boolean" then fastDial = false end
  137.    if type(irisAutoClose) ~= "boolean" then irisAutoClose = false end
  138.    if type(sendIDC) ~= "boolean" then sendIDC = false end
  139.    if type(gateAutoClose) ~= "boolean" then gateAutoClose = false end
  140.    if type(forceDial) ~= "boolean" then forceDial = false end
  141.    if type(minOpenTime) ~= "number" then minOpenTime = 10 end
  142.    if type(maxOpenTime) ~= "number" then maxOpenTime = 2280 end
  143.    if type(pauseBetweenDials) ~= "number" then pauseBetweenDials = 3 end
  144.    if type(infoTime) ~= "number" then infoTime = 10 end
  145.    if type(ringsTheme) ~= "number" then ringsTheme = 0 end
  146.    if minOpenTime < 1 then minOpenTime = 5 elseif minOpenTime > maxOpenTime then minOpenTime = 5 end
  147.    if maxOpenTime < minOpenTime then maxOpenTime = 2280 end
  148.    if pauseBetweenDials < 2 then pauseBetweenDials = 3 end
  149.    if infoTime < 0 then infoTime = 10 end
  150.    if ringsTheme <= 0 then ringsTheme = 0 elseif ringsTheme > 3 then ringsTheme = 0 end
  151.    if type(thisIDC) == "number" and thisIDC >= 0 and thisIDC < 1e9 then os.sleep() else activeErrors = activeErrors + 1 table.insert(errorsLog, "Your IDC is Invalid") brokenLocalIDC = true end
  152.    if type(IDC) == "number" and IDC >= 0 and IDC < 1e9 then os.sleep() else activeErrors = activeErrors + 1 table.insert(errorsLog, "IDC for broadcast is Invalid") brokenBroadcastIDC = true end
  153.    if rsSignal == east then rsInput = sides.east elseif rsSignal == west then rsInput = sides.west elseif rsSignal == north then rsInput = sides.north elseif rsSignal == south then rsInput = sides.south elseif rsSignal == top then rsInput = sides.top elseif rsSignal == bottom then rsInput = sides.bottom end
  154.  
  155. -- End of Check of user Settings ------------------------------------
  156.  
  157. -- Components and system requirements check -------------------------
  158.    if gpu.maxResolution() < 81 then
  159.        activeErrors = activeErrors + 1
  160.        fatalError = true
  161.        table.insert(errorsLog, "Tier 3 GPU and Screen Required")
  162.    end
  163.  
  164.    if component.isAvailable("transportrings") then
  165.        rings = component.transportrings
  166.        errorBypass = true
  167.        NumberOfRings = 0
  168.        for k,v in component.list() do if v == "transportrings" then NumberOfRings = NumberOfRings + 1 end end
  169.        if NumberOfRings > 1 then
  170.            activeErrors = activeErrors + 1
  171.            fatalError = true
  172.            table.insert(errorsLog, "Too Many Transport Rings Connected to Computer.")
  173.        end
  174.    end
  175.  
  176.    if component.isAvailable("stargate") then
  177.        stargate = component.stargate
  178.        NumberOfGates = 0
  179.        for k,v in component.list() do if v == "stargate" then NumberOfGates = NumberOfGates + 1 end end
  180.        if NumberOfGates > 1 then
  181.            activeErrors = activeErrors + 1
  182.            fatalError = true
  183.            table.insert(errorsLog, "Too Many Stargates Connected to Computer.")
  184.        end
  185.        if stargate.getGateType() ~= "MILKYWAY" then fastDial = false else errorBypass = false end
  186.    end
  187.  
  188.    if component.isAvailable("dhd") then
  189.        dhd = component.dhd
  190.        if errorBypass == false then
  191.            NumberOfDHDs = 0
  192.            for k,v in component.list() do if v == "dhd" then NumberOfDHDs = NumberOfDHDs + 1 end end
  193.            if NumberOfDHDs > 1 then
  194.                activeErrors = activeErrors + 1
  195.                fatalError = true
  196.                table.insert(errorsLog, "Too Many DHD Connected to Computer.")
  197.            end
  198.        end
  199.    else
  200.        if errorBypass == false and fastDial then
  201.            activeErrors = activeErrors + 1
  202.            table.insert(errorsLog, "No DHD Connected, Turning off DHD dial")
  203.            fastDial = false
  204.        end
  205.    end
  206.  
  207.    if component.isAvailable("redstone") then
  208.        rs = component.redstone
  209.        NumberOfRsIOs = 0
  210.        for k,v in component.list() do if v == "redstone" then NumberOfRsIOs = NumberOfRsIOs + 1 end end
  211.        if NumberOfRsIOs > 1 then
  212.            activeErrors = activeErrors + 1
  213.            fatalError = true
  214.            table.insert(errorsLog, "Too Many Redstone Components Connected to Computer (RedstoneIO, Redstone Card)")
  215.        end
  216.    else
  217.        activeErrors = activeErrors + 1
  218.        fatalError = true
  219.        table.insert(errorsLog, "No Redstone Component Installed (RedstoneIO or Redstone Card.")
  220.    end
  221.  
  222.    if component.isAvailable("transportrings") and component.isAvailable("stargate") then
  223.        activeErrors = activeErrors + 1
  224.        fatalError = true
  225.        table.insert(errorsLog, "Multiple types of transport devices detected!")
  226.    end
  227.  
  228.    if not component.isAvailable("transportrings") and not component.isAvailable("stargate") then
  229.        activeErrors = activeErrors + 1
  230.        fatalError = true
  231.        table.insert(errorsLog, "No Transport Rings or Stargate Connected.")
  232.    end
  233.  
  234.    if activeErrors > 0 then
  235.        term.clear()
  236.        if activeErrors >= 2 then print("Multiple Errors Detected:") else print("Error Detected:") end
  237.        print()
  238.        gpu.setForeground(0xFF0000)
  239.        for i, v in ipairs(errorsLog) do
  240.            print("Error #" .. i .. " " .. v)
  241.            computer.beep()
  242.            os.sleep(0.2)
  243.        end
  244.        for i, v in ipairs(errorsLog) do
  245.            table.remove(errorsLog, i)
  246.        end
  247.        gpu.setForeground(0xFFFFFF)
  248.        os.sleep(2)
  249.        if fatalError then os.exit(1) end
  250.    end
  251.  
  252. -- End of Components and system requirements check ------------------
  253.  
  254. -- Button Objects ---------------------------------------------------
  255.    local Button = {}
  256.    Button.__index = Button
  257.    function Button.new(xPos, yPos, width, height, label, func, border)
  258.        local self = setmetatable({}, Button)
  259.        if xPos < 1 or xPos > term.window.width then xPos = 1 end
  260.        if yPos < 1 or yPos > term.window.height then yPos = 1 end
  261.        if (width-2) < unicode.len(label) then width = unicode.len(label)+2 end
  262.        if height < 3 then height = 3 end
  263.        if border == nil then
  264.            self.border = true
  265.        else
  266.            self.border = border
  267.        end
  268.        self.xPos = xPos
  269.        self.yPos = yPos
  270.        self.width = width
  271.        self.height = height
  272.        self.label = label
  273.        self.func = func
  274.        self.visible = false
  275.        self.disabled = false
  276.        return self
  277.    end
  278.  
  279.    function Button.display(self, x, y)
  280.        table.insert(ActiveButtons, 1, self)
  281.        if (self.width-2) < unicode.len(self.label) then self.width = unicode.len(self.label)+2 end
  282.        if x ~= nil and y ~= nil then
  283.            self.xPos = x
  284.            self.yPos = y
  285.        end
  286.        if self.border then
  287.            gpu.fill(self.xPos+1, self.yPos, self.width-2, 1, "─")
  288.            gpu.fill(self.xPos+1, self.yPos+self.height-1, self.width-2, 1, "─")
  289.            gpu.fill(self.xPos, self.yPos+1, 1, self.height-2, "│")
  290.            gpu.fill(self.xPos+self.width-1, self.yPos+1, 1, self.height-2, "│")
  291.            gpu.set(self.xPos, self.yPos, "┌")
  292.            gpu.set(self.xPos+self.width-1, self.yPos, "┐")
  293.            gpu.set(self.xPos, self.yPos+self.height-1, "└")
  294.            gpu.set(self.xPos+self.width-1, self.yPos+self.height-1, "┘")
  295.          end
  296.        gpu.set(self.xPos+1, self.yPos+1, self.label)
  297.        self.visible = true
  298.    end
  299.  
  300.    function Button.hide(self)
  301.        self.visible = false
  302.        for i,v in ipairs(ActiveButtons) do
  303.            if v == self then table.remove(ActiveButtons, i) end
  304.        end
  305.        if self.border then
  306.            gpu.fill(self.xPos, self.yPos, self.width, self.height, " ")
  307.        else
  308.            gpu.fill(self.xPos+1, self.yPos+1, self.width-2, 1, " ")
  309.        end
  310.    end
  311.  
  312.    function Button.disable(self, bool)
  313.        if bool == nil then
  314.            self.disabled = false
  315.        else
  316.            self.disabled = bool
  317.          end
  318.        if self.disabled then gpu.setForeground(0x0F0F0F) end
  319.        if self.visible then self:display() end
  320.        gpu.setForeground(0xFFFFFF)
  321.    end
  322.  
  323.    function Button.touch(self, x, y)
  324.        local wasTouched = false
  325.        if self.visible and not self.disabled then  
  326.            if self.border then
  327.                if x >= self.xPos and x <= (self.xPos+self.width-1) and y >= self.yPos and y <= (self.yPos+self.height-1) then wasTouched = true end
  328.            else
  329.                if x >= self.xPos+1 and x <= (self.xPos+self.width-2) and y >= self.yPos+1 and y <= (self.yPos+self.height-2) then wasTouched = true end
  330.            end
  331.        end
  332.        if wasTouched then
  333.            gpu.setBackground(0x878787)
  334.            gpu.set(self.xPos+1, self.yPos+1, self.label)
  335.            gpu.setBackground(0x000000)
  336.            if self.visible then gpu.set(self.xPos+1, self.yPos+1, self.label) end
  337.            self.func()
  338.        end
  339.        return wasTouched
  340.    end
  341.  
  342.    function Button.forceTouch(self)
  343.        self:touch(self.xPos+1, self.yPos+1)
  344.    end
  345.  
  346. -- End of Button Objects --------------------------------------------
  347.  
  348. -- Common Events ----------------------------------------------------
  349.  
  350.    eventInterrupted = event.listen("interrupted", function()
  351.        forceStop = true
  352.    end)
  353.  
  354.    eventTouch = event.listen("touch", function(_, screenAddress, x, y, button, playerName)
  355.        local success, msg = xpcall(function()
  356.          if button == 0 then
  357.            for i,v in ipairs(ActiveButtons) do
  358.              if v:touch(x,y) then break end
  359.            end
  360.          end
  361.        end)
  362.      end)
  363.    -- eventy na tlačitka
  364.  
  365. -- End of Common Events --------------------------------------------
  366.  
  367. -- Buttons ----------------------------------------------------------
  368.    buttons = {
  369.    toggleIrisButton = Button.new(44, 26, 13, 3, "Toogle Iris", function()
  370.            stargate.toggleIris()
  371.            if intruderDetector then intruderDetector = false end
  372.    end),
  373.  
  374.    toggleShieldButton = Button.new(42, 26, 15, 3, "Toogle Shield", function()
  375.        stargate.toggleIris()
  376.        if intruderDetector then intruderDetector = false end
  377.    end),
  378.  
  379.    mainButton = Button.new(4, 10, 96, 3, " ", function()
  380.        wasPressed = true
  381.    end),
  382.  
  383.    abortButton = Button.new(58, 26, 15, 3, "Abort Dialing", function()
  384.        stargate.abortDialing()
  385.        dial = false
  386.    end),}
  387.  
  388. -- End of Buttons ---------------------------------------------------
  389.  
  390. -- Functions --------------------------------------------------------
  391.  
  392. ---- Common functions ----------------------------------------------
  393.    local function checkThisTableContent(subject, minLenght, maxLenght, shortError, longError)
  394.        gpu.setForeground(0xFF0000)
  395.        for i, v in ipairs(subject) do testedValue = i end
  396.            if testedValue <= minLenght then print(shortError)
  397.            elseif testedValue > maxLenght then print(longError)
  398.        end
  399.        gpu.setForeground(0xFFFFFF)
  400.    end
  401.  
  402.    local function errorMessagenger(errorMessage)
  403.        gpu.setForeground(0xFF0000)
  404.        print(errorMessage)
  405.        computer.beep()
  406.        gpu.setForeground(0xFFFFFF)
  407.    end
  408.  
  409.    local function timer(seconds)
  410.        seconds = seconds * 10
  411.        for i = 0 , seconds do
  412.            if forceStop then break end
  413.            os.sleep(0.1)
  414.        end
  415.    end
  416.  
  417.    local function gateTimer(countdown)
  418.        local countdown = tonumber(countdown)
  419.        if countdown <= 0 then
  420.            return "00:00"
  421.        else
  422.            hours = string.format("%02.f", math.floor(countdown/3600))
  423.            mins = string.format("%02.f", math.floor(countdown/60 - (hours*60)))
  424.            secs = string.format("%02.f", math.floor(countdown - hours*3600 - mins *60))
  425.        end
  426.    end
  427.  
  428.    local function hideAllButtons()
  429.        buttons.toggleIrisButton:hide()
  430.        buttons.toggleShieldButton:hide()
  431.        buttons.mainButton:hide()
  432.        buttons.abortButton:hide()
  433.        buttons.toggleIrisButton:disable(true)
  434.        buttons.toggleShieldButton:disable(true)
  435.        buttons.mainButton:disable(true)
  436.        buttons.abortButton:disable(true)
  437.    end
  438.  
  439.    ---- End of Common functions ---------------------------------------
  440.  
  441. ---- Main Screen functions -----------------------------------------
  442.  
  443.    logo = [[⢸⠀⡇⠀⢸⠀⡎⠉⠱⠀⠉⢹⠉⠁ ⠀⢸⠉⠉⡆⢸⠉⠉⡆⢸⠉⠉⠀⡎⠉⠱⠀⡎⠉⠱   ⡏⠉⡆⠀⡇⠀⢸⠀⠉⢹⠉⠁⠈⠉⡏⠉⠀⡎⠉⢱⠀⡷⡄⢸
  444.    ⡆⠀⢸⠀⡇⠀⢸⠀⡌⠉⢱⠀⠀⢸⠀⠀⠀ ⢸⠉⠉⠀⢸⠉⠫⡀⢸⠉⠉⠀⡌⠉⢱⠀⡌⠉⢱   ⡏⠉⢱⠀⡇⠀⢸⠀⠀⢸⠀⠀⠀⠀⡇⠀⠀⡇⠀⢸⠀⡇⠹⣼
  445.    ⠈⠉⠁⠀⠈⠉⠁⠀⠈⠉⠁⠀⠀⠈⠀⠀⠀ ⠈⠀⠀⠀⠈⠀⠀⠁⠈⠉⠉⠀⠈⠉⠁⠀⠈⠉⠁   ⠉⠉⠁⠀⠈⠉⠁⠀⠀⠈⠀⠀⠀⠀⠁⠀⠀⠈⠉⠁⠀⠁⠀⠈ ]]
  446.  
  447.    milkywaySubLogo = "⣳⡃⣩⡁⣺⠅⣻⡇⣏⠃⡳⡇⠭⡇⣏⠃ ⢸⠺⢨⢬⠨⢽⢨⣩⢸⣘⠨⢽⢨⢬⢸⢬ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  448.    pegasusSubLogo = "⡇⡁⡧⡅⣇⡃⠭⡇⡗⠇⠉⡇⡗⠇ ⢸⠺⢨⢬⠨⢽⢨⣩⢸⣘⠨⢽⢨⢬⢸⢬ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  449.    universeSubLogo = "⠉⡇⡼⡆⣩⡁⣹⡇⡧⡅⣍⡅⡗⠇⡧⡅ ⢸⠺⢨⢬⠨⢽⢨⣩⢸⣘⠨⢽⢨⢬⢸⢬ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  450.    oriSubLogo = "⡳⡅⣍⡅⣩⡁ ⡥⡅⣍⡅⠭⡇⡼⡆⡗⠇⡇⡁⡳⡅⣍⡅⡥⡅ ⣍⡅⣩⡁⡼⡆⣇⡃⡗⠇ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  451.    ancientsSubLogo = "⠭⡇⡼⡆⡏⡇⣩⡁⡧⡅⡼⡆⡥⡅⡗⠇ ⡥⡅⣍⡅⠭⡇⡼⡆⡗⠇⡇⡁⡳⡅⣍⡅⡥⡅ ⣍⡅⣩⡁⡼⡆⣇⡃⡗⠇ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  452.    goauldSubLogo = "⢔⣹⣏⡢⢄⣀⠀⣄⣻⣘⣇⣻⡀ ⢀⡶⣄⡴⠦⠀⡠⡠⡠⡠⡀ ⠐⢶⣶⠖⢖⠄ ⢀⡶⣄⡴⠦  ⢔⣹⣏⡢⢄⣀"
  453.  
  454.    local function mainScreen()
  455.        gpu.setResolution(72, 28)
  456.        term.clear()
  457.        term.setCursor(7,2)
  458.        print(logo)
  459.        print()
  460.    end
  461.  
  462.    local function operationScreen()
  463.        mainScreen()
  464.        gpu.setForeground(subColor)
  465.        term.setCursor(posX, 5)
  466.        print(subLogo)
  467.        gpu.setForeground(colorDefault)
  468.        term.setCursor(1, 8)
  469.    end
  470.  
  471.    local function bootingScreen()
  472.        mainScreen()
  473.        print(changelog)
  474.        timer(changelogTimer)
  475.        mainScreen()
  476.        print(instructions)
  477.        timer(infoTime)
  478.    end
  479.  
  480.    local function closingScreen()
  481.        operationScreen()
  482.        term.setCursor(32,8)
  483.        print("Good bye")
  484.    end
  485.  
  486. ---- End of Main Screen functions ----------------------------------
  487.  
  488. ---- Stargate functions---------------------------------------------
  489.    local function setupByGateType()
  490.        if stargate.getGateType() == "MILKYWAY" then
  491.            stargateAddress = stargateAddressMW
  492.            PoO = {"Point of Origin"}
  493.            subLogo = milkywaySubLogo
  494.            subColor = colorRed
  495.            posX = 14
  496.            if fastDial == false then walterMes = true end
  497.        elseif stargate.getGateType() == "PEGASUS" then
  498.            stargateAddress = stargateAddressPG
  499.            PoO = {"Subido"}
  500.            subLogo = pegasusSubLogo
  501.            subColor = colorBlue
  502.            posX = 14
  503.        else
  504.            stargateAddress = stargateAddressUNI
  505.            PoO = {"G17"}
  506.            subLogo = universeSubLogo
  507.            subColor = colorGray
  508.            posX = 13
  509.        end
  510.    end
  511.  
  512.    local function completeAddress(t1, t2)
  513.        for i=1, #t2 do
  514.            t1[#t1 + 1] = t2[i]
  515.        end
  516.    end
  517.  
  518.    local function energyLevel()
  519.        if type(stargate.getEnergyRequiredToDial(table.unpack(stargateAddress))) == "table" then
  520.            if stargate.getEnergyStored() < stargate.getEnergyRequiredToDial(table.unpack(stargateAddress)).open + (stargate.getEnergyRequiredToDial(table.unpack(stargateAddress)).keepAlive * 20 * minOpenTime) then
  521.                errorMessagenger("Not Enough Energy to Establish Connection")
  522.                energyCancel = true
  523.            end
  524.        else
  525.            if forceDial == false then errorMessagenger("No Stargate Detected on Provided Address") energyCancel = true end
  526.        end
  527.    end
  528.  
  529.    local function IrisCheck()
  530.        if stargate.getIrisType() == "NULL" then irisAutoClose = false else
  531.            if stargate.getIrisState() == "CLOSED" then stargate.toggleIris() end
  532.        end
  533.        if stargate.getIrisType() == "SHIELD" then
  534.            buttons.toggleShieldButton:display()
  535.            buttons.toggleShieldButton:disable(false)
  536.        elseif stargate.getIrisState ~= "NULL" and stargate.getIrisState ~="SHIELD" then
  537.            buttons.toggleIrisButton:display()
  538.            buttons.toggleIrisButton:disable(false)
  539.        end
  540.    end
  541.  
  542.    local function computerDial(dialed)
  543.       glyph = stargateAddress[dialed + 1]
  544.           if walterMes == false then
  545.               print("Engaging " .. glyph .. "...")
  546.           end
  547.       stargate.engageSymbol(glyph)
  548.    end
  549.  
  550.    local function dhdDial(dialed)
  551.        for i, v in ipairs(stargateAddress) do
  552.            if offWorldActivation or forceStop then break end
  553.            glyph = stargateAddress[i]
  554.            print("DHD button pressed: "..glyph.."... ")
  555.            dhd.pressButton(glyph)
  556.            os.sleep(0.6)
  557.       end
  558.       if offWorldActivation == false or forceStop == false then
  559.           os.sleep(1.4)
  560.           print("DHD button pressed: Big Red Button... ")
  561.           dhd.pressBRB()
  562.           rsLockDialed = true
  563.       end
  564.    end
  565.  
  566.    local function IDCsender()
  567.        if brokenBroadcastIDC then errorMessagenger("Broadcast IDC Failed: Invalid IDC") sendIDC = false else print("IDC: " .. IDC .. " sent successfully") stargate.sendIrisCode(IDC) end
  568.    end
  569.  
  570. ---- End of Stargate functions -------------------------------------
  571.  
  572. ---- Stargate events -----------------------------------------------
  573.    local function startStargateEvents()
  574.        stargateEventsActive = true
  575.  
  576.        openEvent = event.listen("stargate_open", function()
  577.            if offWorldActivation == false then
  578.                buttons.abortButton:hide()
  579.                buttons.abortButton:disable(true)
  580.                if walterMes == false then print("Stargate opened successfully") end
  581.                rsLockDialed = true
  582.                loop = false
  583.            end
  584.        end)        
  585.  
  586.        failEvent = event.listen("stargate_failed", function()
  587.            if offWorldActivation == false then
  588.                dialingFailed = true
  589.                if walterMes then print("Chevron " .. encodedChevron .. " will not engage. It won't Lock. Can't Establish Connection") else print("Stargate failed to open") end
  590.                if fastDial then errorMessagenger("Make Sure the DHD Contains the Glyph Crystal") timer(2) end
  591.                timer(2)
  592.                cancelStargateEvents()
  593.            end
  594.        end)
  595.                    
  596.        closedEvent = event.listen("stargate_wormhole_closed_fully", function()
  597.            if offWorldActivation then print("Conection lost") timer(1) end
  598.            rsLockDialed = false
  599.            disconnected = true
  600.            if stargate.getIrisState() == "CLOSED" then stargate.toggleIris()
  601.                if stargate.getIrisType() ~= "SHIELD" then print("Opening IRIS") else print("Turning OFF Shield") end
  602.            end
  603.            if standBy == false then cancelStargateEvents() end -------------------------------------------------------------------------------------------------------------------------------------------
  604.        end)
  605.  
  606.        incomingEvent = event.listen("stargate_incoming_wormhole", function()
  607.            offWorldActivation = true
  608.            loop = false
  609.            buttons.abortButton:hide()
  610.            buttons.abortButton:disable(true)
  611.            if dial then stargate.abortDialing() end
  612.            dial = false
  613.            if irisAutoClose and stargate.getIrisState() == "OPENED" then stargate.toggleIris() os.sleep(0.2)
  614.                if stargate.getIrisType() ~= "SHIELD" then print("Closing IRIS") else print("Turning ON Shield") end
  615.            end
  616.        end)
  617.  
  618.         eventEngaged = event.listen("stargate_spin_chevron_engaged", function(evname, address, caller, num, lock, glyph)   
  619.            os.sleep(0.5)
  620.            if lock then
  621.                if walterMes then print("Chevron "..encodedChevron.." Locked") end
  622.                stargate.engageGate()
  623.            else
  624.                if walterMes then print("Chevron "..encodedChevron.. " encoded...") encodedChevron = encodedChevron + 1 end
  625.                computerDial(num)
  626.            end
  627.        end)
  628.  
  629.        eventReceiveCode = event.listen("received_code", function(_, _, _, code)
  630.            os.sleep(0.5)
  631.            if intruderDetector then stargate.sendMessageToIncoming("Intruder Entry Prohibited") else
  632.                if irisAutoClose and brokenLocalIDC == false then
  633.                    if thisIDC == code then
  634.                        if stargate.getIrisState() == "CLOSED" then stargate.toggleIris() wasOpened = true
  635.                            if stargate.getIrisType() == "SHIELD" then print("IDC Accepted - Turning off Shield") stargate.sendMessageToIncoming("IDC Accepted - Turning off Shield") else print("IDC Accepted - Opening Iris") stargate.sendMessageToIncoming("IDC Accepted - Opening Iris") end
  636.                        else
  637.                            if stargate.getIrisType() == "SHIELD" then stargate.sendMessageToIncoming("Shield is OFF!") else stargate.sendMessageToIncoming("Iris is Open!") end
  638.                        end
  639.                    elseif thisIDC ~= code and stargate.getIrisState() == "CLOSED" then stargate.sendMessageToIncoming("IDC is Incorrect!")
  640.                    elseif thisIDC ~= code and stargate.getIrisState() == "OPENED" and wasOpened then
  641.                            if stargate.getIrisType() ~= "SHIELD" then stargate.sendMessageToIncoming("Intruder Detected - closing IRIS") print("Invalid IDC received - Closing Iris") else stargate.sendMessageToIncoming("Intruder Detected - SHIELD is ON") print("Invalid IDC received - Turning on Shield") end
  642.                            stargate.toggleIris()
  643.                            intruderDetector = true
  644.                    end
  645.                elseif irisAutoClose and brokenLocalIDC then errorMessagenger("Error: IDC Database is Damaged!") stargate.sendMessageToIncoming("Error: Database is Damaged - Your IDC is not Valid!")
  646.                end
  647.            end
  648.        end)
  649.    end            
  650.  
  651.   function cancelStargateEvents()
  652.       event.cancel(eventEngaged)
  653.       event.cancel(openEvent)
  654.       event.cancel(failEvent)
  655.       event.cancel(incomingEvent)
  656.       event.cancel(closedEvent)
  657.       event.cancel(eventReceiveCode)
  658.       loop = false
  659.       stargateEventsActive = false
  660.   end
  661.  
  662. ---- End of Stargate events ----------------------------------------
  663.  
  664. ---- Transport Rings functions -------------------------------------
  665.    local function AunisVersionCheck()
  666.       local success, result = pcall(rings.getAunisVersion)
  667.       if not success then AunisVersion = "legacy" else AunisVersion = result end
  668.    end
  669.  
  670.    local function setupByRingsType()
  671.        ringsAddress = ringsAddressGoauld
  672.        ringType = 0
  673.        lastSymbol = 5
  674.        if ringsTheme == 0 then
  675.           --ringsAddress = ringsAddressGoauld ringType = 0 lastSymbol = 5
  676.           subLogo = goauldSubLogo
  677.           subColor = colorGold
  678.           posX = 13
  679.       elseif ringsTheme == 1 then
  680.           -- ringsAddress = ringsAddressOri ringType = 1 lastSymbol = 5
  681.           subLogo = oriSubLogo
  682.           subColor = colorLightGray
  683.           posX = 11
  684.       else
  685.           -- ringsAddress = ringsAddressAncients ringType = 2 lastSymbol = ""
  686.           subLogo = ancientsSubLogo
  687.           subColor = colorLightBlue
  688.           posX = 6
  689.       end
  690.    end
  691.  
  692.    local function messageSystem(msg)
  693.        if msg ~= "OK" then
  694.            local msgString = resultMessages[msg]
  695.            if msgString == nil then msgString = msg end    
  696.            if msg == "ACTIVATED" then
  697.                print(msgString)
  698.            else
  699.                errorMessagenger(msgString)
  700.                rsLockDialed = false
  701.                ringsFailed = true
  702.            end
  703.            timer(3)
  704.        end
  705.    end
  706.  
  707.    local function dialRings()
  708.        rsLockDialed = true
  709.        for i,v in pairs(ringsAddress) do
  710.            if forceStop then break end
  711.            symbol = ringsAddress[i]
  712.            print("Symbol engaged: " .. symbol .. "...")
  713.            rings.addSymbolToAddress(ringType, symbol)
  714.            os.sleep(0.5)
  715.        end
  716.        if forceStop == false then
  717.            os.sleep(0.5)
  718.            local result = rings.addSymbolToAddress(ringType, lastSymbol)
  719.            messageSystem(result)
  720.        end
  721.    end
  722.  
  723. ---- End of Transport Rings functions ------------------------------
  724.  
  725. ---- Transport Rings events ----------------------------------------
  726.   local function startRingsEvents()
  727.       ringsEventsActive = true
  728.       eventTeleportStart = event.listen("transportrings_teleport_start", function(_, address, caller, initiating)
  729.           mainRSLoop = false
  730.           rsLockDialed = true
  731.       end)
  732.  
  733.       eventTeleportFinished = event.listen("transportrings_teleport_finished", function(_, address, caller, initiating)
  734.           rsLockDialed = false
  735.           computer.beep()
  736.       end)
  737.   end  
  738.  
  739.   local function cancelRingsEvents()
  740.       event.cancel(eventTeleportStart)
  741.       event.cancel(eventTeleportFinished)
  742.       ringsEventsActive = false
  743.   end
  744.  
  745. ---- End of Transport Rings events ---------------------------------
  746.  
  747. -- End of Functions -------------------------------------------------
  748.  
  749. -- Initialization ---------------------------------------------------
  750.    hideAllButtons()
  751.    bootingScreen()
  752.    if component.isAvailable("stargate") then
  753.        setupByGateType()
  754.        checkThisTableContent(stargateAddress, 5, 8, "Incomplete Stargate Address or No Stargate Address Entered.", "Stargate Address Corrupted")
  755.        completeAddress(stargateAddress, PoO)
  756.    end
  757.    if component.isAvailable("transportrings") then
  758.        setupByRingsType()
  759.        for i, v in ipairs(ringsAddress)do
  760.            print(v)
  761.        end
  762.        checkThisTableContent(ringsAddress, 3, 5, "Incomplete Rings Address or No Rings Address Entered.", "Rings Address Corrupted")
  763.    end
  764.  
  765. -- End of Initialization --------------------------------------------
  766.  
  767. -- Main Loop --------------------------------------------------------
  768.    ::Start::
  769.    if stargateEventsActive then cancelStargateEvents() end
  770.    if ringsEventsActive then cancelRingsEvents() end
  771.    operationScreen()
  772.    if component.isAvailable("transportrings") then goto Rings end
  773.    timer(1)
  774. ---- Stargate Dialing sequence -------------------------------------
  775.  
  776. ------ Loop Declarations ------------------------------------------
  777.   loop = false                                                  
  778.   dial = false
  779.   rsLockDialed = false
  780.   energyCancel = false
  781.   wasOpened = false
  782.   wasTouched = false
  783.   dialingFailed = false
  784.   offWorldActivation = false
  785.   intruderDetector = false
  786.   mainRSLoop = true
  787.   standBy = true
  788.   dialed = 0
  789.   encodedChevron = 1
  790.  
  791. ------ end of Loop Declarations -----------------------------------
  792.  
  793. ------ Initialization ---------------------------------------------
  794.    buttons.toggleIrisButton:hide()
  795.    buttons.toggleShieldButton:hide()
  796.    buttons.toggleIrisButton:disable(true)
  797.    buttons.toggleShieldButton:disable(true)  
  798.  
  799.    if stargate.dialedAddress == nil then
  800.        if stargate.getIrisState() == "OPENED" then stargate.toggleIris() end
  801.        startStargateEvents()
  802.        offWorldActivation = true
  803.        os.sleep(0.1)
  804.        goto IncomingLoop
  805.    elseif stargate.dialedAddress ~= "[]" and stargate.dialedAddress ~= nil and stargate.getGateStatus() ~= "open" then
  806.        stargate.abortDialing()
  807.        print("Clearing Stargate Address buffer")
  808.        timer(1)
  809.    end
  810.  
  811.    if stargate.getGateStatus() == "open" then print("Closing Stargate") stargate.disengageGate() timer(1) end
  812.    
  813.    startStargateEvents()
  814.  
  815.    if stargate.getGateStatus() ~= "idle" and stargate.getGateType() == "UNIVERSE" then print("Stargate is Restarting...") end
  816.    while stargate.getGateStatus() ~= "idle" do os.sleep(0.1) if forceStop then goto CloseProgram end end
  817.    timer(1)
  818.    IrisCheck()
  819.  
  820. ------ End of Initialization --------------------------------------
  821.  
  822. ------ Dialing Programs -------------------------------------------
  823.    operationScreen()
  824.    print("Press Button to Activate Stargate Dialing Sequence")
  825.    print()
  826.    disconnected = false
  827.    while mainRSLoop do
  828.        if forceStop then goto CloseProgram end
  829.        if rs.getInput(rsInput) > 0 or wasTouched then
  830.            mainRSLoop = false
  831.            wasTouched = false
  832.        end
  833.        if offWorldActivation then mainRSLoop = false goto IncomingLoop end
  834.        os.sleep(0.1)
  835.    end
  836.  
  837.    energyLevel()
  838.    if energyCancel then timer(5) cancelStargateEvents() goto Start end
  839.  
  840.    buttons.abortButton:display()
  841.    buttons.abortButton:disable(false)
  842.  
  843.    if fastDial then print("Initiate the dialing sequence with DHD") dhdDial(0) dial = true else
  844.        if walterMes then print("Input the coordinates and initiate the dialing sequence") else print("Dialing the Stargate") end
  845.        computerDial(0)
  846.        loop = true
  847.        dial = true
  848.        while loop do
  849.            if forceStop then goto CloseProgram end
  850.            if offWorldActivation then loop = false goto IncomingLoop end
  851.            os.sleep(0.1)
  852.        end
  853.    end
  854.  
  855.    print()
  856.    timer(1)
  857.    if sendIDC and dialingFailed == false then timer(4) IDCsender() print() computer.beep() else timer(2) end
  858.    if dialingFailed then goto Start end
  859. ------ End of Dialing Programs ------------------------------------
  860.  
  861. ------ Interlock Loops --------------------------------------------
  862.    if rsLockDialed then
  863.        term.setCursor(1, 24)
  864.        if gateAutoClose then print("Stargate closes in: ") else print("Press Button to Close Stargate") end
  865.        if gateAutoClose == false then
  866.            while disconnected == false do
  867.                os.sleep(0.1)
  868.                if rs.getInput(rsInput) > 0 or wasTouched then
  869.                    wasTouched = false
  870.                    break end
  871.                if forceStop then goto CloseProgram end
  872.            end
  873.        else
  874.            loopTime = maxOpenTime * 10
  875.            stopwatch = maxOpenTime
  876.            gateTimer(stopwatch)
  877.            clockLoop = 0
  878.            term.setCursor(21 ,24)
  879.            print(mins.. ":" .. secs)
  880.            for i = 0, loopTime do
  881.                clockLoop = clockLoop + 1
  882.                if clockLoop == 5 then term.setCursor(21 ,24) print(mins.. " " .. secs) elseif clockLoop == 10 then
  883.                    clockLoop = 0
  884.                    stopwatch = stopwatch - 1
  885.                    gateTimer(stopwatch)
  886.                    term.setCursor(21 ,24)
  887.                    print(mins.. ":" .. secs)
  888.                end
  889.                if forceStop then goto CloseProgram end
  890.                if rs.getInput(rsInput) > 0 or wasTouched then
  891.                    wasTouched = false
  892.                    break end
  893.                if disconnected then break end
  894.                os.sleep(0.1)
  895.            end
  896.        end
  897.        
  898.        stargate.disengageGate()
  899.        print("Closing stargate")
  900.        timer(1)
  901.        if stargate.getGateStatus() ~= "idle" and stargate.getGateType() == "UNIVERSE" then print("Stargate is Restarting...") end
  902.        while stargate.getGateStatus() ~= "idle" do os.sleep(0.1) if forceStop then goto CloseProgram end end
  903.        cancelStargateEvents()
  904.        goto Start
  905.    end
  906.        
  907.    ::IncomingLoop::
  908.  
  909.    if offWorldActivation then operationScreen()
  910.        if walterMes then print("Unscheduled Offworld Activation") print() else print("Incoming Wormhole!") print() end
  911.        while offWorldActivation do
  912.            if forceStop then goto CloseProgram end
  913.            if disconnected then break end
  914.            os.sleep(0.1)
  915.        end
  916.    end
  917.    cancelStargateEvents()
  918.    goto Start
  919.  
  920. ------ End of Interlock Loops -------------------------------------
  921.  
  922. ---- End of Stargate Dialing sequence ------------------------------
  923.  
  924. ---- Transport Rings Dialing sequence ------------------------------
  925. ::Rings::
  926.  
  927. ------ Loop Declarations ------------------------------------------
  928.   mainRSLoop = true
  929.   rsLockDialed = false
  930.   ringsFailed = false
  931.  
  932. ------ End of Loop Declarations -----------------------------------
  933.  
  934. ------ Initialization ---------------------------------------------
  935.    AunisVersionCheck()
  936.    if AunisVersion == "legacy" then
  937.        errorMessagenger("You are using outdated version of Aunis (JSG). This program is not      compatible for transport rings control.")
  938.        print() print("Supported versions: 4.10.0.1 and newer")
  939.        timer(6)
  940.        goto CloseProgram
  941.    end
  942.  
  943.    rings.addSymbolToAddress(ringType, lastSymbol)
  944.  
  945.    os.sleep(0.5)
  946.    startRingsEvents()
  947.  
  948. ------ End of Initialization --------------------------------------
  949.  
  950. ------ Rings Dialing Program --------------------------------------
  951.    print("Press Button to Activate Transport Rings")
  952.    print()
  953.    timer(1)
  954.    while mainRSLoop do
  955.        if forceStop then goto CloseProgram end
  956.        if rs.getInput(rsInput) > 0 or wasTouched then
  957.            mainRSLoop = false
  958.            wasTouched = false
  959.        end
  960.        os.sleep(0.1)
  961.    end
  962.  
  963.   print("Activating Transport Rings Dialing Sequence")
  964.   dialRings()
  965.  
  966. ------ End of Rings Dialing program -------------------------------
  967.  
  968. ------ Interlock Loop ---------------------------------------------
  969.   while rsLockDialed do
  970.       if forceStop then goto CloseProgram end
  971.       os.sleep(0.1)
  972.   end
  973.  
  974.   if ringsFailed == false then
  975.       print()
  976.       print("Preparing Transport Rings for further operation")
  977.       timer(pauseBetweenDials)
  978.   end
  979.  
  980.   cancelRingsEvents()
  981.   goto Start
  982. ------End of Interlock Loop ---------------------------------------
  983.  
  984. ---- End of Transport Rings Dialing sequence -----------------------
  985.  
  986. -- End of Main Loop -------------------------------------------------
  987.  
  988. -- Closing procedure ------------------------------------------------
  989. ::CloseProgram::
  990.  
  991. event.cancel(eventInterrupted)
  992. event.cancel(eventTouch)
  993. hideAllButtons()
  994. if stargateEventsActive then cancelStargateEvents() end
  995. if ringsEventsActive then cancelRingsEvents() end
  996. if component.isAvailable("stargate") and dial then stargate.abortDialing() end
  997. closingScreen()
  998. os.sleep(2)
  999. term.clear()
  1000. gpu.setResolution(160, 50)
  1001. -- End of Closing procedure ----------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement