Make _targetCr an Int id rather than a full creature

This commit is contained in:
2025-10-15 20:09:17 +01:00
parent 57ca53638a
commit 5e6ed1d793
13 changed files with 122 additions and 123 deletions
+32 -29
View File
@@ -5,19 +5,19 @@ module Dodge.Creature.Perception (
visionCheck,
) where
import Control.Monad
import Dodge.Creature.Radius
import Linear
import Control.Lens
import Control.Monad
import qualified Data.Map.Strict as M
import Data.Maybe
import Dodge.Base.Collide
import Dodge.Creature.Radius
import Dodge.Creature.Vocalization
import Dodge.Data.World
import Dodge.FloatFunction
import Geometry.Data
import Geometry.Vector
import qualified IntMapHelp as IM
import Linear
import RandomHelp
import Sound.Data
@@ -48,17 +48,18 @@ basicAwarenessUpdate cr = case _cpAttention $ _crPerception cr of
& maybeBark
where
oldAwareness = _cpAwareness $ _crPerception cr
newAwareness
= (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
newAwareness =
(IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
oldAwareness
becomesCognizant
= any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness
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) ]
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
@@ -73,26 +74,29 @@ 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
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 .~ WarningCry)
. (crActionPlan . apAction .~
[ ImpulsesList
( [Bark soundid] :
replicate numjits thejitter
++ [[ChangeStrategy $ CloseToMelee 0]]
)
, AimAt 0 (w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy)
])
| otherwise = id
maybeBark = fromMaybe id $ do
guard $ becomesCognizant
guard $ cr ^? crVocalization . vcCoolDown == Just 0
let soundid = evalState (takeOne (crWarningSounds cr)) (_randGen w)
numjits = fst $ randomR (15, 25) (_randGen w)
return $
(crActionPlan . apStrategy .~ WarningCry)
. ( crActionPlan . apAction
.~ [ ImpulsesList
( [Bark soundid] :
replicate numjits thejitter
++ [[ChangeStrategy $ CloseToMelee 0]]
)
, AimAt 0 (w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy)
]
)
cogRaised :: Awareness -> Awareness -> Awareness
cogRaised Suspicious{} Cognizant{} = Cognizant 100
@@ -153,7 +157,6 @@ visionCheck cr tpos = doFloatFloat (_viFOV vi) ang * doFloatFloat (_viDist vi) d
dirvec = unitVectorAtAngle (_crDir cr)
ang = angleVV dirvec (tpos - (cpos - crRad (cr ^. crType) *^ dirvec))
d = dist tpos cpos
awakeLevelPerception :: Creature -> Float
awakeLevelPerception cr = case _cpVigilance $ _crPerception cr of