diff --git a/src/Dodge/Creature/Perception.hs b/src/Dodge/Creature/Perception.hs index c5a6ba853..9400347b6 100644 --- a/src/Dodge/Creature/Perception.hs +++ b/src/Dodge/Creature/Perception.hs @@ -5,6 +5,7 @@ module Dodge.Creature.Perception ( visionCheck, ) where +import Control.Monad import Dodge.Creature.Radius import Linear import Control.Lens @@ -47,24 +48,17 @@ basicAwarenessUpdate cr = case _cpAttention $ _crPerception cr of & maybeBark where oldAwareness = _cpAwareness $ _crPerception cr - newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness - becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness - thejitter = RandImpulseCircMove 1 - maybeBark - | becomesCognizant = case vocalizationTest cr of - Just sid -> - crActionPlan . apAction - .~ [ ImpulsesList - [ [Bark sid] - , [RandomImpulse thejitter] - , [RandomImpulse thejitter] - , [RandomImpulse thejitter] - , [RandomImpulse thejitter] - , [RandomImpulse thejitter] - ] - ] - Nothing -> id - | otherwise = id + newAwareness + = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) + oldAwareness + becomesCognizant + = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness + thejitter = [RandomImpulse $ RandImpulseCircMove 1] + maybeBark = fromMaybe id $ do + guard becomesCognizant + sid <- vocalizationTest cr + return $ crActionPlan . apAction + .~ [ ImpulsesList ( [Bark sid] : replicate 5 thejitter) ] -- TODO fold in randgen update, requires that this is a world to world function chaseCritAwarenessUpdate :: World -> Creature -> Creature @@ -79,24 +73,25 @@ chaseCritAwarenessUpdate w cr = case _cpAttention $ _crPerception cr of & maybeBark where oldAwareness = _cpAwareness $ _crPerception cr - newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness - becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness - thejitter = RandImpulseCircMove 3 + newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) + oldAwareness + becomesCognizant = any isCognizant + $ IM.unionWith cogRaised oldAwareness newAwareness + thejitter = [RandomImpulse $ RandImpulseCircMove 3] maybeBark | becomesCognizant -- && randBool && cr ^? crVocalization . vcCoolDown == Just 0 = let soundid = evalState (takeOne (crWarningSounds cr)) (_randGen w) numjits = fst $ randomR (15, 25) (_randGen w) - in crActionPlan . apStrategy - .~ StrategyActions - WarningCry + in (crActionPlan . apStrategy .~ WarningCry) + . (crActionPlan . apAction .~ [ ImpulsesList ( [Bark soundid] : - replicate numjits [RandomImpulse thejitter] + replicate numjits thejitter ++ [[ChangeStrategy $ CloseToMelee 0]] ) , AimAt 0 (w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy) - ] + ]) | otherwise = id cogRaised :: Awareness -> Awareness -> Awareness diff --git a/src/Dodge/Creature/ReaderUpdate.hs b/src/Dodge/Creature/ReaderUpdate.hs index 71a8b29ff..9202dddf7 100644 --- a/src/Dodge/Creature/ReaderUpdate.hs +++ b/src/Dodge/Creature/ReaderUpdate.hs @@ -149,19 +149,12 @@ goToTarget w cr = case cr ^? crIntention . mvToPoint . _Just of Just p -> cr & crActionPlan . apAction .~ [PathTo p] _ -> viewTarget w cr ---lookAroundSelf :: Action ---lookAroundSelf = UseSelf CrTurnAround - viewTarget :: World -> Creature -> Creature viewTarget w cr = case cr ^? crIntention . viewPoint . _Just of Just p | hasLOSIndirect p (cr ^. crPos . _xy) w -> cr - & crActionPlan . apAction - .~ [TurnToPoint p] - -- %~ replaceNullWith - -- ( TurnToPoint p - -- ) + & crActionPlan . apAction .~ [TurnToPoint p] & crIntention . viewPoint .~ Nothing & crActionPlan . apStrategy .~ Investigate | otherwise ->