Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
Plazter

First shared program - Draconic Reactor

Recommended Posts

Hello folks!, i've been working on this little program for a few days, and think im at the final stage i want it to be in.

- This is the first program i share on here, hope you will enjoy it ^^

PASTEBIN

//Plazter

 

ADDED FAILSAFE FUNCTION, Note: In the Vars you're able to set a temperature you want it to turn off at, and set it on or off. The fail safe is on by default.

Picture + code:

 

http://imgur.com/a/jymyH

 

Code:

 


--[[
//      MADE BY...: Plazter
//      Date......: 29. April 2017
//      Mod:......: OpenComputers
//  
//      Note: This program contains a debug tool, thats intented for you to use
//            to figure out where to get your clicks, incase a button or something
//            is not working correctly. if you use this program, i hope you will
//            Enjoy it.
--]]
------------------------------------------------------------------------------------------------------------------
                                                 --[[ WRAPPINGS ]]--
------------------------------------------------------------------------------------------------------------------
component = require("component")
reactor = component.draconic_reactor
FluxGateOutput = component.proxy(component.get("61f04087-c625-45db-b2ab-294f808749a4")) -- 61f04087-c625-45db-b2ab-294f808749a4
FluxGateShield = component.proxy(component.get("b0c649d1-fac1-48bd-bc57-d1f448439233"))
term = require("term")
gpu = component.gpu
event = require("event")
keyboard = require("keyboard")
------------------------------------------------------------------------------------------------------------------
                                                 --[[  TABLES  ]]--
------------------------------------------------------------------------------------------------------------------

args = {...}

colors = { black = 0x000000, white = 0xf8f8ff, blue = 0x0000ff, lightGray = 0xd9d9d9, red = 0xff0000,
purple = 0x9b30ff, carrot = 0xffa500, magenta = 0xcd00cd, lightBlue = 0x87cefa, yellow = 0xffff00,
lime = 0x32cd32, pink = 0xffc0cb, gray = 0x696969, brown = 0x8b4500, green = 0x006400, cyan = 0x008b8b,
olive = 0x6b8e23, gold = 0x8b6914, orangered = 0xdb4e02, diamond = 0x0fa7c7,crimson = 0xaf002a,fuchsia = 0xfd3f92,
folly = 0xff004f, frenchBlue = 0x0072bb, lilac = 0x86608e, flax = 0xeedc82, darkGray = 0x563c5c,
englishGreen = 0x1b4d3e, eggplant = 0x614051, deepPink  = 0xff1493, ruby = 0x843f5b, orange = 0xf5c71a,
lemon = 0xffd300, darkBlue = 0x002e63, bitterLime = 0xbfff00 }
------------------------------------------------------------------------------------------------------------------
                                                 --[[ VARIABLES ]]--
------------------------------------------------------------------------------------------------------------------
Border_bg = colors.white
Default_bg = colors.black
text_col = colors.orange
status_col = colors.blue
failsafe = true
failSafeTemp = 6500
------------------------------------------------------------------------------------------------------------------
                                                 --[[ FUNCTIONS ]]--
------------------------------------------------------------------------------------------------------------------
function guiBorders(x,y,len,height,str) -- BORDER FUNC FOR GUI
  gpu.setBackground(Border_bg)
  gpu.fill(x,y,len,height,str)
  gpu.setBackground(Default_bg)
end
 
function GUI() -- SETS THE GUI LAYOUT (GRAPHICAL USER INTERFACE)
  gpu.setBackground(Default_bg)
  term.clear()
  w,  h = gpu.getResolution()
  guiBorders(1,1,w,1," ")
    for i = 1,h do
      guiBorders(1,i,1,1," ")
      guiBorders(w,i,1,1," ")
    end
  guiBorders(1,h,w,1," ")
  gpu.setForeground(text_col)
end

function Center(y,text) -- CENTERS TEXT   
  w, h = gpu.getResolution()
  term.setCursor((w-string.len(text))/2+1, y)
  term.write(text)
end

function info(title,x,y) -- Rewriting of gpu.set
  gpu.set(x,y,title)
end

function InfoUpdate(y, text) -- Text for function UPDATE
  w, h = gpu.getResolution()
      place = (w-string.len(text))-2
    gpu.set(place, y, text)
end

function display() -- Text to load onto screen on launch
  -- TITLE
  Center(2, "{{  Draconic Reactor  }}")
  -- Info Title
  info("Temperature",2,4)
  info("Shield",2,6)
  info("Generation Rate", 2,8)
  info("RF Output", 2, 10)
  info("RF Net gain", 2,12)
  info("Energy Saturation", 2, 14)
  info("Fuel Conversion Rate", 2,16)
  -- Button Panel
  Center(18, "Set Output")
  Center(19, "<<< << < = > >> >>>")
  Center(21, "Set State")
  Center(22, "Charge - Online - Offline")
  end

