From b700d12898268882eb33d26e8116f24b8c14256b Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Fri, 21 May 2010 10:20:58 +0000
Subject: [PATCH] tells the player when he spotted an hostile while
 running/resting what it is and if it is offscreen

git-svn-id: http://svn.net-core.org/repos/t-engine4@662 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engine/Map.lua                |  8 ++++++++
 game/modules/tome/class/Player.lua | 10 +++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/game/engine/Map.lua b/game/engine/Map.lua
index 7efad1321f..8981dd4b4e 100644
--- a/game/engine/Map.lua
+++ b/game/engine/Map.lua
@@ -616,6 +616,14 @@ function _M:isBound(x, y)
 	return true
 end
 
+--- Checks the given coords to see if they are displayed on screen
+function _M:isOnScreen(x, y)
+	if x >= self.mx and x < self.mx + self.viewport.mwidth and y >= self.my and y < self.my + self.viewport.mheight then
+		return true
+	end
+	return false
+end
+
 --- Import a map into the current one
 -- @param map the map to import
 -- @param dx coordinate where to import it in the current map
diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua
index 22163119fa..904cb1443b 100644
--- a/game/modules/tome/class/Player.lua
+++ b/game/modules/tome/class/Player.lua
@@ -275,7 +275,9 @@ local function spotHostiles(self)
 	-- Check for visible monsters, only see LOS actors, so telepathy wont prevent resting
 	core.fov.calc_circle(self.x, self.y, 20, 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 = true end
+		if actor and self:reactionToward(actor) < 0 and self:canSee(actor) and game.level.map.seens(x, y) then
+			seen = {x=x,y=y,actor=actor}
+		end
 	end, nil)
 	return seen
 end
@@ -283,7 +285,8 @@ end
 --- Can we continue resting ?
 -- We can rest if no hostiles are in sight, and if we need life/mana/stamina (and their regen rates allows them to fully regen)
 function _M:restCheck()
-	if spotHostiles(self) then return false, "hostile spotted" end
+	local spotted = spotHostiles(self)
+	if spotted then return false, ("hostile spotted (%s%s)"):format(spotted.actor.name, game.level.map:isOnScreen(spotted.x, spotted.y) and "" or " - offscreen") end
 
 	-- Check ressources, make sure they CAN go up, otherwise we will never stop
 	if self:getMana() < self:getMaxMana() and self.mana_regen > 0 then return true end
@@ -296,7 +299,8 @@ end
 --- Can we continue running?
 -- We can run if no hostiles are in sight, and if we no interresting terrains are next to us
 function _M:runCheck()
-	if spotHostiles(self) then return false, "hostile spotted" end
+	local spotted = spotHostiles(self)
+	if spotted then return false, ("hostile spotted (%s%s)"):format(spotted.actor.name, game.level.map:isOnScreen(spotted.x, spotted.y) and "" or " - offscreen") end
 
 	-- Notice any noticable terrain
 	local noticed = false
-- 
GitLab