Advertisement
Guest User

Tank

a guest
Mar 3rd, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.77 KB | None | 0 0
  1. --HUD = peripheral.wrap("left")
  2. monitor = peripheral.wrap("top")
  3. --sfBoiler = peripheral.wrap("solid_fueled_boiler_firebox_0")
  4. --lfBoiler = peripheral.wrap("liquid_fueled_boiler_firebox_0")
  5. lavaTank = peripheral.wrap("steel_tank_valve_0")
  6. --ethanolTank = peripheral.wrap("iron_tank_valve_1")
  7. --steamTank = peripheral.wrap("iron_tank_valve_2")
  8. --steamTurbine = peripheral.wrap("steam_turbine_housing_0")
  9. --steamComputer = peripheral.wrap("computer_2")
  10. --mfe = peripheral.wrap("batbox_0")
  11. --mfsu = peripheral.wrap("batbox_1")
  12. --craftingMonitor = peripheral.wrap("me_crafting_monitor_0")
  13.  
  14. steamOn = false
  15.  
  16. rednet.open("bottom")
  17.  
  18. function roundNum(val, decimal)
  19.     if (decimal) then
  20.         return math.floor(((val * 10^decimal) + 0.5) / (10^decimal))
  21.     else
  22.         return math.floor(val+0.5)
  23.     end
  24. end
  25.  
  26.  function drawPixel(x, y, color)
  27.     monitor.setCursorPos(x, y)
  28.     monitor.setBackgroundColor(color)
  29.     monitor.write(" ")
  30.  end
  31.  
  32.  function drawTank(x, y, color, maxLiq, currentLiq, tankName)
  33.        
  34.        if currentLiq == nil then
  35.          currentLiq = 0
  36.        end
  37.        
  38.        if maxLiq == nil then
  39.          maxLiq = 0
  40.        end
  41.        
  42.     percentage = roundNum(((currentLiq / maxLiq) * 100), 0)
  43.        
  44.     for i = 0, 11 do
  45.         drawPixel(x, y + i, colors.white)
  46.         drawPixel(x + 19, y + i, colors.white)
  47.     end
  48.        
  49.     for i = 1, 18 do
  50.         drawPixel(x + i, y + 11, colors.white)
  51.     end
  52.        
  53.     rows =  roundNum((percentage / 10), 0)
  54.        
  55.     for i = 10 - rows, 10 do
  56.         for j = 1, 18 do
  57.             if tankName == "Lava Tank" then
  58.                 if math.random(1, 20 - i) == 1 then
  59.                     if math.random(1, 4) == 1 then
  60.                         drawPixel(x + j, y + i, colors.black)
  61.                     else
  62.                         drawPixel(x + j, y + i, colors.orange)
  63.                     end
  64.                 else
  65.                     drawPixel(x + j, y + i, color)
  66.                 end
  67.             elseif tankName == "Steam Tank" then
  68.                 if math.random(1, 20 - i) == 1 then
  69.                     drawPixel(x + j, y + i, colors.lightGray)
  70.                 else
  71.                     drawPixel(x + j, y + i, color)
  72.                 end
  73.             else
  74.                 drawPixel(x + j, y + i, color)
  75.             end
  76.         end
  77.     end
  78.    
  79.     monitor.setCursorPos(x, y + 13)
  80.     monitor.setBackgroundColor(colors.black)
  81.     monitor.setTextColor(colors.white)
  82.     monitor.write(tankName .. "  " .. tostring(percentage) .. "%")
  83.     monitor.setCursorPos(x, y + 14)
  84.     monitor.write(tostring(currentLiq) .. "mB / " .. tostring(maxLiq) .. "mB")
  85. end
  86.  
  87. function drawLiqBoiler(x, y, waterCap, waterCur, temp, fuelMax, fuelCurrent, steamMax, steamCurrent)
  88.  
  89.  if waterCur == nil then
  90.    waterCur = 0
  91.  end
  92.  
  93.  if waterCap == nil then
  94.    waterCap = 0
  95.  end
  96.  
  97.  if fuelCurrent == nil then
  98.    fuelCurrent = 0
  99.  end
  100.  
  101.  if fuelMax == nil then
  102.    fuelMax = 0
  103.  end
  104.  
  105.  if steamCurrent == nil then
  106.    steamCurrent = 0
  107.  end
  108.  
  109.  if steamMax == nil then
  110.    steamMax = 0
  111.  end
  112.    
  113.     waterPercentage = roundNum(((waterCur / waterCap) * 100), 0)
  114.     fuelPercentage = roundNum(((fuelCurrent / fuelMax) * 100), 0)
  115.     steamPercentage = roundNum(((steamCurrent / steamMax) * 100), 0)
  116.    
  117.     waterRows = roundNum((waterPercentage / 10), 0)
  118.     fuelRows = roundNum((fuelPercentage / 10), 0)
  119.     steamRows = roundNum((steamPercentage / 10), 0)
  120.    
  121.     for i = 0, 11 do
  122.         drawPixel(x, y + i, colors.white)
  123.         drawPixel(x + 2, y + i, colors.white)
  124.         drawPixel(x + 5, y + i, colors.white)
  125.         drawPixel(x + 7, y + i, colors.white)
  126.         drawPixel(x + 10, y + i, colors.white)
  127.         drawPixel(x + 12, y + i, colors.white)
  128.     end
  129.    
  130.     drawPixel(x + 1, y + 11, colors.white)
  131.     drawPixel(x + 6, y + 11, colors.white)
  132.     drawPixel(x + 11, y + 11, colors.white)
  133.    
  134.     for i = 10 - waterRows, 10 do
  135.         drawPixel(x + 1, y + i, colors.blue)
  136.     end
  137.    
  138.     for i = 10 - fuelRows, 10 do
  139.         drawPixel(x + 6, y + i, colors.orange)
  140.     end
  141.    
  142.     for i = 10 - steamRows, 10 do
  143.         drawPixel(x + 11, y + i, colors.gray)
  144.     end
  145.    
  146.    
  147.     monitor.setCursorPos(x, y + 13)
  148.     monitor.setBackgroundColor(colors.black)
  149.     monitor.setTextColor(colors.white)
  150.     monitor.write("Temp = " .. roundNum(temp, 2))
  151. end
  152.  
  153. while true do
  154.         monitor.clear()
  155. --        HUD.clear()
  156.  
  157.         drawTank(2, 2, colors.red, lavaTank.getTanks("unknown")[1].capacity, lavaTank.getTanks("unknown")[1].amount, "Lava Tank")
  158. --        drawTank(26, 2, colors.orange, ethanolTank.getTanks("unknown")[1].capacity, ethanolTank.getTanks("unknown")[1].amount, "Ethanol Tank")
  159. --        drawTank(50, 2, colors.gray, steamTank.getTanks("unknown")[1].capacity, steamTank.getTanks("unknown")[1].amount, "Steam Tank")
  160.        
  161.        
  162. --          drawLiqBoiler(2, 20, lfBoiler.getTanks("unknown")[1].capacity, lfBoiler.getTanks("unknown")[1].amount, lfBoiler.getTemperature(), lfBoiler.getTanks("unknown")[3].capacity, lfBoiler.getTanks("unknown")[3].amount, lfBoiler.getTanks("unknown")[2].capacity, lfBoiler.getTanks("unknown")[2].amount)
  163.        
  164.         sleep(1)
  165. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement