Streamline abms. Fix manticore poison.

This commit is contained in:
Duane 2016-08-06 23:12:26 -05:00
parent 678b025cb0
commit 5ae6e9f89c
5 changed files with 294 additions and 392 deletions

443
abms.lua
View file

@ -58,6 +58,7 @@ spike_soil['fun_caves:black_sand'] = true
-- all the fun_caves globalstep functions
------------------------------------------------------------
local hot_stuff = {"group:surface_hot"}
local traps = {"group:trap"}
local cold_stuff = {"group:surface_cold"}
local poison_stuff = {"group:poison"}
local gravity_off = {gravity = 0.1}
@ -99,6 +100,8 @@ local function firework()
end
end
local sparking = {}
minetest.register_globalstep(function(dtime)
if not (dtime and type(dtime) == 'number') then
return
@ -113,6 +116,162 @@ minetest.register_globalstep(function(dtime)
return
end
-- Trap check
if last_dps_check and time - last_dps_check < 1 then
return
end
local minetest_find_nodes_in_area = minetest.find_nodes_in_area
local players = minetest.get_connected_players()
if not (players and type(players) == 'table') then
return
end
for i = 1, #players do
local player = players[i]
local pos = player:getpos()
pos = vector.round(pos)
local player_name = player:get_player_name()
local minp = vector.subtract(pos, 2)
local maxp = vector.add(pos, 2)
local counts = minetest_find_nodes_in_area(minp, maxp, traps)
if counts and type(counts) == 'table' and #counts > 0 then
for _, tpos in ipairs(counts) do
local node = minetest.get_node_or_nil(tpos)
if not node then
return
end
if node.name == 'fun_caves:stone_with_coal_trap' then
minetest.set_node(tpos, {name="fire:basic_flame"})
local hp = player:get_hp()
if hp > 0 then
player:set_hp(hp - 1)
end
elseif node.name == 'fun_caves:stone_with_diamond_trap' then
fun_caves.diamond_trap(tpos, player)
elseif node.name == 'fun_caves:stone_with_gold_trap' then
fun_caves.gold_trap(tpos, player)
elseif node.name == 'fun_caves:mossycobble_trap' then
player:set_physics_override({speed = 0.1})
minetest.after(1, function() -- this effect is temporary
object:set_physics_override({speed = 1}) -- we'll just set it to 1 and be done.
end)
elseif node.name == 'fun_caves:ice_trap' then
fun_caves.ice_trap(tpos, player)
elseif node.name == 'fun_caves:stone_with_copper_trap' or node.name == 'fun_caves:stone_with_iron_trap' then
if not sparking[player_name] then
sparking[player_name] = true
fun_caves.copper_trap(tpos, player)
minetest.after(1, function()
sparking[player_name] = nil
end)
end
else
minetest.remove_node(tpos)
end
end
end
-- Execute only after an interval.
if last_dps_check and time - last_dps_check > dps_delay then
if pos.y >= 11168 and pos.y <= 15168 then
if not players_in_orbit[player_name] then
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")
minetest.after(20, function()
player:set_physics_override(gravity_on)
end)
players_in_orbit[player_name] = false
end
-- environmental damage
if fun_caves.DEBUG and player:get_hp() < 20 then
-- Regenerate the player while testing.
print("HP: "..player:get_hp())
player:set_hp(20)
return
else
local minp = vector.subtract(pos, 0.5)
local maxp = vector.add(pos, 0.5)
-- Remove status effects.
local status = fun_caves.db.status[player_name]
for status_name, status_param in pairs(status) do
local def = fun_caves.registered_status[status_name]
if not def then
print('Fun Caves: Error - unregistered status ' .. status_name)
break
end
local remove
if type(status_param.remove) == 'number' then
if status_param.remove < time then
remove = true
end
elseif def.remove then
remove = def.remove(player)
else
print('Fun Caves: Error in status remove for ' .. status_name)
end
if remove then
fun_caves.remove_status(player_name, status_name)
elseif def.during then
def.during(player)
end
end
if fun_caves.db.status[player_name]['breathe'] then
player:set_breath(11)
end
-- ... from standing on or near hot objects.
local counts = minetest_find_nodes_in_area(minp, maxp, hot_stuff)
if not (counts and type(counts) == 'table') then
return
end
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, poison_stuff)
if not (counts and type(counts) == 'table') then
return
end
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, cold_stuff)
if not (counts and type(counts) == 'table') then
return
end
if #counts > 1 then
player:set_hp(player:get_hp() - 1)
end
end
-- ... from hunger (even less often).
if dps_count % hunger_delay == 0 and fun_caves.hunger_change then
fun_caves.hunger_change(player, -1)
end
end
end
end
-- Execute only after an interval.
if last_dps_check and time - last_dps_check < dps_delay then
return
@ -147,111 +306,6 @@ minetest.register_globalstep(function(dtime)
end
end
local minetest_find_nodes_in_area = minetest.find_nodes_in_area
local players = minetest.get_connected_players()
if not (players and type(players) == 'table') then
return
end
for i = 1, #players do
local player = players[i]
local pos = player:getpos()
local player_name = player:get_player_name()
if pos.y >= 11168 and pos.y <= 15168 then
if not players_in_orbit[player_name] then
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")
minetest.after(20, function()
player:set_physics_override(gravity_on)
end)
players_in_orbit[player_name] = false
end
-- environmental damage
if fun_caves.DEBUG and player:get_hp() < 20 then
-- Regenerate the player while testing.
print("HP: "..player:get_hp())
player:set_hp(20)
return
else
local minp = vector.subtract(pos, 0.5)
local maxp = vector.add(pos, 0.5)
-- Remove status effects.
local status = fun_caves.db.status[player_name]
for status_name, status_param in pairs(status) do
local def = fun_caves.registered_status[status_name]
if not def then
print('Fun Caves: Error - unregistered status ' .. status_name)
break
end
local remove
if type(status_param.remove) == 'number' then
if status_param.remove < time then
remove = true
end
elseif def.remove then
remove = def.remove(player)
else
print('Fun Caves: Error in status remove for ' .. status_name)
end
if remove then
fun_caves.remove_status(player_name, status_name)
elseif def.during then
def.during(player)
end
end
if fun_caves.db.status[player_name]['breathe'] then
player:set_breath(11)
end
-- ... from standing on or near hot objects.
local counts = minetest_find_nodes_in_area(minp, maxp, hot_stuff)
if not (counts and type(counts) == 'table') then
return
end
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, poison_stuff)
if not (counts and type(counts) == 'table') then
return
end
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, cold_stuff)
if not (counts and type(counts) == 'table') then
return
end
if #counts > 1 then
player:set_hp(player:get_hp() - 1)
end
end
-- ... from hunger (even less often).
if dps_count % hunger_delay == 0 and fun_caves.hunger_change then
fun_caves.hunger_change(player, -1)
end
end
end
-- Set this outside of the player loop, to affect everyone.
if dps_count % hunger_delay == 0 then
dps_count = hunger_delay
@ -285,8 +339,8 @@ minetest.register_abm({
minetest.register_abm({
nodenames = {"fun_caves:hot_cobble",},
neighbors = {"group:water"},
interval = 5,
chance = 60,
interval = time_factor,
chance = 30,
catch_up = false,
action = function(pos, node)
if not (pos and node) then
@ -302,8 +356,8 @@ minetest.register_abm({
-- Exploding fungal fruit
minetest.register_abm({
nodenames = {"fun_caves:fungal_tree_fruit"},
interval = 2 * time_factor,
chance = 150,
interval = 12 * time_factor,
chance = 400,
catch_up = false,
action = function(pos, node)
if not (pos and node) then
@ -333,8 +387,8 @@ minetest.register_abm({
minetest.register_abm({
nodenames = {"fire:basic_flame"},
interval = time_factor,
chance = 100,
interval = 2 * time_factor,
chance = 50,
action = function(p0, node, _, _)
minetest.remove_node(p0)
end,
@ -342,8 +396,8 @@ minetest.register_abm({
minetest.register_abm({
nodenames = {"fun_caves:coffer"},
interval = 2,
chance = 50,
interval = 5,
chance = 20,
catch_up = false,
action = function(p0, node, _, _)
minetest.remove_node(p0)
@ -354,71 +408,75 @@ minetest.register_abm({
-- creation
------------------------------------------------------------
minetest.register_abm({
nodenames = {"fun_caves:dungeon_floor_1"},
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 > dungeon_monster_density then
return
end
for i = 1, 2 do
pos.y = pos.y + 1
local node = minetest.get_node_or_nil(pos)
if not node or node.name ~= "air" then
if fun_caves.dungeon_spawns and #fun_caves.dungeon_spawns > 0 then
print('go monster')
minetest.register_abm({
nodenames = {"fun_caves:dungeon_floor_1"},
neighbors = {'air'},
interval = 7 * time_factor,
chance = 350,
catch_up = false,
action = function(pos, node, aoc, active_object_count_wider)
if not (pos and node) or active_object_count_wider > dungeon_monster_density then
return
end
end
local target_level = math.max(2, math.ceil((pos.y - 3 ^ math.random(9)) / -200))
for i = 1, 2 do
pos.y = pos.y + 1
local node = minetest.get_node_or_nil(pos)
if not node or node.name ~= "air" then
return
end
end
local desc
for i = 1, 100 do
desc = fun_caves.dungeon_spawns[math.random(#fun_caves.dungeon_spawns)]
if desc.level <= target_level then
break
else
desc = nil
local target_level = math.max(2, math.ceil((pos.y - 3 ^ math.random(9)) / -200))
local desc
for i = 1, 100 do
desc = fun_caves.dungeon_spawns[math.random(#fun_caves.dungeon_spawns)]
if desc.level <= target_level then
break
else
desc = nil
end
end
if not desc then
return
end
local obj = minetest.add_entity(pos, desc.name)
if not obj then
return
end
local mob = obj:get_luaentity()
if not mob then
return
end
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)
mob.started_in_dungeon = true
factor = factor * 1.5
mob.hp_max = math.floor(mob.hp_max * factor)
mob.damage = math.floor(mob.damage * factor)
mob.health = math.floor(mob.health * factor)
mob.object:set_hp(mob.health)
mob.initial_promotion = true
check_for_death(mob)
--print('Dungeon quality '..desc.name..': '..mob.health..' health, '..mob.damage..' damage')
end
end
})
end
if not desc then
return
end
local obj = minetest.add_entity(pos, desc.name)
if not obj then
return
end
local mob = obj:get_luaentity()
if not mob then
return
end
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)
mob.started_in_dungeon = true
factor = factor * 1.5
mob.hp_max = math.floor(mob.hp_max * factor)
mob.damage = math.floor(mob.damage * factor)
mob.health = math.floor(mob.health * factor)
mob.object:set_hp(mob.health)
mob.initial_promotion = true
check_for_death(mob)
--print('Dungeon quality '..desc.name..': '..mob.health..' health, '..mob.damage..' damage')
end
end
})
if false then
minetest.register_abm({
nodenames = {"fun_caves:dungeon_floor_1"},
neighbors = {'air'},
interval = 10 * time_factor,
chance = 2000,
interval = 20 * time_factor,
chance = 1000,
catch_up = false,
action = function(pos, node)
if not (pos and node) then
@ -438,8 +496,8 @@ minetest.register_abm({
minetest.register_abm({
nodenames = {"fun_caves:dungeon_wall_1"},
neighbors = {'air'},
interval = 1 * time_factor,
chance = 1000,
interval = 4 * time_factor,
chance = 250,
catch_up = false,
action = function(pos, node)
if not (pos and node) then
@ -475,6 +533,7 @@ minetest.register_abm({
minetest.set_node(pos, {name = 'default:torch', param2 = p2})
end
})
end
-- This puts the burdon on fires, which shouldn't be happening much.
minetest.register_abm({
@ -494,8 +553,8 @@ minetest.register_abm({
minetest.register_abm({
nodenames = {"default:leaves"},
neighbors = {'air'},
interval = 5 * time_factor,
chance = 1000,
interval = 10 * time_factor,
chance = 500,
catch_up = false,
action = function(pos, node)
if not (pos and node) then
@ -512,8 +571,8 @@ minetest.register_abm({
minetest.register_abm({
nodenames = {"default:apple"},
interval = time_factor,
chance = 100,
interval = 2 * time_factor,
chance = 50,
catch_up = false,
action = function(pos, node)
if not (pos and node) then
@ -543,8 +602,8 @@ local no_tree_grow = {'fun_caves:bark', 'fun_caves:leaves'}
local wood_nodes = {{name = 'fun_caves:diamondwood'}, {name = 'fun_caves:ironwood'}, {name = 'fun_caves:sap'}, {name = 'fun_caves:tree'}}
minetest.register_abm({
neighbors = {'air'},
interval = 5 * time_factor,
chance = 900,
interval = 10 * time_factor,
chance = 450,
catch_up = false,
action = function(pos, node)
if not (pos and node) then
@ -612,8 +671,8 @@ minetest.register_abm({
minetest.register_abm({
nodenames = fungal_tree_leaves,
neighbors = {"air", "group:liquid"},
interval = math.ceil(time_factor / 2),
chance = 100,
interval = 4 * time_factor,
chance = 200,
catch_up = false,
action = function(pos, node)
if not (pos and node) then
@ -661,8 +720,8 @@ local huge_mushroom_cap_node = {name = 'fun_caves:huge_mushroom_cap'}
minetest.register_abm({
nodenames = {"fun_caves:giant_mushroom_stem"},
neighbors = {'air'},
interval = time_factor,
chance = 300,
interval = 4 * time_factor,
chance = 200,
action = function(pos, node)
if not (pos and node) then
return
@ -688,8 +747,8 @@ end
minetest.register_abm({
nodenames = {"default:dirt"},
neighbors = {'fun_caves:stone_with_lichen', 'fun_caves:stone_with_algae', 'fun_caves:giant_mushroom_stem'},
interval = time_factor,
chance = 300,
interval = 10 * time_factor,
chance = 500,
catch_up = false,
action = function(pos, node)
if not (pos and node and pos.y < 0) then
@ -713,8 +772,8 @@ minetest.register_abm({
local giant_mushroom_stem_node = {name = 'fun_caves:giant_mushroom_stem'}
minetest.register_abm({
nodenames = mushrooms,
interval = 5 * time_factor,
chance = 750,
interval = 20 * time_factor,
chance = 700,
catch_up = false,
action = function(pos, node)
if not (pos and node and pos.y < 0) then
@ -743,7 +802,7 @@ minetest.register_abm({
local giant_mushroom_cap_node = {name = "fun_caves:giant_mushroom_cap"}
minetest.register_abm({
nodenames = {"fun_caves:huge_mushroom_cap"},
interval = 9 * time_factor,
interval = 40 * time_factor,
chance = 2000,
catch_up = false,
action = function(pos, node)
@ -773,8 +832,8 @@ minetest.register_abm({
-- Spike spread and death
minetest.register_abm({
nodenames = fun_caves.hot_spikes,
interval = time_factor,
chance = 900,
interval = 40 * time_factor,
chance = 2000,
action = function(pos, node)
if not (pos and node and pos.y < 0) then
return
@ -821,11 +880,11 @@ local last_meteor_strike = 0
minetest.register_abm({
nodenames = {"default:dirt_with_grass", "default:dirt_with_dry_grass", 'default:dirt_with_snow'},
neighbors = {"air", 'default:snow'},
interval = 25 * time_factor,
interval = 150 * time_factor,
catch_up = false,
chance = 32767,
chance = 5500,
action = function(pos, node)
if not (pos and node) then
if not (pos and node and pos.y > 0) then
return
end
@ -865,8 +924,8 @@ minetest.register_abm({
-- Remove old craters.
minetest.register_abm({
nodenames = {"fun_caves:meteorite_crater"},
interval = 3 * time_factor,
chance = 330,
interval = 5 * time_factor,
chance = 200,
action = function(pos, node)
if not (pos and node) then
return