Add damage-dealing to the digger heads

This commit is contained in:
FaceDeer 2017-01-06 23:48:48 -07:00
parent ee0cf5538a
commit 257863b888
5 changed files with 53 additions and 2 deletions

@ -59,6 +59,8 @@ Facing of a digger head is significant; it will excavate material from the node
Digger heads come in both regular and "intermittent" versions, each of which is craftable from the other. The intermittent version can have a period and offset defined if you want them to punch regularly-spaced holes. Note that diggers aimed forward should generally always be the regular kind (or have a period of 1), otherwise the digging machine may be unable to move. Digger heads come in both regular and "intermittent" versions, each of which is craftable from the other. The intermittent version can have a period and offset defined if you want them to punch regularly-spaced holes. Note that diggers aimed forward should generally always be the regular kind (or have a period of 1), otherwise the digging machine may be unable to move.
Be cautious around active digger heads when damage is enabled - they bite!
Soft Material Digger Head Soft Material Digger Head
---------------- ----------------

@ -11,6 +11,7 @@ dofile( minetest.get_modpath( "digtron" ) .."/recipes.lua" )
digtron.creative_mode = false -- this causes digtrons to operate without consuming fuel or building materials. digtron.creative_mode = false -- this causes digtrons to operate without consuming fuel or building materials.
digtron.particle_effects = true -- Enables the spray of particles out the back of a digger head digtron.particle_effects = true -- Enables the spray of particles out the back of a digger head
digtron.lava_impassible = true -- when true, lava counts as protected nodes. digtron.lava_impassible = true -- when true, lava counts as protected nodes.
digtron.diggers_damage_creatures = true -- when true, diggers deal damage to creatures when they trigger.
digtron.cycle_time = 1 -- How many seconds a digtron waits between cycles. Auto-controllers can make this wait longer, but cannot make it shorter. digtron.cycle_time = 1 -- How many seconds a digtron waits between cycles. Auto-controllers can make this wait longer, but cannot make it shorter.
digtron.traction_factor = 3.0 -- How many digtron nodes can be moved for each adjacent solid node that the digtron has traction against digtron.traction_factor = 3.0 -- How many digtron nodes can be moved for each adjacent solid node that the digtron has traction against

@ -208,7 +208,18 @@ local execute_cycle = function(pos, clicker)
player_pos.z >= layout.extents.min_z - 1 and player_pos.z <= layout.extents.max_z + 1 then player_pos.z >= layout.extents.min_z - 1 and player_pos.z <= layout.extents.max_z + 1 then
move_player = true move_player = true
end end
-- damage the weak flesh
if digtron.diggers_damage_creatures then
for k, location in pairs(layout.diggers) do
local target = minetest.get_node(location)
local targetdef = minetest.registered_nodes[target.name]
if targetdef.damage_creatures ~= nil then
targetdef.damage_creatures(clicker, location, digtron.find_new_pos(location, target.param2), controlling_coordinate)
end
end
end
--move the array --move the array
digtron.move_digtron(facing, layout.all, layout.extents, nodes_dug, clicker:get_player_name()) digtron.move_digtron(facing, layout.all, layout.extents, nodes_dug, clicker:get_player_name())
local oldpos = {x=pos.x, y=pos.y, z=pos.z} local oldpos = {x=pos.x, y=pos.y, z=pos.z}

@ -83,6 +83,10 @@ minetest.register_node("digtron:digger", {
return digtron.mark_diggable(digpos, nodes_dug) return digtron.mark_diggable(digpos, nodes_dug)
end, end,
damage_creatures = function(player, pos, targetpos, controlling_coordinate)
digtron.damage_creatures(player, targetpos, 8)
end,
}) })
-- Digs out nodes that are "in front" of the digger head. -- Digs out nodes that are "in front" of the digger head.
@ -138,6 +142,13 @@ minetest.register_node("digtron:intermittent_digger", {
return digtron.mark_diggable(digpos, nodes_dug) return digtron.mark_diggable(digpos, nodes_dug)
end, end,
damage_creatures = function(player, pos, targetpos, controlling_coordinate)
local meta = minetest.get_meta(pos)
if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then
digtron.damage_creatures(player, targetpos, 8)
end
end
}) })
-- A special-purpose digger to deal with stuff like sand and gravel in the ceiling. It always digs (no periodicity or offset), but it only digs falling_block nodes -- A special-purpose digger to deal with stuff like sand and gravel in the ceiling. It always digs (no periodicity or offset), but it only digs falling_block nodes
@ -192,6 +203,10 @@ minetest.register_node("digtron:soft_digger", {
return 0, nil return 0, nil
end, end,
damage_creatures = function(player, pos, targetpos, controlling_coordinate)
digtron.damage_creatures(player, targetpos, 4)
end,
}) })
minetest.register_node("digtron:intermittent_soft_digger", { minetest.register_node("digtron:intermittent_soft_digger", {
@ -254,4 +269,11 @@ minetest.register_node("digtron:intermittent_soft_digger", {
return 0, nil return 0, nil
end, end,
damage_creatures = function(player, pos, targetpos, controlling_coordinate)
local meta = minetest.get_meta(pos)
if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then
digtron.damage_creatures(player, targetpos, 4)
end
end,
}) })

@ -429,4 +429,19 @@ digtron.update_builder_item = function(pos)
digtron.create_builder_item = item_stack:get_name() digtron.create_builder_item = item_stack:get_name()
minetest.add_entity(pos,"digtron:builder_item") minetest.add_entity(pos,"digtron:builder_item")
end end
end end
digtron.damage_creatures = function(player, pos, amount)
local objects = minetest.env:get_objects_inside_radius(pos, 1.0)
if objects ~= nil then
for _, obj in ipairs(objects) do
if obj then
obj:punch(player, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = amount},
}, nil )
end
end
end
end