This commit is contained in:
pagliaccio 2013-07-13 13:19:07 +02:00
commit ad0bef9d90
4 changed files with 530 additions and 515 deletions

View File

@ -1,4 +1,9 @@
--- HV battery box
local max_charge = 1500000
local max_charge_rate = 3000
local max_discharge_rate = 5000
-- HV battery box
minetest.register_craft({ minetest.register_craft({
output = 'technic:hv_battery_box 1', output = 'technic:hv_battery_box 1',
recipe = { recipe = {
@ -20,11 +25,11 @@ local battery_box_formspec =
"label[1,3;Power level]".. "label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]" "list[current_player;main;0,5;8,4;]"
minetest.register_node( minetest.register_node("technic:hv_battery_box", {
"technic:hv_battery_box", {
description = "HV Battery Box", description = "HV Battery Box",
tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png", tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png",
"technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png"}, "technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png",
"technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png"},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2}, groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
drop = "technic:hv_battery_box", drop = "technic:hv_battery_box",
@ -34,9 +39,9 @@ minetest.register_node(
meta:set_string("infotext", "HV Battery Box") meta:set_string("infotext", "HV Battery Box")
meta:set_float("technic_hv_power_machine", 1) meta:set_float("technic_hv_power_machine", 1)
meta:set_string("formspec", battery_box_formspec) meta:set_string("formspec", battery_box_formspec)
meta:set_int("HV_EU_demand", 0) -- How much can this node charge meta:set_int("HV_EU_demand", 0) -- How much this node can charge
meta:set_int("HV_EU_supply", 0) -- How much can this node discharge meta:set_int("HV_EU_supply", 0) -- How much this node can discharge
meta:set_int("HV_EU_input", 0) -- How much power is this machine getting. meta:set_int("HV_EU_input", 0) -- How much power this machine is getting.
meta:set_float("internal_EU_charge", 0) meta:set_float("internal_EU_charge", 0)
inv:set_size("src", 1) inv:set_size("src", 1)
inv:set_size("dst", 1) inv:set_size("dst", 1)
@ -54,11 +59,13 @@ minetest.register_node(
}) })
for i = 1,8,1 do for i = 1,8,1 do
minetest.register_node( minetest.register_node("technic:hv_battery_box"..i, {
"technic:hv_battery_box"..i, description = "HV Battery Box",
{description = "HV Battery Box", tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png",
tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png"}, "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_hv_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_hv_battery_box_side0.png^technic_power_meter"..i..".png"},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1}, groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
paramtype="light", paramtype="light",
@ -79,10 +86,10 @@ end
local power_tools = technic.HV_power_tools local power_tools = technic.HV_power_tools
local charge_HV_tools = function(meta, charge) local function charge_HV_tools(meta, charge)
--charge registered power tools --charge registered power tools
local inv = meta:get_inventory() local inv = meta:get_inventory()
if inv:is_empty("src")==false then if not inv:is_empty("src") then
local srcstack = inv:get_stack("src", 1) local srcstack = inv:get_stack("src", 1)
local src_item = srcstack:to_table() local src_item = srcstack:to_table()
local src_meta = get_item_meta(src_item["metadata"]) local src_meta = get_item_meta(src_item["metadata"])
@ -103,15 +110,19 @@ local charge_HV_tools = function(meta, charge)
end end
-- Do the charging -- Do the charging
local item_max_charge = power_tools[toolname] local item_max_charge = power_tools[toolname]
local load = src_meta["charge"] local tool_charge = src_meta["charge"]
local load_step = 1000 -- how much to charge per tick local charge_step = 1000 -- how much to charge per tick
if load<item_max_charge and charge>0 then if tool_charge < item_max_charge and tool_charge > 0 then
if charge-load_step<0 then load_step=charge end if tool_charge - charge_step < 0 then
if load+load_step>item_max_charge then load_step=item_max_charge-load end charge_step = charge
load=load+load_step end
charge=charge-load_step if tool_charge + charge_step > item_max_charge then
technic.set_RE_wear(src_item,load,item_max_charge) charge_step = item_max_charge - tool_charge
src_meta["charge"] = load end
tool_charge = tool_charge + charge_step
charge = charge - charge_step
technic.set_RE_wear(src_item, tool_charge, item_max_charge)
src_meta["charge"] = tool_charge
src_item["metadata"] = set_item_meta(src_meta) src_item["metadata"] = set_item_meta(src_meta)
inv:set_stack("src", 1, src_item) inv:set_stack("src", 1, src_item)
end end
@ -120,38 +131,37 @@ local charge_HV_tools = function(meta, charge)
return charge -- return the remaining charge in the battery return charge -- return the remaining charge in the battery
end end
local discharge_HV_tools = function(meta, charge, max_charge) local function discharge_HV_tools(meta, charge, max_charge)
-- discharging registered power tools -- discharging registered power tools
local inv = meta:get_inventory() local inv = meta:get_inventory()
if inv:is_empty("dst") == false then if not inv:is_empty("dst") then
srcstack = inv:get_stack("dst", 1) srcstack = inv:get_stack("dst", 1)
src_item = srcstack:to_table() src_item = srcstack:to_table()
local src_meta = get_item_meta(src_item["metadata"]) local src_meta = get_item_meta(src_item["metadata"])
local toolname = src_item["name"] local toolname = src_item["name"]
if power_tools[toolname] ~= nil then if power_tools[toolname] ~= nil then
-- Set meta data for the tool if it didn't do it itself :-( -- Set meta data for the tool if it didn't do it itself :-(
src_meta=get_item_meta(src_item["metadata"]) src_meta = get_item_meta(src_item["metadata"]) or {}
if src_meta==nil then
src_meta={}
src_meta["technic_hv_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_hv_power_tool"] == nil then if src_meta["technic_hv_power_tool"] == nil then
src_meta["technic_hv_power_tool"] = true src_meta["technic_hv_power_tool"] = true
src_meta["charge"] = 0 src_meta["charge"] = 0
end end
end
-- Do the discharging -- Do the discharging
local item_max_charge = power_tools[toolname] local item_max_charge = power_tools[toolname]
local load = src_meta["charge"] local tool_charge = src_meta["charge"]
local load_step = 4000 -- how much to discharge per tick local charge_step = 4000 -- how much to discharge per tick
if load>0 and charge<max_charge then if tool_charge > 0 and charge < max_charge then
if charge+load_step>max_charge then load_step=max_charge-charge end if tool_charge + charge_step > max_charge then
if load-load_step<0 then load_step=load end charge_step = max_charge - charge
load=load-load_step end
charge=charge+load_step if tool_charge - charge_step < 0 then
technic.set_RE_wear(src_item,load,item_max_charge) charge_step = charge
src_meta["charge"]=load end
tool_charge = tool_charge - charge_step
charge = charge + charge_step
technic.set_RE_wear(src_item, tool_charge, item_max_charge)
src_meta["charge"] = tool_charge
src_item["metadata"] = set_item_meta(src_meta) src_item["metadata"] = set_item_meta(src_meta)
inv:set_stack("dst", 1, src_item) inv:set_stack("dst", 1, src_item)
end end
@ -160,17 +170,14 @@ local discharge_HV_tools = function(meta, charge, max_charge)
return charge -- return the remaining charge in the battery return charge -- return the remaining charge in the battery
end end
minetest.register_abm( minetest.register_abm({
{nodenames = {"technic:hv_battery_box","technic:hv_battery_box1","technic:hv_battery_box2","technic:hv_battery_box3","technic:hv_battery_box4", nodenames = {"technic:hv_battery_box", "technic:hv_battery_box1", "technic:hv_battery_box2",
"technic:hv_battery_box5","technic:hv_battery_box6","technic:hv_battery_box7","technic:hv_battery_box8" "technic:hv_battery_box3", "technic:hv_battery_box4", "technic:hv_battery_box5",
}, "technic:hv_battery_box6", "technic:hv_battery_box7", "technic:hv_battery_box8"},
interval = 1, interval = 1,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
local max_charge = 1500000 -- Set maximum charge for the device here
local max_charge_rate = 3000 -- Set maximum rate of charging
local max_discharge_rate = 5000 -- Set maximum rate of discharging (16000)
local eu_input = meta:get_int("HV_EU_input") local eu_input = meta:get_int("HV_EU_input")
local current_charge = meta:get_int("internal_EU_charge") -- Battery charge right now local current_charge = meta:get_int("internal_EU_charge") -- Battery charge right now
@ -195,24 +202,27 @@ minetest.register_abm(
meta:set_int("HV_EU_supply", math.min(max_discharge_rate, current_charge)) meta:set_int("HV_EU_supply", math.min(max_discharge_rate, current_charge))
meta:set_int("internal_EU_charge", current_charge) meta:set_int("internal_EU_charge", current_charge)
--dprint("BA: input:"..eu_input.." supply="..meta:get_int("HV_EU_supply").." demand="..meta:get_int("HV_EU_demand").." current:"..current_charge)
-- Select node textures -- Select node textures
local i=math.ceil((current_charge/max_charge)*8) local charge_count = math.ceil((current_charge / max_charge) * 8)
if i > 8 then i = 8 end if charge_count > 8 then
local j = meta:get_float("last_side_shown") charge_count = 8
if i~=j then end
if i>0 then hacky_swap_node(pos,"technic:hv_battery_box"..i) local last_count = meta:get_float("last_side_shown")
elseif i==0 then hacky_swap_node(pos,"technic:hv_battery_box") end if charge_count ~= last_count then
meta:set_float("last_side_shown",i) if charge_count > 0 then
hacky_swap_node(pos,"technic:hv_battery_box"..charge_count)
else
hacky_swap_node(pos,"technic:hv_battery_box")
end
meta:set_float("last_side_shown", charge_count)
end end
local load = math.floor(current_charge/max_charge * 100) local charge_percent = math.floor(current_charge / max_charge * 100)
meta:set_string("formspec", meta:set_string("formspec",
battery_box_formspec.. battery_box_formspec..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"
(load)..":technic_power_meter_fg.png]" ..charge_percent..":technic_power_meter_fg.png]")
)
if eu_input == 0 then if eu_input == 0 then
meta:set_string("infotext", "HV Battery box: "..current_charge.."/"..max_charge.." (idle)") meta:set_string("infotext", "HV Battery box: "..current_charge.."/"..max_charge.." (idle)")

View File

@ -5,8 +5,8 @@
-- Forcefield Generator is a HV machine. -- Forcefield Generator is a HV machine.
-- How expensive is the generator? Leaves room for upgrades lowering the power drain? -- How expensive is the generator? Leaves room for upgrades lowering the power drain?
local forcefield_power_drain = 10 -- default 10 local forcefield_power_drain = 10
local forcefield_update_interval = 1 local forcefield_step_interval = 1
minetest.register_craft({ minetest.register_craft({
output = 'technic:forcefield_emitter_off', output = 'technic:forcefield_emitter_off',
@ -17,65 +17,63 @@ minetest.register_craft({
} }
}) })
-- Idea: Let forcefields have different colors by upgrade slot. -- Idea: Let forcefields have different colors by upgrade slot.
-- Idea: Let forcefields add up by detecting if one hits another. -- Idea: Let forcefields add up by detecting if one hits another.
-- ___ __ -- ___ __
-- / \/ \ -- / \/ \
-- | | -- | |
-- \___/\___/ -- \___/\___/
--
local function add_forcefield(pos, range) local function update_forcefield(pos, range, active)
for x=-range,range do local vm = VoxelManip()
for y=-range,range do local p1 = {x = pos.x-range, y = pos.y-range, z = pos.z-range}
local p2 = {x = pos.x+range, y = pos.y+range, z = pos.z+range}
local MinEdge, MaxEdge = vm:read_from_map(p1, p2)
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
local data = vm:get_data()
local c_air = minetest.get_content_id("air")
local c_field = minetest.get_content_id("technic:forcefield")
for z=-range, range do for z=-range, range do
if ((x*x+y*y+z*z) <= (range * range + range)) then for y=-range, range do
if ((range-1) * (range-1) + (range-1) <= x*x+y*y+z*z) then local vi = area:index(pos.x+(-range), pos.y+y, pos.z+z)
local np={x=pos.x+x,y=pos.y+y,z=pos.z+z} for x=-range, range do
local n = minetest.env:get_node(np).name if x*x+y*y+z*z <= range * range + range and
if (n == "air") then x*x+y*y+z*z >= (range-1) * (range-1) + (range-1) and
minetest.env:add_node(np, {name = "technic:forcefield"}) ((active and data[vi] == c_air) or ((not active) and data[vi] == c_field)) then
if active then
data[vi] = c_field
else
data[vi] = c_air
end end
end end
vi = vi + 1
end end
end end
end end
end
return true
end
local function remove_forcefield(p, range) vm:set_data(data)
for x=-range,range do vm:update_liquids()
for y=-range,range do vm:write_to_map()
for z=-range,range do vm:update_map()
if ((x*x+y*y+z*z) <= (range * range + range)) then
if ((range-1) * (range-1) + (range-1) <= x*x+y*y+z*z) then
local np={x=p.x+x,y=p.y+y,z=p.z+z}
local n = minetest.env:get_node(np).name
if (n == "technic:forcefield") then
minetest.env:remove_node(np)
end
end
end
end
end
end
end end
local get_forcefield_formspec = function(range) local get_forcefield_formspec = function(range)
-- return "invsize[8,9;]".. (if upgrades added later - colors for instance)
return "invsize[3,4;]".. return "invsize[3,4;]"..
"label[0,0;Forcefield emitter]".. "label[0,0;Forcefield emitter]"..
"label[1,1;Range]".. "label[1,1;Range]"..
"label[1,2;"..range.."]".. "label[1,2;"..range.."]"..
"button[0,2;1,1;subtract;-]".. "button[0,2;1,1;subtract;-]"..
"button[2,2;1,1;add;+]".. "button[2,2;1,1;add;+]"..
"button[0,3;3,1;toggle;Enable/Disable]" -- .. "button[0,3;3,1;toggle;Enable/Disable]"
-- "list[current_player;main;0,5;8,4;]"
end end
local forcefield_receive_fields = function(pos, formname, fields, sender) local forcefield_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
local range = meta:get_int("range") local range = meta:get_int("range")
if fields.add then range = range + 1 end if fields.add then range = range + 1 end
if fields.subtract then range = range - 1 end if fields.subtract then range = range - 1 end
if fields.toggle then if fields.toggle then
@ -85,19 +83,20 @@ local forcefield_receive_fields = function(pos, formname, fields, sender)
meta:set_int("enabled", 1) meta:set_int("enabled", 1)
end end
end end
-- Smallest field is 5. Anything less is asking for trouble. -- Smallest field is 5. Anything less is asking for trouble.
-- Largest is 20. It is a matter of pratical node handling. -- Largest is 20. It is a matter of pratical node handling.
if range < 5 then range = 5 end if range < 5 then range = 5 end
if range > 20 then range = 20 end if range > 20 then range = 20 end
if range <= 20 and range >= 5 and meta:get_int("range") ~= range then if range <= 20 and range >= 5 and meta:get_int("range") ~= range then
remove_forcefield(pos, meta:get_int("range")) update_forcefield(pos, meta:get_int("range"), false)
meta:set_int("range", range) meta:set_int("range", range)
meta:set_string("formspec", get_forcefield_formspec(range)) meta:set_string("formspec", get_forcefield_formspec(range))
end end
end end
local forcefield_check = function(pos) local function forcefield_step(pos)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
local eu_input = meta:get_int("HV_EU_input") local eu_input = meta:get_int("HV_EU_input")
@ -107,53 +106,49 @@ local forcefield_check = function(pos)
-- Power off automatically if no longer connected to a switching station -- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "HV") technic.switching_station_timeout_count(pos, "HV")
local power_requirement local power_requirement = 0
if enabled == 1 then if enabled == 1 then
power_requirement = math.floor(4*math.pi*math.pow(meta:get_int("range"), 2)) * forcefield_power_drain power_requirement = math.floor(
4 * math.pi * math.pow(meta:get_int("range"), 2)
) * forcefield_power_drain
else else
power_requirement = eu_demand power_requirement = eu_demand
end end
if eu_input == 0 then if meta:get_int("enabled") == 0 then
meta:set_string("infotext", "Forcefield Generator Unpowered")
meta:set_int("HV_EU_demand", 100)
meta:set_int("enabled", 0)
if node.name == "technic:forcefield_emitter_on" then if node.name == "technic:forcefield_emitter_on" then
remove_forcefield(pos, meta:get_int("range")) update_forcefield(pos, meta:get_int("range"), false)
hacky_swap_node(pos, "technic:forcefield_emitter_off")
meta:set_int("HV_EU_demand", 100)
meta:set_string("infotext", "Forcefield Generator Disabled")
end
elseif eu_input < power_requirement then
meta:set_string("infotext", "Forcefield Generator Unpowered")
if node.name == "technic:forcefield_emitter_on" then
update_forcefield(pos, meta:get_int("range"), false)
hacky_swap_node(pos, "technic:forcefield_emitter_off") hacky_swap_node(pos, "technic:forcefield_emitter_off")
end end
elseif eu_input == power_requirement then elseif eu_input >= power_requirement then
if meta:get_int("enabled") == 1 then
if node.name == "technic:forcefield_emitter_off" then if node.name == "technic:forcefield_emitter_off" then
hacky_swap_node(pos, "technic:forcefield_emitter_on") hacky_swap_node(pos, "technic:forcefield_emitter_on")
meta:set_string("infotext", "Forcefield Generator Active") meta:set_string("infotext", "Forcefield Generator Active")
add_forcefield(pos, meta:get_int("range"))
else
-- Range updated. Move the forcefield.
add_forcefield(pos, meta:get_int("range"))
end end
else update_forcefield(pos, meta:get_int("range"), true)
if node.name == "technic:forcefield_emitter_on" then
remove_forcefield(pos, meta:get_int("range"))
hacky_swap_node(pos, "technic:forcefield_emitter_off")
meta:set_int("HV_EU_demand", 100)
meta:set_string("infotext", "Forcefield Generator Idle")
end end
end
else
meta:set_int("HV_EU_demand", power_requirement) meta:set_int("HV_EU_demand", power_requirement)
end
return true return true
end end
local mesecons = {effector = { local mesecons = {
effector = {
action_on = function(pos, node) action_on = function(pos, node)
minetest.env:get_meta(pos):set_int("enabled", 0) minetest.env:get_meta(pos):set_int("enabled", 0)
end, end,
action_off = function(pos, node) action_off = function(pos, node)
minetest.env:get_meta(pos):set_int("enabled", 1) minetest.env:get_meta(pos):set_int("enabled", 1)
end end
}} }
}
minetest.register_node("technic:forcefield_emitter_off", { minetest.register_node("technic:forcefield_emitter_off", {
description = "Forcefield emitter", description = "Forcefield emitter",
@ -161,10 +156,10 @@ minetest.register_node("technic:forcefield_emitter_off", {
tiles = {"technic_forcefield_emitter_off.png"}, tiles = {"technic_forcefield_emitter_off.png"},
is_ground_content = true, is_ground_content = true,
groups = {cracky = 1}, groups = {cracky = 1},
on_timer = forcefield_check, on_timer = forcefield_step,
on_receive_fields = forcefield_receive_fields, on_receive_fields = forcefield_receive_fields,
on_construct = function(pos) on_construct = function(pos)
minetest.env:get_node_timer(pos):start(forcefield_update_interval) minetest.env:get_node_timer(pos):start(forcefield_step_interval)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_float("technic_hv_power_machine", 1) meta:set_float("technic_hv_power_machine", 1)
meta:set_int("HV_EU_input", 0) meta:set_int("HV_EU_input", 0)
@ -183,10 +178,10 @@ minetest.register_node("technic:forcefield_emitter_on", {
is_ground_content = true, is_ground_content = true,
groups = {cracky = 1, not_in_creative_inventory=1}, groups = {cracky = 1, not_in_creative_inventory=1},
drop='"technic:forcefield_emitter_off" 1', drop='"technic:forcefield_emitter_off" 1',
on_timer = forcefield_check, on_timer = forcefield_step,
on_receive_fields = forcefield_receive_fields, on_receive_fields = forcefield_receive_fields,
on_construct = function(pos) on_construct = function(pos)
minetest.env:get_node_timer(pos):start(forcefield_update_interval) minetest.env:get_node_timer(pos):start(forcefield_step_interval)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
-- meta:set_float("technic_hv_power_machine", 1) -- meta:set_float("technic_hv_power_machine", 1)
-- meta:set_float("HV_EU_input", 0) -- meta:set_float("HV_EU_input", 0)
@ -197,7 +192,7 @@ minetest.register_node("technic:forcefield_emitter_on", {
-- meta:set_string("infotext", "Forcefield emitter"); -- meta:set_string("infotext", "Forcefield emitter");
end, end,
on_dig = function(pos, node, digger) on_dig = function(pos, node, digger)
remove_forcefield(pos, minetest.env:get_meta(pos):get_int("range")) update_forcefield(pos, minetest.env:get_meta(pos):get_int("range"), false)
return minetest.node_dig(pos, node, digger) return minetest.node_dig(pos, node, digger)
end, end,
mesecons = mesecons mesecons = mesecons
@ -208,7 +203,15 @@ minetest.register_node("technic:forcefield", {
sunlight_propagates = true, sunlight_propagates = true,
drop = '', drop = '',
light_source = 8, light_source = 8,
tiles = {{name="technic_forcefield_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0}}}, tiles = {{
name = "technic_forcefield_animated.png",
animation = {
type = "vertical_frames",
aspect_w=16,
aspect_h=16,
length=2.0,
},
}},
is_ground_content = true, is_ground_content = true,
groups = { not_in_creative_inventory=1, unbreakable=1 }, groups = { not_in_creative_inventory=1, unbreakable=1 },
paramtype = "light", paramtype = "light",

View File

@ -5,13 +5,15 @@
-- --
-- The nuclear reactor core needs water and a protective shield to work. -- The nuclear reactor core needs water and a protective shield to work.
-- This is checked now and then and if the machine is tampered with... BOOM! -- This is checked now and then and if the machine is tampered with... BOOM!
local burn_ticks = 24*60 -- [minutes]. How many minutes does the power plant burn per serving? local burn_ticks = 24*60 -- [minutes]. How many minutes does the power plant burn per serving?
local power_supply = 10000 -- [HV] EUs local power_supply = 10000 -- [HV] EUs
local fuel_type = "technic:enriched_uranium" -- This reactor burns this stuff local fuel_type = "technic:enriched_uranium" -- The reactor burns this stuff
-- FIXME: recipe must make more sense like a rod recepticle, steam chamber, HV generator? -- FIXME: recipe must make more sense like a rod recepticle, steam chamber, HV generator?
minetest.register_craft( minetest.register_craft({
{output = 'technic:hv_nuclear_reactor_core', output = 'technic:hv_nuclear_reactor_core',
recipe = { recipe = {
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'}, {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
{'technic:stainless_steel_ingot', '', 'technic:stainless_steel_ingot'}, {'technic:stainless_steel_ingot', '', 'technic:stainless_steel_ingot'},
@ -19,9 +21,8 @@ minetest.register_craft(
} }
}) })
minetest.register_craftitem( minetest.register_craftitem("technic:hv_nuclear_reactor_core",{
"technic:hv_nuclear_reactor_core", description = "Uranium Rod Driven HV Reactor",
{description = "Uranium Rod Driven HV Reactor",
stack_max = 1, stack_max = 1,
}) })
@ -52,13 +53,11 @@ local nodebox = {
{ -0.303, -0.303, -0.397, 0.303, 0.303, 0.397 }, { -0.303, -0.303, -0.397, 0.303, 0.303, 0.397 },
} }
minetest.register_node( minetest.register_node("technic:hv_nuclear_reactor_core", {
"technic:hv_nuclear_reactor_core", description = "Nuclear Reactor",
{description = "Nuclear Reactor",
tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"}, "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"},
-- paramtype2 = "facedir",
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2}, groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
legacy_facedir_simple = true, legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
@ -91,12 +90,11 @@ minetest.register_node(
end, end,
}) })
minetest.register_node( minetest.register_node("technic:hv_nuclear_reactor_core_active", {
"technic:hv_nuclear_reactor_core_active", description = "Uranium Rod Driven HV Reactor",
{description = "Uranium Rod Driven HV Reactor", tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"}, "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"},
-- paramtype2 = "facedir",
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1}, groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
legacy_facedir_simple = true, legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
@ -134,50 +132,53 @@ local check_reactor_structure = function(pos)
-- CCSSS|SSSCC -- CCSSS|SSSCC
-- CCCCC|CCCCC -- CCCCC|CCCCC
-- C = Concrete, S = Stainless Steel, W = water node (not floating), #=reactor core, |=HV cable -- C = Concrete, S = Stainless Steel, W = water node (not floating), #=reactor core, |=HV cable
-- The man-hole and the HV cable is only in the middle. -- The man-hole and the HV cable is only in the middle
local water_nodes = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y-1, z=pos.z-1}, -- The man-hole is optional
local source_water_nodes = minetest.find_nodes_in_area(
{x=pos.x-1, y=pos.y-1, z=pos.z-1},
{x=pos.x+1, y=pos.y+1, z=pos.z+1}, {x=pos.x+1, y=pos.y+1, z=pos.z+1},
"default:water_source") "default:water_source")
--print("Water ( 25):"..#water_nodes) local flowing_water_nodes = minetest.find_nodes_in_area(
if #water_nodes ~= 25 then {x=pos.x-1, y=pos.y-1, z=pos.z-1},
--print("Water supply defect") {x=pos.x+1, y=pos.y+1, z=pos.z+1},
return 0 "default:water_flowing")
if not ((#source_water_nodes + #flowing_water_nodes) >= 25) then
return false
end end
local inner_shield_nodes = minetest.find_nodes_in_area({x=pos.x-2, y=pos.y-2, z=pos.z-2},
local inner_shield_nodes = minetest.find_nodes_in_area(
{x=pos.x-2, y=pos.y-2, z=pos.z-2},
{x=pos.x+2, y=pos.y+2, z=pos.z+2}, {x=pos.x+2, y=pos.y+2, z=pos.z+2},
"technic:concrete") "technic:concrete")
if not (#inner_shield_nodes >= 96) then
--print("Concrete 1 ( 96):"..#inner_shield_nodes) return false
if #inner_shield_nodes ~= 96 then
--print("Inner shield defect")
return 0
end end
local steel_shield_nodes = minetest.find_nodes_in_area({x=pos.x-3, y=pos.y-3, z=pos.z-3},
local steel_shield_nodes = minetest.find_nodes_in_area(
{x=pos.x-3, y=pos.y-3, z=pos.z-3},
{x=pos.x+3, y=pos.y+3, z=pos.z+3}, {x=pos.x+3, y=pos.y+3, z=pos.z+3},
"default:steelblock") "default:steelblock")
if not (#steel_shield_nodes >= 216) then
--print("Steel ( 216):"..#steel_shield_nodes) return false
if #steel_shield_nodes ~= 216 then
--print("Steel shield defect")
return 0
end end
local outer_shield_nodes = minetest.find_nodes_in_area({x=pos.x-5, y=pos.y-5, z=pos.z-5},
local outer_shield_nodes = minetest.find_nodes_in_area(
{x=pos.x-5, y=pos.y-5, z=pos.z-5},
{x=pos.x+5, y=pos.y+5, z=pos.z+5}, {x=pos.x+5, y=pos.y+5, z=pos.z+5},
"technic:concrete") "technic:concrete")
--print("Concrete 2 (1080):"..#outer_shield_nodes) if not (#outer_shield_nodes >= (984 + #inner_shield_nodes)) then
if #outer_shield_nodes ~= (984+#inner_shield_nodes) then return false
--print("Outer shield defect")
return 0
end end
return 1 return true
end end
local explode_reactor = function(pos) local explode_reactor = function(pos)
print("BOOM A reactor exploded!") print("BOOM A reactor exploded!")
end end
minetest.register_abm( minetest.register_abm({
{nodenames = {"technic:hv_nuclear_reactor_core","technic:hv_nuclear_reactor_core_active"}, nodenames = {"technic:hv_nuclear_reactor_core", "technic:hv_nuclear_reactor_core_active"},
interval = 1, interval = 1,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
@ -186,21 +187,25 @@ minetest.register_abm(
-- If more to burn and the energy produced was used: produce some more -- If more to burn and the energy produced was used: produce some more
if burn_time > 0 then if burn_time > 0 then
if not check_reactor_structure(pos) then
explode_reactor(pos)
end
if meta:get_int("HV_EU_supply") == 0 then if meta:get_int("HV_EU_supply") == 0 then
-- We did not use the power -- We did not use the power
meta:set_int("HV_EU_supply", power_sypply) meta:set_int("HV_EU_supply", power_supply)
else else
burn_time = burn_time - 1 burn_time = burn_time - 1
meta:set_int("burn_time", burn_time) meta:set_int("burn_time", burn_time)
meta:set_string("infotext", "Nuclear Reactor Core ("..math.floor(burn_time/(burn_ticks*60)*100).."%)") local percent = math.floor(burn_time / (burn_ticks * 60) * 100)
meta:set_string("infotext", "Nuclear Reactor Core ("..percent.."%)")
end end
end end
-- Burn another piece of coal -- Burn another piece of coal
if burn_time==0 then if burn_time <= 0 then
local inv = meta:get_inventory() local inv = meta:get_inventory()
local correct_fuel_count = 0 local correct_fuel_count = 0
if inv:is_empty("src") == false then if not inv:is_empty("src") then
local srclist = inv:get_list("src") local srclist = inv:get_list("src")
for _, srcstack in pairs(srclist) do for _, srcstack in pairs(srclist) do
if srcstack then if srcstack then
@ -212,7 +217,7 @@ minetest.register_abm(
end end
-- Check that the reactor is complete as well as the correct number of correct fuel -- Check that the reactor is complete as well as the correct number of correct fuel
if correct_fuel_count == 6 then if correct_fuel_count == 6 then
if check_reactor_structure(pos) == 1 then if not check_reactor_structure(pos) then
burn_time = burn_ticks * 60 burn_time = burn_ticks * 60
meta:set_int("burn_time", burn_time) meta:set_int("burn_time", burn_time)
hacky_swap_node (pos,"technic:hv_nuclear_reactor_core_active") hacky_swap_node (pos,"technic:hv_nuclear_reactor_core_active")
@ -221,9 +226,6 @@ minetest.register_abm(
srcstack:take_item() srcstack:take_item()
inv:set_stack("src", idx, srcstack) inv:set_stack("src", idx, srcstack)
end end
else
-- BOOM!!! (the reactor was compromised and it should explode after some time) TNT mod inspired??
explode_reactor(pos)
end end
else else
meta:set_int("HV_EU_supply", 0) meta:set_int("HV_EU_supply", 0)

View File

@ -92,7 +92,7 @@ if z2==1 then temp_z2=str_z2 end
minetest.register_node("technic:hv_cable"..count, { minetest.register_node("technic:hv_cable"..count, {
description = "Gigh Voltage Copper Cable", description = "High Voltage Copper Cable",
tiles = {"technic_hv_cable.png"}, tiles = {"technic_hv_cable.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),