function UPDATE() -- The Information we want to keep update
  InfoUpdate(5, "  "..tostring(temperature).." C") -- Temperature
  InfoUpdate(7,"  "..string.format("%2.f",perc*100).." %") -- Shield %
  InfoUpdate(9,"  "..tostring(gen).." RF/T") -- Generating
  InfoUpdate(11, "  "..tostring(FluxGateOutput.getFlow()).." RF/t") -- What the Current output is set to.
  InfoUpdate(13,"  ".. tostring(FluxGateOutput.getFlow() -FluxGateShield.getFlow()).." RF/t") -- The total gain in rf
  InfoUpdate(15, "  "..string.format("%.3f",tostring(reactorInfo.energySaturation / reactorInfo.maxEnergySaturation * 100)).." %") -- The 		
  --energy Saturation
  InfoUpdate(17, tostring(reactorInfo.fuelConversionRate).." nB/t")  -- Fuel use
end



function getPress(line) -- Reads where we press, and set it as we wishes it
  if x ~= nil and y ~= nil then
    if x >= 32 and x <= 37 and y == 22 then -- Online
      reactor.activateReactor()
      gpu.setBackground(status_col)
      gpu.set(32,22, "Online")
      gpu.setBackground(Default_bg)
      gpu.set(23,22, "Charge")
      gpu.set(41,22,"Offline")
    elseif x >= 23 and x <= 28 and y == 22 then -- Charge
      reactor.chargeReactor()
      gpu.setBackground(status_col)
      gpu.set(23,22, "Charge")
      gpu.setBackground(Default_bg)
      gpu.set(32,22, "Online")
      gpu.set(41,22, "Offline")
    elseif x >= 41 and x <= 47 and y == 22 then --Ofline
      reactor.stopReactor()
      gpu.setBackground(status_col)
      gpu.set(41,22, "Offline")
      gpu.setBackground(Default_bg)
      gpu.set(23,22, "Charge")
      gpu.set(32,22,"Online")
    end

    if x >= 23 and x <= 29 and y == line then -- <<<
      FluxGateOutput.setFlowOverride(currOut - 10000)
    elseif x >= 30 and x <= 32 and y == line then -- <<
      FluxGateOutput.setFlowOverride(currOut - 1000)
    elseif x >= 33 and x <= 34 and y == line then -- <
      FluxGateOutput.setFlowOverride(currOut - 100)
    end

    if x >= 36 and x <= 37 and y == line then -- >
      FluxGateOutput.setFlowOverride(currOut + 100)
    elseif x >= 38 and x <= 41 and y == line then -- >>
      FluxGateOutput.setFlowOverride(currOut + 1000)
    elseif x >= 42 and x <= 46 and y == line then -- >>>
      FluxGateOutput.setFlowOverride(currOut + 10000)
    end 
  end
end

function FailSafe()
	if failsafe then
		if temperature > failSafeTemp then
			reactor.stopReactor()
      		gpu.setBackground(status_col)
      		gpu.set(41,22, "Offline")
      		gpu.setBackground(Default_bg)
      		gpu.set(23,22, "Charge")
      		gpu.set(32,22,"Online")
		end
	end
end
		
------------------------------------------------------------------------------------------------------------------
                                              --[[ PROGRAM INITATION ]]--
------------------------------------------------------------------------------------------------------------------

gpu.setResolution(70,23)

GUI() -- Loads screen layout
display() -- Loads Text Layout
------------------------------------------------------------------------------------------------------------------
                                                 --[[ MAIN LOOP ]]--
------------------------------------------------------------------------------------------------------------------

while true do
    --UPDATING VARS THAT NEEDS TO BE HERE --
    reactorInfo = reactor.getReactorInfo()  
    target = 0.30
    currShield = reactorInfo.fieldStrength
    maxShield = reactorInfo.maxFieldStrength
    perc = (currShield/maxShield)
    shieldDrain = reactorInfo.fieldDrainRate
    shieldStr = reactorInfo.fieldStrength
    temperature = reactorInfo.temperature
    currOut = FluxGateOutput.getFlow()
    gen = reactorInfo.generationRate
    -- FUNCTIONS TO KEEP LOOKING UP --    
    UPDATE()
    getPress(19)
    FailSafe()
    -- EVENT LISTENER 
    _,_,x,y = event.pull(1, "touch")    
      -- DEBUG TOOL
      if args[1] == "debug" then
        if x ~= nil and y~= nil then
          Center(16,"X: ".. x .." Y: "..y)
        end
      end
      -- TERMINATE PROGRAM AND RESTORE RESOLUTION
      if keyboard.isKeyDown(keyboard.keys.w) and keyboard.isControlDown() then
          term.clear()
          w,h = gpu.maxResolution()
          gpu.setResolution(w,h)
          os.exit()
    end

end

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.