Assorted changes, cleanup menu selection text

This commit is contained in:
2022-04-25 23:27:39 +01:00
parent 67e6c4a5bd
commit fa8d8b5899
22 changed files with 217 additions and 108 deletions
+40 -4
View File
@@ -1,11 +1,13 @@
--{-# LANGUAGE TupleSections #-}
module Dodge.Creature.Perception
( perceptionUpdate
, chaseCritPerceptionUpdate
, newSounds
) where
import Dodge.Data
import Dodge.Creature.Vocalization
import Dodge.Base.Collide
import Dodge.RandomHelp
--import Dodge.SoundLogic
import Geometry.Vector
--import Geometry.Data
@@ -13,6 +15,7 @@ import Geometry.Data
import Sound.Data
--import StrictHelp
import Control.Monad.State
import Data.Maybe
import Control.Lens
import qualified Data.IntMap.Strict as IM
@@ -25,10 +28,16 @@ perceptionUpdate
-> Creature
perceptionUpdate is w = rememberSounds w . basicAwarenessUpdate . basicAttentionUpdate is w
chaseCritPerceptionUpdate :: [Int] -> World -> Creature -> Creature
chaseCritPerceptionUpdate is w =
rememberSounds w . chaseCritAwarenessUpdate w . basicAttentionUpdate is w
{- | Update a creatures awareness based upon the creatures' current direction
of attention -}
basicAwarenessUpdate :: Creature -> Creature
basicAwarenessUpdate cr = case _crAttentionDir $ _crPerception cr of
Fixated i -> cr & crPerception . crAwarenessLevel
%~ (IM.insert i (Cognizant 10000) . IM.mapMaybe decreaseAwareness)
AttentiveTo is -> cr
& crPerception . crAwarenessLevel
%~ (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
@@ -41,8 +50,29 @@ basicAwarenessUpdate cr = case _crAttentionDir $ _crPerception cr of
Just sid -> crActionPlan . crImpulse .~ [Bark sid]
Nothing -> id
| otherwise = id
Fixated i -> cr & crPerception . crAwarenessLevel
%~ ( IM.insert i (Cognizant 10000) . IM.mapMaybe decreaseAwareness)
chaseCritAwarenessUpdate :: World -> Creature -> Creature
chaseCritAwarenessUpdate w cr = case _crAttentionDir $ _crPerception cr of
Fixated i -> cr & crPerception . crAwarenessLevel
%~ (IM.insert i (Cognizant 10000) . IM.mapMaybe decreaseAwareness)
AttentiveTo is -> cr
& crPerception . crAwarenessLevel
%~ (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
& maybeBark
where
oldAwareness = _crAwarenessLevel $ _crPerception cr
newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness
becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness
randBool = takeOne [False,True] & evalState $ _randGen w
maybeBark
| becomesCognizant && randBool =
crActionPlan . crStrategy .~ StrategyActions WarningCry
[DoImpulses [Bark $ fromJust $ vocalizationTest cr]
`DoActionThen` 20
`WaitThen` DoImpulses [ChangeStrategy $ CloseToMelee 0]
, AimAt 0 (_crPos $ _creatures w IM.! 0)
]
| otherwise = id
cogRaised :: AwarenessLevel -> AwarenessLevel -> AwarenessLevel
cogRaised Suspicious{} Cognizant{} = Cognizant 100
@@ -76,7 +106,7 @@ basicAttentionUpdate
-> Creature
-> Creature
basicAttentionUpdate cids w cr = cr & crPerception . crAttentionDir .~
AttentiveTo (IM.mapMaybe (newExtraAwareness cr w) $ IM.fromList $ zip cids cids)
AttentiveTo (IM.mapMaybe (newExtraAwareness cr w) $ IM.fromList $ zip cids cids)
newExtraAwareness
:: Creature -- ^ source creature
@@ -110,7 +140,13 @@ newSounds = mapMaybe f . M.elems . _playingSounds
rememberSounds :: World -> Creature -> Creature
rememberSounds w cr = cr
& crMemory . soundsToInvestigate .~ map fst (filter (soundIsClose cr) (newSounds w))
& crMemory . soundsToInvestigate .~ closesounds
& awakeupdate
where
awakeupdate | null closesounds = id
| otherwise = crPerception . crAwakeLevel .~ Vigilant
closesounds = map fst (filter (soundIsClose cr) (newSounds w))
soundIsClose :: Creature -> (Point2,Float) -> Bool
soundIsClose cr (pos,vol) = vol > (_auDist . _crAudition $ _crPerception cr) (dist pos (_crPos cr))