Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

player-controlled monster perceives, too; close #31

  • Loading branch information...
commit 2edcc2c5aa7758416c06ce4bcdfd2b04040f5d32 1 parent d178c1d
@Mikolaj Mikolaj authored
Showing with 20 additions and 8 deletions.
  1. +10 −4 src/MovableState.hs
  2. +10 −4 src/Perception.hs
View
14 src/MovableState.hs
@@ -64,14 +64,20 @@ targetToLoc state visible =
then Just $ clocation (scursor state)
else Nothing -- cursor invalid: set at a different level
TEnemy a -> do
- (ln, m) <- findActorAnyLevel a state -- is target alive?
- guard $ ln == lname (slevel state) -- is target on current level?
- let loc = mloc m
- guard $ S.member loc visible -- is target visible?
+ guard $ memActor state a -- alive and on the current level?
+ let loc = mloc (getActor state a)
+ guard $ S.member loc visible -- visible?
return loc
-- The operations below disregard levels other than the current.
+-- | Checks if the actor is present on the current level.
+memActor :: State -> Actor -> Bool
+memActor (State { slevel = lvl }) a =
+ case a of
+ AHero n -> IM.member n (lheroes lvl)
+ AMonster n -> IM.member n (lmonsters lvl)
+
-- | Gets actor body from the current level. Error if not found.
getActor :: State -> Actor -> Movable
getActor (State { slevel = lvl }) a =
View
14 src/Perception.hs
@@ -10,6 +10,7 @@ import Geometry
import State
import Level
import Movable
+import MovableState
import FOV
import qualified Config
@@ -18,7 +19,8 @@ data Perception =
-- The pplayer field is void if player not on the current level,
-- or if the player controls a blind monster (TODO. But perhaps only non-blind
--- monsters should be controllable?).
+-- monsters should be controllable?). Right now, the field is used only
+-- for player-controlled monsters on the current level.
data Perceptions =
Perceptions { pplayer :: Maybe Perception,
pheroes :: IM.IntMap Perception,
@@ -58,7 +60,8 @@ actorSeesActor actor1 actor2 loc1 loc2 per pl =
actorSeesLoc actor2 loc1 per pl
perception_ :: State -> Perceptions
-perception_ state@(State { slevel = Level { lmap = lmap, lheroes = hs },
+perception_ state@(State { splayer = pl,
+ slevel = Level { lmap = lmap, lheroes = hs },
sconfig = config,
ssensory = sensory }) =
let mode = Config.get config "engine" "fovMode"
@@ -77,9 +80,12 @@ perception_ state@(State { slevel = Level { lmap = lmap, lheroes = hs },
"shadow" -> Shadow
_ -> error $ "perception_: unknown mode: " ++ show mode
+ -- Perception for a player-controlled monster on the current level.
+ pper = if isAMonster pl && memActor state pl
+ then Just $ perception fovMode (mloc (getPlayerBody state)) lmap
+ else Nothing
pers = IM.map (\ h -> perception fovMode (mloc h) lmap) hs
- lpers = IM.elems pers
- pper = Nothing -- TODO, and add it to ptotal, in case it's monster
+ lpers = maybeToList pper ++ IM.elems pers
reachable = S.unions (L.map preachable lpers)
visible = S.unions (L.map pvisible lpers)
in Perceptions { pplayer = pper,
Please sign in to comment.
Something went wrong with that request. Please try again.