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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
- categories = {}
- categoriesN = {}
- elements = {}
- activeCat = 1
- activeEle = 1
- running = true
- shownText = ""
- --Functions
- function addCategory(catn, cat, catc) --Max categories are 19
- categoriesN[catn] = {}
- categoriesN[catn]["name"] = cat
- categoriesN[catn]["char"] = catc
- end
- function addElement(catn, elen, name, nincat, desc, color, gravity, dtemp, mtemp, melt) --Max elements in a category is 6
- if type(categories[catn]) ~= "table" then
- categories[catn] = {}
- end
- categories[catn][nincat] = {}
- categories[catn][nincat]["name"] = name
- categories[catn][nincat]["desc"] = desc
- categories[catn][nincat]["color"] = color
- categories[catn][nincat]["gravity"] = gravity
- categories[catn][nincat]["id"] = elen
- categories[catn][nincat]["temp"] = dtemp
- categories[catn][nincat]["mtemp"] = mtemp
- categories[catn][nincat]["melt"] = melt
- elements[elen] = {}
- elements[elen][1] = catn
- elements[elen][2] = nincat
- end
- function setElement(x, y, id)
- map[y][x] = id
- end
- function drawScreen()
- shell.run("clear")
- for y=1, 17 do
- term.setCursorPos(1, y)
- for x=1, 50 do
- if map[y][x] == 0 then
- term.setBackgroundColor(colors.black)
- else
- term.setBackgroundColor(2^(categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["color"]))
- end
- write(" ")
- end
- end
- for i=1, #categories do
- term.setCursorPos(51, 19+i-#categories)
- if activeCat == i then
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- else
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- write(categoriesN[i]["char"])
- end
- for i=1, #categories[activeCat] do
- term.setCursorPos((i-1)*3+1, 19)
- term.setTextColor(colors.black)
- term.setBackgroundColor(2^(categories[activeCat][i]["color"]))
- write(categories[activeCat][i]["name"])
- end
- term.setCursorPos(50-#shownText, 18)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- write(shownText)
- end
- function checkFallDown(x, y)
- fd = "delete"
- if map[y][x] == 0 or categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["gravity"] == 0 then
- fd = false
- end
- if map[y][x] > 0 and categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["gravity"] > 0 then
- if y == 17 then
- fd = "delete"
- elseif type(map[y+1]) == "table" then
- if map[y+1][x] == 0 or (categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["gravity"] > categories[elements[map[y+1][x]][1]][elements[map[y+1][x]][2]]["gravity"] and categories[elements[map[y+1][x]][1]][elements[map[y+1][x]][2]]["gravity"] ~= 0) then
- fd = "down"
- end
- elseif type(map[y+1][x+1]) == "table" and type(map[y+1][x-1]) == "table" then
- if (map[y+1][x-1] == 0 or (categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["gravity"] > categories[elements[map[y+1][x-1]][1]][elements[map[y+1][x-1]][2]]["gravity"] and categories[elements[map[y+1][x-1]][1]][elements[map[y+1][x-1]][2]]["gravity"] ~= 0)) and (map[y+1][x+1] == 0 or (categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["gravity"] > categories[elements[map[y+1][x+1]][1]][elements[map[y+1][x+1]][2]]["gravity"] and categories[elements[map[y+1][x+1]][1]][elements[map[y+1][x+1]][2]]["gravity"] ~= 0)) then
- if math.random(1, 2) == 1 then
- fd = "leftd"
- else
- fd = "rightd"
- end
- end
- elseif type(map[y+1][x-1]) == "table" then
- if map[y+1][x-1] == 0 or (categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["gravity"] > categories[elements[map[y+1][x-1]][1]][elements[map[y+1][x-1]][2]]["gravity"] and categories[elements[map[y+1][x-1]][1]][elements[map[y+1][x-1]][2]]["gravity"] ~= 0) then
- fd = "leftd"
- end
- elseif type(map[y+1][x+1]) == "table" then
- if map[y+1][x+1] == 0 or (categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["gravity"] > categories[elements[map[y+1][x+1]][1]][elements[map[y+1][x+1]][2]]["gravity"] and categories[elements[map[y+1][x+1]][1]][elements[map[y+1][x+1]][2]]["gravity"] ~= 0) then
- fd = "rightd"
- end
- end
- end
- return(fd)
- end
- function showCategory(catn)
- activeCat = catn
- shownText = categoriesN[catn]["name"]
- end
- function changeSelected(elen)
- activeEle = elen
- shownText = categories[activeCat][elements[elen][2]]["desc"]
- end
- function setTemp(x, y, stemp)
- map[y][x] = stemp
- end
- function changeTemp(x, y, ctemp)
- if ctemp > temps[y][x] then
- temps[y][x] = 0
- else
- temps[y][x] = temps[y][x] + ctemp
- end
- end
- function equalizeTemp(x1, y1, x2, y2)
- if math.abs(temps[y1][x1] - temps[y2][x2]) > 1 then
- if temps[y1][x1] > temps[y2][x2] then
- etemp = (temps[y1][x1] / temps[y2][x2]) * 2
- else
- etemp = (temps[y2][x2] / temps[y1][x1]) * 2
- end
- if etemp > math.abs(temps[y1][x1] - temps[y2][x2]) then
- etemp2 = (temps[y1][x1] + temps[y2][x2]) * 2
- else
- etemp2 = etemp
- end
- if temps[y1][x1] > temps[y2][x2] then
- etemp3 = 0-etemp2
- else
- etemp3 = etemp2
- end
- changeTemp(x1, y1, etemp3)
- changeTemp(x1, y1, 0-etemp3)
- else
- temps[y2][x2] = temps[y1][x1]
- end
- end
- --Preparation
- addCategory(1, "Solids", "O")
- addElement(1, 1, "DMD", 1, "Indestructible solid", 0, 0, 300)
- addCategory(2, "Powders", ":")
- addElement(2, 2, "DST", 1, "Light particles.", 4, 2, 300)
- addElement(2, 3, "STN", 2, "Heavy particles.", 8, 3, 300)
- addElement(2, 4, "BMT", 3, "Very heavy particles.", 7, 4, 300, 1450, 5)
- addElement(2, 5, "LVA", 4, "Molten metal. For some reason in powder form.", 14, 1, 1700, 1450, 4)
- --Main code
- drawScreen()
- while true do
- os.startTimer(0.2)
- event = "temp"
- while event ~= "timer" do
- event, param1, param2, param3 = os.pullEvent()
- if event == "key" then
- if param1 == 16 then
- os.reboot()
- elseif param1 == 57 then
- running = not running
- elseif param1 == 41 then
- term.setCursorPos(1, 1)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- print("| |")
- print("| |")
- print("+-------------------------------------------------+")
- term.setCursorPos(2, 1)
- command = read()
- if string.sub(command, 1, 3) == "set" then
- if string.sub(command, 5, 8) == "temp" then --set temp: [x];[y], [temp]
- tx = tonumber(string.sub(command, string.find(command, ":")+2, string.find(command, ";")-1))
- ty = tonumber(string.sub(command, string.find(command, ";")+1, string.find(command, ",")-1))
- ttemp = tonumber(string.sub(command, string.find(command, ",")+1, #command))
- end
- if type(tx) == "number" and type(ty) == "number" and type(ttemp) == "number" then
- setTemp(tx, ty, ttemp)
- term.setCursorPos(2, 2)
- write("Temperature of x: "..tx..", y: "..ty.." set to "..ttemp)
- else
- term.setCursorPos(2, 2)
- write("Error!")
- end
- end
- end
- elseif event == "mouse_click" then
- if param2 > 50 and param3 > (19-#categories) then
- showCategory(param3-19+#categories)
- elseif param2 < (1+3*#categories[activeCat]) and param3 == 19 then
- changeSelected(categories[activeCat][math.ceil(param2/3)]["id"])
- elseif param2 < 51 and param3 < 18 then
- if param1 == 1 then
- setElement(param2, param3, activeEle)
- setTemp(param2, param3, categories[elements[activeEle][1]][elements[activeEle][2]]["temp"])
- elseif param1 == 2 then
- setElement(param2, param3, 0)
- end
- end
- end
- drawScreen()
- end
- if running then
- for y=1, 17 do
- for x=1, 50 do
- y2 = 18-y
- temp = checkFallDown(x, y2)
- if temp == "delete" then
- setElement(x, y2, 0)
- elseif temp == "down" then
- temp2 = map[y2][x]
- temp3 = temps[y2][x]
- setElement(x, y2, map[y2+1][x])
- setElement(x, y2+1, temp2)
- setTemp(x, y2, temps[y2+1][x])
- setTemp(x, y2+1, temp3)
- elseif temp == "rightd" then
- temp2 = map[y2][x]
- temp3 = temps[y2][x]
- setElement(x, y2, map[y2+1][x+1])
- setElement(x+1, y2+1, temp2)
- setTemp(x, y2, temps[y2+1][x+1])
- setTemp(x+1, y2+1, temp3)
- elseif temp == "leftd" then
- temp2 = map[y2][x]
- temp3 = temps[y2][x]
- setElement(x, y2, map[y2+1][x-1])
- setElement(x-1, y2+1, temp2)
- setTemp(x, y2, temps[y2+1][x-1])
- setTemp(x-1, y2+1, temp3)
- end
- if map[y][x] > 0 then
- if categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["mtemp"] ~= nil then
- if categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["temp"] > categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["mtemp"] then
- if temps[y][x] < categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["mtemp"] then
- map[y][x] = categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["melt"]
- end
- else
- if temps[y][x] > categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["mtemp"] then
- map[y][x] = categories[elements[map[y][x]][1]][elements[map[y][x]][2]]["melt"]
- end
- end
- end
- end
- end
- end
- end
- drawScreen()
- end
Advertisement
Add Comment
Please, Sign In to add comment