Add basic vocalizations to chase creatures
This commit is contained in:
@@ -19,7 +19,6 @@ import Dodge.Base
|
||||
import Dodge.Zone
|
||||
import Dodge.Base.Collide
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.SoundLogic.LoadSound
|
||||
--import Dodge.WorldEvent
|
||||
import Dodge.Inventory
|
||||
--import Dodge.LightSources
|
||||
|
||||
@@ -13,6 +13,7 @@ import Dodge.Creature.State
|
||||
import Dodge.Creature.State.Data
|
||||
import Dodge.Item.Consumable
|
||||
import Dodge.Picture.Layer
|
||||
import Dodge.SoundLogic
|
||||
--import Geometry
|
||||
import Picture
|
||||
--import Dodge.RandomHelp
|
||||
@@ -40,7 +41,6 @@ chaseCrit = defaultCreature
|
||||
overrideMeleeCloseTargetR >=>
|
||||
setViewPos >=>
|
||||
setMvPos >=>
|
||||
-- setTargetMv (pure . _crTarget) >=>
|
||||
goToTarget >=>
|
||||
perceptionUpdate [0] >=>
|
||||
targetYouWhenCognizantR >=>
|
||||
@@ -50,6 +50,7 @@ chaseCrit = defaultCreature
|
||||
, _crInv = IM.fromList [(0,medkit 200)]
|
||||
, _crMeleeCooldown = 0
|
||||
, _crFaction = ColorFaction green
|
||||
, _crVocalization = Vocalization seagullBarkS 50 0
|
||||
, _crMvType = ChaseMvType
|
||||
{ _mvSpeed = 3
|
||||
, _mvTurnRad = f
|
||||
|
||||
@@ -10,7 +10,6 @@ import Dodge.Creature.Impulse.UseItem
|
||||
import Dodge.Creature.State.Data
|
||||
import Dodge.Creature.Stance.Data
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.SoundLogic.LoadSound
|
||||
import Geometry
|
||||
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
@@ -45,6 +44,7 @@ followImpulse
|
||||
-> Impulse
|
||||
-> (World -> World , Creature)
|
||||
followImpulse cr w imp = case imp of
|
||||
Bark sid -> (soundStart (CrMouth cid) cpos sid Nothing, resetCrVocCoolDown cr)
|
||||
Move p -> (id, crMvBy p cr)
|
||||
MoveForward x -> (id, crMvForward x cr)
|
||||
Turn a -> (id, creatureTurn a cr)
|
||||
@@ -85,3 +85,8 @@ followImpulse cr w imp = case imp of
|
||||
hitCr i = over (creatures . ix i . crState . crDamage) (addDam i)
|
||||
. 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
|
||||
|
||||
@@ -30,7 +30,6 @@ import Shape
|
||||
import Dodge.WorldEvent
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.Data.SoundOrigin
|
||||
import Dodge.SoundLogic.LoadSound
|
||||
|
||||
import System.Random
|
||||
import Data.List
|
||||
|
||||
@@ -8,6 +8,7 @@ import Dodge.Data
|
||||
import Dodge.Creature.Perception.Data
|
||||
import Dodge.Creature.Memory.Data
|
||||
import Dodge.Base.Collide
|
||||
import Dodge.SoundLogic
|
||||
import Geometry.Vector
|
||||
--import Geometry.Data
|
||||
import Geometry.Data
|
||||
@@ -25,7 +26,8 @@ perceptionUpdate
|
||||
:: [Int] -- ^ List of creature ids that may direct attention and awareness
|
||||
-> Creature
|
||||
-> Reader World Creature
|
||||
perceptionUpdate is cr = basicAttentionUpdate is cr >>= basicAwarenessUpdate
|
||||
perceptionUpdate is cr = basicAttentionUpdate is cr
|
||||
>>= basicAwarenessUpdate
|
||||
>>= rememberSounds
|
||||
|
||||
{- | Update a creatures awareness based upon the creatures' current direction
|
||||
@@ -33,11 +35,34 @@ perceptionUpdate is cr = basicAttentionUpdate is cr >>= basicAwarenessUpdate
|
||||
basicAwarenessUpdate
|
||||
:: Creature -> Reader World Creature
|
||||
basicAwarenessUpdate cr = case _crAttentionDir $ _crPerception cr of
|
||||
AttentiveTo is -> pure $ cr & crPerception . crAwarenessLevel
|
||||
%~ (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
|
||||
AttentiveTo is -> pure $ 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
|
||||
maybeBark | becomesCognizant = case vocalizationTest cr of
|
||||
Just sid -> crActionPlan . crImpulse .~ [Bark sid]
|
||||
Nothing -> id
|
||||
| otherwise = id
|
||||
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
|
||||
|
||||
isCognizant :: AwarenessLevel -> Bool
|
||||
isCognizant Cognizant {} = True
|
||||
isCognizant _ = False
|
||||
|
||||
combineAwareness :: AwarenessLevel -> AwarenessLevel -> AwarenessLevel
|
||||
combineAwareness (Suspicious x) (Suspicious y)
|
||||
| x + y < 10000 = Suspicious $ x + y
|
||||
|
||||
@@ -153,7 +153,6 @@ watchUpdateStratR fs cr = reader $ \w -> case cr ^? crActionPlan . crStrategy of
|
||||
& crActionPlan . crStrategy .~ listGuard (fs, \_ _ -> WatchAndWait) (w, cr) w cr
|
||||
_ -> cr
|
||||
|
||||
|
||||
listGuard :: ([(a -> Bool, b)] , b) -> a -> b
|
||||
listGuard ( (test,y):ps, z ) x
|
||||
| test x = y
|
||||
|
||||
@@ -11,7 +11,6 @@ import Dodge.Creature.Stance.Data
|
||||
--import Dodge.Creature.Test
|
||||
--import Dodge.Base
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.SoundLogic.LoadSound
|
||||
import Dodge.RandomHelp
|
||||
import Dodge.WorldEvent
|
||||
--import Dodge.WallCreatureCollisions
|
||||
|
||||
@@ -7,7 +7,6 @@ import Dodge.Data
|
||||
import Dodge.Data.SoundOrigin
|
||||
import Dodge.Creature.Stance.Data
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.SoundLogic.LoadSound
|
||||
import Geometry.Data
|
||||
import Sound.Data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user