Refactor ai
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
{- |
|
||||
Module testing for properties of creatures, whether they are reloading, etc.
|
||||
Each function takes the world and a creature and returns a bool.
|
||||
Note that the creature NEED NOT be the same as the creature with that id in the world,
|
||||
in fact in some cases a creature with that id may not even exist.
|
||||
-}
|
||||
module Dodge.Creature.Test
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Base.Collide
|
||||
import Dodge.Creature.Stance.Data
|
||||
import Geometry
|
||||
import SameConstr
|
||||
|
||||
import Data.List (find)
|
||||
import Data.Maybe
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
|
||||
andTest :: (a -> Bool) -> (a -> Bool) -> a -> Bool
|
||||
andTest f g a = f a && g a
|
||||
|
||||
onBoth :: (a -> b -> c) -> (d -> a) -> (d -> b) -> d -> c
|
||||
onBoth f g h x = f (g x) (h x)
|
||||
|
||||
crIsReloading :: (World, Creature) -> Bool
|
||||
crIsReloading (w,cr) = case cr ^? crInv . ix (_crInvSel cr) . wpReloadState of
|
||||
Just t -> t > 0
|
||||
_ -> False
|
||||
|
||||
crCanSeeCID :: Int -> (World, Creature) -> Bool
|
||||
crCanSeeCID cid (w,cr) = hasLOS (_crPos cr) (_crPos $ _creatures w IM.! cid) w
|
||||
|
||||
crIsAiming :: (World,Creature) -> Bool
|
||||
crIsAiming (_,cr) = _posture (_crStance cr) == Aiming
|
||||
|
||||
crHasTarget :: (World,Creature) -> Bool
|
||||
crHasTarget (_,cr) = isJust $ cr ^? crTarget . _Just
|
||||
|
||||
crHasTargetLOS :: (World,Creature) -> Bool
|
||||
crHasTargetLOS (w,cr) = case cr ^? crTarget . _Just of
|
||||
Just i -> crCanSeeCID i (w,cr)
|
||||
Nothing -> False
|
||||
|
||||
crStratConMatches :: Strategy -> (World,Creature) -> Bool
|
||||
crStratConMatches strat (_,cr) = eqConstr strat (_crStrategy $ _crActionPlan cr)
|
||||
|
||||
crAwayFromPost :: (World,Creature) -> Bool
|
||||
crAwayFromPost (_,cr) = case find sentinelGoal $ _crGoal $ _crActionPlan cr of
|
||||
Just (SentinelAt p dir) -> dist p (_crPos cr) > 15
|
||||
_ -> False
|
||||
where
|
||||
sentinelGoal (SentinelAt p dir) = True
|
||||
sentinelGoal _ = False
|
||||
Reference in New Issue
Block a user