Skip to content
Snippets Groups Projects
Commit fc3b19b1 authored by DarkGod's avatar DarkGod
Browse files

Merge branch 'master' of git.net-core.org:darkgod/t-engine4

parents a1b1ca71 e2ea1809
No related branches found
No related tags found
No related merge requests found
......@@ -224,7 +224,14 @@ function _M:runStep()
if not self.running then return false end
if not self.running.busy then
self.running.cnt = self.running.cnt + 1
elseif self.running.busy.no_energy then
end
-- Check after running to spot actors that may slip away from us; we still won't get a turn but we'll get the next one
ret, msg = self:runCheck()
if not ret then
self:runStop(msg)
return false
end
if self.running.busy and self.running.busy.no_energy then
return self:runStep()
end
return true
......
......@@ -801,7 +801,7 @@ function _M:setTarget(target)
return game:targetSetForPlayer(target)
end
local function spotHostiles(self)
local function spotHostiles(self, actors_only)
local seen = {}
if not self.x then return seen end
......@@ -809,9 +809,36 @@ local function spotHostiles(self)
core.fov.calc_circle(self.x, self.y, game.level.map.w, game.level.map.h, self.sight or 10, function(_, x, y) return game.level.map:opaque(x, y) end, function(_, x, y)
local actor = game.level.map(x, y, game.level.map.ACTOR)
if actor and self:reactionToward(actor) < 0 and self:canSee(actor) and game.level.map.seens(x, y) then
seen[#seen + 1] = {x=x,y=y,actor=actor}
seen[#seen + 1] = {x=x,y=y,actor=actor, entity=actor, name=actor.name}
end
end, nil)
if not actors_only then
-- Check for projectiles in line of sight
core.fov.calc_circle(self.x, self.y, game.level.map.w, game.level.map.h, self.sight or 10, function(_, x, y) return game.level.map:opaque(x, y) end, function(_, x, y)
local proj = game.level.map(x, y, game.level.map.PROJECTILE)
if not proj then return end
-- trust ourselves but not our friends
if proj.src and self == proj.src then return end
local sx, sy = proj.start_x, proj.start_y
local tx, ty
-- Bresenham is too so check if we're anywhere near the mathematical line of flight
if proj.project then
tx, ty = proj.project.def.x, proj.project.def.y
elseif proj.homing then
tx, ty = proj.homing.target.x, proj.homing.target.y
end
if tx and ty then
local dist_to_line = math.abs((self.x - sx) * (ty - sy) - (self.y - sy) * (tx - sx)) / core.fov.distance(sx, sy, tx, ty)
local our_way = ((self.x - x) * (tx - x) + (self.y - y) * (ty - y)) > 0
if our_way and dist_to_line < 1.5 then
seen[#seen+1] = {x=x, y=y, projectile=proj, entity=proj, name=(proj.getName and proj:getName()) or proj.name}
end
end
end, nil)
end
return seen
end
......@@ -824,7 +851,7 @@ function _M:automaticTalents()
local uses = {}
for tid, c in pairs(self.talents_auto) do
local t = self.talents_def[tid]
local spotted = spotHostiles(self)
local spotted = spotHostiles(self, true)
if (t.mode ~= "sustained" or not self.sustain_talents[tid]) and not self.talents_cd[tid] and self:preUseTalent(t, true, true) and (not t.auto_use_check or t.auto_use_check(self, t)) then
if (c == 1) or (c == 2 and #spotted <= 0) or (c == 3 and #spotted > 0) then
if c ~= 2 then
......@@ -904,10 +931,10 @@ function _M:restCheck()
local spotted = spotHostiles(self)
if #spotted > 0 then
for _, node in ipairs(spotted) do
node.actor:addParticles(engine.Particles.new("notice_enemy", 1))
node.entity:addParticles(engine.Particles.new("notice_enemy", 1))
end
local dir = game.level.map:compassDirection(spotted[1].x - self.x, spotted[1].y - self.y)
return false, ("hostile spotted to the %s (%s%s)"):format(dir or "???", spotted[1].actor.name, game.level.map:isOnScreen(spotted[1].x, spotted[1].y) and "" or " - offscreen")
return false, ("hostile spotted to the %s (%s%s)"):format(dir or "???", spotted[1].name, game.level.map:isOnScreen(spotted[1].x, spotted[1].y) and "" or " - offscreen")
end
-- Resting improves regen
......@@ -1000,7 +1027,7 @@ function _M:runCheck(ignore_memory)
local spotted = spotHostiles(self)
if #spotted > 0 then
local dir = game.level.map:compassDirection(spotted[1].x - self.x, spotted[1].y - self.y)
return false, ("hostile spotted to the %s (%s%s)"):format(dir or "???", spotted[1].actor.name, game.level.map:isOnScreen(spotted[1].x, spotted[1].y) and "" or " - offscreen")
return false, ("hostile spotted to the %s (%s%s)"):format(dir or "???", spotted[1].name, game.level.map:isOnScreen(spotted[1].x, spotted[1].y) and "" or " - offscreen")
end
if self:fireTalentCheck("callbackOnRun") then return false, "talent prevented" end
......@@ -1101,7 +1128,7 @@ function _M:runStopped()
local spotted = spotHostiles(self)
if #spotted > 0 then
for _, node in ipairs(spotted) do
node.actor:addParticles(engine.Particles.new("notice_enemy", 1))
node.entity:addParticles(engine.Particles.new("notice_enemy", 1))
end
end
......@@ -1342,7 +1369,7 @@ end
function _M:useOrbPortal(portal)
if portal.special then portal:special(self) return end
local spotted = spotHostiles(self)
local spotted = spotHostiles(self, true)
if #spotted > 0 then
local dir = game.level.map:compassDirection(spotted[1].x - self.x, spotted[1].y - self.y)
self:logCombat(spotted[1].actor, "You can not use the Orb with foes watching (#Target# to the %s%s)",dir, game.level.map:isOnScreen(spotted[1].x, spotted[1].y) and "" or " - offscreen")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment