From 33bf2d2f5bcf2c5d9e3bef9ead7b0ff0c4bcd0d0 Mon Sep 17 00:00:00 2001 From: sapier Date: Sat, 12 Jul 2014 20:17:01 +0200 Subject: [PATCH] Fix issue mgen_probab not moving mobs having jumped up a level --- mobf/environment.lua | 10 +++++-- mobf/mgen_probab/direction_control.lua | 41 +++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/mobf/environment.lua b/mobf/environment.lua index 5a93893..06b4f4c 100644 --- a/mobf/environment.lua +++ b/mobf/environment.lua @@ -895,6 +895,8 @@ function environment.pos_is_ok(pos,entity,dont_do_jumpcheck) local lastpos = nil 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 @@ -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" diff --git a/mobf/mgen_probab/direction_control.lua b/mobf/mgen_probab/direction_control.lua index 3fc2336..af277e8 100644 --- a/mobf/mgen_probab/direction_control.lua +++ b/mobf/mgen_probab/direction_control.lua @@ -64,7 +64,7 @@ function direction_control.changeaccel(pos,entity,current_velocity) if maxtries <= 0 then dbg_mobf.pmovement_lvl1( "MOBF: Aborting acceleration finding for this cycle due to max retries") - if state == "collision_jumpable" then + if state == "collision_jumpable" then dbg_mobf.movement_lvl1("Returning " ..printpos(new_accel).." as new accel as mob may jump") return new_accel @@ -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