Make villagers hurry for long paths and night

This commit is contained in:
kno10 2024-10-28 23:54:41 +01:00
parent 16e17ba1ed
commit 488f61ba1b
2 changed files with 7 additions and 5 deletions

View File

@ -657,15 +657,16 @@ function mob_class:flop()
end end
end end
function mob_class:go_to_pos(b) function mob_class:go_to_pos(b, speed)
if not self then return end if not self then return end
if not b then return end if not b then return end
local s = self.object:get_pos() local s = self.object:get_pos()
if vector_distance(b,s) < .4 then return true end if vector_distance(b,s) < .4 then return true end
if b.y > s.y + 0.2 then self:do_jump() end if b.y > s.y + 0.2 then self:do_jump() end
self:turn_in_direction(b.x - s.x, b.z - s.z, 2) self:turn_in_direction(b.x - s.x, b.z - s.z, 2)
self:set_velocity(self.walk_velocity) speed = speed or self.walk_velocity
self:set_animation("walk") self:set_velocity(speed)
self:set_animation(speed <= self.walk_velocity and "walk" or "run")
end end
local check_herd_timer = 0 local check_herd_timer = 0

View File

@ -476,14 +476,15 @@ function mob_class:check_gowp(dtime)
local failed_attempts = self.current_target["failed_attempts"] local failed_attempts = self.current_target["failed_attempts"]
mcl_log("There after " .. failed_attempts .. " failed attempts. current target:".. minetest.pos_to_string(self.current_target.pos) .. ". Distance: " .. distance_to_current_target) mcl_log("There after " .. failed_attempts .. " failed attempts. current target:".. minetest.pos_to_string(self.current_target.pos) .. ". Distance: " .. distance_to_current_target)
local hurry = (self.order == "sleep" or #self.waypoints > 15) and self.run_velocity or self.walk_velocity
self.current_target = table.remove(self.waypoints, 1) self.current_target = table.remove(self.waypoints, 1)
-- use smoothing -- TODO: check for blockers before cutting corners? -- use smoothing -- TODO: check for blockers before cutting corners?
if #self.waypoints > 0 and not self.current_target["action"] then if #self.waypoints > 0 and not self.current_target["action"] then
local curwp, nextwp = self.current_target.pos, self.waypoints[1].pos local curwp, nextwp = self.current_target.pos, self.waypoints[1].pos
self:go_to_pos(vector.new(curwp.x*0.7+nextwp.x*0.3,curwp.y,curwp.z*0.7+nextwp.z*0.3)) self:go_to_pos(vector.new(curwp.x*0.7+nextwp.x*0.3,curwp.y,curwp.z*0.7+nextwp.z*0.3), hurry)
return return
end end
self:go_to_pos(self.current_target.pos) self:go_to_pos(self.current_target.pos, hurry)
--if self.current_target["action"] then self:set_velocity(self.walk_velocity * 0.5) end --if self.current_target["action"] then self:set_velocity(self.walk_velocity * 0.5) end
return return
elseif self.current_target and self.current_target.pos then elseif self.current_target and self.current_target.pos then