Move towards incorporating sound into ai
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
{- | Deals with changes in a creature's awareness of other creatures. -}
|
||||
module Dodge.Creature.AlertLevel
|
||||
( basicPerceptionUpdateR
|
||||
)
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Creature.AlertLevel.Data
|
||||
import Dodge.Base.Collide
|
||||
--import StrictHelp
|
||||
|
||||
import Control.Lens
|
||||
import Control.Monad.Reader
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
|
||||
{- | Ties together (currently) an awareness and attention update -}
|
||||
basicPerceptionUpdateR
|
||||
:: [Int] -- ^ List of creature ids that may direct attention and awareness
|
||||
-> Creature
|
||||
-> Reader World Creature
|
||||
basicPerceptionUpdateR is cr = basicAttentionUpdate is cr >>= basicAwarenessUpdate
|
||||
|
||||
{- | Update a creatures awareness based upon the creatures' current direction
|
||||
of attention -}
|
||||
basicAwarenessUpdate
|
||||
:: Creature -> Reader World Creature
|
||||
basicAwarenessUpdate cr = case _crAttentionDir cr of
|
||||
AttentiveTo is -> pure $ cr & crAwarenessLevel
|
||||
%~ (IM.unionWith combineAwareness is . IM.mapMaybe decreaseAwareness)
|
||||
Fixated i -> pure $ cr & crAwarenessLevel
|
||||
%~ ( IM.insert i (Cognizant 100) . IM.mapMaybe decreaseAwareness)
|
||||
|
||||
combineAwareness :: AwarenessLevel -> AwarenessLevel -> AwarenessLevel
|
||||
combineAwareness (AwarenessInt x) (AwarenessInt y)
|
||||
| x + y < 100 = AwarenessInt $ x + y
|
||||
| otherwise = Cognizant 50
|
||||
combineAwareness (AwarenessInt x) (Cognizant y) = Cognizant $ min 100 $ x + y
|
||||
combineAwareness (Cognizant x) (AwarenessInt y) = Cognizant $ min 100 $ x + y
|
||||
combineAwareness (Cognizant x) (Cognizant y) = Cognizant $ min 100 $ x + y
|
||||
|
||||
{- | Decrease awareness level. Returns 'Maybe' value for use with 'IM.mapMaybe'
|
||||
-}
|
||||
decreaseAwareness :: AwarenessLevel -> Maybe AwarenessLevel
|
||||
decreaseAwareness (AwarenessInt 0) = Nothing
|
||||
decreaseAwareness (AwarenessInt x) = Just $ AwarenessInt (x - 1)
|
||||
decreaseAwareness (Cognizant 0) = Just $ AwarenessInt 100
|
||||
decreaseAwareness (Cognizant x) = Just $ Cognizant $ x - 1
|
||||
{- | Given a fixed group of creatures, direct attention to those of them that
|
||||
- are in view. -}
|
||||
basicAttentionUpdate
|
||||
:: [Int] -- ^ Creatures that may attract this creature's attention
|
||||
-> Creature
|
||||
-> Reader World Creature
|
||||
basicAttentionUpdate cids cr = do
|
||||
w <- ask
|
||||
pure $ cr & crAttentionDir .~
|
||||
AttentiveTo (IM.fromList $ map (, AwarenessInt 2) $ filter (\cid -> canSeeIndirect (_crID cr) cid w) cids)
|
||||
@@ -1,29 +0,0 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE StrictData #-}
|
||||
module Dodge.Creature.AlertLevel.Data
|
||||
( AwakeLevel (..)
|
||||
, AttentionDir (..)
|
||||
, AwarenessLevel (..)
|
||||
-- lenses
|
||||
, getAttentiveTo
|
||||
, getFixated
|
||||
) where
|
||||
import Control.Lens
|
||||
import qualified Data.IntMap as IM
|
||||
|
||||
data AwakeLevel
|
||||
= Comatose
|
||||
| Asleep
|
||||
| Lethargic
|
||||
| Vigilant
|
||||
| Overstrung
|
||||
|
||||
data AttentionDir
|
||||
= AttentiveTo {_getAttentiveTo :: IM.IntMap AwarenessLevel }
|
||||
| Fixated {_getFixated :: Int }
|
||||
|
||||
data AwarenessLevel
|
||||
= AwarenessInt Int
|
||||
| Cognizant Int
|
||||
|
||||
makeLenses ''AttentionDir
|
||||
@@ -7,7 +7,7 @@ import Dodge.Default
|
||||
import Dodge.Creature.State
|
||||
import Dodge.Creature.State.Data
|
||||
import Dodge.Creature.ReaderUpdate
|
||||
import Dodge.Creature.AlertLevel
|
||||
import Dodge.Creature.Perception
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.Creature.Impulse
|
||||
import Dodge.Creature.Action
|
||||
@@ -28,7 +28,7 @@ armourChaseCrit = defaultCreature
|
||||
targetYouWhenCognizantR >=>
|
||||
setTargetMv (pure . _crTarget) >=> -- should be able to remove this?
|
||||
flockACCR >=>
|
||||
basicPerceptionUpdateR [0] >=>
|
||||
perceptionUpdate [0] >=>
|
||||
goToTarget >=>
|
||||
overrideMeleeCloseTargetR >=>
|
||||
return . (crMeleeCooldown %~ max 0 . subtract 1)
|
||||
|
||||
@@ -8,7 +8,7 @@ import Dodge.Creature.Picture
|
||||
import Dodge.Creature.ReaderUpdate
|
||||
import Dodge.Creature.Impulse
|
||||
import Dodge.Creature.Action
|
||||
import Dodge.Creature.AlertLevel
|
||||
import Dodge.Creature.Perception
|
||||
import Dodge.Creature.State
|
||||
import Dodge.Creature.State.Data
|
||||
import Dodge.Item.Consumable
|
||||
@@ -38,9 +38,10 @@ chaseCrit = defaultCreature
|
||||
doStrategyActionsR >=>
|
||||
performActionsR >=>
|
||||
overrideMeleeCloseTargetR >=>
|
||||
setTargetMv (pure . _crTarget) >=>
|
||||
setMvPos >=>
|
||||
-- setTargetMv (pure . _crTarget) >=>
|
||||
goToTarget >=>
|
||||
basicPerceptionUpdateR [0] >=>
|
||||
perceptionUpdate [0] >=>
|
||||
targetYouWhenCognizantR >=>
|
||||
return . (crMeleeCooldown %~ max 0 . subtract 1)
|
||||
, _crHP = 300
|
||||
|
||||
@@ -3,7 +3,7 @@ module Dodge.Creature.ChooseTarget
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Base.Collide
|
||||
import Dodge.Creature.AlertLevel.Data
|
||||
import Dodge.Creature.Perception.Data
|
||||
|
||||
import Control.Lens
|
||||
--import qualified Data.IntMap.Strict as IM
|
||||
@@ -17,7 +17,8 @@ targetYouLOS cr w
|
||||
targetYouCognizant :: Creature -> World -> Maybe Creature
|
||||
targetYouCognizant cr w
|
||||
| hasLOS (_crPos cr) (_crPos $ you w) w
|
||||
&& isCog (cr ^? crAwarenessLevel . ix 0) = Just $ you w
|
||||
&& isCog (cr ^? crPerception . crAwarenessLevel . ix 0)
|
||||
= Just $ you w
|
||||
| otherwise = Nothing
|
||||
where
|
||||
isCog x = case x of
|
||||
|
||||
@@ -9,7 +9,7 @@ import Dodge.Creature.Test
|
||||
import Dodge.Creature.Volition
|
||||
import Dodge.Creature.Strategy
|
||||
import Dodge.Creature.ReaderUpdate
|
||||
import Dodge.Creature.AlertLevel
|
||||
import Dodge.Creature.Perception
|
||||
import Dodge.Creature.State
|
||||
import Dodge.Item.Weapon.Launcher
|
||||
import Dodge.Creature.Impulse
|
||||
@@ -30,7 +30,7 @@ launcherCrit = defaultCreature
|
||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0) [retreatFire])
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
]
|
||||
>=> basicPerceptionUpdateR [0]
|
||||
>=> perceptionUpdate [0]
|
||||
>=> doStrategyActionsR
|
||||
>=> reloadOverrideR
|
||||
>=> targetYouWhenCognizantR
|
||||
|
||||
@@ -11,7 +11,7 @@ import Dodge.Creature.Volition
|
||||
import Dodge.Creature.Strategy
|
||||
--import Dodge.Creature.ChooseTarget
|
||||
import Dodge.Creature.ReaderUpdate
|
||||
import Dodge.Creature.AlertLevel
|
||||
import Dodge.Creature.Perception
|
||||
import Dodge.Creature.State
|
||||
--import Dodge.Creature.State.Data
|
||||
import Dodge.Item.Weapon
|
||||
@@ -41,7 +41,7 @@ ltAutoCrit = defaultCreature
|
||||
)
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
]
|
||||
>=> basicPerceptionUpdateR [0]
|
||||
>=> perceptionUpdate [0]
|
||||
>=> doStrategyActionsR
|
||||
>=> reloadOverrideR
|
||||
>=> targetYouWhenCognizantR
|
||||
|
||||
@@ -8,9 +8,12 @@ module Dodge.Creature.Picture
|
||||
, picAtCrPosNoRot
|
||||
) where
|
||||
import Dodge.Data
|
||||
--import Dodge.Base
|
||||
--import Dodge.Creature.Stance.Data
|
||||
import Dodge.Creature.Perception.Data
|
||||
import Dodge.Creature.State.Data
|
||||
import Dodge.Creature.Stance.Data
|
||||
import Dodge.Creature.Memory.Data
|
||||
import Dodge.Creature.Test
|
||||
--import Dodge.Creature.AlertLevel.Data
|
||||
--import Dodge.Picture.Layer
|
||||
@@ -27,12 +30,13 @@ basicCrPict
|
||||
-> Creature
|
||||
-> World
|
||||
-> Picture
|
||||
basicCrPict col cr w = setLayer 0 $ pictures $
|
||||
basicCrPict col cr w = pictures $
|
||||
targetingPic ++
|
||||
[ tr . dm . rotdir $ scalp cr
|
||||
, tr . dm . rotdir $ upperBody col cr
|
||||
, tr . dm . rotmdir $ feet cr
|
||||
, tr . rotdir $ drawEquipment cr
|
||||
, creatureDisplayText w cr
|
||||
]
|
||||
where
|
||||
dm = damageMod cr
|
||||
@@ -44,6 +48,34 @@ basicCrPict col cr w = setLayer 0 $ pictures $
|
||||
. setDepth 1
|
||||
. color (greyN 0.3)
|
||||
|
||||
creatureDisplayText :: World -> Creature -> Picture
|
||||
creatureDisplayText w cr
|
||||
= setLayer 4
|
||||
. setDepth 50
|
||||
. translate x y
|
||||
. color white
|
||||
. rotate a
|
||||
. scale theScale theScale
|
||||
$ text $ creatureDisplayString cr
|
||||
where
|
||||
campos = _cameraViewFrom w
|
||||
theScale = 0.2 / _cameraZoom w
|
||||
cpos = _crPos cr
|
||||
v = cpos -.- campos
|
||||
a = argV v - 0.5 * pi
|
||||
(V2 x y) = campos +.+ v +.+ _crRad cr *.* normalizeV v
|
||||
|
||||
creatureDisplayString :: Creature -> String
|
||||
creatureDisplayString cr = show . _soundsToInvestigate $ _crMemory cr
|
||||
-- | isAsleep = "Z"
|
||||
-- | isSuspicious = "?"
|
||||
-- | otherwise = ""
|
||||
-- where
|
||||
-- isAsleep = _crAwakeLevel (_crPerception cr) == Asleep
|
||||
-- imAwarenesses = _crAwarenessLevel (_crPerception cr)
|
||||
-- isSuspicious = any f imAwarenesses && not (null imAwarenesses)
|
||||
-- f (Suspicious _) = True
|
||||
-- f _ = False
|
||||
damageMod :: Creature -> Picture -> Picture
|
||||
damageMod cr pic = piercingMod $ bluntScale pic
|
||||
where
|
||||
|
||||
@@ -11,7 +11,7 @@ import Dodge.Creature.Volition
|
||||
import Dodge.Creature.Strategy
|
||||
import Dodge.Creature.ReaderUpdate
|
||||
--import Dodge.Creature.ChooseTarget
|
||||
import Dodge.Creature.AlertLevel
|
||||
import Dodge.Creature.Perception
|
||||
import Dodge.Creature.State
|
||||
--import Dodge.Creature.State.Data
|
||||
import Dodge.Item.Weapon
|
||||
@@ -36,7 +36,7 @@ pistolCrit = defaultCreature
|
||||
[DoActionIf (not . crIsAiming) drawWeapon,chooseMovement cr w])
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
]
|
||||
>=> basicPerceptionUpdateR [0]
|
||||
>=> perceptionUpdate [0]
|
||||
>=> doStrategyActionsR
|
||||
>=> reloadOverrideR
|
||||
>=> targetYouWhenCognizantR
|
||||
|
||||
@@ -9,13 +9,15 @@ module Dodge.Creature.ReaderUpdate
|
||||
, overrideInternalRRR
|
||||
, goToTarget
|
||||
, flockACCR
|
||||
, setMvPos
|
||||
)
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Creature.Stance.Data
|
||||
import Dodge.Creature.Memory.Data
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Creature.Volition
|
||||
import Dodge.Creature.AlertLevel.Data
|
||||
import Dodge.Creature.Perception.Data
|
||||
import Dodge.Base
|
||||
import Geometry
|
||||
import FoldableHelp
|
||||
@@ -23,6 +25,8 @@ import FoldableHelp
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Control.Monad.Reader
|
||||
import Control.Lens
|
||||
import Control.Applicative
|
||||
import Data.Maybe
|
||||
|
||||
overrideMeleeCloseTargetR
|
||||
:: Creature
|
||||
@@ -40,6 +44,11 @@ tryMeleeAttack cr tcr
|
||||
where
|
||||
cpos = _crPos cr
|
||||
|
||||
setMvPos :: Creature -> Reader World Creature
|
||||
setMvPos cr = pure $ cr & crMvTarget .~ mpos
|
||||
where
|
||||
mpos = (_crPos <$> _crTarget cr) <|> listToMaybe (_soundsToInvestigate $ _crMemory cr)
|
||||
|
||||
setTargetMv
|
||||
:: (Creature -> Reader World (Maybe Creature)) -- ^ Function for determining target
|
||||
-> Creature
|
||||
@@ -126,6 +135,6 @@ listGuard ( (test,y):ps, z ) x
|
||||
listGuard (_,z) _ = z
|
||||
|
||||
targetYouWhenCognizantR :: Creature -> Reader World Creature
|
||||
targetYouWhenCognizantR cr = reader $ \w -> case cr ^? crAwarenessLevel . ix 0 of
|
||||
targetYouWhenCognizantR cr = reader $ \w -> case cr ^? crPerception . crAwarenessLevel . ix 0 of
|
||||
Just (Cognizant _) -> cr {_crTarget = Just $! _creatures w IM.! 0}
|
||||
_ -> cr & crTarget .~ Nothing
|
||||
|
||||
@@ -8,7 +8,7 @@ import Dodge.Creature.ReaderUpdate
|
||||
import Dodge.Creature.Strategy
|
||||
import Dodge.Creature.Action
|
||||
--import Dodge.Creature.ChooseTarget
|
||||
import Dodge.Creature.AlertLevel
|
||||
import Dodge.Creature.Perception
|
||||
--import Dodge.Creature.State
|
||||
--import Dodge.Creature.State.Data
|
||||
import Geometry.Data
|
||||
@@ -56,7 +56,7 @@ sentinelFireType f = performActionsR
|
||||
)
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
]
|
||||
>=> basicPerceptionUpdateR [0]
|
||||
>=> perceptionUpdate [0]
|
||||
>=> doStrategyActionsR
|
||||
>=> reloadOverrideR
|
||||
>=> targetYouWhenCognizantR
|
||||
@@ -77,7 +77,7 @@ sentinelExtraWatchUpdate
|
||||
sentinelExtraWatchUpdate xs = performActionsR
|
||||
>=> watchUpdateStratR
|
||||
( xs ++ [(crAwayFromPost, goToPostStrat)] )
|
||||
>=> basicPerceptionUpdateR [0]
|
||||
>=> perceptionUpdate [0]
|
||||
>=> doStrategyActionsR
|
||||
>=> targetYouWhenCognizantR
|
||||
>=> overrideInternalRRR
|
||||
|
||||
@@ -4,7 +4,7 @@ Deals with setting a target for creatures
|
||||
module Dodge.Creature.SetTarget
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Creature.AlertLevel.Data
|
||||
import Dodge.Creature.Perception.Data
|
||||
|
||||
import Control.Lens
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
@@ -13,7 +13,7 @@ targetYouWhenCognizant
|
||||
:: World
|
||||
-> Creature
|
||||
-> Creature
|
||||
targetYouWhenCognizant w cr = case cr ^? crAwarenessLevel . ix 0 of
|
||||
targetYouWhenCognizant w cr = case cr ^? crPerception . crAwarenessLevel . ix 0 of
|
||||
Just (Cognizant _) -> cr & crTarget ?~ _creatures w IM.! 0
|
||||
_ -> cr & crTarget .~ Nothing
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import Dodge.Creature.Volition
|
||||
import Dodge.Creature.Strategy
|
||||
import Dodge.Creature.ReaderUpdate
|
||||
--import Dodge.Creature.ChooseTarget
|
||||
import Dodge.Creature.AlertLevel
|
||||
import Dodge.Creature.Perception
|
||||
import Dodge.Creature.State
|
||||
--import Dodge.Creature.State.Data
|
||||
import Dodge.Item.Weapon
|
||||
@@ -42,7 +42,7 @@ spreadGunCrit = defaultCreature
|
||||
)
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
]
|
||||
>=> basicPerceptionUpdateR [0]
|
||||
>=> perceptionUpdate [0]
|
||||
>=> doStrategyActionsR
|
||||
>=> reloadOverrideR
|
||||
>=> targetYouWhenCognizantR
|
||||
|
||||
@@ -7,7 +7,7 @@ import Dodge.Default
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.Creature.Boid
|
||||
import Dodge.Creature.ReaderUpdate
|
||||
import Dodge.Creature.AlertLevel
|
||||
import Dodge.Creature.Perception
|
||||
import Dodge.Creature.Impulse
|
||||
import Dodge.Creature.State
|
||||
import Dodge.Creature.State.Data
|
||||
@@ -22,7 +22,7 @@ swarmCrit = defaultCreature
|
||||
{ _crUpdate = stateUpdate $ impulsiveAIR $
|
||||
flockToPointUsing (encircleDistP 100) (meleeHeadingMove 0.1 0.1 (pi/4) 3.9)
|
||||
>=> return . (crMeleeCooldown %~ max 0 . subtract 1)
|
||||
>=> basicPerceptionUpdateR [0]
|
||||
>=> perceptionUpdate [0]
|
||||
>=> doStrategyActionsR
|
||||
>=> targetYouWhenCognizantR
|
||||
-- , doStrategyActions
|
||||
|
||||
Reference in New Issue
Block a user