forked from VoxeLibre/VoxeLibre
Villager will now reclaim job during the day even when it isn't work time
This commit is contained in:
parent
325a666c62
commit
465a919f6b
|
@ -770,7 +770,7 @@ local function check_bed (entity)
|
||||||
local n = minetest.get_node(b)
|
local n = minetest.get_node(b)
|
||||||
|
|
||||||
local is_bed_bottom = string.find(n.name,"_bottom")
|
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
|
if n and not is_bed_bottom then
|
||||||
mcl_log("Where did my bed go?!")
|
mcl_log("Where did my bed go?!")
|
||||||
entity._bed = nil --the stormtroopers have killed uncle owen
|
entity._bed = nil --the stormtroopers have killed uncle owen
|
||||||
|
@ -1135,22 +1135,19 @@ local function validate_jobsite(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function do_work (self)
|
local function do_work (self)
|
||||||
--debug_trades(self)
|
|
||||||
if self.child then
|
if not self or self.child then
|
||||||
mcl_log("A child so don't send to work")
|
mcl_log("No self, or a child so don't work")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--mcl_log("Time for work")
|
--mcl_log("Time for work")
|
||||||
|
local jobsite_node = retrieve_my_jobsite (self)
|
||||||
|
|
||||||
-- Don't try if looking_for_work, or gowp possibly
|
if jobsite_node then
|
||||||
if validate_jobsite(self) then
|
|
||||||
--mcl_log("My jobsite is valid. Do i need to travel?")
|
|
||||||
|
|
||||||
local jobsite2 = retrieve_my_jobsite (self)
|
|
||||||
local jobsite = self._jobsite
|
local jobsite = self._jobsite
|
||||||
|
|
||||||
if self and jobsite2 and self._jobsite then
|
local distance_to_jobsite = vector.distance(self.object:get_pos(), jobsite)
|
||||||
local distance_to_jobsite = vector.distance(self.object:get_pos(),self._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)
|
--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
|
if distance_to_jobsite < 2 then
|
||||||
|
@ -1185,9 +1182,7 @@ local function do_work (self)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif self._profession == "unemployed" or has_traded(self) then
|
|
||||||
get_a_job(self)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local below_vec = vector.new(0, -1, 0)
|
local below_vec = vector.new(0, -1, 0)
|
||||||
|
@ -1214,17 +1209,10 @@ local function get_ground_below_floating_object (float_pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function go_to_town_bell(self)
|
local function go_to_town_bell(self)
|
||||||
if self.order == GATHERING then
|
if self.order == GATHERING then return
|
||||||
--mcl_log("Already gathering")
|
else mcl_log("Current order" .. self.order) end
|
||||||
return
|
|
||||||
else
|
|
||||||
mcl_log("Current order" .. self.order)
|
|
||||||
end
|
|
||||||
|
|
||||||
if not self:ready_to_path() then
|
if not self:ready_to_path() then return end
|
||||||
mcl_log("Negative response to go_path. Do not bother")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
mcl_log("Go to town bell")
|
mcl_log("Go to town bell")
|
||||||
|
|
||||||
|
@ -1307,22 +1295,45 @@ local function validate_bed(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function do_activity (self)
|
local function do_activity (self)
|
||||||
-- Maybe just check we're pathfinding first?
|
|
||||||
if self.following then
|
if self.following then
|
||||||
mcl_log("Following, so do not do activity.")
|
mcl_log("Following, so do not do activity.")
|
||||||
return
|
return
|
||||||
end
|
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
|
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)
|
take_bed (self)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Only check in day or during thunderstorm but wandered_too_far code won't work
|
-- Only check in day or during thunderstorm but wandered_too_far code won't work
|
||||||
local wandered_too_far = false
|
local wandered_too_far = false
|
||||||
if check_bed (self) then
|
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
|
end
|
||||||
|
|
||||||
if wandered_too_far then
|
if wandered_too_far then
|
||||||
|
@ -1330,7 +1341,7 @@ local function do_activity (self)
|
||||||
go_home(self, false)
|
go_home(self, false)
|
||||||
elseif get_activity() == SLEEP then
|
elseif get_activity() == SLEEP then
|
||||||
go_home(self, true)
|
go_home(self, true)
|
||||||
elseif get_activity() == WORK then
|
elseif get_activity() == WORK and jobsite_valid then
|
||||||
do_work(self)
|
do_work(self)
|
||||||
elseif get_activity() == GATHERING then
|
elseif get_activity() == GATHERING then
|
||||||
go_to_town_bell(self)
|
go_to_town_bell(self)
|
||||||
|
@ -1339,13 +1350,6 @@ local function do_activity (self)
|
||||||
self.order = nil
|
self.order = nil
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
local function update_max_tradenum(self)
|
local function update_max_tradenum(self)
|
||||||
|
|
Loading…
Reference in New Issue