summaryrefslogtreecommitdiff
path: root/node_controllers.lua
diff options
context:
space:
mode:
authorFaceDeer <derksenmobile@gmail.com>2017-01-14 16:58:37 -0700
committerFaceDeer <derksenmobile@gmail.com>2017-01-14 16:58:37 -0700
commit51c5e9b6417b807ea3b7890240bd2ea43e8a297a (patch)
tree94c33a1c482b4509d10b31a3e260b1f187aaad53 /node_controllers.lua
parentf0e09f136a40efa7ebf41db880693b67b3f9f628 (diff)
Diagonal movement setting for the auto-controller.
Diffstat (limited to 'node_controllers.lua')
-rw-r--r--node_controllers.lua98
1 files changed, 79 insertions, 19 deletions
diff --git a/node_controllers.lua b/node_controllers.lua
index 9efa804..8e68721 100644
--- a/node_controllers.lua
+++ b/node_controllers.lua
@@ -69,32 +69,60 @@ minetest.register_node("digtron:controller", {
-- Auto-controller
---------------------------------------------------------------------------------------------------------------
-local auto_formspec = "size[4.5,1]" ..
+local auto_formspec = "size[3.5,2]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
- "field[0.5,0.8;1,0.1;offset;Cycles;${offset}]" ..
- "tooltip[offset;When triggered, this controller will try to run for the given number of cycles. The cycle count will decrement as it runs, so if it gets halted by a problem you can fix the problem and restart.]" ..
- "field[1.5,0.8;1,0.1;period;Period;${period}]" ..
- "tooltip[period;Number of seconds to wait between each cycle]" ..
- "button_exit[2.2,0.5;1,0.1;set;Set]" ..
+ "field[0.5,0.8;1,0.1;cycles;Cycles;${cycles}]" ..
+ "tooltip[cycles;When triggered, this controller will try to run for the given number of cycles. The cycle count will decrement as it runs, so if it gets halted by a problem you can fix the problem and restart.]" ..
+ "button_exit[1.2,0.5;1,0.1;set;Set]" ..
"tooltip[set;Saves the cycle setting without starting the controller running]" ..
- "button_exit[3.2,0.5;1,0.1;execute;Set &\nExecute]" ..
- "tooltip[execute;Begins executing the given number of cycles]"
-
+ "button_exit[2.2,0.5;1,0.1;execute;Set &\nExecute]" ..
+ "tooltip[execute;Begins executing the given number of cycles]" ..
+ "field[0.5,2.0;1,0.1;slope;Slope;${slope}]" ..
+ "tooltip[slope;For diagonal digging. After every X nodes the auto controller moves forward, the controller will add an additional cycle moving the digtron laterally in the direction of the arrows on the side of this controller. Set to 0 for no lateral digging.]" ..
+ "field[1.5,2.0;1,0.1;offset;Offset;${offset}]" ..
+ "tooltip[offset;Sets the offset of the lateral motion defined in the Slope field. Note: this offset is relative to the controller's location. The controller will move down when it reaches the indicated point.]" ..
+ "field[2.5,2.0;1,0.1;period;Delay;${period}]" ..
+ "tooltip[period;Number of seconds to wait between each cycle]"
+
-- Needed to make this global so that it could recurse into minetest.after
digtron.auto_cycle = function(pos)
+ local node = minetest.get_node(pos)
+ local controlling_coordinate = digtron.get_controlling_coordinate(pos, node.param2)
local meta = minetest.get_meta(pos)
local player = minetest.get_player_by_name(meta:get_string("triggering_player"))
if player == nil or meta:get_string("waiting") == "true" then
return
end
+
+ local cycle = meta:get_int("cycles")
+ local slope = meta:get_int("slope")
+
+ if meta:get_string("lateral_done") ~= "true" and slope ~= 0 and (pos[controlling_coordinate] + meta:get_int("offset")) % slope == 0 then
+ --Do a downward dig cycle. Don't update the "cycles" count, these don't count towards that.
+ local newpos, status, return_code = digtron.execute_downward_dig_cycle(pos, player)
+
+ if vector.equals(pos, newpos) then
+ status = status .. string.format("\nCycles remaining: %d\nHalted!", cycle)
+ meta:set_string("infotext", status)
+ 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
+ else
+ meta = minetest.get_meta(newpos)
+ minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos)
+ meta:set_string("infotext", status)
+ meta:set_string("lateral_done", "true")
+ end
+ return
+ end
local newpos, status, return_code = digtron.execute_dig_cycle(pos, player)
- local cycle = 0
if vector.equals(pos, newpos) then
- cycle = meta:get_int("offset")
status = status .. string.format("\nCycles remaining: %d\nHalted!", cycle)
meta:set_string("infotext", status)
if return_code == 1 then --return code 1 happens when there's unloaded nodes adjacent, just keep trying.
@@ -106,10 +134,11 @@ digtron.auto_cycle = function(pos)
end
meta = minetest.get_meta(newpos)
- cycle = meta:get_int("offset") - 1
- meta:set_int("offset", cycle)
+ cycle = meta:get_int("cycles") - 1
+ meta:set_int("cycles", cycle)
status = status .. string.format("\nCycles remaining: %d", cycle)
meta:set_string("infotext", status)
+ meta:set_string("lateral_done", nil)
if cycle > 0 then
minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos)
@@ -130,8 +159,8 @@ minetest.register_node("digtron:auto_controller", {
tiles = {
"digtron_plate.png^[transformR90^digtron_auto_control_tint.png",
"digtron_plate.png^[transformR270^digtron_auto_control_tint.png",
- "digtron_plate.png^digtron_auto_control_tint.png",
- "digtron_plate.png^[transformR180^digtron_auto_control_tint.png",
+ "digtron_plate.png^digtron_axel_side.png^[transformR270^digtron_auto_control_tint.png",
+ "digtron_plate.png^digtron_axel_side.png^[transformR270^digtron_auto_control_tint.png",
"digtron_plate.png^digtron_auto_control_tint.png",
"digtron_plate.png^digtron_control.png^digtron_auto_control_tint.png",
},
@@ -150,28 +179,59 @@ minetest.register_node("digtron:auto_controller", {
-- Reusing offset and period to keep the digtron node-moving code simple, and the names still fit well
meta:set_int("period", digtron.cycle_time)
meta:set_int("offset", 0)
+ meta:set_int("cycles", 0)
+ meta:set_int("slope", 0)
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
local offset = tonumber(fields.offset)
local period = tonumber(fields.period)
+ local slope = tonumber(fields.slope)
+ local cycles = tonumber(fields.cycles)
if period and period > 0 then
meta:set_int("period", math.max(digtron.cycle_time, math.floor(period)))
end
+
+ if offset then
+ meta:set_int("offset", offset)
+ end
- if offset and offset >= 0 then
- meta:set_int("offset", math.floor(offset))
- if sender:is_player() and offset > 0 then
+ if slope and slope >= 0 then
+ meta:set_int("slope", slope)
+ end
+
+ if cycles and cycles >= 0 then
+ meta:set_int("cycles", math.floor(cycles))
+ if sender:is_player() and cycles > 0 then
meta:set_string("triggering_player", sender:get_player_name())
if fields.execute then
meta:set_string("waiting", nil)
meta:set_string("formspec", nil)
- digtron.auto_cycle(pos)
+ digtron.auto_cycle(pos)
end
end
end
+
+ if fields.set and slope and slope > 0 then
+ local node = minetest.get_node(pos)
+ local controlling_coordinate = digtron.get_controlling_coordinate(pos, node.param2)
+
+ local newpos = pos --digtron.find_new_pos(pos, minetest.get_node(pos).param2)
+ local markerpos = {x=newpos.x, y=newpos.y, z=newpos.z}
+ local x_pos = math.floor((newpos[controlling_coordinate]+offset)/slope)*slope - offset
+ markerpos[controlling_coordinate] = x_pos
+ minetest.add_entity(markerpos, "digtron:marker_vertical")
+ if x_pos >= newpos[controlling_coordinate] then
+ markerpos[controlling_coordinate] = x_pos - slope
+ minetest.add_entity(markerpos, "digtron:marker_vertical")
+ end
+ if x_pos <= newpos[controlling_coordinate] then
+ markerpos[controlling_coordinate] = x_pos + slope
+ minetest.add_entity(markerpos, "digtron:marker_vertical")
+ end
+ end
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)