diff --git a/working_villagers/jobs/bone_collector.lua b/working_villagers/jobs/bone_collector.lua index 7d21119..64871a4 100644 --- a/working_villagers/jobs/bone_collector.lua +++ b/working_villagers/jobs/bone_collector.lua @@ -35,15 +35,16 @@ function bones.is_bone(item_name) return true; end -local function find_bug_node(pos) - if minetest.is_protected(pos, "") then return false end +local function find_bug_node(self) + return function(pos) + if minetest.is_protected(pos, self:get_player_name()) then return false end if working_villages.failed_pos_test(pos) then return false end - local node = minetest.get_node(pos); - local data = bones.get_bone(node.name); - if (not data) then - return false; - end + local node = minetest.get_node(pos); + local data = bones.get_bone(node.name); + if (not data) then + return false; + end -- if data.collect_only_top then -- -- prevent to collect plat part, which can continue to grow @@ -59,7 +60,8 @@ local function find_bug_node(pos) -- end -- end - return true; + return true; + end end local searching_range = {x = 10, y = 5, z = 10} @@ -101,7 +103,7 @@ working_villages.register_job("working_villages:job_bonecollector", { self:handle_obstacles() if self:timer_exceeded("bonecollector:search",20) then self:collect_nearest_item_by_condition(bones.is_bone, searching_range) - local target = func.search_surrounding(self.object:get_pos(), find_bug_node, searching_range) + local target = func.search_surrounding(self.object:get_pos(), find_bug_node(self), searching_range) if target ~= nil then local destination = func.find_adjacent_clear(target) if destination then diff --git a/working_villagers/jobs/brush_collector.lua b/working_villagers/jobs/brush_collector.lua index e98d21f..69b9604 100644 --- a/working_villagers/jobs/brush_collector.lua +++ b/working_villagers/jobs/brush_collector.lua @@ -41,31 +41,33 @@ function shrubs.is_shrub(item_name) return true; end -local function find_herb_node(pos) - if minetest.is_protected(pos, "") then return false end +local function find_herb_node(self) + return function(pos) + if minetest.is_protected(pos, self:get_player_name()) then return false end if working_villages.failed_pos_test(pos) then return false end - local node = minetest.get_node(pos); - local data = shrubs.get_shrub(node.name); - if (not data) then - return false; - end + local node = minetest.get_node(pos); + local data = shrubs.get_shrub(node.name); + if (not data) then + return false; + end - if data.collect_only_top then - -- prevent to collect plat part, which can continue to grow - local pos_below = {x=pos.x, y=pos.y-1, z=pos.z} - local node_below = minetest.get_node(pos_below); - if (node_below.name~=node.name) then - return false; - end - local pos_above = {x=pos.x, y=pos.y+1, z=pos.z} - local node_above = minetest.get_node(pos_above); - if (node_above.name==node.name) then - return false; - end - end + if data.collect_only_top then + -- prevent to collect plat part, which can continue to grow + local pos_below = {x=pos.x, y=pos.y-1, z=pos.z} + local node_below = minetest.get_node(pos_below); + if (node_below.name~=node.name) then + return false; + end + local pos_above = {x=pos.x, y=pos.y+1, z=pos.z} + local node_above = minetest.get_node(pos_above); + if (node_above.name==node.name) then + return false; + end + end - return true; + return true; + end end local searching_range = {x = 10, y = 5, z = 10} @@ -89,7 +91,7 @@ working_villages.register_job("working_villages:job_brushcollector", { self:handle_obstacles() if self:timer_exceeded("brushcollector:search",20) then self:collect_nearest_item_by_condition(shrubs.is_shrub, searching_range) - local target = func.search_surrounding(self.object:get_pos(), find_herb_node, searching_range) + local target = func.search_surrounding(self.object:get_pos(), find_herb_node(self), searching_range) if target ~= nil then local destination = func.find_adjacent_clear(target) if destination then diff --git a/working_villagers/jobs/bug_collector.lua b/working_villagers/jobs/bug_collector.lua index d301a32..2d19ea3 100644 --- a/working_villagers/jobs/bug_collector.lua +++ b/working_villagers/jobs/bug_collector.lua @@ -39,15 +39,16 @@ function bugs.is_bug(item_name) return true; end -local function find_bug_node(pos) - if minetest.is_protected(pos, "") then return false end +local function find_bug_node(self) + return function(pos) + if minetest.is_protected(pos, self:get_player_name()) then return false end if working_villages.failed_pos_test(pos) then return false end - local node = minetest.get_node(pos); - local data = bugs.get_bug(node.name); - if (not data) then - return false; - end + local node = minetest.get_node(pos); + local data = bugs.get_bug(node.name); + if (not data) then + return false; + end -- if data.collect_only_top then -- -- prevent to collect plat part, which can continue to grow @@ -63,7 +64,8 @@ local function find_bug_node(pos) -- end -- end - return true; + return true; + end end local searching_range = {x = 10, y = 5, z = 10} @@ -112,7 +114,7 @@ working_villages.register_job("working_villages:job_bugcollector", { self:handle_obstacles() if self:timer_exceeded("bugcollector:search",20) then self:collect_nearest_item_by_condition(bugs.is_bug, searching_range) - local target = func.search_surrounding(self.object:get_pos(), find_bug_node, searching_range) + local target = func.search_surrounding(self.object:get_pos(), find_bug_node(self), searching_range) if target ~= nil then local destination = func.find_adjacent_clear(target) if destination then diff --git a/working_villagers/jobs/farmer.lua b/working_villagers/jobs/farmer.lua index 58d02aa..b53a90f 100644 --- a/working_villagers/jobs/farmer.lua +++ b/working_villagers/jobs/farmer.lua @@ -76,16 +76,18 @@ function farming_plants.is_plant(item_name) return true; end -local function find_plant_node(pos) - if minetest.is_protected(pos, "") then return false end +local function find_plant_node(self) + return function(pos) + if minetest.is_protected(pos, self:get_player_name()) then return false end if working_villages.failed_pos_test(pos) then return false end - local node = minetest.get_node(pos); - local data = farming_plants.get_plant(node.name); - if (not data) then - return false; + local node = minetest.get_node(pos); + local data = farming_plants.get_plant(node.name); + if (not data) then + return false; + end + return true; end - return true; end local searching_range = {x = 10, y = 3, z = 10} @@ -129,7 +131,7 @@ working_villages.register_job("working_villages:job_farmer", { self:handle_obstacles() if self:timer_exceeded("farmer:search",20) then self:collect_nearest_item_by_condition(farming_plants.is_plant, searching_range) - local target = func.search_surrounding(self.object:get_pos(), find_plant_node, searching_range) + local target = func.search_surrounding(self.object:get_pos(), find_plant_node(self), searching_range) if target ~= nil then local destination = func.find_adjacent_clear(target) if destination then diff --git a/working_villagers/jobs/gardener.lua b/working_villagers/jobs/gardener.lua index 8230b45..1068812 100644 --- a/working_villagers/jobs/gardener.lua +++ b/working_villagers/jobs/gardener.lua @@ -44,22 +44,24 @@ function gardening_nodes.is_dirt(item_name) return true; end -local function find_dirt_node(pos) - if minetest.is_protected(pos, "") then return false end +local function find_dirt_node(self) + return function(pos) + if minetest.is_protected(pos, self:get_player_name()) then return false end if working_villages.failed_pos_test(pos) then return false end - local node = minetest.get_node(pos); - local data = gardening_nodes.get_dirt(node.name); - if (not data) then - return false; + local node = minetest.get_node(pos); + local data = gardening_nodes.get_dirt(node.name); + if (not data) then + return false; + end + local water_rad = 3 + local water_names = { + "default:water_source", + "default:river_water_source", + } + local water_pos = minetest.find_node_near(pos, water_rad, water_names) + return water_pos ~= nil end - local water_rad = 3 - local water_names = { - "default:water_source", - "default:river_water_source", - } - local water_pos = minetest.find_node_near(pos, water_rad, water_names) - return water_pos ~= nil end local searching_range = {x = 10, y = 3, z = 10} @@ -108,7 +110,7 @@ working_villages.register_job("working_villages:job_gardener", { self:handle_obstacles() if self:timer_exceeded("gardener:search",20) then self:collect_nearest_item_by_condition(gardening_nodes.is_dirt, searching_range) - local target = func.search_surrounding(self.object:get_pos(), find_dirt_node, searching_range) + local target = func.search_surrounding(self.object:get_pos(), find_dirt_node(self), searching_range) if target ~= nil then local destination = func.find_adjacent_clear(target) if destination then diff --git a/working_villagers/jobs/gem_miner.lua b/working_villagers/jobs/gem_miner.lua index eb9b001..354b66d 100644 --- a/working_villagers/jobs/gem_miner.lua +++ b/working_villagers/jobs/gem_miner.lua @@ -41,15 +41,16 @@ function gems.is_ore(item_name) return true; end -local function find_ore_node(pos) - if minetest.is_protected(pos, "") then return false end +local function find_ore_node(self) + return function(pos) + if minetest.is_protected(pos, self:get_player_name()) then return false end if working_villages.failed_pos_test(pos) then return false end - local node = minetest.get_node(pos); - local data = gems.get_ore(node.name); - if (not data) then - return false; - end + local node = minetest.get_node(pos); + local data = gems.get_ore(node.name); + if (not data) then + return false; + end -- if data.collect_only_top then -- -- prevent to collect plat part, which can continue to grow @@ -65,7 +66,8 @@ local function find_ore_node(pos) -- end -- end - return true; + return true; + end end local searching_range = {x = 10, y = 5, z = 10} @@ -112,7 +114,7 @@ working_villages.register_job("working_villages:job_gem_miner", { if self:timer_exceeded("gemminer:search",20) then searching_range.h = 2 -- this doesn't prevent burrowing self:collect_nearest_item_by_condition(gems.is_ore, searching_range) - local target = func.search_surrounding_inv(self.object:get_pos(), find_ore_node, searching_range) -- that should fix 'em + local target = func.search_surrounding_inv(self.object:get_pos(), find_ore_node(self), searching_range) -- that should fix 'em if target ~= nil then local destination = func.find_adjacent_clear(target) if destination then -- this definitely makes him burrow diff --git a/working_villagers/jobs/landscaper.lua b/working_villagers/jobs/landscaper.lua index 5ddb421..9f5a5b4 100644 --- a/working_villagers/jobs/landscaper.lua +++ b/working_villagers/jobs/landscaper.lua @@ -51,15 +51,16 @@ function dirts.is_dirt(item_name) return true; end -local function find_dirt_node(pos) - if minetest.is_protected(pos, "") then return false end +local function find_dirt_node(self) + return function(pos) + if minetest.is_protected(pos, self:get_player_name()) then return false end if working_villages.failed_pos_test(pos) then return false end - local node = minetest.get_node(pos); - local data = dirts.get_dirt(node.name); - if (not data) then - return false; - end + local node = minetest.get_node(pos); + local data = dirts.get_dirt(node.name); + if (not data) then + return false; + end -- if data.collect_only_top then -- -- prevent to collect plant part, which can continue to grow @@ -75,7 +76,8 @@ local function find_dirt_node(pos) -- end -- end - return true; + return true; + end end local searching_range = {x = 10, y = 5, z = 10} @@ -123,7 +125,7 @@ working_villages.register_job("working_villages:job_landscaper", { if self:timer_exceeded("landscaper:search",20) then searching_range.h = 2 -- this doesn't really work to keep him from burrowing self:collect_nearest_item_by_condition(dirts.is_dirt, searching_range) - local target = func.search_surrounding_inv(self.object:get_pos(), find_dirt_node, searching_range) + local target = func.search_surrounding_inv(self.object:get_pos(), find_dirt_node(self), searching_range) if target ~= nil then local destination = func.find_adjacent_clear(target) if destination then -- I'm pretty sure this makes him burrow diff --git a/working_villagers/jobs/miner.lua b/working_villagers/jobs/miner.lua index 1f4eff3..5e02a06 100644 --- a/working_villagers/jobs/miner.lua +++ b/working_villagers/jobs/miner.lua @@ -48,15 +48,16 @@ function stones.is_stone(item_name) return true; end -local function find_stone_node(pos) - if minetest.is_protected(pos, "") then return false end +local function find_stone_node(self) + return function(pos) + if minetest.is_protected(pos, self:get_player_name()) then return false end if working_villages.failed_pos_test(pos) then return false end - local node = minetest.get_node(pos); - local data = stones.get_stone(node.name); - if (not data) then - return false; - end + local node = minetest.get_node(pos); + local data = stones.get_stone(node.name); + if (not data) then + return false; + end -- if data.collect_only_top then -- -- prevent to collect plat part, which can continue to grow @@ -72,7 +73,8 @@ local function find_stone_node(pos) -- end -- end - return true; + return true; + end end local searching_range = {x = 10, y = 5, z = 10} @@ -119,7 +121,7 @@ working_villages.register_job("working_villages:job_miner", { if self:timer_exceeded("miner:search",20) then searching_range.h = 2 -- this doesn't prevent burrowing self:collect_nearest_item_by_condition(stones.is_stone, searching_range) - local target = func.search_surrounding_inv(self.object:get_pos(), find_stone_node, searching_range) -- that should fix 'em + local target = func.search_surrounding_inv(self.object:get_pos(), find_stone_node(self), searching_range) -- that should fix 'em if target ~= nil then local destination = func.find_adjacent_clear(target) if destination then -- this definitely makes him burrow diff --git a/working_villagers/jobs/plant_collector.lua b/working_villagers/jobs/plant_collector.lua index efcc640..09ec204 100644 --- a/working_villagers/jobs/plant_collector.lua +++ b/working_villagers/jobs/plant_collector.lua @@ -40,35 +40,38 @@ function herbs.is_herb(item_name) return true; end -local function find_herb_node(pos) - if minetest.is_protected(pos, "") then return false end +local function find_herb_node(self) + return function(pos) + if minetest.is_protected(pos, self:get_player_name()) then return false end if working_villages.failed_pos_test(pos) then return false end - local node = minetest.get_node(pos); - local data = herbs.get_herb(node.name); - if (not data) then - return false; - end + local node = minetest.get_node(pos); + local data = herbs.get_herb(node.name); + if (not data) then + return false; + end - if data.collect_only_top then - -- prevent to collect plat part, which can continue to grow - local pos_below = {x=pos.x, y=pos.y-1, z=pos.z} - local node_below = minetest.get_node(pos_below); - if (node_below.name~=node.name) then - return false; - end - local pos_above = {x=pos.x, y=pos.y+1, z=pos.z} - local node_above = minetest.get_node(pos_above); - if (node_above.name==node.name) then - return false; - end - end + if data.collect_only_top then + -- prevent to collect plat part, which can continue to grow + local pos_below = {x=pos.x, y=pos.y-1, z=pos.z} + local node_below = minetest.get_node(pos_below); + if (node_below.name~=node.name) then + return false; + end + local pos_above = {x=pos.x, y=pos.y+1, z=pos.z} + local node_above = minetest.get_node(pos_above); + if (node_above.name==node.name) then + return false; + end + end - if data.responsible_foraging then - return minetest.find_node_near(pos, 9, node.name) ~= nil - end + -- don't raze renewable resources + if data.responsible_foraging then + return minetest.find_node_near(pos, 9, node.name) ~= nil + end - return true; + return true; + end end local searching_range = {x = 10, y = 5, z = 10} @@ -91,7 +94,7 @@ working_villages.register_job("working_villages:job_herbcollector", { self:handle_obstacles() if self:timer_exceeded("herbcollector:search",20) then self:collect_nearest_item_by_condition(herbs.is_herb, searching_range) - local target = func.search_surrounding(self.object:get_pos(), find_herb_node, searching_range) + local target = func.search_surrounding(self.object:get_pos(), find_herb_node(self), searching_range) if target ~= nil then local destination = func.find_adjacent_clear(target) if destination then diff --git a/working_villagers/jobs/snowclearer.lua b/working_villagers/jobs/snowclearer.lua index 63454b8..e6c770b 100644 --- a/working_villagers/jobs/snowclearer.lua +++ b/working_villagers/jobs/snowclearer.lua @@ -1,9 +1,11 @@ local func = working_villages.require("jobs/util") -local function find_snow(p) - if minetest.is_protected(p, "") then return false end +local function find_snow(self) + return function(p) + if minetest.is_protected(p, self:get_player_name()) then return false end if working_villages.failed_pos_test(p) then return false end - -- what about ice? better bring bucket boy if you enable better ice - return minetest.get_node(p).name == "default:snow" + -- TODO what about ice? better bring bucket boy if you enable better ice + return minetest.get_node(p).name == "default:snow" + end end local searching_range = {x = 10, y = 3, z = 10} @@ -51,7 +53,7 @@ I'm doing anyway, clearing the snow away.", self:count_timer("snowclearer:change_dir") self:handle_obstacles() if self:timer_exceeded("snowclearer:search",20) then - local target = func.search_surrounding(self.object:get_pos(), find_snow, searching_range) + local target = func.search_surrounding(self.object:get_pos(), find_snow(self), searching_range) if target ~= nil then local destination = func.find_adjacent_clear(target) if destination==false then diff --git a/working_villagers/jobs/watercarrier.lua b/working_villagers/jobs/watercarrier.lua index 1a1f286..9ac87be 100644 --- a/working_villagers/jobs/watercarrier.lua +++ b/working_villagers/jobs/watercarrier.lua @@ -32,16 +32,18 @@ function liquids.is_liquid(item_name) return true; end -local function find_liquid_nodes(pos) - if minetest.is_protected(pos, "") then return false end +local function find_liquid_nodes(self) + return function(pos) + if minetest.is_protected(pos, self:get_player_name()) then return false end if working_villages.failed_pos_test(pos) then return false end - local node = minetest.get_node(pos); - local data = liquids.get_liquid(node.name); - if (not data) then - return false; + local node = minetest.get_node(pos); + local data = liquids.get_liquid(node.name); + if (not data) then + return false; + end + return true; end - return true; end local searching_range = {x = 10, y = 3, z = 10} @@ -80,7 +82,7 @@ working_villages.register_job("working_villages:job_watercarrier", { self:handle_obstacles() if self:timer_exceeded("watercarrier:search",20) then self:collect_nearest_item_by_condition(liquids.is_liquid, searching_range) - local target = func.search_surrounding(self.object:get_pos(), find_liquid_nodes, searching_range) + local target = func.search_surrounding(self.object:get_pos(), find_liquid_nodes(self), searching_range) if target ~= nil then local destination = func.find_adjacent_clear(target) if destination then diff --git a/working_villagers/jobs/wizard.lua b/working_villagers/jobs/wizard.lua index 7acbeb2..28a86ad 100644 --- a/working_villagers/jobs/wizard.lua +++ b/working_villagers/jobs/wizard.lua @@ -37,23 +37,26 @@ function spellbooks.is_book(item_name) return true; end -local function find_book_nodes(pos) +-- TODO support other types of magick items +local function find_book_nodes(self) + return function(pos) if minetest.is_protected(pos, "") then return false end if working_villages.failed_pos_test(pos) then return false end - local node = minetest.get_node(pos); - local data = spellbooks.get_book(node.name); - if (not data) then - return false; + local node = minetest.get_node(pos); + local data = spellbooks.get_book(node.name); + if (not data) then + return false; + end + local meta = minetest.get_meta(pos) + local text = meta:get_string("text") + local owner = meta:get_string("owner") + local title = meta:get_string("title") + if text == nil or text == "" then return false end + if owner == nil or owner == "" then return false end + if title == nil or title == "" then return false end + return true; end - local meta = minetest.get_meta(pos) - local text = meta:get_string("text") - local owner = meta:get_string("owner") - local title = meta:get_string("title") - if text == nil or text == "" then return false end - if owner == nil or owner == "" then return false end - if title == nil or title == "" then return false end - return true; end local searching_range = {x = 10, y = 3, z = 10} @@ -97,7 +100,7 @@ working_villages.register_job("working_villages:job_wizard", { self:handle_obstacles() if self:timer_exceeded("wizard:search",20) then self:collect_nearest_item_by_condition(spellbooks.is_book, searching_range) - local target = func.search_surrounding(self.object:get_pos(), find_book_nodes, searching_range) + local target = func.search_surrounding(self.object:get_pos(), find_book_nodes(self), searching_range) if target ~= nil then local destination = func.find_adjacent_clear(target) if destination then diff --git a/working_villagers/jobs/woodcutter.lua b/working_villagers/jobs/woodcutter.lua index ec0e182..ad803ad 100644 --- a/working_villagers/jobs/woodcutter.lua +++ b/working_villagers/jobs/woodcutter.lua @@ -1,14 +1,16 @@ local func = working_villages.require("jobs/util") -local function find_tree(p) - local adj_node = minetest.get_node(p) - if minetest.get_item_group(adj_node.name, "tree") > 0 then - -- FIXME: need a player name if villagers can own a protected area - if minetest.is_protected(p, "") then return false end - if working_villages.failed_pos_test(p) then return false end - return true +local function find_tree(self) + return function(p) + local adj_node = minetest.get_node(p) + if minetest.get_item_group(adj_node.name, "tree") > 0 then + -- FIXME: need a player name if villagers can own a protected area + if minetest.is_protected(p, self:get_player_name()) then return false end + if working_villages.failed_pos_test(p) then return false end + return true + end + return false end - return false end local function is_sapling(n) @@ -101,7 +103,7 @@ When I find a sappling I'll plant it on some soil near a bright place so a new t end end end - local target = func.search_surrounding(self.object:get_pos(), find_tree, searching_range) + local target = func.search_surrounding(self.object:get_pos(), find_tree(self), searching_range) if target ~= nil then local destination = func.find_adjacent_clear(target) destination = func.find_ground_below(destination)