Add jitter on chase crit bark

This commit is contained in:
2022-05-19 10:58:13 +01:00
parent 565a71a5a2
commit 41e5538eb7
5 changed files with 45 additions and 10 deletions
+28 -8
View File
@@ -33,7 +33,7 @@ chaseCritPerceptionUpdate is w =
rememberSounds w . chaseCritAwarenessUpdate w . basicAttentionUpdate is w
{- | Update a creatures awareness based upon the creatures' current direction
of attention -}
of attention -} -- TODO delete?
basicAwarenessUpdate :: Creature -> Creature
basicAwarenessUpdate cr = case _crAttentionDir $ _crPerception cr of
Fixated i -> cr & crPerception . crAwarenessLevel
@@ -46,10 +46,23 @@ basicAwarenessUpdate cr = case _crAttentionDir $ _crPerception cr of
oldAwareness = _crAwarenessLevel $ _crPerception cr
newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness
becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness
maybeBark | becomesCognizant = case vocalizationTest cr of
Just sid -> crActionPlan . crImpulse .~ [Bark sid]
Nothing -> id
| otherwise = id
thejitter = do
p <- randInCirc 1
return $ Move p
maybeBark
| becomesCognizant = case vocalizationTest cr of
Just sid -> crActionPlan . crAction .~
[ImpulsesList
[[Bark sid]
,[RandomImpulse thejitter]
,[RandomImpulse thejitter]
,[RandomImpulse thejitter]
,[RandomImpulse thejitter]
,[RandomImpulse thejitter]
]
]
Nothing -> id
| otherwise = id
chaseCritAwarenessUpdate :: World -> Creature -> Creature
chaseCritAwarenessUpdate w cr = case _crAttentionDir $ _crPerception cr of
@@ -64,14 +77,21 @@ chaseCritAwarenessUpdate w cr = case _crAttentionDir $ _crPerception cr of
newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness
becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness
randBool = takeOne [False,True] & evalState $ _randGen w
thejitter = do
p <- randInCirc 2
return $ Move p
maybeBark
| becomesCognizant && randBool = case vocalizationTest cr of
Just soundid -> crActionPlan . crStrategy .~ StrategyActions WarningCry
[DoImpulses [Bark soundid]
`DoActionThen` 20
`WaitThen` DoImpulses [ChangeStrategy $ CloseToMelee 0]
[ImpulsesList ([Bark soundid]: replicate 20 [RandomImpulse thejitter]++
[[ChangeStrategy $ CloseToMelee 0] ])
, AimAt 0 (_crPos $ _creatures w IM.! 0)
]
--[ImpulsesList [Bark soundid: replicate 20 (RandomImpulse thejitter)]
-- `DoActionThen` 20
-- `WaitThen` DoImpulses [ChangeStrategy $ CloseToMelee 0]
--, AimAt 0 (_crPos $ _creatures w IM.! 0)
--]
Nothing -> id
| otherwise = id