Clean up several functions.
This commit is contained in:
parent
e6f482c9d5
commit
42916c4666
5 changed files with 159 additions and 103 deletions
150
abms.lua
150
abms.lua
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue