diff options
Diffstat (limited to 'src/Xanthous/Data')
-rw-r--r-- | src/Xanthous/Data/EntityMap.hs | 3 | ||||
-rw-r--r-- | src/Xanthous/Data/EntityMap/Graphics.hs | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/Xanthous/Data/EntityMap.hs b/src/Xanthous/Data/EntityMap.hs index 5b5e8a063f2c..a068828a157c 100644 --- a/src/Xanthous/Data/EntityMap.hs +++ b/src/Xanthous/Data/EntityMap.hs @@ -110,6 +110,9 @@ instance TraversableWithIndex EntityID EntityMap where itraversed = byID . itraversed . rmap sequenceA . distrib itraverse = itraverseOf itraversed +type instance Element (EntityMap a) = a +instance MonoFoldable (EntityMap a) + emptyEntityMap :: EntityMap a emptyEntityMap = EntityMap mempty mempty 0 diff --git a/src/Xanthous/Data/EntityMap/Graphics.hs b/src/Xanthous/Data/EntityMap/Graphics.hs index 3124c6a334cc..ace5ae49e804 100644 --- a/src/Xanthous/Data/EntityMap/Graphics.hs +++ b/src/Xanthous/Data/EntityMap/Graphics.hs @@ -4,6 +4,7 @@ module Xanthous.Data.EntityMap.Graphics ( visiblePositions , visibleEntities , linesOfSight + , canSee ) where -------------------------------------------------------------------------------- import Xanthous.Prelude hiding (lines) @@ -49,3 +50,7 @@ visibleEntities pos visionRadius . map (\(p, es) -> over _2 (Positioned p) <$> es) . fold . linesOfSight pos visionRadius + +canSee :: Entity e => (e -> Bool) -> Position -> Word -> EntityMap e -> Bool +canSee match pos radius = any match . visibleEntities pos radius +-- ^ this might be optimizable |