Remove Reader from launcherCrit

This commit is contained in:
2021-12-11 19:20:09 +00:00
parent ab7a503515
commit 37b81c2967
4 changed files with 25 additions and 58 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ armourChaseCrit = defaultCreature
, Left $ setTargetMv (\_ -> _targetCr . _crIntention) , Left $ setTargetMv (\_ -> _targetCr . _crIntention)
, Left flockACC , Left flockACC
, Left $ perceptionUpdate' [0] , Left $ perceptionUpdate' [0]
, Left goToTarget' , Left goToTarget
, Right overrideMeleeCloseTarget , Right overrideMeleeCloseTarget
, Right (crMeleeCooldown %~ max 0 . subtract 1) , Right (crMeleeCooldown %~ max 0 . subtract 1)
] ]
+3 -3
View File
@@ -37,9 +37,9 @@ chaseCrit = defaultCreature
[ Right doStrategyActions [ Right doStrategyActions
, Left performActions , Left performActions
, Right overrideMeleeCloseTarget , Right overrideMeleeCloseTarget
, Right setViewPos' , Right setViewPos
, Right setMvPos' , Right setMvPos
, Left goToTarget' , Left goToTarget
, Left $ perceptionUpdate' [0] , Left $ perceptionUpdate' [0]
, Left targetYouWhenCognizant , Left targetYouWhenCognizant
, Right (crMeleeCooldown %~ max 0 . subtract 1) , Right (crMeleeCooldown %~ max 0 . subtract 1)
+12 -11
View File
@@ -5,6 +5,7 @@ module Dodge.Creature.LauncherCrit
import Dodge.Data import Dodge.Data
import Dodge.Default import Dodge.Default
import Dodge.Creature.Picture import Dodge.Creature.Picture
import Dodge.Creature.ChainUpdates
import Dodge.Creature.Test import Dodge.Creature.Test
import Dodge.Creature.Volition import Dodge.Creature.Volition
import Dodge.Creature.Strategy import Dodge.Creature.Strategy
@@ -19,24 +20,24 @@ import Picture
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
import Control.Lens import Control.Lens
import Control.Monad.Reader
launcherCrit :: Creature launcherCrit :: Creature
launcherCrit = defaultCreature launcherCrit = defaultCreature
{ _crPict = basicCrPict red { _crPict = basicCrPict red
, _crUpdate = stateUpdate $ impulsiveAIR $ , _crUpdate = stateUpdate' $ impulsiveAI $ chainCreatureUpdatesLR
performActionsR [ Left performActions
>=> watchUpdateStratR , Left $ watchUpdateStrat
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0) [retreatFire]) [ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0) [retreatFire])
, (crAwayFromPost, goToPostStrat) , (crAwayFromPost, goToPostStrat)
] ]
>=> perceptionUpdate [0] , Left $ perceptionUpdate' [0]
>=> doStrategyActionsR , Right doStrategyActions
>=> reloadOverrideR , Right reloadOverride
>=> targetYouWhenCognizantR , Left targetYouWhenCognizant
>=> overrideInternalRRR , Right $ overrideInternal
(\cr -> (&&) <$> crHasTargetR cr <*> crStratConMatchesR (GetTo (V2 0 0)) cr) (\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
(pure . (crActionPlan . crStrategy .~ WatchAndWait)) (crActionPlan . crStrategy .~ WatchAndWait)
]
, _crActionPlan = ActionPlan , _crActionPlan = ActionPlan
{ _crImpulse = [] { _crImpulse = []
, _crAction = [] , _crAction = []
+9 -43
View File
@@ -14,13 +14,10 @@ module Dodge.Creature.ReaderUpdate
, overrideInternalRRR , overrideInternalRRR
, overrideInternal , overrideInternal
, goToTarget , goToTarget
, goToTarget'
, flockACCR , flockACCR
, flockACC , flockACC
, setMvPos , setMvPos
, setMvPos'
, setViewPos , setViewPos
, setViewPos'
) )
where where
import Dodge.Data import Dodge.Data
@@ -56,29 +53,16 @@ tryMeleeAttack cr tcr
where where
cpos = _crPos cr cpos = _crPos cr
setMvPos :: Creature -> Reader World Creature setMvPos :: Creature -> Creature
setMvPos cr = pure $ cr & crIntention . mvToPoint .~ mpos setMvPos cr = cr & crIntention . mvToPoint .~ mpos
where
int = _crIntention cr
mpos = (_crPos <$> _targetCr int)
<|> _mvToPoint int
-- <|> listToMaybe (_soundsToInvestigate $ _crMemory cr)
--
setMvPos' :: Creature -> Creature
setMvPos' cr = cr & crIntention . mvToPoint .~ mpos
where where
int = _crIntention cr int = _crIntention cr
mpos = (_crPos <$> _targetCr int) mpos = (_crPos <$> _targetCr int)
<|> _mvToPoint int <|> _mvToPoint int
-- <|> listToMaybe (_soundsToInvestigate $ _crMemory cr) -- <|> listToMaybe (_soundsToInvestigate $ _crMemory cr)
setViewPos :: Creature -> Reader World Creature setViewPos :: Creature -> Creature
setViewPos cr = pure $ cr & crIntention . viewPoint %~ (<|> mpos) setViewPos cr = cr & crIntention . viewPoint %~ (<|> mpos)
where
mpos = listToMaybe (_soundsToInvestigate $ _crMemory cr)
setViewPos' :: Creature -> Creature
setViewPos' cr = cr & crIntention . viewPoint %~ (<|> mpos)
where where
mpos = listToMaybe (_soundsToInvestigate $ _crMemory cr) mpos = listToMaybe (_soundsToInvestigate $ _crMemory cr)
@@ -134,20 +118,14 @@ flockACC w cr = case cr ^? crIntention . targetCr . _Just of
else negate r *.* horDir else negate r *.* horDir
in cr & crIntention . mvToPoint ?~ tpos +.+ horShift in cr & crIntention . mvToPoint ?~ tpos +.+ horShift
goToTarget :: Creature -> Reader World Creature goToTarget :: World -> Creature -> Creature
goToTarget cr = do goToTarget w cr =
case cr ^? crIntention . mvToPoint . _Just of
Just p -> pure $ cr & crActionPlan . crAction .~ [PathTo p]
_ -> viewTarget cr
goToTarget' :: World -> Creature -> Creature
goToTarget' w cr =
case cr ^? crIntention . mvToPoint . _Just of case cr ^? crIntention . mvToPoint . _Just of
Just p -> cr & crActionPlan . crAction .~ [PathTo p] Just p -> cr & crActionPlan . crAction .~ [PathTo p]
_ -> viewTarget' w cr _ -> viewTarget w cr
viewTarget' :: World -> Creature -> Creature viewTarget :: World -> Creature -> Creature
viewTarget' w cr = do viewTarget w cr = do
case cr ^? crIntention . viewPoint . _Just of case cr ^? crIntention . viewPoint . _Just of
Just p | hasLOSIndirect p (_crPos cr) w -> cr' Just p | hasLOSIndirect p (_crPos cr) w -> cr'
& crActionPlan . crAction %~ replaceNullWith (TurnToA p) & crActionPlan . crAction %~ replaceNullWith (TurnToA p)
@@ -157,18 +135,6 @@ viewTarget' w cr = do
where where
cr' = cr & crPerception . crAwakeLevel .~ Vigilant cr' = cr & crPerception . crAwakeLevel .~ Vigilant
viewTarget :: Creature -> Reader World Creature
viewTarget cr = do
w <- ask
case cr ^? crIntention . viewPoint . _Just of
Just p | hasLOSIndirect p (_crPos cr) w -> pure $ cr'
& crActionPlan . crAction %~ replaceNullWith (TurnToA p)
& crIntention . viewPoint .~ Nothing
| otherwise -> pure $ cr' & crActionPlan . crAction %~ replaceNullWith (PathTo p)
Nothing -> pure $ cr & crPerception . crAwakeLevel .~ Lethargic
where
cr' = cr & crPerception . crAwakeLevel .~ Vigilant
replaceNullWith :: a -> [a] -> [a] replaceNullWith :: a -> [a] -> [a]
replaceNullWith x [] = [x] replaceNullWith x [] = [x]
replaceNullWith _ xs = xs replaceNullWith _ xs = xs