diff options
author | Griffin Smith <grfn@gws.fyi> | 2020-07-03T17·40-0400 |
---|---|---|
committer | glittershark <grfn@gws.fyi> | 2020-07-03T17·47+0000 |
commit | 26bb34823d884a619985cf91262f180e0ad4d207 (patch) | |
tree | 714606f889f87d7f9db3c8c1627933d5386388f8 /users/glittershark/xanthous/src/Xanthous/Game/Lenses.hs | |
parent | 361ffd42d7d0f6a3ab1c6a2345b2784b9381cb4d (diff) |
fix(xan): Don't allow looking at invisible things r/1198
Extract the conditional we're using to decide whether or not to render a given entity at a position, and use that when getting the list of entities to describe as a result of the "Look" command. Change-Id: I1ec86211c2fcbd984dd52338fb5631667c22c723 Reviewed-on: https://cl.tvl.fyi/c/depot/+/903 Reviewed-by: glittershark <grfn@gws.fyi> Reviewed-by: BuildkiteCI Tested-by: BuildkiteCI
Diffstat (limited to 'users/glittershark/xanthous/src/Xanthous/Game/Lenses.hs')
-rw-r--r-- | users/glittershark/xanthous/src/Xanthous/Game/Lenses.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/users/glittershark/xanthous/src/Xanthous/Game/Lenses.hs b/users/glittershark/xanthous/src/Xanthous/Game/Lenses.hs index 1f2d21665fdb..6242b855f1cc 100644 --- a/users/glittershark/xanthous/src/Xanthous/Game/Lenses.hs +++ b/users/glittershark/xanthous/src/Xanthous/Game/Lenses.hs @@ -12,6 +12,7 @@ module Xanthous.Game.Lenses , getInitialState , initialStateFromSeed , entitiesAtCharacter + , revealedEntitiesAtPosition -- * Collisions , Collision(..) @@ -129,3 +130,21 @@ entitiesAtCharacter = lens getter setter getter gs = gs ^. entities . EntityMap.atPosition (gs ^. characterPosition) setter gs ents = gs & entities . EntityMap.atPosition (gs ^. characterPosition) .~ ents + +-- | Returns all entities at the given position that are revealed to the +-- character. +-- +-- Concretely, this is either entities that are *currently* visible to the +-- character, or entities, that are immobile and that the character has seen +-- before +revealedEntitiesAtPosition :: Position -> GameState -> (VectorBag SomeEntity) +revealedEntitiesAtPosition p gs + | p `member` characterVisiblePositions gs + = entitiesAtPosition + | p `member` (gs ^. revealedPositions) + = immobileEntitiesAtPosition + | otherwise + = mempty + where + entitiesAtPosition = gs ^. entities . EntityMap.atPosition p + immobileEntitiesAtPosition = filter (not . entityCanMove) entitiesAtPosition |