From 1becf78dee950030d75dd8e8f57b5937fde07c44 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Sun, 22 Jan 2017 11:06:37 -0700 Subject: [PATCH] Traction revamp. Digtrons can now ignore traction when moving down, and pushers ignore traction entirely. --- doc.lua | 4 ++-- util_execute_cycle.lua | 45 ++++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/doc.lua b/doc.lua index 82a4b88..d9304cc 100644 --- a/doc.lua +++ b/doc.lua @@ -63,7 +63,7 @@ digtron.doc.auto_controller_usagehelp = "An Auto-control module can be set to ru digtron.doc.pusher_longdesc = "A simplified controller that merely moves a Digtron around without triggering its builder or digger modules" digtron.doc.pusher_usagehelp = "Aka the \"can you rebuild it six inches to the left\" module. This is a much simplified control module that does not trigger the digger or builder heads when right-clicked, it only moves the digging machine. It's up to you to ensure there's space for it to move into.\n\n".. -"Since movement alone does not require fuel, a pusher module has no internal furnace." +"Since movement alone does not require fuel, a pusher module has no internal furnace. Pushers also don't require traction, since their primary purpose is repositioning Digtrons let's say they have a built-in crane or something." digtron.doc.axle_longdesc = "A device that allows one to rotate their Digtron into new orientations" digtron.doc.axle_usagehelp = "This magical module can rotate a Digtron array in place around itself. Right-clicking on it will rotate the Digtron 90 degrees in the direction the orange arrows on its sides indicate (widdershins around the Y axis by default, use the screwdriver to change this) assuming there's space for the Digtron in its new orientation. Builders and diggers will not trigger on rotation." @@ -140,7 +140,7 @@ doc.add_entry("digtron", "concepts", { "Period - Builder and digger heads can be made periodic by changing the period value to something other than 1. This determines how frequently they trigger. A period of 1 triggers on every block, a period of 2 triggers once every second block, a period of 3 triggers once every third block, etc. These are useful when setting up a machine to place regularly-spaced features as it goes. For example, you could have a builder head that places a torch every 8 steps, or a digger block that punches a landing in the side of a vertical stairwell at every level.\n\n".. "Offset - The location at which a periodic module triggers is globally uniform. This is handy if you want to line up the blocks you're building (for example, placing pillars and a crosspiece every 4 blocks in a tunnel, or punching alcoves in a wall to place glass windows). If you wish to change how the pattern lines up, modify the \"offset\" setting.\n\n" .. "Shift-right-clicking - since most of the blocks of the digging machine have control screens associated with right-clicking, building additional blocks on top of them or rotating them with the screwdriver requires the shift key to be held down when right-clicking on them.\n\n" .. -"Traction - Digtrons cannot fly. By default, they need to be touching one block of solid ground for every three blocks of Digtron in order to move." +"Traction - Digtrons cannot fly. By default, they need to be touching one block of solid ground for every three blocks of Digtron in order to move. Digtrons can fall, though - traction is never needed when a Digtron is moving downward. \"Pusher\" controllers can ignore the need for traction when moving in any direction." }}) doc.add_entry("digtron", "noises", { diff --git a/util_execute_cycle.lua b/util_execute_cycle.lua index 78bf386..c23c376 100644 --- a/util_execute_cycle.lua +++ b/util_execute_cycle.lua @@ -40,7 +40,7 @@ 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) +local function neighbour_test(layout, status_text, dir) 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}) @@ -55,8 +55,8 @@ local function neighbour_test(layout, status_text) 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 + if dir and dir.y ~= -1 and layout.traction * digtron.traction_factor < table.getn(layout.all) then + -- digtrons can't fly, though they can fall minetest.sound_play("squeal", {gain=1.0, pos=layout.controller}) return string.format("Digtron has %d blocks but only enough traction to move %d blocks.\n", table.getn(layout.all), layout.traction * digtron.traction_factor) .. status_text, 2 @@ -87,17 +87,18 @@ end -- 7 - insufficient builder materials in inventory digtron.execute_dig_cycle = function(pos, clicker) local meta = minetest.get_meta(pos) + local facing = minetest.get_node(pos).param2 + local dir = minetest.facedir_to_dir(facing) 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", math.max(0, fuel_burning)) local layout = DigtronLayout.create(pos, clicker) - local status_text, return_code = neighbour_test(layout, status_text) + local status_text, return_code = neighbour_test(layout, status_text, dir) 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) ---------------------------------------------------------------------------------------------------------------------- @@ -120,7 +121,7 @@ digtron.execute_dig_cycle = function(pos, clicker) table.insert(items_dropped, itemname) end if digtron.particle_effects then - table.insert(particle_systems, dig_dust(digtron.find_new_pos(location.pos, facing), target.param2)) + table.insert(particle_systems, dig_dust(vector.add(location.pos, dir), target.param2)) end end digging_fuel_cost = digging_fuel_cost + fuel_cost @@ -135,7 +136,7 @@ digtron.execute_dig_cycle = function(pos, clicker) -- as having been dug. local can_move = true for _, location in pairs(layout.all) do - local newpos = digtron.find_new_pos(location.pos, facing) + local newpos = vector.add(location.pos, dir) if not digtron.can_move_to(newpos, layout.protected, layout.nodes_dug) then can_move = false end @@ -165,7 +166,7 @@ digtron.execute_dig_cycle = function(pos, clicker) for k, location in pairs(layout.builders) do local target = minetest.get_node(location.pos) local targetdef = minetest.registered_nodes[target.name] - local test_location = digtron.find_new_pos(location.pos, facing) + local test_location = vector.add(location.pos, dir) if targetdef.test_build ~= nil then test_build_return_code, test_build_return_item = targetdef.test_build(location.pos, test_location, layout.inventories, layout.protected, layout.nodes_dug, controlling_coordinate, layout.controller) if test_build_return_code > 1 then @@ -235,13 +236,13 @@ digtron.execute_dig_cycle = function(pos, clicker) end --move the array - layout:move_layout_image(minetest.facedir_to_dir(facing)) + layout:move_layout_image(dir) layout:write_layout_image(clicker) local oldpos = {x=pos.x, y=pos.y, z=pos.z} - pos = digtron.find_new_pos(pos, facing) + pos = vector.add(pos, dir) meta = minetest.get_meta(pos) if move_player then - clicker:moveto(digtron.find_new_pos(clicker:getpos(), facing), true) + clicker:moveto(vector.add(dir, clicker:getpos()), true) end -- store or drop the products of the digger heads @@ -320,19 +321,20 @@ digtron.execute_move_cycle = function(pos, clicker) local layout = DigtronLayout.create(pos, clicker) local status_text = "" - local status_text, return_code = neighbour_test(layout, status_text) + local status_text, return_code = neighbour_test(layout, status_text, nil) -- skip traction check for pusher by passing nil for direction if return_code ~= 0 then return pos, status_text, return_code end local facing = minetest.get_node(pos).param2 + local dir = minetest.facedir_to_dir(facing) local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing) -- if the player is standing within the array or next to it, move him too. local move_player = move_player_test(layout, clicker) -- test if any digtrons are obstructed by non-digtron nodes - layout:move_layout_image(minetest.facedir_to_dir(facing)) + layout:move_layout_image(dir) if not layout:can_write_layout_image() then -- mark this node as waiting, will clear this flag in digtron.cycle_time seconds minetest.get_meta(pos):set_string("waiting", "true") @@ -346,9 +348,9 @@ digtron.execute_move_cycle = function(pos, clicker) --move the array layout:write_layout_image(clicker) - pos = digtron.find_new_pos(pos, facing) + pos = vector.add(pos, dir) if move_player then - clicker:moveto(digtron.find_new_pos(clicker:getpos(), facing), true) + clicker:moveto(vector.add(clicker:getpos(), dir), true) end return pos, "", 0 end @@ -363,17 +365,18 @@ end -- 4 - insufficient fuel digtron.execute_downward_dig_cycle = function(pos, clicker) local meta = minetest.get_meta(pos) + local facing = minetest.get_node(pos).param2 + local dir = digtron.facedir_to_down_dir(facing) 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", math.max(0, fuel_burning)) local layout = DigtronLayout.create(pos, clicker) - local status_text, return_code = neighbour_test(layout, status_text) + local status_text, return_code = neighbour_test(layout, status_text, dir) 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) ---------------------------------------------------------------------------------------------------------------------- @@ -396,7 +399,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) table.insert(items_dropped, itemname) end if digtron.particle_effects then - table.insert(particle_systems, dig_dust(digtron.find_new_pos_downward(location.pos, facing), target.param2)) + table.insert(particle_systems, dig_dust(vector.add(location.pos, dir), target.param2)) end end digging_fuel_cost = digging_fuel_cost + fuel_cost @@ -411,7 +414,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) -- as having been dug. local can_move = true for _, location in pairs(layout.all) do - local newpos = digtron.find_new_pos_downward(location.pos, facing) + local newpos = vector.add(location.pos, dir) if not digtron.can_move_to(newpos, layout.protected, layout.nodes_dug) then can_move = false end @@ -449,10 +452,10 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) layout:move_layout_image(digtron.facedir_to_down_dir(facing)) layout:write_layout_image(clicker) local oldpos = {x=pos.x, y=pos.y, z=pos.z} - pos = digtron.find_new_pos_downward(pos, facing) + pos = vector.add(pos, dir) meta = minetest.get_meta(pos) if move_player then - clicker:moveto(digtron.find_new_pos_downward(clicker:getpos(), facing), true) + clicker:moveto(vector.add(clicker:getpos(), dir), true) end -- store or drop the products of the digger heads