mirror of
https://github.com/minetest-mods/digtron.git
synced 2024-12-23 04:42:23 +01:00
Auto-controller will keep trying if it encounters an unloaded node, this is a condition that can spontaneously self-correct
This commit is contained in:
parent
0b84a1dffa
commit
e704249735
@ -49,7 +49,7 @@ minetest.register_node("digtron:controller", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local newpos, status = digtron.execute_cycle(pos, clicker)
|
local newpos, status, return_code = digtron.execute_cycle(pos, clicker)
|
||||||
|
|
||||||
meta = minetest.get_meta(newpos)
|
meta = minetest.get_meta(newpos)
|
||||||
if status ~= nil then
|
if status ~= nil then
|
||||||
@ -90,14 +90,18 @@ digtron.auto_cycle = function(pos)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local newpos, status = digtron.execute_cycle(pos, player)
|
local newpos, status, return_code = digtron.execute_cycle(pos, player)
|
||||||
|
|
||||||
local cycle = 0
|
local cycle = 0
|
||||||
if vector.equals(pos, newpos) then
|
if vector.equals(pos, newpos) then
|
||||||
cycle = meta:get_int("offset")
|
cycle = meta:get_int("offset")
|
||||||
status = status .. string.format("\nCycles remaining: %d\nHalted!", cycle)
|
status = status .. string.format("\nCycles remaining: %d\nHalted!", cycle)
|
||||||
meta:set_string("infotext", status)
|
meta:set_string("infotext", status)
|
||||||
meta:set_string("formspec", auto_formspec)
|
if return_code == 1 then --return code 1 happens when there's unloaded nodes adjacent, just keep trying.
|
||||||
|
minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos)
|
||||||
|
else
|
||||||
|
meta:set_string("formspec", auto_formspec)
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,7 +39,15 @@ local burn_smoke = function(pos, amount)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- returns newpos, status string
|
-- returns newpos, status string, and a return code indicating why the method returned (so the auto-controller can keep trying if it's due to unloaded nodes)
|
||||||
|
-- 0 - success
|
||||||
|
-- 1 - failed due to unloaded nodes
|
||||||
|
-- 2 - failed due to insufficient traction
|
||||||
|
-- 3 - obstructed by undiggable node
|
||||||
|
-- 4 - insufficient fuel
|
||||||
|
-- 5 - unknown builder error during testing
|
||||||
|
-- 6 - builder with unset output
|
||||||
|
-- 7 - insufficient builder materials in inventory
|
||||||
digtron.execute_cycle = function(pos, clicker)
|
digtron.execute_cycle = function(pos, clicker)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local fuel_burning = meta:get_float("fuel_burning") -- get amount of burned fuel left over from last cycle
|
local fuel_burning = meta:get_float("fuel_burning") -- get amount of burned fuel left over from last cycle
|
||||||
@ -48,8 +56,8 @@ digtron.execute_cycle = function(pos, clicker)
|
|||||||
local layout = digtron.get_all_digtron_neighbours(pos, clicker)
|
local layout = digtron.get_all_digtron_neighbours(pos, clicker)
|
||||||
if layout.all == nil then
|
if layout.all == nil then
|
||||||
-- get_all_digtron_neighbours returns nil if the digtron array touches unloaded nodes, too dangerous to do anything in that situation. Abort.
|
-- get_all_digtron_neighbours returns nil if the digtron array touches unloaded nodes, too dangerous to do anything in that situation. Abort.
|
||||||
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
minetest.sound_play("buzzer", {gain=0.25, pos=pos})
|
||||||
return pos, "Digtron is adjacent to unloaded nodes.\n" .. status_text
|
return pos, "Digtron is adjacent to unloaded nodes.\n" .. status_text, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if layout.water_touching == true then
|
if layout.water_touching == true then
|
||||||
@ -62,7 +70,7 @@ digtron.execute_cycle = function(pos, clicker)
|
|||||||
-- digtrons can't fly
|
-- digtrons can't fly
|
||||||
minetest.sound_play("squeal", {gain=1.0, pos=pos})
|
minetest.sound_play("squeal", {gain=1.0, pos=pos})
|
||||||
return pos, string.format("Digtron has %d nodes but only enough traction to move %d nodes.\n", table.getn(layout.all), layout.traction * digtron.traction_factor)
|
return pos, string.format("Digtron has %d nodes but only enough traction to move %d nodes.\n", table.getn(layout.all), layout.traction * digtron.traction_factor)
|
||||||
.. status_text
|
.. status_text, 2
|
||||||
end
|
end
|
||||||
|
|
||||||
local facing = minetest.get_node(pos).param2
|
local facing = minetest.get_node(pos).param2
|
||||||
@ -121,7 +129,7 @@ digtron.execute_cycle = function(pos, clicker)
|
|||||||
)
|
)
|
||||||
minetest.sound_play("squeal", {gain=1.0, pos=pos})
|
minetest.sound_play("squeal", {gain=1.0, pos=pos})
|
||||||
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
||||||
return pos, "Digtron is obstructed.\n" .. status_text --Abort, don't dig and don't build.
|
return pos, "Digtron is obstructed.\n" .. status_text, 3 --Abort, don't dig and don't build.
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------
|
||||||
@ -168,7 +176,7 @@ digtron.execute_cycle = function(pos, clicker)
|
|||||||
|
|
||||||
if test_fuel_needed > fuel_burning + test_fuel_burned then
|
if test_fuel_needed > fuel_burning + test_fuel_burned then
|
||||||
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
||||||
return pos, "Digtron needs more fuel." -- abort, don't dig and don't build.
|
return pos, "Digtron needs more fuel.", 4 -- abort, don't dig and don't build.
|
||||||
end
|
end
|
||||||
|
|
||||||
if not can_build then
|
if not can_build then
|
||||||
@ -179,15 +187,18 @@ digtron.execute_cycle = function(pos, clicker)
|
|||||||
end, pos
|
end, pos
|
||||||
)
|
)
|
||||||
local return_string = nil
|
local return_string = nil
|
||||||
|
local return_code = 5
|
||||||
if test_build_return_code == 3 then
|
if test_build_return_code == 3 then
|
||||||
minetest.sound_play("honk", {gain=0.5, pos=pos}) -- A builder is not configured
|
minetest.sound_play("honk", {gain=0.5, pos=pos}) -- A builder is not configured
|
||||||
return_string = "Digtron connected to at least one builder with no output material assigned.\n"
|
return_string = "Digtron connected to at least one builder with no output material assigned.\n"
|
||||||
|
return_code = 6
|
||||||
elseif test_build_return_code == 2 then
|
elseif test_build_return_code == 2 then
|
||||||
minetest.sound_play("dingding", {gain=1.0, pos=pos}) -- Insufficient inventory
|
minetest.sound_play("dingding", {gain=1.0, pos=pos}) -- Insufficient inventory
|
||||||
return_string = string.format("Digtron has insufficient building materials. Needed: %s\n",
|
return_string = string.format("Digtron has insufficient building materials. Needed: %s\n",
|
||||||
test_build_return_item:get_name())
|
test_build_return_item:get_name())
|
||||||
|
return_code = 7
|
||||||
end
|
end
|
||||||
return pos, return_string .. status_text --Abort, don't dig and don't build.
|
return pos, return_string .. status_text, return_code --Abort, don't dig and don't build.
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------
|
||||||
@ -289,5 +300,5 @@ digtron.execute_cycle = function(pos, clicker)
|
|||||||
minetest.check_for_falling({x=node_to_dig.x, y=node_to_dig.y+1, z=node_to_dig.z})
|
minetest.check_for_falling({x=node_to_dig.x, y=node_to_dig.y+1, z=node_to_dig.z})
|
||||||
node_to_dig, whether_to_dig = nodes_dug:pop()
|
node_to_dig, whether_to_dig = nodes_dug:pop()
|
||||||
end
|
end
|
||||||
return pos, status_text
|
return pos, status_text, 0
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user