Cleanup
This commit is contained in:
@@ -105,18 +105,18 @@ performAction cr w ac = case ac of
|
||||
(imps , Nothing ) -> (imps, Just afta)
|
||||
DoActionWhile f act -> performAction cr w $ DoActionWhilePartial act f act
|
||||
DoActionWhilePartial partAc f resetAc
|
||||
| f (w,cr) -> case performAction cr w partAc of
|
||||
| f w cr -> case performAction cr w partAc of
|
||||
(imps, Just nxta) -> (imps, Just $ DoActionWhilePartial nxta f resetAc)
|
||||
(imps, Nothing) -> (imps, Just $ DoActionWhilePartial resetAc f resetAc)
|
||||
| otherwise -> performAction cr w partAc
|
||||
DoActionIf f ifa
|
||||
| f (w,cr) -> performAction cr w ifa
|
||||
| f w cr -> performAction cr w ifa
|
||||
| otherwise -> ([],Nothing)
|
||||
DoActionIfElse ifa f elsea
|
||||
| f (w,cr) -> performAction cr w ifa
|
||||
| f w cr -> performAction cr w ifa
|
||||
| otherwise -> performAction cr w elsea
|
||||
DoActionWhileInterrupt repa f afta
|
||||
| f (w,cr) -> (fst $ performAction cr w repa, Just $ DoActionWhileInterrupt repa f afta)
|
||||
| f w cr -> (fst $ performAction cr w repa, Just $ DoActionWhileInterrupt repa f afta)
|
||||
| otherwise -> performAction cr w afta
|
||||
DoActions [] -> ([], Nothing)
|
||||
DoActions acs ->
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
module Dodge.Creature.Impulse
|
||||
( impulsiveAIR
|
||||
-- , impulsiveAI
|
||||
, impulsiveAI
|
||||
( impulsiveAI
|
||||
, followImpulses
|
||||
) where
|
||||
import Dodge.Data
|
||||
@@ -10,27 +8,13 @@ import Dodge.Creature.Impulse.Movement
|
||||
import Dodge.Creature.Impulse.UseItem
|
||||
import Dodge.SoundLogic
|
||||
import Geometry
|
||||
import LensHelp
|
||||
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import System.Random
|
||||
import Control.Lens
|
||||
import Control.Monad.Reader
|
||||
import Data.Bifunctor
|
||||
--import Data.Maybe
|
||||
|
||||
impulsiveAIR
|
||||
:: (Creature -> Reader World Creature)
|
||||
-> Creature
|
||||
-> World
|
||||
-> (World -> World , Maybe Creature)
|
||||
impulsiveAIR impf cr w = second Just $ followImpulses w . ($ w) . runReader $ impf cr
|
||||
|
||||
--impulsiveAI :: (World -> Creature -> Creature)
|
||||
-- -> Creature
|
||||
-- -> World
|
||||
-- -> (World -> World , Maybe Creature)
|
||||
--impulsiveAI impf cr w = second Just $ followImpulses w $ impf w cr
|
||||
|
||||
impulsiveAI :: (World -> Creature -> Creature)
|
||||
-> Creature
|
||||
-> World
|
||||
@@ -56,14 +40,13 @@ followImpulse cr w imp = case imp of
|
||||
ChangePosture post -> (id, cr & crStance . posture .~ post)
|
||||
UseItem -> (tryUseItem cr, cr)
|
||||
SwitchToItem i -> (id, cr & crInvSel .~ i)
|
||||
Melee cid' ->
|
||||
(hitCr cid'
|
||||
, crMvBy (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crMeleeCooldown .~ 20) -- randomise cooldown?
|
||||
Melee cid' -> (hitCr cid'
|
||||
, crMvBy (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crMeleeCooldown .~ 20)
|
||||
RandomTurn a -> (id, creatureTurn (rr a) cr)
|
||||
MakeSound sid -> ( soundStart (CrSound (_crID cr)) (_crPos cr) sid Nothing , cr )
|
||||
DropItem -> undefined
|
||||
ChangeStrategy strat -> (id, cr & crActionPlan . crStrategy .~ strat)
|
||||
AddGoal gl -> (id, cr & crActionPlan . crGoal %~ (gl :) )
|
||||
AddGoal gl -> (id, cr & crActionPlan . crGoal .:~ gl )
|
||||
ArbitraryImpulseFunction f -> (id, f w cr)
|
||||
ArbitraryImpulse f -> followImpulse cr w (f cr w)
|
||||
ImpulseUseTargetCID f -> case cr ^? crIntention . targetCr . _Just of
|
||||
|
||||
@@ -28,7 +28,7 @@ launcherCrit = defaultCreature
|
||||
[ Left performActions
|
||||
, Left $ watchUpdateStrat
|
||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0) [retreatFire])
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
, (const crAwayFromPost, const goToPostStrat)
|
||||
]
|
||||
, Left $ perceptionUpdate' [0]
|
||||
, Right doStrategyActions
|
||||
|
||||
@@ -30,18 +30,18 @@ ltAutoCrit = defaultCreature
|
||||
[ Left performActions
|
||||
, Left $ watchUpdateStrat
|
||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||
[DoActionIf (not . crIsAiming) drawWeapon
|
||||
[DoActionIf (const $ not . crIsAiming) drawWeapon
|
||||
,DoActionThen
|
||||
(DoActionWhile crHasTargetLOS $ ArbitraryAction chooseMovement)
|
||||
(DoActionWhile crHasTargetLOS' $ ArbitraryAction chooseMovement)
|
||||
(DoImpulses [ChangeStrategy WatchAndWait])
|
||||
]
|
||||
)
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
, (const crAwayFromPost, const goToPostStrat)
|
||||
]
|
||||
, Left $ perceptionUpdate' [0]
|
||||
, Right $ doStrategyActions
|
||||
, Right $ reloadOverride
|
||||
, Left $ targetYouWhenCognizant
|
||||
, Right doStrategyActions
|
||||
, Right reloadOverride
|
||||
, Left targetYouWhenCognizant
|
||||
, Right $ overrideInternal
|
||||
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
||||
(crActionPlan . crStrategy .~ WatchAndWait)
|
||||
|
||||
@@ -33,13 +33,13 @@ pistolCrit = defaultCreature
|
||||
[Left performActions
|
||||
,Left $ watchUpdateStrat
|
||||
[ (crHasTargetLOS, \w cr -> StrategyActions (ShootAt 0)
|
||||
[DoActionIf (not . crIsAiming) drawWeapon,chooseMovement cr w])
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
[DoActionIf (const $ not . crIsAiming) drawWeapon,chooseMovement cr w])
|
||||
, (const crAwayFromPost, const goToPostStrat)
|
||||
]
|
||||
,Left $ perceptionUpdate' [0]
|
||||
,Right $ doStrategyActions
|
||||
,Right $ reloadOverride
|
||||
,Left $ targetYouWhenCognizant
|
||||
,Right doStrategyActions
|
||||
,Right reloadOverride
|
||||
,Left targetYouWhenCognizant
|
||||
,Right $ overrideInternal
|
||||
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
||||
(crActionPlan . crStrategy .~ WatchAndWait)
|
||||
|
||||
@@ -24,6 +24,7 @@ import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
import Control.Applicative
|
||||
import Data.Maybe
|
||||
import Data.Bifunctor
|
||||
|
||||
overrideMeleeCloseTarget :: Creature -> Creature
|
||||
overrideMeleeCloseTarget cr = maybe cr (tryMeleeAttack cr) (_targetCr $ _crIntention cr)
|
||||
@@ -117,7 +118,8 @@ reloadOverride cr
|
||||
reloadActions =
|
||||
[ holsterWeapon
|
||||
, 1 `WaitThen`
|
||||
DoActionWhileInterrupt NoAction crIsReloading (DoImpulses [ChangeStrategy WatchAndWait])
|
||||
DoActionWhileInterrupt NoAction (const crIsReloading)
|
||||
(DoImpulses [ChangeStrategy WatchAndWait])
|
||||
]
|
||||
|
||||
overrideInternal :: (Creature -> Bool) -> (Creature -> Creature) -> Creature -> Creature
|
||||
@@ -126,13 +128,13 @@ overrideInternal test update cr
|
||||
| otherwise = cr
|
||||
|
||||
watchUpdateStrat
|
||||
:: [ ((World, Creature) -> Bool, World -> Creature -> Strategy) ]
|
||||
:: [ (World -> Creature -> Bool, World -> Creature -> Strategy) ]
|
||||
-> World
|
||||
-> Creature
|
||||
-> Creature
|
||||
watchUpdateStrat fs w cr = case cr ^? crActionPlan . crStrategy of
|
||||
Just WatchAndWait -> cr
|
||||
& crActionPlan . crStrategy .~ listGuard (fs, \_ _ -> WatchAndWait) (w, cr) w cr
|
||||
& crActionPlan . crStrategy .~ listGuard (map (first uncurry) fs, \_ _ -> WatchAndWait) (w, cr) w cr
|
||||
_ -> cr
|
||||
|
||||
listGuard :: ([(a -> Bool, b)] , b) -> a -> b
|
||||
|
||||
@@ -23,7 +23,7 @@ sentinelAI w = reloadOverride .
|
||||
[ (crHasTargetLOS
|
||||
, \ _ cr -> StrategyActions (ShootAt (fromJust $ tcid cr))
|
||||
[ DoActionIf
|
||||
(not . crIsAiming)
|
||||
(const $ not . crIsAiming)
|
||||
(drawWeapon `DoActionThen` (50 `WaitThen` NoAction))
|
||||
`DoActionThen` lostest
|
||||
`DoActionWhile` advanceShoot
|
||||
@@ -38,7 +38,7 @@ sentinelAI w = reloadOverride .
|
||||
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
|
||||
@@ -53,7 +53,7 @@ sentinelFireType f = chainCreatureUpdatesLR
|
||||
, aiming
|
||||
]
|
||||
)
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
, (const crAwayFromPost, const goToPostStrat)
|
||||
]
|
||||
, Left $ perceptionUpdate' [0]
|
||||
-- , Left $ perceptionUp 0
|
||||
@@ -65,21 +65,21 @@ sentinelFireType f = chainCreatureUpdatesLR
|
||||
(crActionPlan . crStrategy .~ WatchAndWait)
|
||||
]
|
||||
where
|
||||
drawwp = DoActionIfElse NoAction crIsAiming (DoActionThen drawWeapon (WaitThen 50 NoAction))
|
||||
drawwp = DoActionIfElse NoAction (const crIsAiming) (DoActionThen drawWeapon (WaitThen 50 NoAction))
|
||||
aiming = AimAt
|
||||
{ _targetID = 0
|
||||
, _targetSeenAt = V2 0 0 -- hack
|
||||
}
|
||||
|
||||
sentinelExtraWatchUpdate
|
||||
:: [((World, Creature) -> Bool , World -> Creature -> Strategy)]
|
||||
:: [(World -> Creature -> Bool , World -> Creature -> Strategy)]
|
||||
-> World
|
||||
-> Creature
|
||||
-> Creature
|
||||
sentinelExtraWatchUpdate xs = chainCreatureUpdatesLR
|
||||
[ Left performActions
|
||||
, Left $ watchUpdateStrat
|
||||
( xs ++ [(crAwayFromPost, goToPostStrat)] )
|
||||
( xs ++ [(const crAwayFromPost, const goToPostStrat)] )
|
||||
, Left $ perceptionUpdate' [0]
|
||||
, Right doStrategyActions
|
||||
, Left targetYouWhenCognizant
|
||||
|
||||
@@ -31,18 +31,18 @@ spreadGunCrit = defaultCreature
|
||||
[Left performActions
|
||||
,Left $ watchUpdateStrat
|
||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||
[DoActionIf (not . crIsAiming) drawWeapon
|
||||
[DoActionIf (const $ not . crIsAiming) drawWeapon
|
||||
,DoActionThen
|
||||
(DoActionWhile crHasTargetLOS $ ArbitraryAction chooseMovement)
|
||||
(DoActionWhile crHasTargetLOS' $ ArbitraryAction chooseMovement)
|
||||
(DoImpulses [ChangeStrategy WatchAndWait])
|
||||
]
|
||||
)
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
, (const crAwayFromPost, const goToPostStrat)
|
||||
]
|
||||
,Left $ perceptionUpdate' [0]
|
||||
,Right $ doStrategyActions
|
||||
,Right $ reloadOverride
|
||||
,Left $ targetYouWhenCognizant
|
||||
,Right doStrategyActions
|
||||
,Right reloadOverride
|
||||
,Left targetYouWhenCognizant
|
||||
,Right $ overrideInternal
|
||||
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
||||
(\ cr -> cr & crActionPlan . crStrategy .~ WatchAndWait)
|
||||
|
||||
+15
-46
@@ -1,7 +1,6 @@
|
||||
module Dodge.Creature.State
|
||||
( stateUpdate
|
||||
, stateUpdateDamage
|
||||
, stateUpdateDamage'
|
||||
, doDamage
|
||||
, clearDamage
|
||||
, invSideEff
|
||||
@@ -24,7 +23,7 @@ import qualified IntMapHelp as IM
|
||||
--import StrictHelp
|
||||
|
||||
import qualified Data.IntSet as IS
|
||||
import Data.Maybe
|
||||
--import Data.Maybe
|
||||
import Data.Function
|
||||
import Control.Lens
|
||||
--import Control.Applicative
|
||||
@@ -45,34 +44,15 @@ import qualified Data.Vector.Mutable as MV
|
||||
-- update shield positions
|
||||
stateUpdate :: (Creature -> World -> (World -> World, Creature))
|
||||
-> Creature -> World -> World
|
||||
stateUpdate f cr w = let (fw,mcr) = stateUpdateDamage' doDamage f cr w
|
||||
in fw $ w & creatures . at (_crID cr) .~ mcr
|
||||
stateUpdate = stateUpdateDamage doDamage
|
||||
|
||||
stateUpdateDamage :: (Creature -> Creature) -> CRUpdate -> CRUpdate
|
||||
stateUpdateDamage :: (Creature -> Creature)
|
||||
-> (Creature -> World -> (World -> World, Creature))
|
||||
-- -> CRUpdate
|
||||
-> Creature -> World -> World
|
||||
stateUpdateDamage damageupdate u cr w = case u (updateMovement cr) w of
|
||||
(f, maybeCr) ->
|
||||
( invSideEff (fromMaybe cr maybeCr) . movementSideEff cr . deathEff . f
|
||||
, fmap (stepReloading . damageupdate) $ crOrCorpse =<< maybeCr
|
||||
)
|
||||
where
|
||||
crOrCorpse cr'
|
||||
| cr' ^. crHP > 0 = Just cr'
|
||||
| otherwise = Nothing
|
||||
deathEff
|
||||
| cr ^.crHP > 0 = id
|
||||
| otherwise = stopSoundFrom (CrWeaponSound (_crID cr) 0)
|
||||
. over decorations addCorpse
|
||||
. dropByState cr
|
||||
addCorpse = IM.insertNewKey
|
||||
$ uncurryV translate (_crOldPos cr)
|
||||
$ rotate (_crDir cr)
|
||||
(_crCorpse cr)
|
||||
stateUpdateDamage' :: (Creature -> Creature) -> CRUpdate' -> CRUpdate
|
||||
stateUpdateDamage' damageupdate u cr w = case u (updateMovement cr) w of
|
||||
(f, upcr) ->
|
||||
( invSideEff upcr . movementSideEff cr . deathEff . f
|
||||
, stepReloading . damageupdate <$> crOrCorpse upcr
|
||||
)
|
||||
(f, upcr) -> invSideEff upcr . movementSideEff cr . deathEff . f $ w
|
||||
& creatures . at (_crID cr) .~ (stepReloading . damageupdate <$> crOrCorpse upcr)
|
||||
where
|
||||
crOrCorpse cr'
|
||||
| cr' ^. crHP > 0 = Just cr'
|
||||
@@ -88,22 +68,16 @@ stateUpdateDamage' damageupdate u cr w = case u (updateMovement cr) w of
|
||||
(_crCorpse cr)
|
||||
-- | Drop items according to the creature state.
|
||||
dropByState :: Creature -> World -> World
|
||||
dropByState cr w = foldr (copyInvItemToFloor cr) w is
|
||||
where
|
||||
is :: [Int]
|
||||
is = case cr ^. crState . crDropsOnDeath of
|
||||
DropAll -> IM.keys $ _crInv cr
|
||||
DropSpecific xs -> xs
|
||||
DropAmount n -> take n $ evalState (shuffle $ IM.keys $ _crInv cr) (_randGen w)
|
||||
dropByState cr w = foldr (copyInvItemToFloor cr) w $ case cr ^. crState . crDropsOnDeath of
|
||||
DropAll -> IM.keys $ _crInv cr
|
||||
DropSpecific xs -> xs
|
||||
DropAmount n -> take n $ evalState (shuffle $ IM.keys $ _crInv cr) (_randGen w)
|
||||
|
||||
setOldPos :: Creature -> Creature
|
||||
setOldPos cr = cr
|
||||
& crOldPos .~ _crPos cr
|
||||
& crOldDir .~ _crDir cr
|
||||
|
||||
--meleeCooldown :: CRUpdate -> CRUpdate
|
||||
--meleeCooldown u cr = u $ cr & crMeleeCooldown . _Just %~ (max 0 . (\x -> x - 1))
|
||||
|
||||
clearDamage :: Creature -> Creature
|
||||
clearDamage = crState . crDamage .~ []
|
||||
|
||||
@@ -125,15 +99,15 @@ bpVector = V.fromList $ 0 : [0 .. 18]
|
||||
movementSideEff :: Creature -> World -> World
|
||||
movementSideEff cr w
|
||||
| hasJetPack = case cr ^? crStance . carriage of
|
||||
Just (Boosting v)
|
||||
-> makeFlameletTimed
|
||||
Just (Boosting v) -> w
|
||||
& randGen .~ g
|
||||
& makeFlameletTimed
|
||||
(oldPos +.+ (_crRad cr + 3) *.* unitVectorAtAngle (_crDir cr + pi))
|
||||
20
|
||||
(momentum +.+ 1 *.* rotateV randDir (vInverse v))
|
||||
Nothing
|
||||
1
|
||||
20
|
||||
$ set randGen g w
|
||||
_ -> w
|
||||
| otherwise = footstepSideEffect cr w
|
||||
where
|
||||
@@ -146,7 +120,6 @@ movementSideEff cr w
|
||||
(randDir,g) = randomR (-0.5,0.5) $ _randGen w
|
||||
(randAng,_) = randomR (0,2*pi) $ _randGen w
|
||||
|
||||
|
||||
heldItemUpdate :: Item -> Item
|
||||
heldItemUpdate = invItemUpdate
|
||||
. (itUse %~ useupdate)
|
||||
@@ -220,7 +193,3 @@ isFrictionless cr = case cr ^? crStance . carriage of
|
||||
Just (Boosting _) -> True
|
||||
Just Floating -> True
|
||||
_ -> False
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import Dodge.Creature.Volition
|
||||
|
||||
import Data.List
|
||||
|
||||
goToPostStrat :: World -> Creature -> Strategy
|
||||
goToPostStrat w cr = case find sentinelGoal $ _crGoal $ _crActionPlan cr of
|
||||
goToPostStrat :: Creature -> Strategy
|
||||
goToPostStrat cr = case find sentinelGoal $ _crGoal $ _crActionPlan cr of
|
||||
Just (SentinelAt p _) -> StrategyActions (GetTo p)
|
||||
[DoActionThen (WaitThen 150 holsterIfAiming)
|
||||
$ DoActionThen (PathTo p)
|
||||
@@ -21,6 +21,5 @@ goToPostStrat w cr = case find sentinelGoal $ _crGoal $ _crActionPlan cr of
|
||||
sentinelGoal (SentinelAt _ _) = True
|
||||
sentinelGoal _ = False
|
||||
holsterIfAiming
|
||||
| crIsAiming (w,cr) = holsterWeapon
|
||||
| crIsAiming cr = holsterWeapon
|
||||
| otherwise = NoAction
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ swarmCrit :: Creature
|
||||
swarmCrit = defaultCreature
|
||||
{ _crUpdate = stateUpdate $ impulsiveAI $ chainCreatureUpdatesLR
|
||||
[ Left $ flockToPointUsing' (encircleDistP 100) (meleeHeadingMove 0.1 0.1 (pi/4) 3.9)
|
||||
, Right $ (crMeleeCooldown %~ max 0 . subtract 1)
|
||||
, Right (crMeleeCooldown %~ max 0 . subtract 1)
|
||||
, Left $ perceptionUpdate' [0]
|
||||
, Right $ doStrategyActions
|
||||
, Left $ targetYouWhenCognizant
|
||||
, Right doStrategyActions
|
||||
, Left targetYouWhenCognizant
|
||||
]
|
||||
-- , doStrategyActions
|
||||
-- , targetYouWhenCognizant
|
||||
|
||||
+24
-21
@@ -34,8 +34,8 @@ 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 (_,cr) = case cr ^? crInv . ix (_crInvSel cr) . itConsumption . reloadState . _Just' of
|
||||
crIsReloading :: Creature -> Bool
|
||||
crIsReloading cr = case cr ^? crInv . ix (_crInvSel cr) . itConsumption . reloadState . _Just' of
|
||||
Just t -> t > 0
|
||||
_ -> False
|
||||
|
||||
@@ -56,26 +56,23 @@ 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 :: (World,Creature) -> Bool
|
||||
crIsAiming (_,cr) = _posture (_crStance cr) == Aiming
|
||||
crIsAiming :: Creature -> Bool
|
||||
crIsAiming cr = _posture (_crStance cr) == Aiming
|
||||
|
||||
crIsAiming' :: Creature -> Bool
|
||||
crIsAiming' cr = _posture (_crStance cr) == Aiming
|
||||
|
||||
crIsAimingR :: Creature -> Reader World Bool
|
||||
crIsAimingR cr = return $ _posture (_crStance cr) == Aiming
|
||||
|
||||
crHasTarget :: (World,Creature) -> Bool
|
||||
crHasTarget (_,cr) = isJust $ cr ^? crIntention . targetCr . _Just
|
||||
|
||||
crHasTarget' :: Creature -> Bool
|
||||
crHasTarget' cr = isJust $ cr ^? crIntention . targetCr . _Just
|
||||
|
||||
crHasTargetR :: Creature -> Reader World Bool
|
||||
crHasTargetR cr = return $ isJust $ cr ^? crIntention . targetCr . _Just
|
||||
|
||||
crHasTargetLOS :: (World,Creature) -> Bool
|
||||
crHasTargetLOS (w,cr) = case cr ^? crIntention . targetCr . _Just of
|
||||
crHasTargetLOS :: World -> Creature -> Bool
|
||||
crHasTargetLOS w cr = case cr ^? crIntention . targetCr . _Just of
|
||||
Just i -> crCanSeeCr i (w,cr)
|
||||
Nothing -> False
|
||||
|
||||
crHasTargetLOS' :: World -> Creature -> Bool
|
||||
crHasTargetLOS' w cr = case cr ^? crIntention . targetCr . _Just of
|
||||
Just i -> crCanSeeCr i (w,cr)
|
||||
Nothing -> False
|
||||
|
||||
@@ -84,8 +81,8 @@ crHasTargetLOSR cr = reader $ \w -> case cr ^? crIntention . targetCr . _Just of
|
||||
Just i -> crCanSeeCr i (w,cr)
|
||||
Nothing -> False
|
||||
|
||||
crSafeDistFromTarg :: Float -> (World,Creature) -> Bool
|
||||
crSafeDistFromTarg d (_,cr) = case cr ^? crIntention . targetCr . _Just of
|
||||
crSafeDistFromTarg :: Float -> Creature -> Bool
|
||||
crSafeDistFromTarg d cr = case cr ^? crIntention . targetCr . _Just of
|
||||
Just tcr -> dist (_crPos cr) (_crPos tcr) > d
|
||||
Nothing -> True
|
||||
|
||||
@@ -103,8 +100,8 @@ crStratConMatches' strat cr = eqConstr strat (_crStrategy $ _crActionPlan cr)
|
||||
crStratConMatchesR :: Strategy -> Creature -> Reader World Bool
|
||||
crStratConMatchesR strat cr = return $ eqConstr strat (_crStrategy $ _crActionPlan cr)
|
||||
|
||||
crAwayFromPost :: (World,Creature) -> Bool
|
||||
crAwayFromPost (_,cr) = case find sentinelGoal $ _crGoal $ _crActionPlan cr of
|
||||
crAwayFromPost :: Creature -> Bool
|
||||
crAwayFromPost cr = case find sentinelGoal $ _crGoal $ _crActionPlan cr of
|
||||
Just (SentinelAt p _) -> dist p (_crPos cr) > 15
|
||||
_ -> False
|
||||
where
|
||||
@@ -119,8 +116,14 @@ crAwayFromPostR cr = return $ case find sentinelGoal $ _crGoal $ _crActionPlan c
|
||||
sentinelGoal (SentinelAt _ _) = True
|
||||
sentinelGoal _ = False
|
||||
|
||||
crHasAmmo :: (World,Creature) -> Bool
|
||||
crHasAmmo (_,cr) = maybe False (> 0) $ cr ^? crInv . ix (_crInvSel cr) . itConsumption . ammoLoaded
|
||||
crHasAmmo :: Creature -> Bool
|
||||
crHasAmmo cr = maybe False (> 0) $ cr ^? crInv . ix (_crInvSel cr) . itConsumption . ammoLoaded
|
||||
|
||||
crCanShoot :: (World,Creature) -> Bool
|
||||
crHasAmmo' :: Creature -> Bool
|
||||
crHasAmmo' cr = maybe False (> 0) $ cr ^? crInv . ix (_crInvSel cr) . itConsumption . ammoLoaded
|
||||
|
||||
crCanShoot :: Creature -> Bool
|
||||
crCanShoot p = crIsAiming p && crHasAmmo p
|
||||
|
||||
crCanShoot' :: Creature -> Bool
|
||||
crCanShoot' p = crIsAiming' p && crHasAmmo' p
|
||||
|
||||
@@ -23,7 +23,7 @@ fleeFrom cr mtcr = case mtcr of
|
||||
|
||||
shootTillEmpty :: Action
|
||||
--shootTillEmpty = (crCanShoot `DoActionWhile` DoImpulses [UseItem])
|
||||
shootTillEmpty = (crCanShoot `DoActionWhile` DoImpulses [UseItem])
|
||||
shootTillEmpty = (const crCanShoot `DoActionWhile` DoImpulses [UseItem])
|
||||
`DoActionThen` 20 `WaitThen` holsterWeapon
|
||||
|
||||
--advanceShoot :: Int -> Action
|
||||
@@ -39,5 +39,5 @@ shootFirstMiss :: Action
|
||||
shootFirstMiss =
|
||||
LeadTarget (V2 30 50) `DoActionThen`
|
||||
DoImpulses [UseItem] `DoActionThen`
|
||||
(crCanShoot `DoActionWhile` DoActions [LeadTarget (V2 0 0),DoImpulses [UseItem]])
|
||||
(const crCanShoot `DoActionWhile` DoActions [LeadTarget (V2 0 0),DoImpulses [UseItem]])
|
||||
`DoActionThen` 20 `WaitThen` holsterWeapon
|
||||
|
||||
Reference in New Issue
Block a user