From dd4d445b3ad2fdf58b9886aeb4c66a0b9803eac8 Mon Sep 17 00:00:00 2001 From: zorman2000 Date: Thu, 19 Jan 2017 20:11:11 -0500 Subject: [PATCH] Actions: Fix unlock not working properly. Pathfinding: Fix bug of map not generating if difference between z-coordinates is zero. Code cleanup. --- actions/pathfinder.lua | 25 +++++++++++-------------- dialogue.lua | 6 ++++++ npc.lua | 4 +--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/actions/pathfinder.lua b/actions/pathfinder.lua index d12c409..6be41d8 100644 --- a/actions/pathfinder.lua +++ b/actions/pathfinder.lua @@ -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 diff --git a/dialogue.lua b/dialogue.lua index d199908..1d33a6f 100644 --- a/dialogue.lua +++ b/dialogue.lua @@ -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 diff --git a/npc.lua b/npc.lua index 2522ed4..6da4d56 100755 --- a/npc.lua +++ b/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