{-# LANGUAGE DeriveGeneric, GeneralizedNewtypeDeriving #-}
module Game.LambdaHack.Common.Perception
( PerVisible(..)
, PerSmelled(..)
, Perception(..)
, PerLid
, PerFid
, totalVisible, totalSmelled
, emptyPer, nullPer, addPer, diffPer
) where
import Prelude ()
import Game.LambdaHack.Core.Prelude
import Data.Binary
import qualified Data.EnumMap.Strict as EM
import qualified Data.EnumSet as ES
import GHC.Generics (Generic)
import Game.LambdaHack.Common.Types
import Game.LambdaHack.Common.Point
newtype PerVisible = PerVisible {pvisible :: ES.EnumSet Point}
deriving (Show, Eq, Binary)
newtype PerSmelled = PerSmelled {psmelled :: ES.EnumSet Point}
deriving (Show, Eq, Binary)
data Perception = Perception
{ psight :: PerVisible
, psmell :: PerSmelled
}
deriving (Show, Eq, Generic)
instance Binary Perception
type PerLid = EM.EnumMap LevelId Perception
type PerFid = EM.EnumMap FactionId PerLid
totalVisible :: Perception -> ES.EnumSet Point
totalVisible = pvisible . psight
totalSmelled :: Perception -> ES.EnumSet Point
totalSmelled = psmelled . psmell
emptyPer :: Perception
emptyPer = Perception { psight = PerVisible ES.empty
, psmell = PerSmelled ES.empty }
nullPer :: Perception -> Bool
nullPer per = per == emptyPer
addPer :: Perception -> Perception -> Perception
addPer per1 per2 =
Perception
{ psight = PerVisible
$ totalVisible per1 `ES.union` totalVisible per2
, psmell = PerSmelled
$ totalSmelled per1 `ES.union` totalSmelled per2
}
diffPer :: Perception -> Perception -> Perception
diffPer per1 per2 =
Perception
{ psight = PerVisible
$ totalVisible per1 ES.\\ totalVisible per2
, psmell = PerSmelled
$ totalSmelled per1 ES.\\ totalSmelled per2
}