mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-26 20:41:11 +01:00
Prevent attempting to path through 2 doors until code supports it. Clean up also.
This commit is contained in:
parent
e3307d647b
commit
87f04bdd9f
2 changed files with 24 additions and 24 deletions
|
@ -3,7 +3,6 @@ local mob_class = mcl_mobs.mob_class
|
||||||
|
|
||||||
local LOGGING_ON = minetest.settings:get_bool("mcl_logging_mobs_villager",false)
|
local LOGGING_ON = minetest.settings:get_bool("mcl_logging_mobs_villager",false)
|
||||||
local PATHFINDING = "gowp"
|
local PATHFINDING = "gowp"
|
||||||
local enable_pathfinding = true
|
|
||||||
|
|
||||||
local LOG_MODULE = "[Mobs]"
|
local LOG_MODULE = "[Mobs]"
|
||||||
local function mcl_log (message)
|
local function mcl_log (message)
|
||||||
|
@ -64,26 +63,27 @@ local function generate_enriched_path(wp_in, door_open_pos, door_close_pos, cur_
|
||||||
local cur_pos_to_add = vector.add(cur_pos, one_down)
|
local cur_pos_to_add = vector.add(cur_pos, one_down)
|
||||||
if door_open_pos and vector.equals (cur_pos, door_open_pos) then
|
if door_open_pos and vector.equals (cur_pos, door_open_pos) then
|
||||||
mcl_log ("Door open match")
|
mcl_log ("Door open match")
|
||||||
--action = {type = "door", action = "open"}
|
action = {type = "door", action = "open"}
|
||||||
action = {}
|
--action = {}
|
||||||
action["type"] = "door"
|
--action["type"] = "door"
|
||||||
action["action"] = "open"
|
--action["action"] = "open"
|
||||||
action["target"] = cur_door_pos
|
action["target"] = cur_door_pos
|
||||||
cur_pos_to_add = vector.add(cur_pos, one_down)
|
cur_pos_to_add = vector.add(cur_pos, one_down)
|
||||||
elseif door_close_pos and vector.equals(cur_pos, door_close_pos) then
|
elseif door_close_pos and vector.equals(cur_pos, door_close_pos) then
|
||||||
mcl_log ("Door close match")
|
mcl_log ("Door close match")
|
||||||
--action = {type = "door", action = "closed"}
|
action = {type = "door", action = "close"}
|
||||||
action = {}
|
--action = {}
|
||||||
action["type"] = "door"
|
--action["type"] = "door"
|
||||||
action["action"] = "close"
|
--action["action"] = "close"
|
||||||
action["target"] = cur_door_pos
|
action["target"] = cur_door_pos
|
||||||
cur_pos_to_add = vector.add(cur_pos, one_down)
|
cur_pos_to_add = vector.add(cur_pos, one_down)
|
||||||
elseif cur_door_pos and vector.equals(cur_pos, cur_door_pos) then
|
elseif cur_door_pos and vector.equals(cur_pos, cur_door_pos) then
|
||||||
mcl_log("Current door pos")
|
mcl_log("Current door pos")
|
||||||
cur_pos_to_add = vector.add(cur_pos, one_down)
|
cur_pos_to_add = vector.add(cur_pos, one_down)
|
||||||
action = {}
|
action = {type = "door", action = "open"}
|
||||||
action["type"] = "door"
|
--action = {}
|
||||||
action["action"] = "open"
|
--action["type"] = "door"
|
||||||
|
--action["action"] = "open"
|
||||||
action["target"] = cur_door_pos
|
action["target"] = cur_door_pos
|
||||||
else
|
else
|
||||||
cur_pos_to_add = cur_pos
|
cur_pos_to_add = cur_pos
|
||||||
|
@ -132,7 +132,7 @@ local function calculate_path_through_door (p, t, cur_door_pos)
|
||||||
local pos_closest_to_door = nil
|
local pos_closest_to_door = nil
|
||||||
local other_side_of_door = nil
|
local other_side_of_door = nil
|
||||||
|
|
||||||
local wp
|
local wp, prospective_wp
|
||||||
|
|
||||||
if cur_door_pos then
|
if cur_door_pos then
|
||||||
mcl_log("Found a door near: " .. minetest.pos_to_string(cur_door_pos))
|
mcl_log("Found a door near: " .. minetest.pos_to_string(cur_door_pos))
|
||||||
|
@ -143,18 +143,19 @@ local function calculate_path_through_door (p, t, cur_door_pos)
|
||||||
if n.name == "air" then
|
if n.name == "air" then
|
||||||
mcl_log("We have air space next to door at: " .. minetest.pos_to_string(pos_closest_to_door))
|
mcl_log("We have air space next to door at: " .. minetest.pos_to_string(pos_closest_to_door))
|
||||||
|
|
||||||
wp = minetest.find_path(p,pos_closest_to_door,150,1,4)
|
prospective_wp = minetest.find_path(p,pos_closest_to_door,150,1,4)
|
||||||
|
|
||||||
if wp then
|
if prospective_wp then
|
||||||
mcl_log("Found a path to next to door".. minetest.pos_to_string(pos_closest_to_door))
|
mcl_log("Found a path to next to door".. minetest.pos_to_string(pos_closest_to_door))
|
||||||
other_side_of_door = vector.add(cur_door_pos,-v)
|
other_side_of_door = vector.add(cur_door_pos,-v)
|
||||||
mcl_log("Opposite is: ".. minetest.pos_to_string(other_side_of_door))
|
mcl_log("Opposite is: ".. minetest.pos_to_string(other_side_of_door))
|
||||||
|
|
||||||
local wp_otherside_door_to_target = minetest.find_path(other_side_of_door,t,150,1,4)
|
local wp_otherside_door_to_target = minetest.find_path(other_side_of_door,t,150,1,4)
|
||||||
if wp_otherside_door_to_target and #wp_otherside_door_to_target > 0 then
|
if wp_otherside_door_to_target and #wp_otherside_door_to_target > 0 then
|
||||||
table.insert(wp, cur_door_pos)
|
table.insert(prospective_wp, cur_door_pos)
|
||||||
append_paths (wp, wp_otherside_door_to_target)
|
append_paths (prospective_wp, wp_otherside_door_to_target)
|
||||||
enriched_path = generate_enriched_path(wp, pos_closest_to_door, other_side_of_door, cur_door_pos)
|
enriched_path = generate_enriched_path(prospective_wp, pos_closest_to_door, other_side_of_door, cur_door_pos)
|
||||||
|
wp = prospective_wp
|
||||||
mcl_log("We have a path from outside door to target")
|
mcl_log("We have a path from outside door to target")
|
||||||
else
|
else
|
||||||
mcl_log("We cannot path from outside door to target")
|
mcl_log("We cannot path from outside door to target")
|
||||||
|
@ -202,7 +203,6 @@ function mob_class:gopath(target,callback_arrived)
|
||||||
|
|
||||||
if not wp then
|
if not wp then
|
||||||
mcl_log("No direct path. Path through door")
|
mcl_log("No direct path. Path through door")
|
||||||
-- target could be pos
|
|
||||||
local cur_door_pos = minetest.find_node_near(target, 16, {"group:door"})
|
local cur_door_pos = minetest.find_node_near(target, 16, {"group:door"})
|
||||||
wp = calculate_path_through_door(p, t, cur_door_pos)
|
wp = calculate_path_through_door(p, t, cur_door_pos)
|
||||||
|
|
||||||
|
@ -218,15 +218,14 @@ function mob_class:gopath(target,callback_arrived)
|
||||||
|
|
||||||
--path from pos to door, path from otherside to target
|
--path from pos to door, path from otherside to target
|
||||||
|
|
||||||
|
|
||||||
if not wp then
|
if not wp then
|
||||||
mcl_log("Could not calculate path")
|
mcl_log("Could not calculate path")
|
||||||
self._pf_last_failed = os.time()
|
self._pf_last_failed = os.time()
|
||||||
-- Cover for a flaw in pathfind where it chooses the wrong door and gets stuck. Take a break, allow others.
|
-- If cannot path, don't immediately try again
|
||||||
end
|
end
|
||||||
--output_table(wp)
|
|
||||||
|
|
||||||
if wp and #wp > 0 then
|
if wp and #wp > 0 then
|
||||||
|
--output_table(wp)
|
||||||
self._target = t
|
self._target = t
|
||||||
self.callback_arrived = callback_arrived
|
self.callback_arrived = callback_arrived
|
||||||
local current_location = table.remove(wp,1)
|
local current_location = table.remove(wp,1)
|
||||||
|
@ -318,7 +317,7 @@ function mob_class:check_gowp(dtime)
|
||||||
-- arrived at location, finish gowp
|
-- arrived at location, finish gowp
|
||||||
local distance_to_targ = vector.distance(p,self._target)
|
local distance_to_targ = vector.distance(p,self._target)
|
||||||
--mcl_log("Distance to targ: ".. tostring(distance_to_targ))
|
--mcl_log("Distance to targ: ".. tostring(distance_to_targ))
|
||||||
if distance_to_targ < 2 then
|
if distance_to_targ < 1.5 then
|
||||||
mcl_log("Arrived at _target")
|
mcl_log("Arrived at _target")
|
||||||
self.waypoints = nil
|
self.waypoints = nil
|
||||||
self._target = nil
|
self._target = nil
|
||||||
|
@ -400,6 +399,7 @@ function mob_class:check_gowp(dtime)
|
||||||
self:go_to_pos(self._current_target)
|
self:go_to_pos(self._current_target)
|
||||||
else
|
else
|
||||||
mcl_log("close to current target: ".. minetest.pos_to_string(self.current_target["pos"]))
|
mcl_log("close to current target: ".. minetest.pos_to_string(self.current_target["pos"]))
|
||||||
|
mcl_log("target is: ".. minetest.pos_to_string(self._target))
|
||||||
self.current_target = nil
|
self.current_target = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1202,7 +1202,7 @@ local function get_ground_below_floating_object (float_pos)
|
||||||
until node.name ~= "air"
|
until node.name ~= "air"
|
||||||
|
|
||||||
-- If pos is 1 below float_pos, then just return float_pos as there is no air below it
|
-- If pos is 1 below float_pos, then just return float_pos as there is no air below it
|
||||||
if pos.y == float_pos.y -1 then
|
if pos.y == float_pos.y - 1 then
|
||||||
--mcl_log("pos is only 1 lower than float pos so no air below")
|
--mcl_log("pos is only 1 lower than float pos so no air below")
|
||||||
return float_pos
|
return float_pos
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue