Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modem_position = "back"
- monitor_position = "right"
- monitor_scale = 1
- modem_channel = 4
- show_percentage = true
- sleep_timeout = 0.5
- tanks={
- "1,0,0",
- "0,0,-1",
- "0,-1,0"
- }
- os.loadAPI("ocs/apis/sensor")
- sens = sensor.wrap(sensor_position)
- modem = peripheral.wrap(modem_position)
- while true do
- local data_table={}
- for i, v in ipairs(tanks) do
- target_details = sens.getTargetDetails(v)
- table.insert(data_table, target_details)
- print("a")
- end
- local send_data={id=os.getComputerID(), data=data_table}
- serialized_data = textutils.serialize(send_data)
- modem.transmit(modem_channel,modem_channel,serialized_data)
- sleep(sleep_timeout)
- end
- tank_colors={
- {name="lava", color=colors.orange},
- {name="water", color=colors.blue},
- {name="biofuel", color=colors.orange},
- {name="mobessence", color=colors.green},
- {name="creosote", color=colors.brown},
- {name="fuel", color=colors.yellow},
- {name="oil", color=colors.gray},
- {name="biomass", color=colors.green},
- {name="sludge", color=colors.blue},
- {name="sewage", color=colors.brown},
- {name="liquiddna", color=colors.pink},
- {name="honey", color=colors.yellow},
- {name="milk", color=colors.white},
- {name="ethanol", color=colors.orange},
- {name="pinkslime", color=colors.pink},
- {name="iron.molten", color=colors.red},
- {name="gold.molten", color=colors.yellow},
- {name="ardite.molten", color=colors.brown},
- {name="copper.molten", color=colors.orange},
- {name="bronze.molten", color=colors.brown},
- {name="aluminumbrass.molten", color=colors.yellow},
- {name="manyullyn.molten", color=colors.purple},
- {name="alumite.molten", color=colors.pink},
- {name="aluminum.molten", color=colors.pink},
- {name="obsidian.molten", color=colors.purple},
- {name="cobalt.molten", color=colors.blue},
- {name="steel.molten", color=colors.lightGray},
- {name="glass.molten", color=colors.lightBlue},
- {name="stone.seared", color=colors.gray},
- {name="emerald.liquid", color=colors.lime},
- {name="blood", color=colors.red},
- {name="nickel.molten", color=colors.yellow},
- {name="lead.molten", color=colors.purple},
- {name="silver.molten", color=colors.cyan},
- {name="fluid.platinum.molten", color=colors.cyan},
- {name="invar.molten", color=colors.lightGray},
- {name="electrum.molten", color=colors.yellow},
- {name="ender", color=colors.green},
- {name="slime.blue", color=colors.lightBlue},
- {name="pigiron.molten", color=colors.pink},
- {name="immibis.liquidxp", color=colors.lime},
- {name="redstone", color=colors.red},
- {name="glowstone", color=colors.yellow},
- {name="pyrotheum", color=colors.orange},
- {name="cryotheum", color=colors.cyan},
- {name="coal", color=colors.gray},
- {name="shadow.iron.molten", color=colors.lightGray},
- }
- modem = peripheral.wrap("left")
- monitor = peripheral.wrap("top")
- monitor.setTextScale(1)
- modem.open(modem_channel)
- unique_tank_hash = {}
- function tableLength(T)
- local count = 0
- for _ in pairs(T) do
- count = count + 1
- print("a")
- end
- return count
- end
- function getColor(data)
- for _, v in pairs(tank_colors) do
- if (v.name == data.Name) or
- (v.name == data.RawName) then
- print("b")
- return v.color
- end
- end
- return colors.white
- end
- function drawGraph()
- local graph_width=0
- local tanks_num = table.getn(unique_tank_hash)
- local percentage_line = 0
- if tanks_num == 0 then
- print("c_if")
- return
- end
- while graph_width <= 0 do
- graph_width = math.floor((width-tanks_num+1) / tanks_num)
- tanks_num = tanks_num - 1
- print("d")
- end
- tanks_num = tanks_num + 1
- if (show_percentage) and
- (graph_width > 4) then
- percentage_line = 1
- print("e_if")
- end
- local count=0
- for k, v in pairs(unique_tank_hash) do
- local x = (count * graph_width) + 1 + count
- local x_end = x + graph_width -1
- percent = v.Amount / v.Capacity
- percentage = (height-percentage_line) * percent
- y = (height-percentage_line) - math.floor(percentage + 0.5) + percentage_line
- print("f")
- if percentage_line == 1 then
- local round_percent = math.floor((percent*100) + 0.5)
- local text = round_percent.."%"
- local x_pos = x + math.floor((graph_width-string.len(text))/2)
- monitor.setCursorPos(x_pos,1)
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- monitor.write(text)
- monitor.write("g")
- end
- for i=1+percentage_line,height do
- for j=x,x_end do
- local c = colors.black
- if i > y then
- c = getColor(v)
- end
- monitor.setBackgroundColor(c)
- monitor.setCursorPos(j, i)
- monitor.write(" ")
- end
- end
- count = count + 1
- if count >= tanks_num then
- return
- end
- end
- end
- function removeTanks(temp_tank_hash, sensor_id)
- local deletables = {}
- local temp_tank_hash_empty = false
- if not next(temp_tank_hash) then
- temp_tank_hash_empty = true
- end
- for k, v in pairs(unique_tank_hash) do
- local other_hash = textutils.unserialize(k)
- if other_hash[1] == sensor_id then
- if temp_tank_hash_empty then
- deletables[k] = k
- else
- local found = false
- for i, j in pairs(temp_tank_hash) do
- if k == i then
- found = true
- break
- end
- end
- if not found then
- deletables[k] = k
- end
- end
- end
- end
- for k, v in pairs(deletables) do
- unique_tank_hash[k] = nil
- end
- end
- while true do
- local event, modemSide, senderChannel,
- replyChannel, message, senderDistance = os.pullEvent("modem_message")
- unser_message = textutils.unserialize(message)
- sensor_id = unser_message.id
- sensor_data = unser_message.data
- local temp_tank_hash = {}
- for i, v in ipairs(sensor_data) do
- tanks=v.Tanks
- position=v.Position
- for j, value in ipairs(tanks) do
- tank = value
- local hash={sensor_id, position, j}
- unique_tank_hash[textutils.serialize(hash)] = tank
- temp_tank_hash[textutils.serialize(hash)] = tank
- end
- end
- removeTanks(temp_tank_hash, sensor_id)
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- width, height = monitor.getSize()
- drawGraph()
- end
Advertisement
Add Comment
Please, Sign In to add comment