Add crab crit, rethink Action datatype slightly

This commit is contained in:
2026-04-07 15:29:02 +01:00
parent 35d169b585
commit f0e568e694
25 changed files with 606 additions and 465 deletions
+76 -34
View File
@@ -1,6 +1,6 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Creature.ReaderUpdate (
doStrategyActions,
setTargetMv,
targetYouWhenCognizant,
overrideMeleeCloseTarget,
watchUpdateStrat,
@@ -9,7 +9,8 @@ module Dodge.Creature.ReaderUpdate (
-- goToTarget,
flockACC,
chaseCritMv,
setMvPos,
crabCritMv,
setMvPosToTargetCr,
setViewPos,
hoverCritMv,
) where
@@ -45,19 +46,18 @@ tryMeleeAttack cr tcr
&& dist tpos cpos < crRad (cr ^. crType) + crRad (tcr ^. crType) + 5
&& abs (_crDir cr - argV (tpos -.- cpos)) < pi / 4 =
cr & crActionPlan . apAction
.~ [ DoImpulses [Melee $ _crID tcr] `DoActionThen`
.~ DoImpulses [Melee $ _crID tcr] `DoActionThen`
DoReplicate 10 NoAction
`DoActionThen` DoImpulses
[ChangeStrategy (CloseToMelee $ _crID tcr)]
]
& crActionPlan . apStrategy .~ MeleeStrike
-- `DoActionThen` DoImpulses
-- [ChangeStrategy (CloseToMelee $ _crID tcr)]
-- & crActionPlan . apStrategy .~ MeleeStrike
| otherwise = cr
where
cpos = cr ^. crPos . _xy
tpos = tcr ^. crPos . _xy
setMvPos :: World -> Creature -> Creature
setMvPos w cr = cr & crIntention . mvToPoint .~ mpos
setMvPosToTargetCr :: World -> Creature -> Creature
setMvPosToTargetCr w cr = cr & crIntention . mvToPoint .~ mpos
where
int = _crIntention cr
mtpos = do
@@ -81,17 +81,17 @@ attentionViewPoint w cr = do
guard $ visionCheck cr (tcr ^. crPos . _xy) > 0
tcr ^? crPos . _xy
setTargetMv ::
-- | Function for determining target
(World -> Creature -> Maybe Creature) ->
World ->
Creature ->
Creature
setTargetMv targFunc w cr =
maybe
cr
(\ctarg -> cr & crIntention . mvToPoint ?~ (ctarg ^. crPos . _xy))
(targFunc w cr)
--setTargetMv ::
-- -- | Function for determining target
-- (World -> Creature -> Maybe Creature) ->
-- World ->
-- Creature ->
-- Creature
--setTargetMv targFunc w cr =
-- maybe
-- cr
-- (\ctarg -> cr & crIntention . mvToPoint ?~ (ctarg ^. crPos . _xy))
-- (targFunc w cr)
-- ugly
flockACC :: World -> Creature -> Creature
@@ -120,48 +120,88 @@ flockACC w cr = fromMaybe cr $ do
else negate r *.* horDir
in cr & crIntention . mvToPoint ?~ tpos +.+ horShift
crabCritMv :: World -> Creature -> Creature
crabCritMv w cr = case _apStrategy (_crActionPlan cr) of
WarningCry -> cr
CloseToMelee tid | Just (p,a) <- aimi tid -> cr & crActionPlan . apAction .~ EvadeAim p a 3
& crType . dodgeCooldown .~ 20
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> cr
_ -> case cr ^? crIntention . mvToPoint . _Just of
Just p
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) ->
cr & crActionPlan . apAction .~ PathTo p (DoImpulses [ChangeStrategy Wander])
| otherwise ->
cr & crActionPlan . apAction .~ bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
& crActionPlan . apStrategy .~ Search
& crIntention . mvToPoint .~ Nothing
_ -> viewTarget w cr
where
notpath = \case
Just NoAction -> False
Just PathTo {} -> False
_ -> True
aimi tid = do
tcr <- w ^? cWorld . lWorld . creatures . ix tid
Aiming <- tcr ^? crStance . posture
let txy = tcr ^. crPos . _xy
cxy = cr ^. crPos . _xy
0 <- cr ^? crType . dodgeCooldown
guard $ hasLOS cxy txy w
&& abs (nearZeroAngle (tcr^.crDir - argV (cxy - txy))) < 0.3
return (txy, tcr ^. crDir)
chaseCritMv :: World -> Creature -> Creature
chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
WarningCry -> cr
MeleeStrike -> cr
CloseToMelee cid
| VocReady == (cr ^. crVocalization) ->
cr
& crActionPlan . apAction
.:~ ImpulsesList
.~ ImpulsesList
( [Bark soundid] :
replicate numjits [RandomImpulse thejitter]
++ [[ChangeStrategy (CloseToMelee cid)]]
)
) NoAction
& resetCrVocCoolDown w
& crActionPlan . apStrategy .~ WarningCry
where
thejitter = RandImpulseCircMove 3
soundid = evalState (takeOne (crWarningSounds cr)) (_randGen w)
numjits = fst $ randomR (15, 25) (_randGen w)
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> cr
_ -> case cr ^? crIntention . mvToPoint . _Just of
Just p
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) ->
cr & crActionPlan . apAction .~ [PathTo p (DoImpulses [ChangeStrategy Wander])]
cr & crActionPlan . apAction .~ PathTo p (DoImpulses [ChangeStrategy Wander])
| otherwise ->
cr & crActionPlan . apAction .~ [bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]]
cr & crActionPlan . apAction .~ bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
& crActionPlan . apStrategy .~ WatchAndWait
& crIntention . mvToPoint .~ Nothing
_ -> viewTarget w cr
where
notpath = \case
Just NoAction -> False
Just PathTo {} -> False
_ -> True
hoverCritMv :: World -> Creature -> Creature
hoverCritMv w cr = case _apStrategy (_crActionPlan cr) of
WarningCry -> cr
MeleeStrike -> cr
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> cr
_ -> case cr ^? crIntention . mvToPoint . _Just of
Just p
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) ->
cr & crActionPlan . apAction .~ [PathTo p (DoImpulses [ChangeStrategy Wander])]
cr & crActionPlan . apAction .~ PathTo p (DoImpulses [ChangeStrategy Wander])
| otherwise ->
cr & crActionPlan . apAction .~ [bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]]
cr & crActionPlan . apAction .~ bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
& crActionPlan . apStrategy .~ WatchAndWait
& crIntention . mvToPoint .~ Nothing
_ -> viewTarget w cr
where
notpath = \case
Just NoAction -> False
Just PathTo {} -> False
_ -> True
--goToTarget :: World -> Creature -> Creature
--goToTarget w cr = case cr ^? crIntention . mvToPoint . _Just of
@@ -173,23 +213,25 @@ viewTarget w cr = case cr ^? crIntention . viewPoint . _Just of
Just p
| hasLOSIndirect p (cr ^. crPos . _xy) w ->
cr
& crActionPlan . apAction .~ [TurnToPoint p]
& crActionPlan . apAction .~ TurnToPoint p
& crIntention . viewPoint .~ Nothing
& crActionPlan . apStrategy .~ Investigate
| otherwise ->
cr & crActionPlan . apAction %~ replaceNullWith (PathTo p (DoImpulses [ChangeStrategy Wander]))
-- cr & crActionPlan . apAction %~ replaceNullWith (PathTo p (DoImpulses [ChangeStrategy Wander]))
cr & crActionPlan . apAction .~ PathTo p (DoImpulses [ChangeStrategy Wander])
& crActionPlan . apStrategy .~ Investigate
Nothing -> cr
replaceNullWith :: a -> [a] -> [a]
replaceNullWith x [] = [x]
replaceNullWith _ xs = xs
--replaceNullWith :: a -> [a] -> [a]
--replaceNullWith x [] = [x]
--replaceNullWith _ xs = xs
doStrategyActions :: Creature -> Creature
doStrategyActions cr = case cr ^? crActionPlan . apStrategy of
Just (StrategyActions strat acs) ->
cr
& crActionPlan . apAction .~ acs
-- & crActionPlan . apAction .~ acs
& crActionPlan . apAction .~ head acs
& crActionPlan . apStrategy .~ strat
_ -> cr