Fix issue mgen_probab not moving mobs having jumped up a level

This commit is contained in:
sapier 2014-07-12 20:17:01 +02:00
parent 41789b71be
commit 33bf2d2f5b
2 changed files with 45 additions and 6 deletions

View File

@ -896,6 +896,8 @@ function environment.pos_is_ok(pos,entity,dont_do_jumpcheck)
local retval = "temp_ok"
local min_ground_distance = 33000 -- above max height
--check if mob at pos will be in correct environment
for i=1,#cornerpositions,1 do
if not mobf_pos_is_same(lastpos,cornerpositions[i]) then
@ -929,6 +931,10 @@ function environment.pos_is_ok(pos,entity,dont_do_jumpcheck)
retval = "collision"
end
end
min_ground_distance =
MIN(min_ground_distance,
mobf_ground_distance(cornerpositions[i],entity.environment.media))
end
lastpos = cornerpositions[i]
end
@ -944,7 +950,7 @@ function environment.pos_is_ok(pos,entity,dont_do_jumpcheck)
if mobf_above_water(pos) then
if ground_distance > max_ground_distance then
if min_ground_distance > max_ground_distance then
dbg_mobf.environment_lvl2("MOBF: \tdropping above water")
retval = "drop_above_water"
end
@ -952,7 +958,7 @@ function environment.pos_is_ok(pos,entity,dont_do_jumpcheck)
retval = "above_water"
end
if ground_distance > max_ground_distance then
if min_ground_distance > max_ground_distance then
dbg_mobf.environment_lvl2("MOBF: \tdropping "
.. ground_distance .. " / " .. max_ground_distance)
retval = "drop"

View File

@ -320,6 +320,33 @@ function direction_control.precheck_movement(
speedfactor = speedfactor +0.1
until ( speedfactor > 1 or speed_found)
-- try if our state would at least keep same if we walk towards
-- the good pos
if not speed_found then
dbg_mobf.pmovement_lvl2("MOBF: trying min speed towards good pos")
movement_state.accel_to_set =
movement_generic.get_accel_to(new_pos, entity, nil,
entity.data.movement.min_accel)
local next_pos =
movement_generic.predict_next_block(
movement_state.basepos,
movement_state.current_velocity,
movement_state.accel_to_set)
local next_quality = environment.pos_quality(
next_pos,
entity
)
if ((mobf_calc_distance(next_pos,new_pos) <
(mobf_calc_distance(movement_state.basepos,new_pos))) and
environment.evaluate_state(next_quality,
LT_DROP_PENDING)) then
speed_found = true
end
end
if speed_found then
dbg_mobf.pmovement_lvl2("MOBF: redirecting to safe position .. "
.. printpos(new_pos))
@ -328,6 +355,12 @@ function direction_control.precheck_movement(
end
end
if new_pos == nil then
dbg_mobf.pmovement_lvl2("MOBF: no suitable pos found")
else
dbg_mobf.pmovement_lvl2("MOBF: didn't find a way to suitable pos")
end
--no suitable pos found, if mob is safe atm just stop it
if mob_is_safe then
if movement_state.current_quality == GQ_FULL then
@ -342,14 +375,14 @@ function direction_control.precheck_movement(
movement_generic.get_accel_to(targetpos, entity, nil,
entity.data.movement.min_accel)
dbg_mobf.pmovement_lvl2(
"MOBF: no suitable pos found but at good pos, slowing down")
"MOBF: good pos, slowing down")
movement_state.changed = true
return
else --stopp immediatlely
else --stop immediatlely
entity.object:setvelocity({x=0,y=0,z=0})
movement_state.accel_to_set = {x=0,y=nil,z=0}
dbg_mobf.pmovement_lvl2(
"MOBF: no suitable pos found stopping at safe pos")
"MOBF: stopping at safe pos")
movement_state.changed = true
return
end