fugitiveplatypus

Cons.lua

Jun 23rd, 2013
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.47 KB | None | 0 0
  1. write("Loading Cons module... ")
  2.  
  3. Cons = {}
  4.  
  5. function Cons.fullBuilding(stone, glass, n)
  6.         Cons.buildFrom(stone, glass, 1, n)
  7. end
  8.  
  9. function Cons.buildFrom(stone, glass, stage, n)
  10.         local l = {}
  11.         while stage <= 8 and stage >= 1 do
  12.                 table.insert(l, stage)
  13.                 stage = stage + 1
  14.         end
  15.  
  16.         Cons.parts(stone, glass, l, n)
  17.  
  18. end
  19.  
  20. function Cons.parts(stone, glass, list, n)
  21.  
  22.         while table.getn(list) >= 1 do
  23.                 local t = list[1]
  24.                 table.remove(list, 1)
  25.  
  26.                 if t == 1 then
  27.                         Cons.eHallway(stone, glass)
  28.  
  29.                 elseif t == 2 then
  30.                         Gassy.go(-8, 8, 0)
  31.                         Gassy.turn(0)
  32.                         Gassy.push()
  33.  
  34.                 elseif t == 3 then
  35.                         Cons.eFloor(20, 20, stone)
  36.  
  37.                 elseif t == 4 then
  38.                         Gassy.turnRight()
  39.                         Gassy.up()
  40.  
  41.                 elseif t == 5 then
  42.                         Cons.eWalls(stone, n)
  43.  
  44.                 elseif t == 6 then
  45.                         Gassy.push()
  46.                         Cons.eCeiling(stone, glass)
  47.  
  48.                 elseif t == 7 then
  49.                         Gassy.go(8, 8, 1)
  50.  
  51.                 elseif t == 8 then
  52.                         Cons.eRectangle(4, 4, stone)
  53.  
  54.                 end
  55.         end
  56. end
  57.  
  58. function Cons.eRectangle(l, w, stone)
  59.  
  60.         for i=1, 4 do
  61.                 if i % 2 == 1 then
  62.                         Cons.eLine(l - 1, stone)
  63.                 else
  64.                         Cons.eLine(w - 1, stone)
  65.                 end
  66.                 Gassy.forward()
  67.                 Gassy.turnRight()
  68.         end
  69. end
  70.  
  71. function Cons.eCeiling(stone, glass)
  72.  
  73.         Cons.eBlueprint({
  74.                         { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
  75.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  76.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  77.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  78.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  79.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  80.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  81.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  82.                         { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
  83.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  84.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  85.                         { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
  86.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  87.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  88.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  89.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  90.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  91.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  92.                         { 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2 },
  93.                         { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }
  94.                   }, glass, bricks)
  95.  
  96. end
  97.  
  98. function Cons.eBlueprint(schema, ...)
  99.         local tempe = nil
  100.         local num = 0
  101.         local imax = table.getn(schema)
  102.         local jmax = table.getn(schema[1])
  103.         local toggle = true
  104.  
  105.         for i=1, imax do
  106.  
  107.                 for j=1, jmax do
  108.  
  109.                         if schema[i][j] ~= num then
  110.                                 num = schema[i][j]
  111.                                 if num ~= 0 then
  112.                                         tempe = arg[num]
  113.                                         tempe.sel(tempe)
  114.                                 end
  115.                         end
  116.  
  117.                         if num ~= 0 then
  118.                                 tempe.placeDown(tempe)
  119.                         end
  120.  
  121.                         if j ~= jmax then
  122.                                 Gassy.forward()
  123.                         end
  124.  
  125.                 end
  126.  
  127.                 if i ~= imax then
  128.                         if toggle then
  129.                                 Gassy.turnRight()
  130.                                 Gassy.forward()
  131.                                 Gassy.turnRight()
  132.                                 toggle = false
  133.                         else
  134.                                 Gassy.turnLeft()
  135.                                 Gassy.forward()
  136.                                 Gassy.turnLeft()
  137.                                 toggle = true
  138.                         end
  139.                 end
  140.         end
  141. end
  142.  
  143. function Cons.eWalls(stone, n)
  144.         if n == nil then
  145.                 n = 5
  146.         end
  147.         for j=1, 4 do
  148.                 for i=1, 4 do
  149.                         Cons.eLine(9, stone)
  150.                         Gassy.forward(3)
  151.                         Cons.eLine(8, stone)
  152.                         Gassy.forward()
  153.                         Gassy.turnRight()
  154.                 end
  155.                 Gassy.up()
  156.         end
  157.  
  158.         for j=1, n - 4 do
  159.                 for i=1, 4 do
  160.                         Cons.eLine(19, stone)
  161.                         Gassy.forward()
  162.                         Gassy.turnRight()
  163.                 end
  164.                 Gassy.up()
  165.         end
  166. end
  167.  
  168. function Cons.eHallway(stone, glass)
  169.  
  170.         Cons.eFloor(8, 4, stone)
  171.  
  172.         Gassy.turnRight()
  173.         Gassy.forward(3)
  174.         Gassy.turnRight()
  175.         Gassy.up()
  176.  
  177.         local tempe
  178.         for i=1, 5 do
  179.                 if i == 1 or i == 5 then
  180.                         tempe = stone
  181.                 else
  182.                         tempe = glass
  183.                 end
  184.  
  185.                 Cons.eLine(8, tempe)
  186.  
  187.                 Gassy.turnRight()
  188.                 Gassy.forward(3)
  189.                 Gassy.turnRight()
  190.  
  191.                 Cons.eLine(8, tempe)
  192.  
  193.                 if i ~= 5 then
  194.                         Gassy.turnRight()
  195.                         Gassy.forward(3)
  196.                         Gassy.turnRight()
  197.                         Gassy.up()
  198.                 end
  199.  
  200.         end
  201.         Gassy.turnRight()
  202.         Gassy.forward(2)
  203.         Gassy.turnRight()
  204.  
  205.         Cons.eFloor(8, 2, glass)
  206. end
  207.  
  208. function Cons.eFloor(l, w, e)
  209.         local toggle = true
  210.         for i=1, w do
  211.                 Cons.eLine(l, e)
  212.                 if i ~= w then
  213.                         if toggle then
  214.                                 Gassy.turnRight()
  215.                                 Gassy.forward()
  216.                                 Gassy.turnRight()
  217.                                 toggle = false
  218.                         else
  219.                                 Gassy.turnLeft()
  220.                                 Gassy.forward()
  221.                                 Gassy.turnLeft()
  222.                                 toggle = true
  223.                         end
  224.                 end
  225.         end
  226. end
  227.  
  228. function Cons.eLine(l, e)
  229.         e.sel(e)
  230.         for j=1, l do
  231.                 e.placeDown(e)
  232.                 if j ~= l then
  233.                         Gassy.forward()
  234.                 end
  235.         end
  236. end
  237.  
  238. print("Done.")
Advertisement
Add Comment
Please, Sign In to add comment