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.Data
|
||||||
import Dodge.Default
|
import Dodge.Default
|
||||||
import Dodge.Creature.State
|
import Dodge.Creature.State
|
||||||
|
import Dodge.Creature.ChainUpdates
|
||||||
import Dodge.Creature.ReaderUpdate
|
import Dodge.Creature.ReaderUpdate
|
||||||
import Dodge.Creature.Perception
|
import Dodge.Creature.Perception
|
||||||
import Dodge.Creature.Picture
|
import Dodge.Creature.Picture
|
||||||
@@ -15,21 +16,22 @@ 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
|
--import Control.Monad.Reader
|
||||||
|
|
||||||
armourChaseCrit :: Creature
|
armourChaseCrit :: Creature
|
||||||
armourChaseCrit = defaultCreature
|
armourChaseCrit = defaultCreature
|
||||||
{ _crUpdate = stateUpdate $ impulsiveAIR $
|
{ _crUpdate = stateUpdate' $ impulsiveAI $ chainCreatureUpdatesLR
|
||||||
watchUpdateStratR [] >=>
|
[ Left $ watchUpdateStrat []
|
||||||
doStrategyActionsR >=>
|
, Right doStrategyActions
|
||||||
performActionsR >=>
|
, Left performActions
|
||||||
targetYouWhenCognizantR >=>
|
, Left targetYouWhenCognizant
|
||||||
setTargetMv (pure . _targetCr . _crIntention) >=> -- should be able to remove this?
|
, Left $ setTargetMv' (\_ -> _targetCr . _crIntention)
|
||||||
flockACCR >=>
|
, Left flockACC
|
||||||
perceptionUpdate [0] >=>
|
, Left $ perceptionUpdate' [0]
|
||||||
goToTarget >=>
|
, Left goToTarget'
|
||||||
overrideMeleeCloseTargetR >=>
|
, Right overrideMeleeCloseTarget
|
||||||
return . (crMeleeCooldown %~ max 0 . subtract 1)
|
, Right (crMeleeCooldown %~ max 0 . subtract 1)
|
||||||
|
]
|
||||||
, _crHP = 300
|
, _crHP = 300
|
||||||
, _crPict = basicCrPict green
|
, _crPict = basicCrPict green
|
||||||
, _crInv = IM.fromList
|
, _crInv = IM.fromList
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ module Dodge.Creature.ReaderUpdate
|
|||||||
( doStrategyActionsR
|
( doStrategyActionsR
|
||||||
, doStrategyActions
|
, doStrategyActions
|
||||||
, setTargetMv
|
, setTargetMv
|
||||||
|
, setTargetMv'
|
||||||
, targetYouWhenCognizantR
|
, targetYouWhenCognizantR
|
||||||
, targetYouWhenCognizant
|
, targetYouWhenCognizant
|
||||||
, overrideMeleeCloseTargetR
|
, overrideMeleeCloseTargetR
|
||||||
|
, overrideMeleeCloseTarget
|
||||||
, watchUpdateStratR
|
, watchUpdateStratR
|
||||||
, watchUpdateStrat
|
, watchUpdateStrat
|
||||||
, reloadOverrideR
|
, reloadOverrideR
|
||||||
@@ -13,7 +15,9 @@ module Dodge.Creature.ReaderUpdate
|
|||||||
, overrideInternalRRR
|
, overrideInternalRRR
|
||||||
, overrideInternal
|
, overrideInternal
|
||||||
, goToTarget
|
, goToTarget
|
||||||
|
, goToTarget'
|
||||||
, flockACCR
|
, flockACCR
|
||||||
|
, flockACC
|
||||||
, setMvPos
|
, setMvPos
|
||||||
, setViewPos
|
, setViewPos
|
||||||
)
|
)
|
||||||
@@ -37,6 +41,9 @@ overrideMeleeCloseTargetR
|
|||||||
-> Reader World Creature
|
-> Reader World Creature
|
||||||
overrideMeleeCloseTargetR cr = return $ maybe cr (tryMeleeAttack cr) (_targetCr $ _crIntention cr)
|
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 :: Creature -> Creature -> Creature
|
||||||
tryMeleeAttack cr tcr
|
tryMeleeAttack cr tcr
|
||||||
| _crMeleeCooldown cr == 0
|
| _crMeleeCooldown cr == 0
|
||||||
@@ -70,6 +77,18 @@ setTargetMv targFunc cr = do
|
|||||||
case targ of
|
case targ of
|
||||||
Nothing -> pure cr
|
Nothing -> pure cr
|
||||||
Just crTarg -> pure $ cr & crIntention . mvToPoint ?~ _crPos crTarg
|
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 :: Creature -> Reader World Creature
|
||||||
flockACCR cr = do
|
flockACCR cr = do
|
||||||
case cr ^? crIntention . targetCr . _Just of
|
case cr ^? crIntention . targetCr . _Just of
|
||||||
@@ -93,12 +112,51 @@ flockACCR cr = do
|
|||||||
else negate r *.* horDir
|
else negate r *.* horDir
|
||||||
pure $ cr & crIntention . mvToPoint ?~ tpos +.+ horShift
|
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 :: Creature -> Reader World Creature
|
||||||
goToTarget cr = do
|
goToTarget cr = do
|
||||||
case cr ^? crIntention . mvToPoint . _Just of
|
case cr ^? crIntention . mvToPoint . _Just of
|
||||||
Just p -> pure $ cr & crActionPlan . crAction .~ [PathTo p]
|
Just p -> pure $ cr & crActionPlan . crAction .~ [PathTo p]
|
||||||
_ -> viewTarget cr
|
_ -> 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 :: Creature -> Reader World Creature
|
||||||
viewTarget cr = do
|
viewTarget cr = do
|
||||||
w <- ask
|
w <- ask
|
||||||
|
|||||||
Reference in New Issue
Block a user