A couple of go fixes/enhancements

master
Ciaran Gultnieks 2014-04-05 00:25:45 +01:00
parent 75dd710cae
commit 46652fc616
1 changed files with 25 additions and 1 deletions

View File

@ -97,6 +97,11 @@ people.actions.go = function(state)
if curpatharea.name == state.action.footpathdest.name then
dbg.v2(state.ent.name.." arrived at footpath destination")
if state.action.endpos then
state.action.footpathdest = nil
state.action.pos = state.action.endpos
return false
end
return true
end
@ -168,6 +173,24 @@ people.actions.go = function(state)
end
local distance = vector.distance({x=state.pos.x, y=0, z=state.pos.z}, {x=curdest.x, y=0, z=curdest.z})
-- If it's a long way to the destination position, see if we can find
-- a route using a footpath instead.
if distance > 30 and not state.action.footpathdest then
local pathstartarea, psdist = areas:findNearestArea(state.pos, "^path_.+")
if pathstartarea and psdist < distance then
local pathdestarea, psdist = areas:findNearestArea(state.action.pos, "^path_.+")
if pathdestarea and psdist < distance then
state.action.endpos = state.action.pos
state.action.pos = vector.new(pathstartarea.pos1)
state.action.pos.y = state.action.pos.y + 0.5
state.action.footpathdest = pathdestarea
dbg.v2(state.ent.name.." using footpath from "..pathstartarea.name.." to "..pathdestarea.name.." for intermediate route")
return false
end
end
end
if distance < 0.2 then
if state.action.intermediate then
dbg.v3(state.ent.name.." arrived intermediate ")
@ -179,7 +202,8 @@ people.actions.go = function(state)
end
dbg.v2(state.ent.name.." arrived near "..minetest.pos_to_string(curdest))
state.setpos = {x=curdest.x, y=state.pos.y, z=curdest.z}
state.setpos = vector.round(curdest)
state.setpos.y = state.pos.y
if state.action.footpathdest or not state.action.intermediate then
-- If we arrived at the pos, but we still have a
-- pathdest or intermediate dest, we carry on to do that.