Add mod.conf
[minetest_pyramids/tsm_pyramids.git] / room.lua
blobd972b69d7ac0dec7681827de9e4a417acfc2c8f4
1 local room = {"a","a","a","a","a","a","a","a","a",
2 "a","c","a","c","a","c","a","c","a",
3 "a","s","a","s","a","s","a","s","a",
4 "a","a","a","a","a","a","a","a","a",
5 "a","a","a","a","a","a","a","a","a",
6 "a","a","a","a","a","a","a","a","a",
7 "a","s","a","s","a","s","a","s","a",
8 "a","c","a","c","a","c","a","c","a",
9 "a","a","a","a","a","a","a","a","a"}
11 local trap = {"b","b","b","b","b","b","b","b","b",
12 "l","b","l","b","l","b","l","b","b",
13 "l","b","l","b","l","b","l","b","b",
14 "l","b","l","l","l","b","l","l","b",
15 "l","l","b","l","b","l","l","b","b",
16 "l","b","l","l","l","l","l","l","b",
17 "l","b","l","b","l","b","l","b","b",
18 "l","b","l","b","l","b","l","b","b",
19 "b","b","b","b","b","b","b","b","b"}
21 local code_sandstone = {
22 ["s"] = "sandstone",
23 ["1"] = "deco_stone1",
24 ["2"] = "deco_stone2",
25 ["3"] = "deco_stone3",
26 ["c"] = "chest",
27 ["b"] = "sandstonebrick",
28 ["a"] = "air",
29 ["l"] = "lava_source",
30 ["t"] = "trap",
32 local code_desert = table.copy(code_sandstone)
33 code_desert["s"] = "desert_sandstone"
34 code_desert["1"] = "deco_stone4"
35 code_desert["2"] = "deco_stone5"
36 code_desert["3"] = "deco_stone6"
37 code_desert["b"] = "desert_sandstone_brick"
38 code_desert["t"] = "desert_trap"
40 local function replace(str, iy, code_table, deco)
41 local out = "default:"
42 if iy < 4 and str == "c" then str = "a" end
43 if iy == 0 and str == "s" then out = "tsm_pyramids:" str = deco[1] end
44 if iy == 3 and str == "s" then out = "tsm_pyramids:" str = deco[2] end
45 if str == "a" then out = "" end
46 return out..code_table[str]
47 end
49 local function replace2(str, iy, code_table)
50 local out = "default:"
51 if iy == 0 and str == "l" then out = "tsm_pyramids:" str = "t"
52 elseif iy < 3 and str == "l" then str = "a" end
54 if str == "a" then out = "" end
55 return out..code_table[str]
56 end
58 function pyramids.make_room(pos, stype)
59 local code_table = code_sandstone
60 if stype == "desert" then
61 code_table = code_desert
62 end
63 -- Select random deco block
64 local deco_ids = {"1", "2", "3"}
65 local deco = {}
66 for i=1, 2 do
67 local r = math.random(1, #deco_ids)
68 table.insert(deco, deco_ids[r])
69 table.remove(deco_ids, r)
70 end
71 local hole = {x=pos.x+7,y=pos.y+5, z=pos.z+7}
72 for iy=0,4,1 do
73 for ix=0,8,1 do
74 for iz=0,8,1 do
75 local n_str = room[tonumber(ix*9+iz+1)]
76 local p2 = 0
77 if n_str == "c" then
78 if ix < 3 then p2 = 1 else p2 = 3 end
79 pyramids.fill_chest({x=hole.x+ix,y=hole.y-iy,z=hole.z+iz})
80 end
81 minetest.set_node({x=hole.x+ix,y=hole.y-iy,z=hole.z+iz}, {name=replace(n_str, iy, code_table, deco), param2=p2})
82 end
83 end
84 end
85 end
87 function pyramids.make_traps(pos, stype)
88 local code_table = code_sandstone
89 if stype == "desert" then
90 code_table = code_desert
91 end
92 local hole = {x=pos.x+7,y=pos.y, z=pos.z+7}
93 for iy=0,4,1 do
94 for ix=0,8,1 do
95 for iz=0,8,1 do
96 local n_str = trap[tonumber(ix*9+iz+1)]
97 local p2 = 0
98 minetest.set_node({x=hole.x+ix,y=hole.y-iy,z=hole.z+iz}, {name=replace2(n_str, iy, code_table), param2=p2})
99 end