This commit is contained in:
kay27 2020-12-01 20:10:37 +04:00
parent e0734952ce
commit 06c97be4a2
1 changed files with 23 additions and 19 deletions

View File

@ -139,7 +139,7 @@ local mob_sound = function(self, soundname, is_opinion, fixed_pitch)
end end
end end
-- Reeturn true if object is in view_range -- Return true if object is in view_range
local function object_in_range(self, object) local function object_in_range(self, object)
if not object then if not object then
return false return false
@ -158,11 +158,9 @@ local function object_in_range(self, object)
else else
dist = self.view_range dist = self.view_range
end end
if vector.distance(self.object:get_pos(), object:get_pos()) > dist then
return false local p1, p2 = self.object:get_pos(), object:get_pos()
else return p1 and p2 and (vector.distance(p1, p2) <= dist)
return true
end
end end
-- attack player/mob -- attack player/mob
@ -710,18 +708,23 @@ end
-- check if within physical map limits (-30911 to 30927) -- check if within physical map limits (-30911 to 30927)
local within_limits = function(pos, radius) local within_limits, wmin, wmax = nil, -30913, 30928
within_limits = function(pos, radius)
if (pos.x - radius) > -30913 if mcl_vars then
and (pos.x + radius) < 30928 if mcl_vars.mapgen_edge_min and mcl_vars.mapgen_edge_max then
and (pos.y - radius) > -30913 wmin, wmax = mcl_vars.mapgen_edge_min, mcl_vars.mapgen_edge_max
and (pos.y + radius) < 30928 within_limits = function(pos, radius)
and (pos.z - radius) > -30913 return pos
and (pos.z + radius) < 30928 then and (pos.x - radius) > wmin and (pos.x + radius) < wmax
return true -- within limits and (pos.y - radius) > wmin and (pos.y + radius) < wmax
and (pos.z - radius) > wmin and (pos.z + radius) < wmax
end
end
end end
return pos
return false -- beyond limits and (pos.x - radius) > wmin and (pos.x + radius) < wmax
and (pos.y - radius) > wmin and (pos.y + radius) < wmax
and (pos.z - radius) > wmin and (pos.z + radius) < wmax
end end
@ -2222,10 +2225,8 @@ local do_states = function(self, 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
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() or s
local dist = vector.distance(p, s)
-- stop attacking if player invisible or out of range -- stop attacking if player invisible or out of range
if not self.attack if not self.attack
@ -2246,6 +2247,9 @@ local do_states = function(self, dtime)
return return
end end
-- calculate distance from mob and enemy
local dist = vector.distance(p, s)
if self.attack_type == "explode" then if self.attack_type == "explode" then
local vec = { local vec = {