Start removing Reader monad from internal creature update

This commit is contained in:
2021-12-11 18:24:53 +00:00
parent cdeb3dfa67
commit 154abf0bad
4 changed files with 25 additions and 56 deletions
+18 -50
View File
@@ -1,10 +1,10 @@
module Dodge.Creature.SentinelAI
( sentinelAI
, sentinelFireType
, sentinelFireTypeR
, sentinelExtraWatchUpdate
) where
import Dodge.Data
import Dodge.Creature.ChainUpdates
import Dodge.Base.Collide
import Dodge.Creature.Test
import Dodge.Creature.Volition
@@ -16,11 +16,10 @@ import Geometry.Data
import Data.Maybe
import Control.Lens
import Control.Monad
import Control.Monad.Reader
sentinelAI :: Creature -> Reader World Creature
sentinelAI = sentinelExtraWatchUpdate
sentinelAI :: World -> Creature -> Creature
sentinelAI w = reloadOverride .
sentinelExtraWatchUpdate
[ (crHasTargetLOS
, \ _ cr -> StrategyActions (ShootAt (fromJust $ tcid cr))
[ DoActionIf
@@ -35,22 +34,15 @@ sentinelAI = sentinelExtraWatchUpdate
]
)
]
>=> reloadOverrideR
w
where
advanceShoot = DoImpulses [UseItem, MoveForward 3]
tcid cr = _crID <$> _targetCr (_crIntention cr)
lostest (w,cr) = maybe False (\cid -> canSee (_crID cr) cid w) (tcid cr)
lostest (w',cr) = maybe False (\cid -> canSee (_crID cr) cid w') (tcid cr)
--chainCreatureUpdates :: [World -> Creature -> Creature] -> World -> Creature -> Creature
--chainCreatureUpdates ls w cr = foldr (\f -> f w) cr ls
chainCreatureUpdatesLR
:: [Either (World -> Creature -> Creature) (Creature -> Creature)]
-> World -> Creature -> Creature
chainCreatureUpdatesLR ls w cr = foldr unf cr ls
where
unf (Left g) = g w
unf (Right g) = g
sentinelFireType :: (Int -> Action) -> World -> Creature -> Creature
sentinelFireType f = chainCreatureUpdatesLR
@@ -79,46 +71,22 @@ sentinelFireType f = chainCreatureUpdatesLR
, _targetSeenAt = V2 0 0 -- hack
}
sentinelFireTypeR
:: (Int -> Action)
-> Creature
-> Reader World Creature
sentinelFireTypeR f = performActionsR
>=> watchUpdateStratR
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
[ drawwp `DoActionThen` f 0 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
, aiming
]
)
, (crAwayFromPost, goToPostStrat)
]
>=> perceptionUpdate [0]
>=> doStrategyActionsR
>=> reloadOverrideR
>=> targetYouWhenCognizantR
>=> overrideInternalRRR
(\cr -> (&&) <$> crHasTargetR cr <*> crStratConMatchesR (GetTo (V2 0 0)) cr)
(pure . (crActionPlan . crStrategy .~ WatchAndWait))
where
drawwp = DoActionIfElse NoAction crIsAiming (DoActionThen drawWeapon (WaitThen 50 NoAction))
aiming = AimAt
{ _targetID = 0
, _targetSeenAt = V2 0 0 -- hack
}
sentinelExtraWatchUpdate
:: [((World, Creature) -> Bool , World -> Creature -> Strategy)]
-> World
-> Creature
-> Reader World Creature
sentinelExtraWatchUpdate xs = performActionsR
>=> watchUpdateStratR
-> Creature
sentinelExtraWatchUpdate xs = chainCreatureUpdatesLR
[ Left performActions
, Left $ watchUpdateStrat
( xs ++ [(crAwayFromPost, goToPostStrat)] )
>=> perceptionUpdate [0]
>=> doStrategyActionsR
>=> targetYouWhenCognizantR
>=> overrideInternalRRR
(\cr -> (&&) <$> crHasTargetR cr <*> crStratConMatchesR (GetTo (V2 0 0)) cr)
(pure . (crActionPlan . crStrategy .~ WatchAndWait))
, Left $ perceptionUpdate' [0]
, Right doStrategyActions
, Left targetYouWhenCognizant
, Right $ overrideInternal
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
(crActionPlan . crStrategy .~ WatchAndWait)
]
--shootAtAdvance :: Int -> [Action]
--shootAtAdvance tcid =