Reworked for a new power model
This commit is contained in:
parent
d85d1b2b15
commit
bb42118f3d
@ -22,61 +22,33 @@ local MP = minetest.get_modpath("techage")
|
||||
local I,_ = dofile(MP.."/intllib.lua")
|
||||
|
||||
local STANDBY_TICKS = 4
|
||||
local COUNTDOWN_TICKS = 4
|
||||
local CYCLE_TIME = 2
|
||||
local POWER_CONSUMPTION = 10
|
||||
local POWER_MAX_LOAD = 300
|
||||
|
||||
local POWER_HYSTERESIS = 10
|
||||
local Power = techage.ElectricCable
|
||||
local generator = techage.generator
|
||||
|
||||
-- called from pipe network
|
||||
local function valid_power_dir(pos, power_dir, in_dir)
|
||||
return power_dir == in_dir
|
||||
end
|
||||
|
||||
local function formspec(self, pos, mem)
|
||||
return "size[5,3]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"image[0,0.5;1,2;"..generator.formspec_battery_capa(POWER_MAX_LOAD, mem.capa)..
|
||||
"image[0,0.5;1,2;"..techage.power.formspec_power_bar(POWER_MAX_LOAD, mem.capa).."]"..
|
||||
"label[0.2,2.5;Load]"..
|
||||
"button[1.1,1;1.8,1;update;"..I("Update").."]"..
|
||||
"image_button[3,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
|
||||
"image[4,0.5;1,2;"..generator.formspec_battery_load(mem)..
|
||||
"image[4,0.5;1,2;"..techage.power.formspec_load_bar(mem.charging).."]"..
|
||||
"label[4.2,2.5;Flow]"
|
||||
end
|
||||
|
||||
local function turn_off(pos, mem)
|
||||
generator.turn_power_on(pos, 0)
|
||||
mem.charging = false
|
||||
mem.unloading = false
|
||||
end
|
||||
|
||||
local function switch_to_unloading(pos, mem)
|
||||
if not mem.unloading then
|
||||
mem.unloading = true
|
||||
mem.charging = false
|
||||
generator.turn_power_on(pos, 2 * POWER_CONSUMPTION)
|
||||
end
|
||||
end
|
||||
|
||||
local function switch_to_charging(pos, mem)
|
||||
if mem.sum > POWER_CONSUMPTION and not mem.charging then
|
||||
mem.charging = true
|
||||
mem.unloading = false
|
||||
generator.turn_power_on(pos, -POWER_CONSUMPTION)
|
||||
end
|
||||
mem.delayed_call = false
|
||||
end
|
||||
|
||||
local function start_node(pos, mem, state)
|
||||
turn_off(pos, mem)
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
|
||||
local function stop_node(pos, mem, state)
|
||||
turn_off(pos, mem)
|
||||
mem.charging = nil
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
@ -88,51 +60,75 @@ local State = techage.NodeStates:new({
|
||||
stop_node = stop_node,
|
||||
})
|
||||
|
||||
--
|
||||
-- Power network callbacks
|
||||
--
|
||||
|
||||
-- Pass1: Power balance calculation
|
||||
local function on_power_pass1(pos, mem)
|
||||
print("on_power_pass1", mem.charging)
|
||||
if State:is_active(mem) and mem.capa > POWER_HYSTERESIS then
|
||||
mem.correction = POWER_CONSUMPTION -- uncharging
|
||||
else
|
||||
mem.correction = 0
|
||||
end
|
||||
return -mem.correction
|
||||
end
|
||||
|
||||
-- Pass2: Power balance adjustment
|
||||
local function on_power_pass2(pos, mem, sum)
|
||||
print("on_power_pass2", mem.charging, sum)
|
||||
if State:is_active(mem) then
|
||||
if sum > mem.correction + POWER_CONSUMPTION and
|
||||
mem.capa < POWER_MAX_LOAD - POWER_HYSTERESIS then
|
||||
mem.charging = true
|
||||
return mem.correction + POWER_CONSUMPTION
|
||||
elseif sum > mem.correction then
|
||||
mem.charging = nil -- turn off
|
||||
return mem.correction
|
||||
elseif sum > -POWER_CONSUMPTION and mem.capa > POWER_HYSTERESIS then
|
||||
mem.charging = false -- uncharging
|
||||
return 0
|
||||
else
|
||||
mem.charging = nil -- turn off
|
||||
return mem.correction
|
||||
end
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
-- Pass3: Power balance result
|
||||
local function on_power_pass3(pos, mem, sum)
|
||||
print("on_power_pass3", mem.charging, sum)
|
||||
mem.power_result = sum
|
||||
end
|
||||
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
print("node_timer", mem.charging, mem.capa)
|
||||
if State:is_active(mem) then
|
||||
mem.capa = mem.capa or 0
|
||||
if mem.charging then
|
||||
if mem.charging == true then
|
||||
if mem.capa < POWER_MAX_LOAD then
|
||||
mem.capa = mem.capa + 1
|
||||
else
|
||||
turn_off(pos, mem)
|
||||
mem.charging = nil -- turn off
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
elseif mem.unloading then
|
||||
elseif mem.charging == false then -- uncharging
|
||||
if mem.capa > 0 then
|
||||
mem.capa = mem.capa - 2
|
||||
mem.capa = mem.capa - 1
|
||||
else
|
||||
turn_off(pos, mem)
|
||||
mem.charging = nil -- turn off
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
return State:is_active(mem)
|
||||
end
|
||||
|
||||
local function turn_power_on(pos, in_dir, sum)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if State:is_active(mem) then
|
||||
mem.capa = mem.capa or 0
|
||||
mem.sum = sum
|
||||
if mem.unloading then
|
||||
if sum < 0 then
|
||||
turn_off(pos, mem)
|
||||
elseif sum > 2 * POWER_CONSUMPTION then
|
||||
turn_off(pos, mem)
|
||||
end
|
||||
elseif mem.charging then
|
||||
if sum < 0 then
|
||||
turn_off(pos, mem)
|
||||
end
|
||||
else -- turned off
|
||||
if sum > POWER_CONSUMPTION and not mem.delayed_call then
|
||||
minetest.after(math.random(1.2, 5.0),
|
||||
switch_to_charging, pos, mem)
|
||||
mem.delayed_call = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_receive_fields(pos, formname, fields, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
@ -164,7 +160,7 @@ local function set_capa(pos, oldnode, digger, capa)
|
||||
local node = ItemStack(oldnode.name)
|
||||
local meta = node:get_meta()
|
||||
meta:set_int("capa", capa or 0)
|
||||
local text = I("TA3 Akku Box").." ("..techage.percent(POWER_MAX_LOAD, capa).." %)"
|
||||
local text = I("TA3 Akku Box").." ("..techage.power.percent(POWER_MAX_LOAD, capa).." %)"
|
||||
meta:set_string("description", text)
|
||||
local inv = minetest.get_inventory({type="player", name=digger:get_player_name()})
|
||||
local left_over = inv:add_item("main", node)
|
||||
@ -184,24 +180,12 @@ minetest.register_node("techage:ta3_akku", {
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
techage = {
|
||||
turn_on = turn_power_on,
|
||||
read_power_consumption = generator.read_power_consumption,
|
||||
power_network = Power,
|
||||
power_side = "R",
|
||||
},
|
||||
|
||||
on_construct = tubelib2.init_mem,
|
||||
|
||||
after_place_node = function(pos, placer, itemstack)
|
||||
local mem = generator.after_place_node(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
State:node_init(pos, mem, "")
|
||||
mem.charging = false
|
||||
mem.unloading = false
|
||||
mem.capa = get_capa(itemstack)
|
||||
on_rightclick(pos)
|
||||
end,
|
||||
@ -209,22 +193,32 @@ minetest.register_node("techage:ta3_akku", {
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
generator.after_dig_node(pos, oldnode)
|
||||
set_capa(pos, oldnode, digger, mem.capa)
|
||||
end,
|
||||
|
||||
after_tube_update = generator.after_tube_update,
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
Power:add_secondary_node_names({"techage:ta3_akku"})
|
||||
techage.power.register_node({"techage:ta3_akku"}, {
|
||||
on_power_pass1 = on_power_pass1,
|
||||
on_power_pass2 = on_power_pass2,
|
||||
on_power_pass3 = on_power_pass3,
|
||||
conn_sides = {"R"},
|
||||
power_network = Power,
|
||||
})
|
||||
|
||||
techage.register_help_page(I("TA3 Akku Box"),
|
||||
I([[Used to store electrical energy.
|
||||
Charged in about 10 min,
|
||||
provides energy for 5 min.]]), "techage:ta3_akku")
|
||||
provides energy for 10 min.]]), "techage:ta3_akku")
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
|
@ -21,17 +21,10 @@ local M = minetest.get_meta
|
||||
local MP = minetest.get_modpath("techage")
|
||||
local I,_ = dofile(MP.."/intllib.lua")
|
||||
|
||||
local POWER_CONSUMPTION = 2
|
||||
|
||||
local Pipe = techage.SteamPipe
|
||||
local consumer = techage.consumer
|
||||
|
||||
local function valid_power_dir(pos, power_dir, in_dir)
|
||||
return power_dir == in_dir
|
||||
end
|
||||
|
||||
local function turn_on_clbk(pos, in_dir, sum)
|
||||
return true
|
||||
local function turn_on(pos, mem, in_dir, on)
|
||||
return on
|
||||
end
|
||||
|
||||
minetest.register_node("techage:coalboiler_base", {
|
||||
@ -44,21 +37,7 @@ minetest.register_node("techage:coalboiler_base", {
|
||||
fixed = {-13/32, -16/32, -13/32, 13/32, 16/32, 13/32},
|
||||
},
|
||||
|
||||
techage = {
|
||||
turn_on = turn_on_clbk,
|
||||
read_power_consumption = consumer.read_power_consumption,
|
||||
power_network = Pipe,
|
||||
power_side = "F",
|
||||
valid_power_dir = valid_power_dir,
|
||||
},
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local mem = consumer.after_place_node(pos, placer)
|
||||
mem.power_consumption = POWER_CONSUMPTION
|
||||
end,
|
||||
|
||||
after_tube_update = consumer.after_tube_update,
|
||||
after_dig_node = consumer.after_dig_node,
|
||||
on_construct = tubelib2.init_mem,
|
||||
|
||||
drop = "",
|
||||
paramtype2 = "facedir",
|
||||
@ -68,8 +47,11 @@ minetest.register_node("techage:coalboiler_base", {
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:coalboiler_base"})
|
||||
techage.power.register_node({"techage:coalboiler_base"}, {
|
||||
turn_on = turn_on,
|
||||
conn_sides = {"F"},
|
||||
power_network = Pipe,
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
|
@ -25,13 +25,10 @@ local CYCLE_TIME = 4
|
||||
local STANDBY_TICKS = 2
|
||||
local COUNTDOWN_TICKS = 2
|
||||
local HEAT_STEP = 10
|
||||
local WATER_CONSUMPTION = 0.5
|
||||
local WATER_CONSUMPTION = 0.1
|
||||
local MAX_WATER = 10
|
||||
local POWER_CAPACITY = 30
|
||||
|
||||
local Pipe = techage.SteamPipe
|
||||
local generator = techage.generator
|
||||
|
||||
|
||||
local Water = {
|
||||
["bucket:bucket_river_water"] = true,
|
||||
@ -41,6 +38,7 @@ local Water = {
|
||||
|
||||
local function formspec(self, pos, mem)
|
||||
local temp = mem.temperature or 20
|
||||
local bar = mem.running and 3 or 0
|
||||
return "size[8,7]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
@ -53,7 +51,7 @@ local function formspec(self, pos, mem)
|
||||
"image[1,1.6;1,1;techage_form_mask.png]"..
|
||||
"image[2,0.5;1,2;techage_form_temp_bg.png^[lowpart:"..
|
||||
temp..":techage_form_temp_fg.png]"..
|
||||
"image[7,0.5;1,2;"..generator.formspec_level(mem, mem.power_result)..
|
||||
"image[7,0.5;1,2;"..techage.power.formspec_power_bar(10, bar).."]"..
|
||||
"image_button[6,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
|
||||
"button[3,1.5;2,1;update;"..I("Update").."]"..
|
||||
"list[current_player;main;0,3;8,4;]"..
|
||||
@ -62,20 +60,19 @@ local function formspec(self, pos, mem)
|
||||
default.get_hotbar_bg(0, 3)
|
||||
end
|
||||
|
||||
local function valid_power_dir(pos, power_dir, in_dir)
|
||||
return power_dir == in_dir
|
||||
end
|
||||
|
||||
local function can_start(pos, mem, state)
|
||||
return mem.temperature and mem.temperature > 80
|
||||
end
|
||||
|
||||
local function start_node(pos, mem, state)
|
||||
generator.turn_power_on(pos, POWER_CAPACITY)
|
||||
local out_dir = techage.power.side_to_outdir(pos, "F")
|
||||
mem.running = techage.power.start_line_node(pos, out_dir, "techage:turbine", true)
|
||||
end
|
||||
|
||||
local function stop_node(pos, mem, state)
|
||||
generator.turn_power_on(pos, 0)
|
||||
local out_dir = techage.power.side_to_outdir(pos, "F")
|
||||
techage.power.start_line_node(pos, out_dir, "techage:turbine_on", false)
|
||||
mem.running = false
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
@ -122,7 +119,7 @@ end
|
||||
local function steaming(pos, mem, temp)
|
||||
mem.water_level = math.max((mem.water_level or 0) - WATER_CONSUMPTION, 0)
|
||||
if temp >= 80 then
|
||||
if mem.power_result > 0 then
|
||||
if mem.running then
|
||||
State:keep_running(pos, mem, COUNTDOWN_TICKS)
|
||||
else
|
||||
State:fault(pos, mem)
|
||||
@ -142,18 +139,6 @@ local function node_timer(pos, elapsed)
|
||||
return mem.temperature > 20
|
||||
end
|
||||
|
||||
local function turn_power_on(pos, in_dir, sum)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
-- store result for formspec
|
||||
mem.power_result = sum
|
||||
if State:is_active(mem) and sum <= 0 then
|
||||
State:fault(pos, mem)
|
||||
-- No automatic turn on
|
||||
mem.power_capacity = 0
|
||||
end
|
||||
M(pos):set_string("formspec", formspec(State, pos, mem))
|
||||
end
|
||||
|
||||
local function on_receive_fields(pos, formname, fields, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return
|
||||
@ -162,6 +147,9 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
State:state_button_event(pos, mem, fields)
|
||||
|
||||
if fields.update then
|
||||
if mem.temperature > 20 then
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
M(pos):set_string("formspec", formspec(State, pos, mem))
|
||||
end
|
||||
end
|
||||
@ -242,29 +230,15 @@ minetest.register_node("techage:coalboiler_top", {
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
|
||||
techage = {
|
||||
turn_on = turn_power_on,
|
||||
read_power_consumption = generator.read_power_consumption,
|
||||
power_network = Pipe,
|
||||
trigger_boiler = function(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.fire_trigger = true
|
||||
if not minetest.get_node_timer(pos):is_started() then
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
end,
|
||||
power_side = "F",
|
||||
valid_power_dir = valid_power_dir,
|
||||
},
|
||||
|
||||
on_construct = function(pos)
|
||||
tubelib2.init_mem(pos)
|
||||
local inv = M(pos):get_inventory()
|
||||
inv:set_size('water', 1)
|
||||
inv:set_size('input', 1)
|
||||
end,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local mem = generator.after_place_node(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
State:node_init(pos, mem, "")
|
||||
local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
|
||||
if node.name == "techage:coalboiler_base" then
|
||||
@ -274,15 +248,20 @@ minetest.register_node("techage:coalboiler_top", {
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
generator.after_dig_node(pos, oldnode)
|
||||
end,
|
||||
|
||||
after_tube_update = generator.after_tube_update,
|
||||
|
||||
on_metadata_inventory_put = function(pos)
|
||||
minetest.after(0.5, move_to_water, pos)
|
||||
end,
|
||||
|
||||
trigger_boiler = function(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.fire_trigger = true
|
||||
if not minetest.get_node_timer(pos):is_started() then
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
end,
|
||||
|
||||
drop = "",
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=1},
|
||||
@ -291,9 +270,11 @@ minetest.register_node("techage:coalboiler_top", {
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
})
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:coalboiler_top"})
|
||||
techage.power.register_node({"techage:coalboiler_top"}, {
|
||||
conn_sides = {"F"},
|
||||
power_network = Pipe,
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:coalboiler_top",
|
||||
recipe = {
|
||||
|
@ -21,10 +21,7 @@ local M = minetest.get_meta
|
||||
local MP = minetest.get_modpath("techage")
|
||||
local I,_ = dofile(MP.."/intllib.lua")
|
||||
|
||||
local POWER_CONSUMPTION = 2
|
||||
|
||||
local Power = techage.SteamPipe
|
||||
local consumer = techage.consumer
|
||||
|
||||
local function swap_node(pos, name)
|
||||
local node = minetest.get_node(pos)
|
||||
@ -36,24 +33,15 @@ local function swap_node(pos, name)
|
||||
end
|
||||
|
||||
-- called from pipe network
|
||||
local function valid_power_dir(pos, power_dir, in_dir)
|
||||
return power_dir == in_dir or power_dir == tubelib2.Turn180Deg[in_dir]
|
||||
end
|
||||
|
||||
-- called from pipe network
|
||||
local function turn_on(pos, in_dir, sum)
|
||||
if techage.power.start_dedicated_node(pos, in_dir, "techage:coalboiler_base", sum) then
|
||||
if sum > 0 then
|
||||
swap_node(pos, "techage:cooler_on")
|
||||
else
|
||||
swap_node(pos, "techage:cooler")
|
||||
end
|
||||
return true
|
||||
local function turn_on(pos, mem, dir, on)
|
||||
on = techage.power.start_line_node(pos, dir, "techage:coalboiler_base", on)
|
||||
if on then
|
||||
swap_node(pos, "techage:cooler_on")
|
||||
else
|
||||
swap_node(pos, "techage:cooler")
|
||||
end
|
||||
return false
|
||||
end
|
||||
return on
|
||||
end
|
||||
|
||||
minetest.register_node("techage:cooler", {
|
||||
description = I("TA3 Cooler"),
|
||||
@ -66,22 +54,9 @@ minetest.register_node("techage:cooler", {
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_cooler.png",
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_cooler.png",
|
||||
},
|
||||
techage = {
|
||||
turn_on = turn_on,
|
||||
read_power_consumption = consumer.read_power_consumption,
|
||||
power_network = Power,
|
||||
power_side = "L",
|
||||
valid_power_dir = valid_power_dir,
|
||||
},
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local mem = consumer.after_place_node(pos, placer)
|
||||
mem.power_consumption = POWER_CONSUMPTION
|
||||
end,
|
||||
on_construct = tubelib2.init_mem,
|
||||
|
||||
after_tube_update = consumer.after_tube_update,
|
||||
after_dig_node = consumer.after_dig_node,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -118,17 +93,7 @@ minetest.register_node("techage:cooler_on", {
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_cooler.png",
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_cooler.png",
|
||||
},
|
||||
techage = {
|
||||
turn_on = turn_on,
|
||||
read_power_consumption = consumer.read_power_consumption,
|
||||
power_network = Power,
|
||||
power_side = "L",
|
||||
valid_power_dir = valid_power_dir,
|
||||
},
|
||||
|
||||
after_tube_update = consumer.after_tube_update,
|
||||
after_dig_node = consumer.after_dig_node,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
diggable = false,
|
||||
@ -137,6 +102,12 @@ minetest.register_node("techage:cooler_on", {
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
techage.power.register_node({"techage:cooler", "techage:cooler_on"}, {
|
||||
turn_on = turn_on,
|
||||
conn_sides = {"L", "R"},
|
||||
power_network = Power,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:cooler",
|
||||
recipe = {
|
||||
@ -146,9 +117,6 @@ minetest.register_craft({
|
||||
},
|
||||
})
|
||||
|
||||
Power:add_secondary_node_names({"techage:cooler", "techage:cooler_on"})
|
||||
|
||||
|
||||
techage.register_help_page(I("TA3 Cooler"),
|
||||
I([[Part of the Coal Power Station.
|
||||
Has to be placed in the steam circulation
|
||||
|
@ -16,8 +16,6 @@
|
||||
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
-- Techage Related Data
|
||||
local TRD = function(pos) return (minetest.registered_nodes[minetest.get_node(pos).name] or {}).techage end
|
||||
|
||||
-- Load support for intllib.
|
||||
local MP = minetest.get_modpath("techage")
|
||||
@ -42,9 +40,9 @@ end
|
||||
local function node_timer(pos, elapsed)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.running then
|
||||
local trd = TRD({x=pos.x, y=pos.y+2, z=pos.z})
|
||||
if trd and trd.trigger_boiler then
|
||||
trd.trigger_boiler({x=pos.x, y=pos.y+2, z=pos.z})
|
||||
local ndef = minetest.registered_nodes[minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}).name]
|
||||
if ndef and ndef.trigger_boiler then
|
||||
ndef.trigger_boiler({x=pos.x, y=pos.y+2, z=pos.z})
|
||||
end
|
||||
mem.burn_cycles = (mem.burn_cycles or 0) - 1
|
||||
if mem.burn_cycles <= 0 then
|
||||
|
@ -16,8 +16,6 @@
|
||||
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
-- Techage Related Data
|
||||
local TRD = function(pos) return (minetest.registered_nodes[minetest.get_node(pos).name] or {}).techage end
|
||||
|
||||
-- Load support for intllib.
|
||||
local MP = minetest.get_modpath("techage")
|
||||
@ -26,17 +24,16 @@ local I,_ = dofile(MP.."/intllib.lua")
|
||||
local STANDBY_TICKS = 4
|
||||
local COUNTDOWN_TICKS = 4
|
||||
local CYCLE_TIME = 8
|
||||
local POWER_CAPACITY = 50
|
||||
local POWER_CAPACITY = 75
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local generator = techage.generator
|
||||
|
||||
local function formspec(self, pos, mem)
|
||||
return "size[8,7]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"image[6,0.5;1,2;"..generator.formspec_level(mem, mem.power_result)..
|
||||
"image[6,0.5;1,2;"..techage.power.formspec_power_bar(POWER_CAPACITY, mem.power_result).."]"..
|
||||
"image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
|
||||
"button[2,1.5;2,1;update;"..I("Update").."]"..
|
||||
"list[current_player;main;0,3;8,4;]"..
|
||||
@ -50,13 +47,11 @@ local function turbine_running(pos)
|
||||
end
|
||||
|
||||
local function start_node(pos, mem, state)
|
||||
generator.turn_power_on(pos, POWER_CAPACITY)
|
||||
mem.techage_state = techage.RUNNING
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
|
||||
local function stop_node(pos, mem, state)
|
||||
mem.techage_state = techage.STOPPED
|
||||
generator.turn_power_on(pos, 0)
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
@ -70,12 +65,30 @@ local State = techage.NodeStates:new({
|
||||
stop_node = stop_node,
|
||||
})
|
||||
|
||||
-- Pass1: Power balance calculation
|
||||
local function on_power_pass1(pos, mem)
|
||||
if State:is_active(mem) then
|
||||
return -POWER_CAPACITY
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-- Pass2: Power balance adjustment
|
||||
local function on_power_pass2(pos, mem, sum)
|
||||
return 0
|
||||
end
|
||||
|
||||
-- Pass3: Power balance result
|
||||
local function on_power_pass3(pos, mem, sum)
|
||||
mem.power_result = sum
|
||||
end
|
||||
|
||||
local function distibuting(pos, mem)
|
||||
if mem.power_result > 0 then
|
||||
State:keep_running(pos, mem, COUNTDOWN_TICKS)
|
||||
else
|
||||
State:fault(pos, mem)
|
||||
generator.turn_power_on(pos, 0)
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
end
|
||||
|
||||
@ -85,27 +98,11 @@ local function node_timer(pos, elapsed)
|
||||
distibuting(pos, mem)
|
||||
else
|
||||
State:fault(pos, mem)
|
||||
generator.turn_power_on(pos, 0)
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
return State:is_active(mem)
|
||||
end
|
||||
|
||||
local function valid_power_dir(pos, power_dir, in_dir)
|
||||
return power_dir == in_dir
|
||||
end
|
||||
|
||||
local function turn_power_on(pos, in_dir, sum)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
-- store result for formspec
|
||||
mem.power_result = sum
|
||||
if State:is_active(mem) and sum <= 0 then
|
||||
State:fault(pos, mem)
|
||||
-- No automatic turn on
|
||||
mem.power_capacity = 0
|
||||
end
|
||||
M(pos):set_string("formspec", formspec(State, pos, mem))
|
||||
end
|
||||
|
||||
local function on_receive_fields(pos, formname, fields, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return
|
||||
@ -134,25 +131,19 @@ minetest.register_node("techage:generator", {
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_generator.png",
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_generator.png^[transformFX]",
|
||||
},
|
||||
techage = {
|
||||
turn_on = turn_power_on,
|
||||
read_power_consumption = generator.read_power_consumption,
|
||||
power_network = Cable,
|
||||
power_side = "R",
|
||||
},
|
||||
|
||||
on_construct = tubelib2.init_mem,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local mem = generator.after_place_node(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
State:node_init(pos, mem, "")
|
||||
on_rightclick(pos)
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
generator.after_dig_node(pos, oldnode)
|
||||
end,
|
||||
|
||||
after_tube_update = generator.after_tube_update,
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
@ -194,23 +185,12 @@ minetest.register_node("techage:generator_on", {
|
||||
},
|
||||
},
|
||||
},
|
||||
techage = {
|
||||
turn_on = turn_power_on,
|
||||
read_power_consumption = generator.read_power_consumption,
|
||||
power_network = Cable,
|
||||
power_side = "R",
|
||||
},
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
generator.after_dig_node(pos, oldnode)
|
||||
end,
|
||||
|
||||
after_tube_update = generator.after_tube_update,
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
|
||||
drop = "",
|
||||
paramtype2 = "facedir",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
diggable = false,
|
||||
@ -228,7 +208,13 @@ minetest.register_craft({
|
||||
},
|
||||
})
|
||||
|
||||
Cable:add_secondary_node_names({"techage:generator", "techage:generator_on"})
|
||||
techage.power.register_node({"techage:generator", "techage:generator_on"}, {
|
||||
on_power_pass1 = on_power_pass1,
|
||||
on_power_pass2 = on_power_pass2,
|
||||
on_power_pass3 = on_power_pass3,
|
||||
conn_sides = {"R"},
|
||||
power_network = Cable,
|
||||
})
|
||||
|
||||
techage.register_help_page(I("TA3 Generator"),
|
||||
I([[Part of the Coal Power Station.
|
||||
@ -236,4 +222,4 @@ Has to be placed side by side
|
||||
with the TA3 Turbine.
|
||||
Connect the Generator with your TA3 machines
|
||||
by means of Electric Cables and Junction Boxes
|
||||
(see TA3 Coal Power Station)]]), "techage:generator")
|
||||
(see TA3 Coal Power Station)]]), "techage:generator")
|
||||
|
@ -21,10 +21,7 @@ local M = minetest.get_meta
|
||||
local MP = minetest.get_modpath("techage")
|
||||
local I,_ = dofile(MP.."/intllib.lua")
|
||||
|
||||
local POWER_CONSUMPTION = 15
|
||||
|
||||
local Power = techage.SteamPipe
|
||||
local consumer = techage.consumer
|
||||
|
||||
local function swap_node(pos, name)
|
||||
local node = minetest.get_node(pos)
|
||||
@ -60,10 +57,14 @@ local function stop_sound(pos)
|
||||
end
|
||||
|
||||
-- called from pipe network
|
||||
local function turn_on(pos, dir, sum)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
local res = techage.power.start_dedicated_node(pos, 6, "techage:cooler", sum)
|
||||
if sum > 0 and res then
|
||||
local function turn_on(pos, mem, dir, on)
|
||||
if on then
|
||||
on = techage.power.start_line_node(pos, 6, "techage:cooler", true)
|
||||
else
|
||||
techage.power.start_line_node(pos, 6, "techage:cooler_on", false)
|
||||
end
|
||||
|
||||
if on then
|
||||
swap_node(pos, "techage:turbine_on")
|
||||
mem.running = true
|
||||
play_sound(pos)
|
||||
@ -72,9 +73,9 @@ local function turn_on(pos, dir, sum)
|
||||
mem.running = false
|
||||
stop_sound(pos)
|
||||
end
|
||||
return on
|
||||
end
|
||||
|
||||
|
||||
minetest.register_node("techage:turbine", {
|
||||
description = I("TA3 Turbine"),
|
||||
tiles = {
|
||||
@ -86,22 +87,7 @@ minetest.register_node("techage:turbine", {
|
||||
"techage_filling_ta3.png^techage_appl_turbine.png^techage_frame_ta3.png",
|
||||
"techage_filling_ta3.png^techage_appl_turbine.png^techage_frame_ta3.png",
|
||||
},
|
||||
techage = {
|
||||
turn_on = turn_on,
|
||||
read_power_consumption = consumer.read_power_consumption,
|
||||
power_network = Power,
|
||||
power_side = "L",
|
||||
valid_power_dir = valid_power_dir,
|
||||
},
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local mem = consumer.after_place_node(pos, placer)
|
||||
mem.power_consumption = POWER_CONSUMPTION
|
||||
mem.running = false
|
||||
end,
|
||||
|
||||
after_tube_update = consumer.after_tube_update,
|
||||
after_dig_node = consumer.after_dig_node,
|
||||
on_construct = tubelib2.init_mem,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
@ -138,17 +124,7 @@ minetest.register_node("techage:turbine_on", {
|
||||
},
|
||||
},
|
||||
},
|
||||
techage = {
|
||||
turn_on = turn_on,
|
||||
read_power_consumption = consumer.read_power_consumption,
|
||||
power_network = Power,
|
||||
power_side = "L",
|
||||
valid_power_dir = valid_power_dir,
|
||||
},
|
||||
|
||||
after_tube_update = consumer.after_tube_update,
|
||||
after_dig_node = consumer.after_dig_node,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
diggable = false,
|
||||
@ -157,6 +133,12 @@ minetest.register_node("techage:turbine_on", {
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
techage.power.register_node({"techage:turbine", "techage:turbine_on"}, {
|
||||
turn_on = turn_on,
|
||||
conn_sides = {"L", "U"},
|
||||
power_network = Power,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:turbine",
|
||||
recipe = {
|
||||
@ -172,8 +154,6 @@ Has to be placed side by side
|
||||
with the TA3 Generator.
|
||||
(see TA3 Coal Power Station)]]), "techage:turbine")
|
||||
|
||||
Power:add_secondary_node_names({"techage:turbine", "techage:turbine_on"})
|
||||
|
||||
minetest.register_lbm({
|
||||
label = "[techage] Turbine sound",
|
||||
name = "techage:power_station",
|
||||
|
24
init.lua
24
init.lua
@ -96,22 +96,14 @@ else
|
||||
end
|
||||
|
||||
-- Coal power station
|
||||
-- dofile(MP.."/coal_power_station/help.lua")
|
||||
-- dofile(MP.."/coal_power_station/firebox.lua")
|
||||
-- dofile(MP.."/coal_power_station/boiler_base.lua")
|
||||
-- dofile(MP.."/coal_power_station/boiler_top.lua")
|
||||
-- dofile(MP.."/coal_power_station/generator.lua")
|
||||
-- dofile(MP.."/coal_power_station/turbine.lua")
|
||||
-- dofile(MP.."/coal_power_station/cooler.lua")
|
||||
-- dofile(MP.."/coal_power_station/akkubox.lua")
|
||||
|
||||
-- dofile(MP.."/power2/electric_cable.lua")
|
||||
-- dofile(MP.."/power2/power2.lua")
|
||||
-- dofile(MP.."/power2/junction.lua") -- network junction box
|
||||
-- dofile(MP.."/power2/junctionbox.lua") -- network junction box
|
||||
-- dofile(MP.."/power2/lamp.lua")
|
||||
-- dofile(MP.."/power2/generator.lua")
|
||||
-- dofile(MP.."/power2/akkubox.lua")
|
||||
dofile(MP.."/coal_power_station/help.lua")
|
||||
dofile(MP.."/coal_power_station/firebox.lua")
|
||||
dofile(MP.."/coal_power_station/boiler_base.lua")
|
||||
dofile(MP.."/coal_power_station/boiler_top.lua")
|
||||
dofile(MP.."/coal_power_station/generator.lua")
|
||||
dofile(MP.."/coal_power_station/turbine.lua")
|
||||
dofile(MP.."/coal_power_station/cooler.lua")
|
||||
dofile(MP.."/coal_power_station/akkubox.lua")
|
||||
|
||||
--dofile(MP.."/test/generator.lua")
|
||||
--dofile(MP.."/test/lamp.lua")
|
||||
|
@ -157,6 +157,7 @@ function techage.power.register_node(names, pwr_def)
|
||||
if ndef then
|
||||
minetest.override_item(name, {
|
||||
power = {
|
||||
turn_on = pwr_def.turn_on, -- line-like networks
|
||||
on_power_pass1 = pwr_def.on_power_pass1,
|
||||
on_power_pass2 = pwr_def.on_power_pass2,
|
||||
on_power_pass3 = pwr_def.on_power_pass3,
|
||||
@ -229,3 +230,29 @@ function techage.power.formspec_load_bar(charging)
|
||||
end
|
||||
return "techage_form_level_off.png"
|
||||
end
|
||||
|
||||
function techage.power.side_to_outdir(pos, side)
|
||||
local node = minetest.get_node(pos)
|
||||
return side_to_dir(node.param2, side)
|
||||
end
|
||||
|
||||
|
||||
-- Simplified version of power distribution for line-like networks
|
||||
-- like the for the steam engine pipe.
|
||||
-- Function uses the node "turn_on" callback
|
||||
-- Returns true, if node could be started/stopped.
|
||||
function techage.power.start_line_node(pos, out_dir, node_name, on)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
local conn = mem.connections and mem.connections[out_dir]
|
||||
if conn and conn.in_dir and conn.pos then
|
||||
local node = minetest.get_node(conn.pos)
|
||||
if node.name == node_name then
|
||||
local pwr = PWR(conn.pos)
|
||||
if pwr and pwr.turn_on then
|
||||
local mem = tubelib2.get_mem(conn.pos)
|
||||
return pwr.turn_on(conn.pos, mem, conn.in_dir, on)
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
@ -27,11 +27,9 @@ local COUNTDOWN_TICKS = 2
|
||||
local HEAT_STEP = 10
|
||||
local WATER_CONSUMPTION = 0.5
|
||||
local MAX_WATER = 10
|
||||
local POWER_CAPACITY = 10
|
||||
|
||||
local Pipe = techage.SteamPipe
|
||||
|
||||
|
||||
local Water = {
|
||||
["bucket:bucket_river_water"] = true,
|
||||
["bucket:bucket_water"] = true,
|
||||
@ -40,6 +38,7 @@ local Water = {
|
||||
|
||||
local function formspec(self, pos, mem)
|
||||
local temp = mem.temperature or 20
|
||||
local bar = mem.running and 3 or 0
|
||||
return "size[8,7]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
@ -52,7 +51,7 @@ local function formspec(self, pos, mem)
|
||||
"image[1,1.6;1,1;techage_form_mask.png]"..
|
||||
"image[2,0.5;1,2;techage_form_temp_bg.png^[lowpart:"..
|
||||
temp..":techage_form_temp_fg.png]"..
|
||||
"image[7,0.5;1,2;"..techage.power.formspec_power_bar(POWER_CAPACITY, mem.power_result).."]"..
|
||||
"image[7,0.5;1,2;"..techage.power.formspec_power_bar(10, bar).."]"..
|
||||
"image_button[6,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
|
||||
"button[3,1.5;2,1;update;"..I("Update").."]"..
|
||||
"list[current_player;main;0,3;8,4;]"..
|
||||
@ -66,11 +65,14 @@ local function can_start(pos, mem, state)
|
||||
end
|
||||
|
||||
local function start_node(pos, mem, state)
|
||||
techage.power.power_distribution(pos)
|
||||
local out_dir = techage.side_to_outdir("U")
|
||||
mem.running = techage.power.start_line_node(pos, out_dir, "techage:cylinder", true)
|
||||
end
|
||||
|
||||
local function stop_node(pos, mem, state)
|
||||
techage.power.power_distribution(pos)
|
||||
local out_dir = techage.side_to_outdir("U")
|
||||
techage.power.start_line_node(pos, out_dir, "techage:cylinder_on", false)
|
||||
mem.running = false
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
@ -84,25 +86,6 @@ local State = techage.NodeStates:new({
|
||||
stop_node = stop_node,
|
||||
})
|
||||
|
||||
|
||||
-- Pass1: Power balance calculation
|
||||
local function on_power_pass1(pos, mem)
|
||||
if State:is_active(mem) then
|
||||
return -POWER_CAPACITY
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-- Pass2: Power balance adjustment
|
||||
local function on_power_pass2(pos, mem, sum)
|
||||
return 0
|
||||
end
|
||||
|
||||
-- Pass3: Power balance result
|
||||
local function on_power_pass3(pos, mem, sum)
|
||||
mem.power_result = sum
|
||||
end
|
||||
|
||||
local function get_water(pos)
|
||||
local inv = M(pos):get_inventory()
|
||||
local items = inv:get_stack("water", 1)
|
||||
@ -136,7 +119,7 @@ end
|
||||
local function steaming(pos, mem, temp)
|
||||
mem.water_level = math.max((mem.water_level or 0) - WATER_CONSUMPTION, 0)
|
||||
if temp >= 80 then
|
||||
if mem.power_result > 0 then
|
||||
if mem.running then
|
||||
State:keep_running(pos, mem, COUNTDOWN_TICKS)
|
||||
else
|
||||
State:fault(pos, mem)
|
||||
@ -171,6 +154,7 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function on_rightclick(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
M(pos):set_string("formspec", formspec(State, pos, mem))
|
||||
@ -288,6 +272,7 @@ minetest.register_node("techage:boiler2", {
|
||||
end,
|
||||
|
||||
power_signal_heat = function(pos)
|
||||
print("power_signal_heat")
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.fire_trigger = true
|
||||
if not minetest.get_node_timer(pos):is_started() then
|
||||
@ -303,9 +288,6 @@ minetest.register_node("techage:boiler2", {
|
||||
})
|
||||
|
||||
techage.power.register_node({"techage:boiler2"}, {
|
||||
on_power_pass1 = on_power_pass1,
|
||||
on_power_pass2 = on_power_pass2,
|
||||
on_power_pass3 = on_power_pass3,
|
||||
conn_sides = {"U"},
|
||||
power_network = Pipe,
|
||||
})
|
||||
@ -338,4 +320,4 @@ and filled with water.
|
||||
techage.register_help_page(I("TA2 Boiler Top"),
|
||||
I([[Part of the steam engine.
|
||||
Has to be placed on top of TA2 Boiler Base.
|
||||
(see TA2 Steam Engine)]]), "techage:boiler2")
|
||||
(see TA2 Steam Engine)]]), "techage:boiler2")
|
||||
|
@ -21,8 +21,6 @@ local M = minetest.get_meta
|
||||
local MP = minetest.get_modpath("techage")
|
||||
local I,_ = dofile(MP.."/intllib.lua")
|
||||
|
||||
local POWER_CONSUMPTION = 8
|
||||
|
||||
local Pipe = techage.SteamPipe
|
||||
|
||||
local function swap_node(pos, name)
|
||||
@ -34,13 +32,9 @@ local function swap_node(pos, name)
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function on_power_pass1(pos, mem)
|
||||
return POWER_CONSUMPTION
|
||||
end
|
||||
|
||||
local function on_power_pass2(pos, mem, sum)
|
||||
mem.running = sum > 0
|
||||
return 0
|
||||
local function turn_on(pos, mem, in_dir, on)
|
||||
mem.running = on
|
||||
return on
|
||||
end
|
||||
|
||||
-- called from flywheel
|
||||
@ -121,8 +115,7 @@ minetest.register_node("techage:cylinder_on", {
|
||||
})
|
||||
|
||||
techage.power.register_node({"techage:cylinder", "techage:cylinder_on"}, {
|
||||
on_power_pass1 = on_power_pass1,
|
||||
on_power_pass2 = on_power_pass2,
|
||||
turn_on = turn_on,
|
||||
conn_sides = {"L"},
|
||||
power_network = Pipe,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user