mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-12-24 17:09:32 +01:00
pathfind to jobsites
This commit is contained in:
parent
dbc5564d02
commit
f8fc111b4a
2 changed files with 53 additions and 26 deletions
|
@ -2329,6 +2329,7 @@ local function go_to_pos(entity,b)
|
||||||
if b.x > s.x then yaw = yaw + math.pi end
|
if b.x > s.x then yaw = yaw + math.pi end
|
||||||
entity.object:set_yaw(yaw)
|
entity.object:set_yaw(yaw)
|
||||||
set_velocity(entity,entity.follow_velocity)
|
set_velocity(entity,entity.follow_velocity)
|
||||||
|
mobs:set_animation(entity, "walk")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- execute current state (stand, walk, run, attacks)
|
-- execute current state (stand, walk, run, attacks)
|
||||||
|
@ -2387,9 +2388,9 @@ local do_states = function(self, dtime)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif self.state == "gowp" then
|
elseif self.state == "gowp" then
|
||||||
if not self.waypoints or not self._target then return end
|
|
||||||
local p = self.object:get_pos()
|
local p = self.object:get_pos()
|
||||||
if vector.distance(p,self._target) < 1 then
|
if not p or not self._target then return end
|
||||||
|
if vector.distance(p,self._target) < 2 or #self.waypoints == 0 then
|
||||||
self.waypoints = nil
|
self.waypoints = nil
|
||||||
self._target = nil
|
self._target = nil
|
||||||
self.current_target = nil
|
self.current_target = nil
|
||||||
|
@ -2399,13 +2400,19 @@ local do_states = function(self, dtime)
|
||||||
end
|
end
|
||||||
if not self.current_target or vector.distance(p,self.current_target) < 1.5 then
|
if not self.current_target or vector.distance(p,self.current_target) < 1.5 then
|
||||||
self.current_target = table.remove(self.waypoints, 1)
|
self.current_target = table.remove(self.waypoints, 1)
|
||||||
else
|
--minetest.log("nextwp:".. tostring(self.current_target) )
|
||||||
|
elseif self.current_target then
|
||||||
go_to_pos(self,self.current_target)
|
go_to_pos(self,self.current_target)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.current_target and not minetest.line_of_sight(self.object:get_pos(),self.current_target) then
|
if self.current_target and not minetest.line_of_sight(self.object:get_pos(),self.current_target) then
|
||||||
self.waypoints=minetest.find_path(p,self._target,150,1,4)
|
self.waypoints=minetest.find_path(p,self._target,150,1,4)
|
||||||
self.current_target = nil
|
self.current_target = nil
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not self.current_target then
|
||||||
|
--minetest.log("no path")
|
||||||
|
self.state = "walk"
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif self.state == "walk" then
|
elseif self.state == "walk" then
|
||||||
|
@ -2913,11 +2920,19 @@ local do_states = function(self, dtime)
|
||||||
end
|
end
|
||||||
|
|
||||||
function mobs:go_wplist(self,target,callback_arrived)
|
function mobs:go_wplist(self,target,callback_arrived)
|
||||||
if not target then return end
|
local p = self.object:get_pos()
|
||||||
self._target = target
|
local t = vector.offset(target,0,1,0)
|
||||||
self.waypoints = minetest.find_path(self.object:get_pos(),target,150,1,4)
|
if not target or not p then return end
|
||||||
|
local wp = minetest.find_path(p,t,150,1,4)
|
||||||
|
if wp and #wp > 0 then
|
||||||
|
self._target = t
|
||||||
self.callback_arrived = callback_arrived
|
self.callback_arrived = callback_arrived
|
||||||
|
self.waypoints = wp
|
||||||
self.state = "gowp"
|
self.state = "gowp"
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
--minetest.log("no path found")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,14 @@ local tiernames = {
|
||||||
"Master",
|
"Master",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local badges = {
|
||||||
|
"mcl_core:wood",
|
||||||
|
"mcl_core:stone",
|
||||||
|
"mcl_core:goldblock",
|
||||||
|
"mcl_core:emeraldblock",
|
||||||
|
"mcl_core:diamondblock",
|
||||||
|
}
|
||||||
|
|
||||||
local professions = {
|
local professions = {
|
||||||
unemployed = {
|
unemployed = {
|
||||||
name = N("Unemployed"),
|
name = N("Unemployed"),
|
||||||
|
@ -454,7 +462,7 @@ local professions = {
|
||||||
"mobs_mc_villager_smith.png",
|
"mobs_mc_villager_smith.png",
|
||||||
"mobs_mc_villager_smith.png",
|
"mobs_mc_villager_smith.png",
|
||||||
},
|
},
|
||||||
jobsite = "mcl_villages:stonebrickcarved", --FIXME: smithing table
|
jobsite = "mcl_anvils:anvil", --FIXME: smithing table
|
||||||
trades = {
|
trades = {
|
||||||
{
|
{
|
||||||
{ { "mcl_core:coal_lump", 15, 15 }, E1 },
|
{ { "mcl_core:coal_lump", 15, 15 }, E1 },
|
||||||
|
@ -602,10 +610,21 @@ local function employ(self,jobsite_pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function unemploy(self)
|
local function look_for_job(self)
|
||||||
self._profession="unemployed"
|
local p = self.object:get_pos()
|
||||||
self._jobsite = nil
|
local nn = minetest.find_nodes_in_area(vector.offset(p,-48,-48,-48),vector.offset(p,48,48,48),jobsites)
|
||||||
self.object:set_properties({textures=professions[self._profession].textures})
|
for _,n in pairs(nn) do
|
||||||
|
local m=minetest.get_meta(n)
|
||||||
|
if m:get_string("villager") == "" then
|
||||||
|
--minetest.log("goingt to jobsite "..minetest.pos_to_string(n) )
|
||||||
|
minetest.after(0,function()
|
||||||
|
mobs:go_wplist(self,n,function()
|
||||||
|
--minetest.log("arrived jobsite "..minetest.pos_to_string(n) )
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_a_job(self)
|
local function get_a_job(self)
|
||||||
|
@ -614,16 +633,7 @@ local function get_a_job(self)
|
||||||
for _,n in pairs(nn) do
|
for _,n in pairs(nn) do
|
||||||
if n and employ(self,n) then return true end
|
if n and employ(self,n) then return true end
|
||||||
end
|
end
|
||||||
end
|
if self.state ~= "gowp" then look_for_job(self) end
|
||||||
|
|
||||||
local function check_jobsite(self)
|
|
||||||
local n = minetest.get_node(self._jobsite)
|
|
||||||
local m = minetest.get_meta(self._jobsite)
|
|
||||||
if n.name ~= professions[self._profession].jobsite or m:get_string("villager") ~= self._id then
|
|
||||||
--unemploy(self)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local update_max_tradenum = function(self)
|
local update_max_tradenum = function(self)
|
||||||
|
@ -1231,9 +1241,11 @@ mobs:register_mob("mobs_mc:villager", {
|
||||||
look_at_player = true,
|
look_at_player = true,
|
||||||
on_rightclick = function(self, clicker)
|
on_rightclick = function(self, clicker)
|
||||||
local trg=vector.new(0,9,0)
|
local trg=vector.new(0,9,0)
|
||||||
mobs:go_wplist(self,trg,function()
|
if self._jobsite then
|
||||||
minetest.log("arrived at "..minetest.pos_to_string(trg))
|
mobs:go_wplist(self,self._jobsite,function()
|
||||||
|
--minetest.log("arrived at jobsite")
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
if clicker:get_wielded_item():get_name() == "mcl_farming:bread" then
|
if clicker:get_wielded_item():get_name() == "mcl_farming:bread" then
|
||||||
if mobs:feed_tame(self, clicker, 1, true, true) then return end
|
if mobs:feed_tame(self, clicker, 1, true, true) then return end
|
||||||
if mobs:protect(self, clicker) then return end
|
if mobs:protect(self, clicker) then return end
|
||||||
|
|
Loading…
Reference in a new issue