Streamline abms.

This commit is contained in:
Duane 2016-08-04 21:40:50 -05:00
parent 2f9d41c11e
commit fb45d350b3
4 changed files with 97 additions and 115 deletions

190
abms.lua
View file

@ -10,6 +10,7 @@ local cold_delay = 5
local monster_delay = 3 local monster_delay = 3
local hunger_delay = 60 local hunger_delay = 60
local dps_count = hunger_delay local dps_count = hunger_delay
local dungeon_monster_density = 5
local players_in_orbit = {} local players_in_orbit = {}
local mushrooms = {"flowers:mushroom_brown", "flowers:mushroom_red"} local mushrooms = {"flowers:mushroom_brown", "flowers:mushroom_red"}
@ -284,8 +285,8 @@ minetest.register_abm({
minetest.register_abm({ minetest.register_abm({
nodenames = {"fun_caves:hot_cobble",}, nodenames = {"fun_caves:hot_cobble",},
neighbors = {"group:water"}, neighbors = {"group:water"},
interval = 10, interval = 5,
chance = 10, chance = 60,
catch_up = false, catch_up = false,
action = function(pos, node) action = function(pos, node)
if not (pos and node) then if not (pos and node) then
@ -313,48 +314,11 @@ minetest.register_abm({
end end
}) })
-- Exploding fungal fruit -- in a fire
minetest.register_abm({
nodenames = {"fun_caves:fungal_tree_fruit"},
neighbors = {"fire:basic_flame"},
interval = time_factor,
chance = 50,
catch_up = false,
action = function(pos, node)
if not (pos and node) then
return
end
fun_caves.soft_boom(pos)
end
})
-- giant/huge mushroom "leaf decay"
-- This should be more efficient than the normal leaf decay,
-- since it only checks below the node.
minetest.register_abm({
nodenames = {"fun_caves:giant_mushroom_cap", "fun_caves:huge_mushroom_cap"},
interval = time_factor,
chance = 25,
action = function(pos, node)
if not (pos and node) then
return
end
-- 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.remove_node(pos)
return
end
end
})
-- Destroy mushroom caps in the light. -- Destroy mushroom caps in the light.
minetest.register_abm({ minetest.register_abm({
nodenames = {"fun_caves:giant_mushroom_cap", "fun_caves:huge_mushroom_cap"}, nodenames = {"fun_caves:giant_mushroom_cap", "fun_caves:huge_mushroom_cap"},
interval = 2 * time_factor, interval = 3 * time_factor,
chance = 110, chance = 200,
action = function(pos, node) action = function(pos, node)
if not (pos and node) then if not (pos and node) then
return return
@ -378,8 +342,8 @@ minetest.register_abm({
minetest.register_abm({ minetest.register_abm({
nodenames = {"fun_caves:coffer"}, nodenames = {"fun_caves:coffer"},
interval = time_factor, interval = 2,
chance = 10, chance = 50,
action = function(p0, node, _, _) action = function(p0, node, _, _)
minetest.remove_node(p0) minetest.remove_node(p0)
end, end,
@ -391,11 +355,12 @@ minetest.register_abm({
minetest.register_abm({ minetest.register_abm({
nodenames = {"fun_caves:dungeon_floor_1"}, nodenames = {"fun_caves:dungeon_floor_1"},
interval = 10 * time_factor, neighbors = {'air'},
chance = 250, interval = 5 * time_factor,
chance = 500,
catch_up = false, catch_up = false,
action = function(pos, node, aoc, active_object_count_wider) action = function(pos, node, aoc, active_object_count_wider)
if not (pos and node) or active_object_count_wider > 5 then if not (pos and node) or active_object_count_wider > dungeon_monster_density then
return return
end end
@ -423,9 +388,7 @@ minetest.register_abm({
return return
end end
local name = desc.name local obj = minetest.add_entity(pos, desc.name)
local level = desc.level
local obj = minetest.add_entity(pos, name)
if not obj then if not obj then
return return
end end
@ -445,15 +408,16 @@ minetest.register_abm({
mob.initial_promotion = true mob.initial_promotion = true
check_for_death(mob) check_for_death(mob)
--print('Dungeon quality '..name..': '..mob.health..' health, '..mob.damage..' damage') --print('Dungeon quality '..desc.name..': '..mob.health..' health, '..mob.damage..' damage')
end end
end end
}) })
minetest.register_abm({ minetest.register_abm({
nodenames = {"fun_caves:dungeon_floor_1"}, nodenames = {"fun_caves:dungeon_floor_1"},
interval = 20 * time_factor, neighbors = {'air'},
chance = 500, interval = 10 * time_factor,
chance = 1000,
catch_up = false, catch_up = false,
action = function(pos, node) action = function(pos, node)
if not (pos and node) then if not (pos and node) then
@ -472,6 +436,7 @@ minetest.register_abm({
minetest.register_abm({ minetest.register_abm({
nodenames = {"fun_caves:dungeon_wall_1"}, nodenames = {"fun_caves:dungeon_wall_1"},
neighbors = {'air'},
interval = time_factor, interval = time_factor,
chance = 100, chance = 100,
catch_up = false, catch_up = false,
@ -510,11 +475,12 @@ minetest.register_abm({
end end
}) })
-- This puts the burdon on fires, which shouldn't be happening much.
minetest.register_abm({ minetest.register_abm({
nodenames = {"fun_caves:tree"}, nodenames = {'fire:basic_flame'},
neighbors = {'fire:basic_flame'}, neighbors = {"fun_caves:tree"},
interval = time_factor, interval = time_factor,
chance = 20, chance = 50,
action = function(pos, node) action = function(pos, node)
if not (pos and node) then if not (pos and node) then
return return
@ -526,8 +492,9 @@ minetest.register_abm({
minetest.register_abm({ minetest.register_abm({
nodenames = {"default:leaves"}, nodenames = {"default:leaves"},
interval = 20 * time_factor, neighbors = {'air'},
chance = 200, interval = 5 * time_factor,
chance = 1000,
catch_up = false, catch_up = false,
action = function(pos, node) action = function(pos, node)
if not (pos and node) then if not (pos and node) then
@ -545,7 +512,7 @@ minetest.register_abm({
minetest.register_abm({ minetest.register_abm({
nodenames = {"default:apple"}, nodenames = {"default:apple"},
interval = time_factor, interval = time_factor,
chance = 80, chance = 100,
catch_up = false, catch_up = false,
action = function(pos, node) action = function(pos, node)
if not (pos and node) then if not (pos and node) then
@ -644,8 +611,8 @@ minetest.register_abm({
minetest.register_abm({ minetest.register_abm({
nodenames = fungal_tree_leaves, nodenames = fungal_tree_leaves,
neighbors = {"air", "group:liquid"}, neighbors = {"air", "group:liquid"},
interval = time_factor, interval = math.ceil(time_factor / 2),
chance = 50, chance = 100,
catch_up = false, catch_up = false,
action = function(pos, node) action = function(pos, node)
if not (pos and node) then if not (pos and node) then
@ -657,23 +624,6 @@ minetest.register_abm({
return return
end end
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, 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) <= light_max then
minetest.set_node(grow_pos, node)
return
elseif grow_node and is_fungal_leaf[grow_node.name] and grow_node.name ~= node.name then
minetest.remove_node(grow_pos)
return
end
if math.random(40) == 1 then if math.random(40) == 1 then
minetest.set_node(pos, fungal_nodes[#fungal_nodes]) minetest.set_node(pos, fungal_nodes[#fungal_nodes])
return return
@ -683,6 +633,25 @@ minetest.register_abm({
minetest.set_node(pos, fungal_nodes[math.random(#fungal_nodes - 1)]) minetest.set_node(pos, fungal_nodes[math.random(#fungal_nodes - 1)])
return return
end end
pos.y = pos.y - 1
local grow_node = minetest.get_node_or_nil(pos)
if grow_node and grow_node.name == "air" then
minetest.set_node(pos, node)
return
end
pos.x = pos.x + math.random(-1, 1)
pos.y = pos.y + math.random(-1, 1) + 1
pos.z = pos.z + math.random(-1, 1)
grow_node = minetest.get_node_or_nil(pos)
if grow_node and grow_node.name == "air" and (minetest.get_node_light(pos, nil) or 99) <= light_max then
minetest.set_node(pos, node)
return
elseif grow_node and is_fungal_leaf[grow_node.name] and grow_node.name ~= node.name then
minetest.remove_node(pos)
return
end
end end
}) })
@ -690,26 +659,28 @@ minetest.register_abm({
local huge_mushroom_cap_node = {name = 'fun_caves:huge_mushroom_cap'} 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 * time_factor, neighbors = {'air'},
chance = 150, interval = time_factor,
chance = 300,
action = function(pos, node) action = function(pos, node)
if not (pos and node) then if not (pos and node) then
return return
end end
local pos_up = {x=pos.x,y=pos.y+1,z=pos.z} pos.y = pos.y + 1
local node_up = minetest.get_node_or_nil(pos_up) local node_up = minetest.get_node_or_nil(pos)
if not node_up or node_up.name ~= "air" then if not node_up or node_up.name ~= "air" then
return return
end end
if (minetest.get_node_light(pos_up, nil) or 99) <= light_max then if (minetest.get_node_light(pos, nil) or 99) <= light_max then
minetest.set_node(pos_up, huge_mushroom_cap_node) minetest.set_node(pos, huge_mushroom_cap_node)
end end
end end
}) })
-- new fungi -- ***********************************************
-- new fungi -- This may be too cpu-intensive.
local mushroom_nodes = {} local mushroom_nodes = {}
for _, mushroom in pairs(mushrooms) do for _, mushroom in pairs(mushrooms) do
mushroom_nodes[#mushroom_nodes+1] = {name = mushroom} mushroom_nodes[#mushroom_nodes+1] = {name = mushroom}
@ -717,29 +688,27 @@ end
minetest.register_abm({ minetest.register_abm({
nodenames = {"default:dirt"}, nodenames = {"default:dirt"},
neighbors = {"air"}, neighbors = {"air"},
interval = 2 * time_factor, interval = time_factor,
chance = 75, chance = 300,
catch_up = false,
action = function(pos, node) action = function(pos, node)
if not (pos and node) then if not (pos and node and pos.y < 0) then
return return
end end
if pos.y > 0 then pos.y = pos.y + 1
return local grow_node = minetest.get_node_or_nil(pos)
end
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" if grow_node and grow_node.name == "air"
and (minetest.get_node_light(grow_pos, nil) or 99) <= light_max then and (minetest.get_node_light(pos, nil) or 99) <= light_max then
if math.random(4) == 1 then if math.random(4) == 1 then
minetest.set_node(grow_pos, fungal_nodes[math.random(#fungal_nodes - 1)]) minetest.set_node(pos, fungal_nodes[math.random(#fungal_nodes - 1)])
else else
minetest.set_node(grow_pos, mushroom_nodes[math.random(#mushroom_nodes)]) minetest.set_node(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'} local giant_mushroom_stem_node = {name = 'fun_caves:giant_mushroom_stem'}
@ -747,13 +716,9 @@ minetest.register_abm({
nodenames = mushrooms, nodenames = mushrooms,
interval = 5 * time_factor, interval = 5 * time_factor,
chance = 750, chance = 750,
catch_up = false,
action = function(pos, node) action = function(pos, node)
if not (pos and node) then if not (pos and node and pos.y < 0) then
return
end
-- Clumsy, but it's the best way to limit them to caves.
if pos.y > 0 then
return return
end end
@ -781,6 +746,7 @@ minetest.register_abm({
nodenames = {"fun_caves:huge_mushroom_cap"}, nodenames = {"fun_caves:huge_mushroom_cap"},
interval = 9 * time_factor, interval = 9 * time_factor,
chance = 2000, chance = 2000,
catch_up = false,
action = function(pos, node) action = function(pos, node)
if not (pos and node) then if not (pos and node) then
return return
@ -808,10 +774,10 @@ minetest.register_abm({
-- Spike spread and death -- Spike spread and death
minetest.register_abm({ minetest.register_abm({
nodenames = fun_caves.hot_spikes, nodenames = fun_caves.hot_spikes,
interval = 3 * time_factor, interval = time_factor,
chance = 300, chance = 900,
action = function(pos, node) action = function(pos, node)
if not (pos and node) then if not (pos and node and pos.y < 0) then
return return
end end
@ -829,22 +795,20 @@ minetest.register_abm({
return return
end end
local new_pos = { pos.x = pos.x + math.random(-2, 2)
x = pos.x + math.random(-2, 2), pos.y = pos.y + math.random(-1, 1)
y = pos.y + math.random(-1, 1), pos.z = pos.z + math.random(-2, 2)
z = pos.z + math.random(-2, 2) local new_node = minetest.get_node_or_nil(pos)
}
local new_node = minetest.get_node_or_nil(new_pos)
if not (new_node and spike_air[new_node.name]) then if not (new_node and spike_air[new_node.name]) then
return return
end end
local node_under = minetest.get_node_or_nil({x = new_pos.x, y = new_pos.y - 1, z = new_pos.z}) local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
if not (node_under and spike_soil[node_under.name]) then if not (node_under and spike_soil[node_under.name]) then
return return
end end
minetest.set_node(new_pos, {name = hot_spikes[1]}) minetest.set_node(pos, {name = hot_spikes[1]})
end end
}) })

View file

@ -152,7 +152,7 @@ local cap = {
{-0.4, -0.5, 0.4, 0.4, -0.25, 0.5}, {-0.4, -0.5, 0.4, 0.4, -0.25, 0.5},
} }, } },
light_source = light_max, light_source = light_max,
groups = {fleshy=1, dig_immediate=3, flammable=2, plant=1}, groups = {fleshy=1, falling_node = 1, dig_immediate=3, flammable=2, plant=1},
} }
minetest.register_node("fun_caves:giant_mushroom_cap", cap) minetest.register_node("fun_caves:giant_mushroom_cap", cap)
@ -171,7 +171,7 @@ minetest.register_node("fun_caves:huge_mushroom_cap", {
{-0.33, -0.33, -0.33, 0.33, -0.17, 0.33}, {-0.33, -0.33, -0.33, 0.33, -0.17, 0.33},
} }, } },
light_source = light_max, light_source = light_max,
groups = {fleshy=1, dig_immediate=3, flammable=2, plant=1}, groups = {fleshy=1, falling_node = 1, dig_immediate=3, flammable=2, plant=1},
}) })
-- mushroom stem, giant or huge -- mushroom stem, giant or huge

View file

@ -42,6 +42,11 @@ if fun_caves.pyramids_everywhere == nil then
fun_caves.pyramids_everywhere = false fun_caves.pyramids_everywhere = false
end end
fun_caves.quick_leaf_decay = minetest.setting_getbool('fun_caves_quick_leaf_decay')
if fun_caves.quick_leaf_decay == nil then
fun_caves.quick_leaf_decay = false
end
fun_caves.DEBUG = false -- for maintenance only fun_caves.DEBUG = false -- for maintenance only
@ -454,3 +459,13 @@ if fun_caves.db.status then
end end
end end
---------------------------------------------------------------------- ----------------------------------------------------------------------
if fun_caves.quick_leaf_decay then
for name, node in pairs(minetest.registered_nodes) do
if node.groups.leafdecay then
node.groups.leafdecay = 0
node.groups.qfc_leafdecay = 0
end
end
end

View file

@ -18,3 +18,6 @@ fun_caves_starting_equipment (Starting Equipment) bool false
# Set to create pyramids in any biome. # Set to create pyramids in any biome.
fun_caves_pyramids_everywhere (Pyramids Everywhere) bool false fun_caves_pyramids_everywhere (Pyramids Everywhere) bool false
# Set to use experimental leaf decay.
fun_caves_quick_leaf_decay (Quick Experimental Decay) bool false