tsm_pyramids/room.lua

107 lines
3.0 KiB
Lua
Raw Normal View History

2019-08-19 18:38:48 +02:00
local layout_room = {
" "," "," "," "," "," "," "," "," ",
" ","c"," ","c"," ","c"," ","c"," ",
" ","s"," ","s"," ","s"," ","s"," ",
" "," "," "," "," "," "," "," "," ",
" "," "," "," "," "," "," "," "," ",
" "," "," "," "," "," "," "," "," ",
" ","s"," ","s"," ","s"," ","s"," ",
" ","c"," ","c"," ","c"," ","c"," ",
" "," "," "," "," "," "," "," "," "
}
2019-08-19 18:38:48 +02:00
local layout_trap = {
"S","S","S","S","S","S","S","S","S",
"~","S","~","S","~","S","~","S","S",
"~","S","~","S","~","S","~","S","S",
"~","S","~","~","~","S","~","~","S",
"~","~","S","~","S","~","~","S","S",
"~","S","~","~","~","~","~","~","S",
"~","S","~","S","~","S","~","S","S",
"~","S","~","S","~","S","~","S","S",
"S","S","S","S","S","S","S","S","S"
}
2013-10-01 14:37:40 +02:00
2018-05-25 00:23:05 +02:00
local code_sandstone = {
2019-08-19 18:38:48 +02:00
[" "] = "air",
2018-05-25 00:23:05 +02:00
["s"] = "sandstone",
2019-08-19 18:38:48 +02:00
["S"] = "sandstonebrick",
2018-05-25 00:23:05 +02:00
["1"] = "deco_stone1",
["2"] = "deco_stone2",
["3"] = "deco_stone3",
["c"] = "chest",
2019-08-19 18:38:48 +02:00
["~"] = "lava_source",
2018-05-25 00:23:05 +02:00
["t"] = "trap",
}
local code_desert = table.copy(code_sandstone)
code_desert["s"] = "desert_sandstone"
code_desert["1"] = "deco_stone4"
code_desert["2"] = "deco_stone5"
code_desert["3"] = "deco_stone6"
2019-08-19 18:38:48 +02:00
code_desert["S"] = "desert_sandstone_brick"
2019-08-19 17:26:05 +02:00
code_desert["t"] = "desert_trap"
2018-05-25 00:34:33 +02:00
local function replace(str, iy, code_table, deco)
local out = "default:"
2019-08-19 18:38:48 +02:00
if iy < 4 and str == "c" then str = " " end
2018-05-25 00:34:33 +02:00
if iy == 0 and str == "s" then out = "tsm_pyramids:" str = deco[1] end
if iy == 3 and str == "s" then out = "tsm_pyramids:" str = deco[2] end
2019-08-19 18:38:48 +02:00
if str == " " then out = "" end
2018-05-25 00:23:05 +02:00
return out..code_table[str]
end
2018-05-25 00:23:05 +02:00
local function replace2(str, iy, code_table)
2013-10-01 14:37:40 +02:00
local out = "default:"
2019-08-19 18:38:48 +02:00
if iy == 0 and str == "~" then out = "tsm_pyramids:" str = "t"
elseif iy < 3 and str == "~" then str = " " end
2013-10-01 14:37:40 +02:00
2019-08-19 18:38:48 +02:00
if str == " " then out = "" end
2018-05-25 00:23:05 +02:00
return out..code_table[str]
2013-10-01 14:37:40 +02:00
end
2019-08-19 18:06:55 +02:00
function tsm_pyramids.make_room(pos, stype)
2018-05-25 00:23:05 +02:00
local code_table = code_sandstone
if stype == "desert" then
code_table = code_desert
end
2018-05-25 00:34:33 +02:00
-- Select random deco block
local deco_ids = {"1", "2", "3"}
local deco = {}
for i=1, 2 do
local r = math.random(1, #deco_ids)
table.insert(deco, deco_ids[r])
table.remove(deco_ids, r)
end
2018-05-25 00:23:05 +02:00
local hole = {x=pos.x+7,y=pos.y+5, z=pos.z+7}
2016-12-30 14:22:38 +01:00
for iy=0,4,1 do
for ix=0,8,1 do
for iz=0,8,1 do
2019-08-19 18:38:48 +02:00
local n_str = layout_room[tonumber(ix*9+iz+1)]
2016-12-30 14:22:38 +01:00
local p2 = 0
if n_str == "c" then
if ix < 3 then p2 = 1 else p2 = 3 end
2019-08-19 18:06:55 +02:00
tsm_pyramids.fill_chest({x=hole.x+ix,y=hole.y-iy,z=hole.z+iz})
2016-12-30 14:22:38 +01:00
end
2018-05-25 00:34:33 +02:00
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})
end
end
end
end
2013-10-01 14:37:40 +02:00
2019-08-19 18:06:55 +02:00
function tsm_pyramids.make_traps(pos, stype)
2018-05-25 00:23:05 +02:00
local code_table = code_sandstone
if stype == "desert" then
code_table = code_desert
end
local hole = {x=pos.x+7,y=pos.y, z=pos.z+7}
2016-12-30 14:22:38 +01:00
for iy=0,4,1 do
for ix=0,8,1 do
for iz=0,8,1 do
2019-08-19 18:38:48 +02:00
local n_str = layout_trap[tonumber(ix*9+iz+1)]
2016-12-30 14:22:38 +01:00
local p2 = 0
2018-05-25 00:23:05 +02:00
minetest.set_node({x=hole.x+ix,y=hole.y-iy,z=hole.z+iz}, {name=replace2(n_str, iy, code_table), param2=p2})
2016-12-30 14:22:38 +01:00
end
2013-10-01 14:37:40 +02:00
end
end
end