Advertisement
LDDestroier

lightspeed alpha (progdor selfextract)

Jun 10th, 2017
1,062
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 63.71 KB | None | 0 0
  1. local fullname = "Lightspeed Alpha v1.0"
  2. local doCompress = false
  3. local data = {
  4.   [ "/eShip6_broken.img" ] = {
  5.     "                 777b77",
  6.     "               bbbfff7ff",
  7.     "              777bfff7",
  8.     "             7fffbbbbbb",
  9.     "             fffffffffff",
  10.     "             fffffffffff",
  11.     "             7fffb77777",
  12.     "              bbbbfff7",
  13.     "               777fff7ff",
  14.     "                 777b77",
  15.   },
  16.   [ "/ui" ] = {
  17.     "0000 00000000000000000000                   00000",
  18.     "",
  19.     "00000000000000",
  20.     "",
  21.     "00000",
  22.     "0000             000000",
  23.     "0000000000       00000000",
  24.     "0                   00000000",
  25.     "                     00000000",
  26.     "                    00000000",
  27.     "                 0000000",
  28.     "                 000000",
  29.     "",
  30.     "",
  31.     "",
  32.     "                    00000 00000",
  33.   },
  34.   [ "/eShip3_broken.img" ] = {
  35.     "                 eeeeeee",
  36.     "                e1111111f",
  37.     "              eeffe1e11ff",
  38.     "              fffffffef",
  39.     "              ff11fffff",
  40.     "              e11e111f1ff",
  41.     "                1eeeee1ef",
  42.     "                 1111111",
  43.   },
  44.   [ "/eShip11_broken.img" ] = {
  45.     "",
  46.     "                777779",
  47.     "              777ff779f",
  48.     "             7999f7799f",
  49.     "             97ff9997ff",
  50.     "             f7ffff7f",
  51.     "             ff7f7fff",
  52.     "             7f777777ff",
  53.     "             7777ff779f",
  54.     "              7977ff79f",
  55.     "                999999",
  56.   },
  57.   [ "/eShip8_broken.img" ] = {
  58.     "",
  59.     "                    7b",
  60.     "              7777bbbbf",
  61.     "             77ff77777f",
  62.     "             fffff7f7f",
  63.     "             ff7ffffff",
  64.     "             bb77ff7f7f",
  65.     "              bbbbbbbbf",
  66.     "                    7b",
  67.   },
  68.   [ "/eShip4.img" ] = {
  69.     "                     eee",
  70.     "               eeeeee111",
  71.     "              e      e",
  72.     "              1      1",
  73.     "               1111ee1ee",
  74.     "                     111",
  75.   },
  76.   [ "/Lightspeed" ] = {
  77.     "world = {}",
  78.     "playerX = 0",
  79.     "playerY = 0",
  80.     "",
  81.     "p = shell.dir()..\"/\"",
  82.     "",
  83.     "pShips = {",
  84.     "   {name = \"The Gillian\", laserx = 12, lasery = 6.5, maxHull = 18, fire = {{x = -1, y = 0}, {x = -1, y = 1}, {x = -1, y = 4}, {x = -1, y = 5}},",
  85.     "   wCooldown = 20, image = paintutils.loadImage(p..\"pShip1.img\"),",
  86.     "   rooms = {{rType = \"controll\", x = 8, y = 2, level = 9, damage = 0, repair = 0}, {rType = \"weapons\", x = 5, y = 2, level = 4, damage = 0, repair = 0}}},",
  87.     "",
  88.     "   {name = \"Sinjin\", laserx = 12, lasery = 6.5, maxHull = 20, fire = {{x = -1, y = 0}, {x = -1, y = 1}, {x = -1, y = 4}, {x = -1, y = 5}},",
  89.     "   wCooldown = 20, image = paintutils.loadImage(p..\"pShip2.img\"),",
  90.     "   rooms = {{rType = \"controll\", x = 7, y = 2, level = 4, damage = 0, repair = 0}, {rType = \"weapons\", x = 3, y = 1, level = 3, damage = 0, repair = 0}, {rType = \"shields\", x = 3, y = 3, level = 1, damage = 0, repair = 0}}},",
  91.     "}",
  92.     "",
  93.     "eShips = {",
  94.     "   {laserx = 13, lasery = 6.5, maxHull = 10, fire = {{x = 24, y = 0}, {x = 24, y = 5}},",
  95.     "   wCooldown = 20, image = paintutils.loadImage(p..\"eShip1.img\"), image_broken = paintutils.loadImage(\"eShip1_broken.img\"),",
  96.     "   rooms = {{rType = \"controll\", x = 17, y = 1, level = 3, damage = 0, repair = 0}, {rType = \"weapons\", x = 17, y = 3, level = 5, damage = 0, repair = 0}}},",
  97.     "",
  98.     "   {laserx = 13, lasery = 6.5, maxHull = 7, fire = {{x = 24, y = 0}, {x = 24, y = 1}, {x = 24, y = 4}, {x = 24, y = 5}},",
  99.     "   wCooldown = 20, image = paintutils.loadImage(p..\"eShip2.img\"), image_broken = paintutils.loadImage(\"eShip2_broken.img\"),",
  100.     "   rooms = {{rType = \"controll\", x = 18, y = 1, level = 5, damage = 0, repair = 0}, {rType = \"weapons\", x = 18, y = 3, level = 4, damage = 0, repair = 0}}},",
  101.     "",
  102.     "   {laserx = 13, lasery = 6.5, maxHull = 5, fire = {{x = 24, y = 0}, {x = 24, y = 1}, {x = 24, y = 4}, {x = 24, y = 5}},",
  103.     "   wCooldown = 20, image = paintutils.loadImage(p..\"eShip3.img\"), image_broken = paintutils.loadImage(\"eShip3_broken.img\"),",
  104.     "   rooms = {{rType = \"controll\", x = 16, y = 2, level = 7, damage = 0, repair = 0}, {rType = \"weapons\", x = 19, y = 2, level = 2, damage = 0, repair = 0}}},",
  105.     "",
  106.     "   {laserx = 13, lasery = 6.5, maxHull = 2, fire = {{x = 24, y = 0}, {x = 24, y = 1}, {x = 24, y = 4}, {x = 24, y = 5}},",
  107.     "   wCooldown = 20, image = paintutils.loadImage(p..\"eShip4.img\"), image_broken = paintutils.loadImage(\"eShip4_broken.img\"),",
  108.     "   rooms = {{rType = \"controll\", x = 15, y = 2, level = 8, damage = 0, repair = 0}, {rType = \"weapons\", x = 18, y = 2, level = 2, damage = 0, repair = 0}}},",
  109.     "",
  110.     "   {laserx = 13, lasery = 6.5, maxHull = 12, fire = {{x = 24, y = 0}, {x = 24, y = 1}, {x = 24, y = 4}, {x = 24, y = 5}},",
  111.     "   wCooldown = 20, image = paintutils.loadImage(p..\"eShip5.img\"), image_broken = paintutils.loadImage(\"eShip5_broken.img\"),",
  112.     "   rooms = {{rType = \"controll\", x = 16, y = 1, level = 1, damage = 0, repair = 0}, {rType = \"weapons\", x = 16, y = 3, level = 5, damage = 0, repair = 0}}},",
  113.     "",
  114.     "",
  115.     "   {laserx = 13, lasery = 6.5, maxHull = 12, fire = {{x = 23, y = 0}, {x = 23, y = 3}, {x = 23, y = 4}, {x = 23, y = 7}},",
  116.     "   wCooldown = 20, image = paintutils.loadImage(p..\"eShip6.img\"), image_broken = paintutils.loadImage(\"eShip6_broken.img\"),",
  117.     "   rooms = {{rType = \"controll\", x = 14, y = 3, level = 4, damage = 0, repair = 0}, {rType = \"weapons\", x = 18, y = 1, level = 3, damage = 0, repair = 0}, {rType = \"shields\", x = 18, y = 5, level = 1, damage = 0, repair = 0}}},",
  118.     "",
  119.     "   {laserx = 13, lasery = 6.5, maxHull = 10, fire = {{x = 22, y = 1}, {x = 22, y = 2}, {x = 22, y = 5}, {x = 22, y = 6}},",
  120.     "   wCooldown = 20, image = paintutils.loadImage(p..\"eShip7.img\"), image_broken = paintutils.loadImage(\"eShip7_broken.img\"),",
  121.     "   rooms = {{rType = \"controll\", x = 15, y = 2, level = 1, damage = 0, repair = 0}, {rType = \"weapons\", x = 15, y = 4, level = 5, damage = 0, repair = 0}}},",
  122.     "",
  123.     "   {laserx = 13, lasery = 6.5, maxHull = 6, fire = {{x = 22, y = 1}, {x = 22, y = 2}, {x = 22, y = 5}, {x = 22, y = 6}},",
  124.     "   wCooldown = 20, image = paintutils.loadImage(p..\"eShip8.img\"), image_broken = paintutils.loadImage(\"eShip8_broken.img\"),",
  125.     "   rooms = {{rType = \"controll\", x = 15, y = 3, level = 10, damage = 0, repair = 0}, {rType = \"weapons\", x = 18, y = 3, level = 4, damage = 0, repair = 0}}},",
  126.     "",
  127.     "   {laserx = 13, lasery = 6.5, maxHull = 8, fire = {{x = 22, y = 1}, {x = 22, y = 2}, {x = 22, y = 5}, {x = 22, y = 6}},",
  128.     "   wCooldown = 20, image = paintutils.loadImage(p..\"eShip9.img\"), image_broken = paintutils.loadImage(\"eShip9_broken.img\"),",
  129.     "   rooms = {{rType = \"controll\", x = 14, y = 3, level = 8, damage = 0, repair = 0}, {rType = \"weapons\", x = 17, y = 3, level = 5, damage = 0, repair = 0}}},",
  130.     "",
  131.     "   {laserx = 13, lasery = 6.5, maxHull = 10, fire = {{x = 23, y = 0}, {x = 23, y = 3}, {x = 23, y = 4}, {x = 23, y = 7}},",
  132.     "   wCooldown = 20, image = paintutils.loadImage(p..\"eShip10.img\"), image_broken = paintutils.loadImage(\"eShip10_broken.img\"),",
  133.     "   rooms = {{rType = \"controll\", x = 18, y = 3, level = 3, damage = 0, repair = 0}, {rType = \"weapons\", x = 18, y = 1, level = 4, damage = 0, repair = 0}, {rType = \"shields\", x = 18, y = 5, level = 1, damage = 0, repair = 0}}},",
  134.     "",
  135.     "",
  136.     "   {laserx = 13, lasery = 8, maxHull = 13, fire = {{x = 22, y = 1}, {x = 22, y = 2}, {x = 22, y = 3}, {x = 22, y = 6}, {x = 22, y = 7}, {x = 22, y = 8}},",
  137.     "   wCooldown = 20, image = paintutils.loadImage(p..\"eShip11.img\"), image_broken = paintutils.loadImage(\"eShip11_broken.img\"),",
  138.     "   rooms = {{rType = \"controll\", x = 14, y = 4, level = 3, damage = 0, repair = 0}, {rType = \"weapons\", x = 17, y = 2, level = 7, damage = 0, repair = 0}, {rType = \"shields\", x = 17, y = 6, level = 2, damage = 0, repair = 0}}},",
  139.     "",
  140.     "   {laserx = 13, lasery = 8, maxHull = 13, fire = {{x = 22, y = 1}, {x = 22, y = 2}, {x = 22, y = 3}, {x = 22, y = 6}, {x = 22, y = 7}, {x = 22, y = 8}},",
  141.     "   wCooldown = 20, image = paintutils.loadImage(p..\"eShip12.img\"), image_broken = paintutils.loadImage(\"eShip12_broken.img\"),",
  142.     "   rooms = {{rType = \"controll\", x = 14, y = 4, level = 3, damage = 0, repair = 0}, {rType = \"weapons\", x = 17, y = 2, level = 7, damage = 0, repair = 0}, {rType = \"shields\", x = 17, y = 6, level = 2, damage = 0, repair = 0}}},",
  143.     "}",
  144.     "",
  145.     "pShip = {}",
  146.     "eShip = {}",
  147.     "unlockedShips = {}",
  148.     "killCount = 0",
  149.     "",
  150.     "laserPhase = 0",
  151.     "miss = 0",
  152.     "missTime = 8",
  153.     "tick = 1",
  154.     "scrapSymbol = string.char(21)",
  155.     "stop = false",
  156.     "",
  157.     "scrap = 0",
  158.     "fuel = 0",
  159.     "score = 0",
  160.     "",
  161.     "target = -1",
  162.     "repeatShot = false",
  163.     "",
  164.     "screenWidth, screenHeight = term.getSize()",
  165.     "",
  166.     "x1 = 3",
  167.     "y1 = 4",
  168.     "",
  169.     "x2 = 26",
  170.     "y2 = 4",
  171.     "",
  172.     "function deepCopy(table)",
  173.     "   local copy = {}",
  174.     "",
  175.     "   for k, v in pairs(table) do",
  176.     "       local subcopy = v",
  177.     "",
  178.     "       if (type(v) == \"table\") then",
  179.     "           subcopy = deepCopy(v)",
  180.     "       end",
  181.     "",
  182.     "       copy[k] = subcopy",
  183.     "   end",
  184.     "",
  185.     "   return copy",
  186.     "end",
  187.     "",
  188.     "function drawSpaceBackground()",
  189.     "   term.setBackgroundColor(colors.black)",
  190.     "   term.setTextColor(colors.white)",
  191.     "   term.clear()",
  192.     "",
  193.     "   for i = 1, 100 do",
  194.     "       local x = math.random(screenWidth)",
  195.     "       local y = math.random(screenHeight)",
  196.     "       term.setCursorPos(x, y)",
  197.     "       write(\".\")",
  198.     "   end",
  199.     "end",
  200.     "",
  201.     "function drawBattle()",
  202.     "   while true do",
  203.     "       if (laserPhase > 0) then",
  204.     "           if (laserPhase ~= 1) then",
  205.     "               term.setBackgroundColor(colors.black)",
  206.     "               term.setTextColor(colors.red)",
  207.     "               for x = x1 + pShip.laserx + 2, x2 + eShip.laserx - 2 do",
  208.     "                   term.setCursorPos(x, math.ceil((pShip.lasery + eShip.lasery) / 2))",
  209.     "                   write(string.char(131))",
  210.     "               end",
  211.     "           else",
  212.     "               term.setBackgroundColor(colors.black)",
  213.     "               term.setTextColor(colors.black)",
  214.     "               for x = x1 + pShip.laserx + 2, x2 + eShip.laserx - 2 do",
  215.     "                   term.setCursorPos(x, math.ceil((pShip.lasery + eShip.lasery) / 2))",
  216.     "                   write(\" \")",
  217.     "               end",
  218.     "           end",
  219.     "           laserPhase = laserPhase - 1",
  220.     "       end",
  221.     "",
  222.     "       term.setBackgroundColor(colors.black)",
  223.     "       term.setTextColor(colors.white)",
  224.     "       term.setCursorPos(math.floor(screenWidth / 2) - 1, 8)",
  225.     "",
  226.     "       if (miss > 0) then",
  227.     "           write(\"Miss\")",
  228.     "           miss = miss - 1",
  229.     "       else",
  230.     "           write(\"    \")",
  231.     "       end",
  232.     "",
  233.     "       term.setBackgroundColor(colors.lightBlue)",
  234.     "       term.setTextColor(colors.blue)",
  235.     "       for i = 1, 20 do",
  236.     "           term.setCursorPos(i, screenHeight)",
  237.     "           if (i <= pShip.wCooldown) then",
  238.     "               write(\"=\")",
  239.     "           else",
  240.     "               paintutils.drawPixel(i, screenHeight, colors.black)",
  241.     "           end",
  242.     "       end",
  243.     "       for roomNr, room in pairs(pShip.rooms) do",
  244.     "           if (room.rType == \"weapons\") then",
  245.     "               for i = 1, room.level - room.damage do",
  246.     "                   pShip.wCooldown = pShip.wCooldown + 0.125",
  247.     "               end",
  248.     "           end",
  249.     "       end",
  250.     "",
  251.     "       term.setBackgroundColor(colors.lightBlue)",
  252.     "       term.setTextColor(colors.blue)",
  253.     "       for i = 1, 20 do",
  254.     "           term.setCursorPos(screenWidth + 1 - i, screenHeight)",
  255.     "           if (i <= eShip.wCooldown) then",
  256.     "               write(\"=\")",
  257.     "           else",
  258.     "               paintutils.drawPixel(screenWidth + 1 - i, screenHeight, colors.black)",
  259.     "           end",
  260.     "       end",
  261.     "       for roomNr, room in pairs(eShip.rooms) do",
  262.     "           if (room.rType == \"weapons\") then",
  263.     "               for i = 1, room.level - room.damage do",
  264.     "                   eShip.wCooldown = eShip.wCooldown + 0.125",
  265.     "               end",
  266.     "           end",
  267.     "       end",
  268.     "",
  269.     "       for fNr, fire in pairs(pShip.fire) do",
  270.     "           if (tick == 0) then",
  271.     "               fType = 187",
  272.     "               if (fire.x % 2 ~= fire.y % 2) then",
  273.     "                   fType = 127",
  274.     "               end",
  275.     "           else",
  276.     "               fType = 127",
  277.     "               if (fire.x % 2 ~= fire.y % 2) then",
  278.     "                   fType = 187",
  279.     "               end",
  280.     "           end",
  281.     "           term.setCursorPos(x1 + fire.x, y1 + fire.y)",
  282.     "           term.setBackgroundColor(colors.red)",
  283.     "           term.setTextColor(colors.orange)",
  284.     "           write(string.char(fType))",
  285.     "       end",
  286.     "",
  287.     "       for fNr, fire in pairs(eShip.fire) do",
  288.     "           if (tick == 0) then",
  289.     "               fType = 171",
  290.     "               if (fire.x % 2 ~= fire.y % 2) then",
  291.     "                   fType = 127",
  292.     "               end",
  293.     "           else",
  294.     "               fType = 127",
  295.     "               if (fire.x % 2 ~= fire.y % 2) then",
  296.     "                   fType = 171",
  297.     "               end",
  298.     "           end",
  299.     "           term.setCursorPos(x2 + fire.x, y2 + fire.y)",
  300.     "           term.setBackgroundColor(colors.red)",
  301.     "           term.setTextColor(colors.orange)",
  302.     "           write(string.char(fType))",
  303.     "       end",
  304.     "",
  305.     "       if (tick == 0) then",
  306.     "           tick = 1",
  307.     "       else",
  308.     "           tick = 0",
  309.     "       end",
  310.     "",
  311.     "       sleep(0.1)",
  312.     "   end",
  313.     "end",
  314.     "",
  315.     "function drawHullBarPlayer(x, y, value, max)",
  316.     "   term.setTextColor(colors.gray)",
  317.     "   for i = x, max do",
  318.     "       term.setCursorPos(i, y)",
  319.     "       if (value >= i) then",
  320.     "           term.setBackgroundColor(colors.lime)",
  321.     "       else",
  322.     "           term.setBackgroundColor(colors.red)",
  323.     "       end",
  324.     "       write(\"L\")",
  325.     "   end",
  326.     "end",
  327.     "",
  328.     "function drawHullBarEnemy(x, y, value, max)",
  329.     "   term.setTextColor(colors.gray)",
  330.     "   for i = 1, max do",
  331.     "       term.setCursorPos(x - i + 1, y)",
  332.     "       if (value >= i) then",
  333.     "           term.setBackgroundColor(colors.lime)",
  334.     "       else",
  335.     "           term.setBackgroundColor(colors.red)",
  336.     "       end",
  337.     "       write(\"L\")",
  338.     "   end",
  339.     "end",
  340.     "",
  341.     "function drawBattleScreen()",
  342.     "   drawHullBarPlayer(1, 1, pShip.hull, pShip.maxHull)",
  343.     "   term.setTextColor(colors.gray)",
  344.     "",
  345.     "   local shieldRoomNr = -1",
  346.     "   for roomNr2, room2 in pairs(pShip.rooms) do",
  347.     "       if (room2.rType == \"shields\") then",
  348.     "           shieldRoomNr = roomNr2",
  349.     "       end",
  350.     "   end",
  351.     "   if (shieldRoomNr > 0) then",
  352.     "       for i = 1, pShip.rooms[shieldRoomNr].level do",
  353.     "           term.setCursorPos((i - 1) * 4 + 1, 2)",
  354.     "           if (pShip.rooms[shieldRoomNr].level - pShip.rooms[shieldRoomNr].damage >= i) then",
  355.     "               term.setBackgroundColor(colors.lightBlue)",
  356.     "           else",
  357.     "               term.setBackgroundColor(colors.blue)",
  358.     "           end",
  359.     "           write(\"___|\")",
  360.     "       end",
  361.     "       paintutils.drawLine(16, 4, 16, 9, colors.lightBlue)",
  362.     "   else",
  363.     "       paintutils.drawLine(16, 4, 16, 9, colors.black)",
  364.     "   end",
  365.     "",
  366.     "   drawHullBarEnemy(screenWidth, 1, eShip.hull, eShip.maxHull)",
  367.     "   term.setTextColor(colors.gray)",
  368.     "",
  369.     "   local shieldRoomNr = -1",
  370.     "   for roomNr2, room2 in pairs(eShip.rooms) do",
  371.     "       if (room2.rType == \"shields\") then",
  372.     "           shieldRoomNr = roomNr2",
  373.     "       end",
  374.     "   end",
  375.     "   if (shieldRoomNr > 0) then",
  376.     "       for i = 1, eShip.rooms[shieldRoomNr].level do",
  377.     "           term.setCursorPos(screenWidth - i * 4 + 1, 2)",
  378.     "           if (eShip.rooms[shieldRoomNr].level - eShip.rooms[shieldRoomNr].damage >= i) then",
  379.     "               term.setBackgroundColor(colors.lightBlue)",
  380.     "           else",
  381.     "               term.setBackgroundColor(colors.blue)",
  382.     "           end",
  383.     "           write(\"___|\")",
  384.     "       end",
  385.     "   end",
  386.     "",
  387.     "   paintutils.drawImage(pShip.image, x1, y1)",
  388.     "   for roomNr, room in pairs(pShip.rooms) do",
  389.     "       local color = colors.white",
  390.     "       if (math.floor(room.x % 6 / 3) ~= math.floor(room.y % 4 / 2)) then",
  391.     "           color = colors.lightGray",
  392.     "       end",
  393.     "",
  394.     "       paintutils.drawFilledBox(x1 + room.x, y1 + room.y, x1 + room.x + 2, y1 + room.y + 1, color)",
  395.     "       term.setCursorPos(x1 + room.x + 1, y1 + room.y)",
  396.     "       term.setBackgroundColor(colors.black)",
  397.     "       term.setTextColor(colors.white)",
  398.     "",
  399.     "       local barY = 0",
  400.     "",
  401.     "       if (room.rType == \"controll\") then",
  402.     "           write(\"C\")",
  403.     "           barY = screenHeight - 1",
  404.     "       elseif (room.rType == \"weapons\") then",
  405.     "           write(\"W\")",
  406.     "           barY = screenHeight - 2",
  407.     "       elseif (room.rType == \"shields\") then",
  408.     "           write(\"S\")",
  409.     "           barY = screenHeight - 3",
  410.     "       else",
  411.     "           write(\"?\")",
  412.     "       end",
  413.     "",
  414.     "       term.setTextColor(colors.gray)",
  415.     "       for i = 1, room.level do",
  416.     "           if (i <= room.level - room.damage) then",
  417.     "               term.setBackgroundColor(colors.lime)",
  418.     "           else",
  419.     "               term.setBackgroundColor(colors.red)",
  420.     "           end",
  421.     "           term.setCursorPos(1 + i, barY - 1)",
  422.     "           write(\"L\")",
  423.     "       end",
  424.     "   end",
  425.     "",
  426.     "   paintutils.drawImage(eShip.image, x2, y2)",
  427.     "   for roomNr, room in pairs(eShip.rooms) do",
  428.     "       local color = colors.white",
  429.     "       if (math.floor(room.x % 6 / 3) ~= math.floor(room.y % 4 / 2)) then",
  430.     "           color = colors.lightGray",
  431.     "       end",
  432.     "       paintutils.drawFilledBox(x2 + room.x, y2 + room.y, x2 + room.x + 2, y2 + room.y + 1, color)",
  433.     "       ",
  434.     "       if (target == roomNr) then",
  435.     "           term.setCursorPos(x2 + room.x + 1, y2 + room.y + 1)",
  436.     "           if (repeatShot == false) then",
  437.     "               term.setTextColor(colors.red)",
  438.     "           else",
  439.     "               term.setTextColor(colors.orange)",
  440.     "           end",
  441.     "           write(string.char(174))",
  442.     "       end",
  443.     "",
  444.     "       term.setCursorPos(x2 + room.x + 1, y2 + room.y)",
  445.     "       term.setBackgroundColor(colors.black)",
  446.     "       term.setTextColor(colors.white)",
  447.     "       ",
  448.     "       if (room.rType == \"controll\") then",
  449.     "           write(\"C\")",
  450.     "           barY = screenHeight - 1",
  451.     "       elseif (room.rType == \"weapons\") then",
  452.     "           write(\"W\")",
  453.     "           barY = screenHeight - 2",
  454.     "       elseif (room.rType == \"shields\") then",
  455.     "           write(\"S\")",
  456.     "           barY = screenHeight - 3",
  457.     "       else",
  458.     "           write(\"?\")",
  459.     "       end",
  460.     "",
  461.     "       term.setTextColor(colors.gray)",
  462.     "       for i = 1, room.level do",
  463.     "           if (i <= room.level - room.damage) then",
  464.     "               term.setBackgroundColor(colors.lime)",
  465.     "           else",
  466.     "               term.setBackgroundColor(colors.red)",
  467.     "           end",
  468.     "           term.setCursorPos(screenWidth - i, barY - 1)",
  469.     "           write(\"L\")",
  470.     "       end",
  471.     "   end",
  472.     "",
  473.     "   term.setBackgroundColor(colors.white)",
  474.     "   term.setTextColor(colors.black)",
  475.     "",
  476.     "   term.setCursorPos(1, screenHeight - 2)",
  477.     "   write(\"C\")",
  478.     "   term.setCursorPos(1, screenHeight - 3)",
  479.     "   write(\"W\")",
  480.     "   term.setCursorPos(1, screenHeight - 4)",
  481.     "   write(\"S\")",
  482.     "",
  483.     "   term.setCursorPos(screenWidth, screenHeight - 2)",
  484.     "   write(\"C\")",
  485.     "   term.setCursorPos(screenWidth, screenHeight - 3)",
  486.     "   write(\"W\")",
  487.     "   term.setCursorPos(screenWidth, screenHeight - 4)",
  488.     "   write(\"S\")",
  489.     "end",
  490.     "",
  491.     "function playerShooting()",
  492.     "   while true do",
  493.     "       if (pShip.wCooldown >= 20) then",
  494.     "           if (target ~= -1) then",
  495.     "               local roomNr = target",
  496.     "               local room = eShip.rooms[roomNr]",
  497.     "",
  498.     "               local evasion = 0",
  499.     "               for roomNr2, room2 in pairs(eShip.rooms) do",
  500.     "                   if (room2.rType == \"controll\") then",
  501.     "                       evasion = (room2.level - room2.damage) * 0.05",
  502.     "                   end",
  503.     "               end",
  504.     "",
  505.     "               local dDamage = 0",
  506.     "               for roomNr2, room2 in pairs(pShip.rooms) do",
  507.     "                   if (room2.rType == \"weapons\") then",
  508.     "                       dDamage = math.ceil((room2.level - room2.damage) / 2)",
  509.     "                   end",
  510.     "               end",
  511.     "",
  512.     "               local shieldL = 0",
  513.     "               local shieldRoomNr = -1",
  514.     "               for roomNr2, room2 in pairs(eShip.rooms) do",
  515.     "                   if (room2.rType == \"shields\") then",
  516.     "                       shieldL = room2.level - room2.damage",
  517.     "                       shieldRoomNr = roomNr2",
  518.     "                   end",
  519.     "               end",
  520.     "",
  521.     "               if (math.random() > evasion) then",
  522.     "                   if (shieldL <= 0) then",
  523.     "                       eShip.hull = eShip.hull - dDamage",
  524.     "                       room.damage = room.damage + 1",
  525.     "                   else",
  526.     "                       if (dDamage >= 2) then",
  527.     "                           eShip.rooms[shieldRoomNr].damage = eShip.rooms[shieldRoomNr].damage + 1",
  528.     "                       end",
  529.     "                   end",
  530.     "               else",
  531.     "                   miss = missTime",
  532.     "               end",
  533.     "               laserPhase = 2",
  534.     "               pShip.wCooldown = 0",
  535.     "",
  536.     "               if (repeatShot == false) then",
  537.     "                   target = -1",
  538.     "               end",
  539.     "           end",
  540.     "       end",
  541.     "       ",
  542.     "       drawBattleScreen()",
  543.     "",
  544.     "       sleep(0.2)",
  545.     "   end",
  546.     "end",
  547.     "",
  548.     "function battlePlayer()",
  549.     "   while true do",
  550.     "       drawBattleScreen()",
  551.     "",
  552.     "       local event, button, X, Y = os.pullEventRaw(\"mouse_click\")",
  553.     "       ",
  554.     "       local hit = false",
  555.     "",
  556.     "       for roomNr, room in pairs(eShip.rooms) do",
  557.     "           if (X >= x2 + room.x and X <= x2 + room.x + 2) then",
  558.     "               if (Y == y2 + room.y or Y == y2 + room.y + 1) then",
  559.     "                   target = roomNr",
  560.     "                   if (button == 1) then",
  561.     "                       repeatShot = false",
  562.     "                   else",
  563.     "                       repeatShot = true",
  564.     "                   end",
  565.     "                   hit = true",
  566.     "               end",
  567.     "           end",
  568.     "       end",
  569.     "",
  570.     "       if (hit == false) then",
  571.     "           target = -1",
  572.     "       end",
  573.     "   end",
  574.     "end",
  575.     "",
  576.     "function battleAI()",
  577.     "   while true do",
  578.     "       if (eShip.wCooldown >= 20) then",
  579.     "           local room = pShip.rooms[math.ceil(math.random(table.getn(pShip.rooms)))]",
  580.     "",
  581.     "           local evasion = 0",
  582.     "           for roomNr2, room2 in pairs(pShip.rooms) do",
  583.     "               if (room2.rType == \"controll\") then",
  584.     "                   evasion = (room2.level - room2.damage) * 0.05",
  585.     "               end",
  586.     "           end",
  587.     "",
  588.     "           local dDamage = 0",
  589.     "           for roomNr2, room2 in pairs(eShip.rooms) do",
  590.     "               if (room2.rType == \"weapons\") then",
  591.     "                   dDamage = math.ceil((room2.level - room2.damage) / 2)",
  592.     "               end",
  593.     "           end",
  594.     "",
  595.     "           local shieldL = 0",
  596.     "           local shieldRoomNr = -1",
  597.     "           for roomNr2, room2 in pairs(pShip.rooms) do",
  598.     "               if (room2.rType == \"shields\") then",
  599.     "                   shieldL = room2.level - room2.damage",
  600.     "                   shieldRoomNr = roomNr2",
  601.     "               end",
  602.     "           end",
  603.     "",
  604.     "           if (math.random() > evasion) then",
  605.     "               if (shieldL <= 0) then",
  606.     "                   pShip.hull = pShip.hull - dDamage",
  607.     "                   room.damage = room.damage + 1",
  608.     "               else",
  609.     "                   if (dDamage >= 2) then",
  610.     "                       pShip.rooms[shieldRoomNr].damage = pShip.rooms[shieldRoomNr].damage + 1",
  611.     "                   end",
  612.     "               end",
  613.     "           else",
  614.     "               miss = missTime",
  615.     "           end",
  616.     "           laserPhase = 2",
  617.     "           eShip.wCooldown = 0",
  618.     "       end",
  619.     "",
  620.     "       drawBattleScreen()",
  621.     "",
  622.     "       if (eShip.hull <= 0) then",
  623.     "           sleep(0.5)",
  624.     "           paintutils.drawImage(eShip.image_broken, x2, y2 - 1)",
  625.     "           break",
  626.     "       end",
  627.     "",
  628.     "       if (pShip.hull <= 0) then",
  629.     "           break",
  630.     "       end",
  631.     "",
  632.     "       sleep(1)",
  633.     "   end",
  634.     "end",
  635.     "",
  636.     "function repair()",
  637.     "   while true do",
  638.     "       for roomNr, room in pairs(pShip.rooms) do",
  639.     "           if (room.damage > 0) then",
  640.     "               room.repair = room.repair + 1",
  641.     "               if (room.repair > 5 * 20) then",
  642.     "                   room.repair = 0",
  643.     "                   room.damage = room.damage - 1",
  644.     "               end",
  645.     "           end",
  646.     "       end",
  647.     "",
  648.     "       for roomNr, room in pairs(eShip.rooms) do",
  649.     "           if (room.damage > 0) then",
  650.     "               room.repair = room.repair + 1",
  651.     "               if (room.repair > 5 * 20) then",
  652.     "                   room.repair = 0",
  653.     "                   room.damage = room.damage - 1",
  654.     "               end",
  655.     "           end",
  656.     "       end",
  657.     "",
  658.     "       sleep(0.2)",
  659.     "   end",
  660.     "end",
  661.     "",
  662.     "function setShipPlayer(ship)",
  663.     "   pShip = deepCopy(ship)",
  664.     "   pShip.hull = pShip.maxHull",
  665.     "end",
  666.     "",
  667.     "function setShipAI(tier)",
  668.     "   local eShipType = math.random(1, 5) + 5 * (tier - 1)",
  669.     "   eShip = deepCopy(eShips[eShipType])",
  670.     "   eShip.hull = eShip.maxHull",
  671.     "end",
  672.     "",
  673.     "function battle(tier)",
  674.     "   setShipAI(tier)",
  675.     "   for roomNr, room in pairs(pShip.rooms) do",
  676.     "       room.damage = 0",
  677.     "   end",
  678.     "   target = -1",
  679.     "",
  680.     "   drawSpaceBackground()",
  681.     "   parallel.waitForAny(battlePlayer, battleAI, drawBattle, repair, playerShooting)",
  682.     "",
  683.     "   if (eShip.hull <= 0) then",
  684.     "       sleep(0.5)",
  685.     "       paintutils.drawFilledBox(4, 3, screenWidth - 3, screenHeight - 2, colors.gray)",
  686.     "       term.setTextColor(colors.lime)",
  687.     "",
  688.     "       term.setCursorPos(5, 4)",
  689.     "       write(\"The enemy has been defeated.\")",
  690.     "",
  691.     "       term.setCursorPos(5, 5)",
  692.     "       write(\"You try to find some scrap.\")",
  693.     "",
  694.     "       term.setCursorPos(5, 7)",
  695.     "       write(\"You found some scrap: \"..scrapSymbol..\" \"..math.ceil(eShip.maxHull * 1.3))",
  696.     "",
  697.     "       if (getRoomLevel(\"controll\", \"player\") > 0 and math.random(1, 15) <= 1) then",
  698.     "           term.setCursorPos(5, 9)",
  699.     "           write(\"You found an upgrade for the Controll room.\")",
  700.     "           upgrade(\"controll\")",
  701.     "       elseif (getRoomLevel(\"weapons\", \"player\") > 0 and math.random(1, 14) <= 1) then",
  702.     "           term.setCursorPos(5, 9)",
  703.     "           write(\"You found an upgrade for the Weapons room.\")",
  704.     "           upgrade(\"weapons\")",
  705.     "       end",
  706.     "",
  707.     "       scrap = scrap + math.ceil(eShip.maxHull * 1.3)",
  708.     "       score = score + 5 * tier",
  709.     "",
  710.     "       loadInfo()",
  711.     "       killCount = killCount + 1",
  712.     "       saveInfo()",
  713.     "",
  714.     "       sleep(0.5)",
  715.     "       os.pullEventRaw()",
  716.     "   end",
  717.     "end",
  718.     "",
  719.     "function generateWorld()",
  720.     "   world = {}",
  721.     "   for x = -49, 51 do",
  722.     "       local colomn = {}",
  723.     "       for y = -49, 51 do",
  724.     "           local random = math.random(0, 10)",
  725.     "           local cInfo",
  726.     "",
  727.     "           if (random == 10) then",
  728.     "               local fuelForSale = 4 + math.random(1, 4)",
  729.     "               cInfo = {3, {fuelForSale, math.random(-1, 2), math.random(-1, 2), math.random(-1, 2)}}",
  730.     "           elseif (random >= 4) then",
  731.     "               cInfo = 2",
  732.     "           else",
  733.     "               cInfo = 0",
  734.     "           end",
  735.     "",
  736.     "           colomn[y + 50] = cInfo",
  737.     "       end",
  738.     "       world[x + 50] = colomn",
  739.     "   end",
  740.     "end",
  741.     "",
  742.     "function drawWorld()",
  743.     "   drawSpaceBackground()",
  744.     "   term.setTextColor(colors.black)",
  745.     "",
  746.     "   for x = playerX - 4, playerX + 4 do",
  747.     "       for y = playerY - 2, playerY + 2 do",
  748.     "           local cInfo = world[x + 50][y + 50]",
  749.     "",
  750.     "           local cType = 0",
  751.     "           if (type(cInfo) == \"table\") then",
  752.     "               cType = cInfo[1]",
  753.     "           else",
  754.     "               cType = cInfo",
  755.     "           end",
  756.     "",
  757.     "           if (x == playerX and y == playerY) then",
  758.     "               term.setBackgroundColor(colors.white)",
  759.     "           else",
  760.     "               if (cType == 0) then",
  761.     "                   term.setBackgroundColor(colors.gray)",
  762.     "               elseif (cType == 1) then",
  763.     "                   term.setBackgroundColor(colors.lime)",
  764.     "               elseif (cType == 2) then",
  765.     "                   term.setBackgroundColor(colors.red)",
  766.     "               elseif (cType == 3) then",
  767.     "                   term.setBackgroundColor(colors.blue)",
  768.     "               end",
  769.     "           end",
  770.     "",
  771.     "           term.setCursorPos(math.ceil(screenWidth / 2) + (x - playerX) * 6 - 1, math.ceil(screenHeight / 2) + (y - playerY) * 4 - 1)",
  772.     "           write(\"   \")",
  773.     "           term.setCursorPos(math.ceil(screenWidth / 2) + (x - playerX) * 6 - 1, math.ceil(screenHeight / 2) + (y - playerY) * 4)",
  774.     "           write(\"   \")",
  775.     "           term.setCursorPos(math.ceil(screenWidth / 2) + (x - playerX) * 6 - 1    , math.ceil(screenHeight / 2) + (y - playerY) * 4 + 1)",
  776.     "           write(\"   \")",
  777.     "       end",
  778.     "   end",
  779.     "",
  780.     "   drawHullBarPlayer(1, 1, pShip.hull, pShip.maxHull)",
  781.     "",
  782.     "   term.setBackgroundColor(colors.gray)",
  783.     "   term.setTextColor(colors.lime)",
  784.     "",
  785.     "   term.setCursorPos(screenWidth - string.len(\"Scrap: \"..scrapSymbol..\" \"..scrap) + 1, 1)",
  786.     "   write(\"Scrap: \"..scrapSymbol..\" \"..scrap)",
  787.     "",
  788.     "   term.setCursorPos(screenWidth - string.len(\"Fuel: \"..fuel) + 1, 2)",
  789.     "   write(\"Fuel: \"..fuel)",
  790.     "",
  791.     "   term.setCursorPos(1, screenHeight)",
  792.     "   write(\"Save and exit\")",
  793.     "end",
  794.     "",
  795.     "function move()",
  796.     "   drawWorld()",
  797.     "   while true do",
  798.     "       local event, button, X, Y = os.pullEventRaw(\"mouse_click\")",
  799.     "",
  800.     "       if (button == 1) then",
  801.     "           if (X >= math.ceil(screenWidth / 2) - 6 - 1 and X < math.ceil(screenWidth / 2) - 6 - 1 + 3) then",
  802.     "               if (Y >= math.ceil(screenHeight / 2) - 1 and Y <= math.ceil(screenHeight / 2) - 1 + 3) then",
  803.     "                   local cInfo = world[playerX + 50][playerY + 50]",
  804.     "",
  805.     "                   if (type(cInfo) ~= \"table\") then",
  806.     "                       if (cInfo ~= 3) then",
  807.     "                           world[playerX + 50][playerY + 50] = 1",
  808.     "                       end",
  809.     "                   end",
  810.     "",
  811.     "                   playerX = playerX - 1",
  812.     "                   break",
  813.     "               end",
  814.     "           elseif (X >= math.ceil(screenWidth / 2) - 1 and X < math.ceil(screenWidth / 2) - 1 + 3) then",
  815.     "               if (Y >= math.ceil(screenHeight / 2) - 4 - 1 and Y <= math.ceil(screenHeight / 2) - 4 - 1 + 3) then",
  816.     "                   local cInfo = world[playerX + 50][playerY + 50]",
  817.     "",
  818.     "                   if (type(cInfo) ~= \"table\") then",
  819.     "                       if (cInfo ~= 3) then",
  820.     "                           world[playerX + 50][playerY + 50] = 1",
  821.     "                       end",
  822.     "                   end",
  823.     "",
  824.     "                   playerY = playerY - 1",
  825.     "                   break",
  826.     "               elseif (Y >= math.ceil(screenHeight / 2) + 4 - 1 and Y <= math.ceil(screenHeight / 2) + 4 - 1 + 3) then",
  827.     "                   local cInfo = world[playerX + 50][playerY + 50]",
  828.     "",
  829.     "                   if (type(cInfo) ~= \"table\") then",
  830.     "                       if (cInfo ~= 3) then",
  831.     "                           world[playerX + 50][playerY + 50] = 1",
  832.     "                       end",
  833.     "                   end",
  834.     "",
  835.     "                   playerY = playerY + 1",
  836.     "                   break",
  837.     "               end",
  838.     "           elseif (X >= math.ceil(screenWidth / 2) + 6 - 1 and X < math.ceil(screenWidth / 2) + 6 - 1 + 3) then",
  839.     "               if (Y >= math.ceil(screenHeight / 2) - 1 and Y <= math.ceil(screenHeight / 2) - 1 + 3) then",
  840.     "                   local cInfo = world[playerX + 50][playerY + 50]",
  841.     "",
  842.     "                   if (type(cInfo) ~= \"table\") then",
  843.     "                       if (cInfo ~= 3) then",
  844.     "                           world[playerX + 50][playerY + 50] = 1",
  845.     "                       end",
  846.     "                   end",
  847.     "",
  848.     "                   playerX = playerX + 1",
  849.     "                   break",
  850.     "               end",
  851.     "           elseif (Y == screenHeight and X <= string.len(\"Save and exit\")) then",
  852.     "               saveGame()",
  853.     "               stop = true",
  854.     "               break",
  855.     "           end",
  856.     "       end",
  857.     "   end",
  858.     "   fuel = fuel - 1",
  859.     "end",
  860.     "",
  861.     "function upgradePrice(room)",
  862.     "   local level = getRoomLevel(room, \"player\")",
  863.     "   if (room == \"shields\") then",
  864.     "       level = level * 5",
  865.     "   end",
  866.     "   local price = math.floor(5 + 0.7 * level ^ 2)",
  867.     "   return price",
  868.     "end",
  869.     "",
  870.     "function upgrade(roomT)",
  871.     "   for roomNr, room in pairs(pShip.rooms) do",
  872.     "       if (room.rType == roomT) then",
  873.     "           room.level = room.level + 1",
  874.     "           break",
  875.     "       end",
  876.     "   end",
  877.     "end",
  878.     "",
  879.     "function getRoomLevel(roomT, ship)",
  880.     "   local level = 0",
  881.     "",
  882.     "   if (ship == \"player\") then",
  883.     "       for roomNr, room in pairs(pShip.rooms) do",
  884.     "           if (room.rType == roomT) then",
  885.     "               level = room.level - room.damage",
  886.     "               break",
  887.     "           end",
  888.     "       end",
  889.     "   elseif (ship == \"enemy\") then",
  890.     "       for roomNr, room in pairs(eShip.rooms) do",
  891.     "           if (room.rType == roomT) then",
  892.     "               level = room.level - room.damage",
  893.     "               break",
  894.     "           end",
  895.     "       end",
  896.     "   end",
  897.     "",
  898.     "   return level",
  899.     "end",
  900.     "",
  901.     "function drawNiceBorder(x1, y1, x2, y2, bg, fg)",
  902.     "   paintutils.drawFilledBox(x1 + 1, y1 + 1, x2 - 1, y2 - 1, colors.gray)",
  903.     "",
  904.     "   for i = x1 + 1, x2 - 1 do",
  905.     "       term.setBackgroundColor(bg)",
  906.     "       term.setTextColor(fg)",
  907.     "       term.setCursorPos(i, y1)",
  908.     "       write(string.char(131))",
  909.     "   end",
  910.     "   for i = x1 + 1, x2 - 1 do",
  911.     "       term.setBackgroundColor(fg)",
  912.     "       term.setTextColor(bg)",
  913.     "       term.setCursorPos(i, y2)",
  914.     "       write(string.char(143))",
  915.     "   end",
  916.     "   for i = y1 + 1, y2 - 1 do",
  917.     "       term.setBackgroundColor(bg)",
  918.     "       term.setTextColor(fg)",
  919.     "       term.setCursorPos(x1, i)",
  920.     "       write(string.char(149))",
  921.     "   end",
  922.     "   for i = y1 + 1, y2 - 1 do",
  923.     "       term.setBackgroundColor(fg)",
  924.     "       term.setTextColor(bg)",
  925.     "       term.setCursorPos(x2, i)",
  926.     "       write(string.char(149))",
  927.     "   end",
  928.     "",
  929.     "   term.setCursorPos(x1, y1)",
  930.     "   term.setBackgroundColor(bg)",
  931.     "   term.setTextColor(fg)",
  932.     "   write(string.char(151))",
  933.     "",
  934.     "   term.setCursorPos(x1, y2)",
  935.     "   term.setBackgroundColor(fg)",
  936.     "   term.setTextColor(bg)",
  937.     "   write(string.char(138))",
  938.     "",
  939.     "   term.setCursorPos(x2, y1)",
  940.     "   term.setBackgroundColor(fg)",
  941.     "   term.setTextColor(bg)",
  942.     "   write(string.char(148))",
  943.     "",
  944.     "   term.setCursorPos(x2, y2)",
  945.     "   term.setBackgroundColor(fg)",
  946.     "   term.setTextColor(bg)",
  947.     "   write(string.char(133))",
  948.     "end",
  949.     "",
  950.     "function drawBorder(close)",
  951.     "   drawNiceBorder(4, 3, screenWidth - 3, screenHeight - 2, colors.gray, colors.lime)",
  952.     "",
  953.     "   if (close) then",
  954.     "       term.setBackgroundColor(colors.red)",
  955.     "       term.setTextColor(colors.white)",
  956.     "       term.setCursorPos(screenWidth - 3, 3)",
  957.     "       write(\"X\")",
  958.     "   end",
  959.     "end",
  960.     "",
  961.     "function drawShop(fuelForSale, c, w, s)",
  962.     "   term.setBackgroundColor(colors.gray)",
  963.     "   term.setTextColor(colors.lime)",
  964.     "   ",
  965.     "   term.setCursorPos(5, 4)",
  966.     "   write(\"Shop:\")",
  967.     "",
  968.     "   term.setCursorPos(5, 6)",
  969.     "   write(\"Fuel: \"..fuelForSale..\" (\"..scrapSymbol..\" 2)\")",
  970.     "",
  971.     "   term.setCursorPos(5, 8)",
  972.     "   write(\"Repair: 1 (\"..scrapSymbol..\" 1)\")",
  973.     "",
  974.     "   local x = 5",
  975.     "",
  976.     "   if (c <= 0 and getRoomLevel(\"controll\", \"player\") > 0) then",
  977.     "       term.setBackgroundColor(colors.gray)",
  978.     "       term.setTextColor(colors.lime)",
  979.     "       term.setCursorPos(x, 11)",
  980.     "       write(\"Controll\")",
  981.     "       term.setCursorPos(x, 13)",
  982.     "       write(scrapSymbol..\" \"..upgradePrice(\"controll\"))",
  983.     "       term.setCursorPos(x, 14)",
  984.     "       write(\"Current:\"..getRoomLevel(\"controll\", \"player\"))",
  985.     "",
  986.     "       term.setBackgroundColor(colors.lime)",
  987.     "       term.setTextColor(colors.black)",
  988.     "       term.setCursorPos(x, 12)",
  989.     "       write(\"[Upgrade]\")",
  990.     "       x = x + 10",
  991.     "   end",
  992.     "",
  993.     "   if (w <= 0 and getRoomLevel(\"weapons\", \"player\") > 0) then",
  994.     "       term.setBackgroundColor(colors.gray)",
  995.     "       term.setTextColor(colors.lime)",
  996.     "       term.setCursorPos(x, 11)",
  997.     "       write(\"Weapons\")",
  998.     "       term.setCursorPos(x, 13)",
  999.     "       write(scrapSymbol..\" \"..upgradePrice(\"weapons\"))",
  1000.     "       term.setCursorPos(x, 14)",
  1001.     "       write(\"Current:\"..getRoomLevel(\"weapons\", \"player\"))",
  1002.     "",
  1003.     "       term.setBackgroundColor(colors.lime)",
  1004.     "       term.setTextColor(colors.black)",
  1005.     "       term.setCursorPos(x, 12)",
  1006.     "       write(\"[Upgrade]\")",
  1007.     "       x = x + 10",
  1008.     "   end",
  1009.     "",
  1010.     "   if (s <= 0 and getRoomLevel(\"shields\", \"player\") > 0) then",
  1011.     "       term.setBackgroundColor(colors.gray)",
  1012.     "       term.setTextColor(colors.lime)",
  1013.     "       term.setCursorPos(x, 11)",
  1014.     "       write(\"Shields\")",
  1015.     "       term.setCursorPos(x, 13)",
  1016.     "       write(scrapSymbol..\" \"..upgradePrice(\"shields\"))",
  1017.     "       term.setCursorPos(x, 14)",
  1018.     "       write(\"Current:\"..getRoomLevel(\"shields\", \"player\"))",
  1019.     "",
  1020.     "       term.setBackgroundColor(colors.lime)",
  1021.     "       term.setTextColor(colors.black)",
  1022.     "       term.setCursorPos(x, 12)",
  1023.     "       write(\"[Upgrade]\")",
  1024.     "       x = x + 10",
  1025.     "   end",
  1026.     "",
  1027.     "   term.setBackgroundColor(colors.lime)",
  1028.     "   term.setTextColor(colors.black)",
  1029.     "",
  1030.     "   term.setCursorPos(5, 7)",
  1031.     "   write(\"[ BUY ]\")",
  1032.     "",
  1033.     "   term.setCursorPos(5, 9)",
  1034.     "   write(\"[ BUY ]\")",
  1035.     "",
  1036.     "   drawHullBarPlayer(1, 1, pShip.hull, pShip.maxHull)",
  1037.     "",
  1038.     "   term.setBackgroundColor(colors.gray)",
  1039.     "   term.setTextColor(colors.lime)",
  1040.     "",
  1041.     "   term.setCursorPos(screenWidth - string.len(\"Fuel: \"..fuel), 2)",
  1042.     "   write(\" Fuel: \"..fuel)",
  1043.     "",
  1044.     "   term.setCursorPos(screenWidth - string.len(\"Scrap: \"..scrapSymbol..\" \"..scrap), 1)",
  1045.     "   write(\" Scrap: \"..scrapSymbol..\" \"..scrap)",
  1046.     "end",
  1047.     "",
  1048.     "function shop(shopInfo)",
  1049.     "   drawBorder(true)",
  1050.     "",
  1051.     "   while true do",
  1052.     "       drawShop(shopInfo[1], shopInfo[2], shopInfo[3], shopInfo[4])",
  1053.     "",
  1054.     "       local event, button, X, Y = os.pullEventRaw(\"mouse_click\")",
  1055.     "",
  1056.     "       if (button == 1) then",
  1057.     "           if (X >= 5 and X <= 11 and Y == 7) then",
  1058.     "               if (scrap >= 2 and shopInfo[1] >= 1) then",
  1059.     "                   scrap = scrap - 2",
  1060.     "                   fuel = fuel + 1",
  1061.     "                   shopInfo[1] = shopInfo[1] - 1",
  1062.     "               end",
  1063.     "           elseif (X >= 5 and X <= 11 and Y == 9) then",
  1064.     "               if (scrap >= 1) then",
  1065.     "                   if (pShip.hull < pShip.maxHull) then",
  1066.     "                       scrap = scrap - 1",
  1067.     "                       pShip.hull = pShip.hull + 1",
  1068.     "                   end",
  1069.     "               end",
  1070.     "           elseif (Y == 12) then",
  1071.     "               local spaces = {}",
  1072.     "",
  1073.     "               if (shopInfo[2] <= 0 and getRoomLevel(\"controll\", \"player\") > 0) then",
  1074.     "                   table.insert(spaces, \"controll\")",
  1075.     "               end",
  1076.     "               if (shopInfo[3] <= 0 and getRoomLevel(\"weapons\", \"player\") > 0) then",
  1077.     "                   table.insert(spaces, \"weapons\")",
  1078.     "               end",
  1079.     "               if (shopInfo[4] <= 0 and getRoomLevel(\"shields\", \"player\") > 0) then",
  1080.     "                   table.insert(spaces, \"shields\")",
  1081.     "               end",
  1082.     "",
  1083.     "               if (X >= 5 and X < 5 + 9) then",
  1084.     "                   if (table.getn(spaces) >= 1) then",
  1085.     "                       if (spaces[1] == \"controll\") then",
  1086.     "                           if (scrap >= upgradePrice(spaces[1])) then",
  1087.     "                               scrap = scrap - upgradePrice(spaces[1])",
  1088.     "                               upgrade(spaces[1])",
  1089.     "                           end",
  1090.     "                       elseif (spaces[1] == \"weapons\") then",
  1091.     "                           if (scrap >= upgradePrice(spaces[1])) then",
  1092.     "                               scrap = scrap - upgradePrice(spaces[1])",
  1093.     "                               upgrade(spaces[1])",
  1094.     "                           end",
  1095.     "                       elseif (spaces[1] == \"shields\") then",
  1096.     "                           if (scrap >= upgradePrice(spaces[1])) then",
  1097.     "                               scrap = scrap - upgradePrice(spaces[1])",
  1098.     "                               upgrade(spaces[1])",
  1099.     "                           end",
  1100.     "                       end",
  1101.     "                   end",
  1102.     "               elseif (X >= 5 + 10 and X < 5 + 9 + 10) then",
  1103.     "                   if (table.getn(spaces) >= 2) then",
  1104.     "                       if (spaces[2] == \"controll\") then",
  1105.     "                           if (scrap >= upgradePrice(spaces[2])) then",
  1106.     "                               scrap = scrap - upgradePrice(spaces[2])",
  1107.     "                               upgrade(spaces[2])",
  1108.     "                           end",
  1109.     "                       elseif (spaces[2] == \"weapons\") then",
  1110.     "                           if (scrap >= upgradePrice(spaces[2])) then",
  1111.     "                               scrap = scrap - upgradePrice(spaces[2])",
  1112.     "                               upgrade(spaces[2])",
  1113.     "                           end",
  1114.     "                       elseif (spaces[2] == \"shields\") then",
  1115.     "                           if (scrap >= upgradePrice(spaces[2])) then",
  1116.     "                               scrap = scrap - upgradePrice(spaces[2])",
  1117.     "                               upgrade(spaces[2])",
  1118.     "                           end",
  1119.     "                       end",
  1120.     "                   end",
  1121.     "               elseif (X >= 5 + 10 and X < 5 + 9 + 20) then",
  1122.     "                   if (table.getn(spaces) >= 3) then",
  1123.     "                       if (spaces[3] == \"controll\") then",
  1124.     "                           if (scrap >= upgradePrice(spaces[3])) then",
  1125.     "                               scrap = scrap - upgradePrice(spaces[3])",
  1126.     "                               upgrade(spaces[3])",
  1127.     "                           end",
  1128.     "                       elseif (spaces[3] == \"weapons\") then",
  1129.     "                           if (scrap >= upgradePrice(spaces[3])) then",
  1130.     "                               scrap = scrap - upgradePrice(spaces[3])",
  1131.     "                               upgrade(spaces[3])",
  1132.     "                           end",
  1133.     "                       elseif (spaces[3] == \"shields\") then",
  1134.     "                           if (scrap >= upgradePrice(spaces[3])) then",
  1135.     "                               scrap = scrap - upgradePrice(spaces[3])",
  1136.     "                               upgrade(spaces[3])",
  1137.     "                           end",
  1138.     "                       end",
  1139.     "                   end",
  1140.     "               end",
  1141.     "           elseif (X == screenWidth - 3) then",
  1142.     "               if (Y == 3) then",
  1143.     "                   break",
  1144.     "               end",
  1145.     "           end",
  1146.     "       end",
  1147.     "   end",
  1148.     "end",
  1149.     "",
  1150.     "function gameLost()",
  1151.     "   fs.delete(\"saveFile.sav\")",
  1152.     "",
  1153.     "   drawBorder(false)",
  1154.     "",
  1155.     "   term.setBackgroundColor(colors.gray)",
  1156.     "   term.setTextColor(colors.lime)",
  1157.     "   ",
  1158.     "   term.setCursorPos(5, 4)",
  1159.     "   textutils.slowWrite(\"You have failed in your mission to save the\")",
  1160.     "   term.setCursorPos(5, 5)",
  1161.     "   textutils.slowWrite(\"universe...\")",
  1162.     "",
  1163.     "   term.setCursorPos(5, 7)",
  1164.     "   textutils.slowWrite(\"Your score is: \"..score)",
  1165.     "   sleep(0.5)",
  1166.     "   os.pullEventRaw()",
  1167.     "end",
  1168.     "",
  1169.     "function newGame(ship)",
  1170.     "   scrap = 0",
  1171.     "   fuel = 15",
  1172.     "   score = 0",
  1173.     "",
  1174.     "   generateWorld()",
  1175.     "   setShipPlayer(ship)",
  1176.     "end",
  1177.     "",
  1178.     "function saveGame()",
  1179.     "   local info = {scrap = scrap, fuel = fuel, score = score, playerX = playerX, playerY = playerY, world = world, pShip = pShip}",
  1180.     "",
  1181.     "   local file = fs.open(\"saveFile.sav\", \"w\")",
  1182.     "   file.write(textutils.serialize(info))",
  1183.     "   file.close()",
  1184.     "end",
  1185.     "",
  1186.     "function loadGame()",
  1187.     "   local file = fs.open(\"saveFile.sav\", \"r\")",
  1188.     "   local data = file.readAll()",
  1189.     "   file.close()",
  1190.     "   local info = textutils.unserialize(data)",
  1191.     "",
  1192.     "   scrap = info.scrap",
  1193.     "   fuel = info.fuel",
  1194.     "   score = info.score",
  1195.     "   playerX = info.playerX",
  1196.     "   playerY = info.playerY",
  1197.     "   world = info.world",
  1198.     "   pShip = info.pShip",
  1199.     "end",
  1200.     "",
  1201.     "function saveInfo()",
  1202.     "   local info = {unlockedShips = unlockedShips, killCount = killCount}",
  1203.     "",
  1204.     "   local file = fs.open(\"info.sav\", \"w\")",
  1205.     "   file.write(textutils.serialize(info))",
  1206.     "   file.close()",
  1207.     "end",
  1208.     "",
  1209.     "function loadInfo()",
  1210.     "   if (fs.exists(\"info.sav\")) then",
  1211.     "       local file = fs.open(\"info.sav\", \"r\")",
  1212.     "       local data = file.readAll()",
  1213.     "       file.close()",
  1214.     "       local info = textutils.unserialize(data)",
  1215.     "",
  1216.     "       unlockedShips = info.unlockedShips",
  1217.     "       killCount = info.killCount",
  1218.     "   else",
  1219.     "       unlockedShips = {}",
  1220.     "       for shipNr, ship in pairs(pShips) do",
  1221.     "           if (shipNr == 1) then",
  1222.     "               unlockedShips[shipNr] = true",
  1223.     "           else",
  1224.     "               unlockedShips[shipNr] = false",
  1225.     "           end",
  1226.     "       end",
  1227.     "       killCount = 0",
  1228.     "   end",
  1229.     "end",
  1230.     "",
  1231.     "function unlock(shipNr)",
  1232.     "   loadInfo()",
  1233.     "   ",
  1234.     "   if (unlockedShips[shipNr] == false) then",
  1235.     "       local width = 25",
  1236.     "       local height = 3",
  1237.     "       drawNiceBorder(screenWidth - width, 2, screenWidth - 1, height + 1, colors.gray, colors.lime)",
  1238.     "       ",
  1239.     "       term.setBackgroundColor(colors.black)",
  1240.     "       term.setTextColor(colors.red)",
  1241.     "       term.setCursorPos(screenWidth - width + 1, 3)",
  1242.     "       write(string.char(187))",
  1243.     "",
  1244.     "       term.setBackgroundColor(colors.gray)",
  1245.     "       term.setTextColor(colors.lime)",
  1246.     "       term.setCursorPos(screenWidth - width + 1 + 2, 3)",
  1247.     "       write(\"New ship unlocked!\")",
  1248.     "",
  1249.     "       unlockedShips[shipNr] = true",
  1250.     "       saveInfo()",
  1251.     "",
  1252.     "       sleep(0.5)",
  1253.     "       os.pullEventRaw()",
  1254.     "   end",
  1255.     "end",
  1256.     "",
  1257.     "function play()",
  1258.     "   while true do",
  1259.     "       if (fuel >= 0 and pShip.hull > 0) then",
  1260.     "           move()",
  1261.     "           saveGame()",
  1262.     "",
  1263.     "           if (stop == true) then",
  1264.     "               stop = false",
  1265.     "               break",
  1266.     "           end",
  1267.     "",
  1268.     "           local cInfo = world[playerX + 50][playerY + 50]",
  1269.     "",
  1270.     "           local cType = 0",
  1271.     "           if (type(cInfo) == \"table\") then",
  1272.     "               cType = cInfo[1]",
  1273.     "           else",
  1274.     "               cType = cInfo",
  1275.     "           end",
  1276.     "",
  1277.     "           if (cType == 2) then",
  1278.     "               battle(math.floor(math.sqrt(math.abs(playerX) ^ 2 + math.abs(playerY) ^ 2) / 10) + 1)",
  1279.     "",
  1280.     "               loadInfo()",
  1281.     "               if (killCount >= 2) then",
  1282.     "                   unlock(2)",
  1283.     "               end",
  1284.     "           elseif (cType == 3) then",
  1285.     "               shop(cInfo[2])",
  1286.     "           end",
  1287.     "       else",
  1288.     "           gameLost()",
  1289.     "           break",
  1290.     "       end",
  1291.     "   end",
  1292.     "end",
  1293.     "",
  1294.     "function startScene()",
  1295.     "   term.setBackgroundColor(colors.white)",
  1296.     "   term.clear()",
  1297.     "   sleep(0.5)",
  1298.     "   term.setBackgroundColor(colors.lightGray)",
  1299.     "   term.clear()",
  1300.     "   sleep(0.2)",
  1301.     "   term.setBackgroundColor(colors.gray)",
  1302.     "   term.clear()",
  1303.     "   sleep(0)",
  1304.     "   term.setBackgroundColor(colors.black)",
  1305.     "   term.clear()",
  1306.     "   sleep(1)",
  1307.     "",
  1308.     "   term.setTextColor(colors.lime)",
  1309.     "   local speed = 15",
  1310.     "",
  1311.     "   term.setCursorPos(2, 2)",
  1312.     "   textutils.slowWrite(\"An evil lord has taken over the universe...\", speed)",
  1313.     "   sleep(0.7)",
  1314.     "   term.setCursorPos(2, 3)",
  1315.     "   textutils.slowWrite(\"It's your duty to slay his troops and free the\", speed)",
  1316.     "   term.setCursorPos(2, 4)",
  1317.     "   textutils.slowWrite(\"citizens!\", speed)",
  1318.     "   sleep(0.5)",
  1319.     "   term.setCursorPos(2, 5)",
  1320.     "   textutils.slowWrite(\"We have prepared a spaceship for you.\", speed)",
  1321.     "   sleep(0.5)",
  1322.     "   term.setCursorPos(2, 7)",
  1323.     "   textutils.slowWrite(\"Good luck!\", speed)",
  1324.     "",
  1325.     "   os.pullEventRaw()",
  1326.     "end",
  1327.     "",
  1328.     "function drawHangar(ship)",
  1329.     "   drawSpaceBackground()",
  1330.     "",
  1331.     "   term.setBackgroundColor(colors.gray)",
  1332.     "   term.setTextColor(colors.lime)",
  1333.     "",
  1334.     "   term.setCursorPos(1, 1)",
  1335.     "   write(\"< Back\")",
  1336.     "",
  1337.     "   term.setCursorPos(8, 1)",
  1338.     "   write(ship.name)",
  1339.     "",
  1340.     "   term.setCursorPos(screenWidth - string.len(\"Start Game >\") + 1, 1)",
  1341.     "   write(\"Start Game >\")",
  1342.     "",
  1343.     "   term.setCursorPos(math.floor(screenWidth / 2) - math.floor(string.len(\"  <  \") / 2) + 1 - 3, screenHeight)",
  1344.     "   write(\"  <  \")",
  1345.     "",
  1346.     "   term.setCursorPos(math.floor(screenWidth / 2) - math.floor(string.len(\"  >  \") / 2) + 1 + 3, screenHeight)",
  1347.     "   write(\"  >  \")",
  1348.     "",
  1349.     "   drawHullBarPlayer(1, 3, ship.maxHull, ship.maxHull)",
  1350.     "",
  1351.     "   term.setBackgroundColor(colors.white)",
  1352.     "   term.setTextColor(colors.black)",
  1353.     "",
  1354.     "   term.setCursorPos(1, 5)",
  1355.     "   write(\"C\")",
  1356.     "   term.setCursorPos(1, 6)",
  1357.     "   write(\"W\")",
  1358.     "   term.setCursorPos(1, 7)",
  1359.     "   write(\"S\")",
  1360.     "",
  1361.     "   local newX = 18",
  1362.     "   local newY = 7",
  1363.     "   paintutils.drawImage(ship.image, newX, newY)",
  1364.     "   for roomNr, room in pairs(ship.rooms) do",
  1365.     "       local color = colors.white",
  1366.     "       if (math.floor(room.x % 6 / 3) ~= math.floor(room.y % 4 / 2)) then",
  1367.     "           color = colors.lightGray",
  1368.     "       end",
  1369.     "",
  1370.     "       paintutils.drawFilledBox(newX + room.x, newY + room.y, newX + room.x + 2, newY + room.y + 1, color)",
  1371.     "       term.setCursorPos(newX + room.x + 1, newY + room.y)",
  1372.     "       term.setBackgroundColor(colors.black)",
  1373.     "       term.setTextColor(colors.white)",
  1374.     "",
  1375.     "       local barY = 0",
  1376.     "",
  1377.     "       if (room.rType == \"controll\") then",
  1378.     "           write(\"C\")",
  1379.     "           barY = 5",
  1380.     "       elseif (room.rType == \"weapons\") then",
  1381.     "           write(\"W\")",
  1382.     "           barY = 6",
  1383.     "       elseif (room.rType == \"shields\") then",
  1384.     "           write(\"S\")",
  1385.     "           barY = 7",
  1386.     "       else",
  1387.     "           write(\"?\")",
  1388.     "       end",
  1389.     "",
  1390.     "       term.setTextColor(colors.gray)",
  1391.     "       for i = 1, room.level do",
  1392.     "           if (i <= room.level - room.damage) then",
  1393.     "               term.setBackgroundColor(colors.lime)",
  1394.     "           else",
  1395.     "               term.setBackgroundColor(colors.red)",
  1396.     "           end",
  1397.     "           term.setCursorPos(1 + i, barY)",
  1398.     "           write(\"L\")",
  1399.     "       end",
  1400.     "   end",
  1401.     "end",
  1402.     "",
  1403.     "function hangar()",
  1404.     "   loadInfo()",
  1405.     "   local shipNr = 1",
  1406.     "",
  1407.     "   while true do",
  1408.     "       local ship = pShips[shipNr]",
  1409.     "       drawHangar(ship)",
  1410.     "",
  1411.     "       local event, button, X, Y = os.pullEventRaw(\"mouse_click\")",
  1412.     "",
  1413.     "       if (button == 1) then",
  1414.     "           if (Y == 1) then",
  1415.     "               if (X <= 6) then",
  1416.     "                   break",
  1417.     "               elseif (X >= screenWidth - 11) then",
  1418.     "                   newGame(ship)",
  1419.     "                   startScene()",
  1420.     "                   play()",
  1421.     "                   break",
  1422.     "               end",
  1423.     "           elseif (Y == screenHeight) then",
  1424.     "               if (X >= math.floor(screenWidth / 2) - 5 + 1 and X < math.floor(screenWidth / 2) + 1) then",
  1425.     "                   while true do",
  1426.     "                       shipNr = shipNr - 1",
  1427.     "                       if (shipNr < 1) then",
  1428.     "                           shipNr = table.getn(pShips)",
  1429.     "                       end",
  1430.     "",
  1431.     "                       if (unlockedShips[shipNr]) then",
  1432.     "                           break",
  1433.     "                       end",
  1434.     "                   end",
  1435.     "               elseif (X > math.floor(screenWidth / 2) + 1 and X <= math.floor(screenWidth / 2) + 5 + 1) then",
  1436.     "                   while true do",
  1437.     "                       shipNr = shipNr + 1",
  1438.     "                       if (shipNr > table.getn(pShips)) then",
  1439.     "                           shipNr = 1",
  1440.     "                       end",
  1441.     "",
  1442.     "                       if (unlockedShips[shipNr]) then",
  1443.     "                           break",
  1444.     "                       end",
  1445.     "                   end",
  1446.     "               end",
  1447.     "           end",
  1448.     "       end",
  1449.     "   end",
  1450.     "end",
  1451.     "",
  1452.     "function mainMenu()",
  1453.     "   while true do",
  1454.     "       drawSpaceBackground()",
  1455.     "       term.setBackgroundColor(colors.gray)",
  1456.     "       ",
  1457.     "       if (fs.exists(\"saveFile.sav\")) then",
  1458.     "           term.setTextColor(colors.lime)",
  1459.     "       else",
  1460.     "           term.setTextColor(colors.lightGray)",
  1461.     "       end",
  1462.     "",
  1463.     "       term.setCursorPos(math.floor(screenWidth / 2) - math.floor(string.len(\"Continue\") / 2) + 1, 5)",
  1464.     "       write(\"Continue\")",
  1465.     "",
  1466.     "       term.setTextColor(colors.lime)",
  1467.     "",
  1468.     "       term.setCursorPos(math.floor(screenWidth / 2) - math.floor(string.len(\"New Game\") / 2) + 1, 7)",
  1469.     "       write(\"New Game\")",
  1470.     "",
  1471.     "       term.setCursorPos(math.floor(screenWidth / 2) - math.floor(string.len(\"Exit\") / 2) + 1, 9)",
  1472.     "       write(\"Exit\")",
  1473.     "",
  1474.     "       local event, button, X, Y = os.pullEventRaw(\"mouse_click\")",
  1475.     "",
  1476.     "       if (button == 1) then",
  1477.     "           if (Y == 5) then",
  1478.     "               if (X >= math.floor(screenWidth / 2) - math.floor(string.len(\"Continue\") / 2) + 1 and X < math.floor(screenWidth / 2) - math.floor(string.len(\"Continue\") / 2) + 1 + string.len(\"Continue\")) then",
  1479.     "                   if (fs.exists(\"saveFile.sav\")) then",
  1480.     "                       loadGame()",
  1481.     "                       play()",
  1482.     "                   end",
  1483.     "               end",
  1484.     "           elseif (Y == 7) then",
  1485.     "               if (X >= math.floor(screenWidth / 2) - math.floor(string.len(\"New Game\") / 2) + 1 and X < math.floor(screenWidth / 2) - math.floor(string.len(\"New Game\") / 2) + 1 + string.len(\"New Game\")) then",
  1486.     "                   hangar()",
  1487.     "               end",
  1488.     "           elseif (Y == 9) then",
  1489.     "               if (X >= math.floor(screenWidth / 2) - math.floor(string.len(\"Exit\") / 2) + 1 and X < math.floor(screenWidth / 2) - math.floor(string.len(\"Exit\") / 2) + 1 + string.len(\"Exit\")) then",
  1490.     "                   term.clear()",
  1491.     "                   break",
  1492.     "               end",
  1493.     "           end",
  1494.     "       end",
  1495.     "   end",
  1496.     "end",
  1497.     "",
  1498.     "mainMenu()",
  1499.   },
  1500.   [ "/eShip6.img" ] = {
  1501.     "                 777b77",
  1502.     "               bbb   7",
  1503.     "              777b   7",
  1504.     "             7   bbbbbb",
  1505.     "             7   b77777",
  1506.     "              bbbb   7",
  1507.     "               777   7",
  1508.     "                 777b77",
  1509.   },
  1510.   [ "/eShip8.img" ] = {
  1511.     "",
  1512.     "                    7b",
  1513.     "              7777bbbb",
  1514.     "             77      7",
  1515.     "             bb      7",
  1516.     "              bbbbbbbb",
  1517.     "                    7b",
  1518.   },
  1519.   [ "/eShip13.img" ] = {
  1520.     "",
  1521.     "                977779",
  1522.     "             9999   99",
  1523.     "            7   9   9",
  1524.     "            7   9   9",
  1525.     "             9999   99",
  1526.     "                977779",
  1527.   },
  1528.   [ "/eShip12.img" ] = {
  1529.     "",
  1530.     "               9999977",
  1531.     "              99   777",
  1532.     "              77   77",
  1533.     "               77   7",
  1534.     "               99   9",
  1535.     "              77   77",
  1536.     "              99   777",
  1537.     "               9999977",
  1538.   },
  1539.   [ "/pShip2.img" ] = {
  1540.     "555ddd55",
  1541.     "d55   d555",
  1542.     " d5   5   5",
  1543.     " 55   5   d",
  1544.     "555   55dd",
  1545.     "dddddddd",
  1546.   },
  1547.   [ "/eShip14.img" ] = {
  1548.     "",
  1549.     "             999999999",
  1550.     "           999   7777",
  1551.     "          9977   77999",
  1552.     "             7777   77",
  1553.     "             ",
  1554.     "             ",
  1555.     "             7777   77",
  1556.     "          9977   77999",
  1557.     "           999   7777",
  1558.     "             999999999",
  1559.   },
  1560.   [ "/eShip2_broken.img" ] = {
  1561.     "                eeeeeeee",
  1562.     "               e1111e111f",
  1563.     "               ff1f111fff",
  1564.     "                 ffff1",
  1565.     "                 fefff",
  1566.     "               ff11e1ffff",
  1567.     "               ee11ee1eef",
  1568.     "                11111111",
  1569.   },
  1570.   [ "/eShip13_broken.img" ] = {
  1571.     "",
  1572.     "                977779",
  1573.     "             999977799f",
  1574.     "            777797f79ff",
  1575.     "            ff7fffff9",
  1576.     "            ffffff7ff",
  1577.     "            77f797779ff",
  1578.     "             999977799f",
  1579.     "                977779",
  1580.   },
  1581.   [ "/pShip1.img" ] = {
  1582.     "555555    55",
  1583.     "dddd555555d",
  1584.     "    d      5",
  1585.     "    5      d",
  1586.     "55555ddddd5",
  1587.     "ddddd     dd",
  1588.   },
  1589.   [ "/eShip12_broken.img" ] = {
  1590.     "",
  1591.     "               9999977",
  1592.     "              99777777f",
  1593.     "              7777777ff",
  1594.     "              f777777",
  1595.     "               7ff7ff",
  1596.     "               ffffff",
  1597.     "              f9ffff9",
  1598.     "              7777777ff",
  1599.     "              99777777f",
  1600.     "               9999977",
  1601.   },
  1602.   [ "/eShip1.img" ] = {
  1603.     "                eeeeeeee",
  1604.     "               e1   111",
  1605.     "              e11   e",
  1606.     "              11e   e",
  1607.     "               1e   1ee",
  1608.     "                11111111",
  1609.   },
  1610.   [ "/eShip1_broken.img" ] = {
  1611.     "                eeeeeeee",
  1612.     "               e11e1111ff",
  1613.     "              e11ef1eff",
  1614.     "              feffffff",
  1615.     "              fffff1ff",
  1616.     "              11ef11eff",
  1617.     "               1ee111eeff",
  1618.     "                11111111",
  1619.   },
  1620.   [ "/eShip2.img" ] = {
  1621.     "                eeeeeeee",
  1622.     "               e11   111",
  1623.     "                 1   1",
  1624.     "                 1   1",
  1625.     "               ee1   1ee",
  1626.     "                11111111",
  1627.   },
  1628.   [ "/eShip10_broken.img" ] = {
  1629.     "                 777b77",
  1630.     "             77bbb7f77ff",
  1631.     "            77777bff77",
  1632.     "            fffffbfffbb",
  1633.     "                 fffff7f",
  1634.     "                 ffff7ff",
  1635.     "            fffffbfff77",
  1636.     "            77bbbbf7f7",
  1637.     "             7777777f7ff",
  1638.     "                 777b77",
  1639.   },
  1640.   [ "/eShip10.img" ] = {
  1641.     "                 777b77",
  1642.     "             77bbb   7",
  1643.     "            77777b   7",
  1644.     "                 b   bb",
  1645.     "                 b   77",
  1646.     "            77bbbb   7",
  1647.     "             77777   7",
  1648.     "                 777b77",
  1649.   },
  1650.   [ "/eShip7.img" ] = {
  1651.     "",
  1652.     "               777b777",
  1653.     "              7   bbbb",
  1654.     "             77   b77",
  1655.     "             bb   b77",
  1656.     "              b   b777",
  1657.     "               bbbbbbb",
  1658.   },
  1659.   [ "/eShip14_broken.img" ] = {
  1660.     "",
  1661.     "             999999999",
  1662.     "           9997777777f",
  1663.     "          997777777999",
  1664.     "          fff7777ff777",
  1665.     "             f7fffff7ff",
  1666.     "             ffff77ffff",
  1667.     "          fff7f77777f7",
  1668.     "          997777777999",
  1669.     "           9997777777f",
  1670.     "             999999999",
  1671.   },
  1672.   [ "/eShip7_broken.img" ] = {
  1673.     "",
  1674.     "               777b777",
  1675.     "              77ffbbbbf",
  1676.     "             7ffffbf7ff",
  1677.     "             ffffffff",
  1678.     "             f7ffff7f",
  1679.     "             bbfffb77ff",
  1680.     "              bff7b777f",
  1681.     "               bbbbbbb",
  1682.   },
  1683.   [ "/info.sav" ] = {
  1684.     "{",
  1685.     "  killCount = 90,",
  1686.     "  unlockedShips = {",
  1687.     "    true,",
  1688.     "    true,",
  1689.     "  },",
  1690.     "}",
  1691.   },
  1692.   [ "/eShip3.img" ] = {
  1693.     "                 eeeeeee",
  1694.     "                e1111111",
  1695.     "              ee      1",
  1696.     "              e1      1",
  1697.     "                1eeeee1e",
  1698.     "                 1111111",
  1699.   },
  1700.   [ "/eShip9.img" ] = {
  1701.     "",
  1702.     "                77777b",
  1703.     "              777bbbbb",
  1704.     "             7      77",
  1705.     "             b      77",
  1706.     "              bbbbbbbb",
  1707.     "                77777b",
  1708.   },
  1709.   [ "/eShip9_broken.img" ] = {
  1710.     "",
  1711.     "                77777b",
  1712.     "              777bbbbbf",
  1713.     "             77ffbf777f",
  1714.     "             ffffff7fff",
  1715.     "             fff7f7ffff",
  1716.     "             bf7777f77f",
  1717.     "              bbbbbbbbf",
  1718.     "                77777b",
  1719.   },
  1720.   [ "/eShip4_broken.img" ] = {
  1721.     "                     eee",
  1722.     "               eeeeee111f",
  1723.     "              e1111f1efff",
  1724.     "              ff1effff",
  1725.     "              fffff1ff",
  1726.     "              1effe111fff",
  1727.     "               111eee1eef",
  1728.     "                     111",
  1729.   },
  1730.   [ "/eShip11.img" ] = {
  1731.     "",
  1732.     "                777779",
  1733.     "              777   79",
  1734.     "             7999   99",
  1735.     "             9   9997",
  1736.     "             7   7777",
  1737.     "             7777   79",
  1738.     "              797   79",
  1739.     "                999999",
  1740.   },
  1741.   [ "/eShip5_broken.img" ] = {
  1742.     "               eeeeeeeee",
  1743.     "              e1fff11111f",
  1744.     "              effff11efff",
  1745.     "              ffffff1f",
  1746.     "              f1ffffff",
  1747.     "              e1fffefefff",
  1748.     "              e1fffe11eef",
  1749.     "               11ee11111",
  1750.   },
  1751.   [ "/eShip5.img" ] = {
  1752.     "               eeeeeeeee",
  1753.     "              e1   11111",
  1754.     "              e1   11e",
  1755.     "              e1   e1e",
  1756.     "              e1   e11ee",
  1757.     "               11ee11111",
  1758.   },
  1759. }
  1760.  
  1761. local tArg = {...}
  1762. local outpath = ((tArg[1] ~= "") and tArg[1]) or (shell and shell.getRunningProgram() or "lightspeed")
  1763. if fs.combine("",outpath) == "rom/programs/http/pastebin" then outpath = (shell and shell.dir() or "") end
  1764.  
  1765. local progdor = fs.getName(shell.getRunningProgram())
  1766. local dir = shell.dir()
  1767.  
  1768. local yield = function()
  1769.     os.queueEvent("yield")
  1770.     os.pullEvent("yield")
  1771. end
  1772.  
  1773. -- CCA API START --
  1774.  
  1775. local bit = bit32
  1776. --[[
  1777. local function pack(bn1, bn2)
  1778.     bytes = {}
  1779.     bytes[1] = bit.band(bn1, 0xFF)
  1780.     bytes[2] = bit.rshift(bn1, 8) + bit.lshift(bit.band(bn2, 0xF), 4)
  1781.     bytes[3] = bit.rshift(bn2, 4)
  1782.     return bytes[1], bytes[2], bytes[3]
  1783. end
  1784. local function upack(b1, b2, b3)
  1785.     bn1 = b1 + bit.lshift(bit.band(b2, 0xF), 8)
  1786.     bn2 = bit.lshift(b3,4) + bit.band(bit.rshift(b2, 4), 0xF)
  1787.     return bn1, bn2
  1788. end
  1789. --]]
  1790. local function pack(bn1, bn2)
  1791.     return bit.band(bn1, 0xFF), bit.rshift(bn1, 8) + bit.lshift(bit.band(bn2, 0xF), 4), bit.rshift(bn2, 4)
  1792. end
  1793. local function upack(b1, b2, b3)
  1794.     return (b1 + bit.lshift(bit.band(b2, 0xF), 8)), (bit.lshift(b3,4) + bit.band(bit.rshift(b2, 4), 0xF))
  1795. end
  1796. local function createDict(bool)
  1797.     local ret = {}
  1798.     for i = 1, 255 do
  1799.         if bool then
  1800.             ret[string.char(i)] = i
  1801.         else
  1802.             ret[i] = string.char(i)
  1803.         end
  1804.     end
  1805.     if not bool then ret[256] = 256 end
  1806.     return ret
  1807. end
  1808. local function cp(sInput)
  1809.     local dic = createDict(true)
  1810.     local s = ""
  1811.     local ch
  1812.     local dlen = 256
  1813.     local result = {}
  1814.     local temp
  1815.     for i = 1, #sInput do
  1816.         if dlen == 4095 then
  1817.             result[#result + 1] = dic[s]
  1818.             result[#result + 1] = 256
  1819.             dic = createDict(true)
  1820.             dlen = 256
  1821.             s = ""
  1822.         end
  1823.         ch = sInput:sub(i, i)
  1824.         temp = s..ch
  1825.         if dic[temp] then
  1826.             s = temp
  1827.         else
  1828.             result[#result + 1] = dic[s]
  1829.             dlen = dlen +1
  1830.             dic[temp] = dlen       
  1831.             s = ch
  1832.         end
  1833.     end
  1834.     result[#result + 1] = dic[s]
  1835.    
  1836.     return result
  1837. end
  1838. local function dc(data)
  1839.     local dic = createDict(false)  
  1840.     local entry
  1841.     local ch
  1842.     local currCode
  1843.     local result = {}
  1844.     result[#result + 1] = dic[data[1]]
  1845.     prefix = dic[data[1]]
  1846.     for i = 2, #data do
  1847.         currCode = data[i]
  1848.         if currCode == 256 then
  1849.             dic = createDict(false)
  1850.             prefix = ""
  1851.         else
  1852.             entry = dic[currCode]
  1853.             if entry then--exists in dictionary
  1854.                 ch = entry:sub(1, 1)       
  1855.                 result[#result + 1] = entry
  1856.                 if prefix ~= "" then
  1857.                     dic[#dic+1] = prefix .. ch
  1858.                 end
  1859.             else   
  1860.                 ch = prefix:sub(1, 1)
  1861.                 result[#result + 1] = prefix..ch
  1862.                 dic[#dic + 1] = prefix..ch
  1863.             end
  1864.        
  1865.             prefix = dic[currCode]
  1866.         end
  1867.     end
  1868.    
  1869.     return table.concat(result)
  1870. end
  1871. local function trim(inp)
  1872.     for i = 0,2 do
  1873.         if inp[#inp] == 0 then
  1874.             inp[#inp] = nil
  1875.         end
  1876.     end
  1877. end
  1878. local function decompress(input)
  1879.     local rec = {}
  1880.     for i = 1, #input, 3 do
  1881.         if i % 66 == 0 then
  1882.             yield()
  1883.         end
  1884.         rec[#rec+1], rec[#rec+2] = upack(input[i], input[i+1] or 0, input[i+2] or 0)
  1885.     end
  1886.     trim(rec)
  1887.     return dc(rec)
  1888. end
  1889. local function compress(input)
  1890.     local rec = {}
  1891.     local data = cp(input)
  1892.     for i=1, #data, 2 do
  1893.         yield()
  1894.         rec[#rec+1], rec[#rec+2], rec[#rec+3] = pack(data[i], data[i+1] or 0)
  1895.     end
  1896.     trim(rec)
  1897.     return rec
  1898. end
  1899.  
  1900. -- CCA API END --
  1901.  
  1902. local explode = function(div,str)
  1903.     if (div=='') then return false end
  1904.     local pos,arr = 0,{}
  1905.     for st,sp in function() return string.find(str,div,pos,true) end do
  1906.         table.insert(arr,str:sub(pos,st-1))
  1907.         pos = sp + 1
  1908.     end
  1909.     table.insert(arr,str:sub(pos))
  1910.     return arr
  1911. end
  1912. local sanitize = function(sani,tize)
  1913.     local _,x = string.find(sani,tize)
  1914.     if x then
  1915.         return sani:sub(x+1)
  1916.     else
  1917.         return sani
  1918.     end
  1919. end
  1920. local tablize = function(input)
  1921.     if type(input) == "string" then
  1922.         return explode("\n",input)
  1923.     elseif type(input) == "table" then
  1924.         return table.concat(input,"\n")
  1925.     end
  1926. end
  1927. local compyress = function(input)
  1928.     return string.char(unpack(compress(input)))
  1929. end
  1930. local decompyress = function(input)
  1931.     local out = {}
  1932.     for a = 1, #input do
  1933.         table.insert(out,string.byte(input:sub(a,a)))
  1934.     end
  1935.     return decompress(out)
  1936. end
  1937.  
  1938. if not outpath then
  1939.     outpath = input
  1940. end
  1941.  
  1942. local choice = function(input,verbose)
  1943.     if not input then
  1944.         input = "yn"
  1945.     end
  1946.     if verbose then
  1947.         write("[")
  1948.         for a = 1, #input do
  1949.             write(input:sub(a,a):upper())
  1950.             if a < #input then
  1951.                 write(",")
  1952.             end
  1953.         end
  1954.         write("]?")
  1955.     end
  1956.     local evt,char
  1957.     repeat
  1958.         evt,char = os.pullEvent("char")
  1959.     until string.find(input:lower(),char:lower())
  1960.     if verbose then
  1961.         print(char:upper())
  1962.     end
  1963.     local pos = string.find(input:lower(),char:lower())
  1964.     return pos, char:lower()
  1965. end
  1966.  
  1967. local doPack = function(list,output,doCompress,verbose)
  1968.     local tx = term.getTextColor()
  1969.     if fs.isReadOnly(output) and (fs.combine("",output) ~= "") then return 5 end
  1970.     local packageSelf = true
  1971.     local packageReadOnly = true
  1972.     local ro_asked = false
  1973.     local ps_asked = false
  1974.     if fs.exists(output) and (not fs.isDir(output)) then
  1975.         fs.delete(output)
  1976.     end
  1977.     local amnt = 0
  1978.     for k,v in pairs(list) do
  1979.         amnt = amnt + 1
  1980.     end
  1981.     local num = 0
  1982.     for k,v in pairs(list) do
  1983.         num = num + 1
  1984.         if v == true then
  1985.             fs.makeDir(fs.combine(output,k))
  1986.         else
  1987.             local file = fs.open(fs.combine(output,k),"w")
  1988.             if verbose then
  1989.                 write("[")
  1990.                 if term.isColor() then term.setTextColor(colors.lightGray) end
  1991.                 write(k)
  1992.                 term.setTextColor(tx)
  1993.                 write("]")
  1994.             end
  1995.             if doCompress then
  1996.                 file.write(decompyress(tablize(v)))
  1997.             else
  1998.                 file.write(tablize(v))
  1999.             end
  2000.             file.close()
  2001.             local tx = term.getTextColor()
  2002.             if fs.getName(k):lower() == "peasant" then
  2003.                 if term.isColor() then
  2004.                     term.setTextColor(colors.orange)
  2005.                 end
  2006.                 print(" UNBURNINATED")
  2007.             else
  2008.                 if term.isColor() then
  2009.                     term.setTextColor(colors.green)
  2010.                 end
  2011.                 print(" GOOD")
  2012.             end
  2013.             term.setTextColor(tx)
  2014.         end
  2015.     end
  2016.     return 2
  2017. end
  2018.  
  2019. if not fs.isDir(outpath) then
  2020.     fs.delete(outpath)
  2021. end
  2022.  
  2023. local success, res = pcall( function() return doPack(data,outpath,doCompress,true) end ) --functionized it!
  2024.  
  2025. if not success then
  2026.     term.setTextColor(colors.white)
  2027.     print("\n***Something went wrong!***")
  2028.     return printError(res)
  2029. end
  2030.  
  2031. if res then
  2032.     local msgs = {
  2033.         [2] = "Successfully unpacked '"..fullname.."' to '"..outpath.."/'",
  2034.         [5] = "You don't have permission.",
  2035.     }
  2036.     print(msgs[res])
  2037. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement