diff --git a/game/engine/Map.lua b/game/engine/Map.lua index 7efad1321fa5b24eecb571b4ebaf117fdae1fead..8981dd4b4eb00f07b6ced4a1e1e1987073e47fc8 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 22163119faf8f6468b5295808a5262daf78e7950..904cb1443b5108d5d12d4217d83753fcbee7dbee 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