diff options
author | TenPlus1 <kinsellaja@yahoo.com> | 2018-07-18 10:13:19 +0100 |
---|---|---|
committer | TenPlus1 <kinsellaja@yahoo.com> | 2018-07-18 10:13:19 +0100 |
commit | 63c9812dad43adfb5736408f48a61ff02267d9ed (patch) | |
tree | 79178e548dd9fe6fe89e3ddbc320be18458a5663 /api.lua | |
parent | f6b5effe09d3116c9e1231eaa38f7f9ab2535eb9 (diff) |
new line_of_sight and fence_top added
Diffstat (limited to 'api.lua')
-rw-r--r-- | api.lua | 39 |
1 files changed, 7 insertions, 32 deletions
@@ -3,7 +3,7 @@ mobs = {} mobs.mod = "redo" -mobs.version = "20180708" +mobs.version = "20180710" -- Intllib @@ -213,17 +213,17 @@ local get_distance = function(a, b) end --- check line of sight (BrunoMine) +-- check line of sight (by BrunoMine, tweaked by Astrobe) local line_of_sight = function(self, pos1, pos2, stepsize) stepsize = stepsize or 1 + local stepv = vector.multiply(vector.direction(pos1, pos2), stepsize) + local s, pos = minetest.line_of_sight(pos1, pos2, stepsize) -- normal walking and flying mobs can see you through air - if s == true then - return true - end + if s == true then return true end -- New pos1 to be analyzed local npos1 = {x = pos1.x, y = pos1.y, z = pos1.z} @@ -236,39 +236,15 @@ local line_of_sight = function(self, pos1, pos2, stepsize) -- Nodename found local nn = minetest.get_node(pos).name - -- Target Distance (td) to travel - local td = get_distance(pos1, pos2) - - -- Actual Distance (ad) traveled - local ad = 0 - -- It continues to advance in the line of sight in search of a real -- obstruction which counts as 'normal' nodebox. while minetest.registered_nodes[nn] and (minetest.registered_nodes[nn].walkable == false or minetest.registered_nodes[nn].drawtype == "nodebox") do - -- Check if you can still move forward - if td < ad + stepsize then - return true -- Reached the target - end + npos1 = vector.add(npos1, stepv) - -- Moves the analyzed pos - local d = get_distance(pos1, pos2) - - npos1.x = ((pos2.x - pos1.x) / d * stepsize) + pos1.x - npos1.y = ((pos2.y - pos1.y) / d * stepsize) + pos1.y - npos1.z = ((pos2.z - pos1.z) / d * stepsize) + pos1.z - - -- NaN checks - if d == 0 - or npos1.x ~= npos1.x - or npos1.y ~= npos1.y - or npos1.z ~= npos1.z then - return false - end - - ad = ad + stepsize + if get_distance(npos1, pos2) < stepsize then return true end -- scan again r, pos = minetest.line_of_sight(npos1, pos2, stepsize) @@ -277,7 +253,6 @@ local line_of_sight = function(self, pos1, pos2, stepsize) -- New Nodename found nn = minetest.get_node(pos).name - end return false |