diff --git a/working_villagers/jobs/bone_collector.lua b/working_villagers/jobs/bone_collector.lua index 16dc736..7d21119 100644 --- a/working_villagers/jobs/bone_collector.lua +++ b/working_villagers/jobs/bone_collector.lua @@ -36,8 +36,8 @@ function bones.is_bone(item_name) end local function find_bug_node(pos) - if minetest.is_protected(p, "") then return false end - if working_villages.failed_pos_test(p) then return false end + 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 = bones.get_bone(node.name); @@ -118,12 +118,14 @@ working_villages.register_job("working_villages:job_bonecollector", { self:set_displayed_action("collecting some bones") local success, ret = self:go_to(destination) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("looking at the unreachable bones") self:delay(100) else success, ret = self:dig(target,true) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("confused as to why collecting failed") self:delay(100) diff --git a/working_villagers/jobs/brush_collector.lua b/working_villagers/jobs/brush_collector.lua index 40c94ab..e98d21f 100644 --- a/working_villagers/jobs/brush_collector.lua +++ b/working_villagers/jobs/brush_collector.lua @@ -42,8 +42,8 @@ function shrubs.is_shrub(item_name) end local function find_herb_node(pos) - if minetest.is_protected(p, "") then return false end - if working_villages.failed_pos_test(p) then return false end + 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 = shrubs.get_shrub(node.name); @@ -106,12 +106,14 @@ working_villages.register_job("working_villages:job_brushcollector", { self:set_displayed_action("collecting some brush") local success, ret = self:go_to(destination) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("looking at the unreachable brush") self:delay(100) else success, ret = self:dig(target,true) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("confused as to why collecting failed") self:delay(100) diff --git a/working_villagers/jobs/bug_collector.lua b/working_villagers/jobs/bug_collector.lua index 57576b4..d301a32 100644 --- a/working_villagers/jobs/bug_collector.lua +++ b/working_villagers/jobs/bug_collector.lua @@ -40,8 +40,8 @@ function bugs.is_bug(item_name) end local function find_bug_node(pos) - if minetest.is_protected(p, "") then return false end - if working_villages.failed_pos_test(p) then return false end + 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 = bugs.get_bug(node.name); @@ -129,12 +129,14 @@ working_villages.register_job("working_villages:job_bugcollector", { self:set_displayed_action("collecting some bugs") local success, ret = self:go_to(destination) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("looking at the unreachable bugs") self:delay(100) else success, ret = self:dig(target,true) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("confused as to why collecting failed") self:delay(100) diff --git a/working_villagers/jobs/farmer.lua b/working_villagers/jobs/farmer.lua index 0b3aaed..58d02aa 100644 --- a/working_villagers/jobs/farmer.lua +++ b/working_villagers/jobs/farmer.lua @@ -77,8 +77,8 @@ function farming_plants.is_plant(item_name) end local function find_plant_node(pos) - if minetest.is_protected(p, "") then return false end - if working_villages.failed_pos_test(p) then return false end + 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 = farming_plants.get_plant(node.name); @@ -141,12 +141,35 @@ working_villages.register_job("working_villages:job_farmer", { end local plant_name = minetest.get_node(target).name self:set_displayed_action("farming some "..plant_name) - self:go_to(destination) - local plant_data = farming_plants.get_plant(plant_name); - self:dig(target,true) - if plant_data and plant_data.replant then - for index, value in ipairs(plant_data.replant) do - self:place(value, vector.add(target, vector.new(0,index-1,0))) + --self:go_to(destination) + --local plant_data = farming_plants.get_plant(plant_name); + --self:dig(target,true) + --if plant_data and plant_data.replant then + -- for index, value in ipairs(plant_data.replant) do + -- self:place(value, vector.add(target, vector.new(0,index-1,0))) + -- end + --end + + local success, ret = self:go_to(destination) + if not success then + assert(target ~= nil) + working_villages.failed_pos_record(target) + self:set_displayed_action("looking at the unreachable plants") + self:delay(100) + else + local plant_data = farming_plants.get_plant(plant_name); + success, ret = self:dig(target,true) + if not success then + assert(target ~= nil) + working_villages.failed_pos_record(target) + self:set_displayed_action("confused as to why farming failed") + self:delay(100) + else + if plant_data and plant_data.replant then + for index, value in ipairs(plant_data.replant) do + self:place(value, vector.add(target, vector.new(0,index-1,0))) + end + end end end end diff --git a/working_villagers/jobs/gardener.lua b/working_villagers/jobs/gardener.lua index 5c60311..8230b45 100644 --- a/working_villagers/jobs/gardener.lua +++ b/working_villagers/jobs/gardener.lua @@ -45,8 +45,8 @@ function gardening_nodes.is_dirt(item_name) end local function find_dirt_node(pos) - if minetest.is_protected(p, "") then return false end - if working_villages.failed_pos_test(p) then return false end + 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 = gardening_nodes.get_dirt(node.name); @@ -118,28 +118,36 @@ working_villages.register_job("working_villages:job_gardener", { print("failure: no adjacent walkable found") destination = target end - self:go_to(destination) local plant_name = minetest.get_node(target).name self:set_displayed_action("tilling some "..plant_name) - local plant_data = gardening_nodes.get_dirt(plant_name) - --self:dig(target,true) - --if plant_data and plant_data.replant then - -- for index, value in ipairs(plant_data.replant) do - -- self:place(value, vector.add(target, vector.new(0,index-1,0))) - -- end - --end - local name = stack:get_name() - if name == nil then return end - local def = minetest.registered_items[name] - if def == nil then return end - local on_use = def.on_use - if on_use == nil then return end - local user = self - local pointed_thing = {under=target, type="node",} - local new_stack = on_use(stack, user, pointed_thing) - -- TODO register position failure ? - self:set_wield_item_stack(new_stack) - for _=0,10 do coroutine.yield() end --wait 10 steps + --self:go_to(destination) + local success, ret = self:go_to(destination) + if not success then + assert(target ~= nil) + working_villages.failed_pos_record(target) + self:set_displayed_action("looking at the unreachable dirt") + self:delay(100) + else + local plant_data = gardening_nodes.get_dirt(plant_name) + --self:dig(target,true) + --if plant_data and plant_data.replant then + -- for index, value in ipairs(plant_data.replant) do + -- self:place(value, vector.add(target, vector.new(0,index-1,0))) + -- end + --end + local name = stack:get_name() + if name == nil then return end + local def = minetest.registered_items[name] + if def == nil then return end + local on_use = def.on_use + if on_use == nil then return end + local user = self + local pointed_thing = {under=target, type="node",} + local new_stack = on_use(stack, user, pointed_thing) + -- TODO register position failure ? + self:set_wield_item_stack(new_stack) + for _=0,10 do coroutine.yield() end --wait 10 steps + end end elseif self:timer_exceeded("gardener:change_dir",50) then self:change_direction_randomly() diff --git a/working_villagers/jobs/gem_miner.lua b/working_villagers/jobs/gem_miner.lua index 857fc3f..eb9b001 100644 --- a/working_villagers/jobs/gem_miner.lua +++ b/working_villagers/jobs/gem_miner.lua @@ -42,8 +42,8 @@ function gems.is_ore(item_name) end local function find_ore_node(pos) - if minetest.is_protected(p, "") then return false end - if working_villages.failed_pos_test(p) then return false end + 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 = gems.get_ore(node.name); @@ -128,12 +128,14 @@ working_villages.register_job("working_villages:job_gem_miner", { -- We may not be able to reach the log local success, ret = self:go_to(destination) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("looking at the unreachable rocks") self:delay(100) else success, ret = self:dig(target,true) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("confused as to why mining failed") self:delay(100) diff --git a/working_villagers/jobs/landscaper.lua b/working_villagers/jobs/landscaper.lua index d547b9a..5ddb421 100644 --- a/working_villagers/jobs/landscaper.lua +++ b/working_villagers/jobs/landscaper.lua @@ -52,8 +52,8 @@ function dirts.is_dirt(item_name) end local function find_dirt_node(pos) - if minetest.is_protected(p, "") then return false end - if working_villages.failed_pos_test(p) then return false end + 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 = dirts.get_dirt(node.name); @@ -139,12 +139,14 @@ working_villages.register_job("working_villages:job_landscaper", { -- We may not be able to reach the log local success, ret = self:go_to(destination) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("looking at the unreachable dirt") self:delay(100) else success, ret = self:dig(target,true) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("confused as to why digging failed at (x="..target.x..', y='..target.y..', z='..target.z..')') self:delay(100) diff --git a/working_villagers/jobs/miner.lua b/working_villagers/jobs/miner.lua index b56bf42..1f4eff3 100644 --- a/working_villagers/jobs/miner.lua +++ b/working_villagers/jobs/miner.lua @@ -49,8 +49,8 @@ function stones.is_stone(item_name) end local function find_stone_node(pos) - if minetest.is_protected(p, "") then return false end - if working_villages.failed_pos_test(p) then return false end + 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 = stones.get_stone(node.name); @@ -135,12 +135,14 @@ working_villages.register_job("working_villages:job_miner", { -- We may not be able to reach the log local success, ret = self:go_to(destination) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("looking at the unreachable rocks") self:delay(100) else success, ret = self:dig(target,true) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("confused as to why mining failed at (x="..target.x..', y='..target.y..', z='..target.z..')') self:delay(100) diff --git a/working_villagers/jobs/plant_collector.lua b/working_villagers/jobs/plant_collector.lua index 1c24834..efcc640 100644 --- a/working_villagers/jobs/plant_collector.lua +++ b/working_villagers/jobs/plant_collector.lua @@ -41,8 +41,8 @@ function herbs.is_herb(item_name) end local function find_herb_node(pos) - if minetest.is_protected(p, "") then return false end - if working_villages.failed_pos_test(p) then return false end + 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 = herbs.get_herb(node.name); @@ -108,12 +108,14 @@ working_villages.register_job("working_villages:job_herbcollector", { --herbs.get_herb(minetest.get_node(target).name); --self:dig(target,true) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("looking at the unreachable plant") self:delay(100) else success, ret = self:dig(target,true) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("confused as to why collecting failed") self:delay(100) diff --git a/working_villagers/jobs/snowclearer.lua b/working_villagers/jobs/snowclearer.lua index f74fb60..63454b8 100644 --- a/working_villagers/jobs/snowclearer.lua +++ b/working_villagers/jobs/snowclearer.lua @@ -63,12 +63,14 @@ I'm doing anyway, clearing the snow away.", --self:dig(target,true) local success, ret = self:go_to(destination) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("looking at the unreachable snow") self:delay(100) else success, ret = self:dig(target,true) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("confused as to why clearing failed") self:delay(100) diff --git a/working_villagers/jobs/watercarrier.lua b/working_villagers/jobs/watercarrier.lua index c0ebfa7..1a1f286 100644 --- a/working_villagers/jobs/watercarrier.lua +++ b/working_villagers/jobs/watercarrier.lua @@ -33,8 +33,8 @@ function liquids.is_liquid(item_name) end local function find_liquid_nodes(pos) - if minetest.is_protected(p, "") then return false end - if working_villages.failed_pos_test(p) then return false end + 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 = liquids.get_liquid(node.name); @@ -93,6 +93,7 @@ working_villages.register_job("working_villages:job_watercarrier", { --self:go_to(destination) local success, ret = self:go_to(destination) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("looking at the unreachable snow") self:delay(100) @@ -146,62 +147,3 @@ working_villages.register_job("working_villages:job_watercarrier", { working_villages.liquids = liquids --- move to wield item ---local log = working_villages.require("log") ---function working_villages.villager:manipulate_chest2(chest_pos, take_func, put_func, data) --- if func.is_chest(chest_pos) then --- -- try to put items --- local vil_inv = self:get_inventory(); --- --- -- from villager to chest --- if put_func then --- local size = vil_inv:get_size("main"); --- for index = 1,size do --- local stack = vil_inv:get_stack("main", index); --- if (not stack:is_empty()) and (put_func(self, stack, data)) then --- local chest_meta = minetest.get_meta(chest_pos); --- local chest_inv = chest_meta:get_inventory(); --- local leftover = chest_inv:add_item("main", stack); --- vil_inv:set_stack("main", index, leftover); --- for _=0,10 do coroutine.yield() end --wait 10 steps --- end --- end --- end --- -- from chest to villager --- if take_func then --- local chest_meta = minetest.get_meta(chest_pos); --- local chest_inv = chest_meta:get_inventory(); --- local size = chest_inv:get_size("main"); --- for index = 1,size do --- chest_meta = minetest.get_meta(chest_pos); --- chest_inv = chest_meta:get_inventory(); --- local stack = chest_inv:get_stack("main", index); --- if (not stack:is_empty()) and (take_func(self, stack, data)) then --- local leftover = vil_inv:add_item("wield_item", stack); --- chest_inv:set_stack("main", index, leftover); --- for _=0,10 do coroutine.yield() end --wait 10 steps --- end --- end --- end --- else --- log.error("Villager %s doe's not find cheston position %s.", self.inventory_name, minetest.pos_to_string(chest_pos)) --- end ---end --- ---function working_villages.villager:handle_chest2(take_func, put_func, data) --- if (not self.job_data.manipulated_chest2) then --- local chest_pos = self.pos_data.chest_pos --- if (chest_pos~=nil) then --- log.action("villager %s is handling chest at %s", self.inventory_name, minetest.pos_to_string(chest_pos)) --- self:set_state_info("I am taking and puting items from/to my chest.") --- self:set_displayed_action("active") --- local chest = minetest.get_node(chest_pos); --- local dir = minetest.facedir_to_dir(chest.param2); --- local destination = vector.subtract(chest_pos, dir); --- self:go_to(destination) --- self:manipulate_chest2(chest_pos, take_func, put_func, data); --- end --- self.job_data.manipulated_chest2 = true; --- end ---end - diff --git a/working_villagers/jobs/wizard.lua b/working_villagers/jobs/wizard.lua index c8a8b42..7acbeb2 100644 --- a/working_villagers/jobs/wizard.lua +++ b/working_villagers/jobs/wizard.lua @@ -38,8 +38,8 @@ function spellbooks.is_book(item_name) end local function find_book_nodes(pos) - if minetest.is_protected(p, "") then return false end - if working_villages.failed_pos_test(p) then return false end + 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); @@ -111,6 +111,7 @@ working_villages.register_job("working_villages:job_wizard", { --self:go_to(destination) local success, ret = self:go_to(destination) if not success then + assert(target ~= nil) working_villages.failed_pos_record(target) self:set_displayed_action("looking at the unreachable snow") self:delay(100) @@ -151,6 +152,7 @@ working_villages.register_job("working_villages:job_wizard", { local pointed_thing = {under=target, type="node",} local new_stack = on_use(stack, user, pointed_thing) self:set_wield_item_stack(new_stack) + -- TODO record position failure for _=0,10 do coroutine.yield() end --wait 10 steps -- TODO record successes so he's useful end @@ -161,29 +163,5 @@ working_villages.register_job("working_villages:job_wizard", { end, }) ---function working_villages.villager:get_properties() --- return self.object:get_properties() ----- local entity = self.object:get_luaentity() ----- assert(entity ~= nil) ----- assert(entity.hp_max ~= nil) ----- return { ----- ["hp_max"] = entity.hp_max, ----- } ---end ---function working_villages.villager:get_hp() --- return self.object:get_hp() ---end ---function working_villages.villager:set_hp(hp) --- return self.object:set_hp(hp) ---end ----- TODO -----function working_villages.villager:get_hp() ----- return 20 -----end ------- alright, this stubs it out. -----function working_villages.villager:set_hp() ----- return 20 -----end - working_villages.spellbooks = spellbooks