Villager will now reclaim job during the day even when it isn't work time

This commit is contained in:
ancientmarinerdev 2022-12-31 19:41:42 +00:00 committed by Gitea
parent 325a666c62
commit 465a919f6b
1 changed files with 70 additions and 66 deletions

View File

@ -770,7 +770,7 @@ local function check_bed (entity)
local n = minetest.get_node(b)
local is_bed_bottom = string.find(n.name,"_bottom")
mcl_log("" .. tostring(is_bed_bottom))
--mcl_log("is bed bottom: " .. tostring(is_bed_bottom))
if n and not is_bed_bottom then
mcl_log("Where did my bed go?!")
entity._bed = nil --the stormtroopers have killed uncle owen
@ -1135,22 +1135,19 @@ local function validate_jobsite(self)
end
local function do_work (self)
--debug_trades(self)
if self.child then
mcl_log("A child so don't send to work")
if not self or self.child then
mcl_log("No self, or a child so don't work")
return
end
--mcl_log("Time for work")
local jobsite_node = retrieve_my_jobsite (self)
-- Don't try if looking_for_work, or gowp possibly
if validate_jobsite(self) then
--mcl_log("My jobsite is valid. Do i need to travel?")
local jobsite2 = retrieve_my_jobsite (self)
if jobsite_node then
local jobsite = self._jobsite
if self and jobsite2 and self._jobsite then
local distance_to_jobsite = vector.distance(self.object:get_pos(),self._jobsite)
local distance_to_jobsite = vector.distance(self.object:get_pos(), jobsite)
--mcl_log("Villager: ".. minetest.pos_to_string(self.object:get_pos()) .. ", jobsite: " .. minetest.pos_to_string(self._jobsite) .. ", distance to jobsite: ".. distance_to_jobsite)
if distance_to_jobsite < 2 then
@ -1185,9 +1182,7 @@ local function do_work (self)
end)
end
end
elseif self._profession == "unemployed" or has_traded(self) then
get_a_job(self)
end
end
local below_vec = vector.new(0, -1, 0)
@ -1214,17 +1209,10 @@ local function get_ground_below_floating_object (float_pos)
end
local function go_to_town_bell(self)
if self.order == GATHERING then
--mcl_log("Already gathering")
return
else
mcl_log("Current order" .. self.order)
end
if self.order == GATHERING then return
else mcl_log("Current order" .. self.order) end
if not self:ready_to_path() then
mcl_log("Negative response to go_path. Do not bother")
return
end
if not self:ready_to_path() then return end
mcl_log("Go to town bell")
@ -1307,22 +1295,45 @@ local function validate_bed(self)
end
local function do_activity (self)
-- Maybe just check we're pathfinding first?
if self.following then
mcl_log("Following, so do not do activity.")
return
end
if self.state == PATHFINDING then
mcl_log("Pathfinding, so do not do activity.")
return
end
if not validate_bed(self) and self.state ~= PATHFINDING then
local jobsite_valid = false
if not mcl_beds.is_night() then
if self.order == SLEEP then self.order = nil end
mcl_log("Villager has no bed. Currently at location: "..minetest.pos_to_string(self.object:get_pos()))
if not validate_jobsite(self) then
--debug_trades(self)
if self._profession == "unemployed" or has_traded(self) then
get_a_job(self)
return
end
else
jobsite_valid = true
--mcl_log("My jobsite is valid. Do i need to travel?")
end
else
if self.order == WORK then self.order = nil end
if not validate_bed(self) then
if self.order == SLEEP then self.order = nil end
mcl_log("Villager at this location has no bed: " .. minetest.pos_to_string(self.object:get_pos()))
take_bed (self)
end
end
-- Only check in day or during thunderstorm but wandered_too_far code won't work
local wandered_too_far = false
if check_bed (self) then
wandered_too_far = ( self.state ~= PATHFINDING ) and (vector.distance(self.object:get_pos(),self._bed) > 50 )
wandered_too_far = vector.distance(self.object:get_pos(),self._bed) > 50
end
if wandered_too_far then
@ -1330,7 +1341,7 @@ local function do_activity (self)
go_home(self, false)
elseif get_activity() == SLEEP then
go_home(self, true)
elseif get_activity() == WORK then
elseif get_activity() == WORK and jobsite_valid then
do_work(self)
elseif get_activity() == GATHERING then
go_to_town_bell(self)
@ -1339,13 +1350,6 @@ local function do_activity (self)
self.order = nil
end
-- Daytime is work and play time
if not mcl_beds.is_night() then
if self.order == SLEEP then self.order = nil end
else
if self.order == WORK then self.order = nil end
end
end
local function update_max_tradenum(self)