Skip to content

Commit

Permalink
starting to add support for villager-owned protected areas
Browse files Browse the repository at this point in the history
  • Loading branch information
jichi authored and jichi committed Dec 3, 2023
1 parent 381bd5f commit a70f791
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 150 deletions.
20 changes: 11 additions & 9 deletions working_villagers/jobs/bone_collector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand Down
46 changes: 24 additions & 22 deletions working_villagers/jobs/brush_collector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down
20 changes: 11 additions & 9 deletions working_villagers/jobs/bug_collector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions working_villagers/jobs/farmer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 deletions working_villagers/jobs/gardener.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions working_villagers/jobs/gem_miner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions working_villagers/jobs/landscaper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions working_villagers/jobs/miner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit a70f791

Please sign in to comment.