Rename Perception datatype/fields
This commit is contained in:
@@ -34,15 +34,15 @@ chaseCritPerceptionUpdate is w =
|
||||
{- | Update a creatures awareness based upon the creatures' current direction
|
||||
of attention -} -- TODO delete?
|
||||
basicAwarenessUpdate :: Creature -> Creature
|
||||
basicAwarenessUpdate cr = case _crAttentionDir $ _crPerception cr of
|
||||
Fixated i -> cr & crPerception . crAwarenessLevel
|
||||
basicAwarenessUpdate cr = case _cpAttention $ _crPerception cr of
|
||||
Fixated i -> cr & crPerception . cpAwareness
|
||||
%~ (IM.insert i (Cognizant 10000) . IM.mapMaybe decreaseAwareness)
|
||||
AttentiveTo is -> cr
|
||||
& crPerception . crAwarenessLevel
|
||||
& crPerception . cpAwareness
|
||||
%~ (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
|
||||
& maybeBark
|
||||
where
|
||||
oldAwareness = _crAwarenessLevel $ _crPerception cr
|
||||
oldAwareness = _cpAwareness $ _crPerception cr
|
||||
newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness
|
||||
becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness
|
||||
thejitter = do
|
||||
@@ -65,15 +65,15 @@ basicAwarenessUpdate cr = case _crAttentionDir $ _crPerception cr of
|
||||
|
||||
-- TODO fold in randgen update, requires that this is a world to world function
|
||||
chaseCritAwarenessUpdate :: World -> Creature -> Creature
|
||||
chaseCritAwarenessUpdate w cr = case _crAttentionDir $ _crPerception cr of
|
||||
Fixated i -> cr & crPerception . crAwarenessLevel
|
||||
chaseCritAwarenessUpdate w cr = case _cpAttention $ _crPerception cr of
|
||||
Fixated i -> cr & crPerception . cpAwareness
|
||||
%~ (IM.insert i (Cognizant 10000) . IM.mapMaybe decreaseAwareness)
|
||||
AttentiveTo is -> cr
|
||||
& crPerception . crAwarenessLevel
|
||||
& crPerception . cpAwareness
|
||||
%~ (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
|
||||
& maybeBark
|
||||
where
|
||||
oldAwareness = _crAwarenessLevel $ _crPerception cr
|
||||
oldAwareness = _cpAwareness $ _crPerception cr
|
||||
newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness
|
||||
becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness
|
||||
--randBool = takeOne [False,True] & evalState $ _randGen w
|
||||
@@ -92,15 +92,15 @@ chaseCritAwarenessUpdate w cr = case _crAttentionDir $ _crPerception cr of
|
||||
]
|
||||
| otherwise = id
|
||||
|
||||
cogRaised :: AwarenessLevel -> AwarenessLevel -> AwarenessLevel
|
||||
cogRaised :: Awareness -> Awareness -> Awareness
|
||||
cogRaised Suspicious{} Cognizant{} = Cognizant 100
|
||||
cogRaised _ _ = Suspicious 0
|
||||
|
||||
isCognizant :: AwarenessLevel -> Bool
|
||||
isCognizant :: Awareness -> Bool
|
||||
isCognizant Cognizant {} = True
|
||||
isCognizant _ = False
|
||||
|
||||
combineAwareness :: AwarenessLevel -> AwarenessLevel -> AwarenessLevel
|
||||
combineAwareness :: Awareness -> Awareness -> Awareness
|
||||
combineAwareness (Suspicious x) (Suspicious y)
|
||||
| x + y < 5000 = Suspicious $ x + y
|
||||
| otherwise = Cognizant 1000
|
||||
@@ -110,7 +110,7 @@ combineAwareness (Cognizant x) (Cognizant y) = Cognizant $ min 10000 $ x + y
|
||||
|
||||
{- | Decrease awareness level. Returns 'Maybe' value for use with 'IM.mapMaybe'
|
||||
-}
|
||||
decreaseAwareness :: AwarenessLevel -> Maybe AwarenessLevel
|
||||
decreaseAwareness :: Awareness -> Maybe Awareness
|
||||
decreaseAwareness (Suspicious 0) = Nothing
|
||||
decreaseAwareness (Suspicious x) = Just $ Suspicious (x - 50)
|
||||
decreaseAwareness (Cognizant 0) = Just $ Suspicious 1000
|
||||
@@ -123,26 +123,26 @@ basicAttentionUpdate
|
||||
-> World
|
||||
-> Creature
|
||||
-> Creature
|
||||
basicAttentionUpdate cids w cr = cr & crPerception . crAttentionDir .~
|
||||
basicAttentionUpdate cids w cr = cr & crPerception . cpAttention .~
|
||||
AttentiveTo (IM.mapMaybe (newExtraAwareness cr w) $ IM.fromList $ zip cids cids)
|
||||
|
||||
newExtraAwareness
|
||||
:: Creature -- ^ source creature
|
||||
-> World
|
||||
-> Int -- ^ target creature id
|
||||
-> Maybe AwarenessLevel
|
||||
-> Maybe Awareness
|
||||
newExtraAwareness cr w cid
|
||||
| not $ canSeeIndirect (_crID cr) cid w = Nothing
|
||||
| otherwise = Just . Suspicious $ _viFOV vi ang * _viDist vi d * awakeLevelPerception cr
|
||||
where
|
||||
vi = _crVision $ _crPerception cr
|
||||
vi = _cpVision $ _crPerception cr
|
||||
tpos = _crPos $ _creatures w IM.! cid
|
||||
cpos = _crPos cr
|
||||
ang = angleVV (unitVectorAtAngle (_crDir cr)) (tpos - cpos)
|
||||
d = dist tpos cpos
|
||||
|
||||
awakeLevelPerception :: Creature -> Float
|
||||
awakeLevelPerception cr = case _crAwakeLevel $ _crPerception cr of
|
||||
awakeLevelPerception cr = case _cpVigilance $ _crPerception cr of
|
||||
Comatose -> 0
|
||||
Asleep -> 10
|
||||
Lethargic -> 200
|
||||
@@ -162,13 +162,13 @@ rememberSounds w cr = cr
|
||||
& awakeupdate
|
||||
where
|
||||
awakeupdate | null closesounds = id
|
||||
| otherwise = crPerception . crAwakeLevel .~ Vigilant
|
||||
| otherwise = crPerception . cpVigilance .~ Vigilant
|
||||
closesounds = map fst (filter (soundIsClose w cr) (newSounds w))
|
||||
|
||||
-- TODO work out correct form for sounds passing through walls
|
||||
soundIsClose :: World -> Creature -> (Point2,Float) -> Bool
|
||||
soundIsClose w cr (pos,vol) = dist cpos pos < 2000
|
||||
&& vol > (_auDist . _crAudition $ _crPerception cr) (dist pos cpos)
|
||||
&& vol > (_auDist . _cpAudition $ _crPerception cr) (dist pos cpos)
|
||||
&& hasLOS cpos pos w
|
||||
where
|
||||
cpos = _crPos cr
|
||||
|
||||
Reference in New Issue
Block a user