Skip to content
Snippets Groups Projects
Commit b700d128 authored by dg's avatar dg
Browse files

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
parent 9bdbc03b
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
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