multiple changes to village generation, villages are now on maps, and lots of bugfixes and tweaks

This commit is contained in:
kaadmy 2015-10-02 13:58:37 -07:00
parent 7184c0be7e
commit 24ae3f7d8d
10 changed files with 136 additions and 40 deletions

View File

@ -1,6 +1,7 @@
local player_soundspec = {}
local player_lastsound = {}
local player_health = {}
local player_lastpos = {}
local enable_flowing_water_sound = minetest.setting_getbool("enable_flowing_water_sound")
if enable_flowing_water_sound == nil then enable_flowing_water_sound = true end
@ -16,9 +17,11 @@ local function step(dtime)
or player_pos.y < -30000 or player_pos.y > 30000
or player_pos.z < -30000 or player_pos.z > 30000 then
minetest.chat_send_player(name, "Don't go past 30000m in any direction!")
player.set_hp(0)
player:setpos(player_lastpos[name])
end
player_lastpos[name] = player:getpos()
if player:get_hp() < player_health[name] then
minetest.sound_play(
"default_hurt",
@ -105,6 +108,8 @@ local function on_joinplayer(player)
-- uncomment to disable the sneak glitch
player:set_physics_override({sneak_glitch = false})
player_lastpos[name] = player:getpos()
end
local function on_leaveplayer(player)
@ -113,6 +118,7 @@ local function on_leaveplayer(player)
player_soundspec[name] = nil
player_lastsound[name] = nil
player_health[name] = nil
player_lastpos[name] = nil
end
minetest.register_privilege("uberspeed", "Can use /uberspeed command")

View File

@ -10,7 +10,7 @@ default.ui.register_page("nav_nav", form_nav)
local open_formspecs = {}
local timer = 10
local update_time = 0.25
local update_time = 0.1
function nav.add_waypoint(pos, name, label, isinfo, type)
nav.waypoints[name] = {pos = pos, label = label, isinfo = isinfo or false, type = type}
@ -64,17 +64,12 @@ function nav.show_map(player)
for _, wptname in pairs(wpts) do
local wpt = nav.waypoints[wptname]
local isinfo = wpt.isinfo
if wptname == "player_" .. name then
isinfo = true
end
form = form .. get_formspec_waypoint(
3.5+(((wpt.pos.x-pos.x)/nav.map_radius)*3),
6+(((pos.z-wpt.pos.z)/nav.map_radius)*3),
wptname,
wpt.label,
isinfo)
wpt.isinfo)
end
form = form .. "image[5.5,3;1,1;nav_map_compass.png]"
@ -85,19 +80,6 @@ function nav.show_map(player)
minetest.show_formspec(name, "nav_map", form)
end
minetest.register_craftitem(
"nav:map",
{
description = "Map",
inventory_image = "nav_inventory.png",
wield_image = "nav_inventory.png",
stack_max = 1,
on_use = function(itemstack, player, pointed_thing)
open_formspecs[player:get_player_name()] = true
nav.show_map(player)
end,
})
local function recieve_fields(player, form_name, fields)
if form_name == "nav_map" then
if fields.quit or fields.nav_map_tracker then
@ -112,7 +94,7 @@ local function on_joinplayer(player)
minetest.after(
1.0,
function()
nav.add_waypoint(player:getpos(), "player_"..name, name, false, "player")
nav.add_waypoint(player:getpos(), "player_"..name, name, true, "player")
end)
end
@ -148,6 +130,19 @@ local function step(dtime)
end
end
minetest.register_craftitem(
"nav:map",
{
description = "Map",
inventory_image = "nav_inventory.png",
wield_image = "nav_inventory.png",
stack_max = 1,
on_use = function(itemstack, player, pointed_thing)
open_formspecs[player:get_player_name()] = true
nav.show_map(player)
end,
})
minetest.register_craft(
{
output = "nav:map",

View File

@ -80,6 +80,8 @@ function util.remove_area(pos1, pos2)
end
end
end
manip:write_to_map()
end
function util.areafunc(pos1, pos2, func)
@ -109,23 +111,22 @@ function util.reconstruct(pos1, pos2)
-- fix chests
local nodes = minetest.find_nodes_in_area(pos1, pos2, "default:chest")
local node = minetest.registered_nodes["default:chest"]
for _, pos in ipairs(nodes) do
local node = minetest.registered_nodes[minetest.get_node(pos).name]
node.on_construct(pos)
end
local nodes = minetest.find_nodes_in_area(pos1, pos2, "music:player")
for _, pos in ipairs(nodes) do
local node = minetest.registered_nodes[minetest.get_node(pos).name]
-- fix music players
nodes = minetest.find_nodes_in_area(pos1, pos2, "music:player")
node = minetest.registered_nodes["music:player"]
for _, pos in ipairs(nodes) do
node.on_construct(pos)
end
-- fix furnaces
local nodes = minetest.find_nodes_in_area(pos1, pos2, "default:furnace")
for _, pos in ipairs(nodes) do
local node = minetest.registered_nodes[minetest.get_node(pos).name]
nodes = minetest.find_nodes_in_area(pos1, pos2, "default:furnace")
node = minetest.registered_nodes["default:furnace"]
for _, pos in ipairs(nodes) do
node.on_construct(pos)
end
end

View File

@ -2,3 +2,4 @@ default
util
mobs
goodies
nav

View File

@ -6,6 +6,74 @@ local mp = minetest.get_modpath("village")
village.villages = {}
local village_file = minetest.get_worldpath() .. "/villages"
function village.get_id(name, pos)
return name .. minetest.hash_node_position(pos)
end
function village.save_villages()
local f = io.open(village_file, "w")
for name, def in pairs(village.villages) do
f:write(name .. " " .. def.name .. " " .. minetest.hash_node_position(def.pos) .. "\n")
end
io.close(f)
end
function village.load_villages()
local f = io.open(village_file, "r")
if f then
repeat
local l = f:read("*l")
if l == nil then break end
for name, fname, pos in string.gfind(l, "(.+) (%a+) (%d.+)") do
village.villages[name] = {
name = fname,
pos = minetest.get_position_from_hash(pos),
}
end
until f:read(0) == nil
io.close(f)
else
village.save_villages()
end
village.load_waypoints()
end
function village.load_waypoints()
for name, def in pairs(village.villages) do
nav.remove_waypoint("village_" .. name)
nav.add_waypoint(
def.pos,
"village_" .. name,
def.name .. " village",
true,
"village"
)
end
end
function village.get_nearest_village(pos)
local nearest = 100000 -- big number
local name = nil
for name, def in pairs(village.villages) do
local dist = vector.distance(pos, def.pos)
if dist < nearest then
nearest = dist
name = name
end
end
return {dist = nearest, name = name}
end
village.chunkdefs = {}
village.chunkdefs["livestock_pen"] = {
@ -101,12 +169,19 @@ function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill)
if nofill ~= true then
minetest.place_schematic(
{x = pos.x, y = pos.y-8, z = pos.z},
mp.."/schematics/village_filler.mts",
{x = pos.x, y = pos.y, z = pos.z},
mp.."/schematics/village_empty.mts",
"0",
{},
true
)
minetest.place_schematic(
{x = pos.x-6, y = pos.y-5, z = pos.z-6},
mp.."/schematics/village_filler.mts",
"0",
{},
false
)
end
minetest.place_schematic(
@ -227,16 +302,19 @@ function village.spawn_village(pos, pr)
local depth = pr:next(village.min_size, village.max_size)
village.villages[name] = {
village.villages[village.get_id(name, pos)] = {
name = name,
pos = pos,
}
village.spawn_chunk(pos, "0", {}, pr, "well")
village.save_villages()
village.load_waypoints()
local houses = {}
local built = {}
local roads = {}
village.spawn_chunk(pos, "0", {}, pr, "well")
built[minetest.hash_node_position(pos)] = true
village.spawn_road(pos, houses, built, roads, depth, pr)
@ -310,4 +388,10 @@ function village.spawn_village(pos, pr)
)
end
end
end
end
minetest.after(
0,
function()
village.load_villages()
end)

View File

@ -8,6 +8,8 @@ village = {}
village.min_size = 2 -- min chunk gen iterations
village.max_size = 6 -- max chunk gen iterations
village.min_spawn_dist = 256 -- closest distance a village will spawn from another village
village.pr = PseudoRandom(minetest.get_mapgen_params().seed)
dofile(minetest.get_modpath("village").."/names.lua")

View File

@ -44,9 +44,14 @@ minetest.register_abm(
minetest.remove_node(pos)
local pr = PseudoRandom(minetest.get_mapgen_params().seed+pos.x+pos.y+pos.z)
if node.name == "village:grassland_village_mg" then
if pr:next(1, 60) == 1 then
print("Spawning a (Mapgen)Grassland village at "..dump(pos))
minetest.after(3.0, function() village.spawn_village(pos, pr) end) -- a short delay to (hopefully)ensure that the surrounding terrain is generated
if pr:next(1, 30) == 1 then
local nearest = village.get_nearest_village(pos)
if nearest.dist > village.min_spawn_dist then
print("Spawning a (Mapgen)Grassland village at "..dump(pos))
minetest.after(3.0, function() village.spawn_village(pos, pr) end) -- a short delay to (hopefully)ensure that the surrounding terrain is generated
else
print("Cannot spawn village, too near another village")
end
end
else
print("Spawning a Grassland village at "..dump(pos))

View File

@ -33,6 +33,8 @@ function village.name.generate(pr)
local name = prefix..middle..postfix
name = name:gsub("^%l", string.upper)
village.name.used[name] = true
return name

Binary file not shown.