Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

prevent a player-controlled monster from tageting itself

and let it run, despite seeing a monster (itself)
  • Loading branch information...
commit 5eca39eb99a68ab37d8582d28b1afa3f05bafeb5 1 parent 2edcc2c
@Mikolaj Mikolaj authored
Showing with 18 additions and 15 deletions.
  1. +12 −3 src/Actions.hs
  2. +2 −4 src/MovableState.hs
  3. +4 −8 src/Perception.hs
View
15 src/Actions.hs
@@ -159,8 +159,14 @@ continueRun dir =
loc <- gets (mloc . getPlayerBody)
per <- currentPerception
msg <- currentMessage
- let lvl@(Level { lmap = lmap, lheroes = hs }) = slevel state
- mslocs = S.fromList (L.map mloc (levelMonsterList state))
+ ms <- gets (lmonsters . slevel)
+ hs <- gets (lheroes . slevel)
+ lmap <- gets (lmap . slevel)
+ pl <- gets splayer
+ let dms = case pl of
+ AMonster n -> IM.delete n ms -- don't be afraid of yourself
+ AHero _ -> ms
+ mslocs = S.fromList (L.map mloc (IM.elems dms))
monstersVisible = not (S.null (mslocs `S.intersection` ptvisible per))
newsReported = not (L.null msg)
t = lmap `at` loc -- tile at current location
@@ -533,7 +539,10 @@ targetMonster = do
TEnemy (AMonster n) | targeting -> n -- try next monster
TEnemy (AMonster n) -> n - 1 -- try to retarget old monster
_ -> -1 -- try to target first monster (e.g., number 0)
- (lt, gt) = IM.split i ms
+ dms = case pl of
+ AMonster n -> IM.delete n ms -- don't target yourself
+ AHero _ -> ms
+ (lt, gt) = IM.split i dms
gtlt = IM.assocs gt ++ IM.assocs lt
lf = L.filter (\ (_, m) -> actorSeesLoc pl (mloc m) per pl) gtlt
tgt = case lf of
View
6 src/MovableState.hs
@@ -99,10 +99,8 @@ insertActor a m =
AHero n -> updateLevel (updateHeroes (IM.insert n m))
AMonster n -> updateLevel (updateMonsters (IM.insert n m))
-levelHeroList :: State -> [Movable]
-levelHeroList (State { slevel = Level { lheroes = hs } }) = IM.elems hs
-
-levelMonsterList :: State -> [Movable]
+levelHeroList, levelMonsterList :: State -> [Movable]
+levelHeroList (State { slevel = Level { lheroes = hs } }) = IM.elems hs
levelMonsterList (State { slevel = Level { lmonsters = ms } }) = IM.elems ms
-- | Finds an actor at a location on the current level. Perception irrelevant.
View
12 src/Perception.hs
@@ -26,11 +26,9 @@ data Perceptions =
pheroes :: IM.IntMap Perception,
ptotal :: Perception }
-ptreachable :: Perceptions -> S.Set Loc
+ptreachable, ptvisible :: Perceptions -> S.Set Loc
ptreachable = preachable . ptotal
-
-ptvisible :: Perceptions -> S.Set Loc
-ptvisible = pvisible . ptotal
+ptvisible = pvisible . ptotal
actorPrLoc :: (Perception -> S.Set Loc) ->
Actor -> Loc -> Perceptions -> Actor -> Bool
@@ -47,10 +45,8 @@ actorPrLoc projection actor loc per pl =
tryAny = tryHero `mplus` tryPl
in fromMaybe False tryAny -- assume not visible, if no perception found
-actorSeesLoc :: Actor -> Loc -> Perceptions -> Actor -> Bool
-actorSeesLoc = actorPrLoc pvisible
-
-actorReachesLoc :: Actor -> Loc -> Perceptions -> Actor -> Bool
+actorSeesLoc, actorReachesLoc :: Actor -> Loc -> Perceptions -> Actor -> Bool
+actorSeesLoc = actorPrLoc pvisible
actorReachesLoc = actorPrLoc preachable
-- Not quite correct if FOV not symmetric (Shadow).
Please sign in to comment.
Something went wrong with that request. Please try again.