Clean up several functions.

This commit is contained in:
Duane 2016-06-23 07:23:03 -05:00
parent e6f482c9d5
commit 42916c4666
5 changed files with 159 additions and 103 deletions

150
abms.lua
View file

@ -1,3 +1,7 @@
-------------------------------------------------------------------
-- Abms
-------------------------------------------------------------------
-- see also, fungal_tree.lua -- see also, fungal_tree.lua
-- player surface damage and hunger -- player surface damage and hunger
@ -23,7 +27,7 @@ for i = 1, 4 do
end end
local leaves = {} local leaves = {}
for _, leaf in pairs(fungal_tree_leaves) do for _, leaf in ipairs(fungal_tree_leaves) do
leaves[leaf] = true leaves[leaf] = true
end end
@ -41,6 +45,13 @@ spike_soil['fun_caves:black_sand'] = true
------------------------------------------------------------ ------------------------------------------------------------
-- all the fun_caves globalstep functions -- all the fun_caves globalstep functions
------------------------------------------------------------ ------------------------------------------------------------
local hot_stuff = {"group:surface_hot"}
local cold_stuff = {"group:surface_cold"}
local poison_stuff = {"group:poison"}
local gravity_off = {gravity = 0.1}
local gravity_on = {gravity = 1}
local fortress_floor = {x = 30, y = 2, z = 30}
local fortress_group = {'group:fortress'}
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
local time = minetest.get_gametime() local time = minetest.get_gametime()
@ -50,12 +61,13 @@ minetest.register_globalstep(function(dtime)
end end
-- Promote mobs based on spawn position -- Promote mobs based on spawn position
local is_fortress = fun_caves.is_fortress
for _, mob in pairs(minetest.luaentities) do for _, mob in pairs(minetest.luaentities) do
if not mob.initial_promotion then if not mob.initial_promotion then
local pos = mob.object:getpos() local pos = mob.object:getpos()
if mob.hp_max and mob.object and mob.health and mob.damage then if mob.hp_max and mob.object and mob.health and mob.damage then
local factor = 1 + (math.max(math.abs(pos.x), math.abs(pos.y), math.abs(pos.z)) / 6200) local factor = 1 + (math.max(math.abs(pos.x), math.abs(pos.y), math.abs(pos.z)) / 6200)
if fun_caves.is_fortress(pos) then if is_fortress(pos) then
mob.started_in_fortress = true mob.started_in_fortress = true
factor = factor * 1.5 factor = factor * 1.5
end end
@ -70,14 +82,17 @@ minetest.register_globalstep(function(dtime)
end end
-- Spawn mobs in fortresses -- only when a player is near -- Spawn mobs in fortresses -- only when a player is near
local minetest_find_nodes_in_area = minetest.find_nodes_in_area
local armor_expire = fun_caves.armor_expire
local players = minetest.get_connected_players() local players = minetest.get_connected_players()
local do_fortress_spawns = (fun_caves.fortress_spawns and #fun_caves.fortress_spawns > 0)
for i = 1, #players do for i = 1, #players do
local player = players[i] local player = players[i]
local pos = player:getpos() local pos = player:getpos()
local player_name = player:get_player_name() local player_name = player:get_player_name()
-- How many mobs are up at the moment? This is a rough check. if do_fortress_spawns and is_fortress(pos) and dps_count % monster_delay == 0 then
if fun_caves.fortress_spawns and #fun_caves.fortress_spawns > 0 and dps_count % monster_delay == 0 then -- How many mobs are up at the moment? This is a rough check.
local mob_count = 0 local mob_count = 0
for _, mob in pairs(minetest.luaentities) do for _, mob in pairs(minetest.luaentities) do
if mob.health and mob.started_in_fortress then if mob.health and mob.started_in_fortress then
@ -91,7 +106,9 @@ minetest.register_globalstep(function(dtime)
-- If we need more, spawn them. -- If we need more, spawn them.
if mob_count < fortress_mob_count then if mob_count < fortress_mob_count then
local floor_nodes, count = minetest.find_nodes_in_area_under_air({x=pos.x-30, y=pos.y-2, z=pos.z-30}, {x=pos.x+30, y=pos.y+2, z=pos.z+30}, {"group:fortress"}) local f1 = vector.subtract(pos, fortress_floor)
local f2 = vector.add(pos, fortress_floor)
local floor_nodes, count = minetest.find_nodes_in_area_under_air(f1, f2, fortress_group)
if #floor_nodes > 0 then if #floor_nodes > 0 then
local new_mob_pos = floor_nodes[math.random(#floor_nodes)] local new_mob_pos = floor_nodes[math.random(#floor_nodes)]
new_mob_pos.y = new_mob_pos.y + 2 new_mob_pos.y = new_mob_pos.y + 2
@ -106,14 +123,14 @@ minetest.register_globalstep(function(dtime)
if pos.y >= 11168 and pos.y <= 15168 then if pos.y >= 11168 and pos.y <= 15168 then
if not players_in_orbit[player_name] then if not players_in_orbit[player_name] then
player:set_physics_override({gravity=0.1}) player:set_physics_override(gravity_off)
player:set_sky("#000000", "plain", {}) player:set_sky("#000000", "plain")
players_in_orbit[player_name] = true players_in_orbit[player_name] = true
end end
elseif players_in_orbit[player_name] then elseif players_in_orbit[player_name] then
player:set_sky("#000000", "regular", {}) player:set_sky("#000000", "regular")
minetest.after(20, function() minetest.after(20, function()
player:set_physics_override({gravity=1}) player:set_physics_override(gravity_on)
end) end)
players_in_orbit[player_name] = false players_in_orbit[player_name] = false
end end
@ -125,30 +142,32 @@ minetest.register_globalstep(function(dtime)
player:set_hp(20) player:set_hp(20)
return return
else else
if fun_caves.elixir_armor and fun_caves.armor_expire and fun_caves.armor_expire[player_name] and fun_caves.armor_expire[player_name] < time then if fun_caves.elixir_armor and armor_expire and armor_expire[player_name] and armor_expire[player_name] < time then
player:set_armor_groups({fleshy=100}) local armor = player:get_armor_groups()
armor.fleshy = 100
player:set_armor_groups(armor)
minetest.chat_send_player(player_name, minetest.colorize('#FF0000', 'Your skin feels softer...')) minetest.chat_send_player(player_name, minetest.colorize('#FF0000', 'Your skin feels softer...'))
fun_caves.armor_expire[player_name] = nil armor_expire[player_name] = nil
end end
local minp = vector.subtract(pos, 0.5) local minp = vector.subtract(pos, 0.5)
local maxp = vector.add(pos, 0.5) local maxp = vector.add(pos, 0.5)
-- ... from standing on or near hot objects. -- ... from standing on or near hot objects.
local counts = minetest.find_nodes_in_area(minp, maxp, {"group:surface_hot"}) local counts = minetest_find_nodes_in_area(minp, maxp, hot_stuff)
if #counts > 1 then if #counts > 1 then
player:set_hp(player:get_hp() - 1) player:set_hp(player:get_hp() - 1)
end end
-- ... from standing on or near poison. -- ... from standing on or near poison.
local counts = minetest.find_nodes_in_area(minp, maxp, {"group:poison"}) local counts = minetest_find_nodes_in_area(minp, maxp, poison_stuff)
if #counts > 1 then if #counts > 1 then
player:set_hp(player:get_hp() - 1) player:set_hp(player:get_hp() - 1)
end end
-- ... from standing on or near cold objects (less often). -- ... from standing on or near cold objects (less often).
if dps_count % cold_delay == 0 then if dps_count % cold_delay == 0 then
counts = minetest.find_nodes_in_area(minp, maxp, {"group:surface_cold"}) counts = minetest_find_nodes_in_area(minp, maxp, cold_stuff)
if #counts > 1 then if #counts > 1 then
player:set_hp(player:get_hp() - 1) player:set_hp(player:get_hp() - 1)
end end
@ -213,7 +232,7 @@ minetest.register_abm({
-- Check for stem under the cap. -- Check for stem under the cap.
local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z}) local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
if not node_under or node_under.name ~= "fun_caves:giant_mushroom_stem" then if not node_under or node_under.name ~= "fun_caves:giant_mushroom_stem" then
minetest.set_node(pos, {name = "air"}) minetest.remove_node(pos)
return return
end end
end end
@ -226,7 +245,7 @@ minetest.register_abm({
chance = 110, chance = 110,
action = function(pos, node) action = function(pos, node)
if (minetest.get_node_light(pos, nil) or 99) >= fun_caves.light_max + 2 then if (minetest.get_node_light(pos, nil) or 99) >= fun_caves.light_max + 2 then
minetest.set_node(pos, {name = "air"}) minetest.remove_node(pos)
return return
end end
end end
@ -237,15 +256,18 @@ minetest.register_abm({
------------------------------------------------------------ ------------------------------------------------------------
-- Freezing vapor hardens into ice. -- Freezing vapor hardens into ice.
local ice_node = {name = 'default:ice'}
minetest.register_abm({ minetest.register_abm({
nodenames = {"fun_caves:freezing_vapor"}, nodenames = {"fun_caves:freezing_vapor"},
interval = fun_caves.time_factor, interval = fun_caves.time_factor,
chance = 10, chance = 10,
action = function(pos, node) action = function(pos, node)
minetest.set_node(pos, {name = 'default:ice'}) minetest.set_node(pos, ice_node)
end end
}) })
local no_tree_grow = {'fun_caves:bark', 'fun_caves:leaves'}
local wood_nodes = {{name = 'fun_caves:diamondwood'}, {name = 'fun_caves:ironwood'}, {name = 'fun_caves:tree'}}
minetest.register_abm({ minetest.register_abm({
nodenames = { "fun_caves:tree", 'fun_caves:ironwood', 'fun_caves:diamondwood' }, nodenames = { "fun_caves:tree", 'fun_caves:ironwood', 'fun_caves:diamondwood' },
neighbors = {'air'}, neighbors = {'air'},
@ -253,7 +275,7 @@ minetest.register_abm({
chance = 900, chance = 900,
catch_up = false, catch_up = false,
action = function(pos, node) action = function(pos, node)
local new_pos = minetest.find_node_near(pos, 1, {'fun_caves:bark', 'fun_caves:leaves'}) local new_pos = minetest.find_node_near(pos, 1, no_tree_grow)
if new_pos then if new_pos then
return return
end end
@ -264,16 +286,18 @@ minetest.register_abm({
end end
if math.random(50) == 1 then if math.random(50) == 1 then
minetest.set_node(new_pos, {name = "fun_caves:diamondwood"}) minetest.set_node(new_pos, wood_nodes[1])
elseif math.random(25) == 1 then elseif math.random(25) == 1 then
minetest.set_node(new_pos, {name = "fun_caves:ironwood"}) minetest.set_node(new_pos, wood_nodes[2])
else else
minetest.set_node(new_pos, {name = "fun_caves:tree"}) minetest.set_node(new_pos, wood_nodes[3])
end end
end end
}) })
-- vacuum sucks -- vacuum sucks
local vacuum = {name = 'fun_caves:vacuum'}
local air_list = {'air'}
minetest.register_abm({ minetest.register_abm({
nodenames = {"fun_caves:vacuum"}, nodenames = {"fun_caves:vacuum"},
neighbors = {"air"}, neighbors = {"air"},
@ -286,17 +310,24 @@ minetest.register_abm({
local p1 = vector.subtract(pos, 1) local p1 = vector.subtract(pos, 1)
local p2 = vector.add(pos, 1) local p2 = vector.add(pos, 1)
local positions = minetest.find_nodes_in_area(p1, p2, {"air"}) local positions = minetest.find_nodes_in_area(p1, p2, air_list)
local minetest_get_node_or_nil = minetest.get_node_or_nil
local minetest_set_node = minetest.set_node
for _, p3 in pairs(positions) do for _, p3 in pairs(positions) do
local node2 = minetest.get_node_or_nil(p3) local node2 = minetest_get_node_or_nil(p3)
if node2 and node2.name == 'air' then if node2 and node2.name == 'air' then
minetest.set_node(p3, {name = 'fun_caves:vacuum'}) minetest_set_node(p3, vacuum)
end end
end end
end end
}) })
-- fungal spread -- fungal spread
local fungal_nodes = {}
for _, leaf in pairs(fungal_tree_leaves) do
fungal_nodes[#fungal_nodes+1] = {name = leaf}
end
fungal_nodes[#fungal_nodes+1] = {name = 'fun_caves:fungal_tree_fruit'}
minetest.register_abm({ minetest.register_abm({
nodenames = fungal_tree_leaves, nodenames = fungal_tree_leaves,
neighbors = {"air", "group:liquid"}, neighbors = {"air", "group:liquid"},
@ -312,33 +343,34 @@ minetest.register_abm({
local grow_pos = {x=pos.x, y=pos.y-1, z=pos.z} local grow_pos = {x=pos.x, y=pos.y-1, z=pos.z}
local grow_node = minetest.get_node_or_nil(grow_pos) local grow_node = minetest.get_node_or_nil(grow_pos)
if grow_node and grow_node.name == "air" then if grow_node and grow_node.name == "air" then
minetest.set_node(grow_pos, {name = node.name}) minetest.set_node(grow_pos, node)
return return
end end
grow_pos = {x=math.random(-1,1)+pos.x, y=math.random(-1,1)+pos.y, z=math.random(-1,1)+pos.z} grow_pos = {x=math.random(-1,1)+pos.x, y=math.random(-1,1)+pos.y, z=math.random(-1,1)+pos.z}
grow_node = minetest.get_node_or_nil(grow_pos) grow_node = minetest.get_node_or_nil(grow_pos)
if grow_node and grow_node.name == "air" and (minetest.get_node_light(grow_pos, nil) or 99) <= fun_caves.light_max then if grow_node and grow_node.name == "air" and (minetest.get_node_light(grow_pos, nil) or 99) <= fun_caves.light_max then
minetest.set_node(grow_pos, {name = node.name}) minetest.set_node(grow_pos, node)
return return
elseif grow_node and leaves[grow_node.name] and grow_node.name ~= node.name then elseif grow_node and leaves[grow_node.name] and grow_node.name ~= node.name then
minetest.set_node(grow_pos, {name = 'air'}) minetest.remove_node(grow_pos)
return return
end end
if math.random(40) == 1 then if math.random(40) == 1 then
minetest.set_node(pos, {name = "fun_caves:fungal_tree_fruit"}) minetest.set_node(pos, fungal_nodes[#fungal_nodes])
return return
end end
if math.random(100) == 1 then if math.random(100) == 1 then
minetest.set_node(pos, {name = fungal_tree_leaves[math.random(#fungal_tree_leaves)]}) minetest.set_node(pos, fungal_nodes[math.random(#fungal_nodes - 1)])
return return
end end
end end
}) })
-- mushroom growth -- caps regenerate in time -- mushroom growth -- caps regenerate in time
local huge_mushroom_cap_node = {name = 'fun_caves:huge_mushroom_cap'}
minetest.register_abm({ minetest.register_abm({
nodenames = {"fun_caves:giant_mushroom_stem"}, nodenames = {"fun_caves:giant_mushroom_stem"},
interval = 2 * fun_caves.time_factor, interval = 2 * fun_caves.time_factor,
@ -351,12 +383,16 @@ minetest.register_abm({
end end
if (minetest.get_node_light(pos_up, nil) or 99) <= fun_caves.light_max then if (minetest.get_node_light(pos_up, nil) or 99) <= fun_caves.light_max then
minetest.set_node(pos_up, {name = "fun_caves:huge_mushroom_cap"}) minetest.set_node(pos_up, huge_mushroom_cap_node)
end end
end end
}) })
-- new fungi -- new fungi
local mushroom_nodes = {}
for _, mushroom in pairs(mushrooms) do
mushroom_nodes[#mushroom_nodes+1] = {name = mushroom}
end
minetest.register_abm({ minetest.register_abm({
nodenames = {"default:dirt"}, nodenames = {"default:dirt"},
neighbors = {"air"}, neighbors = {"air"},
@ -372,15 +408,16 @@ minetest.register_abm({
if grow_node and grow_node.name == "air" if grow_node and grow_node.name == "air"
and (minetest.get_node_light(grow_pos, nil) or 99) <= fun_caves.light_max then and (minetest.get_node_light(grow_pos, nil) or 99) <= fun_caves.light_max then
if math.random(4) == 1 then if math.random(4) == 1 then
minetest.set_node(grow_pos, {name = fungal_tree_leaves[math.random(#fungal_tree_leaves)]}) minetest.set_node(grow_pos, fungal_nodes[math.random(#fungal_nodes - 1)])
else else
minetest.set_node(grow_pos, {name = mushrooms[math.random(#mushrooms)]}) minetest.set_node(grow_pos, mushroom_nodes[math.random(#mushroom_nodes)])
end end
end end
end end
}) })
-- mushroom growth -- small into huge -- mushroom growth -- small into huge
local giant_mushroom_stem_node = {name = 'fun_caves:giant_mushroom_stem'}
minetest.register_abm({ minetest.register_abm({
nodenames = mushrooms, nodenames = mushrooms,
interval = 5 * fun_caves.time_factor, interval = 5 * fun_caves.time_factor,
@ -404,12 +441,13 @@ minetest.register_abm({
return return
end end
minetest.set_node(pos_up, {name = "fun_caves:huge_mushroom_cap"}) minetest.set_node(pos_up, huge_mushroom_cap_node)
minetest.set_node(pos, {name = "fun_caves:giant_mushroom_stem"}) minetest.set_node(pos, giant_mushroom_stem_node)
end end
}) })
-- mushroom growth -- huge into giant -- mushroom growth -- huge into giant
local giant_mushroom_cap_node = {name = "fun_caves:giant_mushroom_cap"}
minetest.register_abm({ minetest.register_abm({
nodenames = {"fun_caves:huge_mushroom_cap"}, nodenames = {"fun_caves:huge_mushroom_cap"},
interval = 9 * fun_caves.time_factor, interval = 9 * fun_caves.time_factor,
@ -429,7 +467,7 @@ minetest.register_abm({
return return
end end
minetest.set_node(pos_up, {name = "fun_caves:giant_mushroom_cap"}) minetest.set_node(pos_up, giant_mushroom_cap_node)
minetest.set_node(pos, {name = "fun_caves:giant_mushroom_stem"}) minetest.set_node(pos, {name = "fun_caves:giant_mushroom_stem"})
end end
}) })
@ -494,7 +532,8 @@ minetest.register_abm({
local sky = {} local sky = {}
sky.bgcolor, sky.type, sky.textures = players[i]:get_sky() sky.bgcolor, sky.type, sky.textures = players[i]:get_sky()
ps[#ps+1] = { p = players[i], sky = sky } ps[#ps+1] = { p = players[i], sky = sky }
players[i]:set_sky(0xffffff, "plain", {}) --players[i]:set_sky(0xffffff, "plain", {})
players[i]:set_sky(0xffffff, "plain")
end end
end end
@ -574,7 +613,7 @@ local function destroy(pos, cid)
return return
end end
minetest.set_node(pos, {name="air"}) minetest.remove_node(pos)
end end
local function explode(pos, radius) local function explode(pos, radius)
@ -591,22 +630,23 @@ local function explode(pos, radius)
local c_air = minetest.get_content_id("air") local c_air = minetest.get_content_id("air")
local math_random = math.random
for z = -radius, radius do for z = -radius, radius do
for y = -radius, 4*radius do for y = -radius, 4*radius do
local vi = a:index(pos.x + (-radius), pos.y + y, pos.z + z) local vi = a:index(pos.x + (-radius), pos.y + y, pos.z + z)
for x = -radius, radius do for x = -radius, radius do
if (x * x) + (y * y / 4) + (z * z) <= if (x * x) + (y * y / 4) + (z * z) <=
(radius * radius) + math.random(-radius, radius) then (radius * radius) + math_random(-radius, radius) then
local cid = data[vi] local cid = data[vi]
p.x = pos.x + x p.x = pos.x + x
p.y = pos.y + y p.y = pos.y + y
p.z = pos.z + z p.z = pos.z + z
if cid ~= c_air then if cid ~= c_air then
destroy(p, cid) destroy(p, cid)
end
end
vi = vi + 1
end end
end
vi = vi + 1
end
end end
end end
end end
@ -630,10 +670,12 @@ local function entity_physics(pos, radius)
-- Make the damage radius larger than the destruction radius -- Make the damage radius larger than the destruction radius
radius = radius * 2 radius = radius * 2
local objs = minetest.get_objects_inside_radius(pos, radius) local objs = minetest.get_objects_inside_radius(pos, radius)
local math_max = math.max
local vector_distance = vector.distance
for _, obj in pairs(objs) do for _, obj in pairs(objs) do
local obj_pos = obj:getpos() local obj_pos = obj:getpos()
local obj_vel = obj:getvelocity() local obj_vel = obj:getvelocity()
local dist = math.max(1, vector.distance(pos, obj_pos)) local dist = math_max(1, vector_distance(pos, obj_pos))
if obj_vel ~= nil then if obj_vel ~= nil then
obj:setvelocity(calc_velocity(pos, obj_pos, obj:setvelocity(calc_velocity(pos, obj_pos,
@ -657,7 +699,7 @@ fun_caves.soft_boom = function(pos)
minetest.sound_play("tnt_explode", {pos=pos, gain=1.5, max_hear_distance=2*64}) minetest.sound_play("tnt_explode", {pos=pos, gain=1.5, max_hear_distance=2*64})
local radius = 5 local radius = 5
minetest.set_node(pos, {name="air"}) minetest.remove_node(pos)
explode(pos, radius) explode(pos, radius)
entity_physics(pos, radius) entity_physics(pos, radius)
add_effects(pos, radius) add_effects(pos, radius)

View file

@ -11,7 +11,6 @@ fun_caves.cavegen = function(minp, maxp, data, area, node, heightmap, underzone)
local csize = vector.add(vector.subtract(maxp, minp), 1) local csize = vector.add(vector.subtract(maxp, minp), 1)
local map_max = {x = csize.x, y = csize.y + 2, z = csize.z} local map_max = {x = csize.x, y = csize.y + 2, z = csize.z}
local map_min = {x = minp.x, y = minp.y - 1, z = minp.z} local map_min = {x = minp.x, y = minp.y - 1, z = minp.z}
--local noise_area = VoxelArea:new({MinEdge=map_min, MaxEdge={x=maxp.x,y=maxp.y+1,z=maxp.z}})
local cave_1 = minetest.get_perlin_map(fun_caves.cave_noise_1, map_max):get3dMap_flat(map_min) local cave_1 = minetest.get_perlin_map(fun_caves.cave_noise_1, map_max):get3dMap_flat(map_min)
local cave_2 = minetest.get_perlin_map(fun_caves.cave_noise_2, map_max):get3dMap_flat(map_min) local cave_2 = minetest.get_perlin_map(fun_caves.cave_noise_2, map_max):get3dMap_flat(map_min)
@ -21,10 +20,11 @@ fun_caves.cavegen = function(minp, maxp, data, area, node, heightmap, underzone)
local index = 0 local index = 0
local index3d = 0 local index3d = 0
local cave_width = fun_caves.cave_width
local styx_sea_level = fun_caves.underzones['Styx'].sealevel
for z = minp.z, maxp.z do for z = minp.z, maxp.z do
for x = minp.x, maxp.x do for x = minp.x, maxp.x do
index = index + 1 index = index + 1
--index3d = noise_area:index(x, minp.y-1, z)
index3d = (z - minp.z) * (csize.y + 2) * csize.x + (x - minp.x) + 1 index3d = (z - minp.z) * (csize.y + 2) * csize.x + (x - minp.x) + 1
local ivm = area:index(x, minp.y-1, z) local ivm = area:index(x, minp.y-1, z)
@ -66,8 +66,8 @@ fun_caves.cavegen = function(minp, maxp, data, area, node, heightmap, underzone)
write = true write = true
elseif underzone and (y < underzone.ceiling + 10 - (underzone.vary and cave_3[index] or 0) and y > underzone.floor - 10 + (underzone.vary and cave_3[index] or 0)) then elseif underzone and (y < underzone.ceiling + 10 - (underzone.vary and cave_3[index] or 0) and y > underzone.floor - 10 + (underzone.vary and cave_3[index] or 0)) then
-- nop -- nop
elseif ((y <= maxp.y and y >= minp.y) or (data[ivm] == node['default:stone'])) and y < height - cave_3[index] and cave_1[index3d] * cave_2[index3d] > fun_caves.cave_width then elseif ((y <= maxp.y and y >= minp.y) or (data[ivm] == node['default:stone'])) and y < height - cave_3[index] and cave_1[index3d] * cave_2[index3d] > cave_width then
if y <= fun_caves.underzones['Styx'].sealevel then if y <= styx_sea_level then
data[ivm] = node["default:water_source"] data[ivm] = node["default:water_source"]
else else
data[ivm] = node["air"] data[ivm] = node["air"]

View file

@ -30,19 +30,19 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
local biomemap = minetest.get_mapgen_object("biomemap") local biomemap = minetest.get_mapgen_object("biomemap")
local map_max = {x = csize.x, y = csize.y + 2, z = csize.z} local map_max = {x = csize.x, y = csize.y + 2, z = csize.z}
local map_min = {x = minp.x, y = minp.y - 1, z = minp.z} local map_min = {x = minp.x, y = minp.y - 1, z = minp.z}
--local noise_area = VoxelArea:new({MinEdge={x=0,y=-1,z=0}, MaxEdge={x=csize.x,y=csize.y+1,z=csize.z}})
local biome_n = minetest.get_perlin_map(biome_noise, map_max):get3dMap_flat(map_min) local biome_n = minetest.get_perlin_map(biome_noise, map_max):get3dMap_flat(map_min)
local plant_n = minetest.get_perlin_map(plant_noise, {x=csize.x, y=csize.z}):get2dMap_flat({x=minp.x, y=minp.z}) local plant_n = minetest.get_perlin_map(plant_noise, {x=csize.x, y=csize.z}):get2dMap_flat({x=minp.x, y=minp.z})
local math_random = math.random
local dis_map = {} local dis_map = {}
if underzone and underzone.name == 'Dis' then if underzone and underzone.name == 'Dis' then
for i = 0, 10, 2 do for i = 0, 10, 2 do
dis_map[i] = {} dis_map[i] = {}
for j = 0, 10, 2 do for j = 0, 10, 2 do
dis_map[i][j] = math.random(6) dis_map[i][j] = math_random(6)
if dis_map[i][j] == 6 then if dis_map[i][j] == 6 then
dis_map[i][j] = 5 + math.random(10) dis_map[i][j] = 5 + math_random(10)
end end
end end
end end
@ -55,10 +55,14 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
local index = 0 local index = 0
local index3d = 0 local index3d = 0
local pos = {x=0, y=0, z=0}
local math_floor = math.floor
local math_max = math.max
local math_min = math.min
local math_log = math.log
for z = minp.z, maxp.z do for z = minp.z, maxp.z do
for x = minp.x, maxp.x do for x = minp.x, maxp.x do
index = index + 1 index = index + 1
--index3d = noise_area:index(x - minp.x, -1, z - minp.z)
index3d = (z - minp.z) * (csize.y + 2) * csize.x + (x - minp.x) + 1 index3d = (z - minp.z) * (csize.y + 2) * csize.x + (x - minp.x) + 1
local ivm = area:index(x, minp.y, z) local ivm = area:index(x, minp.y, z)
@ -84,7 +88,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
-- Compress biomes at the surface to avoid fluids. -- Compress biomes at the surface to avoid fluids.
if y > fluid_compression then if y > fluid_compression then
biome_val = biome_val / math.max(1, math.log(y - fluid_compression)) biome_val = biome_val / math_max(1, math_log(y - fluid_compression))
end end
for _, bi in pairs(fun_caves.cave_biomes) do for _, bi in pairs(fun_caves.cave_biomes) do
@ -117,7 +121,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end end
if data[ivm] == node["default:stone"] then if data[ivm] == node["default:stone"] then
if node_above == node["air"] and biome and biome.dirt and math.random(biome.dirt_chance) == 1 then if node_above == node["air"] and biome and biome.dirt and math_random(biome.dirt_chance) == 1 then
data[ivm] = node[biome.dirt] data[ivm] = node[biome.dirt]
write = true write = true
break break
@ -131,7 +135,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end end
if air_above then if air_above then
if biome and biome.deco and math.random(biome.deco_chance) == 1 then if biome and biome.deco and math_random(biome.deco_chance) == 1 then
data[ivm] = node[biome.deco] data[ivm] = node[biome.deco]
write = true write = true
break break
@ -156,7 +160,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end end
if air_below then if air_below then
if biome and biome.deco and math.random(biome.deco_chance) == 1 then if biome and biome.deco and math_random(biome.deco_chance) == 1 then
data[ivm] = node[biome.deco] data[ivm] = node[biome.deco]
write = true write = true
break break
@ -169,7 +173,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end end
-- smallest city generator ever -- smallest city generator ever
if underzone and underzone.name == 'Dis' and data[ivm] == node['air'] and math.floor((x - minp.x) / 8) % 2 == 0 and math.floor((z - minp.z) / 8) % 2 == 0 and y - underzone.floor < dis_map[math.floor((x - minp.x) / 8)][math.floor((z - minp.z) / 8)] * 4 + 1 and y - underzone.floor >= 0 then if underzone and underzone.name == 'Dis' and data[ivm] == node['air'] and math_floor((x - minp.x) / 8) % 2 == 0 and math_floor((z - minp.z) / 8) % 2 == 0 and y - underzone.floor < dis_map[math_floor((x - minp.x) / 8)][math_floor((z - minp.z) / 8)] * 4 + 1 and y - underzone.floor >= 0 then
local dx = (x - minp.x) % 16 local dx = (x - minp.x) % 16
local dy = y - underzone.floor + 1 local dy = y - underzone.floor + 1
local dz = (z - minp.z) % 16 local dz = (z - minp.z) % 16
@ -189,22 +193,22 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
if data[ivm] == node["air"] and y < maxp.y then if data[ivm] == node["air"] and y < maxp.y then
-- hanging down -- hanging down
-- stone hasn't yet been changed -- stone hasn't yet been changed
if biome and biome.stalactite and node_above == node["default:stone"] and math.random(biome.stalactite_chance) == 1 then if biome and biome.stalactite and node_above == node["default:stone"] and math_random(biome.stalactite_chance) == 1 then
data[ivm] = node[biome.stalactite] data[ivm] = node[biome.stalactite]
write = true write = true
break break
end end
-- fluids -- fluids
if y > minp.y and biome and biome.fluid and node_below == node[biome.floor_node] and math.random(biome.fluid_chance) == 1 then if y > minp.y and biome and biome.fluid and node_below == node[biome.floor_node] and math_random(biome.fluid_chance) == 1 then
data[ivm] = node[biome.fluid] data[ivm] = node[biome.fluid]
write = true write = true
break break
-- standing up -- standing up
elseif node_below == node[biome.floor_node] and biome and biome.stalagmite and math.random(biome.stalagmite_chance) == 1 then elseif node_below == node[biome.floor_node] and biome and biome.stalagmite and math_random(biome.stalagmite_chance) == 1 then
if type(biome.stalagmite) == 'table' then if type(biome.stalagmite) == 'table' then
data[ivm] = node[biome.stalagmite[math.random(#biome.stalagmite)]] data[ivm] = node[biome.stalagmite[math_random(#biome.stalagmite)]]
else else
data[ivm] = node[biome.stalagmite] data[ivm] = node[biome.stalagmite]
end end
@ -213,11 +217,11 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
-- vegetation -- vegetation
elseif node_below == node["fun_caves:polluted_dirt"] then elseif node_below == node["fun_caves:polluted_dirt"] then
if math.random(10) == 1 then if math_random(10) == 1 then
data[ivm] = node["default:dry_shrub"] data[ivm] = node["default:dry_shrub"]
write = true write = true
break break
elseif math.random(50) == 1 then elseif math_random(50) == 1 then
local air_count = 0 local air_count = 0
local j local j
for i = 1, 9 do for i = 1, 9 do
@ -227,23 +231,26 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end end
end end
if air_count > 6 then if air_count > 6 then
fun_caves.place_schematic(minp, maxp, data, p2data, area, node, {x=x,y=y,z=z}, fun_caves.schematics['decaying_tree'], true) pos.x = x
pos.y = y
pos.z = z
fun_caves.place_schematic(minp, maxp, data, p2data, area, node, pos, fun_caves.schematics['decaying_tree'], true)
end end
end end
elseif node_below == node["default:dirt"] and biome and biome.fungi then elseif node_below == node["default:dirt"] and biome and biome.fungi then
if math.random(10) == 1 then if math_random(10) == 1 then
data[ivm] = node["flowers:mushroom_red"] data[ivm] = node["flowers:mushroom_red"]
write = true write = true
break break
elseif math.random(10) == 1 then elseif math_random(10) == 1 then
data[ivm] = node["flowers:mushroom_brown"] data[ivm] = node["flowers:mushroom_brown"]
write = true write = true
break break
elseif node_above == node["air"] and math.random(10) == 1 then elseif node_above == node["air"] and math_random(10) == 1 then
data[ivm] = node["fun_caves:giant_mushroom_stem"] data[ivm] = node["fun_caves:giant_mushroom_stem"]
write = true write = true
break break
elseif math.random(30) == 1 then elseif math_random(30) == 1 then
local air_count = 0 local air_count = 0
local j local j
for i = 1, 12 do for i = 1, 12 do
@ -253,7 +260,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end end
end end
if air_count > 5 then if air_count > 5 then
fun_caves.make_fungal_tree(data, area, ivm, math.random(2, math.min(air_count, 12))) fun_caves.make_fungal_tree(data, area, ivm, math_random(2, math_min(air_count, 12)))
end end
end end
elseif node_below == node["fun_caves:giant_mushroom_stem"] and data[ivm - area.ystride * 2] == node["fun_caves:giant_mushroom_stem"] then elseif node_below == node["fun_caves:giant_mushroom_stem"] and data[ivm - area.ystride * 2] == node["fun_caves:giant_mushroom_stem"] then
@ -261,7 +268,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
write = true write = true
break break
elseif node_below == node["fun_caves:giant_mushroom_stem"] then elseif node_below == node["fun_caves:giant_mushroom_stem"] then
if node_above == node["air"] and math.random(3) == 1 then if node_above == node["air"] and math_random(3) == 1 then
data[ivm] = node["fun_caves:giant_mushroom_stem"] data[ivm] = node["fun_caves:giant_mushroom_stem"]
write = true write = true
break break
@ -299,20 +306,20 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
local node_below = data[ivm - area.ystride] local node_below = data[ivm - area.ystride]
local node_above = data[ivm + area.ystride] local node_above = data[ivm + area.ystride]
if y < water_level and data[ivm] == node["default:sand"] and node_above == node["default:water_source"] and data[ivm + area.ystride * 2] == node["default:water_source"] and coral_biomes[biome] and pn < -0.1 and math.random(5) == 1 and fun_caves.surround(node, data, area, ivm) then if y < water_level and data[ivm] == node["default:sand"] and node_above == node["default:water_source"] and data[ivm + area.ystride * 2] == node["default:water_source"] and coral_biomes[biome] and pn < -0.1 and math_random(5) == 1 and fun_caves.surround(node, data, area, ivm) then
if math.random(100) == 1 then if math_random(100) == 1 then
data[ivm] = node["fun_caves:precious_coral_water_sand"] data[ivm] = node["fun_caves:precious_coral_water_sand"]
else else
data[ivm] = node["fun_caves:staghorn_coral_water_sand"] data[ivm] = node["fun_caves:staghorn_coral_water_sand"]
end end
write = true write = true
break break
elseif y < water_level and node_below == node["default:sand"] and node_above == node["default:water_source"] and data[ivm] == node["default:water_source"] and coral_biomes[biome] and pn < -0.1 and math.random(5) < 3 then elseif y < water_level and node_below == node["default:sand"] and node_above == node["default:water_source"] and data[ivm] == node["default:water_source"] and coral_biomes[biome] and pn < -0.1 and math_random(5) < 3 then
if math.random(15) == 1 then if math_random(15) == 1 then
data[ivm] = node["fun_caves:brain_coral"] data[ivm] = node["fun_caves:brain_coral"]
write = true write = true
break break
elseif math.random(15) == 1 then elseif math_random(15) == 1 then
data[ivm] = node["fun_caves:dragon_eye"] data[ivm] = node["fun_caves:dragon_eye"]
write = true write = true
break break
@ -340,7 +347,10 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
-- against a given node (or nodes). However, it's slow. -- against a given node (or nodes). However, it's slow.
-- To speed it up, we cache the results for each plant -- To speed it up, we cache the results for each plant
-- on each node, and avoid calling find_nodes every time. -- on each node, and avoid calling find_nodes every time.
local posm, count = minetest.find_nodes_in_area({x=x, y=y, z=z}, {x=x, y=y, z=z}, desc.place_on) pos.x = x
pos.y = y
pos.z = z
local posm, count = minetest.find_nodes_in_area(pos, pos, desc.place_on)
if #posm > 0 then if #posm > 0 then
node_match_cache[desc.content_id][data[ivm]] = "good" node_match_cache[desc.content_id][data[ivm]] = "good"
else else
@ -348,14 +358,14 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end end
end end
if node_match_cache[desc.content_id][data[ivm]] == "good" and desc.fill_ratio and (not desc.biomes or (biome and desc.biomes and table.contains(desc.biomes, biome))) and math.random() <= desc.fill_ratio then if node_match_cache[desc.content_id][data[ivm]] == "good" and desc.fill_ratio and (not desc.biomes or (biome and desc.biomes and table.contains(desc.biomes, biome))) and math_random() <= desc.fill_ratio then
data[ivm] = desc.content_id data[ivm] = desc.content_id
write = true write = true
break break
end end
end end
end end
elseif y > minp.y and node_below == node["default:river_water_source"] and data[ivm] == node["air"] and water_lily_biomes[biome] and pn > 0.5 and math.random(water_lily_ratio) == 1 then elseif y > minp.y and node_below == node["default:river_water_source"] and data[ivm] == node["air"] and water_lily_biomes[biome] and pn > 0.5 and math_random(water_lily_ratio) == 1 then
-- on top of the water -- on top of the water
-- I haven't figured out what the decoration manager is -- I haven't figured out what the decoration manager is
-- doing with the noise functions, but this works ok. -- doing with the noise functions, but this works ok.

View file

@ -99,18 +99,17 @@ fun_caves.place_schematic = function(minp, maxp, data, p2data, area, node, pos,
if pos.x + x > minp.x and pos.x + x < maxp.x and pos.z + z > minp.z and pos.z + z < maxp.z then if pos.x + x > minp.x and pos.x + x < maxp.x and pos.z + z > minp.z and pos.z + z < maxp.z then
local ivm = area:index(pos.x + x, pos.y, pos.z + z) local ivm = area:index(pos.x + x, pos.y, pos.z + z)
local isch = z1 * schem.size.y * schem.size.x + x1 + 1 local isch = z1 * schem.size.y * schem.size.x + x1 + 1
local math_random = math.random
for y = 0, schem.size.y - 1 do for y = 0, schem.size.y - 1 do
local dy = pos.y - minp.y + y local dy = pos.y - minp.y + y
--if math.min(dx, csize.x - dx) + math.min(dy, csize.y - dy) + math.min(dz, csize.z - dz) > bevel then if yslice[y] or 255 >= math_random(255) then
if yslice[y] or 255 >= math.random(255) then
local prob = schem.data[isch].prob or schem.data[isch].param1 or 255 local prob = schem.data[isch].prob or schem.data[isch].param1 or 255
if prob >= math.random(255) and schem.data[isch].name ~= "air" then if prob >= math_random(255) and schem.data[isch].name ~= "air" then
data[ivm] = node[schem.data[isch].name] data[ivm] = node[schem.data[isch].name]
end end
local param2 = schem.data[isch].param2 or 0 local param2 = schem.data[isch].param2 or 0
p2data[ivm] = param2 p2data[ivm] = param2
end end
--end
ivm = ivm + area.ystride ivm = ivm + area.ystride
isch = isch + schem.size.x isch = isch + schem.size.x

View file

@ -201,27 +201,32 @@ fun_caves.treegen = function(minp, maxp, data, p2data, area, node)
local index = 0 local index = 0
local index3d = 0 local index3d = 0
local math_random = math.random
local math_floor = math.floor
local math_abs = math.abs
local math_max = math.max
local math_sqrt = math.sqrt
for z = minp.z, maxp.z do for z = minp.z, maxp.z do
for x = minp.x, maxp.x do for x = minp.x, maxp.x do
local dx = (x + 32) % 160 - 80 local dx = (x + 32) % 160 - 80
local dz = (z + 32) % 160 - 80 local dz = (z + 32) % 160 - 80
local r2 = 70 + math.floor(dx / 4) % 3 * 6 + math.floor(dz / 4) % 3 * 6 local r2 = 70 + math_floor(dx / 4) % 3 * 6 + math_floor(dz / 4) % 3 * 6
index = index + 1 index = index + 1
index3d = (z - minp.z) * (csize.y + 2) * csize.x + (x - minp.x) + 1 index3d = (z - minp.z) * (csize.y + 2) * csize.x + (x - minp.x) + 1
local ivm = area:index(x, minp.y - 1, z) local ivm = area:index(x, minp.y - 1, z)
local distance = math.floor(math.sqrt(dx ^ 2 + dz ^ 2)) local distance = math_floor(math_sqrt(dx ^ 2 + dz ^ 2))
for y = minp.y - 1, maxp.y + 1 do for y = minp.y - 1, maxp.y + 1 do
local dy = y - minp.y local dy = y - minp.y
local r = 20 local r = 20
if math.abs(y - 50) > 130 then if math_abs(y - 50) > 130 then
r = math.max(0, r - math.floor((math.abs(y - 50) - 130) / 2)) r = math_max(0, r - math_floor((math_abs(y - 50) - 130) / 2))
end end
local distance3 local distance3
if y > 112 then if y > 112 then
distance3 = math.floor(math.sqrt(dx ^ 2 + dz ^ 2 + (y - 192) ^ 2)) distance3 = math_floor(math_sqrt(dx ^ 2 + dz ^ 2 + (y - 192) ^ 2))
end end
if distance < r then if distance < r then
@ -243,7 +248,7 @@ fun_caves.treegen = function(minp, maxp, data, p2data, area, node)
data[ivm] = node['fun_caves:diamondwood'] data[ivm] = node['fun_caves:diamondwood']
end end
if data[ivm] ~= node['air'] and data[ivm] ~= node['fun_caves:weightless_water'] and math.random(500) == 1 then if data[ivm] ~= node['air'] and data[ivm] ~= node['fun_caves:weightless_water'] and math_random(500) == 1 then
data[ivm] = node['fun_caves:sap'] data[ivm] = node['fun_caves:sap']
end end
write = true write = true
@ -252,15 +257,15 @@ fun_caves.treegen = function(minp, maxp, data, p2data, area, node)
write = true write = true
-- foliage -- foliage
elseif y < 272 and y > 112 and distance3 and distance3 < r2 and y % 10 == 0 and (math.floor(dx / 4) % 3 == 0 or math.floor(dz / 4) % 3 == 0) then elseif y < 272 and y > 112 and distance3 and distance3 < r2 and y % 10 == 0 and (math_floor(dx / 4) % 3 == 0 or math_floor(dz / 4) % 3 == 0) then
if data[ivm] == node['air'] then if data[ivm] == node['air'] then
data[ivm] = node['fun_caves:bark'] data[ivm] = node['fun_caves:bark']
write = true write = true
end end
elseif y < 275 and y > 115 and distance3 and distance3 < r2 and (y + 3) % 10 < 7 and (math.floor((dx + 3) / 4) % 3 < 2 or math.floor((dz + 3) / 4) % 3 < 2) then elseif y < 275 and y > 115 and distance3 and distance3 < r2 and (y + 3) % 10 < 7 and (math_floor((dx + 3) / 4) % 3 < 2 or math_floor((dz + 3) / 4) % 3 < 2) then
local r = math.abs(((y + 3) % 10) - 3) local r = math_abs(((y + 3) % 10) - 3)
if (r < 2 or math.random(r) == 1) and data[ivm] == node['air'] then if (r < 2 or math_random(r) == 1) and data[ivm] == node['air'] then
if distance3 > r2 - 10 and math.random(10) == 1 then if distance3 > r2 - 10 and math_random(10) == 1 then
data[ivm] = node['fun_caves:leaves_special'] data[ivm] = node['fun_caves:leaves_special']
else else
data[ivm] = node['fun_caves:leaves'] data[ivm] = node['fun_caves:leaves']