diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..2467b80 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,22 @@ +unused_args = false +allow_defined_top = true + +globals = { + "minetest", + "spacecannon" +} + +read_globals = { + -- Stdlib + string = {fields = {"split"}}, + table = {fields = {"copy", "getn"}}, + + -- mod deps + "technic", "default", + + -- Minetest + "minetest", + "vector", "ItemStack", + "dump" + +} diff --git a/cannon.lua b/cannon.lua index 640228a..a9bec82 100644 --- a/cannon.lua +++ b/cannon.lua @@ -57,22 +57,22 @@ local register_spacecannon = function(def) end if collided then - spacecannon.destroy(pos, def.range) + spacecannon.destroy(pos, def.range, def.intensity) self.object:remove() end elseif node.name ~= "air" and node.name ~= "vacuum:vacuum" then -- collision - spacecannon.destroy(pos, def.range) + spacecannon.destroy(pos, def.range, def.intensity) self.object:remove() end end, on_activate = function(self, staticdata) - minetest.after(def.timeout, - function(self) - self.object:remove() + minetest.after(def.timeout, + function(me) + me.object:remove() end, self) end @@ -143,8 +143,6 @@ local register_spacecannon = function(def) end, on_receive_fields = function(pos, formname, fields, sender) - local meta = minetest.get_meta(pos); - if fields.fire then spacecannon.fire(pos, def.color, def.speed, def.range) end @@ -170,6 +168,7 @@ end register_spacecannon({ color = "green", range = 1, + intensity = 1, timeout = 8, speed = 10, desc = "fast,low damage", @@ -179,6 +178,7 @@ register_spacecannon({ register_spacecannon({ color = "yellow", range = 3, + intensity = 2, timeout = 8, speed = 5, desc = "medium speed, medium damage", @@ -188,6 +188,7 @@ register_spacecannon({ register_spacecannon({ color = "red", range = 5, + intensity = 4, timeout = 15, speed = 3, desc = "slow, heavy damage", diff --git a/util.lua b/util.lua index b8cff5e..7d5ecf2 100644 --- a/util.lua +++ b/util.lua @@ -20,7 +20,6 @@ spacecannon.fire = function(pos, color, speed, range) -- check fuel/power local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") if meta:get_int("powerstorage") < spacecannon.config.powerstorage * range then -- not enough power @@ -45,12 +44,14 @@ end -- destroy stuff in range -- TODO: resilient material list -spacecannon.destroy = function(pos,range) +spacecannon.destroy = function(pos, range, intensity) if not spacecannon.can_destroy(pos) then return end + local particle_texture = nil + for x=-range,range do for y=-range,range do for z=-range,range do @@ -64,14 +65,28 @@ spacecannon.destroy = function(pos,range) local n = minetest.get_node_or_nil(np) if n and n.name ~= "air" then - minetest.set_node(np, {name="air"}) - local itemstacks = minetest.get_node_drops(n.name) - for _, itemname in ipairs(itemstacks) do - if math.random(5) == 5 then - -- chance drop - minetest.add_item(np, itemname) + local node_def = minetest.registered_nodes[n.name] + + if node_def and node_def.tiles and node_def.tiles[1] then + particle_texture = node_def.tiles[1] + end + + if node_def.on_blast then + -- custom on_blast + node_def.on_blast(np, intensity) + + else + -- default behavior + minetest.set_node(np, {name="air"}) + local itemstacks = minetest.get_node_drops(n.name) + for _, itemname in ipairs(itemstacks) do + if math.random(5) == 5 then + -- chance drop + minetest.add_item(np, itemname) + end end end + end end end @@ -98,6 +113,25 @@ spacecannon.destroy = function(pos,range) glow = 5 }) + if particle_texture then + minetest.add_particlespawner({ + amount = 64, + time = 0.5, + minpos = vector.subtract(pos, radius / 2), + maxpos = vector.add(pos, radius / 2), + minvel = {x = -10, y = -10, z = -10}, + maxvel = {x = 10, y = 10, z = 10}, + minacc = vector.new(), + maxacc = vector.new(), + minexptime = 1, + maxexptime = 2.5, + minsize = radius * 3, + maxsize = radius * 5, + texture = particle_texture, + glow = 5 + }) + end + minetest.sound_play("tnt_explode", {pos = pos, gain = 1.5, max_hear_distance = math.min(radius * 20, 128)}) end