From d90ff1a19abae956fea54fde1d0dd8d2c811cf87 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Thu, 14 Feb 2013 10:16:27 +0000
Subject: [PATCH] Boss NPCs that can move through walls will have easier time
 tracking the player; so they wont get lost in walls so much

git-svn-id: http://svn.net-core.org/repos/t-engine4@6415 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/modules/tome/class/NPC.lua | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/game/modules/tome/class/NPC.lua b/game/modules/tome/class/NPC.lua
index 856b3d7154..be5d3d3020 100644
--- a/game/modules/tome/class/NPC.lua
+++ b/game/modules/tome/class/NPC.lua
@@ -416,6 +416,11 @@ function _M:addedToLevel(level, x, y)
 		end
 	end
 
+	-- Bosses that can pass through things should be smart about finding their target
+	if self.rank > 3 and self.can_pass and type(self.can_pass) == "table" and next(self.can_pass) and self.ai_state and not self.ai_state.boss_ghost_no_astar then
+		self.ai_state.ai_move = "move_astar"
+	end
+
 	return mod.class.Actor.addedToLevel(self, level, x, y)
 end
 
@@ -462,3 +467,20 @@ function _M:aiCanPass(x, y)
 	end
 	return engine.interface.ActorAI.aiCanPass(self, x, y)
 end
+
+--- Returns the seen coords of the target
+-- This will usually return the exact coords, but if the target is only partially visible (or not at all)
+-- it will return estimates, to throw the AI a bit off
+-- @param target the target we are tracking
+-- @return x, y coords to move/cast to
+function _M:aiSeeTargetPos(target)
+	if not target then return self.x, self.y end
+	local tx, ty = target.x, target.y
+
+	-- Special case, a boss that can pass walls can always home in on the target; otherwise it would get lost in the walls for a long while
+	-- We check wall walking not on self but rather as a check if the target could reach us
+	if self.rank > 3 and target.canMove and not target:canMove(self.x, self.y, true) then
+		return util.bound(tx, 0, game.level.map.w - 1), util.bound(ty, 0, game.level.map.h - 1)
+	end
+	return ActorAI.aiSeeTargetPos(target)
+end
-- 
GitLab