From 9e9433dcaea671c1e04ba606da5a45b0b7dffd60 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 20 Aug 2019 01:07:42 +0200 Subject: [PATCH] Add room type argument in spawnpyramid command --- init.lua | 32 +++++++++++++++++++++----------- room.lua | 17 +++++++++++++---- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/init.lua b/init.lua index f70eede..7fffcc9 100644 --- a/init.lua +++ b/init.lua @@ -89,8 +89,7 @@ local function make_entrance(pos, brick) end end -local function make(pos, brick, sandstone, stone, sand, ptype) - minetest.log("action", "Created pyramid at ("..pos.x..","..pos.y..","..pos.z..")") +local function make(pos, brick, sandstone, stone, sand, ptype, room_id) for iy=0,10,1 do for ix=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 - - tsm_pyramids.make_room(pos, ptype) + local ok, msg = tsm_pyramids.make_room(pos, ptype, room_id) 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) + minetest.log("action", "Created pyramid at ("..pos.x..","..pos.y..","..pos.z..")") + return ok, msg end 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", { description = S("Generate a pyramid"), - params = "", + params = S("[]"), privs = { server = true }, func = function(name, param) local player = minetest.get_player_by_name(name) @@ -226,13 +226,23 @@ minetest.register_chatcommand("spawnpyramid", { end local pos = player:get_pos() pos = vector.round(pos) - local r = math.random(1,2) - if r == 1 then - make(pos, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand", "sandstone") - else - make(pos, "default:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand", "desert") + local s = math.random(1,2) + local r = tonumber(param) + local room_id + if r then + 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 - return true, S("Pyramid generated at @1.", minetest.pos_to_string(pos)) end, } ) diff --git a/room.lua b/room.lua index f86621d..10b2996 100644 --- a/room.lua +++ b/room.lua @@ -1,3 +1,5 @@ +local S = minetest.get_translator("tsm_pyramids") + -- ROOM LAYOUTS local room_types = { @@ -593,7 +595,7 @@ local function replace2(str, iy, code_table) return out..code_table[str] end -function tsm_pyramids.make_room(pos, stype) +function tsm_pyramids.make_room(pos, stype, room_id) local code_table = code_sandstone if stype == "desert" then code_table = code_desert @@ -607,8 +609,14 @@ function tsm_pyramids.make_room(pos, stype) table.remove(deco_ids, r) end local hole = {x=pos.x+7,y=pos.y+5, z=pos.z+7} - local r = math.random(1, #room_types) - local room = room_types[r] + if room_id == nil then + 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 for iy=0,4,1 do for ix=0,8,1 do @@ -630,11 +638,12 @@ function tsm_pyramids.make_room(pos, stype) end end else - minetest.log("error", "Invalid pyramid room style! room_types index="..r) + minetest.log("error", "Invalid pyramid room style! room type ID="..r) end if room.traps then tsm_pyramids.make_traps(pos, stype) end + return true end local shuffle_traps = function(chance)