limit size of the digtron with config option: digtron_size_limit, default to 1000 nodes (#52)

This commit is contained in:
Thomas Rudin 2019-06-10 07:15:27 +02:00 committed by FaceDeer
parent b3d01a714c
commit 445140abaa
2 changed files with 25 additions and 1 deletions

@ -27,6 +27,7 @@ setting("bool", "uses_resources", true, "Digtron uses resources when active")
setting("bool", "lava_impassible", true, "Lava counts as a protected node")
setting("bool", "damage_creatures", true, "Diggers damage creatures") -- TODO: legacy setting, remove eventually
setting("int", "damage_hp", 8, "Damage diggers do")
setting("int", "size_limit", 1000, "Digtron size limit in nodes per moving digtron")
if digtron.config.damage_creatures == false then digtron.config.damage_hp = 0 end -- TODO: remove when damage_creatures is removed
@ -65,4 +66,4 @@ setting("int", "power_ratio", 100, "The electrical charge to 1 coal heat unit co
setting("float", "marker_crate_good_duration", 3.0, "Duration that 'good' crate markers last")
setting("float", "marker_crate_bad_duration", 9.0, "Duration that 'bad' crate markers last")
setting("bool", "emerge_unloaded_mapblocks", true, "When Digtron encounters unloaded map blocks, emerge them.")
setting("bool", "emerge_unloaded_mapblocks", true, "When Digtron encounters unloaded map blocks, emerge them.")

@ -95,6 +95,12 @@ local function test_stop_block(pos, items)
return false
end
local function check_digtron_size(layout)
if #layout.all > digtron.config.size_limit then
return S("Size limit of @1 reached with @2 nodes!", digtron.config.size_limit, #layout.all)
end
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
@ -104,6 +110,7 @@ end
-- 5 - unknown builder error during testing
-- 6 - builder with unset output
-- 7 - insufficient builder materials in inventory
-- 8 - size/node limit reached
digtron.execute_dig_cycle = function(pos, clicker)
local meta = minetest.get_meta(pos)
local facing = minetest.get_node(pos).param2
@ -118,6 +125,11 @@ digtron.execute_dig_cycle = function(pos, clicker)
if return_code ~= 0 then
return pos, status_text, return_code
end
local size_check_error = check_digtron_size(layout)
if size_check_error then
return pos, size_check_error, 8
end
local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)
@ -405,6 +417,11 @@ digtron.execute_move_cycle = function(pos, clicker)
return pos, status_text, return_code
end
local size_check_error = check_digtron_size(layout)
if size_check_error then
return pos, size_check_error, 8
end
local facing = minetest.get_node(pos).param2
local dir = minetest.facedir_to_dir(facing)
local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)
@ -459,6 +476,12 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
if return_code ~= 0 then
return pos, status_text, return_code
end
local size_check_error = check_digtron_size(layout)
if size_check_error then
return pos, size_check_error, 8
end
local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)