added new line_of_sight that uses raycasting when mt5.0 is found (thanks Astrobe)

This commit is contained in:
TenPlus1 2019-05-08 16:14:49 +01:00
parent ddbd403285
commit 392974e835
3 changed files with 132 additions and 91 deletions

46
api.lua
View File

@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = {
mod = "redo",
version = "20190430",
version = "20190508",
intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {},
}
@ -330,7 +330,7 @@ end
-- check line of sight (BrunoMine)
function mob_class:line_of_sight(pos1, pos2, stepsize)
local line_of_sight = function(self, pos1, pos2, stepsize)
stepsize = stepsize or 1
@ -401,7 +401,7 @@ end
-- check line of sight (by BrunoMine, tweaked by Astrobe)
function mob_class:NEW_line_of_sight(pos1, pos2, stepsize)
local new_line_of_sight = function(self, pos1, pos2, stepsize)
if not pos1 or not pos2 then return end
@ -447,10 +447,46 @@ function mob_class:NEW_line_of_sight(pos1, pos2, stepsize)
return false
end
-- check line of sight using raycasting (thanks Astrobe)
local ray_line_of_sight = function(self, pos1, pos2)
local ray = minetest.raycast(pos1, pos2, true, false)
local thing = ray:next()
while thing do
if thing.type == "object"
and thing.ref ~= self.object
and not thing.ref:is_player() then return false end
if thing.type == "node" then
local name = minetest.get_node(thing.under).name
if minetest.registered_items[name].walkable then return false end
end
thing = ray:next()
end
return true
end
-- detect if using minetest 5.0 by searching for permafrost node
local is_50 = minetest.registered_nodes["default:permafrost"]
function mob_class:line_of_sight(pos1, pos2, stepsize)
if is_50 then -- only use if minetest 5.0 is detected
return ray_line_of_sight(self, pos1, pos2)
end
return line_of_sight(self, pos1, pos2, stepsize)
end
-- global function
function mobs:line_of_sight(entity, pos1, pos2, stepsize)
return mob_class.line_of_sight(entity, pos1, pos2, stepsize)
return mob_class.line_of_sight(pos1, pos2, stepsize)
end

View File

@ -576,7 +576,7 @@ Certain variables need to be set before using the above functions:
'self.driver_scale' sets driver scale for mobs larger than {x=1, y=1}
mobs:line_of_sight(self, pos1, pos2, stepsize)
mobs:line_of_sight(self, pos1, pos2, stepsize) [DEPRECATED]
This function is for use within the mobs definition for special use cases and
returns true if a mob can see the player or victim.
@ -586,6 +586,10 @@ returns true if a mob can see the player or victim.
'pos2' position of vistim or player
'stepsize' usually set to 1
Use this instead:
mob_class:line_of_sight(pos1, pos2, stepsize)
External Settings for "minetest.conf"
------------------------------------

View File

@ -23,6 +23,7 @@ Lucky Blocks: 9
Changelog:
- 1.50 - Added new line_of_sight function that uses raycasting if mt5.0 is found (thanks Astrobe)
- 1.49- Added mobs:force_capture(self, player) function, api functions now use metatables thanks to bell07
- 1.48- Add mobs:set_velocity(self, velocity) global function
- 1.47- Mob damage changes, min and max light level for damage added, ignition sources checked for lava damage