power distribution changed
|
@ -328,15 +328,6 @@ tiles.act = {
|
|||
},
|
||||
},
|
||||
}
|
||||
tiles.def = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta#.png^techage_appl_autocrafter.png^techage_frame_ta#_top.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_appl_autocrafter.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_appl_autocrafter.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
}
|
||||
|
||||
local tubing = {
|
||||
on_pull_item = function(pos, in_dir, num)
|
||||
|
@ -350,6 +341,7 @@ local tubing = {
|
|||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
|
||||
local inv = M(pos):get_inventory()
|
||||
CRD(pos).State:start_if_standby(pos)
|
||||
return techage.put_items(inv, "src", stack)
|
||||
end
|
||||
end,
|
||||
|
@ -371,9 +363,6 @@ local tubing = {
|
|||
on_node_load = function(pos)
|
||||
CRD(pos).State:on_node_load(pos)
|
||||
end,
|
||||
on_node_repair = function(pos)
|
||||
return CRD(pos).State:on_node_repair(pos)
|
||||
end,
|
||||
}
|
||||
|
||||
local node_name_ta2, node_name_ta3, node_name_ta4 =
|
||||
|
@ -381,8 +370,6 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
|
|||
drawtype = "normal",
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
has_item_meter = true,
|
||||
aging_factor = 10,
|
||||
formspec = formspec,
|
||||
tubing = tubing,
|
||||
after_place_node = function(pos, placer)
|
||||
|
|
|
@ -312,15 +312,6 @@ tiles.act = {
|
|||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_distri_red.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_distri_blue.png",
|
||||
}
|
||||
tiles.def = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta#.png^techage_appl_distri.png^techage_frame_ta#_top.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_distri_yellow.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_distri_green.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_distri_red.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_distri_blue.png^techage_appl_defect.png",
|
||||
}
|
||||
|
||||
local tubing = {
|
||||
on_pull_item = function(pos, in_dir, num)
|
||||
|
@ -329,6 +320,7 @@ local tubing = {
|
|||
end,
|
||||
on_push_item = function(pos, in_dir, stack)
|
||||
local inv = M(pos):get_inventory()
|
||||
CRD(pos).State:start_if_standby(pos)
|
||||
return techage.put_items(inv, "src", stack)
|
||||
end,
|
||||
on_unpull_item = function(pos, in_dir, stack)
|
||||
|
@ -358,17 +350,12 @@ local tubing = {
|
|||
on_node_load = function(pos)
|
||||
CRD(pos).State:on_node_load(pos)
|
||||
end,
|
||||
on_node_repair = function(pos)
|
||||
return CRD(pos).State:on_node_repair(pos)
|
||||
end,
|
||||
}
|
||||
|
||||
local node_name_ta2, node_name_ta3, node_name_ta4 =
|
||||
techage.register_consumer("distributor", I("Distributor"), tiles, {
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
has_item_meter = true,
|
||||
aging_factor = 10,
|
||||
formspec = formspec,
|
||||
tubing = tubing,
|
||||
after_place_node = function(pos, placer)
|
||||
|
|
|
@ -197,15 +197,6 @@ tiles.act = {
|
|||
},
|
||||
},
|
||||
}
|
||||
tiles.def = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta#.png^techage_frame_ta#_top.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_appl_electronic_fab.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_appl_electronic_fab.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
}
|
||||
|
||||
local tubing = {
|
||||
on_pull_item = function(pos, in_dir, num)
|
||||
|
@ -219,6 +210,7 @@ local tubing = {
|
|||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
|
||||
local inv = M(pos):get_inventory()
|
||||
CRD(pos).State:start_if_standby(pos)
|
||||
return techage.put_items(inv, "src", stack)
|
||||
end
|
||||
end,
|
||||
|
@ -240,9 +232,6 @@ local tubing = {
|
|||
on_node_load = function(pos)
|
||||
CRD(pos).State:on_node_load(pos)
|
||||
end,
|
||||
on_node_repair = function(pos)
|
||||
return CRD(pos).State:on_node_repair(pos)
|
||||
end,
|
||||
}
|
||||
|
||||
local node_name_ta2, node_name_ta3, node_name_ta4 =
|
||||
|
@ -250,8 +239,6 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
|
|||
drawtype = "normal",
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
has_item_meter = true,
|
||||
aging_factor = 10,
|
||||
formspec = formspec,
|
||||
tubing = tubing,
|
||||
after_place_node = function(pos, placer)
|
||||
|
|
|
@ -212,15 +212,6 @@ tiles.act = {
|
|||
"techage_filling_ta#.png^techage_appl_rinser.png^techage_frame_ta#.png",
|
||||
"techage_filling_ta#.png^techage_appl_rinser.png^techage_frame_ta#.png",
|
||||
}
|
||||
tiles.def = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_appl_rinser_top.png^techage_frame_ta#_top.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_appl_rinser.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_appl_rinser.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
}
|
||||
|
||||
local tubing = {
|
||||
on_pull_item = function(pos, in_dir, num)
|
||||
|
@ -234,6 +225,7 @@ local tubing = {
|
|||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
|
||||
local inv = M(pos):get_inventory()
|
||||
CRD(pos).State:start_if_standby(pos)
|
||||
return techage.put_items(inv, "src", stack)
|
||||
end
|
||||
end,
|
||||
|
@ -255,9 +247,6 @@ local tubing = {
|
|||
on_node_load = function(pos)
|
||||
CRD(pos).State:on_node_load(pos)
|
||||
end,
|
||||
on_node_repair = function(pos)
|
||||
return CRD(pos).State:on_node_repair(pos)
|
||||
end,
|
||||
}
|
||||
|
||||
local node_name_ta2, node_name_ta3, node_name_ta4 =
|
||||
|
@ -281,8 +270,6 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
|
|||
},
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
has_item_meter = true,
|
||||
aging_factor = 10,
|
||||
formspec = formspec,
|
||||
tubing = tubing,
|
||||
after_place_node = function(pos, placer)
|
||||
|
|
|
@ -151,15 +151,6 @@ tiles.act = {
|
|||
"techage_filling_ta#.png^techage_appl_sieve.png^techage_frame_ta#.png",
|
||||
"techage_filling_ta#.png^techage_appl_sieve.png^techage_frame_ta#.png",
|
||||
}
|
||||
tiles.def = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_appl_sieve_top.png^techage_frame_ta#_top.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_appl_sieve.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_appl_sieve.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
}
|
||||
|
||||
local tubing = {
|
||||
on_pull_item = function(pos, in_dir, num)
|
||||
|
@ -173,6 +164,7 @@ local tubing = {
|
|||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
|
||||
local inv = M(pos):get_inventory()
|
||||
CRD(pos).State:start_if_standby(pos)
|
||||
return techage.put_items(inv, "src", stack)
|
||||
end
|
||||
end,
|
||||
|
@ -194,9 +186,6 @@ local tubing = {
|
|||
on_node_load = function(pos)
|
||||
CRD(pos).State:on_node_load(pos)
|
||||
end,
|
||||
on_node_repair = function(pos)
|
||||
return CRD(pos).State:on_node_repair(pos)
|
||||
end,
|
||||
}
|
||||
|
||||
local node_name_ta2, node_name_ta3, node_name_ta4 =
|
||||
|
@ -218,8 +207,6 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
|
|||
},
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
has_item_meter = true,
|
||||
aging_factor = 10,
|
||||
formspec = formspec,
|
||||
tubing = tubing,
|
||||
after_place_node = function(pos, placer)
|
||||
|
|
|
@ -23,8 +23,8 @@ local CRD = function(pos) return (minetest.registered_nodes[minetest.get_node(po
|
|||
local MP = minetest.get_modpath("techage")
|
||||
local I,_ = dofile(MP.."/intllib.lua")
|
||||
|
||||
local STANDBY_TICKS = 10
|
||||
local COUNTDOWN_TICKS = 10
|
||||
local STANDBY_TICKS = 6
|
||||
local COUNTDOWN_TICKS = 4
|
||||
local CYCLE_TIME = 4
|
||||
|
||||
|
||||
|
@ -163,15 +163,6 @@ tiles.act = {
|
|||
"techage_filling_ta#.png^techage_appl_grinder2.png^techage_frame_ta#.png",
|
||||
"techage_filling_ta#.png^techage_appl_grinder2.png^techage_frame_ta#.png",
|
||||
}
|
||||
tiles.def = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_appl_grinder.png^techage_frame_ta#_top.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_appl_grinder2.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_appl_grinder2.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
}
|
||||
|
||||
local tubing = {
|
||||
on_pull_item = function(pos, in_dir, num)
|
||||
|
@ -185,6 +176,7 @@ local tubing = {
|
|||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
|
||||
local inv = M(pos):get_inventory()
|
||||
CRD(pos).State:start_if_standby(pos)
|
||||
return techage.put_items(inv, "src", stack)
|
||||
end
|
||||
end,
|
||||
|
@ -206,9 +198,6 @@ local tubing = {
|
|||
on_node_load = function(pos)
|
||||
CRD(pos).State:on_node_load(pos)
|
||||
end,
|
||||
on_node_repair = function(pos)
|
||||
return CRD(pos).State:on_node_repair(pos)
|
||||
end,
|
||||
}
|
||||
|
||||
local node_name_ta2, node_name_ta3, node_name_ta4 =
|
||||
|
@ -230,8 +219,6 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
|
|||
},
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
has_item_meter = true,
|
||||
aging_factor = 10,
|
||||
formspec = formspec,
|
||||
tubing = tubing,
|
||||
after_place_node = function(pos, placer)
|
||||
|
|
|
@ -110,15 +110,6 @@ tiles.act = {
|
|||
},
|
||||
},
|
||||
}
|
||||
tiles.def = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png^techage_appl_defect.png",
|
||||
"techage_appl_pusher.png^[transformR180]^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_appl_pusher.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
}
|
||||
|
||||
local tubing = {
|
||||
is_pusher = true, -- is a pulling/pushing node
|
||||
|
@ -134,17 +125,12 @@ local tubing = {
|
|||
on_node_load = function(pos)
|
||||
CRD(pos).State:on_node_load(pos)
|
||||
end,
|
||||
on_node_repair = function(pos)
|
||||
return CRD(pos).State:on_node_repair(pos)
|
||||
end,
|
||||
}
|
||||
|
||||
local node_name_ta2, node_name_ta3, node_name_ta4 =
|
||||
techage.register_consumer("pusher", I("Pusher"), tiles, {
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
has_item_meter = true,
|
||||
aging_factor = 10,
|
||||
tubing = tubing,
|
||||
after_place_node = function(pos, placer)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
|
|
|
@ -24,18 +24,20 @@ local I,_ = dofile(MP.."/intllib.lua")
|
|||
local TA2_Power = techage.Axle
|
||||
local TA3_Power = techage.SteamPipe
|
||||
local TA4_Power = techage.ElectricCable
|
||||
local provide_power = techage.power.provide_power
|
||||
local power_switched = techage.power.power_switched
|
||||
|
||||
local STANDBY_TICKS = 4
|
||||
local COUNTDOWN_TICKS = 4
|
||||
local CYCLE_TIME = 16
|
||||
local POWER_CAPACITY = 50
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_CAPA = 20
|
||||
|
||||
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;"..techage.power.formspec_power_bar(POWER_CAPACITY, mem.power_result).."]"..
|
||||
"image[6,0.5;1,2;"..techage.power.formspec_power_bar(PWR_CAPA, mem.provided).."]"..
|
||||
"image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
|
||||
"button[2.5,1;1.8,1;update;"..I("Update").."]"..
|
||||
"list[current_player;main;0,3;8,4;]"..
|
||||
|
@ -43,11 +45,16 @@ local function formspec(self, pos, mem)
|
|||
end
|
||||
|
||||
local function start_node(pos, mem, state)
|
||||
techage.power.power_distribution(pos)
|
||||
mem.generating = true
|
||||
power_switched(pos)
|
||||
techage.switch_axles(pos, true)
|
||||
end
|
||||
|
||||
local function stop_node(pos, mem, state)
|
||||
techage.power.power_distribution(pos)
|
||||
mem.generating = false
|
||||
mem.provided = 0
|
||||
power_switched(pos)
|
||||
techage.switch_axles(pos, false)
|
||||
end
|
||||
|
||||
local State2 = techage.NodeStates:new({
|
||||
|
@ -77,33 +84,19 @@ local State4 = techage.NodeStates:new({
|
|||
stop_node = stop_node,
|
||||
})
|
||||
|
||||
local tStates = {0, State2, State3, State4}
|
||||
|
||||
-- Pass1: Power balance calculation
|
||||
local function on_power_pass1(pos, mem)
|
||||
local state = tStates[mem.state_num or 2]
|
||||
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 node_timer(pos, elapsed)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
local state = tStates[mem.state_num or 2]
|
||||
return state:is_active(mem)
|
||||
if mem.generating then
|
||||
mem.provided = provide_power(pos, PWR_CAPA)
|
||||
return true
|
||||
else
|
||||
mem.provided = 0
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local tStates = {0, State2, State3, State4}
|
||||
|
||||
local function on_receive_fields(pos, formname, fields, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return
|
||||
|
@ -147,10 +140,6 @@ minetest.register_node("techage:t2_source", {
|
|||
on_rightclick(pos)
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State2:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
|
@ -180,10 +169,6 @@ minetest.register_node("techage:t3_source", {
|
|||
on_rightclick(pos)
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State3:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
|
@ -213,35 +198,22 @@ minetest.register_node("techage:t4_source", {
|
|||
on_rightclick(pos)
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State4:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
})
|
||||
|
||||
techage.power.register_node({"techage:t2_source"}, {
|
||||
on_power_pass1 = on_power_pass1,
|
||||
on_power_pass2 = on_power_pass2,
|
||||
on_power_pass3 = on_power_pass3,
|
||||
conn_sides = {"R"},
|
||||
power_network = TA2_Power,
|
||||
})
|
||||
|
||||
techage.power.register_node({"techage:t3_source"}, {
|
||||
on_power_pass1 = on_power_pass1,
|
||||
on_power_pass2 = on_power_pass2,
|
||||
on_power_pass3 = on_power_pass3,
|
||||
conn_sides = {"R"},
|
||||
power_network = TA3_Power,
|
||||
})
|
||||
|
||||
techage.power.register_node({"techage:t4_source"}, {
|
||||
on_power_pass1 = on_power_pass1,
|
||||
on_power_pass2 = on_power_pass2,
|
||||
on_power_pass3 = on_power_pass3,
|
||||
conn_sides = {"R"},
|
||||
power_network = TA4_Power,
|
||||
})
|
||||
|
|
|
@ -256,7 +256,6 @@ end
|
|||
-- on_unpull_item = func(pos, in_dir, item),
|
||||
-- on_recv_message = func(pos, topic, payload),
|
||||
-- on_node_load = func(pos), -- LBM function
|
||||
-- on_node_repair = func(pos), -- repair defect (feature!) nodes
|
||||
-- on_transfer = func(pos, in_dir, topic, payload),
|
||||
-- }
|
||||
function techage.register_node(names, node_definition)
|
||||
|
@ -339,15 +338,6 @@ function techage.transfer(pos, outdir, topic, payload, network, nodenames)
|
|||
return false
|
||||
end
|
||||
|
||||
-- for defect nodes
|
||||
function techage.repair_node(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
if NodeDef[node.name] and NodeDef[node.name].on_node_repair then
|
||||
return NodeDef[node.name].on_node_repair(pos)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------
|
||||
-- Client side Push/Pull item functions
|
||||
-------------------------------------------------------------------
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
- up to 3 stages of nodes (TA2/TA3/TA4)
|
||||
- power consumption
|
||||
- node state handling
|
||||
- registration of passive, active and defect nodes
|
||||
- registration of passive and active nodes
|
||||
- Tube connections are on left and right side (from left to right)
|
||||
- Power connection are on front and back side (front or back)
|
||||
]]--
|
||||
|
@ -26,40 +26,52 @@ local M = minetest.get_meta
|
|||
local CRD = function(pos) return (minetest.registered_nodes[minetest.get_node(pos).name] or {}).consumer end
|
||||
local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).consumer end
|
||||
|
||||
local CYCLE_TIME = 2 -- required from power
|
||||
|
||||
local ValidPowerConsumingStates = {
|
||||
[techage.RUNNING] = true,
|
||||
[techage.BLOCKED] = true,
|
||||
[techage.FAULT] = true,
|
||||
[techage.NOPOWER] = true,
|
||||
}
|
||||
|
||||
local consume_power = techage.power.consume_power
|
||||
local power_available = techage.power.power_available
|
||||
|
||||
local function can_start(pos, mem, state)
|
||||
return power_available(pos)
|
||||
end
|
||||
|
||||
local function start_node(pos, mem, state)
|
||||
-- First finish the start process, than check power and
|
||||
-- if needed, switch to "nopower"
|
||||
minetest.after(0.5, techage.power.power_distribution, pos)
|
||||
mem.conn_next_call = 0
|
||||
mem.conn_cycle_timer = 0
|
||||
end
|
||||
|
||||
local function stop_node(pos, mem, state)
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
|
||||
local function on_power_pass1(pos, mem)
|
||||
local crd = CRD(pos)
|
||||
if ValidPowerConsumingStates[crd.State:get_state(mem)] then
|
||||
return crd.power_consumption
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
local function on_power_pass2(pos, mem, sum)
|
||||
local function node_timer(pos, elapsed)
|
||||
--print("node_timer")
|
||||
local crd = CRD(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
local state = crd.State:get_state(mem)
|
||||
if sum > 0 and state == techage.NOPOWER then
|
||||
crd.State:start(pos, mem)
|
||||
return 0
|
||||
elseif sum <= 0 and ValidPowerConsumingStates[state] or state == techage.STANDBY then
|
||||
crd.State:nopower(pos, mem)
|
||||
return -crd.power_consumption
|
||||
if ValidPowerConsumingStates[state] then
|
||||
local got = consume_power(pos, crd.power_consumption)
|
||||
if state == techage.NOPOWER and got == crd.power_consumption then
|
||||
crd.State:start(pos, mem)
|
||||
elseif state ~= techage.NOPOWER and got < crd.power_consumption then
|
||||
crd.State:nopower(pos, mem)
|
||||
end
|
||||
end
|
||||
-- call the secondary timer routine with the requested frequency
|
||||
local res
|
||||
mem.conn_next_call = mem.conn_next_call or 0
|
||||
mem.conn_cycle_timer = (mem.conn_cycle_timer or 0) + CYCLE_TIME
|
||||
--print(mem.conn_next_call, mem.conn_cycle_timer)
|
||||
if mem.conn_cycle_timer >= mem.conn_next_call then
|
||||
crd.node_timer(pos, crd.cycle_time)
|
||||
mem.conn_next_call = mem.conn_next_call + crd.cycle_time
|
||||
end
|
||||
return ValidPowerConsumingStates[state] or state == techage.STANDBY
|
||||
end
|
||||
|
||||
local function prepare_tiles(tiles, stage, power_png)
|
||||
|
@ -75,7 +87,7 @@ local function prepare_tiles(tiles, stage, power_png)
|
|||
end
|
||||
return tbl
|
||||
end
|
||||
|
||||
|
||||
-- 'validStates' is optional and can be used to e.g. enable
|
||||
-- only one TA2 node {false, true, false, false}
|
||||
function techage.register_consumer(base_name, inv_name, tiles, tNode, validStates)
|
||||
|
@ -84,10 +96,9 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||
for stage = 2,4 do
|
||||
local name_pas = "techage:ta"..stage.."_"..base_name.."_pas"
|
||||
local name_act = "techage:ta"..stage.."_"..base_name.."_act"
|
||||
local name_def = "techage:ta"..stage.."_"..base_name.."_def"
|
||||
local name_inv = "TA"..stage.." "..inv_name
|
||||
names[#names+1] = name_pas
|
||||
|
||||
|
||||
if validStates[stage] then
|
||||
local on_recv_message = tNode.tubing.on_recv_message
|
||||
if stage > 2 then
|
||||
|
@ -95,7 +106,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||
return "unsupported"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local power_network
|
||||
local power_png = 'techage_axle_clutch.png'
|
||||
local power_used = tNode.power_consumption ~= nil
|
||||
|
@ -110,31 +121,31 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||
end
|
||||
power_network:add_secondary_node_names({name_pas, name_act})
|
||||
end
|
||||
|
||||
|
||||
local tState = techage.NodeStates:new({
|
||||
node_name_passive = name_pas,
|
||||
node_name_active = name_act,
|
||||
node_name_defect = name_def,
|
||||
infotext_name = name_inv,
|
||||
cycle_time = tNode.cycle_time,
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = tNode.standby_ticks,
|
||||
has_item_meter = tNode.has_item_meter,
|
||||
aging_factor = tNode.aging_factor * (stage-1) * 2,
|
||||
formspec_func = tNode.formspec,
|
||||
on_state_change = tNode.on_state_change,
|
||||
can_start = power_used and can_start or nil,
|
||||
start_node = power_used and start_node or nil,
|
||||
stop_node = power_used and stop_node or nil,
|
||||
})
|
||||
|
||||
|
||||
local tConsumer = {
|
||||
stage = stage,
|
||||
State = tState,
|
||||
-- number of items to be processed per cycle
|
||||
num_items = tNode.num_items[stage],
|
||||
power_consumption = power_used and
|
||||
tNode.power_consumption[stage] or {0,0,0,0},
|
||||
tNode.power_consumption[stage] or 0,
|
||||
node_timer = tNode.node_timer,
|
||||
cycle_time = tNode.cycle_time,
|
||||
}
|
||||
|
||||
|
||||
tNode.groups.not_in_creative_inventory = 0
|
||||
|
||||
minetest.register_node(name_pas, {
|
||||
|
@ -144,9 +155,9 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||
drawtype = tNode.drawtype,
|
||||
node_box = tNode.node_box,
|
||||
selection_box = tNode.selection_box,
|
||||
|
||||
|
||||
on_construct = tubelib2.init_mem,
|
||||
|
||||
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
local meta = M(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
|
@ -168,13 +179,11 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||
tNode.after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end
|
||||
techage.remove_node(pos)
|
||||
CRDN(oldnode).State:after_dig_node(pos, oldnode,
|
||||
oldmetadata, digger)
|
||||
end,
|
||||
|
||||
|
||||
can_dig = tNode.can_dig,
|
||||
on_rotate = screwdriver.disallow,
|
||||
on_timer = tNode.node_timer,
|
||||
on_timer = node_timer,
|
||||
on_receive_fields = tNode.on_receive_fields,
|
||||
on_rightclick = tNode.on_rightclick,
|
||||
allow_metadata_inventory_put = tNode.allow_metadata_inventory_put,
|
||||
|
@ -202,7 +211,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||
selection_box = tNode.selection_box,
|
||||
|
||||
on_rotate = screwdriver.disallow,
|
||||
on_timer = tNode.node_timer,
|
||||
on_timer = node_timer,
|
||||
on_receive_fields = tNode.on_receive_fields,
|
||||
on_rightclick = tNode.on_rightclick,
|
||||
allow_metadata_inventory_put = tNode.allow_metadata_inventory_put,
|
||||
|
@ -219,62 +228,13 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||
sounds = tNode.sounds,
|
||||
})
|
||||
|
||||
minetest.register_node(name_def, {
|
||||
description = name_inv,
|
||||
tiles = prepare_tiles(tiles.def, stage, power_png),
|
||||
consumer = tConsumer,
|
||||
drawtype = tNode.drawtype,
|
||||
node_box = tNode.node_box,
|
||||
selection_box = tNode.selection_box,
|
||||
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
local meta = M(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
meta:set_int("push_dir", techage.side_to_indir("L", node.param2))
|
||||
meta:set_int("pull_dir", techage.side_to_indir("R", node.param2))
|
||||
local number = "-"
|
||||
if stage > 2 then
|
||||
number = techage.add_node(pos, name_pas)
|
||||
end
|
||||
if tNode.after_place_node then
|
||||
tNode.after_place_node(pos, placer, itemstack, pointed_thing)
|
||||
end
|
||||
CRD(pos).State:defect(pos, mem)
|
||||
end,
|
||||
|
||||
on_rotate = screwdriver.disallow,
|
||||
on_receive_fields = tNode.on_receive_fields,
|
||||
on_rightclick = tNode.on_rightclick,
|
||||
allow_metadata_inventory_put = tNode.allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_move = tNode.allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_take = tNode.allow_metadata_inventory_take,
|
||||
on_metadata_inventory_move = tNode.on_metadata_inventory_move,
|
||||
on_metadata_inventory_put = tNode.on_metadata_inventory_put,
|
||||
on_metadata_inventory_take = tNode.on_metadata_inventory_take,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
if tNode.after_dig_node then
|
||||
tNode.after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end
|
||||
techage.remove_node(pos)
|
||||
end,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = tNode.groups,
|
||||
is_ground_content = false,
|
||||
sounds = tNode.sounds,
|
||||
})
|
||||
|
||||
if power_used then
|
||||
techage.power.register_node({name_pas, name_act}, {
|
||||
on_power_pass1 = on_power_pass1,
|
||||
on_power_pass2 = on_power_pass2,
|
||||
conn_sides = {"F", "B"},
|
||||
power_network = power_network,
|
||||
})
|
||||
end
|
||||
techage.register_node({name_pas, name_act, name_def}, tNode.tubing)
|
||||
techage.register_node({name_pas, name_act}, tNode.tubing)
|
||||
end
|
||||
end
|
||||
return names[1], names[2], names[3]
|
||||
|
|
|
@ -108,14 +108,6 @@ function techage.firebox.on_receive_fields(pos, formname, fields, player)
|
|||
if fields.power_level then
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.power_level = PowerLevel[fields.power_level]
|
||||
techage.transfer(
|
||||
{x=pos.x, y=pos.y+2, z=pos.z},
|
||||
nil, -- outdir
|
||||
"power_level", -- topic
|
||||
mem.power_level, -- payload
|
||||
nil, -- network
|
||||
{"techage:coalboiler_top"} -- nodenames
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -26,18 +26,18 @@ Node states:
|
|||
| | | | |
|
||||
| button | +---------+ |
|
||||
| | ^ |
|
||||
repair | V | button |
|
||||
button | V | button |
|
||||
| +---------+ | | button
|
||||
| | |---------+ |
|
||||
| | RUNNING | |
|
||||
| +--------| |---------+ |
|
||||
| | +---------+ | |
|
||||
| | ^ | | |
|
||||
| | | | | |
|
||||
| V | V V |
|
||||
| +--------->| |---------+ |
|
||||
| | power | RUNNING | |
|
||||
| | +------| |---------+ |
|
||||
| | | +---------+ | |
|
||||
| | | ^ | | |
|
||||
| | | | | | |
|
||||
| | V | V V |
|
||||
| +---------+ +----------+ +---------+ |
|
||||
| | | | NOPOWER/ | | | |
|
||||
+---| DEFECT | | STANDBY/ | | FAULT |----------+
|
||||
+---| NOPOWER | | STANDBY/ | | FAULT |----------+
|
||||
| | | BLOCKED | | |
|
||||
+---------+ +----------+ +---------+
|
||||
|
||||
|
@ -45,7 +45,6 @@ Node mem data:
|
|||
"techage_state" - node state, like "RUNNING"
|
||||
"techage_item_meter" - node item/runtime counter
|
||||
"techage_countdown" - countdown to stadby mode
|
||||
"techage_aging" - aging counter
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
|
@ -64,7 +63,6 @@ techage.STANDBY = 3 -- nothing to do (e.g. no input items), or blocked anyhow (o
|
|||
techage.NOPOWER = 4 -- only for power consuming nodes
|
||||
techage.FAULT = 5 -- any fault state (e.g. wrong source items), which can be fixed by the player
|
||||
techage.BLOCKED = 6 -- a pushing node is blocked due to a full destination inventory
|
||||
techage.DEFECT = 7 -- a defect (broken), which has to be repaired by the player
|
||||
|
||||
techage.StatesImg = {
|
||||
"techage_inv_button_off.png",
|
||||
|
@ -73,7 +71,6 @@ techage.StatesImg = {
|
|||
"techage_inv_button_nopower.png",
|
||||
"techage_inv_button_error.png",
|
||||
"techage_inv_button_warning.png",
|
||||
"techage_inv_button_off.png",
|
||||
}
|
||||
|
||||
-- Return state button image for the node inventory
|
||||
|
@ -94,7 +91,7 @@ function techage.get_power_image(pos, mem)
|
|||
end
|
||||
|
||||
-- State string based on button states
|
||||
techage.StateStrings = {"stopped", "running", "standby", "nopower", "fault", "blocked", "defect"}
|
||||
techage.StateStrings = {"stopped", "running", "standby", "nopower", "fault", "blocked"}
|
||||
|
||||
--
|
||||
-- Local States
|
||||
|
@ -105,11 +102,8 @@ local STANDBY = techage.STANDBY
|
|||
local NOPOWER = techage.NOPOWER
|
||||
local FAULT = techage.FAULT
|
||||
local BLOCKED = techage.BLOCKED
|
||||
local DEFECT = techage.DEFECT
|
||||
|
||||
|
||||
local AGING_FACTOR = 4 -- defect random factor
|
||||
|
||||
--
|
||||
-- NodeStates Class Functions
|
||||
--
|
||||
|
@ -134,11 +128,9 @@ function NodeStates:new(attr)
|
|||
-- mandatory
|
||||
cycle_time = attr.cycle_time, -- for running state
|
||||
standby_ticks = attr.standby_ticks, -- for standby state
|
||||
has_item_meter = attr.has_item_meter, -- true/false
|
||||
-- optional
|
||||
node_name_passive = attr.node_name_passive,
|
||||
node_name_active = attr.node_name_active,
|
||||
node_name_defect = attr.node_name_defect,
|
||||
infotext_name = attr.infotext_name,
|
||||
can_start = attr.can_start or can_start,
|
||||
start_node = attr.start_node,
|
||||
|
@ -146,10 +138,6 @@ function NodeStates:new(attr)
|
|||
formspec_func = attr.formspec_func,
|
||||
on_state_change = attr.on_state_change,
|
||||
}
|
||||
if attr.aging_factor then
|
||||
o.aging_level1 = attr.aging_factor * techage.machine_aging_value
|
||||
o.aging_level2 = attr.aging_factor * techage.machine_aging_value * AGING_FACTOR
|
||||
end
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
|
@ -161,12 +149,7 @@ function NodeStates:node_init(pos, mem, number)
|
|||
if self.infotext_name then
|
||||
M(pos):set_string("infotext", self.infotext_name.." "..number..": stopped")
|
||||
end
|
||||
if self.has_item_meter then
|
||||
mem.techage_item_meter = 0
|
||||
end
|
||||
if self.aging_level1 then
|
||||
mem.techage_aging = 0
|
||||
end
|
||||
mem.techage_item_meter = 0
|
||||
if self.formspec_func then
|
||||
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
|
||||
end
|
||||
|
@ -174,30 +157,27 @@ end
|
|||
|
||||
function NodeStates:stop(pos, mem)
|
||||
local state = mem.techage_state or STOPPED
|
||||
if state ~= DEFECT then
|
||||
mem.techage_state = STOPPED
|
||||
if self.stop_node then
|
||||
self.stop_node(pos, mem, state)
|
||||
end
|
||||
if self.node_name_passive then
|
||||
swap_node(pos, self.node_name_passive)
|
||||
end
|
||||
if self.infotext_name then
|
||||
local number = M(pos):get_string("node_number")
|
||||
M(pos):set_string("infotext", self.infotext_name.." "..number..": stopped")
|
||||
end
|
||||
if self.formspec_func then
|
||||
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
|
||||
end
|
||||
if self.on_state_change then
|
||||
self.on_state_change(pos, state, STOPPED)
|
||||
end
|
||||
if minetest.get_node_timer(pos):is_started() then
|
||||
minetest.get_node_timer(pos):stop()
|
||||
end
|
||||
return true
|
||||
mem.techage_state = STOPPED
|
||||
if self.stop_node then
|
||||
self.stop_node(pos, mem, state)
|
||||
end
|
||||
return false
|
||||
if self.node_name_passive then
|
||||
swap_node(pos, self.node_name_passive)
|
||||
end
|
||||
if self.infotext_name then
|
||||
local number = M(pos):get_string("node_number")
|
||||
M(pos):set_string("infotext", self.infotext_name.." "..number..": stopped")
|
||||
end
|
||||
if self.formspec_func then
|
||||
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
|
||||
end
|
||||
if self.on_state_change then
|
||||
self.on_state_change(pos, state, STOPPED)
|
||||
end
|
||||
if minetest.get_node_timer(pos):is_started() then
|
||||
minetest.get_node_timer(pos):stop()
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function NodeStates:start(pos, mem, called_from_on_timer)
|
||||
|
@ -297,7 +277,7 @@ end
|
|||
|
||||
function NodeStates:nopower(pos, mem)
|
||||
local state = mem.techage_state or RUNNING
|
||||
if state ~= STOPPED and state ~= DEFECT then
|
||||
if state ~= STOPPED then
|
||||
mem.techage_state = NOPOWER
|
||||
if self.node_name_passive then
|
||||
swap_node(pos, self.node_name_passive)
|
||||
|
@ -341,26 +321,6 @@ function NodeStates:fault(pos, mem)
|
|||
return false
|
||||
end
|
||||
|
||||
function NodeStates:defect(pos, mem)
|
||||
local state = mem.techage_state or STOPPED
|
||||
mem.techage_state = DEFECT
|
||||
if self.node_name_defect then
|
||||
swap_node(pos, self.node_name_defect)
|
||||
end
|
||||
if self.infotext_name then
|
||||
local number = M(pos):get_string("node_number")
|
||||
M(pos):set_string("infotext", self.infotext_name.." "..number..": defect")
|
||||
end
|
||||
if self.formspec_func then
|
||||
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
|
||||
end
|
||||
if self.on_state_change then
|
||||
self.on_state_change(pos, state, DEFECT)
|
||||
end
|
||||
minetest.get_node_timer(pos):stop()
|
||||
return true
|
||||
end
|
||||
|
||||
function NodeStates:get_state(mem)
|
||||
return mem.techage_state or techage.STOPPED
|
||||
end
|
||||
|
@ -397,21 +357,11 @@ end
|
|||
|
||||
-- To be called after successful node action to raise the timer
|
||||
-- and keep the node in state RUNNING
|
||||
function NodeStates:keep_running(pos, mem, val)
|
||||
function NodeStates:keep_running(pos, mem, val, num_items)
|
||||
-- set to RUNNING if not already done
|
||||
self:start(pos, mem, true)
|
||||
mem.techage_countdown = val
|
||||
if self.has_item_meter then
|
||||
mem.techage_item_meter = (mem.techage_item_meter or 999999) + 1
|
||||
end
|
||||
if self.aging_level1 then
|
||||
local cnt = mem.techage_aging + 1
|
||||
mem.techage_aging = cnt
|
||||
if (cnt > (self.aging_level1) and math.random(self.aging_level2) == 1)
|
||||
or cnt >= 999999 then
|
||||
self:defect(pos, mem)
|
||||
end
|
||||
end
|
||||
mem.techage_countdown = val or 4
|
||||
mem.techage_item_meter = (mem.techage_item_meter or 0) + (num_items or 1)
|
||||
end
|
||||
|
||||
-- Start/stop node based on button events.
|
||||
|
@ -449,13 +399,11 @@ function NodeStates:on_receive_message(pos, topic, payload)
|
|||
return "blocked"
|
||||
end
|
||||
return self:get_state_string(tubelib2.get_mem(pos))
|
||||
elseif self.has_item_meter and topic == "counter" then
|
||||
elseif topic == "counter" then
|
||||
return mem.techage_item_meter or 1
|
||||
elseif self.has_item_meter and topic == "clear_counter" then
|
||||
elseif topic == "clear_counter" then
|
||||
mem.techage_item_meter = 0
|
||||
return true
|
||||
elseif self.aging_level1 and topic == "aging" then
|
||||
return mem.techage_aging or 1
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -466,6 +414,7 @@ function NodeStates:on_node_load(pos, not_start_timer)
|
|||
-- Meta data corrupt?
|
||||
local number = M(pos):get_string("node_number")
|
||||
if number == "" then
|
||||
minetest.log("warning", "[TA] Node at "..S(pos).." has no node_number")
|
||||
swap_node(pos, "techage:defect_dummy")
|
||||
return
|
||||
end
|
||||
|
@ -474,6 +423,13 @@ function NodeStates:on_node_load(pos, not_start_timer)
|
|||
if number ~= "-" then
|
||||
local info = techage.get_node_info(number)
|
||||
if not info or not info.pos or not vector.equals(pos, info.pos) then
|
||||
if not info then
|
||||
minetest.log("warning", "[TA] Node at "..S(pos).." has no info")
|
||||
elseif not info.pos then
|
||||
minetest.log("warning", "[TA] Node at "..S(pos).." has no info.pos")
|
||||
elseif not vector.equals(pos, info.pos) then
|
||||
minetest.log("warning", "[TA] Node at "..S(pos).." is pos ~= info.pos")
|
||||
end
|
||||
swap_node(pos, "techage:defect_dummy")
|
||||
return
|
||||
end
|
||||
|
@ -500,50 +456,6 @@ function NodeStates:on_node_load(pos, not_start_timer)
|
|||
end
|
||||
end
|
||||
|
||||
-- Repair of defect (feature!) nodes
|
||||
function NodeStates:on_node_repair(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.techage_state == DEFECT then
|
||||
mem.techage_state = STOPPED
|
||||
if self.node_name_passive then
|
||||
swap_node(pos, self.node_name_passive)
|
||||
end
|
||||
if self.aging_level1 then
|
||||
mem.techage_aging = 0
|
||||
end
|
||||
if self.infotext_name then
|
||||
local number = M(pos):get_string("node_number")
|
||||
M(pos):set_string("infotext", self.infotext_name.." "..number..": stopped")
|
||||
end
|
||||
if self.formspec_func then
|
||||
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Return working or defect machine, depending on machine lifetime
|
||||
function NodeStates:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
local inv = minetest.get_inventory({type="player", name=digger:get_player_name()})
|
||||
local cnt = math.max(mem.techage_aging or 1, 1)
|
||||
local left_over
|
||||
if self.aging_level1 then
|
||||
local is_defect = cnt > self.aging_level1 and math.random(self.aging_level2 / cnt) == 1
|
||||
if self.node_name_defect and is_defect then
|
||||
left_over = inv:add_item("main", ItemStack(self.node_name_defect))
|
||||
else
|
||||
left_over = inv:add_item("main", ItemStack(self.node_name_passive))
|
||||
end
|
||||
else
|
||||
left_over = inv:add_item("main", ItemStack(self.node_name_passive))
|
||||
end
|
||||
if left_over and left_over:get_count() > 0 then
|
||||
minetest.add_item(pos, left_over)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("techage:defect_dummy", {
|
||||
description = "Corrupted Node (to be replaced)",
|
||||
tiles = {
|
||||
|
|
|
@ -21,108 +21,73 @@ local M = minetest.get_meta
|
|||
local MP = minetest.get_modpath("techage")
|
||||
local I,_ = dofile(MP.."/intllib.lua")
|
||||
|
||||
local STANDBY_TICKS = 4
|
||||
local CYCLE_TIME = 2
|
||||
local POWER_CONSUMPTION = 10
|
||||
local POWER_MAX_LOAD = 300
|
||||
local POWER_HYSTERESIS = 10
|
||||
local PWR_PERF = 10
|
||||
local PWR_CAPA = 3000
|
||||
|
||||
local Power = techage.ElectricCable
|
||||
local secondary_power = techage.power.secondary_power
|
||||
local power_switched = techage.power.power_switched
|
||||
|
||||
local function in_range(val, min, max)
|
||||
if val < min then return min end
|
||||
if val > max then return max end
|
||||
return val
|
||||
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;"..techage.power.formspec_power_bar(POWER_MAX_LOAD, mem.capa).."]"..
|
||||
"image[0,0.5;1,2;"..techage.power.formspec_power_bar(PWR_CAPA, 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;"..techage.power.formspec_load_bar(mem.charging).."]"..
|
||||
"image[4,0.5;1,2;"..techage.power.formspec_load_bar(-(mem.delivered or 0), PWR_PERF).."]"..
|
||||
"label[4.2,2.5;Flow]"
|
||||
end
|
||||
|
||||
|
||||
local function start_node(pos, mem, state)
|
||||
techage.power.power_distribution(pos)
|
||||
mem.generating = true
|
||||
mem.delivered = 0
|
||||
power_switched(pos)
|
||||
end
|
||||
|
||||
local function stop_node(pos, mem, state)
|
||||
mem.charging = nil
|
||||
techage.power.power_distribution(pos)
|
||||
mem.generating = false
|
||||
mem.delivered = 0
|
||||
power_switched(pos)
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
node_name_passive = "techage:ta3_akku",
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
standby_ticks = 0,
|
||||
formspec_func = formspec,
|
||||
start_node = start_node,
|
||||
stop_node = stop_node,
|
||||
})
|
||||
|
||||
--
|
||||
-- Power network callbacks
|
||||
--
|
||||
|
||||
-- Pass1: Power balance calculation
|
||||
local function on_power_pass1(pos, mem)
|
||||
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)
|
||||
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)
|
||||
mem.power_result = sum
|
||||
end
|
||||
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if State:is_active(mem) then
|
||||
mem.capa = mem.capa or 0
|
||||
if mem.charging == true then
|
||||
if mem.capa < POWER_MAX_LOAD then
|
||||
mem.capa = mem.capa + 1
|
||||
else
|
||||
mem.charging = nil -- turn off
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
elseif mem.charging == false then -- uncharging
|
||||
if mem.capa > 0 then
|
||||
mem.capa = mem.capa - 1
|
||||
else
|
||||
mem.charging = nil -- turn off
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
mem.capa = mem.capa or 0
|
||||
if mem.generating then
|
||||
local delivered
|
||||
if mem.capa >= PWR_CAPA then
|
||||
mem.delivered = secondary_power(pos, PWR_PERF, 0)
|
||||
elseif mem.capa <= 0 then
|
||||
mem.delivered = secondary_power(pos, 0, PWR_PERF)
|
||||
else
|
||||
mem.delivered = secondary_power(pos, PWR_PERF, PWR_PERF)
|
||||
end
|
||||
mem.capa = mem.capa - mem.delivered
|
||||
mem.capa = in_range(mem.capa, 0, PWR_CAPA)
|
||||
return true
|
||||
end
|
||||
return State:is_active(mem)
|
||||
mem.delivered = 0
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
|
@ -147,7 +112,7 @@ end
|
|||
local function get_capa(itemstack)
|
||||
local meta = itemstack:get_meta()
|
||||
if meta then
|
||||
return meta:get_int("capa")
|
||||
return in_range(meta:get_int("capa") * (PWR_CAPA/100), 0, 100)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
@ -155,8 +120,10 @@ end
|
|||
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.power.percent(POWER_MAX_LOAD, capa).." %)"
|
||||
capa = techage.power.percent(PWR_CAPA, capa)
|
||||
capa = (math.floor((capa or 0) / 5)) * 5
|
||||
meta:set_int("capa", capa)
|
||||
local text = I("TA3 Akku Box").." ("..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)
|
||||
|
@ -182,13 +149,13 @@ minetest.register_node("techage:ta3_akku", {
|
|||
after_place_node = function(pos, placer, itemstack)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
State:node_init(pos, mem, "")
|
||||
mem.capa = get_capa(itemstack)
|
||||
--mem.capa = get_capa(itemstack)
|
||||
mem.capa = 300
|
||||
on_rightclick(pos)
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
--State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
set_capa(pos, oldnode, digger, mem.capa)
|
||||
end,
|
||||
|
||||
|
@ -196,7 +163,7 @@ minetest.register_node("techage:ta3_akku", {
|
|||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
|
||||
drop = "",
|
||||
drop = "", -- don't remove, item will be added via 'set_capa'
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
@ -205,9 +172,6 @@ minetest.register_node("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,
|
||||
})
|
||||
|
@ -226,3 +190,18 @@ minetest.register_craft({
|
|||
{"techage:iron_ingot", "techage:iron_ingot", "default:wood"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_lbm({
|
||||
label = "[techage] Akku conversion",
|
||||
name = "techage:akku_conversion",
|
||||
nodenames = {"techage:ta3_akku"},
|
||||
run_at_every_load = true,
|
||||
action = function(pos, node)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.power_result then -- old node?
|
||||
mem.power_result = nil
|
||||
mem.capa = in_range((mem.capa or 0) * 10, 0, PWR_CAPA)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
|
|
@ -54,6 +54,8 @@ techage.register_node({"techage:coalboiler_base"}, {
|
|||
return true
|
||||
elseif topic == "stop" then
|
||||
return true
|
||||
elseif topic == "running" then
|
||||
return true
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
|
@ -30,6 +30,11 @@ local MAX_WATER = 10
|
|||
|
||||
local Pipe = techage.SteamPipe
|
||||
|
||||
local function transfer(pos, topic, payload)
|
||||
return techage.transfer(pos, "F", topic, payload, Pipe,
|
||||
{"techage:turbine", "techage:turbine_on"})
|
||||
end
|
||||
|
||||
local Water = {
|
||||
["bucket:bucket_river_water"] = true,
|
||||
["bucket:bucket_water"] = true,
|
||||
|
@ -38,7 +43,7 @@ local Water = {
|
|||
|
||||
local function formspec(self, pos, mem)
|
||||
local temp = mem.temperature or 20
|
||||
local bar = mem.running and 3 or 0
|
||||
local ratio = mem.power_ratio or 0
|
||||
return "size[8,7]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
|
@ -51,7 +56,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(10, bar).."]"..
|
||||
"image[7,0.5;1,2;"..techage.power.formspec_power_bar(1, ratio).."]"..
|
||||
"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;]"..
|
||||
|
@ -65,14 +70,11 @@ local function can_start(pos, mem, state)
|
|||
end
|
||||
|
||||
local function start_node(pos, mem, state)
|
||||
print("start_node", S(pos))
|
||||
mem.running = techage.transfer(pos, "F", "start", nil, Pipe, {"techage:turbine"})
|
||||
techage.transfer(pos, "F", "power_level", mem.power_level, Pipe, {"techage:turbine"})
|
||||
mem.running = transfer(pos, "start", nil)
|
||||
end
|
||||
|
||||
local function stop_node(pos, mem, state)
|
||||
print("stop_node", S(pos))
|
||||
techage.transfer(pos, "F", "stop", nil, Pipe, {"techage:turbine_on"})
|
||||
transfer(pos, "stop", nil)
|
||||
mem.running = false
|
||||
end
|
||||
|
||||
|
@ -118,7 +120,9 @@ local function water_temperature(pos, mem)
|
|||
end
|
||||
|
||||
local function steaming(pos, mem, temp)
|
||||
mem.water_level = math.max((mem.water_level or 0) - WATER_CONSUMPTION, 0)
|
||||
local wc = WATER_CONSUMPTION * (mem.power_ratio or 1)
|
||||
mem.water_level = math.max((mem.water_level or 0) - wc, 0)
|
||||
mem.running = transfer(pos, "running", nil)
|
||||
if temp >= 80 then
|
||||
if mem.running then
|
||||
State:keep_running(pos, mem, COUNTDOWN_TICKS)
|
||||
|
@ -145,6 +149,7 @@ local function on_receive_fields(pos, formname, fields, player)
|
|||
return
|
||||
end
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.temperature = mem.temperature or 20
|
||||
State:state_button_event(pos, mem, fields)
|
||||
|
||||
if fields.update then
|
||||
|
@ -159,12 +164,15 @@ end
|
|||
local function on_rightclick(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
M(pos):set_string("formspec", formspec(State, pos, mem))
|
||||
if not minetest.get_node_timer(pos):is_started() then
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
end
|
||||
|
||||
local function can_dig(pos, player)
|
||||
local inv = M(pos):get_inventory()
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
return inv:is_empty("water") and inv:is_empty("input") and not mem.running
|
||||
return inv:is_empty("input") and not mem.running
|
||||
end
|
||||
|
||||
local function move_to_water(pos)
|
||||
|
@ -247,15 +255,10 @@ minetest.register_node("techage:coalboiler_top", {
|
|||
end
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_metadata_inventory_put = function(pos)
|
||||
minetest.after(0.5, move_to_water, pos)
|
||||
end,
|
||||
|
||||
drop = "",
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=1},
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
@ -273,15 +276,8 @@ techage.register_node({"techage:coalboiler_top"}, {
|
|||
if topic == "trigger" then
|
||||
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
|
||||
elseif topic == "power_level" then
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.power_level = payload
|
||||
print("coalboiler_top power_level", payload)
|
||||
techage.transfer(pos, "F", topic, payload, Pipe,
|
||||
{"techage:turbine", "techage:turbine_on"})
|
||||
mem.power_ratio = transfer(pos, topic, payload)
|
||||
return mem.power_ratio
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
|
@ -23,6 +23,11 @@ local I,_ = dofile(MP.."/intllib.lua")
|
|||
|
||||
local Pipe = techage.SteamPipe
|
||||
|
||||
local function transfer(pos, in_dir, topic, payload)
|
||||
return techage.transfer(pos, in_dir, topic, payload, Pipe,
|
||||
{"techage:coalboiler_base"})
|
||||
end
|
||||
|
||||
local function swap_node(pos, name)
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == name then
|
||||
|
@ -32,6 +37,11 @@ local function swap_node(pos, name)
|
|||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
-- called with any pipe change
|
||||
local function after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
|
||||
swap_node(pos, "techage:cooler")
|
||||
end
|
||||
|
||||
minetest.register_node("techage:cooler", {
|
||||
description = I("TA3 Cooler"),
|
||||
tiles = {
|
||||
|
@ -83,6 +93,7 @@ minetest.register_node("techage:cooler_on", {
|
|||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_cooler.png",
|
||||
},
|
||||
|
||||
after_tube_update = after_tube_update,
|
||||
paramtype2 = "facedir",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
diggable = false,
|
||||
|
@ -101,16 +112,20 @@ techage.power.register_node({"techage:cooler", "techage:cooler_on"}, {
|
|||
techage.register_node({"techage:cooler", "techage:cooler_on"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
if topic == "start" then
|
||||
local on = techage.transfer(pos, in_dir, "start", nil, Pipe, {"techage:coalboiler_base"})
|
||||
if on then
|
||||
if transfer(pos, in_dir, topic, nil) then
|
||||
swap_node(pos, "techage:cooler_on")
|
||||
return true
|
||||
end
|
||||
return on
|
||||
elseif topic == "stop" then
|
||||
techage.transfer(pos, in_dir, "stop", nil, Pipe, {"techage:coalboiler_base"})
|
||||
swap_node(pos, "techage:cooler")
|
||||
return false
|
||||
return transfer(pos, in_dir, topic, nil)
|
||||
elseif topic == "running" then
|
||||
if transfer(pos, in_dir, topic, nil) then
|
||||
return true
|
||||
end
|
||||
swap_node(pos, "techage:cooler")
|
||||
end
|
||||
return false
|
||||
end
|
||||
})
|
||||
|
||||
|
|
|
@ -39,21 +39,22 @@ end
|
|||
|
||||
local function node_timer(pos, elapsed)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
print("firebox burn_cycles = "..(mem.burn_cycles or 0))
|
||||
if mem.running then
|
||||
techage.transfer(
|
||||
-- trigger generator and provide power ratio 0..1
|
||||
local ratio = techage.transfer(
|
||||
{x=pos.x, y=pos.y+2, z=pos.z},
|
||||
nil, -- outdir
|
||||
"trigger", -- topic
|
||||
nil, -- payload
|
||||
mem.power_level/4.0, -- payload
|
||||
nil, -- network
|
||||
{"techage:coalboiler_top"} -- nodenames
|
||||
)
|
||||
mem.burn_cycles = (mem.burn_cycles or 0) - 1
|
||||
mem.burn_cycles = (mem.burn_cycles or 0) - math.max((ratio or 0.1), 0.1)
|
||||
if mem.burn_cycles <= 0 then
|
||||
local taken = firebox.get_fuel(pos)
|
||||
if taken then
|
||||
mem.burn_cycles = firebox.Burntime[taken:get_name()] / CYCLE_TIME
|
||||
mem.burn_cycles = mem.burn_cycles * 4 / (mem.power_level or 4)
|
||||
mem.burn_cycles_total = mem.burn_cycles
|
||||
else
|
||||
mem.running = false
|
||||
|
|
|
@ -23,38 +23,40 @@ local I,_ = dofile(MP.."/intllib.lua")
|
|||
|
||||
local STANDBY_TICKS = 4
|
||||
local COUNTDOWN_TICKS = 4
|
||||
local CYCLE_TIME = 8
|
||||
local POWER_CAPACITY = 80
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_CAPA = 80
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local provide_power = techage.power.provide_power
|
||||
local power_switched = techage.power.power_switched
|
||||
|
||||
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;"..techage.power.formspec_power_bar(POWER_CAPACITY, mem.power_result).."]"..
|
||||
"image[6,0.5;1,2;"..techage.power.formspec_power_bar(PWR_CAPA, mem.provided).."]"..
|
||||
"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;]"..
|
||||
default.get_hotbar_bg(0, 3)
|
||||
end
|
||||
|
||||
local function turbine_running(pos)
|
||||
local pos1 = techage.get_pos(pos, 'L')
|
||||
local node = minetest.get_node(pos1)
|
||||
if node.name == "techage:turbine_on" then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
local function can_start(pos, mem, state)
|
||||
return (mem.triggered or 0) > 0 -- by means of firebox
|
||||
end
|
||||
|
||||
local function start_node(pos, mem, state)
|
||||
techage.power.power_distribution(pos)
|
||||
mem.generating = true -- needed for power distribution
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
power_switched(pos)
|
||||
end
|
||||
|
||||
local function stop_node(pos, mem, state)
|
||||
techage.power.power_distribution(pos)
|
||||
mem.generating = false
|
||||
minetest.get_node_timer(pos):stop()
|
||||
power_switched(pos)
|
||||
mem.provided = 0
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
|
@ -63,45 +65,25 @@ local State = techage.NodeStates:new({
|
|||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
formspec_func = formspec,
|
||||
can_start = turbine_running,
|
||||
can_start = can_start,
|
||||
start_node = start_node,
|
||||
stop_node = stop_node,
|
||||
})
|
||||
|
||||
-- Pass1: Power balance calculation
|
||||
local function on_power_pass1(pos, mem)
|
||||
if State:is_active(mem) then
|
||||
return -POWER_CAPACITY * (mem.power_level or 4) / 4
|
||||
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)
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
end
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if turbine_running(pos) then
|
||||
distibuting(pos, mem)
|
||||
--print("generator", mem.triggered, mem.generating, PWR_CAPA * (mem.power_level or 0))
|
||||
mem.triggered = mem.triggered or 0
|
||||
if mem.triggered > 0 and mem.generating then
|
||||
mem.provided = provide_power(pos, PWR_CAPA * (mem.power_level or 0))
|
||||
mem.triggered = mem.triggered - 1
|
||||
State:keep_running(pos, mem, COUNTDOWN_TICKS)
|
||||
elseif mem.generating then -- trigger missing
|
||||
State:stop(pos, mem)
|
||||
mem.generating = 0
|
||||
mem.provided = 0
|
||||
else
|
||||
State:fault(pos, mem)
|
||||
techage.power.power_distribution(pos)
|
||||
mem.provided = 0
|
||||
end
|
||||
return State:is_active(mem)
|
||||
end
|
||||
|
@ -120,8 +102,10 @@ end
|
|||
|
||||
local function on_rightclick(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
techage.power.power_distribution(pos)
|
||||
M(pos):set_string("formspec", formspec(State, pos, mem))
|
||||
if mem.generating then
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("techage:generator", {
|
||||
|
@ -144,15 +128,10 @@ minetest.register_node("techage:generator", {
|
|||
on_rightclick(pos)
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
|
||||
drop = "",
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
@ -213,9 +192,6 @@ minetest.register_craft({
|
|||
})
|
||||
|
||||
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,
|
||||
})
|
||||
|
@ -223,11 +199,19 @@ techage.power.register_node({"techage:generator", "techage:generator_on"}, {
|
|||
-- for logical communication
|
||||
techage.register_node({"techage:generator", "techage:generator_on"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
print("generator", topic, payload)
|
||||
--print("generator", topic, payload)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if topic == "power_level" then
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.power_level = payload
|
||||
elseif topic == "trigger" then
|
||||
mem.triggered = 2
|
||||
mem.power_level = payload
|
||||
if mem.generating then
|
||||
return math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.1)
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
|
@ -23,6 +23,16 @@ local I,_ = dofile(MP.."/intllib.lua")
|
|||
|
||||
local Pipe = techage.SteamPipe
|
||||
|
||||
local function transfer_cooler(pos, topic, payload)
|
||||
return techage.transfer(pos, 6, topic, payload, Pipe,
|
||||
{"techage:cooler", "techage:cooler_on"})
|
||||
end
|
||||
|
||||
local function transfer_generator(pos, topic, payload)
|
||||
return techage.transfer(pos, "R", topic, payload, nil,
|
||||
{"techage:generator", "techage:generator_on"})
|
||||
end
|
||||
|
||||
local function swap_node(pos, name)
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == name then
|
||||
|
@ -54,7 +64,7 @@ end
|
|||
-- called with any pipe change
|
||||
local function after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
techage.transfer(pos, 6, "stop", nil, Pipe, {"techage:cooler_on"})
|
||||
transfer_cooler(pos, "stop", nil)
|
||||
swap_node(pos, "techage:turbine")
|
||||
mem.running = false
|
||||
stop_sound(pos)
|
||||
|
@ -127,27 +137,32 @@ techage.power.register_node({"techage:turbine", "techage:turbine_on"}, {
|
|||
-- for logical communication
|
||||
techage.register_node({"techage:turbine", "techage:turbine_on"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
print("turbine", topic, payload)
|
||||
--print("turbine", topic, payload)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if topic == "power_level" then
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.power_level = payload
|
||||
techage.transfer(pos, "R", topic, payload, nil,
|
||||
{"techage:generator", "techage:generator_on"})
|
||||
if topic == "trigger" then
|
||||
return transfer_generator(pos, topic, payload)
|
||||
elseif topic == "start" then
|
||||
local on = techage.transfer(pos, 6, "start", nil, Pipe, {"techage:cooler"})
|
||||
if on then
|
||||
if transfer_cooler(pos, topic, payload) then
|
||||
swap_node(pos, "techage:turbine_on")
|
||||
mem.running = true
|
||||
play_sound(pos)
|
||||
return true
|
||||
end
|
||||
return on
|
||||
return false
|
||||
elseif topic == "running" then
|
||||
if not transfer_cooler(pos, topic, payload) then
|
||||
swap_node(pos, "techage:turbine")
|
||||
mem.running = false
|
||||
stop_sound(pos)
|
||||
return false
|
||||
end
|
||||
return true
|
||||
elseif topic == "stop" then
|
||||
techage.transfer(pos, 6, "stop", nil, Pipe, {"techage:cooler_on"})
|
||||
transfer_cooler(pos, topic, payload)
|
||||
swap_node(pos, "techage:turbine")
|
||||
mem.running = false
|
||||
stop_sound(pos)
|
||||
return false
|
||||
return true
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
|
@ -21,9 +21,12 @@ local M = minetest.get_meta
|
|||
local MP = minetest.get_modpath("techage")
|
||||
local I,_ = dofile(MP.."/intllib.lua")
|
||||
|
||||
local POWER_CONSUMPTION = 3
|
||||
local PWR_NEEDED = 3
|
||||
local CYCLE_TIME = 2
|
||||
|
||||
local Power = techage.ElectricCable
|
||||
local consume_power = techage.power.consume_power
|
||||
local power_available = techage.power.power_available
|
||||
|
||||
local function infotext(pos, state)
|
||||
M(pos):set_string("infotext", I("TA3 Booster")..": "..state)
|
||||
|
@ -38,43 +41,24 @@ local function swap_node(pos, name)
|
|||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function play_sound(pos)
|
||||
local function node_timer(pos, elapsed)
|
||||
--print("node_timer sink "..S(pos))
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.running then
|
||||
mem.handle = minetest.sound_play("techage_booster", {
|
||||
pos = pos,
|
||||
gain = 1,
|
||||
max_hear_distance = 7})
|
||||
minetest.after(2, play_sound, pos)
|
||||
end
|
||||
end
|
||||
|
||||
local function stop_sound(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.handle then
|
||||
minetest.sound_stop(mem.handle)
|
||||
mem.handle = nil
|
||||
end
|
||||
end
|
||||
|
||||
local function on_power_pass1(pos, mem)
|
||||
--print("on_power_pass1")
|
||||
if mem.running then
|
||||
mem.correction = POWER_CONSUMPTION
|
||||
else
|
||||
mem.correction = 0
|
||||
end
|
||||
return mem.correction
|
||||
end
|
||||
|
||||
local function on_power_pass2(pos, mem, sum)
|
||||
if sum > 0 then
|
||||
mem.has_power = true
|
||||
return 0
|
||||
else
|
||||
mem.has_power = false
|
||||
return -mem.correction
|
||||
local got = consume_power(pos, PWR_NEEDED)
|
||||
if got < PWR_NEEDED then
|
||||
swap_node(pos, "techage:ta3_booster")
|
||||
else
|
||||
swap_node(pos, "techage:ta3_booster_on")
|
||||
minetest.sound_play("techage_booster", {
|
||||
pos = pos,
|
||||
gain = 1,
|
||||
max_hear_distance = 7})
|
||||
end
|
||||
return true
|
||||
end
|
||||
swap_node(pos, "techage:ta3_booster")
|
||||
return false
|
||||
end
|
||||
|
||||
minetest.register_node("techage:ta3_booster", {
|
||||
|
@ -90,13 +74,13 @@ minetest.register_node("techage:ta3_booster", {
|
|||
},
|
||||
|
||||
on_construct = tubelib2.init_mem,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local node = minetest.get_node(pos)
|
||||
local indir = techage.side_to_indir("R", node.param2)
|
||||
M(pos):set_int("indir", indir)
|
||||
infotext(pos, "stopped")
|
||||
end,
|
||||
on_time = node_timer,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
|
@ -135,6 +119,7 @@ minetest.register_node("techage:ta3_booster_on", {
|
|||
},
|
||||
},
|
||||
|
||||
on_time = node_timer,
|
||||
paramtype2 = "facedir",
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
diggable = false,
|
||||
|
@ -144,8 +129,6 @@ minetest.register_node("techage:ta3_booster_on", {
|
|||
})
|
||||
|
||||
techage.power.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
|
||||
on_power_pass1 = on_power_pass1,
|
||||
on_power_pass2 = on_power_pass2,
|
||||
power_network = Power,
|
||||
conn_sides = {"F", "B", "U", "D"},
|
||||
})
|
||||
|
@ -157,27 +140,23 @@ techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
|
|||
if M(pos):get_int("indir") == in_dir then
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if topic == "power" then
|
||||
return mem.has_power
|
||||
return power_available(pos)
|
||||
elseif topic == "start" then
|
||||
if mem.has_power then
|
||||
if power_available(pos) then
|
||||
mem.running = true
|
||||
play_sound(pos)
|
||||
swap_node(pos, "techage:ta3_booster_on")
|
||||
infotext(pos, "running")
|
||||
techage.power.power_distribution(pos)
|
||||
else
|
||||
infotext(pos, "no power")
|
||||
end
|
||||
elseif topic == "stop" then
|
||||
mem.running = false
|
||||
stop_sound(pos)
|
||||
swap_node(pos, "techage:ta3_booster")
|
||||
if mem.has_power then
|
||||
infotext(pos, "stopped")
|
||||
else
|
||||
infotext(pos, "no power")
|
||||
end
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -196,14 +175,3 @@ techage.register_help_page(I("TA3 Booster"),
|
|||
I([[Part of the TA3 Industrial Furnace
|
||||
and further machines.
|
||||
Used to increase the air/gas pressure.]]), "techage:ta3_booster")
|
||||
|
||||
|
||||
minetest.register_lbm({
|
||||
label = "[techage] Booster sound",
|
||||
name = "techage:booster",
|
||||
nodenames = {"techage:ta3_booster_on"},
|
||||
run_at_every_load = true,
|
||||
action = function(pos, node)
|
||||
play_sound(pos)
|
||||
end
|
||||
})
|
||||
|
|
|
@ -172,15 +172,6 @@ tiles.pas = {
|
|||
"techage_concrete.png^techage_appl_furnace.png^techage_frame_ta#.png",
|
||||
}
|
||||
tiles.act = tiles.pas
|
||||
tiles.def = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_concrete.png^techage_frame_ta#_top.png",
|
||||
"techage_concrete.png^techage_frame_ta#_top.png",
|
||||
"techage_concrete.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_concrete.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_concrete.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_concrete.png^techage_appl_furnace.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
}
|
||||
|
||||
local tubing = {
|
||||
on_pull_item = function(pos, in_dir, num)
|
||||
|
@ -194,6 +185,7 @@ local tubing = {
|
|||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
|
||||
local inv = M(pos):get_inventory()
|
||||
CRD(pos).State:start_if_standby(pos)
|
||||
return techage.put_items(inv, "src", stack)
|
||||
end
|
||||
end,
|
||||
|
@ -215,9 +207,6 @@ local tubing = {
|
|||
on_node_load = function(pos)
|
||||
CRD(pos).State:on_node_load(pos)
|
||||
end,
|
||||
on_node_repair = function(pos)
|
||||
return CRD(pos).State:on_node_repair(pos)
|
||||
end,
|
||||
}
|
||||
|
||||
local _, node_name_ta3, _ =
|
||||
|
@ -225,8 +214,6 @@ local _, node_name_ta3, _ =
|
|||
drawtype = "normal",
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
has_item_meter = true,
|
||||
aging_factor = 10,
|
||||
formspec = formspec,
|
||||
tubing = tubing,
|
||||
on_state_change = on_node_state_change,
|
||||
|
|
11
init.lua
|
@ -13,7 +13,6 @@ elseif minetest.global_exists("tubelib2") and tubelib2.version < 1.4 then
|
|||
else
|
||||
techage.max_num_forceload_blocks = tonumber(minetest.setting_get("techage_max_num_forceload_blocks")) or 12
|
||||
techage.basalt_stone_enabled = minetest.setting_get("techage_basalt_stone_enabled") == "true"
|
||||
techage.machine_aging_value = tonumber(minetest.setting_get("techage_machine_aging_value")) or 100
|
||||
techage.ore_rarity = tonumber(minetest.setting_get("techage_ore_rarity")) or 1
|
||||
techage.modified_recipes_enabled = minetest.setting_get("techage_modified_recipes_enabled") == "true"
|
||||
|
||||
|
@ -29,7 +28,6 @@ else
|
|||
dofile(MP.."/basis/node_states.lua") -- state model
|
||||
dofile(MP.."/basis/tubes.lua") -- tubelib replacement
|
||||
dofile(MP.."/basis/command.lua") -- tubelib replacement
|
||||
dofile(MP.."/basis/consumer.lua") -- consumer base model
|
||||
dofile(MP.."/basis/firebox_lib.lua") -- common firebox functions
|
||||
dofile(MP.."/basis/mark.lua")
|
||||
dofile(MP.."/basis/assemble.lua")
|
||||
|
@ -82,6 +80,7 @@ else
|
|||
dofile(MP.."/steam_engine/gearbox.lua")
|
||||
|
||||
-- Basic Machines
|
||||
dofile(MP.."/basis/consumer.lua") -- consumer base model
|
||||
dofile(MP.."/basic_machines/source.lua")
|
||||
dofile(MP.."/basic_machines/pusher.lua")
|
||||
dofile(MP.."/basic_machines/blackhole.lua")
|
||||
|
@ -136,8 +135,8 @@ else
|
|||
|
||||
-- Test
|
||||
dofile(MP.."/recipe_checker.lua")
|
||||
dofile(MP.."/test/sink.lua")
|
||||
dofile(MP.."/test/source.lua")
|
||||
dofile(MP.."/test/akku.lua")
|
||||
dofile(MP.."/test/switch.lua")
|
||||
--dofile(MP.."/.test/sink.lua")
|
||||
--dofile(MP.."/.test/source.lua")
|
||||
--dofile(MP.."/.test/akku.lua")
|
||||
--dofile(MP.."/.test/switch.lua")
|
||||
end
|
|
@ -3,9 +3,11 @@ 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
|
||||
|
||||
local POWER_CONSUMPTION = 0.5
|
||||
local PWR_NEEDED = 0.5
|
||||
local CYCLE_TIME = 2
|
||||
|
||||
local Power = techage.ElectricCable
|
||||
local Cable = techage.ElectricCable
|
||||
local consume_power = techage.power.consume_power
|
||||
|
||||
local function swap_node(pos, postfix)
|
||||
local node = techage.get_node_lvm(pos)
|
||||
|
@ -17,23 +19,20 @@ local function swap_node(pos, postfix)
|
|||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function on_power_pass1(pos, mem)
|
||||
local function node_timer(pos, elapsed)
|
||||
--print("node_timer lamp "..S(pos))
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.running then
|
||||
mem.correction = POWER_CONSUMPTION
|
||||
else
|
||||
mem.correction = 0
|
||||
end
|
||||
return mem.correction
|
||||
end
|
||||
|
||||
local function on_power_pass2(pos, mem, sum)
|
||||
if sum > 0 and mem.running then
|
||||
swap_node(pos, "on")
|
||||
return 0
|
||||
else
|
||||
swap_node(pos, "off")
|
||||
return -mem.correction
|
||||
local got = consume_power(pos, PWR_NEEDED)
|
||||
if got < PWR_NEEDED then
|
||||
swap_node(pos, "off")
|
||||
else
|
||||
swap_node(pos, "on")
|
||||
end
|
||||
return true
|
||||
end
|
||||
swap_node(pos, "off")
|
||||
return false
|
||||
end
|
||||
|
||||
local function lamp_on_rightclick(pos, node, clicker)
|
||||
|
@ -43,10 +42,13 @@ local function lamp_on_rightclick(pos, node, clicker)
|
|||
local mem = tubelib2.get_mem(pos)
|
||||
if not mem.running then
|
||||
mem.running = true
|
||||
node_timer(pos, 2)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
else
|
||||
mem.running = false
|
||||
minetest.get_node_timer(pos):stop()
|
||||
swap_node(pos, "off")
|
||||
end
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
|
||||
local function on_rotate(pos, node, user, mode, new_param2)
|
||||
|
@ -73,6 +75,7 @@ function techage.register_lamp(basename, ndef_off, ndef_on)
|
|||
ndef_off.on_construct = tubelib2.init_mem
|
||||
ndef_off.on_rightclick = lamp_on_rightclick
|
||||
ndef_off.on_rotate = on_rotate
|
||||
ndef_off.on_timer = node_timer
|
||||
ndef_off.on_place = on_place
|
||||
ndef_off.paramtype = "light"
|
||||
ndef_off.light_source = 0
|
||||
|
@ -85,6 +88,7 @@ function techage.register_lamp(basename, ndef_off, ndef_on)
|
|||
ndef_on.on_construct = tubelib2.init_mem
|
||||
ndef_on.on_rightclick = lamp_on_rightclick
|
||||
ndef_on.on_rotate = on_rotate
|
||||
ndef_on.on_timer = node_timer
|
||||
ndef_on.paramtype = "light"
|
||||
ndef_on.light_source = minetest.LIGHT_MAX
|
||||
ndef_on.sunlight_propagates = true
|
||||
|
@ -98,9 +102,7 @@ function techage.register_lamp(basename, ndef_off, ndef_on)
|
|||
minetest.register_node(basename.."_on", ndef_on)
|
||||
|
||||
techage.power.register_node({basename.."_off", basename.."_on"}, {
|
||||
on_power_pass1 = on_power_pass1,
|
||||
on_power_pass2 = on_power_pass2,
|
||||
power_network = Power,
|
||||
power_network = Cable,
|
||||
conn_sides = ndef_off.conn_sides or determine_power_side, -- will be handled by clbk function
|
||||
})
|
||||
end
|
||||
|
|
|
@ -212,15 +212,6 @@ tiles.pas = {
|
|||
"techage_filling_ta#.png^techage_appl_oildrill.png^techage_frame_ta#.png",
|
||||
}
|
||||
tiles.act = tiles.pas
|
||||
tiles.def = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta#.png^techage_frame_ta#_top.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_appl_oildrill.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_appl_oildrill.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
}
|
||||
|
||||
local tubing = {
|
||||
on_pull_item = function(pos, in_dir, num)
|
||||
|
@ -234,6 +225,7 @@ local tubing = {
|
|||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
|
||||
local inv = M(pos):get_inventory()
|
||||
CRD(pos).State:start_if_standby(pos)
|
||||
return techage.put_items(inv, "src", stack)
|
||||
end
|
||||
end,
|
||||
|
@ -255,9 +247,6 @@ local tubing = {
|
|||
on_node_load = function(pos)
|
||||
CRD(pos).State:on_node_load(pos)
|
||||
end,
|
||||
on_node_repair = function(pos)
|
||||
return CRD(pos).State:on_node_repair(pos)
|
||||
end,
|
||||
}
|
||||
|
||||
local _, node_name_ta3, _ =
|
||||
|
@ -265,8 +254,6 @@ local _, node_name_ta3, _ =
|
|||
drawtype = "normal",
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
has_item_meter = true,
|
||||
aging_factor = 10,
|
||||
formspec = formspec,
|
||||
tubing = tubing,
|
||||
on_state_change = on_node_state_change,
|
||||
|
|
|
@ -138,15 +138,6 @@ tiles.act = {
|
|||
"techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.png^[transformR90]",
|
||||
"techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.png^[transformR90]",
|
||||
}
|
||||
tiles.def = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png",
|
||||
"techage_appl_pumpjack.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_appl_pumpjack.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_defect.png",
|
||||
}
|
||||
|
||||
local tubing = {
|
||||
is_pusher = true, -- is a pulling/pushing node
|
||||
|
@ -162,17 +153,12 @@ local tubing = {
|
|||
on_node_load = function(pos)
|
||||
CRD(pos).State:on_node_load(pos)
|
||||
end,
|
||||
on_node_repair = function(pos)
|
||||
return CRD(pos).State:on_node_repair(pos)
|
||||
end,
|
||||
}
|
||||
|
||||
local _, node_name_ta3, _ =
|
||||
techage.register_consumer("pumpjack", I("TA3 Oil Pumpjack"), tiles, {
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
has_item_meter = true,
|
||||
aging_factor = 10,
|
||||
formspec = formspec,
|
||||
tubing = tubing,
|
||||
after_place_node = function(pos, placer)
|
||||
|
|
248
power/power.lua
|
@ -24,6 +24,12 @@ local PWRN = function(node) return (minetest.registered_nodes[node.name] or {}).
|
|||
-- Used to determine the already passed nodes while power distribution
|
||||
local Route = {}
|
||||
|
||||
local function in_range(val, min, max)
|
||||
if val < min then return min end
|
||||
if val > max then return max end
|
||||
return val
|
||||
end
|
||||
|
||||
local function pos_already_reached(pos)
|
||||
local key = minetest.hash_node_position(pos)
|
||||
if not Route[key] then
|
||||
|
@ -32,7 +38,7 @@ local function pos_already_reached(pos)
|
|||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
local SideToDir = {B=1, R=2, F=3, L=4, D=5, U=6}
|
||||
|
||||
local function side_to_dir(param2, side)
|
||||
|
@ -94,58 +100,101 @@ local function matching_nodes(pos, peer_pos)
|
|||
return not tube_type1 or not tube_type2 or tube_type1 == tube_type2
|
||||
end
|
||||
|
||||
local function get_clbk(pos, clbk_name)
|
||||
local pwr = PWR(pos)
|
||||
return pwr and pwr[clbk_name]
|
||||
end
|
||||
|
||||
local function connection_walk(pos, clbk_name, sum)
|
||||
local function connection_walk(pos, clbk)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.interrupted_dirs = mem.interrupted_dirs or {}
|
||||
local clbk = get_clbk(pos, clbk_name)
|
||||
--print("connection_walk", S(pos), sum, clbk)
|
||||
if clbk then
|
||||
sum = sum - (clbk(pos, mem, sum) or 0)
|
||||
clbk(pos, mem)
|
||||
end
|
||||
for out_dir,item in pairs(mem.connections or {}) do
|
||||
if item.pos and not pos_already_reached(item.pos) and
|
||||
not mem.interrupted_dirs[out_dir] then
|
||||
sum = connection_walk(item.pos, clbk_name, sum)
|
||||
connection_walk(item.pos, clbk)
|
||||
end
|
||||
end
|
||||
return sum
|
||||
end
|
||||
|
||||
-- Start the overall power consumption and depending on that
|
||||
-- turn nodes on/off
|
||||
local function power_distribution(pos)
|
||||
local sum = 0
|
||||
Route = {}
|
||||
pos_already_reached(pos)
|
||||
sum = connection_walk(pos, "on_power_pass1", sum)
|
||||
Route = {}
|
||||
pos_already_reached(pos)
|
||||
sum = connection_walk(pos, "on_power_pass2", sum)
|
||||
Route = {}
|
||||
pos_already_reached(pos)
|
||||
sum = connection_walk(pos, "on_power_pass3", sum)
|
||||
--print("power sum = "..sum)
|
||||
end
|
||||
|
||||
local function register_lbm(name)
|
||||
minetest.register_lbm({
|
||||
label = "[TechAge] Node update",
|
||||
nodenames = {name},
|
||||
name = name.."_update",
|
||||
run_at_every_load = true,
|
||||
action = function(pos, node)
|
||||
local pwr = PWRN(node)
|
||||
-- repair power_dirs
|
||||
if pwr and pwr.conn_sides and M(pos):get_string("power_dirs") == "" then
|
||||
set_conn_dirs(pos, pwr.conn_sides)
|
||||
-- determine one "generating" node as master (largest hash number)
|
||||
local function determine_master(pos)
|
||||
Route = {}
|
||||
pos_already_reached(pos)
|
||||
local hash = 0
|
||||
local master = nil
|
||||
connection_walk(pos, function(pos, mem)
|
||||
if mem.generating then
|
||||
local new = minetest.hash_node_position(pos)
|
||||
if hash <= new then
|
||||
hash = new
|
||||
master = pos
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
end)
|
||||
return master
|
||||
end
|
||||
|
||||
-- store master position on all network nodes
|
||||
local function store_master(pos, master_pos)
|
||||
Route = {}
|
||||
pos_already_reached(pos)
|
||||
connection_walk(pos, function(pos, mem)
|
||||
mem.master_pos = master_pos
|
||||
mem.is_master = false
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
-- called from any generator
|
||||
local function on_power_switch(pos)
|
||||
print("on_power_change"..S(pos))
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.master_pos = nil
|
||||
mem.is_master = nil
|
||||
|
||||
local mpos = determine_master(pos)
|
||||
store_master(pos, mpos)
|
||||
if mpos then
|
||||
print("master = "..S(mpos))
|
||||
local mem = tubelib2.get_mem(mpos)
|
||||
mem.is_master = true
|
||||
return mem
|
||||
end
|
||||
end
|
||||
|
||||
local function min(val, max)
|
||||
if val < 0 then return 0 end
|
||||
if val > max then return max end
|
||||
return val
|
||||
end
|
||||
|
||||
-- called from master every 2 seconds
|
||||
local function accounting(mem)
|
||||
-- defensive programming
|
||||
mem.needed1 = mem.needed1 or 0
|
||||
mem.needed2 = mem.needed2 or 0
|
||||
mem.available1 = mem.available1 or 0
|
||||
mem.available2 = mem.available2 or 0
|
||||
-- calculate the primary and secondary supply and demand
|
||||
mem.supply1 = min(mem.needed1 + mem.needed2, mem.available1)
|
||||
mem.demand1 = min(mem.needed1, mem.available1 + mem.available2)
|
||||
mem.supply2 = min(mem.demand1 - mem.supply1, mem.available2)
|
||||
mem.demand2 = min(mem.supply1 - mem.demand1, mem.available1)
|
||||
mem.reserve = (mem.available1 + mem.available1) > mem.needed1
|
||||
print("needed = "..mem.needed1.."/"..mem.needed2..", available = "..mem.available1.."/"..mem.available2)
|
||||
print("supply = "..mem.supply1.."/"..mem.supply2..", demand = "..mem.demand1.."/"..mem.demand2..", reserve = "..dump(mem.reserve))
|
||||
-- reset values for nect cycle
|
||||
mem.needed1 = 0
|
||||
mem.needed2 = 0
|
||||
mem.available1 = 0
|
||||
mem.available2 = 0
|
||||
end
|
||||
|
||||
-- called from tubelib2.after_tube_update
|
||||
local function on_network_change(pos)
|
||||
local mem = on_power_switch(pos)
|
||||
if mem then
|
||||
accounting(mem)
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
|
@ -153,7 +202,8 @@ end
|
|||
--
|
||||
techage.power = {}
|
||||
|
||||
techage.power.power_distribution = power_distribution
|
||||
techage.power.power_switched = on_power_switch
|
||||
techage.power.on_network_change = on_network_change
|
||||
|
||||
-- Used to turn on/off the power by means of a power switch
|
||||
function techage.power.power_cut(pos, dir, cable, cut)
|
||||
|
@ -172,12 +222,12 @@ function techage.power.power_cut(pos, dir, cable, cut)
|
|||
mem.interrupted_dirs = {true, true, true, true, true, true}
|
||||
for dir,_ in pairs(mem.connections) do
|
||||
mem.interrupted_dirs[dir] = false
|
||||
power_distribution(npos)
|
||||
on_power_switch(npos)
|
||||
mem.interrupted_dirs[dir] = true
|
||||
end
|
||||
else
|
||||
mem.interrupted_dirs = {}
|
||||
power_distribution(npos)
|
||||
on_power_switch(npos)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -187,9 +237,6 @@ function techage.power.register_node(names, pwr_def)
|
|||
if ndef then
|
||||
minetest.override_item(name, {
|
||||
power = {
|
||||
on_power_pass1 = pwr_def.on_power_pass1,
|
||||
on_power_pass2 = pwr_def.on_power_pass2,
|
||||
on_power_pass3 = pwr_def.on_power_pass3,
|
||||
conn_sides = pwr_def.conn_sides or {"L", "R", "U", "D", "F", "B"},
|
||||
power_network = pwr_def.power_network,
|
||||
after_place_node = ndef.after_place_node,
|
||||
|
@ -227,38 +274,121 @@ function techage.power.register_node(names, pwr_def)
|
|||
mem.connections[out_dir] = {pos = peer_pos, in_dir = peer_in_dir}
|
||||
end
|
||||
-- To be called delayed, so that all network connections have been established
|
||||
minetest.after(0.2, power_distribution, pos)
|
||||
minetest.after(0.2, on_network_change, pos)
|
||||
if pwr.after_tube_update then
|
||||
return pwr.after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
|
||||
end
|
||||
end,
|
||||
})
|
||||
pwr_def.power_network:add_secondary_node_names({name})
|
||||
register_lbm(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function techage.power.consume_power(pos, needed)
|
||||
local master_pos = tubelib2.get_mem(pos).master_pos
|
||||
if master_pos then
|
||||
local mem = tubelib2.get_mem(master_pos)
|
||||
-- for next cycle
|
||||
mem.needed1 = (mem.needed1 or 0) + needed
|
||||
-- current cycle
|
||||
mem.demand1 = mem.demand1 or 0
|
||||
local val = math.min(needed, mem.demand1)
|
||||
mem.demand1 = mem.demand1 - val
|
||||
return val
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function techage.power.provide_power(pos, provide)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.is_master then
|
||||
accounting(mem)
|
||||
elseif mem.master_pos then
|
||||
mem = tubelib2.get_mem(mem.master_pos)
|
||||
else
|
||||
return 0
|
||||
end
|
||||
-- for next cycle
|
||||
mem.available1 = (mem.available1 or 0) + provide
|
||||
-- current cycle
|
||||
mem.supply1 = mem.supply1 or 0
|
||||
local val = math.min(provide, mem.supply1)
|
||||
mem.supply1 = mem.supply1 - val
|
||||
return val
|
||||
end
|
||||
|
||||
function techage.power.secondary_power(pos, provide, needed)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.is_master then
|
||||
accounting(mem)
|
||||
elseif mem.master_pos then
|
||||
mem = tubelib2.get_mem(mem.master_pos)
|
||||
else
|
||||
return 0
|
||||
end
|
||||
-- for next cycle
|
||||
mem.available2 = (mem.available2 or 0) + provide
|
||||
mem.needed2 = (mem.needed2 or 0) + needed
|
||||
|
||||
-- defensive programming
|
||||
mem.supply2 = mem.supply2 or 0
|
||||
mem.demand2 = mem.demand2 or 0
|
||||
|
||||
-- check as generator
|
||||
if mem.supply2 > 0 then
|
||||
local val = math.min(provide, mem.supply2)
|
||||
mem.supply2 = mem.supply2 - val
|
||||
return val
|
||||
end
|
||||
-- check as consumer
|
||||
if mem.demand2 > 0 then
|
||||
local val = math.min(needed, mem.demand2)
|
||||
mem.demand2 = mem.demand2 - val
|
||||
return -val
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function techage.power.power_available(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.is_master then
|
||||
return mem.reserve
|
||||
elseif mem.master_pos then
|
||||
mem = tubelib2.get_mem(mem.master_pos)
|
||||
return mem.reserve
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function techage.power.percent(max_val, curr_val)
|
||||
return math.min(math.ceil(((curr_val or 0) * 100.0) / (max_val or 1.0)), 100)
|
||||
end
|
||||
|
||||
function techage.power.formspec_load_bar(charging, max_val)
|
||||
local percent
|
||||
charging = charging or 0
|
||||
max_val = max_val or 1
|
||||
if charging ~= 0 then
|
||||
percent = 50 + math.ceil((charging * 50.0) / max_val)
|
||||
end
|
||||
|
||||
if charging > 0 then
|
||||
return "techage_form_level_off.png^[lowpart:"..percent..":techage_form_level_charge.png"
|
||||
elseif charging < 0 then
|
||||
return "techage_form_level_unload.png^[lowpart:"..percent..":techage_form_level_off.png"
|
||||
else
|
||||
return "techage_form_level_off.png"
|
||||
end
|
||||
end
|
||||
|
||||
function techage.power.formspec_power_bar(max_power, current_power)
|
||||
local percent = techage.power.percent(max_power, current_power)
|
||||
return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png"
|
||||
end
|
||||
|
||||
-- charging is true, false, or nil if turned off
|
||||
function techage.power.formspec_load_bar(charging)
|
||||
if charging ~= nil then
|
||||
if charging then
|
||||
return "techage_form_level_charge.png"
|
||||
else
|
||||
return "techage_form_level_unload.png"
|
||||
end
|
||||
end
|
||||
return "techage_form_level_off.png"
|
||||
end
|
||||
|
||||
function techage.power.side_to_outdir(pos, side)
|
||||
local node = minetest.get_node(pos)
|
||||
|
|
|
@ -176,6 +176,7 @@ local function on_network_change(pos)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Generic API functions
|
||||
--
|
||||
|
|
|
@ -38,7 +38,7 @@ local Water = {
|
|||
|
||||
local function formspec(self, pos, mem)
|
||||
local temp = mem.temperature or 20
|
||||
local bar = mem.running and 3 or 0
|
||||
local ratio = mem.power_ratio or 0
|
||||
return "size[8,7]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
|
@ -51,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(10, bar).."]"..
|
||||
"image[7,0.5;1,2;"..techage.power.formspec_power_bar(1, ratio).."]"..
|
||||
"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;]"..
|
||||
|
@ -65,11 +65,10 @@ local function can_start(pos, mem, state)
|
|||
end
|
||||
|
||||
local function start_node(pos, mem, state)
|
||||
mem.running = techage.transfer(pos, 6, "start", nil, Pipe, {"techage:cylinder"})
|
||||
mem.running = true
|
||||
end
|
||||
|
||||
local function stop_node(pos, mem, state)
|
||||
techage.transfer(pos, 6, "stop", nil, Pipe, {"techage:cylinder_on"})
|
||||
mem.running = false
|
||||
end
|
||||
|
||||
|
@ -115,7 +114,8 @@ local function water_temperature(pos, mem)
|
|||
end
|
||||
|
||||
local function steaming(pos, mem, temp)
|
||||
mem.water_level = math.max((mem.water_level or 0) - WATER_CONSUMPTION, 0)
|
||||
local wc = WATER_CONSUMPTION * (mem.power_ratio or 1)
|
||||
mem.water_level = math.max((mem.water_level or 0) - wc, 0)
|
||||
if temp >= 80 then
|
||||
if mem.running then
|
||||
State:keep_running(pos, mem, COUNTDOWN_TICKS)
|
||||
|
@ -142,6 +142,7 @@ local function on_receive_fields(pos, formname, fields, player)
|
|||
return
|
||||
end
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.temperature = mem.temperature or 20
|
||||
State:state_button_event(pos, mem, fields)
|
||||
|
||||
if fields.update then
|
||||
|
@ -161,7 +162,7 @@ end
|
|||
local function can_dig(pos, player)
|
||||
local inv = M(pos):get_inventory()
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
return inv:is_empty("water") and inv:is_empty("input") and not mem.running
|
||||
return inv:is_empty("input") and not mem.running
|
||||
end
|
||||
|
||||
local function move_to_water(pos)
|
||||
|
@ -261,15 +262,10 @@ minetest.register_node("techage:boiler2", {
|
|||
end
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_metadata_inventory_put = function(pos)
|
||||
minetest.after(0.5, move_to_water, pos)
|
||||
end,
|
||||
|
||||
drop = "",
|
||||
groups = {cracky=1},
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
|
@ -289,6 +285,13 @@ techage.register_node({"techage:boiler2"}, {
|
|||
if not minetest.get_node_timer(pos):is_started() then
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
if mem.running then
|
||||
mem.power_ratio = techage.transfer(pos, 6, "trigger", nil, Pipe, {
|
||||
"techage:cylinder", "techage:cylinder_on"}) or 0
|
||||
return mem.power_ratio
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
|
@ -32,24 +32,11 @@ local function swap_node(pos, name)
|
|||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
-- called from flywheel
|
||||
local function start_cylinder(pos, on)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if on and mem.running then
|
||||
swap_node(pos, "techage:cylinder_on")
|
||||
techage.power.power_distribution(pos)
|
||||
return true
|
||||
else
|
||||
swap_node(pos, "techage:cylinder")
|
||||
techage.power.power_distribution(pos)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- called with any pipe change
|
||||
local function after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.running = false
|
||||
swap_node(pos, "techage:cylinder")
|
||||
end
|
||||
|
||||
minetest.register_node("techage:cylinder", {
|
||||
|
@ -65,8 +52,6 @@ minetest.register_node("techage:cylinder", {
|
|||
},
|
||||
|
||||
on_construct = tubelib2.init_mem,
|
||||
start_cylinder = start_cylinder,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
@ -104,9 +89,7 @@ minetest.register_node("techage:cylinder_on", {
|
|||
},
|
||||
},
|
||||
|
||||
start_cylinder = start_cylinder,
|
||||
after_tube_update = after_tube_update,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
diggable = false,
|
||||
|
@ -124,12 +107,27 @@ techage.power.register_node({"techage:cylinder", "techage:cylinder_on"}, {
|
|||
techage.register_node({"techage:cylinder", "techage:cylinder_on"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if topic == "start" then
|
||||
mem.running = true
|
||||
return true
|
||||
if topic == "trigger" then
|
||||
local power = techage.transfer(pos, "R", "trigger", nil, nil, {
|
||||
"techage:flywheel", "techage:flywheel_on"}) or 0
|
||||
print("trigger", power, mem.running)
|
||||
|
||||
if not power then
|
||||
return 0
|
||||
elseif power > 0 and not mem.running then
|
||||
swap_node(pos, "techage:cylinder_on")
|
||||
mem.running = true
|
||||
return power
|
||||
elseif power <= 0 and mem.running then
|
||||
swap_node(pos, "techage:cylinder")
|
||||
mem.running = false
|
||||
return 0
|
||||
else
|
||||
return power
|
||||
end
|
||||
elseif topic == "stop" then
|
||||
swap_node(pos, "techage:cylinder")
|
||||
mem.running = false
|
||||
return false
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
|
@ -27,8 +27,9 @@ local CYCLE_TIME = 2
|
|||
|
||||
local function node_timer(pos, elapsed)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
print("firebox burn_cycles = "..(mem.burn_cycles or 0))
|
||||
if mem.running then
|
||||
techage.transfer(
|
||||
local power = techage.transfer(
|
||||
{x=pos.x, y=pos.y+2, z=pos.z},
|
||||
nil, -- outdir
|
||||
"trigger", -- topic
|
||||
|
@ -36,7 +37,7 @@ local function node_timer(pos, elapsed)
|
|||
nil, -- network
|
||||
{"techage:boiler2"} -- nodenames
|
||||
)
|
||||
mem.burn_cycles = (mem.burn_cycles or 0) - 1
|
||||
mem.burn_cycles = (mem.burn_cycles or 0) - math.max((power or 0.1), 0.1)
|
||||
if mem.burn_cycles <= 0 then
|
||||
local taken = firebox.get_fuel(pos)
|
||||
if taken then
|
||||
|
@ -167,6 +168,8 @@ minetest.register_lbm({
|
|||
run_at_every_load = true,
|
||||
action = function(pos, node)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.power_level = nil
|
||||
end
|
||||
})
|
||||
|
||||
|
|
|
@ -23,65 +23,50 @@ local I,_ = dofile(MP.."/intllib.lua")
|
|||
|
||||
local STANDBY_TICKS = 4
|
||||
local COUNTDOWN_TICKS = 4
|
||||
local CYCLE_TIME = 8
|
||||
local POWER_CAPACITY = 25
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_CAPA = 25
|
||||
|
||||
local Axle = techage.Axle
|
||||
local provide_power = techage.power.provide_power
|
||||
local power_switched = techage.power.power_switched
|
||||
|
||||
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;"..techage.power.formspec_power_bar(POWER_CAPACITY, mem.power_result).."]"..
|
||||
"image[6,0.5;1,2;"..techage.power.formspec_power_bar(PWR_CAPA, mem.provided).."]"..
|
||||
"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;]"..
|
||||
default.get_hotbar_bg(0, 3)
|
||||
end
|
||||
|
||||
local function start_cylinder(pos, on, mem)
|
||||
if not on then
|
||||
if mem.handle then
|
||||
minetest.sound_stop(mem.handle)
|
||||
mem.handle = nil
|
||||
end
|
||||
end
|
||||
local pos2 = techage.get_pos(pos, 'L')
|
||||
local ndef = minetest.registered_nodes[minetest.get_node(pos2).name]
|
||||
if ndef and ndef.start_cylinder then
|
||||
return ndef.start_cylinder(pos2, on)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function can_start(pos, mem, state)
|
||||
return start_cylinder(pos, true, mem)
|
||||
end
|
||||
|
||||
local function play_sound(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.techage_state == techage.RUNNING then
|
||||
mem.handle = minetest.sound_play("techage_steamengine", {
|
||||
pos = pos,
|
||||
gain = 0.5,
|
||||
max_hear_distance = 10})
|
||||
minetest.after(2, play_sound, pos)
|
||||
end
|
||||
return (mem.triggered or 0) > 0 -- by means of firebox
|
||||
end
|
||||
|
||||
local function start_node(pos, mem, state)
|
||||
techage.power.power_distribution(pos)
|
||||
if mem.power_result > 0 then
|
||||
techage.switch_axles(pos, true)
|
||||
play_sound(pos)
|
||||
end
|
||||
mem.generating = true -- needed for power distribution
|
||||
techage.switch_axles(pos, true)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
mem.handle = minetest.sound_play("techage_steamengine", {
|
||||
pos = pos,
|
||||
gain = 0.5,
|
||||
max_hear_distance = 10})
|
||||
power_switched(pos)
|
||||
end
|
||||
|
||||
local function stop_node(pos, mem, state)
|
||||
start_cylinder(pos, false, mem)
|
||||
techage.power.power_distribution(pos)
|
||||
mem.generating = false
|
||||
techage.switch_axles(pos, false)
|
||||
minetest.get_node_timer(pos):stop()
|
||||
if mem.handle then
|
||||
minetest.sound_stop(mem.handle)
|
||||
mem.handle = nil
|
||||
end
|
||||
power_switched(pos)
|
||||
mem.provided = 0
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
|
@ -95,43 +80,25 @@ 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)
|
||||
start_cylinder(pos, false, mem)
|
||||
techage.power.power_distribution(pos)
|
||||
end
|
||||
end
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
local pos2 = techage.get_pos(pos, 'L')
|
||||
if minetest.get_node(pos2).name == "techage:cylinder_on" and tubelib2.get_mem(pos2).running then
|
||||
distibuting(pos, mem)
|
||||
mem.triggered = mem.triggered or 0
|
||||
if mem.triggered > 0 and mem.generating then
|
||||
mem.provided = provide_power(pos, PWR_CAPA)
|
||||
mem.triggered = mem.triggered - 1
|
||||
State:keep_running(pos, mem, COUNTDOWN_TICKS)
|
||||
mem.handle = minetest.sound_play("techage_steamengine", {
|
||||
pos = pos,
|
||||
gain = 0.5,
|
||||
max_hear_distance = 10})
|
||||
elseif mem.generating then -- trigger missing
|
||||
State:stop(pos, mem)
|
||||
mem.generating = 0
|
||||
mem.provided = 0
|
||||
techage.transfer(pos, "L", "stop", nil, nil, {
|
||||
"techage:cylinder_on"})
|
||||
else
|
||||
State:fault(pos, mem)
|
||||
start_cylinder(pos, false, mem)
|
||||
techage.power.power_distribution(pos)
|
||||
mem.provided = 0
|
||||
end
|
||||
return State:is_active(mem)
|
||||
end
|
||||
|
@ -151,6 +118,9 @@ end
|
|||
local function on_rightclick(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
M(pos):set_string("formspec", formspec(State, pos, mem))
|
||||
if mem.generating then
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("techage:flywheel", {
|
||||
|
@ -173,15 +143,10 @@ minetest.register_node("techage:flywheel", {
|
|||
on_rightclick(pos)
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
|
||||
drop = "",
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
@ -242,13 +207,24 @@ minetest.register_node("techage:flywheel_on", {
|
|||
})
|
||||
|
||||
techage.power.register_node({"techage:flywheel", "techage:flywheel_on"}, {
|
||||
on_power_pass1 = on_power_pass1,
|
||||
on_power_pass2 = on_power_pass2,
|
||||
on_power_pass3 = on_power_pass3,
|
||||
conn_sides = {"R"},
|
||||
power_network = Axle,
|
||||
})
|
||||
|
||||
techage.register_node({"techage:flywheel", "techage:flywheel_on"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if topic == "trigger" then
|
||||
mem.triggered = 2
|
||||
if mem.generating then
|
||||
return math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.1)
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:flywheel",
|
||||
recipe = {
|
||||
|
@ -258,17 +234,6 @@ minetest.register_craft({
|
|||
},
|
||||
})
|
||||
|
||||
minetest.register_lbm({
|
||||
label = "[techage] Steam engine sound",
|
||||
name = "techage:steam_engine",
|
||||
nodenames = {"techage:flywheel_on"},
|
||||
run_at_every_load = true,
|
||||
action = function(pos, node)
|
||||
play_sound(pos)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
})
|
||||
|
||||
techage.register_help_page(I("TA2 Flywheel"),
|
||||
I([[Part of the steam engine.
|
||||
Has to be placed side by side
|
||||
|
|
|
@ -21,9 +21,11 @@ local M = minetest.get_meta
|
|||
local MP = minetest.get_modpath("techage")
|
||||
local I,_ = dofile(MP.."/intllib.lua")
|
||||
|
||||
local POWER_CONSUMPTION = 1
|
||||
local PWR_NEEDED = 1
|
||||
local CYCLE_TIME = 2
|
||||
|
||||
local Axle = techage.Axle
|
||||
local consume_power = techage.power.consume_power
|
||||
|
||||
local function swap_node(pos, name)
|
||||
local node = minetest.get_node(pos)
|
||||
|
@ -34,18 +36,27 @@ 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)
|
||||
if sum > 0 then
|
||||
swap_node(pos, "techage:gearbox_on")
|
||||
techage.switch_axles(pos, true)
|
||||
else
|
||||
local function node_timer(pos, elapsed)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
local got = consume_power(pos, PWR_NEEDED)
|
||||
if mem.running and got < PWR_NEEDED then
|
||||
swap_node(pos, "techage:gearbox")
|
||||
techage.switch_axles(pos, false)
|
||||
mem.running = false
|
||||
elseif not mem.running and got == PWR_NEEDED then
|
||||
swap_node(pos, "techage:gearbox_on")
|
||||
techage.switch_axles(pos, true)
|
||||
mem.running = true
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
|
||||
local function after_place_node(pos, placer, itemstack, pointed_thing)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
|
||||
minetest.register_node("techage:gearbox", {
|
||||
|
@ -53,7 +64,9 @@ minetest.register_node("techage:gearbox", {
|
|||
tiles = {"techage_filling_ta2.png^techage_axle_gearbox.png^techage_frame_ta2.png"},
|
||||
|
||||
on_construct = tubelib2.init_mem,
|
||||
|
||||
after_place_node = after_place_node,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
@ -77,17 +90,19 @@ minetest.register_node("techage:gearbox_on", {
|
|||
},
|
||||
},
|
||||
|
||||
after_place_node = after_place_node,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
paramtype2 = "facedir",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
diggable = false,
|
||||
drop = "",
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
techage.power.register_node({"techage:gearbox", "techage:gearbox_on"}, {
|
||||
on_power_pass1 = on_power_pass1,
|
||||
on_power_pass2 = on_power_pass2,
|
||||
power_network = Axle,
|
||||
})
|
||||
|
||||
|
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 555 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 446 B |
Before Width: | Height: | Size: 201 B After Width: | Height: | Size: 198 B |
Before Width: | Height: | Size: 548 B After Width: | Height: | Size: 229 B |
Before Width: | Height: | Size: 262 B After Width: | Height: | Size: 192 B |
Before Width: | Height: | Size: 283 B After Width: | Height: | Size: 191 B |
|
@ -16,27 +16,27 @@ 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
|
||||
|
||||
local function destroy_node(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type == "node" then
|
||||
local pos = pointed_thing.under
|
||||
if not minetest.is_protected(pos, placer:get_player_name()) then
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.techage_aging = 999999
|
||||
end
|
||||
end
|
||||
end
|
||||
--local function destroy_node(itemstack, placer, pointed_thing)
|
||||
-- if pointed_thing.type == "node" then
|
||||
-- local pos = pointed_thing.under
|
||||
-- if not minetest.is_protected(pos, placer:get_player_name()) then
|
||||
-- local mem = tubelib2.get_mem(pos)
|
||||
-- mem.techage_aging = 999999
|
||||
-- end
|
||||
-- end
|
||||
--end
|
||||
|
||||
local function repair_node(itemstack, user, pointed_thing)
|
||||
local pos = pointed_thing.under
|
||||
if pos then
|
||||
if techage.repair_node(pos) then
|
||||
minetest.chat_send_player(user:get_player_name(), "[TechAge] Node repaired")
|
||||
itemstack:add_wear(13108)
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
--local function repair_node(itemstack, user, pointed_thing)
|
||||
-- local pos = pointed_thing.under
|
||||
-- if pos then
|
||||
-- if techage.repair_node(pos) then
|
||||
-- minetest.chat_send_player(user:get_player_name(), "[TechAge] Node repaired")
|
||||
-- itemstack:add_wear(13108)
|
||||
-- return itemstack
|
||||
-- end
|
||||
-- end
|
||||
-- return
|
||||
--end
|
||||
|
||||
local function read_state(itemstack, user, pointed_thing)
|
||||
local pos = pointed_thing.under
|
||||
|
@ -45,10 +45,9 @@ local function read_state(itemstack, user, pointed_thing)
|
|||
if number then
|
||||
local state = techage.send_single(number, "state", nil)
|
||||
local counter = techage.send_single(number, "counter", nil)
|
||||
local aging = techage.send_single(number, "aging", nil)
|
||||
if state and counter and aging then
|
||||
if state and counter then
|
||||
if type(counter) ~= "number" then counter = "unknown" end
|
||||
minetest.chat_send_player(user:get_player_name(), "[TechAge] state ="..state..", counter = "..counter..", aging = "..aging)
|
||||
minetest.chat_send_player(user:get_player_name(), "[TechAge] state ="..state..", counter = "..counter)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -59,7 +58,7 @@ minetest.register_tool("techage:repairkit", {
|
|||
inventory_image = "techage_repairkit.png",
|
||||
wield_image = "techage_repairkit.png^[transformR270",
|
||||
groups = {cracky=1, book=1},
|
||||
on_use = repair_node,
|
||||
on_use = read_state,
|
||||
node_placement_prediction = "",
|
||||
})
|
||||
|
||||
|
@ -70,7 +69,7 @@ minetest.register_node("techage:end_wrench", {
|
|||
wield_image = "techage_end_wrench.png",
|
||||
groups = {cracky=1, book=1},
|
||||
on_use = read_state,
|
||||
on_place = destroy_node,
|
||||
on_place = read_state,
|
||||
node_placement_prediction = "",
|
||||
})
|
||||
|
||||
|
|
|
@ -38,11 +38,12 @@ local function hide_node(pos, node, meta, placer)
|
|||
local inv = placer:get_inventory()
|
||||
local stack = inv:get_stack("main", 1)
|
||||
local taken = stack:take_item(1)
|
||||
local ndef = minetest.registered_nodes[taken:get_name()]
|
||||
-- test if it is a simple node without logic
|
||||
if taken:get_count() == 1
|
||||
and minetest.registered_nodes[taken:get_name()]
|
||||
and not minetest.registered_nodes[taken:get_name()].after_place_node
|
||||
and not minetest.registered_nodes[taken:get_name()].on_construct then
|
||||
and not ndef.groups.soil
|
||||
and not ndef.after_place_node
|
||||
and not ndef.on_construct then
|
||||
meta:set_string("techage_hidden_nodename", node.name)
|
||||
meta:set_string("techage_hidden_param2", node.param2)
|
||||
local param2 = minetest.dir_to_facedir(placer:get_look_dir(), true)
|
||||
|
|