From 43881526507f2607619fc9a7779409b4cd42b667 Mon Sep 17 00:00:00 2001 From: kno10 Date: Mon, 28 Oct 2024 23:54:41 +0100 Subject: [PATCH] Make villagers hurry for long paths and night --- mods/ENTITIES/mcl_mobs/movement.lua | 7 ++++--- mods/ENTITIES/mcl_mobs/pathfinding.lua | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/movement.lua b/mods/ENTITIES/mcl_mobs/movement.lua index d6e641de6..c7bff6287 100644 --- a/mods/ENTITIES/mcl_mobs/movement.lua +++ b/mods/ENTITIES/mcl_mobs/movement.lua @@ -657,15 +657,16 @@ function mob_class:flop() 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 b then return end local s = self.object:get_pos() if vector_distance(b,s) < .4 then return true 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:set_velocity(self.walk_velocity) - self:set_animation("walk") + speed = speed or self.walk_velocity + self:set_velocity(speed) + self:set_animation(speed <= self.walk_velocity and "walk" or "run") end local check_herd_timer = 0 diff --git a/mods/ENTITIES/mcl_mobs/pathfinding.lua b/mods/ENTITIES/mcl_mobs/pathfinding.lua index 1082c9ad5..1374237f0 100644 --- a/mods/ENTITIES/mcl_mobs/pathfinding.lua +++ b/mods/ENTITIES/mcl_mobs/pathfinding.lua @@ -476,14 +476,15 @@ function mob_class:check_gowp(dtime) 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) + 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) -- use smoothing -- TODO: check for blockers before cutting corners? if #self.waypoints > 0 and not self.current_target["action"] then 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 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 return elseif self.current_target and self.current_target.pos then