Add room type argument in spawnpyramid command

This commit is contained in:
Wuzzy 2019-08-20 01:07:42 +02:00
parent d64e5d5b47
commit 9e9433dcae
2 changed files with 34 additions and 15 deletions

View File

@ -89,8 +89,7 @@ local function make_entrance(pos, brick)
end end
end end
local function make(pos, brick, sandstone, stone, sand, ptype) local function make(pos, brick, sandstone, stone, sand, ptype, room_id)
minetest.log("action", "Created pyramid at ("..pos.x..","..pos.y..","..pos.z..")")
for iy=0,10,1 do for iy=0,10,1 do
for ix=iy,22-iy,1 do for ix=iy,22-iy,1 do
for iz=iy,22-iy,1 do for iz=iy,22-iy,1 do
@ -105,10 +104,11 @@ local function make(pos, brick, sandstone, stone, sand, ptype)
end end
end end
end end
local ok, msg = tsm_pyramids.make_room(pos, ptype, room_id)
tsm_pyramids.make_room(pos, ptype)
add_spawner({x=pos.x+11,y=pos.y+2, z=pos.z+17}) add_spawner({x=pos.x+11,y=pos.y+2, z=pos.z+17})
make_entrance({x=pos.x,y=pos.y, z=pos.z}, brick) make_entrance({x=pos.x,y=pos.y, z=pos.z}, brick)
minetest.log("action", "Created pyramid at ("..pos.x..","..pos.y..","..pos.z..")")
return ok, msg
end end
local perl1 = {SEED1 = 9130, OCTA1 = 3, PERS1 = 0.5, SCAL1 = 250} -- Values should match minetest mapgen V6 desert noise. local perl1 = {SEED1 = 9130, OCTA1 = 3, PERS1 = 0.5, SCAL1 = 250} -- Values should match minetest mapgen V6 desert noise.
@ -217,7 +217,7 @@ end
minetest.register_chatcommand("spawnpyramid", { minetest.register_chatcommand("spawnpyramid", {
description = S("Generate a pyramid"), description = S("Generate a pyramid"),
params = "", params = S("[<room_type>]"),
privs = { server = true }, privs = { server = true },
func = function(name, param) func = function(name, param)
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
@ -226,13 +226,23 @@ minetest.register_chatcommand("spawnpyramid", {
end end
local pos = player:get_pos() local pos = player:get_pos()
pos = vector.round(pos) pos = vector.round(pos)
local r = math.random(1,2) local s = math.random(1,2)
if r == 1 then local r = tonumber(param)
make(pos, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand", "sandstone") local room_id
else if r then
make(pos, "default:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand", "desert") room_id = r
end
local ok, msg
if s == 1 then
ok, msg = make(pos, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand", "sandstone", room_id)
else
ok, msg = make(pos, "default:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand", "desert", room_id)
end
if ok then
return true, S("Pyramid generated at @1.", minetest.pos_to_string(pos))
else
return false, msg
end end
return true, S("Pyramid generated at @1.", minetest.pos_to_string(pos))
end, end,
} }
) )

View File

@ -1,3 +1,5 @@
local S = minetest.get_translator("tsm_pyramids")
-- ROOM LAYOUTS -- ROOM LAYOUTS
local room_types = { local room_types = {
@ -593,7 +595,7 @@ local function replace2(str, iy, code_table)
return out..code_table[str] return out..code_table[str]
end end
function tsm_pyramids.make_room(pos, stype) function tsm_pyramids.make_room(pos, stype, room_id)
local code_table = code_sandstone local code_table = code_sandstone
if stype == "desert" then if stype == "desert" then
code_table = code_desert code_table = code_desert
@ -607,8 +609,14 @@ function tsm_pyramids.make_room(pos, stype)
table.remove(deco_ids, r) table.remove(deco_ids, r)
end end
local hole = {x=pos.x+7,y=pos.y+5, z=pos.z+7} local hole = {x=pos.x+7,y=pos.y+5, z=pos.z+7}
local r = math.random(1, #room_types) if room_id == nil then
local room = room_types[r] room_id = math.random(1, #room_types)
end
local room
if room_id < 1 or room_id > #room_types then
return false, S("Incorrect room type ID: @1", room_id)
end
local room = room_types[room_id]
if room.style == "yrepeat" then if room.style == "yrepeat" then
for iy=0,4,1 do for iy=0,4,1 do
for ix=0,8,1 do for ix=0,8,1 do
@ -630,11 +638,12 @@ function tsm_pyramids.make_room(pos, stype)
end end
end end
else else
minetest.log("error", "Invalid pyramid room style! room_types index="..r) minetest.log("error", "Invalid pyramid room style! room type ID="..r)
end end
if room.traps then if room.traps then
tsm_pyramids.make_traps(pos, stype) tsm_pyramids.make_traps(pos, stype)
end end
return true
end end
local shuffle_traps = function(chance) local shuffle_traps = function(chance)