diff --git a/elepower_machines/machines/bases/fluidgenerator.lua b/elepower_machines/machines/bases/fluidgenerator.lua index 2401841..942399b 100644 --- a/elepower_machines/machines/bases/fluidgenerator.lua +++ b/elepower_machines/machines/bases/fluidgenerator.lua @@ -1,5 +1,5 @@ -local function get_formspec(power, percent, buffer) +local function get_formspec_default(power, percent, buffer) return "size[8,8.5]".. default.gui_bg.. default.gui_bg_img.. @@ -32,6 +32,13 @@ function ele.register_fluid_generator(nodename, nodedef) break end + -- Allow for custom formspec + local get_formspec = get_formspec_default + if nodedef.get_formspec then + get_formspec = nodedef.get_formspec + nodedef.get_formspec = nil + end + local defaults = { groups = { fluid_container = 1, diff --git a/elepower_machines/machines/bases/generator.lua b/elepower_machines/machines/bases/generator.lua index 9ba3e6e..2dbc8fd 100644 --- a/elepower_machines/machines/bases/generator.lua +++ b/elepower_machines/machines/bases/generator.lua @@ -1,5 +1,5 @@ -local function get_formspec(power, percent) +local function get_formspec_default(power, percent) return "size[8,8.5]".. default.gui_bg.. default.gui_bg_img.. @@ -26,6 +26,13 @@ function elepm.register_fuel_generator(nodename, nodedef) nodedef.groups["tubedevice"] = 1 nodedef.groups["tubedevice_receiver"] = 1 + -- Allow for custom formspec + local get_formspec = get_formspec_default + if nodedef.get_formspec then + get_formspec = nodedef.get_formspec + nodedef.get_formspec = nil + end + nodedef.on_timer = function (pos, elapsed) local meta = minetest.get_meta(pos) diff --git a/elepower_machines/machines/bases/storage.lua b/elepower_machines/machines/bases/storage.lua index acbe178..bd04646 100644 --- a/elepower_machines/machines/bases/storage.lua +++ b/elepower_machines/machines/bases/storage.lua @@ -1,5 +1,5 @@ -local function get_formspec(power) +local function get_formspec_default(power) return "size[8,8.5]".. default.gui_bg.. default.gui_bg_img.. @@ -42,6 +42,13 @@ function elepm.register_storage(nodename, nodedef) nodedef.can_dig = can_dig + -- Allow for custom formspec + local get_formspec = get_formspec_default + if nodedef.get_formspec then + get_formspec = nodedef.get_formspec + nodedef.get_formspec = nil + end + nodedef.on_timer = function (pos, elapsed) local meta = minetest.get_meta(pos) local refresh = false diff --git a/elepower_machines/machines/steam_turbine.lua b/elepower_machines/machines/steam_turbine.lua index f74da2d..69738ec 100644 --- a/elepower_machines/machines/steam_turbine.lua +++ b/elepower_machines/machines/steam_turbine.lua @@ -1,7 +1,19 @@ +local function get_formspec(power, percent, buffer) + return "size[8,8.5]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + ele.formspec.power_meter(power).. + ele.formspec.fluid_bar(7, 0, buffer).. + "list[current_player;main;0,4.25;8,1;]".. + "list[current_player;main;0,5.5;8,3;8]".. + default.get_hotbar_bg(0, 4.25) +end + ele.register_fluid_generator("elepower_machines:steam_turbine", { description = "Steam Turbine", - ele_usage = 64, + ele_usage = 128, tiles = { "elepower_machine_top.png^elepower_power_port.png", "elepower_machine_base.png", "elepower_machine_side.png", "elepower_machine_side.png", "elepower_turbine_side.png", "elepower_turbine_side.png", @@ -22,4 +34,6 @@ ele.register_fluid_generator("elepower_machines:steam_turbine", { }, tube = false, ele_no_automatic_ports = true, + fuel_burn_time = 2, + get_formspec = get_formspec, }) diff --git a/elepower_nuclear/machines/heat_exchanger.lua b/elepower_nuclear/machines/heat_exchanger.lua new file mode 100644 index 0000000..320adc0 --- /dev/null +++ b/elepower_nuclear/machines/heat_exchanger.lua @@ -0,0 +1,100 @@ + +local function get_formspec(heat, cold, water, steam) + return "size[8,8.5]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + ele.formspec.fluid_bar(0, 0, heat).. + ele.formspec.fluid_bar(1, 0, cold).. + "image[3.5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]".. + ele.formspec.fluid_bar(6, 0, water).. + ele.formspec.fluid_bar(7, 0, steam).. + "list[context;dst;5,1;1,1;]".. + "list[current_player;main;0,4.25;8,1;]".. + "list[current_player;main;0,5.5;8,3;8]".. + "listring[context;dst]".. + "listring[current_player;main]".. + default.get_hotbar_bg(0, 4.25) +end + +local function heat_exchanger_timer(pos) + local meta = minetest.get_meta(pos) + local change = false + + local heat = fluid_lib.get_buffer_data(pos, "heat") + local cold = fluid_lib.get_buffer_data(pos, "cold") + local water = fluid_lib.get_buffer_data(pos, "water") + local steam = fluid_lib.get_buffer_data(pos, "steam") + + -- See if we have enough hot coolant + if heat.amount >= 1000 then + local water_convert = math.min(water.amount, 1000) + if steam.amount + water_convert > steam.capacity then + water_convert = steam.capacity - steam.amount + end + + if water_convert > 0 then + if cold.amount + 1000 < cold.capacity then + -- Conversion + heat.amount = heat.amount - 1000 + cold.amount = cold.amount + 1000 + + water.amount = water.amount - water_convert + steam.amount = steam.amount + water_convert + + change = true + end + end + end + + if change then + meta:set_string("cold_fluid", "elepower_nuclear:coolant_source") + meta:set_string("steam_fluid", "elepower_dynamics:steam") + + meta:set_int("heat_fluid_storage", heat.amount) + meta:set_int("cold_fluid_storage", cold.amount) + + meta:set_int("water_fluid_storage", water.amount) + meta:set_int("steam_fluid_storage", steam.amount) + end + + meta:set_string("formspec", get_formspec(heat, cold, water, steam)) + + return false +end + +ele.register_machine("elepower_nuclear:heat_exchanger", { + description = "Shielded Heat Exchanger\nFor use in nuclear power plants", + tiles = { + "elenuclear_machine_top.png", "elepower_lead_block.png", "elenuclear_machine_side.png", + "elenuclear_machine_side.png", "elenuclear_machine_side.png", "elenuclear_heat_exchanger.png", + }, + groups = {cracky = 3, fluid_container = 1}, + fluid_buffers = { + heat = { + capacity = 8000, + accepts = {"elepower_nuclear:hot_coolant_source"}, + drainable = false, + }, + cold = { + capacity = 8000, + accepts = {"elepower_nuclear:coolant_source"}, + drainable = true, + }, + water = { + capacity = 16000, + accepts = {"default:water_source"}, + drainable = false, + }, + steam = { + capacity = 16000, + accepts = {"elepower_dynamics:steam"}, + drainable = true, + }, + }, + on_construct = function (pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", get_formspec()) + end, + on_timer = heat_exchanger_timer, +}) diff --git a/elepower_nuclear/machines/init.lua b/elepower_nuclear/machines/init.lua index 25019a9..f3af94d 100644 --- a/elepower_nuclear/machines/init.lua +++ b/elepower_nuclear/machines/init.lua @@ -3,4 +3,5 @@ local mp = elenuclear.modpath .. "/machines/" dofile(mp.."enrichment_plant.lua") dofile(mp.."fission_reactor.lua") +dofile(mp.."heat_exchanger.lua") diff --git a/elepower_nuclear/textures/elenuclear_heat_exchanger.png b/elepower_nuclear/textures/elenuclear_heat_exchanger.png index 73ab9ab..8b848d4 100644 Binary files a/elepower_nuclear/textures/elenuclear_heat_exchanger.png and b/elepower_nuclear/textures/elenuclear_heat_exchanger.png differ