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,
) 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
+1 -8
View File
@@ -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 ->