Cleanup, change creature height from Maybe Float to Float

This commit is contained in:
2026-05-09 19:50:53 +01:00
parent 72056e5e3e
commit dfb451c450
5 changed files with 87 additions and 103 deletions
+6 -13
View File
@@ -174,20 +174,13 @@ collide3Wall sp wl (ep, mo) = maybe (ep, mo) (,Just (n, OWall wl)) $ intersectSe
collide3Creature :: Point3 -> Creature -> (Point3, MPO) -> (Point3, MPO)
collide3Creature sp cr (ep, m) = fromMaybe (ep, m) $ do
h <- crHeight cr
(p, n) <-
fst $
intersectCylSeg
(cr ^. crPos)
(crRad $ cr ^. crType)
h
sp
ep
let h = crHeight cr
(p, n) <- fst $ intersectCylSeg (cr ^. crPos) (crRad $ cr ^. crType) h sp ep
return (p, Just (n, OCreature cr))
crHeight :: Creature -> Maybe Float
crHeight :: Creature -> Float
crHeight cr = case cr ^. crHP of
HP{} -> Just $ case cr ^. crType of
HP{} -> case cr ^. crType of
HoverCrit {} -> 10
ChaseCrit {} -> 25
Avatar {} -> 25
@@ -198,8 +191,8 @@ crHeight cr = case cr ^. crHP of
HiveCrit {} -> 25
BarrelCrit{} -> 20
_ -> error $ "Need to define crHeight for this crType:\n" <> unlines (prettyShort (cr ^. crType))
CrIsCorpse{} -> Just 5
AvatarDestroyed{} -> Nothing
CrIsCorpse{} -> 5
AvatarDestroyed{} -> 0
wallToSurface :: Wall -> (Point3, Point3, [(Point3, Point3)])
wallToSurface wl = (g x, g $ vNormal (x - y), [(g x, g (y - x)), (g y, g (x - y))])
+10 -12
View File
@@ -247,35 +247,32 @@ updateCalmBee cr cid w
updateSlimeCrit :: Int -> World -> World
updateSlimeCrit cid w
| r < 5 = w & cWorld . lWorld . creatures . at cid .~ Nothing
| cr ^?! crType . slimeSlime < 2500
= w & cWorld . lWorld . creatures . at cid .~ Nothing
| 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 w' <- splitSlimeCrit' hitp hitv cid cr w = w'
| (cr ^?! crType . slimeIsCompressing) && 1 > p
= let (w',g) = runState (setSlimeDir cid (cr & crDamage .~ []) w) (w ^. randGen)
= let (w',g) = runState (setSlimeDir cid cr w) (w ^. randGen)
in w' & randGen .~ g
| otherwise = updateCarriage cid $ w
& cWorld . lWorld . creatures . ix cid .~ mvslime
& cWorld . lWorld . creatures . ix cid %~ mvslime
& cWorld . lWorld . creatures . ix cid . crDamage .~ []
& tocr %~ doSlimeRadChange
& tocr . crType . slimeSplitTimer %~ fsst
& tocr . crType . slimeEngulfProgress %~ (max 0 . subtract 0.5)
where
fsst Nothing = Nothing
fsst (Just (x,ps))
| x > 0 = Just (x-1,ps)
| otherwise = Nothing
fsst (Just (x,ps)) | x > 0 = Just (x-1,ps)
fsst _ = Nothing
tocr = cWorld . lWorld . creatures . ix cid
cr = w ^?! cWorld . lWorld . creatures . ix cid
v = 0.1 *^ unitVectorAtAngle (cr ^. crDir)
mvslime = cr & crType . slimeCompression +~ f (0.1/r)
& crPos . _xy +~ v
mvslime cr' = cr' & crType . slimeCompression +~ f (0.1/r)
& crPos . _xy +~ 0.1 *^ unitVectorAtAngle (cr' ^. crDir)
& crType . slimeIsCompressing %~ f'
f | t = negate
f | cr ^?! crType . slimeIsCompressing = negate
| otherwise = id
f' | p > 1.5 = const True
| otherwise = id
t = cr ^?! crType . slimeIsCompressing
r = cr ^?! crType . slimeSlime . to slimeToRad
p = cr ^?! crType . slimeCompression
@@ -289,6 +286,7 @@ setSlimeDir cid cr w = do
return $ fromMaybe w $ splitSlimeCrit' (x + cxy) (unitVectorAtAngle d) cid cr w
else return $ w & tocr . crDir .~ d
& tocr . crType . slimeIsCompressing .~ False
& tocr . crDamage .~ mempty
where
tocr = cWorld . lWorld . creatures . ix cid
cxy = cr ^. crPos . _xy
+8 -15
View File
@@ -1033,11 +1033,8 @@ crCrSpring c1 c2
| otherwise = cWorld . lWorld . creatures %~ ( olap c1 c2 . olap' c2 c1)
where
z c = c ^. crPos . _z
h c = fmap (+ z c) (crHeight c)
diffheight = fromMaybe True $ do
h1 <- h c1
h2 <- h c2
return $ z c1 > h2 || z c2 > h1
h c = crHeight c + z c
diffheight = z c1 > h c2 || z c2 > h c1
olap a b = ix (a ^. crID) . crPos . _xy +~ overlap b
olap' a b = ix (a ^. crID) . crPos . _xy -~ overlap b
id1 = _crID c1
@@ -1080,22 +1077,18 @@ slimeFood cr = case cr ^. crType of
_ -> False
feedSlime :: Creature -> Creature -> World -> World
feedSlime s c w = fromMaybe w $ do
ch <- crHeight c
return $ if min 10 r1 + s ^?! crType . slimeEngulfProgress < max 15 (ch + 2)
feedSlime s c w = if min 10 r1 + s ^?! crType . slimeEngulfProgress < max 15 (ch + 2)
then w & cWorld.lWorld.creatures.ix (s^.crID).crType.slimeEngulfProgress%~ (min r1.(+0.7))
& slimeSuck s c
else
w
else w
& cWorld . lWorld . creatures . at (c ^. crID) %~ destroyCreature
& cWorld . lWorld . creatures . ix (s ^. crID) %~ f
& cWorld . lWorld . creatures . ix (s ^. crID) . crType . slimeSlime +~ x
& cWorld . lWorld . creatures . ix (s ^. crID) . crType . slimeSlimeChange +~ x
& slimeEatSound (s ^. crID) (s ^. crPos . _xy)
where
f cr = cr
& crType . slimeSlime +~ round (r2^(2::Int) * 100)
& crType . slimeSlimeChange +~ round (r2^(2::Int) * 100)
ch = crHeight c
x = round $ (c^.crType.to crRad)^(2::Int) * 100
r1 = s ^?! crType . slimeSlime . to slimeToRad
r2 = c ^. crType . to crRad
fuseSlimes :: Creature -> Creature -> World -> World
fuseSlimes c1 c2 = (cWorld . lWorld . creatures . ix mini .~ c)
+1
View File
@@ -374,6 +374,7 @@ intersectCircLine c r x y =
f :: Float -> Point2
f a = x + (a *.* (y - x))
--I believe the Maybes are entry or exit points, and reflections in these points
intersectCylSeg :: Point3 -> Float -> Float -> Point3 -> Point3 ->
(Maybe (Point3, Point3), Maybe (Point3, Point3))
intersectCylSeg p r h s e = fromMaybe (Nothing, Nothing) $ do