Simplify slime compression

This commit is contained in:
2026-05-07 10:04:42 +01:00
parent b76148ae2a
commit 7c1ada4546
9 changed files with 158 additions and 154 deletions
+17 -22
View File
@@ -201,7 +201,8 @@ updateCalmBee cr cid w
, Just r <- tcr ^? crType . slimeSlime . to slimeToRad
, Just d <- tcr ^? crType . slimeCompression
= w
& tocr . crStance . carriage .~ Mounted ti (cr ^. crPos - tcr ^. crPos & _xy %~ compressionScale (vNormal ((1/r) *^d)))
-- & tocr . crStance . carriage .~ Mounted ti (cr ^. crPos - tcr ^. crPos & _xy %~ compressionScale (vNormal ((1/r) *^d)))
& tocr . crStance . carriage .~ Mounted ti (cr ^. crPos - tcr ^. crPos & _x %~ (/d) & _y *~ d)
& tocr . crActionPlan . apAction .~ NoAction
| Just (tcr,_) <- gettarg = w
& tocr . crActionPlan . apAction .~ PathTo (tcr ^. crPos . _xy) NoAction
@@ -253,13 +254,8 @@ slimeCritUpdate cid w
| r < 5 = w & cWorld . lWorld . creatures . ix cid . crHP .~ CrDestroyed Gibbed
| Just hitp <- w ^? cWorld . lWorld . creatures . ix cid . crDamage . ix 0 . dmPos
, Just hitv <- w ^? cWorld . lWorld . creatures . ix cid . crDamage . ix 0 . dmVector
-- , Just (cr1,cr2) <- splitSlimeCrit hitp hitv cr
-- =
-- let cid' = IM.newKey $ w ^. cWorld . lWorld . creatures
-- in w & cWorld . lWorld . creatures . ix cid .~ cr1
-- & cWorld . lWorld . creatures . at cid' ?~ (cr2 & crID .~ cid')
, Just w' <- splitSlimeCrit' hitp hitv cid cr w = w'
| (cr ^?! crType . slimeIsCompressing) && r > norm p
| (cr ^?! crType . slimeIsCompressing) && 1 > p
= let (w',g) = runState (setSlimeDir cid (cr & crDamage .~ []) w) (w ^. randGen)
in w' & randGen .~ g
| otherwise = updateCarriage cid $ w
@@ -271,13 +267,14 @@ slimeCritUpdate cid w
where
tocr = cWorld . lWorld . creatures . ix cid
cr = w ^?! cWorld . lWorld . creatures . ix cid
v = 0.1 *^ normalize p
mvslime = cr & crType . slimeCompression +~ f v
-- v = 0.1 *^ normalize p
v = 0.1 *^ unitVectorAtAngle (cr ^. crDir)
mvslime = cr & crType . slimeCompression +~ f (0.1/r)
& crPos . _xy +~ v
& crType . slimeIsCompressing %~ f'
f | t = negate
| otherwise = id
f' | norm p > 3*r/2 = const True
f' | p > 1.5 = const True
| otherwise = id
t = cr ^?! crType . slimeIsCompressing
r = cr ^?! crType . slimeSlime . to slimeToRad
@@ -291,24 +288,20 @@ setSlimeDir cid cr w = do
then do
x <- randInCirc 1
return $ fromMaybe w $ splitSlimeCrit' (x + cxy) (unitVectorAtAngle d) cid cr w
-- let (cr1,cr2) = splitSlimeCrit (x + cxy) (unitVectorAtAngle d) cr ^?! _Just
-- cid' = IM.newKey $ w ^. cWorld . lWorld . creatures
-- return $ w & tocr .~ cr1
-- & tocr' cid' ?~ (cr2 & crID .~ cid')
else return $ w & tocr . crType . slimeCompression .~ r *^ unitVectorAtAngle d
-- else return $ w & tocr . crType . slimeCompression .~ r *^ unitVectorAtAngle d
else return $ w & tocr . crDir .~ d
& tocr . crType . slimeIsCompressing .~ False
where
tocr = cWorld . lWorld . creatures . ix cid
-- tocr' i = cWorld . lWorld . creatures . at i
cxy = cr ^. crPos . _xy
r = cr ^?! crType . slimeSlime . to slimeToRad
doSlimeRadChange :: Creature -> Creature
doSlimeRadChange = crType . slimeRadWobble %~ f
doSlimeRadChange = crType . slimeSlimeChange %~ f
where
f x | x > 1 = x - 1
| x < -1 = x + 1
f x | x > 100 = x - 100
| x < -100 = x + 100
| otherwise = 0
splitSlimeCrit' :: Point2 -> Point2 -> Int -> Creature -> World -> Maybe World
@@ -336,12 +329,14 @@ splitSlimeCrit p v cr = do
return (cr' & crPos . _xy .~ mp + (r1 + 0.51) *^ mvdir
-- & crType . slimeRad .~ r1
& crType . slimeSlime .~ round (r1 ^ (2 :: Int) * 100)
& crType . slimeCompression .~ rotateV (argV mvdir) (V2 r1 0)
& crType . slimeCompression .~ 1 -- rotateV (argV mvdir) (V2 r1 0)
& crType . slimeIsCompressing .~ False
& crDir .~ argV mvdir
,cr' & crPos . _xy .~ mp - (r2 + 0.51) *^ mvdir
-- & crType . slimeRad .~ r2
& crType . slimeSlime .~ round (r2^(2::Int) * 100)
& crType . slimeCompression .~ rotateV (argV (-mvdir)) (V2 r2 0)
& crType . slimeCompression .~ 1 -- rotateV (argV (-mvdir)) (V2 r2 0)
& crType . slimeIsCompressing .~ False
& crDir .~ argV (-mvdir)
& crType . slimeEngulfProgress .~ 0
)
@@ -349,7 +344,7 @@ splitSlimeCrit p v cr = do
cxy = cr ^. crPos . _xy
r = cr ^?! crType . slimeSlime . to slimeToRad
cr' = cr & crDamage .~ []
& crType . slimeRadWobble .~ 0
& crType . slimeSlimeChange .~ 0
& crType . slimeSplitTimer .~ 10
& crType . slimeIsCompressing .~ False