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

View file

@ -152,7 +152,7 @@ local cap = {
{-0.4, -0.5, 0.4, 0.4, -0.25, 0.5},
} },
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)
@ -171,7 +171,7 @@ minetest.register_node("fun_caves:huge_mushroom_cap", {
{-0.33, -0.33, -0.33, 0.33, -0.17, 0.33},
} },
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

View file

@ -42,6 +42,11 @@ if fun_caves.pyramids_everywhere == nil then
fun_caves.pyramids_everywhere = false
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
@ -454,3 +459,13 @@ if fun_caves.db.status then
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.
fun_caves_pyramids_everywhere (Pyramids Everywhere) bool false
# Set to use experimental leaf decay.
fun_caves_quick_leaf_decay (Quick Experimental Decay) bool false