Remove Reader monad from armour chase crit's ai
This commit is contained in:
@@ -4,6 +4,7 @@ module Dodge.Creature.ArmourChase
|
||||
import Dodge.Data
|
||||
import Dodge.Default
|
||||
import Dodge.Creature.State
|
||||
import Dodge.Creature.ChainUpdates
|
||||
import Dodge.Creature.ReaderUpdate
|
||||
import Dodge.Creature.Perception
|
||||
import Dodge.Creature.Picture
|
||||
@@ -15,21 +16,22 @@ import Picture
|
||||
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
import Control.Monad.Reader
|
||||
--import Control.Monad.Reader
|
||||
|
||||
armourChaseCrit :: Creature
|
||||
armourChaseCrit = defaultCreature
|
||||
{ _crUpdate = stateUpdate $ impulsiveAIR $
|
||||
watchUpdateStratR [] >=>
|
||||
doStrategyActionsR >=>
|
||||
performActionsR >=>
|
||||
targetYouWhenCognizantR >=>
|
||||
setTargetMv (pure . _targetCr . _crIntention) >=> -- should be able to remove this?
|
||||
flockACCR >=>
|
||||
perceptionUpdate [0] >=>
|
||||
goToTarget >=>
|
||||
overrideMeleeCloseTargetR >=>
|
||||
return . (crMeleeCooldown %~ max 0 . subtract 1)
|
||||
{ _crUpdate = stateUpdate' $ impulsiveAI $ chainCreatureUpdatesLR
|
||||
[ Left $ watchUpdateStrat []
|
||||
, Right doStrategyActions
|
||||
, Left performActions
|
||||
, Left targetYouWhenCognizant
|
||||
, Left $ setTargetMv' (\_ -> _targetCr . _crIntention)
|
||||
, Left flockACC
|
||||
, Left $ perceptionUpdate' [0]
|
||||
, Left goToTarget'
|
||||
, Right overrideMeleeCloseTarget
|
||||
, Right (crMeleeCooldown %~ max 0 . subtract 1)
|
||||
]
|
||||
, _crHP = 300
|
||||
, _crPict = basicCrPict green
|
||||
, _crInv = IM.fromList
|
||||
|
||||
@@ -3,9 +3,11 @@ module Dodge.Creature.ReaderUpdate
|
||||
( doStrategyActionsR
|
||||
, doStrategyActions
|
||||
, setTargetMv
|
||||
, setTargetMv'
|
||||
, targetYouWhenCognizantR
|
||||
, targetYouWhenCognizant
|
||||
, overrideMeleeCloseTargetR
|
||||
, overrideMeleeCloseTarget
|
||||
, watchUpdateStratR
|
||||
, watchUpdateStrat
|
||||
, reloadOverrideR
|
||||
@@ -13,7 +15,9 @@ module Dodge.Creature.ReaderUpdate
|
||||
, overrideInternalRRR
|
||||
, overrideInternal
|
||||
, goToTarget
|
||||
, goToTarget'
|
||||
, flockACCR
|
||||
, flockACC
|
||||
, setMvPos
|
||||
, setViewPos
|
||||
)
|
||||
@@ -37,6 +41,9 @@ overrideMeleeCloseTargetR
|
||||
-> Reader World Creature
|
||||
overrideMeleeCloseTargetR cr = return $ maybe cr (tryMeleeAttack cr) (_targetCr $ _crIntention cr)
|
||||
|
||||
overrideMeleeCloseTarget :: Creature -> Creature
|
||||
overrideMeleeCloseTarget cr = maybe cr (tryMeleeAttack cr) (_targetCr $ _crIntention cr)
|
||||
|
||||
tryMeleeAttack :: Creature -> Creature -> Creature
|
||||
tryMeleeAttack cr tcr
|
||||
| _crMeleeCooldown cr == 0
|
||||
@@ -70,6 +77,18 @@ setTargetMv targFunc cr = do
|
||||
case targ of
|
||||
Nothing -> pure cr
|
||||
Just crTarg -> pure $ cr & crIntention . mvToPoint ?~ _crPos crTarg
|
||||
|
||||
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
|
||||
@@ -93,12 +112,51 @@ flockACCR cr = do
|
||||
else negate r *.* horDir
|
||||
pure $ cr & crIntention . mvToPoint ?~ tpos +.+ horShift
|
||||
|
||||
-- fugly
|
||||
flockACC :: World -> Creature -> Creature
|
||||
flockACC w cr = case cr ^? crIntention . targetCr . _Just of
|
||||
Nothing -> cr
|
||||
Just tcr ->
|
||||
let tpos = _crPos tcr
|
||||
cpos = _crPos cr
|
||||
isFarACC cr' = _crGroup cr' == _crGroup cr
|
||||
&& _crID cr' /= _crID cr
|
||||
&& dist (_crPos cr') tpos > dist cpos tpos
|
||||
nearACCs = IM.filter isFarACC $ creaturesNearPointI 5 cpos w
|
||||
macr = safeMinimumOn (dist cpos . _crPos) nearACCs
|
||||
in case macr of
|
||||
Nothing -> cr
|
||||
Just acr ->
|
||||
let r = _crRad acr + _crRad cr + 10
|
||||
horDir = normalizeV (vNormal (cpos -.- tpos))
|
||||
horShift = if isLHS tpos cpos (_crPos acr)
|
||||
then r *.* horDir
|
||||
else negate r *.* horDir
|
||||
in cr & crIntention . mvToPoint ?~ tpos +.+ horShift
|
||||
|
||||
goToTarget :: Creature -> Reader World Creature
|
||||
goToTarget cr = do
|
||||
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
|
||||
Just p -> cr & crActionPlan . crAction .~ [PathTo p]
|
||||
_ -> viewTarget' w cr
|
||||
|
||||
viewTarget' :: World -> Creature -> Creature
|
||||
viewTarget' w cr = do
|
||||
case cr ^? crIntention . viewPoint . _Just of
|
||||
Just p | hasLOSIndirect p (_crPos cr) w -> cr'
|
||||
& crActionPlan . crAction %~ replaceNullWith (TurnToA p)
|
||||
& crIntention . viewPoint .~ Nothing
|
||||
| otherwise -> cr' & crActionPlan . crAction %~ replaceNullWith (PathTo p)
|
||||
Nothing -> cr & crPerception . crAwakeLevel .~ Lethargic
|
||||
where
|
||||
cr' = cr & crPerception . crAwakeLevel .~ Vigilant
|
||||
|
||||
viewTarget :: Creature -> Reader World Creature
|
||||
viewTarget cr = do
|
||||
w <- ask
|
||||
|
||||
Reference in New Issue
Block a user