Fix power consumption bug for a stopped collider
This commit is contained in:
parent
77181cbc3b
commit
66937f5743
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2021 Joachim Stolberg
|
Copyright (C) 2019-2023 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -157,7 +157,7 @@ local function create_task(pos, task)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Call on_cyclic_check of all magents so that the magnets don't need a FLB.
|
-- Call on_cyclic_check of all magents so that the magnets don't need a FLB.
|
||||||
local function magnet_on_cyclic_check(pos, nvm)
|
local function magnets_on_cyclic_check(pos, nvm)
|
||||||
local ndef = minetest.registered_nodes["techage:ta4_magnet"]
|
local ndef = minetest.registered_nodes["techage:ta4_magnet"]
|
||||||
for idx,pos2 in ipairs(nvm.magnet_positions or {}) do
|
for idx,pos2 in ipairs(nvm.magnet_positions or {}) do
|
||||||
local res = ndef.on_cyclic_check(pos2)
|
local res = ndef.on_cyclic_check(pos2)
|
||||||
@ -173,6 +173,29 @@ local function magnet_on_cyclic_check(pos, nvm)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Turn off all magnets so that they don't consume power
|
||||||
|
local function magnets_turn_off(pos, nvm)
|
||||||
|
local ndef = minetest.registered_nodes["techage:ta4_magnet"]
|
||||||
|
for idx,pos2 in ipairs(nvm.magnet_positions or {}) do
|
||||||
|
ndef.on_turn_off(pos2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function cable_inlets_turn_on_off(pos, on)
|
||||||
|
local turn_on_off = function(pos, param2, item)
|
||||||
|
local pos2 = getpos(pos, param2, item.route, item.yoffs)
|
||||||
|
local node2 = minetest.get_node(pos2)
|
||||||
|
if item.name == node2.name then
|
||||||
|
local nvm = techage.get_nvm(pos2)
|
||||||
|
techage.power_inlet_turn_on_off(pos2, nvm, on)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local param2 = minetest.get_node(pos).param2
|
||||||
|
turn_on_off(pos, param2, Schedule[2])
|
||||||
|
turn_on_off(pos, param2, Schedule[3])
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_node("techage:ta4_detector_core", {
|
minetest.register_node("techage:ta4_detector_core", {
|
||||||
description = S("TA4 Collider Detector Core"),
|
description = S("TA4 Collider Detector Core"),
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -202,29 +225,33 @@ minetest.register_node("techage:ta4_detector_core", {
|
|||||||
|
|
||||||
on_timer = function(pos, elapsed)
|
on_timer = function(pos, elapsed)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
if not magnet_on_cyclic_check(pos, nvm) then
|
if nvm.running then
|
||||||
techage.del_laser(pos)
|
if not magnets_on_cyclic_check(pos, nvm) then
|
||||||
if nvm.running then
|
|
||||||
terminal_message(pos, "Detector stopped.")
|
|
||||||
nvm.running = false
|
|
||||||
end
|
|
||||||
nvm.magnet_positions = nil
|
|
||||||
elseif nvm.running then
|
|
||||||
local res = check_state(pos)
|
|
||||||
if res == true then
|
|
||||||
experience_points(pos)
|
|
||||||
add_laser(pos)
|
|
||||||
if nvm.ticks <= TIME_SLOTS then -- only once
|
|
||||||
terminal_message(pos, "Detector running.")
|
|
||||||
end
|
|
||||||
elseif res == false then
|
|
||||||
techage.del_laser(pos)
|
techage.del_laser(pos)
|
||||||
|
terminal_message(pos, "Detector stopped.")
|
||||||
|
magnets_turn_off(pos, nvm)
|
||||||
|
cable_inlets_turn_on_off(pos, false)
|
||||||
nvm.running = false
|
nvm.running = false
|
||||||
nvm.magnet_positions = nil
|
nvm.magnet_positions = nil
|
||||||
terminal_message(pos, "Detector stopped.")
|
else
|
||||||
end
|
local res = check_state(pos)
|
||||||
if nvm.running then
|
if res == true then
|
||||||
play_sound(pos)
|
experience_points(pos)
|
||||||
|
add_laser(pos)
|
||||||
|
if nvm.ticks <= TIME_SLOTS then -- only once
|
||||||
|
terminal_message(pos, "Detector running.")
|
||||||
|
end
|
||||||
|
elseif res == false then
|
||||||
|
techage.del_laser(pos)
|
||||||
|
magnets_turn_off(pos, nvm)
|
||||||
|
cable_inlets_turn_on_off(pos, false)
|
||||||
|
nvm.running = false
|
||||||
|
nvm.magnet_positions = nil
|
||||||
|
terminal_message(pos, "Detector stopped.")
|
||||||
|
end
|
||||||
|
if nvm.running then
|
||||||
|
play_sound(pos)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
@ -287,6 +314,7 @@ local function start_task(pos)
|
|||||||
end
|
end
|
||||||
nvm.magnet_positions = t
|
nvm.magnet_positions = t
|
||||||
techage.send_single(own_num, term_num, "append", "ok")
|
techage.send_single(own_num, term_num, "append", "ok")
|
||||||
|
cable_inlets_turn_on_off(pos, true)
|
||||||
|
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
techage.send_single(own_num, term_num, "text", "- Check magnets...")
|
techage.send_single(own_num, term_num, "text", "- Check magnets...")
|
||||||
@ -310,6 +338,7 @@ local function start_task(pos)
|
|||||||
techage.send_single(own_num, term_num, "append", err .. "!!!")
|
techage.send_single(own_num, term_num, "append", err .. "!!!")
|
||||||
nvm.magnet_positions = nil
|
nvm.magnet_positions = nil
|
||||||
nvm.locked = false
|
nvm.locked = false
|
||||||
|
cable_inlets_turn_on_off(pos, false)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -323,12 +352,14 @@ local function start_task(pos)
|
|||||||
techage.send_single(own_num, term_num, "append", err .. "!!!")
|
techage.send_single(own_num, term_num, "append", err .. "!!!")
|
||||||
nvm.magnet_positions = nil
|
nvm.magnet_positions = nil
|
||||||
nvm.locked = false
|
nvm.locked = false
|
||||||
|
cable_inlets_turn_on_off(pos, false)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
techage.send_single(own_num, term_num, "append", "defect!!!")
|
techage.send_single(own_num, term_num, "append", "defect!!!")
|
||||||
nvm.magnet_positions = nil
|
nvm.magnet_positions = nil
|
||||||
nvm.locked = false
|
nvm.locked = false
|
||||||
|
cable_inlets_turn_on_off(pos, false)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
@ -337,7 +368,7 @@ local function start_task(pos)
|
|||||||
techage.send_single(own_num, term_num, "append", "ok")
|
techage.send_single(own_num, term_num, "append", "ok")
|
||||||
|
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
techage.send_single(own_num, term_num, "text", "Collider started.")
|
techage.send_single(own_num, term_num, "text", "Collider starting...")
|
||||||
nvm.ticks = 0
|
nvm.ticks = 0
|
||||||
nvm.running = true
|
nvm.running = true
|
||||||
end
|
end
|
||||||
@ -372,6 +403,9 @@ techage.register_node({"techage:ta4_detector_core"}, {
|
|||||||
nvm.running = false
|
nvm.running = false
|
||||||
techage.del_laser(pos)
|
techage.del_laser(pos)
|
||||||
nvm.locked = false
|
nvm.locked = false
|
||||||
|
magnets_turn_off(pos, nvm)
|
||||||
|
cable_inlets_turn_on_off(pos, false)
|
||||||
|
nvm.magnet_positions = nil
|
||||||
return "Detector stopped."
|
return "Detector stopped."
|
||||||
elseif topic == "status" then
|
elseif topic == "status" then
|
||||||
if nvm.running == true then
|
if nvm.running == true then
|
||||||
|
@ -328,7 +328,11 @@ minetest.register_node("techage:ta4_collider_cable_inlet", {
|
|||||||
|
|
||||||
on_timer = function(pos, elapsed)
|
on_timer = function(pos, elapsed)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
nvm.consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
if nvm.running then
|
||||||
|
nvm.consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||||
|
else
|
||||||
|
nvm.consumed = 0
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -346,6 +350,11 @@ function techage.power_inlet_check(pos, node, meta, nvm)
|
|||||||
return false, "no power"
|
return false, "no power"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Used by the detector to turn on/off the node
|
||||||
|
function techage.power_inlet_turn_on_off(pos, nvm, on)
|
||||||
|
nvm.running = on
|
||||||
|
end
|
||||||
|
|
||||||
power.register_nodes({"techage:ta4_collider_cable_inlet"}, Cable, "con", {"F"})
|
power.register_nodes({"techage:ta4_collider_cable_inlet"}, Cable, "con", {"F"})
|
||||||
|
|
||||||
techage.register_node({"techage:ta4_collider_cable_inlet"}, {
|
techage.register_node({"techage:ta4_collider_cable_inlet"}, {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2021 Joachim Stolberg
|
Copyright (C) 2019-2023 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -119,14 +119,22 @@ minetest.register_node("techage:ta4_magnet", {
|
|||||||
nvm.consumed = power.consume_power(pos, Cable, 6, PWR_NEEDED)
|
nvm.consumed = power.consume_power(pos, Cable, 6, PWR_NEEDED)
|
||||||
if nvm.tube_damage then
|
if nvm.tube_damage then
|
||||||
nvm.tube_damage = nil
|
nvm.tube_damage = nil
|
||||||
|
nvm.running = nil
|
||||||
return -1
|
return -1
|
||||||
elseif nvm.liquid.amount == CAPACITY and
|
elseif nvm.liquid.amount == CAPACITY and
|
||||||
nvm.liquid.name == "techage:isobutane" and
|
nvm.liquid.name == "techage:isobutane" and
|
||||||
nvm.consumed == PWR_NEEDED then
|
nvm.consumed == PWR_NEEDED then
|
||||||
|
nvm.running = true
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
nvm.running = nil
|
||||||
return -2
|
return -2
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
on_turn_off = function(pos)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
nvm.running = nil
|
||||||
|
end,
|
||||||
|
|
||||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
||||||
if tlib2.tube_type == "vtube" then
|
if tlib2.tube_type == "vtube" then
|
||||||
|
Loading…
Reference in New Issue
Block a user