Actions: Fix unlock not working properly.
Pathfinding: Fix bug of map not generating if difference between z-coordinates is zero. Code cleanup.
This commit is contained in:
parent
60b847a02a
commit
dd4d445b3a
@ -119,8 +119,6 @@ end
|
||||
|
||||
function pathfinder.create_map(start_pos, end_pos, extra_range, walkables)
|
||||
|
||||
-- Unused, will not use voxel areas for now
|
||||
--local c_air = minetest.get_content_id("air")
|
||||
minetest.log("Start pos: "..dump(start_pos))
|
||||
minetest.log("End pos: "..dump(end_pos))
|
||||
|
||||
@ -131,26 +129,25 @@ function pathfinder.create_map(start_pos, end_pos, extra_range, walkables)
|
||||
local start_z_sign = (start_pos.z - end_pos.z) / math.abs(start_pos.z - end_pos.z)
|
||||
local end_x_sign = (end_pos.x - start_pos.x) / math.abs(end_pos.x - start_pos.x)
|
||||
local end_z_sign = (end_pos.z - start_pos.z) / math.abs(end_pos.z - start_pos.z)
|
||||
--minetest.log("Start x sign: "..dump(start_x_sign)..", end x sign: "..dump(end_x_sign))
|
||||
--minetest.log("End z sign: "..dump(start_z_sign)..", end z sign: "..dump(end_z_sign))
|
||||
|
||||
-- Correct the signs if they are nan
|
||||
if math.abs(start_pos.x - end_pos.x) == 0 then
|
||||
start_x_sign = -1
|
||||
end_x_sign = 1
|
||||
end
|
||||
if math.abs(start_pos.z - end_pos.z) == 0 then
|
||||
start_z_sign = -1
|
||||
end_z_sign = 1
|
||||
end
|
||||
|
||||
-- Get starting and ending positions, adding the extra nodes to the area
|
||||
local pos1 = {x=start_pos.x + (extra_range * start_x_sign), y = start_pos.y - 1, z=start_pos.z + (extra_range * start_z_sign)}
|
||||
local pos2 = {x=end_pos.x + (extra_range * end_x_sign), y = end_pos.y, z=end_pos.z + (extra_range * end_z_sign)}
|
||||
--minetest.log("Pos 1: "..dump(pos1))
|
||||
--minetest.log("Pos 2: "..dump(pos2))
|
||||
|
||||
-- Get Voxel Area - Not used for the moment
|
||||
-- local vm = minetest.get_voxel_manip()
|
||||
-- local emin, emax = vm:read_from_map(pos1, pos2)
|
||||
-- local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
|
||||
-- local data = vm:get_data()
|
||||
|
||||
local grid = {}
|
||||
|
||||
-- Loop through the area and classify nodes
|
||||
-- The +2 addition tries to ensure the loop runs at least one.
|
||||
for z = 1, math.abs(pos1.z - pos2.z) + 2 do
|
||||
for z = 1, math.abs(pos1.z - pos2.z) do
|
||||
local current_row = {}
|
||||
for x = 1, math.abs(pos1.x - pos2.x) do
|
||||
-- Calculate current position
|
||||
|
@ -279,6 +279,12 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
-- Get player response
|
||||
local player_response = npc.dialogue.dialogue_results.options_dialogue[player_name]
|
||||
|
||||
-- Check if the player hit the negative option
|
||||
if fields["exit"] then
|
||||
-- Unlock queue, reset action timer and unfreeze NPC.
|
||||
npc.unlock_actions(player_response.npc)
|
||||
end
|
||||
|
||||
for i = 1, #player_response.options do
|
||||
local button_label = "opt"..tostring(i)
|
||||
if fields[button_label] then
|
||||
|
4
npc.lua
4
npc.lua
@ -677,17 +677,15 @@ mobs:register_mob("advanced_npc:npc", {
|
||||
-- Increment action timer
|
||||
self.actions.action_timer = self.actions.action_timer + dtime
|
||||
if self.actions.action_timer >= self.actions.action_interval then
|
||||
minetest.log("Current action state = "..dump(self.actions.current_action_state))
|
||||
-- Reset action timer
|
||||
self.actions.action_timer = 0
|
||||
-- Execute action
|
||||
self.freeze = npc.execute_action(self)
|
||||
|
||||
-- Check if there are still remaining actions in the queue
|
||||
if self.freeze == nil and table.getn(self.actions.queue) > 0 then
|
||||
self.freeze = false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return self.freeze
|
||||
|
Loading…
Reference in New Issue
Block a user