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
-- player surface damage and hunger
@ -23,7 +27,7 @@ for i = 1, 4 do
end
local leaves = {}
for _, leaf in pairs(fungal_tree_leaves) do
for _, leaf in ipairs(fungal_tree_leaves) do
leaves[leaf] = true
end
@ -41,6 +45,13 @@ spike_soil['fun_caves:black_sand'] = true
------------------------------------------------------------
-- 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)
local time = minetest.get_gametime()
@ -50,12 +61,13 @@ minetest.register_globalstep(function(dtime)
end
-- Promote mobs based on spawn position
local is_fortress = fun_caves.is_fortress
for _, mob in pairs(minetest.luaentities) do
if not mob.initial_promotion then
local pos = mob.object:getpos()
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)
if fun_caves.is_fortress(pos) then
if is_fortress(pos) then
mob.started_in_fortress = true
factor = factor * 1.5
end
@ -70,14 +82,17 @@ minetest.register_globalstep(function(dtime)
end
-- 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 do_fortress_spawns = (fun_caves.fortress_spawns and #fun_caves.fortress_spawns > 0)
for i = 1, #players do
local player = players[i]
local pos = player:getpos()
local player_name = player:get_player_name()
-- How many mobs are up at the moment? This is a rough check.
if fun_caves.fortress_spawns and #fun_caves.fortress_spawns > 0 and dps_count % monster_delay == 0 then
if do_fortress_spawns and is_fortress(pos) and dps_count % monster_delay == 0 then
-- How many mobs are up at the moment? This is a rough check.
local mob_count = 0
for _, mob in pairs(minetest.luaentities) do
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 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
local new_mob_pos = floor_nodes[math.random(#floor_nodes)]
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 not players_in_orbit[player_name] then
player:set_physics_override({gravity=0.1})
player:set_sky("#000000", "plain", {})
player:set_physics_override(gravity_off)
player:set_sky("#000000", "plain")
players_in_orbit[player_name] = true
end
elseif players_in_orbit[player_name] then
player:set_sky("#000000", "regular", {})
player:set_sky("#000000", "regular")
minetest.after(20, function()
player:set_physics_override({gravity=1})
player:set_physics_override(gravity_on)
end)
players_in_orbit[player_name] = false
end
@ -125,30 +142,32 @@ minetest.register_globalstep(function(dtime)
player:set_hp(20)
return
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
player:set_armor_groups({fleshy=100})
if fun_caves.elixir_armor and armor_expire and armor_expire[player_name] and armor_expire[player_name] < time then
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...'))
fun_caves.armor_expire[player_name] = nil
armor_expire[player_name] = nil
end
local minp = vector.subtract(pos, 0.5)
local maxp = vector.add(pos, 0.5)
-- ... 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
player:set_hp(player:get_hp() - 1)
end
-- ... 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
player:set_hp(player:get_hp() - 1)
end
-- ... from standing on or near cold objects (less often).
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
player:set_hp(player:get_hp() - 1)
end
@ -213,7 +232,7 @@ minetest.register_abm({
-- Check for stem under the cap.
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
minetest.set_node(pos, {name = "air"})
minetest.remove_node(pos)
return
end
end
@ -226,7 +245,7 @@ minetest.register_abm({
chance = 110,
action = function(pos, node)
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
end
end
@ -237,15 +256,18 @@ minetest.register_abm({
------------------------------------------------------------
-- Freezing vapor hardens into ice.
local ice_node = {name = 'default:ice'}
minetest.register_abm({
nodenames = {"fun_caves:freezing_vapor"},
interval = fun_caves.time_factor,
chance = 10,
action = function(pos, node)
minetest.set_node(pos, {name = 'default:ice'})
minetest.set_node(pos, ice_node)
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({
nodenames = { "fun_caves:tree", 'fun_caves:ironwood', 'fun_caves:diamondwood' },
neighbors = {'air'},
@ -253,7 +275,7 @@ minetest.register_abm({
chance = 900,
catch_up = false,
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
return
end
@ -264,16 +286,18 @@ minetest.register_abm({
end
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
minetest.set_node(new_pos, {name = "fun_caves:ironwood"})
minetest.set_node(new_pos, wood_nodes[2])
else
minetest.set_node(new_pos, {name = "fun_caves:tree"})
minetest.set_node(new_pos, wood_nodes[3])
end
end
})
-- vacuum sucks
local vacuum = {name = 'fun_caves:vacuum'}
local air_list = {'air'}
minetest.register_abm({
nodenames = {"fun_caves:vacuum"},
neighbors = {"air"},
@ -286,17 +310,24 @@ minetest.register_abm({
local p1 = vector.subtract(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
local node2 = minetest.get_node_or_nil(p3)
local node2 = minetest_get_node_or_nil(p3)
if node2 and node2.name == 'air' then
minetest.set_node(p3, {name = 'fun_caves:vacuum'})
minetest_set_node(p3, vacuum)
end
end
end
})
-- 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({
nodenames = fungal_tree_leaves,
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_node = minetest.get_node_or_nil(grow_pos)
if grow_node and grow_node.name == "air" then
minetest.set_node(grow_pos, {name = node.name})
minetest.set_node(grow_pos, node)
return
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_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
minetest.set_node(grow_pos, {name = node.name})
minetest.set_node(grow_pos, node)
return
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
end
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
end
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
end
end
})
-- mushroom growth -- caps regenerate in time
local huge_mushroom_cap_node = {name = 'fun_caves:huge_mushroom_cap'}
minetest.register_abm({
nodenames = {"fun_caves:giant_mushroom_stem"},
interval = 2 * fun_caves.time_factor,
@ -351,12 +383,16 @@ minetest.register_abm({
end
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
})
-- new fungi
local mushroom_nodes = {}
for _, mushroom in pairs(mushrooms) do
mushroom_nodes[#mushroom_nodes+1] = {name = mushroom}
end
minetest.register_abm({
nodenames = {"default:dirt"},
neighbors = {"air"},
@ -372,15 +408,16 @@ minetest.register_abm({
if grow_node and grow_node.name == "air"
and (minetest.get_node_light(grow_pos, nil) or 99) <= fun_caves.light_max 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
minetest.set_node(grow_pos, {name = mushrooms[math.random(#mushrooms)]})
minetest.set_node(grow_pos, mushroom_nodes[math.random(#mushroom_nodes)])
end
end
end
})
-- mushroom growth -- small into huge
local giant_mushroom_stem_node = {name = 'fun_caves:giant_mushroom_stem'}
minetest.register_abm({
nodenames = mushrooms,
interval = 5 * fun_caves.time_factor,
@ -404,12 +441,13 @@ minetest.register_abm({
return
end
minetest.set_node(pos_up, {name = "fun_caves:huge_mushroom_cap"})
minetest.set_node(pos, {name = "fun_caves:giant_mushroom_stem"})
minetest.set_node(pos_up, huge_mushroom_cap_node)
minetest.set_node(pos, giant_mushroom_stem_node)
end
})
-- mushroom growth -- huge into giant
local giant_mushroom_cap_node = {name = "fun_caves:giant_mushroom_cap"}
minetest.register_abm({
nodenames = {"fun_caves:huge_mushroom_cap"},
interval = 9 * fun_caves.time_factor,
@ -429,7 +467,7 @@ minetest.register_abm({
return
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"})
end
})
@ -494,7 +532,8 @@ minetest.register_abm({
local sky = {}
sky.bgcolor, sky.type, sky.textures = players[i]:get_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
@ -574,7 +613,7 @@ local function destroy(pos, cid)
return
end
minetest.set_node(pos, {name="air"})
minetest.remove_node(pos)
end
local function explode(pos, radius)
@ -591,22 +630,23 @@ local function explode(pos, radius)
local c_air = minetest.get_content_id("air")
local math_random = math.random
for z = -radius, radius do
for y = -radius, 4*radius do
local vi = a:index(pos.x + (-radius), pos.y + y, pos.z + z)
for x = -radius, radius do
if (x * x) + (y * y / 4) + (z * z) <=
(radius * radius) + math.random(-radius, radius) then
local cid = data[vi]
p.x = pos.x + x
p.y = pos.y + y
p.z = pos.z + z
if cid ~= c_air then
destroy(p, cid)
for y = -radius, 4*radius do
local vi = a:index(pos.x + (-radius), pos.y + y, pos.z + z)
for x = -radius, radius do
if (x * x) + (y * y / 4) + (z * z) <=
(radius * radius) + math_random(-radius, radius) then
local cid = data[vi]
p.x = pos.x + x
p.y = pos.y + y
p.z = pos.z + z
if cid ~= c_air then
destroy(p, cid)
end
end
vi = vi + 1
end
end
vi = vi + 1
end
end
end
end
@ -630,10 +670,12 @@ local function entity_physics(pos, radius)
-- Make the damage radius larger than the destruction radius
radius = radius * 2
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
local obj_pos = obj:getpos()
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
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})
local radius = 5
minetest.set_node(pos, {name="air"})
minetest.remove_node(pos)
explode(pos, radius)
entity_physics(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 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 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_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 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 x = minp.x, maxp.x do
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
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
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
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
if y <= fun_caves.underzones['Styx'].sealevel 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 <= styx_sea_level then
data[ivm] = node["default:water_source"]
else
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 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 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 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 = {}
if underzone and underzone.name == 'Dis' then
for i = 0, 10, 2 do
dis_map[i] = {}
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
dis_map[i][j] = 5 + math.random(10)
dis_map[i][j] = 5 + math_random(10)
end
end
end
@ -55,10 +55,14 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
local index = 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 x = minp.x, maxp.x do
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
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.
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
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
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]
write = true
break
@ -131,7 +135,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end
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]
write = true
break
@ -156,7 +160,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end
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]
write = true
break
@ -169,7 +173,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end
-- 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 dy = y - underzone.floor + 1
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
-- hanging down
-- 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]
write = true
break
end
-- 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]
write = true
break
-- 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
data[ivm] = node[biome.stalagmite[math.random(#biome.stalagmite)]]
data[ivm] = node[biome.stalagmite[math_random(#biome.stalagmite)]]
else
data[ivm] = node[biome.stalagmite]
end
@ -213,11 +217,11 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
-- vegetation
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"]
write = true
break
elseif math.random(50) == 1 then
elseif math_random(50) == 1 then
local air_count = 0
local j
for i = 1, 9 do
@ -227,23 +231,26 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end
end
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
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"]
write = true
break
elseif math.random(10) == 1 then
elseif math_random(10) == 1 then
data[ivm] = node["flowers:mushroom_brown"]
write = true
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"]
write = true
break
elseif math.random(30) == 1 then
elseif math_random(30) == 1 then
local air_count = 0
local j
for i = 1, 12 do
@ -253,7 +260,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end
end
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
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
break
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"]
write = true
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_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 math.random(100) == 1 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
data[ivm] = node["fun_caves:precious_coral_water_sand"]
else
data[ivm] = node["fun_caves:staghorn_coral_water_sand"]
end
write = true
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
if math.random(15) == 1 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
data[ivm] = node["fun_caves:brain_coral"]
write = true
break
elseif math.random(15) == 1 then
elseif math_random(15) == 1 then
data[ivm] = node["fun_caves:dragon_eye"]
write = true
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.
-- To speed it up, we cache the results for each plant
-- 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
node_match_cache[desc.content_id][data[ivm]] = "good"
else
@ -348,14 +358,14 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
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
write = true
break
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
-- I haven't figured out what the decoration manager is
-- 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
local ivm = area:index(pos.x + x, pos.y, pos.z + z)
local isch = z1 * schem.size.y * schem.size.x + x1 + 1
local math_random = math.random
for y = 0, schem.size.y - 1 do
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
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]
end
local param2 = schem.data[isch].param2 or 0
p2data[ivm] = param2
end
--end
ivm = ivm + area.ystride
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 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 x = minp.x, maxp.x do
local dx = (x + 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
index3d = (z - minp.z) * (csize.y + 2) * csize.x + (x - minp.x) + 1
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
local dy = y - minp.y
local r = 20
if math.abs(y - 50) > 130 then
r = math.max(0, r - math.floor((math.abs(y - 50) - 130) / 2))
if math_abs(y - 50) > 130 then
r = math_max(0, r - math_floor((math_abs(y - 50) - 130) / 2))
end
local distance3
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
if distance < r then
@ -243,7 +248,7 @@ fun_caves.treegen = function(minp, maxp, data, p2data, area, node)
data[ivm] = node['fun_caves:diamondwood']
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']
end
write = true
@ -252,15 +257,15 @@ fun_caves.treegen = function(minp, maxp, data, p2data, area, node)
write = true
-- 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
data[ivm] = node['fun_caves:bark']
write = true
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
local r = math.abs(((y + 3) % 10) - 3)
if (r < 2 or math.random(r) == 1) and data[ivm] == node['air'] then
if distance3 > r2 - 10 and math.random(10) == 1 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)
if (r < 2 or math_random(r) == 1) and data[ivm] == node['air'] then
if distance3 > r2 - 10 and math_random(10) == 1 then
data[ivm] = node['fun_caves:leaves_special']
else
data[ivm] = node['fun_caves:leaves']