mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-01-25 16:40:23 +01:00
tidy api
This commit is contained in:
parent
1271570780
commit
469e35d6e0
40
api.lua
40
api.lua
@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi")
|
|||||||
|
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20200720",
|
version = "20200723",
|
||||||
intllib = S,
|
intllib = S,
|
||||||
invis = minetest.global_exists("invisibility") and invisibility or {}
|
invis = minetest.global_exists("invisibility") and invisibility or {}
|
||||||
}
|
}
|
||||||
@ -195,7 +195,9 @@ end
|
|||||||
|
|
||||||
-- calculate distance
|
-- calculate distance
|
||||||
local get_distance = function(a, b)
|
local get_distance = function(a, b)
|
||||||
if not a or not b then return 50 end -- nil check
|
|
||||||
|
-- if not a or not b then return 50 end -- nil check
|
||||||
|
|
||||||
local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z
|
local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z
|
||||||
|
|
||||||
return square(x * x + y * y + z * z)
|
return square(x * x + y * y + z * z)
|
||||||
@ -812,6 +814,11 @@ local remove_mob = function(self, decrease)
|
|||||||
--print("-- active mobs: " .. active_mobs .. " / " .. active_limit)
|
--print("-- active mobs: " .. active_mobs .. " / " .. active_limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- global function for removing mobs
|
||||||
|
function mobs:remove(self, decrease)
|
||||||
|
remove_mob(self, decrease)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- check if mob is dead or only hurt
|
-- check if mob is dead or only hurt
|
||||||
function mob_class:check_for_death(cmi_cause)
|
function mob_class:check_for_death(cmi_cause)
|
||||||
@ -1538,7 +1545,9 @@ local height_switcher = false
|
|||||||
function mob_class:smart_mobs(s, p, dist, dtime)
|
function mob_class:smart_mobs(s, p, dist, dtime)
|
||||||
|
|
||||||
local s1 = self.path.lastpos
|
local s1 = self.path.lastpos
|
||||||
local target_pos = self.attack:get_pos()
|
-- local target_pos = self.attack:get_pos()
|
||||||
|
local target_pos = p
|
||||||
|
|
||||||
|
|
||||||
-- is it becoming stuck?
|
-- is it becoming stuck?
|
||||||
if abs(s1.x - s.x) + abs(s1.z - s.z) < .5 then
|
if abs(s1.x - s.x) + abs(s1.z - s.z) < .5 then
|
||||||
@ -1602,10 +1611,6 @@ function mob_class:smart_mobs(s, p, dist, dtime)
|
|||||||
|
|
||||||
minetest.after(1, function(self)
|
minetest.after(1, function(self)
|
||||||
|
|
||||||
if not self.object:get_luaentity() then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.object:get_luaentity() then
|
if self.object:get_luaentity() then
|
||||||
|
|
||||||
if has_lineofsight then
|
if has_lineofsight then
|
||||||
@ -1687,7 +1692,10 @@ function mob_class:smart_mobs(s, p, dist, dtime)
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
self.state = ""
|
self.state = ""
|
||||||
|
|
||||||
|
if self.attack then
|
||||||
self:do_attack(self.attack)
|
self:do_attack(self.attack)
|
||||||
|
end
|
||||||
|
|
||||||
-- no path found, try something else
|
-- no path found, try something else
|
||||||
if not self.path.way then
|
if not self.path.way then
|
||||||
@ -1785,12 +1793,16 @@ function mob_class:smart_mobs(s, p, dist, dtime)
|
|||||||
-- will try again in 2 second
|
-- will try again in 2 second
|
||||||
self.path.stuck_timer = stuck_timeout - 2
|
self.path.stuck_timer = stuck_timeout - 2
|
||||||
|
|
||||||
elseif s.y < p1.y and (not self.fly) then
|
elseif s.y < p1.y and (not self.fly) then
|
||||||
self:do_jump() --add jump to pathfinding
|
self:do_jump() --add jump to pathfinding
|
||||||
self.path.following = true
|
self.path.following = true
|
||||||
else
|
else
|
||||||
-- yay i found path
|
-- yay i found path
|
||||||
|
if self.attack then
|
||||||
self:mob_sound(self.sounds.war_cry)
|
self:mob_sound(self.sounds.war_cry)
|
||||||
|
else
|
||||||
|
self:mob_sound(self.sounds.random)
|
||||||
|
end
|
||||||
self:set_velocity(self.walk_velocity)
|
self:set_velocity(self.walk_velocity)
|
||||||
|
|
||||||
-- follow path now that it has it
|
-- follow path now that it has it
|
||||||
@ -2284,12 +2296,12 @@ function mob_class:do_states(dtime)
|
|||||||
-- attack routines (explode, dogfight, shoot, dogshoot)
|
-- attack routines (explode, dogfight, shoot, dogshoot)
|
||||||
elseif self.state == "attack" then
|
elseif self.state == "attack" then
|
||||||
|
|
||||||
-- calculate distance from mob and enemy
|
-- get mob and enemy positions and distance between
|
||||||
local s = self.object:get_pos()
|
local s = self.object:get_pos()
|
||||||
local p = self.attack:get_pos() or s
|
local p = self.attack:get_pos()
|
||||||
local dist = get_distance(p, s)
|
local dist = p and get_distance(p, s) or 500
|
||||||
|
|
||||||
-- stop attacking if player invisible or out of range
|
-- stop attacking if player out of range or invisible
|
||||||
if dist > self.view_range
|
if dist > self.view_range
|
||||||
or not self.attack
|
or not self.attack
|
||||||
or not self.attack:get_pos()
|
or not self.attack:get_pos()
|
||||||
@ -2425,7 +2437,8 @@ function mob_class:do_states(dtime)
|
|||||||
|
|
||||||
elseif self.attack_type == "dogfight"
|
elseif self.attack_type == "dogfight"
|
||||||
or (self.attack_type == "dogshoot" and self:dogswitch(dtime) == 2)
|
or (self.attack_type == "dogshoot" and self:dogswitch(dtime) == 2)
|
||||||
or (self.attack_type == "dogshoot" and dist <= self.reach and self:dogswitch() == 0) then
|
or (self.attack_type == "dogshoot" and dist <= self.reach
|
||||||
|
and self:dogswitch() == 0) then
|
||||||
|
|
||||||
if self.fly
|
if self.fly
|
||||||
and dist > self.reach then
|
and dist > self.reach then
|
||||||
@ -2472,7 +2485,6 @@ function mob_class:do_states(dtime)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- rnd: new movement direction
|
-- rnd: new movement direction
|
||||||
|
Loading…
Reference in New Issue
Block a user