Make creature vocalizations stop on death

This commit is contained in:
2021-11-18 02:42:12 +00:00
parent f6d5d5a201
commit 94552ff658
7 changed files with 43 additions and 13 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ chaseCrit = defaultCreature
, _crInv = IM.fromList [(0,medkit 200)]
, _crMeleeCooldown = 0
, _crFaction = ColorFaction green
, _crVocalization = Vocalization seagullBarkS 50 0
, _crVocalization = Vocalization seagullChatterS 50 0
, _crMvType = ChaseMvType
{ _mvSpeed = 3
, _mvTurnRad = f
+1 -4
View File
@@ -3,6 +3,7 @@ module Dodge.Creature.Impulse
)
where
import Dodge.Data
import Dodge.Creature.Vocalization
import Dodge.Data.SoundOrigin
import Dodge.Creature.Impulse.Movement
import Dodge.Creature.Impulse.UseItem
@@ -86,7 +87,3 @@ followImpulse cr w imp = case imp of
. soundStart (CrSound cid) cpos hitS Nothing
addDam i dams = Blunt 100 cpos (posFromID i) (posFromID i) : dams
resetCrVocCoolDown :: Creature -> Creature
resetCrVocCoolDown cr = case cr ^? crVocalization . vcMaxCoolDown of
Just i -> cr & crVocalization . vcCoolDown .~ i
Nothing -> cr
+2 -6
View File
@@ -6,9 +6,10 @@ module Dodge.Creature.Perception
where
import Dodge.Data
import Dodge.Creature.Perception.Data
import Dodge.Creature.Vocalization
import Dodge.Creature.Memory.Data
import Dodge.Base.Collide
import Dodge.SoundLogic
--import Dodge.SoundLogic
import Geometry.Vector
--import Geometry.Data
import Geometry.Data
@@ -50,11 +51,6 @@ basicAwarenessUpdate cr = case _crAttentionDir $ _crPerception cr of
Fixated i -> pure $ cr & crPerception . crAwarenessLevel
%~ ( IM.insert i (Cognizant 10000) . IM.mapMaybe decreaseAwareness)
vocalizationTest :: Creature -> Maybe SoundID
vocalizationTest cr = case cr ^? crVocalization . vcCoolDown of
Just 0 -> Just $ _vcSound $ _crVocalization cr
Nothing -> Nothing
cogRaised :: AwarenessLevel -> AwarenessLevel -> AwarenessLevel
cogRaised Suspicious{} Cognizant{} = Cognizant 100
cogRaised _ _ = Suspicious 0
+15
View File
@@ -0,0 +1,15 @@
module Dodge.Creature.Vocalization where
import Dodge.Data
import Sound.Data
import Control.Lens
vocalizationTest :: Creature -> Maybe SoundID
vocalizationTest cr = case cr ^? crVocalization . vcCoolDown of
Just 0 -> Just $ _vcSound $ _crVocalization cr
_ -> Nothing
resetCrVocCoolDown :: Creature -> Creature
resetCrVocCoolDown cr = case cr ^? crVocalization . vcMaxCoolDown of
Just i -> cr & crVocalization . vcCoolDown .~ i
Nothing -> cr
+3
View File
@@ -12,6 +12,9 @@ module Dodge.SoundLogic (
, soundMultiFrom
, stopSoundFrom
-- * helper to determine the angle of a sound given a world position
, soundAngle
-- * Manipulation of all sounds
, haltSound
, resumeSound
+18
View File
@@ -6,6 +6,8 @@ module Dodge.Update
( update
) where
import Dodge.Data
import Dodge.Data.SoundOrigin
import Dodge.SoundLogic
import Dodge.Menu
import Dodge.Config.Data
import Dodge.Base
@@ -18,6 +20,7 @@ import Dodge.WorldEvent.Sound
import Dodge.Wall.Delete
import Dodge.Wall.Dust
import Dodge.RandomHelp
import Sound.Data
import Geometry
import Geometry.ConvexPoly
import Geometry.Vector3D
@@ -29,6 +32,7 @@ import Data.Function
import qualified Data.Set as S
import qualified Data.IntSet as IS
import qualified Data.IntMap.Strict as IM
import qualified Data.Map.Strict as M
import Control.Lens
import Control.Monad
import Control.Monad.State
@@ -53,6 +57,7 @@ functionalUpdate w = case _menuLayers w of
(_ : _) -> w
[] -> checkEndGame
. updateRadialDistortions
. updateCreatureSoundPositions
. ppEvents
. updateCamera
. colCrsWalls
@@ -87,6 +92,19 @@ functionalUpdate w = case _menuLayers w of
where
(x,y) = cloudZoneOfPoint $ stripZ $ _clPos cl
updateCreatureSoundPositions :: World -> World
updateCreatureSoundPositions w = M.foldrWithKey insertSound w soundsToUpdate
where
insertSound k s w' = w & toPlaySounds %~ M.insertWith (\_ -> id) k (updateSound k s)
updateSound (CrMouth cid) s = case w ^? creatures . ix cid . crPos of
Just p -> s {_soundPos = p, _soundAngDist = Just (soundAngle p w,0)}
Nothing -> s {_soundTime = Just 0}
soundsToUpdate = M.filterWithKey (\k _ -> isCrMouth k) $ _playingSounds w
isCrMouth :: SoundOrigin -> Bool
isCrMouth CrMouth{} = True
isCrMouth _ = False
updateModifications :: World -> World
updateModifications w = foldr f w (_modifications w)
where
+3 -2
View File
@@ -13,6 +13,7 @@ data SoundStatus
| Playing
| ToStart
| ToContinueStart
| ToStop
deriving (Eq,Ord,Show)
newtype SoundID = SoundID { _getSoundID :: Int }
deriving (Eq,Ord,Show)
@@ -23,8 +24,8 @@ data Sound = Sound
{ _soundTime :: Maybe Int
, _soundStatus :: SoundStatus
, _soundChannel :: Maybe Mix.Channel
, _soundAngDist :: Maybe (Int16,Word8)
, _soundPos :: Point2
, _soundAngDist :: Maybe (Int16,Word8) -- why do BOTH of
, _soundPos :: Point2 -- these exist?
, _soundVolume :: Float
, _soundChunkID :: SoundID
}