mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 18:41:09 +01:00
Merge pull request 'Allow villagers to resettle and not run back to job and and old bed' (#2967) from feature/villager_pt_6 into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/2967 Reviewed-by: cora <cora@noreply.git.minetest.land>
This commit is contained in:
commit
4dba6a62cf
1 changed files with 51 additions and 13 deletions
|
@ -30,6 +30,8 @@ local DEFAULT_WALK_CHANCE = 33 -- chance to walk in percent, if no player nearby
|
|||
local PLAYER_SCAN_INTERVAL = 5 -- every X seconds, villager looks for players nearby
|
||||
local PLAYER_SCAN_RADIUS = 4 -- scan radius for looking for nearby players
|
||||
|
||||
local RESETTLE_DISTANCE = 100 -- If a mob is transported this far from home, it gives up bed and job and resettles
|
||||
|
||||
local PATHFINDING = "gowp"
|
||||
|
||||
--[=======[ TRADING ]=======]
|
||||
|
@ -885,11 +887,18 @@ local function has_golem(pos)
|
|||
end
|
||||
end
|
||||
|
||||
local function monsters_near(self)
|
||||
for _,o in pairs(minetest.get_objects_inside_radius(self.object:get_pos(),10)) do
|
||||
local l = o:get_luaentity()
|
||||
if l and l.type =="monster" then return true end
|
||||
end
|
||||
end
|
||||
|
||||
local function has_summon_participants(self)
|
||||
local r = 0
|
||||
for _,o in pairs(minetest.get_objects_inside_radius(self.object:get_pos(),10)) do
|
||||
local l = o:get_luaentity()
|
||||
--TODO check for panicking or gossiping
|
||||
--TODO check for gossiping
|
||||
if l and l.name == "mobs_mc:villager" then r = r + 1 end
|
||||
end
|
||||
return r > 2
|
||||
|
@ -913,7 +922,8 @@ local function check_summon(self,dtime)
|
|||
if self._summon_timer and self._summon_timer > 30 then
|
||||
local pos = self.object:get_pos()
|
||||
self._summon_timer = 0
|
||||
if has_golem(pos) then return false end
|
||||
if has_golem(pos) then return end
|
||||
if not monsters_near(self) then return end
|
||||
if not has_summon_participants(self) then return end
|
||||
summon_golem(self)
|
||||
elseif self._summon_timer == nil then
|
||||
|
@ -1089,25 +1099,38 @@ local function retrieve_my_jobsite (self)
|
|||
return
|
||||
end
|
||||
|
||||
local function remove_job (self)
|
||||
self._jobsite = nil
|
||||
if not has_traded(self) then
|
||||
mcl_log("Cannot retrieve my jobsite. I am now unemployed.")
|
||||
self._profession = "unemployed"
|
||||
self._trades = nil
|
||||
set_textures(self)
|
||||
else
|
||||
mcl_log("Cannot retrieve my jobsite but I've traded so only remove jobsite.")
|
||||
end
|
||||
end
|
||||
|
||||
local function validate_jobsite(self)
|
||||
if self._profession == "unemployed" then return false end
|
||||
|
||||
if not retrieve_my_jobsite (self) then
|
||||
self._jobsite = nil
|
||||
local job_block = retrieve_my_jobsite (self)
|
||||
if not job_block then
|
||||
if self.order == WORK then
|
||||
self.order = nil
|
||||
end
|
||||
|
||||
if not has_traded(self) then
|
||||
mcl_log("Cannot retrieve my jobsite. I am now unemployed.")
|
||||
self._profession = "unemployed"
|
||||
self._trades = nil
|
||||
set_textures(self)
|
||||
else
|
||||
mcl_log("Cannot retrieve my jobsite but I've traded so only remove jobsite.")
|
||||
end
|
||||
remove_job (self)
|
||||
return false
|
||||
else
|
||||
local resettle = vector.distance(self.object:get_pos(),self._jobsite) > RESETTLE_DISTANCE
|
||||
mcl_log("Jobsite far, so resettle: " .. tostring(resettle))
|
||||
if resettle then
|
||||
local m = minetest.get_meta(self._jobsite)
|
||||
m:set_string("villager", nil)
|
||||
remove_job (self)
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -1222,6 +1245,17 @@ local function validate_bed(self)
|
|||
local bed_valid = true
|
||||
|
||||
local m = minetest.get_meta(self._bed)
|
||||
|
||||
local resettle = vector.distance(self.object:get_pos(),self._bed) > RESETTLE_DISTANCE
|
||||
mcl_log("Bed far, so resettle: " .. tostring(resettle))
|
||||
if resettle then
|
||||
mcl_log("Resettled. Ditch bed.")
|
||||
m:set_string("villager", nil)
|
||||
self._bed = nil
|
||||
bed_valid = false
|
||||
return false
|
||||
end
|
||||
|
||||
local owned_by_player = m:get_string("player")
|
||||
mcl_log("Player owner: " .. owned_by_player)
|
||||
if owned_by_player ~= "" then
|
||||
|
@ -1229,7 +1263,7 @@ local function validate_bed(self)
|
|||
m:set_string("villager", nil)
|
||||
self._bed = nil
|
||||
bed_valid = false
|
||||
return
|
||||
return false
|
||||
end
|
||||
|
||||
if m:get_string("villager") ~= self._id then
|
||||
|
@ -1245,6 +1279,10 @@ 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 not validate_bed(self) and self.state ~= PATHFINDING then
|
||||
if self.order == SLEEP then self.order = nil end
|
||||
|
|
Loading…
Reference in a new issue