summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFaceDeer <derksenmobile@gmail.com>2017-01-08 21:34:27 -0700
committerFaceDeer <derksenmobile@gmail.com>2017-01-08 21:34:27 -0700
commit7af220009bf08c45853303e1ce961fe8a0b7a434 (patch)
tree50712d136b5b576f8042cf9098f6ce21c0390e5b
parent32ed41ce6a9575f268839027757e8484688ec49a (diff)
Just moving some code around in preparation to adding a "lateral shunt" option to the auto-controller
-rw-r--r--description.txt4
-rw-r--r--node_controllers.lua71
-rw-r--r--sounds/license.txt6
-rw-r--r--util_execute_cycle.lua107
4 files changed, 103 insertions, 85 deletions
diff --git a/description.txt b/description.txt
new file mode 100644
index 0000000..008cba8
--- /dev/null
+++ b/description.txt
@@ -0,0 +1,4 @@
+digtron - a modular tunnel boring/building machine for minetest, v0.7 - 2017-01-08
+
+Forum : https://forum.minetest.net/viewtopic.php?f=9&t=16295
+github: https://github.com/FaceDeer/digtron/ \ No newline at end of file
diff --git a/node_controllers.lua b/node_controllers.lua
index 7dc1e7f..caa7184 100644
--- a/node_controllers.lua
+++ b/node_controllers.lua
@@ -49,7 +49,7 @@ minetest.register_node("digtron:controller", {
return
end
- local newpos, status, return_code = digtron.execute_cycle(pos, clicker)
+ local newpos, status, return_code = digtron.execute_dig_cycle(pos, clicker)
meta = minetest.get_meta(newpos)
if status ~= nil then
@@ -90,7 +90,7 @@ digtron.auto_cycle = function(pos)
return
end
- local newpos, status, return_code = digtron.execute_cycle(pos, player)
+ local newpos, status, return_code = digtron.execute_dig_cycle(pos, player)
local cycle = 0
if vector.equals(pos, newpos) then
@@ -222,69 +222,12 @@ minetest.register_node("digtron:pusher", {
return
end
- local layout = digtron.get_all_digtron_neighbours(pos, clicker)
- 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.
- minetest.sound_play("buzzer", {gain=0.5, pos=pos})
- meta:set_string("infotext", "Digtron is adjacent to unloaded nodes.")
- return
- end
-
- if layout.traction * digtron.traction_factor < table.getn(layout.all) then
- -- digtrons can't fly
- minetest.sound_play("squeal", {gain=1.0, pos=pos})
- meta:set_string("infotext", string.format("Digtron has %d nodes but only enough traction to move %d nodes.", table.getn(layout.all), layout.traction * digtron.traction_factor))
- return
- end
-
- local facing = minetest.get_node(pos).param2
- local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)
-
- local nodes_dug = Pointset.create() -- empty set, we're not digging anything
-
- -- test if any digtrons are obstructed by non-digtron nodes that haven't been marked
- -- as having been dug.
- local can_move = true
- for _, location in pairs(layout.all) do
- local newpos = digtron.find_new_pos(location, facing)
- if not digtron.can_move_to(newpos, layout.protected, nodes_dug) then
- can_move = false
- end
- end
+ local newpos, status_text, return_code = digtron.execute_move_cycle(pos, clicker)
+ meta:set_string("infotext", status_text)
- if not can_move then
- -- mark this node as waiting, will clear this flag in digtron.cycle_time seconds
- meta:set_string("waiting", "true")
- minetest.get_node_timer(pos):start(digtron.cycle_time)
- minetest.sound_play("squeal", {gain=1.0, pos=pos})
- minetest.sound_play("buzzer", {gain=0.5, pos=pos})
- meta:set_string("infotext", "Digtron is obstructed.")
- return --Abort
- end
-
- meta:set_string("infotext", nil)
- minetest.sound_play("truck", {gain=1.0, pos=pos})
-
- -- if the player is standing within the array or next to it, move him too.
- local player_pos = clicker:getpos()
- local move_player = false
- if player_pos.x >= layout.extents.min_x - 1 and player_pos.x <= layout.extents.max_x + 1 and
- player_pos.y >= layout.extents.min_y - 1 and player_pos.y <= layout.extents.max_y + 1 and
- player_pos.z >= layout.extents.min_z - 1 and player_pos.z <= layout.extents.max_z + 1 then
- move_player = true
- end
-
- --move the array
- digtron.move_digtron(facing, layout.all, layout.extents, nodes_dug)
- local oldpos = {x=pos.x, y=pos.y, z=pos.z}
- pos = digtron.find_new_pos(pos, facing)
- if move_player then
- clicker:moveto(digtron.find_new_pos(player_pos, facing), true)
- end
-
- -- Start the delay before digtron can run again. Do this after moving the array or pos will be wrong.
- minetest.get_meta(pos):set_string("waiting", "true")
- minetest.get_node_timer(pos):start(digtron.cycle_time)
+ -- Start the delay before digtron can run again.
+ minetest.get_meta(newpos):set_string("waiting", "true")
+ minetest.get_node_timer(newpos):start(digtron.cycle_time)
end,
on_timer = function(pos, elapsed)
diff --git a/sounds/license.txt b/sounds/license.txt
index afaaa45..27f624c 100644
--- a/sounds/license.txt
+++ b/sounds/license.txt
@@ -3,12 +3,12 @@ The sounds in this folder were sampled from source .wavs from Freesound.org. Spe
buzzer.ogg - https://freesound.org/people/hypocore/sounds/164090/ - public domain via CC 1.0 by hypocore
construction.ogg - https://www.freesound.org/people/mediapetros/sounds/109117/ - under the CC BY 3.0 license by mediapetros
dingding.ogg - https://www.freesound.org/people/JohnsonBrandEditing/sounds/173932/ public domain via CC 1.0 by JohnsonBrandEditing
-squeal.ogg - https://www.freesound.org/people/RutgerMuller/sounds/104026/ public domain via CC 1.0 by RutgerMuller
honk.ogg - https://freesound.org/people/bigmanjoe/sounds/349922/ public domain via CC 1.0 by bigmanjoe
-truck.ogg - https://www.freesound.org/people/jberkuta14/sounds/134898/ public domain via CC 1.0 by jberkuta14
sploosh.ogg - https://www.freesound.org/people/mr_marcello/sounds/257609/ public domain via CC 1.0 by mr_marcello
-woopwoopwoop.ogg - https://www.freesound.org/people/gregconquest/sounds/188012/ public domain via CC 1.0 by gregconquest
+squeal.ogg - https://www.freesound.org/people/RutgerMuller/sounds/104026/ public domain via CC 1.0 by RutgerMuller
+truck.ogg - https://www.freesound.org/people/jberkuta14/sounds/134898/ public domain via CC 1.0 by jberkuta14
whirr.ogg - https://www.freesound.org/people/daveincamas/sounds/25034/ - under the CC BY 3.0 license by daveincamas
+woopwoopwoop.ogg - https://www.freesound.org/people/gregconquest/sounds/188012/ public domain via CC 1.0 by gregconquest
Creative Commons Attribution 3.0 license:
diff --git a/util_execute_cycle.lua b/util_execute_cycle.lua
index c9614d5..488ee7f 100644
--- a/util_execute_cycle.lua
+++ b/util_execute_cycle.lua
@@ -39,6 +39,32 @@ local burn_smoke = function(pos, amount)
}
end
+--Performs various tests on a layout to play warning noises and see if Digtron can move at all.
+local function neighbour_test(layout, status_text)
+ 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.
+ minetest.sound_play("buzzer", {gain=0.25, pos=layout.controller})
+ return "Digtron is adjacent to unloaded nodes.\n" .. status_text, 1
+ end
+
+ if layout.water_touching == true then
+ minetest.sound_play("sploosh", {gain=1.0, pos=layout.controller})
+ end
+
+ if layout.lava_touching == true then
+ minetest.sound_play("woopwoopwoop", {gain=1.0, pos=layout.controller})
+ end
+
+ if layout.traction * digtron.traction_factor < table.getn(layout.all) then
+ -- digtrons can't fly
+ minetest.sound_play("squeal", {gain=1.0, pos=layout.controller})
+ return 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, 2
+ end
+
+ return status_text, 0
+end
+
-- 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
@@ -48,31 +74,18 @@ end
-- 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_dig_cycle = function(pos, clicker)
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 status_text = string.format("Heat remaining in controller furnace: %d", fuel_burning)
local layout = digtron.get_all_digtron_neighbours(pos, clicker)
- 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.
- minetest.sound_play("buzzer", {gain=0.25, pos=pos})
- return pos, "Digtron is adjacent to unloaded nodes.\n" .. status_text, 1
+
+ local status_text, return_code = neighbour_test(layout, status_text)
+ if return_code ~= 0 then
+ return pos, status_text, return_code
end
- if layout.water_touching == true then
- minetest.sound_play("sploosh", {gain=1.0, pos=pos})
- end
- if layout.lava_touching == true then
- minetest.sound_play("woopwoopwoop", {gain=1.0, pos=pos})
- end
- if layout.traction * digtron.traction_factor < table.getn(layout.all) then
- -- digtrons can't fly
- 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)
- .. status_text, 2
- end
-
local facing = minetest.get_node(pos).param2
local move_dir = minetest.facedir_to_dir(facing)
local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)
@@ -294,3 +307,61 @@ digtron.execute_cycle = function(pos, clicker)
end
return pos, status_text, 0
end
+
+
+-- Simplified version of the above method that only moves, and doesn't execute diggers or builders.
+digtron.execute_move_cycle = function(pos, clicker)
+ local meta = minetest.get_meta(pos)
+ local layout = digtron.get_all_digtron_neighbours(pos, clicker)
+
+ local status_text = ""
+ local status_text, return_code = neighbour_test(layout, status_text)
+ if return_code ~= 0 then
+ return pos, status_text, return_code
+ end
+
+ local facing = minetest.get_node(pos).param2
+ local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)
+
+ local nodes_dug = Pointset.create() -- empty set, we're not digging anything
+
+ -- test if any digtrons are obstructed by non-digtron nodes that haven't been marked
+ -- as having been dug.
+ local can_move = true
+ for _, location in pairs(layout.all) do
+ local newpos = digtron.find_new_pos(location, facing)
+ if not digtron.can_move_to(newpos, layout.protected, nodes_dug) then
+ can_move = false
+ end
+ end
+
+ if not can_move then
+ -- mark this node as waiting, will clear this flag in digtron.cycle_time seconds
+ minetest.get_meta(pos):set_string("waiting", "true")
+ minetest.get_node_timer(pos):start(digtron.cycle_time)
+ minetest.sound_play("squeal", {gain=1.0, pos=pos})
+ minetest.sound_play("buzzer", {gain=0.5, pos=pos})
+ return pos, "Digtron is obstructed.\n" .. status_text, 3 --Abort, don't dig and don't build.
+ end
+
+ minetest.sound_play("truck", {gain=1.0, pos=pos})
+
+ -- if the player is standing within the array or next to it, move him too.
+ local player_pos = clicker:getpos()
+ local move_player = false
+ if player_pos.x >= layout.extents.min_x - 1 and player_pos.x <= layout.extents.max_x + 1 and
+ player_pos.y >= layout.extents.min_y - 1 and player_pos.y <= layout.extents.max_y + 1 and
+ player_pos.z >= layout.extents.min_z - 1 and player_pos.z <= layout.extents.max_z + 1 then
+ move_player = true
+ end
+
+ --move the array
+ digtron.move_digtron(facing, layout.all, layout.extents, nodes_dug)
+ local oldpos = {x=pos.x, y=pos.y, z=pos.z}
+ pos = digtron.find_new_pos(pos, facing)
+ if move_player then
+ clicker:moveto(digtron.find_new_pos(player_pos, facing), true)
+ end
+
+ return pos, "", 0
+end \ No newline at end of file