Remove Reader from chaseCrit

This commit is contained in:
2021-12-11 19:07:14 +00:00
parent e698695842
commit ab7a503515
3 changed files with 33 additions and 34 deletions
+1 -2
View File
@@ -16,7 +16,6 @@ import Picture
import qualified Data.IntMap.Strict as IM
import Control.Lens
--import Control.Monad.Reader
armourChaseCrit :: Creature
armourChaseCrit = defaultCreature
@@ -25,7 +24,7 @@ armourChaseCrit = defaultCreature
, Right doStrategyActions
, Left performActions
, Left targetYouWhenCognizant
, Left $ setTargetMv' (\_ -> _targetCr . _crIntention)
, Left $ setTargetMv (\_ -> _targetCr . _crIntention)
, Left flockACC
, Left $ perceptionUpdate' [0]
, Left goToTarget'
+12 -12
View File
@@ -5,6 +5,7 @@ module Dodge.Creature.ChaseCrit
import Dodge.Data
import Dodge.Default
import Dodge.Creature.Picture
import Dodge.Creature.ChainUpdates
import Dodge.Creature.ReaderUpdate
import Dodge.Creature.Impulse
import Dodge.Creature.Action
@@ -20,7 +21,6 @@ import Picture
--import Data.Maybe
import qualified Data.IntMap.Strict as IM
import Control.Lens
import Control.Monad
--import System.Random
smallChaseCrit :: Creature
@@ -33,17 +33,17 @@ smallChaseCrit = chaseCrit
}
chaseCrit :: Creature
chaseCrit = defaultCreature
{ _crUpdate = stateUpdate $ --dummyUpdate
impulsiveAIR $
doStrategyActionsR >=>
performActionsR >=>
overrideMeleeCloseTargetR >=>
setViewPos >=>
setMvPos >=>
goToTarget >=>
perceptionUpdate [0] >=>
targetYouWhenCognizantR >=>
return . (crMeleeCooldown %~ max 0 . subtract 1)
{ _crUpdate = stateUpdate' $ impulsiveAI $ chainCreatureUpdatesLR
[ Right doStrategyActions
, Left performActions
, Right overrideMeleeCloseTarget
, Right setViewPos'
, Right setMvPos'
, Left goToTarget'
, Left $ perceptionUpdate' [0]
, Left targetYouWhenCognizant
, Right (crMeleeCooldown %~ max 0 . subtract 1)
]
, _crHP = 300
, _crPict = basicCrPict green
, _crInv = IM.fromList [(0,medkit 200)]
+20 -20
View File
@@ -3,7 +3,6 @@ module Dodge.Creature.ReaderUpdate
( doStrategyActionsR
, doStrategyActions
, setTargetMv
, setTargetMv'
, targetYouWhenCognizantR
, targetYouWhenCognizant
, overrideMeleeCloseTargetR
@@ -19,7 +18,9 @@ module Dodge.Creature.ReaderUpdate
, flockACCR
, flockACC
, setMvPos
, setMvPos'
, setViewPos
, setViewPos'
)
where
import Dodge.Data
@@ -62,33 +63,32 @@ setMvPos cr = pure $ cr & crIntention . mvToPoint .~ mpos
mpos = (_crPos <$> _targetCr int)
<|> _mvToPoint int
-- <|> listToMaybe (_soundsToInvestigate $ _crMemory cr)
--
setMvPos' :: Creature -> Creature
setMvPos' cr = cr & crIntention . mvToPoint .~ mpos
where
int = _crIntention cr
mpos = (_crPos <$> _targetCr int)
<|> _mvToPoint int
-- <|> listToMaybe (_soundsToInvestigate $ _crMemory cr)
setViewPos :: Creature -> Reader World Creature
setViewPos cr = pure $ cr & crIntention . viewPoint %~ (<|> mpos)
where
mpos = listToMaybe (_soundsToInvestigate $ _crMemory cr)
setTargetMv
:: (Creature -> Reader World (Maybe Creature)) -- ^ Function for determining target
-> Creature
-> Reader World Creature
setTargetMv targFunc cr = do
targ <- targFunc cr
case targ of
Nothing -> pure cr
Just crTarg -> pure $ cr & crIntention . mvToPoint ?~ _crPos crTarg
setViewPos' :: Creature -> Creature
setViewPos' cr = cr & crIntention . viewPoint %~ (<|> mpos)
where
mpos = listToMaybe (_soundsToInvestigate $ _crMemory cr)
setTargetMv'
:: (World -> Creature -> Maybe Creature) -- ^ Function for determining target
-> World
-> Creature
-> Creature
setTargetMv' targFunc w cr = maybe cr (\ctarg -> cr & crIntention . mvToPoint ?~ _crPos ctarg)
setTargetMv :: (World -> Creature -> Maybe Creature) -- ^ Function for determining target
-> World -> Creature -> Creature
setTargetMv targFunc w cr = maybe
cr
(\ctarg -> cr & crIntention . mvToPoint ?~ _crPos ctarg)
(targFunc w cr)
-- targ <- targFunc cr
-- case targ of
-- Nothing -> pure cr
-- Just crTarg -> pure $ cr & crIntention . mvToPoint ?~ _crPos crTarg
flockACCR :: Creature -> Reader World Creature
flockACCR cr = do
case cr ^? crIntention . targetCr . _Just of