mirror of
https://github.com/pandorabox-io/spacecannon.git
synced 2025-01-02 02:57:29 +01:00
Add railgun cannons (#16)
* feat: add purple and blue cannons (railguns) * fix: linter warnings * fix: last commit Seems I forgot to save some changes that were supposed to be part of the last commit. * feat: don't change cannon projectile range Avoid breaking builds on other servers
This commit is contained in:
parent
e7f3f1eac6
commit
29c0daca0b
13
ammo.lua
Normal file
13
ammo.lua
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
minetest.register_craftitem("spacecannon:railgun_slug", {
|
||||||
|
description = "Railgun slug",
|
||||||
|
inventory_image = "spacecannon_railgun_slug.png",
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "spacecannon:railgun_slug 2",
|
||||||
|
recipe = {
|
||||||
|
{ "", "technic:uranium0_ingot", ""},
|
||||||
|
{"basic_materials:carbon_steel_bar", "technic:stainless_steel_ingot", "basic_materials:carbon_steel_bar"},
|
||||||
|
{ "technic:stainless_steel_ingot", "technic:stainless_steel_ingot", "technic:stainless_steel_ingot"}
|
||||||
|
},
|
||||||
|
})
|
97
cannon.lua
97
cannon.lua
@ -1,3 +1,4 @@
|
|||||||
|
-- vi: noexpandtab
|
||||||
|
|
||||||
local cable_entry = "^technic_cable_connection_overlay.png"
|
local cable_entry = "^technic_cable_connection_overlay.png"
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ local register_spacecannon = function(def)
|
|||||||
timer = 0,
|
timer = 0,
|
||||||
lifetime = 0,
|
lifetime = 0,
|
||||||
static_save = false,
|
static_save = false,
|
||||||
|
penetrated = 0,
|
||||||
|
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
self.timer = self.timer + dtime
|
self.timer = self.timer + dtime
|
||||||
@ -65,25 +67,33 @@ local register_spacecannon = function(def)
|
|||||||
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
|
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
|
||||||
local collided = false
|
local collided = false
|
||||||
for _, obj in pairs(objs) do
|
for _, obj in pairs(objs) do
|
||||||
if obj:get_luaentity() ~= nil and obj:get_luaentity().name ~= self.name then
|
if obj:get_luaentity() ~= nil
|
||||||
|
and obj:get_luaentity().name ~= self.name
|
||||||
|
and obj:get_luaentity().name ~= "__builtin:item"
|
||||||
|
then
|
||||||
collided = true
|
collided = true
|
||||||
obj:punch(self.object, 1.0, {
|
obj:punch(self.object, 1.0, {
|
||||||
full_punch_interval=1.0,
|
full_punch_interval=1.0,
|
||||||
damage_groups={fleshy=def.range*2},
|
damage_groups={fleshy=def.damage},
|
||||||
}, nil)
|
}, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if collided then
|
if collided then
|
||||||
spacecannon.destroy(pos, def.range, def.intensity)
|
spacecannon.destroy(pos, def.range, def.intensity)
|
||||||
self.object:remove()
|
self.penetrated = self.penetrated + 1
|
||||||
|
if self.penetrated >= def.penetration then
|
||||||
|
self.object:remove()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
-- collision
|
-- collision
|
||||||
spacecannon.destroy(pos, def.range, def.intensity)
|
spacecannon.destroy(pos, def.range, def.intensity)
|
||||||
self.object:remove()
|
self.penetrated = self.penetrated + 1
|
||||||
|
if self.penetrated >= def.penetration then
|
||||||
|
self.object:remove()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -112,7 +122,7 @@ local register_spacecannon = function(def)
|
|||||||
action_on = function (pos)
|
action_on = function (pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local owner = meta:get_string("owner")
|
local owner = meta:get_string("owner")
|
||||||
spacecannon.fire(pos, owner, def.color, def.speed, def.range)
|
spacecannon.fire(pos, owner, def.color, def.speed, def.is_th, def.storage_require_mod)
|
||||||
end
|
end
|
||||||
}},
|
}},
|
||||||
|
|
||||||
@ -145,7 +155,13 @@ local register_spacecannon = function(def)
|
|||||||
-- Set default digiline channel (do before updating formspec).
|
-- Set default digiline channel (do before updating formspec).
|
||||||
meta:set_string("channel", "spacecannon")
|
meta:set_string("channel", "spacecannon")
|
||||||
|
|
||||||
spacecannon.update_formspec(meta)
|
-- Set inventory (not used for thermal cannons)
|
||||||
|
if not def.is_th then
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
inv:set_size("src", 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
spacecannon.update_formspec(meta, def.is_th)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
technic_run = function(pos)
|
technic_run = function(pos)
|
||||||
@ -154,13 +170,17 @@ local register_spacecannon = function(def)
|
|||||||
local demand = meta:get_int("HV_EU_demand")
|
local demand = meta:get_int("HV_EU_demand")
|
||||||
local store = meta:get_int("powerstorage")
|
local store = meta:get_int("powerstorage")
|
||||||
|
|
||||||
|
local config_store = spacecannon.config.ki_powerstorage * def.storage_require_mod
|
||||||
|
if def.is_th then config_store = spacecannon.config.th_powerstorage * def.storage_require_mod end
|
||||||
|
local config_require = spacecannon.config.ki_powerrequirement
|
||||||
|
if def.is_th then config_require = spacecannon.config.th_powerrequirement end
|
||||||
|
|
||||||
meta:set_string("infotext", "Power: " .. eu_input .. "/" .. demand .. " Store: " .. store)
|
meta:set_string("infotext", "Power: " .. eu_input .. "/" .. demand .. " Store: " .. store)
|
||||||
|
|
||||||
if store < spacecannon.config.powerstorage * def.range then
|
if store < config_store then
|
||||||
-- charge
|
-- charge
|
||||||
meta:set_int("HV_EU_demand", spacecannon.config.powerrequirement)
|
meta:set_int("HV_EU_demand", config_require)
|
||||||
store = store + eu_input
|
meta:set_int("powerstorage", store + eu_input)
|
||||||
meta:set_int("powerstorage", store)
|
|
||||||
else
|
else
|
||||||
-- charged
|
-- charged
|
||||||
meta:set_int("HV_EU_demand", 0)
|
meta:set_int("HV_EU_demand", 0)
|
||||||
@ -177,16 +197,21 @@ local register_spacecannon = function(def)
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
if fields.fire then
|
if fields.fire then
|
||||||
spacecannon.fire(pos, playername, def.color, def.speed, def.range)
|
spacecannon.fire(pos, playername, def.color, def.speed, def.is_th, def.storage_require_mod)
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields.set_digiline_channel and fields.digiline_channel then
|
if fields.set_digiline_channel and fields.digiline_channel then
|
||||||
meta:set_string("channel", fields.digiline_channel)
|
meta:set_string("channel", fields.digiline_channel)
|
||||||
end
|
end
|
||||||
|
|
||||||
spacecannon.update_formspec(meta)
|
spacecannon.update_formspec(meta, def.is_th)
|
||||||
end
|
end,
|
||||||
|
|
||||||
|
after_dig_node = function(pos, _node, meta, _digger)
|
||||||
|
if meta.inventory and meta.inventory.src and meta.inventory.src[1] then
|
||||||
|
minetest.add_item(pos, ItemStack(meta.inventory.src[1]))
|
||||||
|
end
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
technic.register_machine("HV", "spacecannon:cannon_" .. def.color, technic.receiver)
|
technic.register_machine("HV", "spacecannon:cannon_" .. def.color, technic.receiver)
|
||||||
@ -205,31 +230,75 @@ local register_spacecannon = function(def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
register_spacecannon({
|
register_spacecannon({
|
||||||
|
is_th = true,
|
||||||
color = "green",
|
color = "green",
|
||||||
range = 1,
|
range = 1,
|
||||||
|
storage_require_mod = 1,
|
||||||
|
damage = 2,
|
||||||
intensity = 1,
|
intensity = 1,
|
||||||
timeout = 8,
|
timeout = 8,
|
||||||
speed = 10,
|
speed = 10,
|
||||||
|
penetration = 0,
|
||||||
desc = "fast,low damage",
|
desc = "fast,low damage",
|
||||||
ingredient = "default:mese_block"
|
ingredient = "default:mese_block"
|
||||||
})
|
})
|
||||||
|
|
||||||
register_spacecannon({
|
register_spacecannon({
|
||||||
|
is_th = true,
|
||||||
color = "yellow",
|
color = "yellow",
|
||||||
range = 3,
|
range = 3,
|
||||||
|
storage_require_mod = 3,
|
||||||
intensity = 2,
|
intensity = 2,
|
||||||
|
damage = 6,
|
||||||
timeout = 8,
|
timeout = 8,
|
||||||
speed = 5,
|
speed = 5,
|
||||||
|
penetration = 0,
|
||||||
desc = "medium speed, medium damage",
|
desc = "medium speed, medium damage",
|
||||||
ingredient = "spacecannon:cannon_green"
|
ingredient = "spacecannon:cannon_green"
|
||||||
})
|
})
|
||||||
|
|
||||||
register_spacecannon({
|
register_spacecannon({
|
||||||
|
is_th = true,
|
||||||
color = "red",
|
color = "red",
|
||||||
range = 5,
|
range = 5,
|
||||||
|
storage_require_mod = 5,
|
||||||
intensity = 4,
|
intensity = 4,
|
||||||
|
damage = 10,
|
||||||
timeout = 15,
|
timeout = 15,
|
||||||
speed = 3,
|
speed = 3,
|
||||||
|
penetration = 0,
|
||||||
desc = "slow, heavy damage",
|
desc = "slow, heavy damage",
|
||||||
ingredient = "spacecannon:cannon_yellow"
|
ingredient = "spacecannon:cannon_yellow"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Railguns
|
||||||
|
|
||||||
|
-- Regular railgun
|
||||||
|
register_spacecannon({
|
||||||
|
is_th = false,
|
||||||
|
color = "blue",
|
||||||
|
range = 0,
|
||||||
|
storage_require_mod = 1,
|
||||||
|
intensity = 2,
|
||||||
|
damage = 5,
|
||||||
|
timeout = 10,
|
||||||
|
speed = 9,
|
||||||
|
penetration = 2,
|
||||||
|
desc = "fast, 2x penetrating damage",
|
||||||
|
ingredient = "technic:copper_coil"
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Helical railgun
|
||||||
|
register_spacecannon({
|
||||||
|
is_th = false,
|
||||||
|
color = "purple",
|
||||||
|
range = 0,
|
||||||
|
storage_require_mod = 1.5,
|
||||||
|
intensity = 4,
|
||||||
|
damage = 10,
|
||||||
|
timeout = 15,
|
||||||
|
speed = 10,
|
||||||
|
penetration = 4,
|
||||||
|
desc = "fast, 4x penetrating damage",
|
||||||
|
ingredient = "spacecannon:cannon_blue"
|
||||||
|
})
|
||||||
|
7
init.lua
7
init.lua
@ -2,10 +2,12 @@
|
|||||||
spacecannon = {
|
spacecannon = {
|
||||||
config = {
|
config = {
|
||||||
-- technic EU storage value
|
-- technic EU storage value
|
||||||
powerstorage = 10000,
|
th_powerstorage = 10000,
|
||||||
|
ki_powerstorage = 300,
|
||||||
|
|
||||||
-- charge value in EU
|
-- charge value in EU
|
||||||
powerrequirement = 2500
|
th_powerrequirement = 2500,
|
||||||
|
ki_powerrequirement = 300
|
||||||
},
|
},
|
||||||
node_resilience = {}
|
node_resilience = {}
|
||||||
}
|
}
|
||||||
@ -15,6 +17,7 @@ local MP = minetest.get_modpath("spacecannon")
|
|||||||
dofile(MP.."/util.lua")
|
dofile(MP.."/util.lua")
|
||||||
dofile(MP.."/digiline.lua")
|
dofile(MP.."/digiline.lua")
|
||||||
dofile(MP.."/cannon.lua")
|
dofile(MP.."/cannon.lua")
|
||||||
|
dofile(MP.."/ammo.lua")
|
||||||
dofile(MP.."/node_resilience.lua")
|
dofile(MP.."/node_resilience.lua")
|
||||||
|
|
||||||
print("[OK] Spacecannon")
|
print("[OK] Spacecannon")
|
||||||
|
5
mod.conf
5
mod.conf
@ -1,4 +1,7 @@
|
|||||||
name = spacecannon
|
name = spacecannon
|
||||||
description = Adds three scifi/space cannons with various projectile-speed and explosion-strength
|
description = Adds five scifi/space cannons with various properties
|
||||||
depends = default, technic
|
depends = default, technic
|
||||||
optional_depends = mesecons, digilines
|
optional_depends = mesecons, digilines
|
||||||
|
release = 6899
|
||||||
|
author = BuckarooBanzay
|
||||||
|
title = Spacecannon
|
||||||
|
BIN
textures/cannon_front_purple.png
Executable file
BIN
textures/cannon_front_purple.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 209 B |
BIN
textures/energycube_purple.png
Executable file
BIN
textures/energycube_purple.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 99 B |
BIN
textures/spacecannon_railgun_slug.png
Executable file
BIN
textures/spacecannon_railgun_slug.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 159 B |
98
util.lua
98
util.lua
@ -1,32 +1,58 @@
|
|||||||
|
-- vi: noexpandtab
|
||||||
|
|
||||||
local has_digilines = minetest.get_modpath("digilines")
|
local has_digilines = minetest.get_modpath("digilines")
|
||||||
|
|
||||||
spacecannon.update_formspec_digilines = function(meta)
|
spacecannon.update_formspec = function(meta, is_th)
|
||||||
local channel = meta:get_string("channel") or ""
|
local formspec = ""
|
||||||
|
|
||||||
local formspec =
|
if not is_th then
|
||||||
"formspec_version[4]" ..
|
formspec = formspec ..
|
||||||
"size[6,4;]" ..
|
"formspec_version[4]" ..
|
||||||
|
"size[10.5,9;]"
|
||||||
|
|
||||||
-- Digiline channel
|
-- Ammo inventory
|
||||||
"field[0.5,0.5;3.5,1;digiline_channel;Digiline Channel;" ..
|
formspec = formspec ..
|
||||||
channel .. "]" ..
|
"list[current_name;src;0.375,0.5;1,1;]" ..
|
||||||
"button_exit[4.5,0.5;1,1;set_digiline_channel;Set]" ..
|
"list[current_player;main;0.375,4;8,4;]" ..
|
||||||
|
"listring[]" ..
|
||||||
|
"label[1.75,1;Ammunition]"
|
||||||
|
|
||||||
-- Manual "fire" button
|
-- Manual "fire" button
|
||||||
"button_exit[0.5,2.5;5,1;fire;Fire]"
|
formspec = formspec ..
|
||||||
|
"button_exit[5.125,0.5;5,1;fire;Fire]"
|
||||||
|
|
||||||
|
-- Digiline channel
|
||||||
|
if has_digilines then
|
||||||
|
local channel = meta:get_string("channel") or ""
|
||||||
|
formspec = formspec ..
|
||||||
|
"field[0.375,2.375;4,1;digiline_channel;Digiline Channel;" .. channel .. "]" ..
|
||||||
|
"button_exit[4.5,2.375;1,1;set_digiline_channel;Set]"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
formspec = formspec .. "formspec_version[4]"
|
||||||
|
|
||||||
|
if has_digilines then
|
||||||
|
formspec = formspec .. "size[6,4;]"
|
||||||
|
else
|
||||||
|
formspec = formspec .. "size[6,2;]"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Manual "fire" button
|
||||||
|
formspec = formspec ..
|
||||||
|
"button_exit[0.5,0.5;5,1;fire;Fire]"
|
||||||
|
|
||||||
|
-- Digiline channel
|
||||||
|
if has_digilines then
|
||||||
|
local channel = meta:get_string("channel") or ""
|
||||||
|
formspec = formspec ..
|
||||||
|
"field[0.5,2.5;3.5,1;digiline_channel;Digiline Channel;" .. channel .. "]" ..
|
||||||
|
"button_exit[4.5,2.5;1,1;set_digiline_channel;Set]"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
meta:set_string("formspec", formspec)
|
meta:set_string("formspec", formspec)
|
||||||
end
|
end
|
||||||
|
|
||||||
spacecannon.update_formspec = function(meta)
|
|
||||||
if has_digilines then
|
|
||||||
spacecannon.update_formspec_digilines(meta)
|
|
||||||
else
|
|
||||||
meta:set_string("formspec", "size[8,2;]" ..
|
|
||||||
"button_exit[0,1;8,1;fire;Fire]")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
spacecannon.can_shoot = function()
|
spacecannon.can_shoot = function()
|
||||||
-- arguments: pos, playername
|
-- arguments: pos, playername
|
||||||
return true
|
return true
|
||||||
@ -37,8 +63,7 @@ spacecannon.can_destroy = function()
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
spacecannon.fire = function(pos, playername, color, speed, range)
|
spacecannon.fire = function(pos, playername, color, speed, is_th, storage_require_mod)
|
||||||
|
|
||||||
if not spacecannon.can_shoot(pos, playername) then
|
if not spacecannon.can_shoot(pos, playername) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -46,13 +71,36 @@ spacecannon.fire = function(pos, playername, color, speed, range)
|
|||||||
-- check fuel/power
|
-- check fuel/power
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
if meta:get_int("powerstorage") < spacecannon.config.powerstorage * range then
|
local config_store = spacecannon.config.ki_powerstorage * storage_require_mod
|
||||||
|
if is_th then config_store = spacecannon.config.th_powerstorage * storage_require_mod end
|
||||||
|
|
||||||
|
if meta:get_int("powerstorage") < config_store then
|
||||||
-- not enough power
|
-- not enough power
|
||||||
return
|
return
|
||||||
|
end
|
||||||
|
|
||||||
else
|
-- check ammunition
|
||||||
-- use power
|
if not is_th then
|
||||||
meta:set_int("powerstorage", 0)
|
local inv = meta:get_inventory()
|
||||||
|
if inv:is_empty("src") then
|
||||||
|
--minetest.chat_send_player(playername, "No ammunition loaded!")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local src_stack = inv:get_list("src")[1]
|
||||||
|
if not src_stack or src_stack:get_name() ~= "spacecannon:railgun_slug" then
|
||||||
|
--minetest.chat_send_player(playername, "Incorrect ammunition!")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- use power
|
||||||
|
meta:set_int("powerstorage", 0)
|
||||||
|
|
||||||
|
-- use ammo
|
||||||
|
if not is_th then
|
||||||
|
local src_stack = (meta:get_inventory()):get_list("src")[1]
|
||||||
|
src_stack:take_item();
|
||||||
|
(meta:get_inventory()):set_stack("src", 1, src_stack)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.sound_play("spacecannon_shoot", {
|
minetest.sound_play("spacecannon_shoot", {
|
||||||
|
Loading…
Reference in New Issue
Block a user