Refactor room.lua a bit

This commit is contained in:
Wuzzy 2019-08-19 18:38:48 +02:00
parent d86a85340c
commit 6b453f781e
1 changed files with 33 additions and 29 deletions

View File

@ -1,32 +1,36 @@
local room = {"a","a","a","a","a","a","a","a","a", local layout_room = {
"a","c","a","c","a","c","a","c","a", " "," "," "," "," "," "," "," "," ",
"a","s","a","s","a","s","a","s","a", " ","c"," ","c"," ","c"," ","c"," ",
"a","a","a","a","a","a","a","a","a", " ","s"," ","s"," ","s"," ","s"," ",
"a","a","a","a","a","a","a","a","a", " "," "," "," "," "," "," "," "," ",
"a","a","a","a","a","a","a","a","a", " "," "," "," "," "," "," "," "," ",
"a","s","a","s","a","s","a","s","a", " "," "," "," "," "," "," "," "," ",
"a","c","a","c","a","c","a","c","a", " ","s"," ","s"," ","s"," ","s"," ",
"a","a","a","a","a","a","a","a","a"} " ","c"," ","c"," ","c"," ","c"," ",
" "," "," "," "," "," "," "," "," "
}
local trap = {"b","b","b","b","b","b","b","b","b", local layout_trap = {
"l","b","l","b","l","b","l","b","b", "S","S","S","S","S","S","S","S","S",
"l","b","l","b","l","b","l","b","b", "~","S","~","S","~","S","~","S","S",
"l","b","l","l","l","b","l","l","b", "~","S","~","S","~","S","~","S","S",
"l","l","b","l","b","l","l","b","b", "~","S","~","~","~","S","~","~","S",
"l","b","l","l","l","l","l","l","b", "~","~","S","~","S","~","~","S","S",
"l","b","l","b","l","b","l","b","b", "~","S","~","~","~","~","~","~","S",
"l","b","l","b","l","b","l","b","b", "~","S","~","S","~","S","~","S","S",
"b","b","b","b","b","b","b","b","b"} "~","S","~","S","~","S","~","S","S",
"S","S","S","S","S","S","S","S","S"
}
local code_sandstone = { local code_sandstone = {
[" "] = "air",
["s"] = "sandstone", ["s"] = "sandstone",
["S"] = "sandstonebrick",
["1"] = "deco_stone1", ["1"] = "deco_stone1",
["2"] = "deco_stone2", ["2"] = "deco_stone2",
["3"] = "deco_stone3", ["3"] = "deco_stone3",
["c"] = "chest", ["c"] = "chest",
["b"] = "sandstonebrick", ["~"] = "lava_source",
["a"] = "air",
["l"] = "lava_source",
["t"] = "trap", ["t"] = "trap",
} }
local code_desert = table.copy(code_sandstone) local code_desert = table.copy(code_sandstone)
@ -34,24 +38,24 @@ code_desert["s"] = "desert_sandstone"
code_desert["1"] = "deco_stone4" code_desert["1"] = "deco_stone4"
code_desert["2"] = "deco_stone5" code_desert["2"] = "deco_stone5"
code_desert["3"] = "deco_stone6" code_desert["3"] = "deco_stone6"
code_desert["b"] = "desert_sandstone_brick" code_desert["S"] = "desert_sandstone_brick"
code_desert["t"] = "desert_trap" code_desert["t"] = "desert_trap"
local function replace(str, iy, code_table, deco) local function replace(str, iy, code_table, deco)
local out = "default:" local out = "default:"
if iy < 4 and str == "c" then str = "a" end if iy < 4 and str == "c" then str = " " end
if iy == 0 and str == "s" then out = "tsm_pyramids:" str = deco[1] end 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 if iy == 3 and str == "s" then out = "tsm_pyramids:" str = deco[2] end
if str == "a" then out = "" end if str == " " then out = "" end
return out..code_table[str] return out..code_table[str]
end end
local function replace2(str, iy, code_table) local function replace2(str, iy, code_table)
local out = "default:" local out = "default:"
if iy == 0 and str == "l" then out = "tsm_pyramids:" str = "t" if iy == 0 and str == "~" then out = "tsm_pyramids:" str = "t"
elseif iy < 3 and str == "l" then str = "a" end elseif iy < 3 and str == "~" then str = " " end
if str == "a" then out = "" end if str == " " then out = "" end
return out..code_table[str] return out..code_table[str]
end end
@ -72,7 +76,7 @@ function tsm_pyramids.make_room(pos, stype)
for iy=0,4,1 do for iy=0,4,1 do
for ix=0,8,1 do for ix=0,8,1 do
for iz=0,8,1 do for iz=0,8,1 do
local n_str = room[tonumber(ix*9+iz+1)] local n_str = layout_room[tonumber(ix*9+iz+1)]
local p2 = 0 local p2 = 0
if n_str == "c" then if n_str == "c" then
if ix < 3 then p2 = 1 else p2 = 3 end if ix < 3 then p2 = 1 else p2 = 3 end
@ -93,7 +97,7 @@ function tsm_pyramids.make_traps(pos, stype)
for iy=0,4,1 do for iy=0,4,1 do
for ix=0,8,1 do for ix=0,8,1 do
for iz=0,8,1 do for iz=0,8,1 do
local n_str = trap[tonumber(ix*9+iz+1)] local n_str = layout_trap[tonumber(ix*9+iz+1)]
local p2 = 0 local p2 = 0
minetest.set_node({x=hole.x+ix,y=hole.y-iy,z=hole.z+iz}, {name=replace2(n_str, iy, code_table), param2=p2}) minetest.set_node({x=hole.x+ix,y=hole.y-iy,z=hole.z+iz}, {name=replace2(n_str, iy, code_table), param2=p2})
end end