Work on crab evasion

This commit is contained in:
2026-04-07 17:24:53 +01:00
parent f0e568e694
commit 333f2875cb
9 changed files with 227 additions and 191 deletions
+11 -2
View File
@@ -15,6 +15,7 @@ module Dodge.Creature.ReaderUpdate (
hoverCritMv,
) where
import Dodge.WorldEvent.ThingsHit
import Control.Applicative
import Control.Monad
import Data.Bifunctor
@@ -123,9 +124,11 @@ flockACC w cr = fromMaybe cr $ do
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 tid | Just (p,a) <- aimi tid -> cr & crActionPlan . apAction .~ EvadeAim p a 10
& crType . dodgeCooldown .~ dc
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> cr
Wander | Just tid <- cr ^? crIntention . targetCr . _Just
, canSee tid (cr ^. crID) w -> cr & crActionPlan . apStrategy .~ CloseToMelee tid
_ -> case cr ^? crIntention . mvToPoint . _Just of
Just p
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) ->
@@ -136,9 +139,11 @@ crabCritMv w cr = case _apStrategy (_crActionPlan cr) of
& crIntention . mvToPoint .~ Nothing
_ -> viewTarget w cr
where
dc = fst $ randomR (15,25) (w ^. randGen)
notpath = \case
Just NoAction -> False
Just PathTo {} -> False
Just AimAt {} -> False
_ -> True
aimi tid = do
tcr <- w ^? cWorld . lWorld . creatures . ix tid
@@ -148,6 +153,8 @@ crabCritMv w cr = case _apStrategy (_crActionPlan cr) of
0 <- cr ^? crType . dodgeCooldown
guard $ hasLOS cxy txy w
&& abs (nearZeroAngle (tcr^.crDir - argV (cxy - txy))) < 0.3
&& isWalkable txy cxy w
&& diffAngles (cr ^. crDir) (argV (txy - cxy)) < 0.1
return (txy, tcr ^. crDir)
chaseCritMv :: World -> Creature -> Creature
@@ -182,6 +189,7 @@ chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
notpath = \case
Just NoAction -> False
Just PathTo {} -> False
Just AimAt {} -> False
_ -> True
hoverCritMv :: World -> Creature -> Creature
@@ -201,6 +209,7 @@ hoverCritMv w cr = case _apStrategy (_crActionPlan cr) of
notpath = \case
Just NoAction -> False
Just PathTo {} -> False
Just AimAt {} -> False
_ -> True
--goToTarget :: World -> Creature -> Creature