Remove a usage of StrategyActions

This commit is contained in:
2025-10-15 19:41:26 +01:00
parent f9bcac915f
commit 57ca53638a
2 changed files with 22 additions and 34 deletions
+21 -26
View File
@@ -5,6 +5,7 @@ module Dodge.Creature.Perception (
visionCheck, visionCheck,
) where ) where
import Control.Monad
import Dodge.Creature.Radius import Dodge.Creature.Radius
import Linear import Linear
import Control.Lens import Control.Lens
@@ -47,24 +48,17 @@ basicAwarenessUpdate cr = case _cpAttention $ _crPerception cr of
& maybeBark & maybeBark
where where
oldAwareness = _cpAwareness $ _crPerception cr oldAwareness = _cpAwareness $ _crPerception cr
newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness newAwareness
becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
thejitter = RandImpulseCircMove 1 oldAwareness
maybeBark becomesCognizant
| becomesCognizant = case vocalizationTest cr of = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness
Just sid -> thejitter = [RandomImpulse $ RandImpulseCircMove 1]
crActionPlan . apAction maybeBark = fromMaybe id $ do
.~ [ ImpulsesList guard becomesCognizant
[ [Bark sid] sid <- vocalizationTest cr
, [RandomImpulse thejitter] return $ crActionPlan . apAction
, [RandomImpulse thejitter] .~ [ ImpulsesList ( [Bark sid] : replicate 5 thejitter) ]
, [RandomImpulse thejitter]
, [RandomImpulse thejitter]
, [RandomImpulse thejitter]
]
]
Nothing -> id
| otherwise = id
-- TODO fold in randgen update, requires that this is a world to world function -- TODO fold in randgen update, requires that this is a world to world function
chaseCritAwarenessUpdate :: World -> Creature -> Creature chaseCritAwarenessUpdate :: World -> Creature -> Creature
@@ -79,24 +73,25 @@ chaseCritAwarenessUpdate w cr = case _cpAttention $ _crPerception cr of
& maybeBark & maybeBark
where where
oldAwareness = _cpAwareness $ _crPerception cr oldAwareness = _cpAwareness $ _crPerception cr
newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness oldAwareness
thejitter = RandImpulseCircMove 3 becomesCognizant = any isCognizant
$ IM.unionWith cogRaised oldAwareness newAwareness
thejitter = [RandomImpulse $ RandImpulseCircMove 3]
maybeBark maybeBark
| becomesCognizant -- && randBool | becomesCognizant -- && randBool
&& cr ^? crVocalization . vcCoolDown == Just 0 = && cr ^? crVocalization . vcCoolDown == Just 0 =
let soundid = evalState (takeOne (crWarningSounds cr)) (_randGen w) let soundid = evalState (takeOne (crWarningSounds cr)) (_randGen w)
numjits = fst $ randomR (15, 25) (_randGen w) numjits = fst $ randomR (15, 25) (_randGen w)
in crActionPlan . apStrategy in (crActionPlan . apStrategy .~ WarningCry)
.~ StrategyActions . (crActionPlan . apAction .~
WarningCry
[ ImpulsesList [ ImpulsesList
( [Bark soundid] : ( [Bark soundid] :
replicate numjits [RandomImpulse thejitter] replicate numjits thejitter
++ [[ChangeStrategy $ CloseToMelee 0]] ++ [[ChangeStrategy $ CloseToMelee 0]]
) )
, AimAt 0 (w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy) , AimAt 0 (w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy)
] ])
| otherwise = id | otherwise = id
cogRaised :: Awareness -> Awareness -> Awareness cogRaised :: Awareness -> Awareness -> Awareness
+1 -8
View File
@@ -149,19 +149,12 @@ goToTarget w cr = case cr ^? crIntention . mvToPoint . _Just of
Just p -> cr & crActionPlan . apAction .~ [PathTo p] Just p -> cr & crActionPlan . apAction .~ [PathTo p]
_ -> viewTarget w cr _ -> viewTarget w cr
--lookAroundSelf :: Action
--lookAroundSelf = UseSelf CrTurnAround
viewTarget :: World -> Creature -> Creature viewTarget :: World -> Creature -> Creature
viewTarget w cr = case cr ^? crIntention . viewPoint . _Just of viewTarget w cr = case cr ^? crIntention . viewPoint . _Just of
Just p Just p
| hasLOSIndirect p (cr ^. crPos . _xy) w -> | hasLOSIndirect p (cr ^. crPos . _xy) w ->
cr cr
& crActionPlan . apAction & crActionPlan . apAction .~ [TurnToPoint p]
.~ [TurnToPoint p]
-- %~ replaceNullWith
-- ( TurnToPoint p
-- )
& crIntention . viewPoint .~ Nothing & crIntention . viewPoint .~ Nothing
& crActionPlan . apStrategy .~ Investigate & crActionPlan . apStrategy .~ Investigate
| otherwise -> | otherwise ->