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
+1 -1
View File
@@ -106,7 +106,7 @@ tryEvadeSideways :: Creature -> World -> ActionUpdate
tryEvadeSideways _ w = jumpleft -- (mv,mempty)
where
jumpleft = (mv,DoReplicate 5 (DoImpulses mv))
mv = [Walk (V2 0 d)]
mv = [Walk (V2 0 d),UpdateRandGen]
d = evalState (takeOne [3,-3]) (w ^. randGen)
performAimAt :: Creature -> World -> Int -> Point2 -> ActionUpdate
-2
View File
@@ -41,8 +41,6 @@ crabCrit = defaultCreature
& crType .~ CrabCrit
{ _meleeCooldownL = 0
, _meleeCooldownR = 0
, _footForward = LeftForward
, _strideAmount = 0
, _dodgeCooldown = 0
, _lFootPos = 0
, _rFootPos = 0
+1
View File
@@ -23,6 +23,7 @@ import System.Random
-- note SwitchToItem doesn't necessarily update the root item correctly
followImpulse :: Int -> World -> Impulse -> World
followImpulse cid w = \case
UpdateRandGen -> w & randGen %~ (snd . (randomR (0::Int,0)))
ImpulseNothing -> w
RandomImpulse rimp ->
let (newimp, newgen) = runState (doRandImpulse rimp) (_randGen w)
+1
View File
@@ -9,6 +9,7 @@ crMvType cr = case _crType cr of
Avatar {} -> MvWalking 1.5
ChaseCrit {} -> defaultChaseMvType & mvSpeed .~ 1.8
CrabCrit {} -> defaultChaseMvType & mvSpeed .~ 0.5
& mvTurnJit .~ 0.01
HoverCrit {} -> defaultChaseMvType & mvSpeed .~ 0.16
SwarmCrit -> defaultChaseMvType
AutoCrit -> defaultAimMvType
+14 -8
View File
@@ -85,12 +85,15 @@ drawChaseCrit w cr = mconcat
crabUpperBody :: World -> Creature -> Shape
crabUpperBody _ cr = colorSH (_skinUpper cskin)
$
(overPosSH (Q.apply torsoq) (upperPrismPolyHalfMI 5 $ polyCirc 4 12
(
overPosSH (Q.apply torsoq) (upperPrismPolyHalfMI 5 $ polyCirc 4 10
& each . _x *~ 0.6)
)
<> overPosSH (Q.apply lclawq) (upperPrismPolyHalfMI 4 $ rectNSWE 20 0 (-2) 2)
<> overPosSH (Q.apply rclawq) (upperPrismPolyHalfMI 4 $ rectNSWE 0 (-20) (-2) 2)
)
<> colorSH (_skinHead cskin)
--(overPosSH (Q.apply headq) (upperPrismPolyHalfMI 2 $ [V2 0 (-4), V2 2 (-2), 2, V2 0 4]))
(overPosSH (Q.apply headq) (upperPrismPolyHalfMI 1 $ square 2))
where
-- i = fromIntegral (mod (w ^. cWorld . cClock) 100) / 100
torsoq = (V3 0 0 10,Q.qid)
@@ -104,6 +107,14 @@ crabUpperBody _ cr = colorSH (_skinUpper cskin)
ratck = Q.axisAngle (V3 0 0 1) (0.5 * pi)
rrest = Q.axisAngle (V3 1 0 0) (-1)
rcool = 1 - min 10 (fromIntegral . _meleeCooldownR $ _crType cr) / 10
headq = torsoq `Q.comp` (V3 0 0 5, Q.qid)
-- headq = torsoq `Q.comp` (V3 0 0 5, (Q.qz aimrot ))
-- cxy = cr ^. crPos . _xy
-- aimrot = fromMaybe pi $ do
-- i <- cr ^. crIntention . targetCr
-- tcxy <- w ^? cWorld . lWorld . creatures . ix i . crPos . _xy
-- guard $ hasLOSIndirect cxy tcxy w
-- return $ argV (tcxy - cxy) - cr ^. crDir
chaseUpperBody :: World -> Creature -> Shape
@@ -178,12 +189,7 @@ crabFeet cr =
f p q = q + 2 *^ (p - q)
cdir = -cr ^. crDir
cxy = cr ^. crPos . _xy
-- sh x = translateSHxy x off aFoot <> translateSHxy (- x) (- off) aFoot
afoot = upperPrismPolyST 10 $ polyCirc 3 2
off = 10
sLen = strideLength cr
-- f i = 8 * (sLen - 2*i) / sLen
-- f i = 8 * oneSmooth ((sLen - 2*i) / sLen)
deadFeet :: Creature -> Shape
{-# INLINE deadFeet #-}
+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
+1 -1
View File
@@ -56,7 +56,7 @@ updateLivingCreature cr =
over (cWorld . lWorld . creatures . ix cid) (chaseCritInternal w) w
CrabCrit{} -> \w ->
crUpdate cid . performActions cid $
over (cWorld . lWorld . creatures . ix cid) (crabCritInternal w) w
(crabCritInternal cid) w
AutoCrit {} -> crUpdate cid
SwarmCrit {} -> crUpdate cid
HoverCrit {} -> \w ->