Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2017
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.88 KB | None | 0 0
  1. local north = defines.direction.north
  2. local east = defines.direction.east
  3. local south = defines.direction.south
  4. local west = defines.direction.west
  5.  
  6. local opposite = {[north] = south, [east] = west, [south] = north, [west] = east}
  7. local DX = {[north] = 0, [east] = 1, [south] = 0, [west] = -1}
  8. local DY = {[north] = -1, [east] = 0, [south] = 1, [west] = 0}
  9.  
  10. local make_connection = function(id, outside_x, outside_y, inside_x, inside_y, direction_out)
  11.     return {
  12.         id = id,
  13.         outside_x = outside_x,
  14.         outside_y = outside_y,
  15.         inside_x = inside_x,
  16.         inside_y = inside_y,
  17.         indicator_dx = DX[direction_out],
  18.         indicator_dy = DY[direction_out],
  19.         direction_in = opposite[direction_out],
  20.         direction_out = direction_out,
  21.     }
  22. end
  23.  
  24. local layout_generators = {
  25.     ["factory-1"] = function()
  26.     local size = 17
  27.     local conn = size - 0.5
  28.    
  29.         return {
  30.             name = "factory-1",
  31.             tier = 1,
  32.             inside_door_x = 0,
  33.             inside_door_y = size,
  34.             outside_door_x = 0,
  35.             outside_door_y = 4,
  36.             outside_energy_receiver_type = "factory-power-input-8",
  37.             outside_energy_sender_type = "factory-power-output-8",
  38.             inside_energy_x = -4,
  39.             inside_energy_y = size + 1,
  40.             energy_indicator_x = -3.5,
  41.             energy_indicator_y = size + 2.5,
  42.             overlay_name = "factory-1-overlay",
  43.             overlay_x = 0,
  44.             overlay_y = 3,
  45.             rectangles = {
  46.                 {
  47.                     x1 = -(size + 2), x2 = (size + 2), y1 = -(size + 2), y2 = (size + 2), tile = "out-of-factory"
  48.                 },
  49.                 {
  50.                     x1 = -size, x2 = size, y1 = -size, y2 = size, tile = "factory-wall-1"
  51.                 },
  52.                 {
  53.                     x1 = -(size - 1), x2 = (size - 1), y1 = -(size - 1), y2 = (size - 1), tile = "factory-floor-1"
  54.                 },
  55.                 {
  56.                     x1 = -3, x2 = 3, y1 = (size - 1), y2 = (size + 2), tile = "factory-wall-1"
  57.                 },
  58.                 {
  59.                     x1 = -2, x2 = 2, y1 = (size - 1), y2 = (size + 2), tile = "factory-entrance-1"
  60.                 },
  61.             },
  62.             mosaics = {
  63.                 {   x1 = -6, x2 = 6, y1 = -4, y2 = 4, tile = "factory-pattern-1",
  64.                     pattern = {
  65.                         " ++++    ++ ",
  66.                         "++  ++  +++ ",
  67.                         "++  ++ + ++ ",
  68.                         "++ +++   ++ ",
  69.                         "+++ ++   ++ ",
  70.                         "++  ++   ++ ",
  71.                         "++  ++   ++ ",
  72.                         " ++++  +++++",
  73.                     }
  74.                 },
  75.             },
  76.             lights = {
  77.                 {x = -7.5, y = -7.5},
  78.                 {x = -7.5, y = 7.5},
  79.                 {x = 7.5, y = -7.5},
  80.                 {x = 7.5, y = 7.5},
  81.             },
  82.             connection_tile = "factory-floor-1",
  83.             connections = {
  84.                 w1 = make_connection("w1", -4.5,-2.5, -conn,-9.5, west),
  85.                 w2 = make_connection("w2", -4.5,-1.5, -conn,-5.5, west),
  86.                 w3 = make_connection("w3", -4.5,1.5, -conn,5.5, west),
  87.                 w4 = make_connection("w4", -4.5,2.5, -conn,9.5, west),
  88.                
  89.                 e1 = make_connection("e1", 4.5,-2.5, conn,-9.5, east),
  90.                 e2 = make_connection("e2", 4.5,-1.5, conn,-5.5, east),
  91.                 e3 = make_connection("e3", 4.5,1.5, conn,5.5, east),
  92.                 e4 = make_connection("e4", 4.5,2.5, conn,9.5, east),
  93.                
  94.                 n1 = make_connection("n1", -2.5,-4.5, -9.5,-conn, north),
  95.                 n2 = make_connection("n2", -1.5,-4.5, -5.5,-conn, north),
  96.                 n3 = make_connection("n3", 1.5,-4.5, 5.5,-conn, north),
  97.                 n4 = make_connection("n4", 2.5,-4.5, 9.5,-conn, north),
  98.                
  99.                 s1 = make_connection("s1", -2.5,4.5, -9.5,conn, south),
  100.                 s2 = make_connection("s2", -1.5,4.5, -5.5,conn, south),
  101.                 s3 = make_connection("s3", 1.5,4.5, 5.5,conn, south),
  102.                 s4 = make_connection("s4", 2.5,4.5, 9.5,conn, south),
  103.                
  104.             },
  105.             overlays = {
  106.                 nw = {
  107.                     outside_x = -2,
  108.                     outside_y = -1,
  109.                     inside_x = 3.5,
  110.                     inside_y = size + 0.5,
  111.                 },
  112.                 ne = {
  113.                     outside_x = 2,
  114.                     outside_y = -1,
  115.                     inside_x = 4.5,
  116.                     inside_y = size + 0.5,
  117.                 },
  118.             },
  119.         }
  120.     end,
  121.     ["factory-2"] = function()
  122.     local size = 25
  123.     local conn = size - 0.5
  124.    
  125.         return {
  126.             name = "factory-2",
  127.             tier = 2,
  128.             inside_door_x = 0,
  129.             inside_door_y = size,
  130.             outside_door_x = 0,
  131.             outside_door_y = 6,
  132.             outside_energy_receiver_type = "factory-power-input-12",
  133.             outside_energy_sender_type = "factory-power-output-12",
  134.             inside_energy_x = -4,
  135.             inside_energy_y = size + 1,
  136.             energy_indicator_x = -3.5,
  137.             energy_indicator_y = size + 2.5,
  138.             overlay_name = "factory-2-overlay",
  139.             overlay_x = 0,
  140.             overlay_y = 5,
  141.             rectangles = {
  142.                 {
  143.                     x1 = -(size + 2), x2 = (size + 2), y1 = -(size + 2), y2 = (size + 2), tile = "out-of-factory"
  144.                 },
  145.                 {
  146.                     x1 = -size, x2 = size, y1 = -size, y2 = size, tile = "factory-wall-2"
  147.                 },
  148.                 {
  149.                     x1 = -(size - 1), x2 = (size - 1), y1 = -(size - 1), y2 = (size - 1), tile = "factory-floor-2"
  150.                 },
  151.                 {
  152.                     x1 = -3, x2 = 3, y1 = (size - 1), y2 = (size + 2), tile = "factory-wall-2"
  153.                 },
  154.                 {
  155.                     x1 = -2, x2 = 2, y1 = (size - 1), y2 = (size + 2), tile = "factory-entrance-2"
  156.                 },
  157.             },
  158.             mosaics = {
  159.                 {   x1 = -6, x2 = 6, y1 = -4, y2 = 4, tile = "factory-pattern-2",
  160.                     pattern = {
  161.                         " ++++   +++ ",
  162.                         "++  ++ ++ ++",
  163.                         "++  ++    ++",
  164.                         "++ +++   ++ ",
  165.                         "+++ ++  ++  ",
  166.                         "++  ++ ++   ",
  167.                         "++  ++ ++ ++",
  168.                         " ++++  +++++",
  169.                     }
  170.                 },
  171.             },
  172.             lights = {
  173.                 {x = -5.5, y = -5.5},
  174.                 {x = -5.5, y = 5.5},
  175.                 {x = 5.5, y = -5.5},
  176.                 {x = 5.5, y = 5.5},
  177.                 {x = -17.5, y = -5.5},
  178.                 {x = -17.5, y = 5.5},
  179.                 {x = 17.5, y = -5.5},
  180.                 {x = 17.5, y = 5.5},
  181.                 {x = -5.5, y = -17.5},
  182.                 {x = -5.5, y = 17.5},
  183.                 {x = 5.5, y = -17.5},
  184.                 {x = 5.5, y = 17.5},
  185.                 {x = -17.5, y = -17.5},
  186.                 {x = -17.5, y = 17.5},
  187.                 {x = 17.5, y = -17.5},
  188.                 {x = 17.5, y = 17.5},
  189.             },
  190.             connection_tile = "factory-floor-2",
  191.             connections = {
  192.                 w1 = make_connection("w1", -6.5,-4.5, -conn,-18.5, west),
  193.                 w2 = make_connection("w2", -6.5,-3.5, -conn,-13.5, west),
  194.                 w3 = make_connection("w3", -6.5,-2.5, -conn,-8.5, west),
  195.                 w4 = make_connection("w4", -6.5,2.5, -conn,8.5, west),
  196.                 w5 = make_connection("w5", -6.5,3.5, -conn,13.5, west),
  197.                 w6 = make_connection("w6", -6.5,4.5, -conn,18.5, west),
  198.                
  199.                 e1 = make_connection("e1", 6.5,-4.5, conn,-18.5, east),
  200.                 e2 = make_connection("e2", 6.5,-3.5, conn,-13.5, east),
  201.                 e3 = make_connection("e3", 6.5,-2.5, conn,-8.5, east),
  202.                 e4 = make_connection("e4", 6.5,2.5, conn,8.5, east),
  203.                 e5 = make_connection("e5", 6.5,3.5, conn,13.5, east),
  204.                 e6 = make_connection("e6", 6.5,4.5, conn,18.5, east),
  205.                
  206.                 n1 = make_connection("n1", -4.5,-6.5, -18.5,-conn, north),
  207.                 n2 = make_connection("n2", -3.5,-6.5, -13.5,-conn, north),
  208.                 n3 = make_connection("n3", -2.5,-6.5, -8.5,-conn, north),
  209.                 n4 = make_connection("n4", 2.5,-6.5, 8.5,-conn, north),
  210.                 n5 = make_connection("n5", 3.5,-6.5, 13.5,-conn, north),
  211.                 n6 = make_connection("n6", 4.5,-6.5, 18.5,-conn, north),
  212.                
  213.                 s1 = make_connection("s1", -4.5,6.5, -18.5,conn, south),
  214.                 s2 = make_connection("s2", -3.5,6.5, -13.5,conn, south),
  215.                 s3 = make_connection("s3", -2.5,6.5, -8.5,conn, south),
  216.                 s4 = make_connection("s4", 2.5,6.5, 8.5,conn, south),
  217.                 s5 = make_connection("s5", 3.5,6.5, 13.5,conn, south),
  218.                 s6 = make_connection("s6", 4.5,6.5, 18.5,conn, south),
  219.             },
  220.             overlays = {
  221.                 nw = {
  222.                     outside_x = -3,
  223.                     outside_y = -3,
  224.                     inside_x = 3.5,
  225.                     inside_y = size + 0.5,
  226.                 },
  227.                 ne = {
  228.                     outside_x = 3,
  229.                     outside_y = -3,
  230.                     inside_x = 4.5,
  231.                     inside_y = size + 0.5,
  232.                 },
  233.                
  234.                 sw = {
  235.                     outside_x = -3,
  236.                     outside_y = 1,
  237.                     inside_x = 3.5,
  238.                     inside_y = size + 1.5,
  239.                 },
  240.                 se = {
  241.                     outside_x = 3,
  242.                     outside_y = 1,
  243.                     inside_x = 4.5,
  244.                     inside_y = size + 1.5,
  245.                 },
  246.             },
  247.         }
  248.     end,
  249.     ["factory-3"] = function()
  250.     local size = 33
  251.     local conn = size - 0.5
  252.    
  253.         return {
  254.             name = "factory-3",
  255.             tier = 3,
  256.             inside_door_x = 0,
  257.             inside_door_y = size,
  258.             outside_door_x = 0,
  259.             outside_door_y = 8,
  260.             outside_energy_receiver_type = "factory-power-input-16",
  261.             outside_energy_sender_type = "factory-power-output-16",
  262.             inside_energy_x = -4,
  263.             inside_energy_y = size + 1,
  264.             energy_indicator_x = -3.5,
  265.             energy_indicator_y = size + 2.5,
  266.             overlay_name = "factory-3-overlay",
  267.             overlay_x = 0,
  268.             overlay_y = 7,
  269.             rectangles = {
  270.                 {
  271.                     x1 = -(size + 2), x2 = (size + 2), y1 = -(size + 2), y2 = (size + 2), tile = "out-of-factory"
  272.                 },
  273.                 {
  274.                     x1 = -size, x2 = size, y1 = -size, y2 = size, tile = "factory-wall-3"
  275.                 },
  276.                 {
  277.                     x1 = -(size - 1), x2 = (size - 1), y1 = -(size - 1), y2 = (size - 1), tile = "factory-floor-3"
  278.                 },
  279.                 {
  280.                     x1 = -3, x2 = 3, y1 = (size - 1), y2 = (size + 2), tile = "factory-wall-3"
  281.                 },
  282.                 {
  283.                     x1 = -2, x2 = 2, y1 = (size - 1), y2 = (size + 2), tile = "factory-entrance-3"
  284.                 },
  285.             },
  286.             mosaics = {
  287.                 {   x1 = -6, x2 = 6, y1 = -4, y2 = 4, tile = "factory-pattern-3",
  288.                     pattern = {
  289.                         " ++++   +++ ",
  290.                         "++  ++ ++ ++",
  291.                         "++  ++    ++",
  292.                         "++ +++   ++ ",
  293.                         "+++ ++    ++",
  294.                         "++  ++    ++",
  295.                         "++  ++ ++ ++",
  296.                         " ++++   +++ ",
  297.                     }
  298.                 },
  299.             },
  300.             lights = {
  301.                 {x = -7.5, y = -7.5},
  302.                 {x = -7.5, y = 7.5},
  303.                 {x = 7.5, y = -7.5},
  304.                 {x = 7.5, y = 7.5},
  305.                 {x = -22.5, y = -7.5},
  306.                 {x = -22.5, y = 7.5},
  307.                 {x = 22.5, y = -7.5},
  308.                 {x = 22.5, y = 7.5},
  309.                 {x = -7.5, y = -22.5},
  310.                 {x = -7.5, y = 22.5},
  311.                 {x = 7.5, y = -22.5},
  312.                 {x = 7.5, y = 22.5},
  313.                 {x = -22.5, y = -22.5},
  314.                 {x = -22.5, y = 22.5},
  315.                 {x = 22.5, y = -22.5},
  316.                 {x = 22.5, y = 22.5},
  317.             },
  318.             connection_tile = "factory-floor-3",
  319.             connections = {
  320.                 w1 = make_connection("w1", -8.5,-5.5, -conn,-24.5, west),
  321.                 w2 = make_connection("w2", -8.5,-4.5, -conn,-20.5, west),
  322.                 w3 = make_connection("w3", -8.5,-3.5, -conn,-9.5, west),
  323.                 w4 = make_connection("w4", -8.5,-2.5, -conn,-5.5, west),
  324.                 w5 = make_connection("w5", -8.5,2.5, -conn,5.5, west),
  325.                 w6 = make_connection("w6", -8.5,3.5, -conn,9.5, west),
  326.                 w7 = make_connection("w7", -8.5,4.5, -conn,20.5, west),
  327.                 w8 = make_connection("w8", -8.5,5.5, -conn,24.5, west),
  328.                
  329.                 e1 = make_connection("e1", 8.5,-5.5, conn,-24.5, east),
  330.                 e2 = make_connection("e2", 8.5,-4.5, conn,-20.5, east),
  331.                 e3 = make_connection("e3", 8.5,-3.5, conn,-9.5, east),
  332.                 e4 = make_connection("e4", 8.5,-2.5, conn,-5.5, east),
  333.                 e5 = make_connection("e5", 8.5,2.5, conn,5.5, east),
  334.                 e6 = make_connection("e6", 8.5,3.5, conn,9.5, east),
  335.                 e7 = make_connection("e7", 8.5,4.5, conn,20.5, east),
  336.                 e8 = make_connection("e8", 8.5,5.5, conn,24.5, east),
  337.                
  338.                 n1 = make_connection("n1", -5.5,-8.5, -24.5,-conn, north),
  339.                 n2 = make_connection("n2", -4.5,-8.5, -20.5,-conn, north),
  340.                 n3 = make_connection("n3", -3.5,-8.5, -9.5,-conn, north),
  341.                 n4 = make_connection("n4", -2.5,-8.5, -5.5,-conn, north),
  342.                 n5 = make_connection("n5", 2.5,-8.5, 5.5,-conn, north),
  343.                 n6 = make_connection("n6", 3.5,-8.5, 9.5,-conn, north),
  344.                 n7 = make_connection("n7", 4.5,-8.5, 20.5,-conn, north),
  345.                 n8 = make_connection("n8", 5.5,-8.5, 24.5,-conn, north),
  346.                
  347.                 s1 = make_connection("s1", -5.5,8.5, -24.5,conn, south),
  348.                 s2 = make_connection("s2", -4.5,8.5, -20.5,conn, south),
  349.                 s3 = make_connection("s3", -3.5,8.5, -9.5,conn, south),
  350.                 s4 = make_connection("s4", -2.5,8.5, -5.5,conn, south),
  351.                 s5 = make_connection("s5", 2.5,8.5, 5.5,conn, south),
  352.                 s6 = make_connection("s6", 3.5,8.5, 9.5,conn, south),
  353.                 s7 = make_connection("s7", 4.5,8.5, 20.5,conn, south),
  354.                 s8 = make_connection("s8", 5.5,8.5, 24.5,conn, south),
  355.             },
  356.             overlays = {
  357.                 nw = {
  358.                     outside_x = -4,
  359.                     outside_y = -4,
  360.                     inside_x = 3.5,
  361.                     inside_y = size + 0.5,
  362.                 },
  363.                 ne = {
  364.                     outside_x = 4,
  365.                     outside_y = -4,
  366.                     inside_x = 4.5,
  367.                     inside_y = size + 0.5,
  368.                 },
  369.                
  370.                 sw = {
  371.                     outside_x = -4,
  372.                     outside_y = 2,
  373.                     inside_x = 3.5,
  374.                     inside_y = size + 1.5,
  375.                 },
  376.                 se = {
  377.                     outside_x = 4,
  378.                     outside_y = 2,
  379.                     inside_x = 4.5,
  380.                     inside_y = size + 1.5,
  381.                 },
  382.             },
  383.         }
  384.     end,
  385. }
  386.  
  387. function HasLayout(name)
  388.     return layout_generators[name] ~= nil
  389. end
  390.  
  391. function CreateLayout(name)
  392.     if layout_generators[name] then
  393.         return layout_generators[name]()
  394.     else
  395.         return nil
  396.     end
  397. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement