Reactor heats coolant

This commit is contained in:
Evert Prants 2018-07-27 22:40:35 +03:00
parent 70e124f137
commit 334a78c6cc
No known key found for this signature in database
GPG Key ID: 1688DA83D222D0B5
5 changed files with 187 additions and 22 deletions

@ -6,18 +6,6 @@
-- These nodes are used as "fluids" -- These nodes are used as "fluids"
-- They do not actually exist as nodes that should be placed. -- They do not actually exist as nodes that should be placed.
minetest.register_node("elepower_nuclear:coolant", {
description = "Coolant (cold)",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = 1, coolant = 1},
tiles = {"elenuclear_cold_coolant.png"},
})
minetest.register_node("elepower_nuclear:coolant_hot", {
description = "Coolant (hot)",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = 1, coolant = 1, hot = 1},
tiles = {"elenuclear_hot_coolant.png"},
})
minetest.register_node("elepower_nuclear:heavy_water", { minetest.register_node("elepower_nuclear:heavy_water", {
description = "Heavy Water", description = "Heavy Water",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = 1, water = 1}, groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = 1, water = 1},
@ -41,3 +29,111 @@ minetest.register_node("elepower_nuclear:helium", {
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = 1, gas = 1}, groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = 1, gas = 1},
tiles = {"elenuclear_helium.png"}, tiles = {"elenuclear_helium.png"},
}) })
------------
-- Fluids --
------------
-- Cold coolant
minetest.register_node("elepower_nuclear:coolant_source", {
description = "Cold Coolant Source",
drawtype = "liquid",
tiles = {"elenuclear_cold_coolant.png"},
alpha = 200,
paramtype = "light",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
drop = "",
drowning = 1,
liquidtype = "source",
liquid_alternative_source = "elepower_nuclear:coolant_source",
liquid_alternative_flowing = "elepower_nuclear:coolant_flowing",
liquid_viscosity = 2,
post_effect_color = {a = 128, r = 36, g = 150, b = 255},
groups = {liquid = 3, coolant = 1},
sounds = default.node_sound_water_defaults(),
})
minetest.register_node("elepower_nuclear:coolant_flowing", {
description = "Cold Coolant Flowing",
drawtype = "flowingliquid",
tiles = {"elenuclear_cold_coolant.png"},
special_tiles = {"elenuclear_cold_coolant.png", "elenuclear_cold_coolant.png"},
alpha = 200,
paramtype = "light",
paramtype2 = "flowingliquid",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
drop = "",
drowning = 1,
liquidtype = "flowing",
liquid_alternative_flowing = "elepower_nuclear:coolant_flowing",
liquid_alternative_source = "elepower_nuclear:coolant_source",
liquid_viscosity = 2,
post_effect_color = {a = 128, r = 36, g = 150, b = 255},
groups = {coolant = 3, liquid = 3, not_in_creative_inventory = 1},
sounds = default.node_sound_water_defaults(),
})
-- Hot coolant
minetest.register_node("elepower_nuclear:hot_coolant_source", {
description = "Hot Coolant Source",
drawtype = "liquid",
tiles = {"elenuclear_hot_coolant.png"},
alpha = 200,
paramtype = "light",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
damage_per_second = 4 * 2,
drop = "",
drowning = 1,
liquidtype = "source",
liquid_alternative_source = "elepower_nuclear:hot_coolant_source",
liquid_alternative_flowing = "elepower_nuclear:hot_coolant_flowing",
liquid_viscosity = 2,
post_effect_color = {a = 128, r = 136, g = 100, b = 158},
groups = {liquid = 3, coolant = 1, hot = 1},
sounds = default.node_sound_water_defaults(),
})
minetest.register_node("elepower_nuclear:hot_coolant_flowing", {
description = "Hot Coolant Flowing",
drawtype = "flowingliquid",
tiles = {"elenuclear_hot_coolant.png"},
special_tiles = {"elenuclear_hot_coolant.png", "elenuclear_hot_coolant.png"},
alpha = 200,
paramtype = "light",
paramtype2 = "flowingliquid",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
damage_per_second = 4 * 2,
drop = "",
drowning = 1,
liquidtype = "flowing",
liquid_alternative_flowing = "elepower_nuclear:hot_coolant_flowing",
liquid_alternative_source = "elepower_nuclear:hot_coolant_source",
liquid_viscosity = 2,
post_effect_color = {a = 128, r = 136, g = 100, b = 158},
groups = {coolant = 3, liquid = 3, not_in_creative_inventory = 1, hot = 1},
sounds = default.node_sound_water_defaults(),
})
bucket.register_liquid("elepower_nuclear:coolant_source", "elepower_nuclear:hot_coolant_flowing",
"elepower_nuclear:bucket_coolant", "#2497ff", "Coolant (Cold)")
bucket.register_liquid("elepower_nuclear:hot_coolant_source", "elepower_nuclear:hot_coolant_flowing",
"elepower_nuclear:bucket_hot_coolant", "#88649e", "Coolant (Hot)")

@ -13,7 +13,6 @@
Hot coolant Hot coolant
..in order to keep the heat below critical. Any other detected node will either be MOLTEN or ACTIVATED (TODO) (you don't want this!) ..in order to keep the heat below critical. Any other detected node will either be MOLTEN or ACTIVATED (TODO) (you don't want this!)
Reactor core will be replaced by a molten core when the heat reaches 100%. All components and fuel will be lost! Reactor core will be replaced by a molten core when the heat reaches 100%. All components and fuel will be lost!
Do NOT run the reactor at 100% power 100% percent of the time! Keep some control rods partially inserted at all times.
]] ]]
local AREA_SIZE = 8 local AREA_SIZE = 8
@ -33,7 +32,7 @@ local function calculate_fitness(pos)
local ids = { local ids = {
c_water = minetest.get_content_id("default:water_source"), c_water = minetest.get_content_id("default:water_source"),
c_lava = minetest.get_content_id("default:lava"), c_lava = minetest.get_content_id("default:lava_source"),
} }
local excession = 0 local excession = 0
@ -220,6 +219,7 @@ local function reactor_core_timer(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local headless = false local headless = false
local fuel_reactor = 0
-- SAFEGUARD: Expect a controller to be above the core -- SAFEGUARD: Expect a controller to be above the core
local controller_pos = {x = pos.x, y = pos.y + 1, z = pos.z} local controller_pos = {x = pos.x, y = pos.y + 1, z = pos.z}
@ -270,7 +270,7 @@ local function reactor_core_timer(pos)
end end
if power_setting > 0 then if power_setting > 0 then
local fuel_reactor = fuel_after_depletion(inv) fuel_reactor = fuel_after_depletion(inv)
if fuel_reactor == 0 then if fuel_reactor == 0 then
-- Enforce zero power setting when no fuel present -- Enforce zero power setting when no fuel present
power_setting = 0 power_setting = 0
@ -292,7 +292,7 @@ local function reactor_core_timer(pos)
if heat > ceiling then if heat > ceiling then
heat = heat - 1 heat = heat - 1
else else
heat = heat + 1 heat = heat + fuel_reactor
end end
end end
elseif heat > 0 then elseif heat > 0 then
@ -306,11 +306,25 @@ local function reactor_core_timer(pos)
return false return false
end end
-- Nothing left to do in this timer, exit
if power_setting == 0 and heat == 0 then
meta:set_int("heat", heat)
meta:set_string("formspec", get_core_formspec(heat, power_setting))
return false
end
-- Expect a fluid port below the core -- Expect a fluid port below the core
-- TODO: Allow multiple fluid ports in the core's affected area
local fluid_port_pos = {x = pos.x, y = pos.y - 1, z = pos.z} local fluid_port_pos = {x = pos.x, y = pos.y - 1, z = pos.z}
local fluid_port_node = minetest.get_node_or_nil(fluid_port_pos) local fluid_port_node = minetest.get_node_or_nil(fluid_port_pos)
if fluid_port_node ~= nil and fluid_port_node.name == "elepower_nuclear:reactor_fluid_port" then if fluid_port_node ~= nil and fluid_port_node.name == "elepower_nuclear:reactor_fluid_port" then
-- TODO: Heat coolant local fpmeta = minetest.get_meta(fluid_port_pos)
if fpmeta:get_int("burst") == 0 and heat > 0 then
fpmeta:set_int("burst", 1)
minetest.get_node_timer(fluid_port_pos):start(1.0)
heat = heat - 1
end
end end
meta:set_int("heat", heat) meta:set_int("heat", heat)
@ -332,10 +346,24 @@ local function reactor_controller_timer(pos)
meta:set_int("setting", 100 - (averg / 4)) meta:set_int("setting", 100 - (averg / 4))
meta:set_string("formspec", get_controller_formspec(settings, meta:get_int("selected"))) meta:set_string("formspec", get_controller_formspec(settings, meta:get_int("selected")))
-- Ping the core
local core_pos = {x = pos.x, y = pos.y - 1, z = pos.z}
local core_node = minetest.get_node_or_nil(core_pos)
if core_node and core_node.name == "elepower_nuclear:fission_core" then
local timer = minetest.get_node_timer(core_pos)
if not timer:is_started() then
timer:start(1.0)
end
end
return false return false
end end
local function reactor_controller_manage(pos, formname, fields, sender) local function reactor_controller_manage(pos, formname, fields, sender)
if sender and sender ~= "" and minetest.is_protected(pos, sender:get_player_name()) then
return
end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local selected = meta:get_int("selected") local selected = meta:get_int("selected")
local change = false local change = false
@ -384,12 +412,40 @@ local function reactor_controller_manage(pos, formname, fields, sender)
end end
if change then if change then
minetest.get_node_timer(pos):start(1.0) minetest.get_node_timer(pos):start(0.2)
end end
end end
local function reactor_port_timer(pos) local function reactor_port_timer(pos)
return false local refresh = false
local meta = minetest.get_meta(pos)
local cool = fluid_lib.get_buffer_data(pos, "cool")
local hot = fluid_lib.get_buffer_data(pos, "hot")
local heat_burst = meta:get_int("burst")
if heat_burst > 0 then
-- Convert a bucket of cold coolant into hot coolant
local coolant = math.min(cool.amount, 1000)
if coolant > 0 and hot.amount + coolant < hot.capacity then
meta:set_int("burst", 0)
cool.amount = cool.amount - coolant
hot.amount = hot.amount + coolant
refresh = true
meta:set_string("cool_fluid", "elepower_nuclear:coolant_source")
meta:set_string("hot_fluid", "elepower_nuclear:hot_coolant_source")
meta:set_int("cool_fluid_storage", cool.amount)
meta:set_int("hot_fluid_storage", hot.amount)
end
end
meta:set_string("formspec", get_port_formspec(cool, hot))
return refresh
end end
-- Reactor Core -- Reactor Core
@ -469,20 +525,33 @@ ele.register_base_device("elepower_nuclear:reactor_fluid_port", {
on_timer = reactor_port_timer, on_timer = reactor_port_timer,
on_construct = function (pos) on_construct = function (pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
meta:set_string("cool_fluid", "elepower_nuclear:coolant_source")
meta:set_string("hot_fluid", "elepower_nuclear:hot_coolant_source")
meta:set_string("formspec", get_port_formspec()) meta:set_string("formspec", get_port_formspec())
end, end,
fluid_buffers = { fluid_buffers = {
cool = { cool = {
capacity = 16000, capacity = 16000,
accepts = {"default:water_source", "elepower_nuclear:coolant"}, accepts = {"default:water_source", "elepower_nuclear:coolant_source"},
drainable = false, drainable = false,
}, },
hot = { hot = {
capacity = 16000, capacity = 16000,
accepts = {"elepower_nuclear:coolant_hot"}, accepts = {"elepower_nuclear:hot_coolant_source"},
drainable = true, drainable = true,
} }
}, },
}) })
-- Load reactor cores
minetest.register_lbm({
label = "Refresh Reactors on load",
name = "elepower_nuclear:fission_core",
nodenames = {"elepower_nuclear:fission_core"},
run_at_every_load = true,
action = function (pos)
minetest.get_node_timer(pos):start(1.0)
end,
})

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB