Cleanup, remove Reader monad from Creature.Test
This commit is contained in:
@@ -36,7 +36,7 @@ launcherCrit = defaultCreature
|
|||||||
, const reloadOverride
|
, const reloadOverride
|
||||||
, targetYouWhenCognizant
|
, targetYouWhenCognizant
|
||||||
, const $ overrideInternal
|
, const $ overrideInternal
|
||||||
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
(\cr -> crHasTarget cr && crStratConMatches (GetTo (V2 0 0)) cr)
|
||||||
(crActionPlan . crStrategy .~ WatchAndWait)
|
(crActionPlan . crStrategy .~ WatchAndWait)
|
||||||
]
|
]
|
||||||
, _crActionPlan = ActionPlan
|
, _crActionPlan = ActionPlan
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ ltAutoCrit = defaultCreature
|
|||||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||||
[DoActionIf (const $ not . crIsAiming) drawWeapon
|
[DoActionIf (const $ not . crIsAiming) drawWeapon
|
||||||
,DoActionThen
|
,DoActionThen
|
||||||
(DoActionWhile crHasTargetLOS' $ ArbitraryAction chooseMovement)
|
(DoActionWhile crHasTargetLOS $ ArbitraryAction chooseMovement)
|
||||||
(DoImpulses [ChangeStrategy WatchAndWait])
|
(DoImpulses [ChangeStrategy WatchAndWait])
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@@ -40,7 +40,7 @@ ltAutoCrit = defaultCreature
|
|||||||
, const reloadOverride
|
, const reloadOverride
|
||||||
, targetYouWhenCognizant
|
, targetYouWhenCognizant
|
||||||
, const $ overrideInternal
|
, const $ overrideInternal
|
||||||
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
(\cr -> crHasTarget cr && crStratConMatches (GetTo (V2 0 0)) cr)
|
||||||
(crActionPlan . crStrategy .~ WatchAndWait)
|
(crActionPlan . crStrategy .~ WatchAndWait)
|
||||||
]
|
]
|
||||||
, _crActionPlan = ActionPlan
|
, _crActionPlan = ActionPlan
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ pistolCrit = defaultCreature
|
|||||||
, const reloadOverride
|
, const reloadOverride
|
||||||
, targetYouWhenCognizant
|
, targetYouWhenCognizant
|
||||||
, const $ overrideInternal
|
, const $ overrideInternal
|
||||||
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
(\cr -> crHasTarget cr && crStratConMatches (GetTo (V2 0 0)) cr)
|
||||||
(crActionPlan . crStrategy .~ WatchAndWait)
|
(crActionPlan . crStrategy .~ WatchAndWait)
|
||||||
]
|
]
|
||||||
, _crActionPlan = ActionPlan
|
, _crActionPlan = ActionPlan
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ sentinelFireType f = chainCreatureUpdates
|
|||||||
, const reloadOverride
|
, const reloadOverride
|
||||||
, targetYouWhenCognizant
|
, targetYouWhenCognizant
|
||||||
, const $ overrideInternal
|
, const $ overrideInternal
|
||||||
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
(\cr -> crHasTarget cr && crStratConMatches (GetTo (V2 0 0)) cr)
|
||||||
(crActionPlan . crStrategy .~ WatchAndWait)
|
(crActionPlan . crStrategy .~ WatchAndWait)
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
@@ -84,7 +84,7 @@ sentinelExtraWatchUpdate xs = chainCreatureUpdates
|
|||||||
, const doStrategyActions
|
, const doStrategyActions
|
||||||
, targetYouWhenCognizant
|
, targetYouWhenCognizant
|
||||||
, const $ overrideInternal
|
, const $ overrideInternal
|
||||||
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
(\cr -> crHasTarget cr && crStratConMatches (GetTo (V2 0 0)) cr)
|
||||||
(crActionPlan . crStrategy .~ WatchAndWait)
|
(crActionPlan . crStrategy .~ WatchAndWait)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ spreadGunCrit = defaultCreature
|
|||||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||||
[DoActionIf (const $ not . crIsAiming) drawWeapon
|
[DoActionIf (const $ not . crIsAiming) drawWeapon
|
||||||
,DoActionThen
|
,DoActionThen
|
||||||
(DoActionWhile crHasTargetLOS' $ ArbitraryAction chooseMovement)
|
(DoActionWhile crHasTargetLOS $ ArbitraryAction chooseMovement)
|
||||||
(DoImpulses [ChangeStrategy WatchAndWait])
|
(DoImpulses [ChangeStrategy WatchAndWait])
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@@ -42,7 +42,7 @@ spreadGunCrit = defaultCreature
|
|||||||
,const reloadOverride
|
,const reloadOverride
|
||||||
,targetYouWhenCognizant
|
,targetYouWhenCognizant
|
||||||
,const $ overrideInternal
|
,const $ overrideInternal
|
||||||
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
(\cr -> crHasTarget cr && crStratConMatches (GetTo (V2 0 0)) cr)
|
||||||
(\ cr -> cr & crActionPlan . crStrategy .~ WatchAndWait)
|
(\ cr -> cr & crActionPlan . crStrategy .~ WatchAndWait)
|
||||||
]
|
]
|
||||||
, _crActionPlan = ActionPlan
|
, _crActionPlan = ActionPlan
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import Data.List (find)
|
|||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import qualified Data.IntMap.Strict as IM
|
import qualified Data.IntMap.Strict as IM
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Control.Monad.Reader
|
|
||||||
|
|
||||||
andTest :: (a -> Bool) -> (a -> Bool) -> a -> Bool
|
andTest :: (a -> Bool) -> (a -> Bool) -> a -> Bool
|
||||||
andTest f g a = f a && g a
|
andTest f g a = f a && g a
|
||||||
@@ -28,63 +27,30 @@ crIsReloading cr = case cr ^? crInv . ix (_crInvSel cr) . itConsumption . reload
|
|||||||
Just t -> t > 0
|
Just t -> t > 0
|
||||||
_ -> False
|
_ -> False
|
||||||
|
|
||||||
crIsReloadingR :: Creature -> Reader World Bool
|
|
||||||
crIsReloadingR cr = return $ case cr ^? crInv . ix (_crInvSel cr) . itConsumption . reloadState . _Just' of
|
|
||||||
Just t -> t > 0
|
|
||||||
_ -> False
|
|
||||||
|
|
||||||
crCanSeeCr :: Creature -> (World, Creature) -> Bool
|
crCanSeeCr :: Creature -> (World, Creature) -> Bool
|
||||||
crCanSeeCr tcr (w,cr) = hasLOS (_crPos cr) (_crPos tcr) w
|
crCanSeeCr tcr (w,cr) = hasLOS (_crPos cr) (_crPos tcr) w
|
||||||
|
|
||||||
crCanSeeR :: Creature -> Creature -> Reader World Bool
|
|
||||||
crCanSeeR tcr cr = reader $ \w -> hasLOS (_crPos cr) (_crPos tcr) w
|
|
||||||
|
|
||||||
crCanSeeCID :: Int -> (World, Creature) -> Bool
|
crCanSeeCID :: Int -> (World, Creature) -> Bool
|
||||||
crCanSeeCID cid (w,cr) = hasLOS (_crPos cr) (_crPos $ _creatures w IM.! cid) w
|
crCanSeeCID cid (w,cr) = hasLOS (_crPos cr) (_crPos $ _creatures w IM.! cid) w
|
||||||
|
|
||||||
crCanSeeCIDR :: Int -> Creature -> Reader World Bool
|
|
||||||
crCanSeeCIDR cid cr = reader $ \w -> hasLOS (_crPos cr) (_crPos $ _creatures w IM.! cid) w
|
|
||||||
|
|
||||||
crIsAiming :: Creature -> Bool
|
crIsAiming :: Creature -> Bool
|
||||||
crIsAiming cr = _posture (_crStance cr) == Aiming
|
crIsAiming cr = _posture (_crStance cr) == Aiming
|
||||||
|
|
||||||
crHasTarget' :: Creature -> Bool
|
crHasTarget :: Creature -> Bool
|
||||||
crHasTarget' cr = isJust $ cr ^? crIntention . targetCr . _Just
|
crHasTarget cr = isJust $ cr ^? crIntention . targetCr . _Just
|
||||||
|
|
||||||
|
|
||||||
crHasTargetLOS :: World -> Creature -> Bool
|
crHasTargetLOS :: World -> Creature -> Bool
|
||||||
crHasTargetLOS w cr = case cr ^? crIntention . targetCr . _Just of
|
crHasTargetLOS w cr = case cr ^? crIntention . targetCr . _Just of
|
||||||
Just i -> crCanSeeCr i (w,cr)
|
Just i -> crCanSeeCr i (w,cr)
|
||||||
Nothing -> False
|
Nothing -> False
|
||||||
|
|
||||||
crHasTargetLOS' :: World -> Creature -> Bool
|
|
||||||
crHasTargetLOS' w cr = case cr ^? crIntention . targetCr . _Just of
|
|
||||||
Just i -> crCanSeeCr i (w,cr)
|
|
||||||
Nothing -> False
|
|
||||||
|
|
||||||
crHasTargetLOSR :: Creature -> Reader World Bool
|
|
||||||
crHasTargetLOSR cr = reader $ \w -> case cr ^? crIntention . targetCr . _Just of
|
|
||||||
Just i -> crCanSeeCr i (w,cr)
|
|
||||||
Nothing -> False
|
|
||||||
|
|
||||||
crSafeDistFromTarg :: Float -> Creature -> Bool
|
crSafeDistFromTarg :: Float -> Creature -> Bool
|
||||||
crSafeDistFromTarg d cr = case cr ^? crIntention . targetCr . _Just of
|
crSafeDistFromTarg d cr = case cr ^? crIntention . targetCr . _Just of
|
||||||
Just tcr -> dist (_crPos cr) (_crPos tcr) > d
|
Just tcr -> dist (_crPos cr) (_crPos tcr) > d
|
||||||
Nothing -> True
|
Nothing -> True
|
||||||
|
|
||||||
crSafeDistFromTargR :: Float -> Creature -> Reader World Bool
|
crStratConMatches :: Strategy -> Creature -> Bool
|
||||||
crSafeDistFromTargR d cr = return $ case cr ^? crIntention . targetCr . _Just of
|
crStratConMatches strat cr = eqConstr strat (_crStrategy $ _crActionPlan cr)
|
||||||
Just tcr -> dist (_crPos cr) (_crPos tcr) > d
|
|
||||||
Nothing -> True
|
|
||||||
|
|
||||||
crStratConMatches :: Strategy -> (World,Creature) -> Bool
|
|
||||||
crStratConMatches strat (_,cr) = eqConstr strat (_crStrategy $ _crActionPlan cr)
|
|
||||||
|
|
||||||
crStratConMatches' :: Strategy -> Creature -> Bool
|
|
||||||
crStratConMatches' strat cr = eqConstr strat (_crStrategy $ _crActionPlan cr)
|
|
||||||
|
|
||||||
crStratConMatchesR :: Strategy -> Creature -> Reader World Bool
|
|
||||||
crStratConMatchesR strat cr = return $ eqConstr strat (_crStrategy $ _crActionPlan cr)
|
|
||||||
|
|
||||||
crAwayFromPost :: Creature -> Bool
|
crAwayFromPost :: Creature -> Bool
|
||||||
crAwayFromPost cr = case find sentinelGoal $ _crGoal $ _crActionPlan cr of
|
crAwayFromPost cr = case find sentinelGoal $ _crGoal $ _crActionPlan cr of
|
||||||
@@ -94,14 +60,6 @@ crAwayFromPost cr = case find sentinelGoal $ _crGoal $ _crActionPlan cr of
|
|||||||
sentinelGoal (SentinelAt _ _) = True
|
sentinelGoal (SentinelAt _ _) = True
|
||||||
sentinelGoal _ = False
|
sentinelGoal _ = False
|
||||||
|
|
||||||
crAwayFromPostR :: Creature -> Reader World Bool
|
|
||||||
crAwayFromPostR cr = return $ case find sentinelGoal $ _crGoal $ _crActionPlan cr of
|
|
||||||
Just (SentinelAt p _) -> dist p (_crPos cr) > 15
|
|
||||||
_ -> False
|
|
||||||
where
|
|
||||||
sentinelGoal (SentinelAt _ _) = True
|
|
||||||
sentinelGoal _ = False
|
|
||||||
|
|
||||||
crHasAmmo :: Creature -> Bool
|
crHasAmmo :: Creature -> Bool
|
||||||
crHasAmmo cr = maybe False (> 0) $ cr ^? crInv . ix (_crInvSel cr) . itConsumption . ammoLoaded
|
crHasAmmo cr = maybe False (> 0) $ cr ^? crInv . ix (_crInvSel cr) . itConsumption . ammoLoaded
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user