A bit more tinkering
parent
6e4328bcc4
commit
bc7b1af60f
|
@ -201,7 +201,7 @@ people.actions.go = function(state)
|
|||
return true
|
||||
|
||||
else
|
||||
if not state.action.intermediate then
|
||||
if not state.action.intermediate or #state.action.intermediate > 10 then
|
||||
state.action.intermediate = {}
|
||||
end
|
||||
-- for i = #path, 2, -1 do -- OLD implementation - opposite order to new implementation!
|
||||
|
@ -218,7 +218,7 @@ people.actions.go = function(state)
|
|||
randomdir = math.random(math.pi * 2)
|
||||
vec = vector.from_speed_yaw(24, randomdir)
|
||||
local rpos2 = {x=math.floor(rpos.x + vec.x + 0.5), y=state.pos.y, z=math.floor(rpos.z + vec.z + 0.5)}
|
||||
if not state.action.intermediate then
|
||||
if not state.action.intermediate or #state.action.intermediate > 10 then
|
||||
state.action.intermediate = {}
|
||||
end
|
||||
table.insert(state.action.intermediate, 1, rpos2)
|
||||
|
@ -235,36 +235,44 @@ people.actions.go = function(state)
|
|||
state.yaw = vector.get_yaw(state.pos, curdest)
|
||||
|
||||
-- Abort if we're going to walk somewhere unpleasant
|
||||
local erk = nil
|
||||
local ahead = state.speed
|
||||
if ahead > 0.5 then ahead = 0.5 end
|
||||
local nd = vector.from_speed_yaw(ahead, state.yaw)
|
||||
local nextpos = vector.add(state.pos, nd)
|
||||
nextpos.y = nextpos.y + 1
|
||||
local ncount = 4
|
||||
while ncount > 0 do
|
||||
local nn = minetest.get_node(nextpos).name
|
||||
if nn == "default:water_flowing" or nn == "default:water_source" or nn == "default:lava_flowing" or nn == "default:lava_source" then
|
||||
erk = nn
|
||||
break
|
||||
if distance > 1 then
|
||||
local erk = nil
|
||||
local ahead = state.speed
|
||||
if ahead > 1 then ahead = 1 end
|
||||
local nd = vector.from_speed_yaw(ahead, state.yaw)
|
||||
local nextpos = vector.add(vector.round(state.pos), nd)
|
||||
nextpos.y = nextpos.y + 1
|
||||
-- How far down we'll look, which needs to be at least this to
|
||||
-- be able to descend stairs.
|
||||
local ncount = 5
|
||||
local diags = "at:" ..minetest.pos_to_string(state.pos)
|
||||
diags = diags .. " next+1:" ..minetest.pos_to_string(nextpos)
|
||||
while ncount > 0 do
|
||||
local nn = minetest.get_node(nextpos).name
|
||||
diags = diags .. ":" .. nn
|
||||
if nn == "default:water_flowing" or nn == "default:water_source" or nn == "default:lava_flowing" or nn == "default:lava_source" then
|
||||
erk = nn
|
||||
break
|
||||
end
|
||||
nd = minetest.registered_nodes[nn]
|
||||
if not nd then
|
||||
erk = "mysterious " .. nn
|
||||
break
|
||||
end
|
||||
if nd.walkable then
|
||||
break
|
||||
end
|
||||
nextpos.y = nextpos.y - 1
|
||||
ncount = ncount - 1
|
||||
end
|
||||
nd = minetest.registered_nodes[nn]
|
||||
if not nd then
|
||||
erk = nn
|
||||
break
|
||||
if ncount == 0 then erk = "fall" end
|
||||
if erk then
|
||||
dbg.v1(state.ent.name.." aborted go due to fear of " ..
|
||||
erk .. " - " .. diags)
|
||||
state.speed = 0
|
||||
state.wait = 2
|
||||
return true
|
||||
end
|
||||
if nd.walkable then
|
||||
break
|
||||
end
|
||||
nextpos.y = nextpos.y - 1
|
||||
ncount = ncount - 1
|
||||
end
|
||||
if ncount == 0 then erk = "fall" end
|
||||
if erk then
|
||||
dbg.v1(state.ent.name.." aborted go due to fear of " .. erk)
|
||||
state.speed = 0
|
||||
state.wait = 2
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
14
init.lua
14
init.lua
|
@ -321,11 +321,15 @@ minetest.register_entity("people:person" ,{
|
|||
local pos = self.object:getpos()
|
||||
|
||||
-- Handle gathering
|
||||
-- TODO: Only happens during go and follow currently. Can't happen during "dig" or
|
||||
-- any subaction that "dig" might set - which poses a problem if "dig" were
|
||||
-- to use "go"!! Better way of handling this required.
|
||||
if self.action and (self.action[1] == "go" or self.action[1] == "follow" or self.action[1] == "wait") and
|
||||
(#self.gather.items + #self.gather.nodes > 0 or self.gather.plant) then
|
||||
-- TODO: Only happens during go and follow currently. Can't happen
|
||||
-- during "dig" or any subaction that "dig" might set - which poses
|
||||
-- a problem if "dig" were to use "go"!! Better way of handling this
|
||||
-- required.
|
||||
if self.action and (self.action[1] == "go" or
|
||||
self.action[1] == "follow" or
|
||||
self.action[1] == "wait") and
|
||||
(#self.gather.items + #self.gather.nodes > 0 or
|
||||
self.gather.plant) then
|
||||
local dist = 99
|
||||
if self.gather.lastpos then
|
||||
dist = vector.distance(pos, self.gather.lastpos)
|
||||
|
|
|
@ -73,7 +73,7 @@ people.people_set_active = function(entity)
|
|||
local name = wc[1]
|
||||
local param = wc[2]
|
||||
dbg.v1("Re-running chat command after wake-up: "..name.." : "..param or "nil")
|
||||
local reply = people.do_command(name, param)
|
||||
local success, reply = people.do_command(name, param)
|
||||
if reply then
|
||||
minetest.chat_send_player(name, reply)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue