2023-05-30 05:44:29 +02:00
|
|
|
-- vi: noexpandtab
|
2018-04-23 16:04:35 +02:00
|
|
|
|
2023-06-07 12:36:00 +02:00
|
|
|
--local has_digilines = minetest.get_modpath("digilines") and true
|
|
|
|
local has_pipeworks = minetest.get_modpath("pipeworks") and true
|
|
|
|
|
2018-11-16 08:35:51 +01:00
|
|
|
local cable_entry = "^technic_cable_connection_overlay.png"
|
2018-11-16 08:05:42 +01:00
|
|
|
|
2023-06-07 12:36:00 +02:00
|
|
|
local groups_base = {
|
|
|
|
cracky = 3,
|
|
|
|
oddly_breakable_by_hand = 3,
|
|
|
|
technic_machine = 1,
|
|
|
|
technic_hv = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
local groups_rail = table.copy(groups_base)
|
|
|
|
if has_pipeworks then
|
|
|
|
groups_rail.tubedevice = 1
|
|
|
|
groups_rail.tubedevice_receiver = 1
|
|
|
|
end
|
|
|
|
|
2018-11-15 14:15:10 +01:00
|
|
|
local register_spacecannon = function(def)
|
2018-04-24 09:37:53 +02:00
|
|
|
|
2018-11-15 14:15:10 +01:00
|
|
|
local entity_texture = "energycube_" .. def.color .. ".png"
|
2018-04-24 09:37:53 +02:00
|
|
|
|
2018-11-15 14:15:10 +01:00
|
|
|
minetest.register_entity("spacecannon:energycube_" .. def.color, {
|
2018-04-24 09:37:53 +02:00
|
|
|
initial_properties = {
|
|
|
|
visual = "cube",
|
|
|
|
visual_size = {x=0.25, y=0.25},
|
2021-01-10 19:41:47 +01:00
|
|
|
textures = {
|
|
|
|
entity_texture,
|
|
|
|
entity_texture,
|
|
|
|
entity_texture,
|
|
|
|
entity_texture,
|
|
|
|
entity_texture,
|
|
|
|
entity_texture
|
|
|
|
},
|
2018-04-24 09:37:53 +02:00
|
|
|
collisionbox = {-0.25,-0.25,-0.25, 0.25,0.25,0.25},
|
2018-04-24 13:42:55 +02:00
|
|
|
physical = false
|
2018-04-24 09:37:53 +02:00
|
|
|
},
|
2018-04-24 13:42:55 +02:00
|
|
|
timer = 0,
|
2021-01-10 19:41:47 +01:00
|
|
|
lifetime = 0,
|
2018-11-15 14:15:10 +01:00
|
|
|
static_save = false,
|
2023-05-30 05:44:29 +02:00
|
|
|
penetrated = 0,
|
2018-04-24 09:37:53 +02:00
|
|
|
|
|
|
|
on_step = function(self, dtime)
|
2018-04-24 13:42:55 +02:00
|
|
|
self.timer = self.timer + dtime
|
2021-01-10 19:41:47 +01:00
|
|
|
self.lifetime = self.lifetime + dtime
|
|
|
|
|
|
|
|
if self.lifetime > def.timeout then
|
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-04-24 09:37:53 +02:00
|
|
|
local pos = self.object:getpos()
|
2018-04-24 13:42:55 +02:00
|
|
|
|
|
|
|
if self.timer > 0.5 then
|
|
|
|
-- add sparks along the way
|
|
|
|
minetest.add_particlespawner({
|
|
|
|
amount = 5,
|
|
|
|
time = 0.5,
|
|
|
|
minpos = pos,
|
|
|
|
maxpos = pos,
|
|
|
|
minvel = {x = -2, y = -2, z = -2},
|
|
|
|
maxvel = {x = 2, y = 2, z = 2},
|
|
|
|
minacc = {x = -3, y = -3, z = -3},
|
|
|
|
maxacc = {x = 3, y = 3, z = 3},
|
|
|
|
minexptime = 1,
|
|
|
|
maxexptime = 2.5,
|
|
|
|
minsize = 0.5,
|
|
|
|
maxsize = 0.75,
|
|
|
|
texture = "spacecannon_spark.png",
|
|
|
|
glow = 5
|
|
|
|
})
|
|
|
|
self.timer = 0
|
|
|
|
end
|
|
|
|
|
2018-04-24 09:37:53 +02:00
|
|
|
local node = minetest.get_node(pos)
|
2019-07-29 13:24:21 +02:00
|
|
|
local node_def = minetest.registered_nodes[node.name]
|
2018-04-24 09:37:53 +02:00
|
|
|
|
2019-07-29 13:24:21 +02:00
|
|
|
local goes_through = not node_def.walkable
|
|
|
|
|
|
|
|
if goes_through then
|
2018-11-16 11:19:44 +01:00
|
|
|
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
|
2018-11-15 14:40:14 +01:00
|
|
|
local collided = false
|
2021-01-10 19:34:08 +01:00
|
|
|
for _, obj in pairs(objs) do
|
2023-06-02 03:46:56 +02:00
|
|
|
if (obj:is_player() or (obj:get_luaentity() ~= nil
|
2023-05-30 05:44:29 +02:00
|
|
|
and obj:get_luaentity().name ~= self.name
|
2023-06-02 03:46:56 +02:00
|
|
|
and obj:get_luaentity().name ~= "__builtin:item"))
|
|
|
|
and spacecannon.can_damage(obj)
|
2023-05-30 05:44:29 +02:00
|
|
|
then
|
2018-11-15 14:40:14 +01:00
|
|
|
collided = true
|
|
|
|
obj:punch(self.object, 1.0, {
|
|
|
|
full_punch_interval=1.0,
|
2023-05-30 05:44:29 +02:00
|
|
|
damage_groups={fleshy=def.damage},
|
2018-11-15 14:40:14 +01:00
|
|
|
}, nil)
|
2018-04-24 13:54:36 +02:00
|
|
|
end
|
2018-04-24 08:55:09 +02:00
|
|
|
end
|
2018-11-15 14:40:14 +01:00
|
|
|
|
|
|
|
if collided then
|
2019-07-29 13:13:46 +02:00
|
|
|
spacecannon.destroy(pos, def.range, def.intensity)
|
2023-05-30 05:44:29 +02:00
|
|
|
self.penetrated = self.penetrated + 1
|
|
|
|
if self.penetrated >= def.penetration then
|
|
|
|
self.object:remove()
|
|
|
|
end
|
2018-11-15 14:40:14 +01:00
|
|
|
end
|
|
|
|
|
2019-07-29 13:24:21 +02:00
|
|
|
else
|
2018-04-24 09:37:53 +02:00
|
|
|
-- collision
|
2019-07-29 13:13:46 +02:00
|
|
|
spacecannon.destroy(pos, def.range, def.intensity)
|
2023-05-30 05:44:29 +02:00
|
|
|
self.penetrated = self.penetrated + 1
|
|
|
|
if self.penetrated >= def.penetration then
|
|
|
|
self.object:remove()
|
|
|
|
end
|
2018-04-24 08:55:09 +02:00
|
|
|
end
|
|
|
|
end
|
2018-04-24 09:37:53 +02:00
|
|
|
})
|
2018-04-24 08:55:09 +02:00
|
|
|
|
2023-05-31 17:32:45 +02:00
|
|
|
-- top, bottom
|
|
|
|
local textures = {
|
|
|
|
"cannon_blank.png" .. cable_entry,
|
|
|
|
"cannon_front_" .. def.color .. ".png",
|
|
|
|
"cannon_blank.png" .. cable_entry,
|
|
|
|
"cannon_blank.png" .. cable_entry,
|
|
|
|
"cannon_blank.png" .. cable_entry,
|
|
|
|
"cannon_blank.png" .. cable_entry
|
|
|
|
}
|
|
|
|
if def.textures then
|
|
|
|
textures = def.textures
|
|
|
|
end
|
2018-04-23 16:04:35 +02:00
|
|
|
|
2023-06-07 12:36:00 +02:00
|
|
|
local def_cannon = {
|
2023-05-31 10:48:56 +02:00
|
|
|
description = def.name .. " (" .. def.desc .. ")",
|
2023-05-31 17:32:45 +02:00
|
|
|
tiles = textures,
|
2023-06-07 12:36:00 +02:00
|
|
|
groups = def.is_th and groups_base or groups_rail,
|
2018-11-15 14:15:10 +01:00
|
|
|
drop = "spacecannon:cannon_" .. def.color,
|
2018-04-24 09:37:53 +02:00
|
|
|
sounds = default.node_sound_glass_defaults(),
|
|
|
|
paramtype2 = "facedir",
|
2018-11-15 14:15:10 +01:00
|
|
|
legacy_facedir_simple = true,
|
2018-04-23 16:04:35 +02:00
|
|
|
|
2018-04-24 09:37:53 +02:00
|
|
|
mesecons = {effector = {
|
2021-01-10 19:34:08 +01:00
|
|
|
action_on = function (pos)
|
2021-02-25 19:40:40 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local owner = meta:get_string("owner")
|
2023-05-30 05:44:29 +02:00
|
|
|
spacecannon.fire(pos, owner, def.color, def.speed, def.is_th, def.storage_require_mod)
|
2018-04-24 09:37:53 +02:00
|
|
|
end
|
|
|
|
}},
|
2018-04-23 16:04:35 +02:00
|
|
|
|
2018-04-24 09:37:53 +02:00
|
|
|
connects_to = {"group:technic_hv_cable"},
|
|
|
|
connect_sides = {"bottom", "top", "left", "right", "front", "back"},
|
2018-04-23 16:04:35 +02:00
|
|
|
|
2021-01-10 07:53:26 +01:00
|
|
|
digiline = {
|
|
|
|
receptor = {
|
|
|
|
rules = spacecannon.digiline_rules,
|
|
|
|
action = function() end
|
|
|
|
},
|
|
|
|
effector = {
|
|
|
|
rules = spacecannon.digiline_rules,
|
|
|
|
action = spacecannon.digiline_effector
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2018-04-24 09:37:53 +02:00
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("owner", placer:get_player_name() or "")
|
2023-06-07 12:36:00 +02:00
|
|
|
if has_pipeworks then
|
|
|
|
pipeworks.after_place(pos)
|
|
|
|
end
|
2018-04-24 09:37:53 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_int("powerstorage", 0)
|
|
|
|
|
2018-11-15 14:40:14 +01:00
|
|
|
meta:set_int("HV_EU_input", 0)
|
|
|
|
meta:set_int("HV_EU_demand", 0)
|
2018-04-24 11:24:41 +02:00
|
|
|
|
2021-01-10 07:53:26 +01:00
|
|
|
-- Set default digiline channel (do before updating formspec).
|
|
|
|
meta:set_string("channel", "spacecannon")
|
|
|
|
|
2023-05-30 05:44:29 +02:00
|
|
|
-- 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)
|
2018-04-24 09:37:53 +02:00
|
|
|
end,
|
|
|
|
|
2021-01-10 19:34:08 +01:00
|
|
|
technic_run = function(pos)
|
2018-04-24 09:37:53 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local eu_input = meta:get_int("HV_EU_input")
|
|
|
|
local demand = meta:get_int("HV_EU_demand")
|
|
|
|
local store = meta:get_int("powerstorage")
|
|
|
|
|
2023-05-30 05:44:29 +02:00
|
|
|
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
|
|
|
|
|
2023-05-31 10:48:56 +02:00
|
|
|
local infotext =
|
|
|
|
"Power: " .. eu_input .. "/" .. demand .. " " ..
|
|
|
|
"Store: " .. store .. "\n" ..
|
|
|
|
def.name .. ": " .. def.desc
|
|
|
|
meta:set_string("infotext", infotext)
|
2018-04-24 09:37:53 +02:00
|
|
|
|
2023-05-30 05:44:29 +02:00
|
|
|
if store < config_store then
|
2018-04-24 09:37:53 +02:00
|
|
|
-- charge
|
2023-05-30 05:44:29 +02:00
|
|
|
meta:set_int("HV_EU_demand", config_require)
|
|
|
|
meta:set_int("powerstorage", store + eu_input)
|
2018-04-24 09:37:53 +02:00
|
|
|
else
|
|
|
|
-- charged
|
|
|
|
meta:set_int("HV_EU_demand", 0)
|
|
|
|
end
|
2018-04-24 11:24:41 +02:00
|
|
|
end,
|
|
|
|
|
2021-01-10 19:34:08 +01:00
|
|
|
on_receive_fields = function(pos, _, fields, sender)
|
|
|
|
local playername = sender and sender:get_player_name() or ""
|
|
|
|
if minetest.is_protected(pos, playername) then
|
|
|
|
-- only allow protection-owner to fire and configure
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2021-01-10 07:53:26 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
|
2018-04-24 11:24:41 +02:00
|
|
|
if fields.fire then
|
2023-05-30 05:44:29 +02:00
|
|
|
spacecannon.fire(pos, playername, def.color, def.speed, def.is_th, def.storage_require_mod)
|
2018-04-24 11:24:41 +02:00
|
|
|
end
|
2021-01-10 07:53:26 +01:00
|
|
|
|
|
|
|
if fields.set_digiline_channel and fields.digiline_channel then
|
|
|
|
meta:set_string("channel", fields.digiline_channel)
|
|
|
|
end
|
|
|
|
|
2023-05-30 05:44:29 +02:00
|
|
|
spacecannon.update_formspec(meta, def.is_th)
|
|
|
|
end,
|
2018-04-24 11:24:41 +02:00
|
|
|
|
2023-05-30 05:44:29 +02:00
|
|
|
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
|
2023-06-07 12:36:00 +02:00
|
|
|
if has_pipeworks then
|
|
|
|
pipeworks.after_dig(pos)
|
|
|
|
end
|
2023-05-30 05:44:29 +02:00
|
|
|
end
|
2023-06-07 12:36:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if has_pipeworks and not def.is_th then
|
|
|
|
def_cannon.tube = {
|
|
|
|
insert_object = function(pos, _, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:add_item("src", stack)
|
|
|
|
end,
|
|
|
|
can_insert = function(pos, _, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
stack = stack:peek_item(1)
|
|
|
|
|
|
|
|
return inv:room_for_item("src", stack)
|
|
|
|
end,
|
|
|
|
input_inventory = "src",
|
|
|
|
connect_sides = {
|
|
|
|
left = 1, back = 1, top = 1,
|
|
|
|
right = 1, front = 1, bottom = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("spacecannon:cannon_" .. def.color, def_cannon)
|
2018-04-24 09:37:53 +02:00
|
|
|
|
2018-11-15 14:40:14 +01:00
|
|
|
technic.register_machine("HV", "spacecannon:cannon_" .. def.color, technic.receiver)
|
2018-04-23 16:04:35 +02:00
|
|
|
|
2018-04-24 09:37:53 +02:00
|
|
|
minetest.register_craft({
|
2018-11-15 14:15:10 +01:00
|
|
|
output = 'spacecannon:cannon_' .. def.color,
|
2018-04-24 09:37:53 +02:00
|
|
|
recipe = {
|
2018-11-15 14:15:10 +01:00
|
|
|
{'', 'default:steelblock', ''},
|
|
|
|
{ def.ingredient, def.ingredient, def.ingredient},
|
|
|
|
{'', 'default:steelblock', ''}
|
2018-04-24 09:37:53 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-04-23 16:04:35 +02:00
|
|
|
end
|
|
|
|
|
2018-11-15 14:15:10 +01:00
|
|
|
register_spacecannon({
|
|
|
|
color = "green",
|
2023-05-31 10:48:56 +02:00
|
|
|
name = "Ion cannon",
|
|
|
|
desc = "fast, low damage",
|
|
|
|
is_th = true,
|
2018-11-15 14:15:10 +01:00
|
|
|
range = 1,
|
2023-05-30 05:44:29 +02:00
|
|
|
storage_require_mod = 1,
|
2023-06-02 03:46:56 +02:00
|
|
|
damage = 5,
|
2019-07-29 13:13:46 +02:00
|
|
|
intensity = 1,
|
2018-11-15 14:15:10 +01:00
|
|
|
timeout = 8,
|
|
|
|
speed = 10,
|
2023-05-30 05:44:29 +02:00
|
|
|
penetration = 0,
|
2018-11-15 14:15:10 +01:00
|
|
|
ingredient = "default:mese_block"
|
|
|
|
})
|
|
|
|
|
|
|
|
register_spacecannon({
|
|
|
|
color = "yellow",
|
2023-05-31 10:48:56 +02:00
|
|
|
name = "Plasma cannon",
|
|
|
|
desc = "medium speed, medium damage",
|
|
|
|
is_th = true,
|
2018-11-15 14:15:10 +01:00
|
|
|
range = 3,
|
2023-05-30 05:44:29 +02:00
|
|
|
storage_require_mod = 3,
|
2019-07-29 13:13:46 +02:00
|
|
|
intensity = 2,
|
2023-06-02 03:46:56 +02:00
|
|
|
damage = 8,
|
2018-11-15 14:15:10 +01:00
|
|
|
timeout = 8,
|
|
|
|
speed = 5,
|
2023-05-30 05:44:29 +02:00
|
|
|
penetration = 0,
|
2018-11-15 14:15:10 +01:00
|
|
|
ingredient = "spacecannon:cannon_green"
|
|
|
|
})
|
|
|
|
|
|
|
|
register_spacecannon({
|
|
|
|
color = "red",
|
2023-05-31 10:48:56 +02:00
|
|
|
name = "Nova cannon",
|
|
|
|
desc = "slow, heavy damage",
|
|
|
|
is_th = true,
|
2018-11-15 14:15:10 +01:00
|
|
|
range = 5,
|
2023-05-30 05:44:29 +02:00
|
|
|
storage_require_mod = 5,
|
2019-07-29 13:13:46 +02:00
|
|
|
intensity = 4,
|
2023-05-30 05:44:29 +02:00
|
|
|
damage = 10,
|
2018-11-15 14:15:10 +01:00
|
|
|
timeout = 15,
|
|
|
|
speed = 3,
|
2023-05-30 05:44:29 +02:00
|
|
|
penetration = 0,
|
2018-11-15 14:15:10 +01:00
|
|
|
ingredient = "spacecannon:cannon_yellow"
|
|
|
|
})
|
2023-05-30 05:44:29 +02:00
|
|
|
|
|
|
|
-- Railguns
|
|
|
|
|
|
|
|
-- Regular railgun
|
|
|
|
register_spacecannon({
|
|
|
|
color = "blue",
|
2023-05-31 10:48:56 +02:00
|
|
|
name = "Railgun cannon",
|
|
|
|
desc = "fast, 2x penetrating damage",
|
2023-05-31 17:32:45 +02:00
|
|
|
textures = {
|
|
|
|
"railgun_blank.png" .. cable_entry,
|
|
|
|
"railgun_front.png",
|
|
|
|
"railgun_blank.png" .. cable_entry,
|
|
|
|
"railgun_blank.png" .. cable_entry,
|
|
|
|
"railgun_top_bottom.png",
|
|
|
|
"railgun_top_bottom.png",
|
|
|
|
},
|
2023-05-31 10:48:56 +02:00
|
|
|
is_th = false,
|
2023-05-30 05:44:29 +02:00
|
|
|
range = 0,
|
|
|
|
storage_require_mod = 1,
|
|
|
|
intensity = 2,
|
2023-06-02 03:46:56 +02:00
|
|
|
damage = 6,
|
2023-05-30 05:44:29 +02:00
|
|
|
timeout = 10,
|
|
|
|
speed = 9,
|
|
|
|
penetration = 2,
|
|
|
|
ingredient = "technic:copper_coil"
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Helical railgun
|
|
|
|
register_spacecannon({
|
|
|
|
color = "purple",
|
2023-05-31 10:48:56 +02:00
|
|
|
name = "Helical railgun cannon",
|
|
|
|
desc = "fast, 4x penetrating damage",
|
2023-05-31 17:32:45 +02:00
|
|
|
textures = {
|
|
|
|
"railgun_blank.png" .. cable_entry,
|
|
|
|
"helical_railgun_front.png",
|
|
|
|
"railgun_blank.png" .. cable_entry,
|
|
|
|
"railgun_blank.png" .. cable_entry,
|
|
|
|
"helical_railgun_top_bottom.png",
|
|
|
|
"helical_railgun_top_bottom.png",
|
|
|
|
},
|
2023-05-31 10:48:56 +02:00
|
|
|
is_th = false,
|
2023-05-30 05:44:29 +02:00
|
|
|
range = 0,
|
|
|
|
storage_require_mod = 1.5,
|
|
|
|
intensity = 4,
|
2023-06-02 03:46:56 +02:00
|
|
|
damage = 6,
|
2023-05-30 05:44:29 +02:00
|
|
|
timeout = 15,
|
|
|
|
speed = 10,
|
|
|
|
penetration = 4,
|
|
|
|
ingredient = "spacecannon:cannon_blue"
|
|
|
|
})
|