Add per-map chest spawn areas
This commit is contained in:
parent
bfa1312583
commit
0a5e05201f
2 changed files with 55 additions and 40 deletions
|
@ -2,27 +2,11 @@ assert(minetest.get_mapgen_setting("mg_name") == "singlenode", "singlenode mapge
|
||||||
|
|
||||||
minetest.register_alias("mapgen_singlenode", "ctf_map:ignore")
|
minetest.register_alias("mapgen_singlenode", "ctf_map:ignore")
|
||||||
|
|
||||||
local max_r = 120
|
|
||||||
function ctf_map.place_map(map)
|
|
||||||
local r = map.r
|
|
||||||
local h = map.h
|
|
||||||
minetest.emerge_area(map.pos1, map.pos2)
|
|
||||||
|
|
||||||
local schempath = minetest.get_modpath("ctf_map") .. "/maps/" .. map.schematic
|
|
||||||
local res = minetest.place_schematic(map.pos1, schempath, map.rotation == "z" and "0" or "90")
|
|
||||||
|
|
||||||
if res ~= nil then
|
|
||||||
local seed = minetest.get_mapgen_setting("seed")
|
|
||||||
local pos1_middle = { x = -r, y = -h / 2, z = 0 }
|
|
||||||
local pos2_middle = { x = r, y = h / 2, z = 0 }
|
|
||||||
place_chests(map.pos1, pos2_middle, seed)
|
|
||||||
place_chests(pos1_middle, map.pos2, seed)
|
|
||||||
end
|
|
||||||
|
|
||||||
return res ~= nil
|
|
||||||
end
|
|
||||||
|
|
||||||
|
local max_r = 120
|
||||||
local mapdir = minetest.get_modpath("ctf_map") .. "/maps/"
|
local mapdir = minetest.get_modpath("ctf_map") .. "/maps/"
|
||||||
|
ctf_map.map = nil
|
||||||
|
|
||||||
|
|
||||||
do
|
do
|
||||||
local files_hash = {}
|
local files_hash = {}
|
||||||
|
@ -38,10 +22,32 @@ do
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
ctf_map.map = nil
|
function ctf_map.place_map(map)
|
||||||
|
local r = map.r
|
||||||
|
local h = map.h
|
||||||
|
minetest.emerge_area(map.pos1, map.pos2)
|
||||||
|
|
||||||
|
local schempath = mapdir .. map.schematic
|
||||||
|
local res = minetest.place_schematic(map.pos1, schempath,
|
||||||
|
map.rotation == "z" and "0" or "90")
|
||||||
|
|
||||||
|
if res ~= nil then
|
||||||
|
local seed = minetest.get_mapgen_setting("seed")
|
||||||
|
for _, value in pairs(ctf_map.map.teams) do
|
||||||
|
place_chests(value.chests.from, value.chests.to, seed, value.chests.n)
|
||||||
|
minetest.log("error", "Placing " .. value.chests.n .. " chests from " ..
|
||||||
|
minetest.pos_to_string(value.chests.from) .. " to "..
|
||||||
|
minetest.pos_to_string(value.chests.to))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return res ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function ctf_match.load_map_meta(idx, name)
|
||||||
|
local offset = vector.new(600 * (idx - 1), 0, 0)
|
||||||
|
local meta = Settings(mapdir .. name .. ".conf")
|
||||||
|
|
||||||
function ctf_match.load_map_meta(name, offset)
|
|
||||||
local meta = Settings(mapdir .. name .. ".conf")
|
|
||||||
local map = {
|
local map = {
|
||||||
name = meta:get("name"),
|
name = meta:get("name"),
|
||||||
author = meta:get("author"),
|
author = meta:get("author"),
|
||||||
|
@ -63,9 +69,33 @@ function ctf_match.load_map_meta(name, offset)
|
||||||
local tcolor = meta:get("team." .. i .. ".color")
|
local tcolor = meta:get("team." .. i .. ".color")
|
||||||
local tpos = minetest.string_to_pos(meta:get("team." .. i .. ".pos"))
|
local tpos = minetest.string_to_pos(meta:get("team." .. i .. ".pos"))
|
||||||
|
|
||||||
|
local chests1 = meta:get("team." .. i .. ".chests1")
|
||||||
|
if chests1 then
|
||||||
|
chests1 = vector.add(offset, minetest.string_to_pos(chests1))
|
||||||
|
elseif i == 1 then
|
||||||
|
chests1 = vector.add(offset, { x = -map.r, y = -map.h / 2, z = 0 })
|
||||||
|
elseif i == 2 then
|
||||||
|
chests1 = map.pos1
|
||||||
|
end
|
||||||
|
|
||||||
|
local chests2 = meta:get("team." .. i .. ".chests2")
|
||||||
|
if chests2 then
|
||||||
|
chests2 = vector.add(offset, minetest.string_to_pos(chests2))
|
||||||
|
elseif i == 1 then
|
||||||
|
chests2 = map.pos2
|
||||||
|
elseif i == 2 then
|
||||||
|
chests2 = vector.add(offset, { x = map.r, y = map.h / 2, z = 0 })
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
map.teams[tname] = {
|
map.teams[tname] = {
|
||||||
color = tcolor,
|
color = tcolor,
|
||||||
pos = vector.add(offset, tpos),
|
pos = vector.add(offset, tpos),
|
||||||
|
chests = {
|
||||||
|
from = chests1,
|
||||||
|
to = chests2,
|
||||||
|
n = tonumber(meta:get("team." .. i .. ".num_chests") or "30"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
@ -77,7 +107,7 @@ end
|
||||||
ctf_match.register_on_new_match(function()
|
ctf_match.register_on_new_match(function()
|
||||||
local idx = math.random(#ctf_map.available_maps)
|
local idx = math.random(#ctf_map.available_maps)
|
||||||
local name = ctf_map.available_maps[idx]
|
local name = ctf_map.available_maps[idx]
|
||||||
ctf_map.map = ctf_match.load_map_meta(name, vector.new(600 * (idx - 1), 0, 0))
|
ctf_map.map = ctf_match.load_map_meta(idx, name)
|
||||||
ctf_map.place_map(ctf_map.map)
|
ctf_map.place_map(ctf_map.map)
|
||||||
|
|
||||||
minetest.after(10, function()
|
minetest.after(10, function()
|
||||||
|
|
|
@ -78,13 +78,11 @@ minetest.register_node("tsm_chests:chest", {
|
||||||
|
|
||||||
--[[ here are some configuration variables ]]
|
--[[ here are some configuration variables ]]
|
||||||
|
|
||||||
local chests_per_chunk = 13 -- number of chests per chunk. 15 is a bit high, an actual mod might have a lower number
|
|
||||||
local h_min = -65 -- minimum chest spawning height, relative to water_level
|
local h_min = -65 -- minimum chest spawning height, relative to water_level
|
||||||
local h_max = 40 -- maximum chest spawning height, relative to water_level
|
local h_max = 40 -- maximum chest spawning height, relative to water_level
|
||||||
local t_min = 3 -- minimum amount of treasures found in a chest
|
local t_min = 3 -- minimum amount of treasures found in a chest
|
||||||
local t_max = 6 -- maximum amount of treasures found in a chest
|
local t_max = 6 -- maximum amount of treasures found in a chest
|
||||||
|
|
||||||
local r_max = tonumber(minetest.setting_get("barrier"))
|
|
||||||
local water_level = tonumber(minetest.setting_get("water_level"))
|
local water_level = tonumber(minetest.setting_get("water_level"))
|
||||||
local get_node = minetest.get_node
|
local get_node = minetest.get_node
|
||||||
local env = minetest.env
|
local env = minetest.env
|
||||||
|
@ -173,23 +171,10 @@ end
|
||||||
--[[ here comes the generation code
|
--[[ here comes the generation code
|
||||||
the interesting part which involes treasurer comes way below
|
the interesting part which involes treasurer comes way below
|
||||||
]]
|
]]
|
||||||
function place_chests(minp, maxp, seed)
|
function place_chests(minp, maxp, seed, number_chests)
|
||||||
minp = {x=minp.x, y=minp.y, z=minp.z}
|
minp = {x=minp.x, y=minp.y, z=minp.z}
|
||||||
maxp = {x=maxp.x, y=maxp.y, z=maxp.z}
|
maxp = {x=maxp.x, y=maxp.y, z=maxp.z}
|
||||||
|
|
||||||
if minp.x <= -r_max then
|
|
||||||
minp.x = -r_max + 1
|
|
||||||
end
|
|
||||||
if minp.z <= -r_max then
|
|
||||||
minp.z = -r_max + 1
|
|
||||||
end
|
|
||||||
if minp.x >= r_max then
|
|
||||||
minp.x = r_max - 1
|
|
||||||
end
|
|
||||||
if minp.z >= r_max then
|
|
||||||
minp.z = r_max - 1
|
|
||||||
end
|
|
||||||
|
|
||||||
-- chests minimum and maximum spawn height
|
-- chests minimum and maximum spawn height
|
||||||
local height_min = water_level + h_min
|
local height_min = water_level + h_min
|
||||||
local height_max = water_level + h_max
|
local height_max = water_level + h_max
|
||||||
|
@ -201,7 +186,7 @@ function place_chests(minp, maxp, seed)
|
||||||
local y_max = math.min(maxp.y, height_max)
|
local y_max = math.min(maxp.y, height_max)
|
||||||
local attempts = 0
|
local attempts = 0
|
||||||
local chests_placed = 0
|
local chests_placed = 0
|
||||||
while chests_placed < chests_per_chunk and attempts < chests_per_chunk + 6 do
|
while chests_placed < number_chests and attempts < number_chests + 6 do
|
||||||
attempts = attempts + 1
|
attempts = attempts + 1
|
||||||
local pos = {
|
local pos = {
|
||||||
x = math.random(minp.x, maxp.x),
|
x = math.random(minp.x, maxp.x),
|
||||||
|
|
Loading…
Reference in a new issue