Add randomness to multiple crab evasions

This commit is contained in:
2026-04-09 13:28:39 +01:00
parent 0a8a2210c0
commit c8a06bc084
14 changed files with 194 additions and 179 deletions
+20 -18
View File
@@ -121,32 +121,33 @@ flockACC w cr = fromMaybe cr $ do
else negate r *.* horDir
in cr & crIntention . mvToPoint ?~ tpos +.+ horShift
crabActionUpdate :: World -> Creature -> Creature
crabActionUpdate w cr = case _apStrategy (_crActionPlan cr) of
_ | Just tid <- meleel -> cr & crActionPlan . apAction
crabActionUpdate :: Int -> World -> World
crabActionUpdate cid w = case _apStrategy (_crActionPlan cr) of
_ | Just tid <- meleel -> w & tocr . crActionPlan . apAction
.~ DoImpulses [MeleeL tid] `DoActionThen`
DoReplicate 10 NoAction
-- & crType . meleeCooldownL .~ 20
_ | Just tid <- meleer -> cr & crActionPlan . apAction
_ | Just tid <- meleer -> w & tocr . crActionPlan . apAction
.~ DoImpulses [MeleeR tid] `DoActionThen`
DoReplicate 10 NoAction
-- & crType . meleeCooldownR .~ 20
WarningCry -> cr
CloseToMelee tid | aimi tid -> cr & crActionPlan . apAction .~ EvadeAim
& crType . dodgeCooldown .~ dc
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> cr
WarningCry -> w
CloseToMelee tid | aimi tid -> w & tocr . crActionPlan . apAction .~ EvadeAim
& tocr . crType . dodgeCooldown .~ dc
& randGen .~ g
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> w
Wander | Just tid <- cr ^? crIntention . targetCr . _Just
, canSee tid (cr ^. crID) w -> cr & crActionPlan . apStrategy .~ CloseToMelee tid
, canSee tid (cr ^. crID) w -> w & tocr . crActionPlan . apStrategy .~ CloseToMelee tid
_ -> case cr ^? crIntention . mvToPoint . _Just of
Just p
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) ->
cr & crActionPlan . apAction .~ PathTo p (DoImpulses [ChangeStrategy Wander])
w & tocr . 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
w & tocr . crActionPlan . apAction .~ bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
& tocr . crActionPlan . apStrategy .~ Search
& tocr . crIntention . mvToPoint .~ Nothing
_ -> w & tocr %~ viewTarget w
where
cr = w ^?! cWorld . lWorld . creatures . ix cid
tocr = cWorld . lWorld . creatures . ix cid
meleel = do
tid <- cr ^? crIntention . targetCr . _Just
tcr <- w ^? cWorld . lWorld . creatures . ix tid
@@ -171,8 +172,7 @@ crabActionUpdate w cr = case _apStrategy (_crActionPlan cr) of
&& (_crDir cr - argV (tpos -.- cpos)) >= 0
&& cr ^?! crType . meleeCooldownL < 15
return tid
--dc = fst $ randomR (15,25) (w ^. randGen)
dc = fst $ randomR (15,50) (w ^. randGen)
(dc,g) = randomR (15,50) (w ^. randGen)
notpath = \case
Just NoAction -> False
Just PathTo {} -> False
@@ -180,6 +180,7 @@ crabActionUpdate w cr = case _apStrategy (_crActionPlan cr) of
_ -> True
aimi tid = fromMaybe False $ do
tcr <- w ^? cWorld . lWorld . creatures . ix tid
hp <- cr ^? crHP . _HP
Aiming <- tcr ^? crStance . posture
let txy = tcr ^. crPos . _xy
cxy = cr ^. crPos . _xy
@@ -188,6 +189,7 @@ crabActionUpdate w cr = case _apStrategy (_crActionPlan cr) of
&& abs (nearZeroAngle (tcr^.crDir - argV (cxy - txy))) < 0.3
&& isWalkable txy cxy w
&& diffAngles (cr ^. crDir) (argV (txy - cxy)) < 0.1
&& hp > 0
chaseCritMv :: World -> Creature -> Creature
chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of