Track slime amount using ints

This commit is contained in:
2026-05-06 15:40:31 +01:00
parent e927de6508
commit b76148ae2a
12 changed files with 203 additions and 147 deletions
+1 -1
View File
@@ -193,7 +193,7 @@ crHeight cr = case cr ^. crHP of
Avatar {} -> 25
CrabCrit {} -> 25
SlinkCrit {} -> 25
SlimeCrit {_slimeRad = r} -> min 15 r
SlimeCrit {_slimeSlime = r} -> min 15 $ slimeToRad r
BeeCrit {} -> 10
HiveCrit {} -> 25
BarrelCrit{} -> 20
+4 -4
View File
@@ -69,13 +69,13 @@ slimeCrit :: Creature
slimeCrit = defaultCreature
& crName .~ "slimeCrit"
& crHP .~ HP 1000
& crType .~ SlimeCrit r 0 0 (V2 r 0) False 0
& crType .~ SlimeCrit r 0 0 (V2 (slimeToRad r) 0) False 0
& crFaction .~ ColorFaction (light green)
& crPerception . cpVision . viFOV .~ FloatFOV pi
& crActionPlan .~ SlimeIntelligence
& crStance . carriage .~ Crawling
where
r = 50
r = 250000
hoverCrit :: Creature
hoverCrit =
@@ -91,7 +91,7 @@ beeCrit =
defaultCreature
& crName .~ "beeCrit"
& crHP .~ HP 100
& crType .~ BeeCrit 0 Nothing 0 0 0 Nothing
& crType .~ BeeCrit 0 Nothing 0 0 0 Nothing 1
& crFaction .~ ColorFaction yellow
& crStance . carriage .~ Flying 15
@@ -100,6 +100,6 @@ hiveCrit =
defaultCreature
& crName .~ "hiveCrit"
& crHP .~ HP 100000
& crType .~ HiveCrit mempty 0
& crType .~ HiveCrit mempty 0 400
& crStance . carriage .~ Rooted
& crFaction .~ ColorFaction yellow
+2 -2
View File
@@ -13,6 +13,6 @@ crMass = \case
BarrelCrit{} -> 10
SlinkCrit{} -> 100
LampCrit {} -> 3
SlimeCrit {_slimeRad = r} -> r * r / 10
BeeCrit {_beeSlime = x} -> 3 + x
SlimeCrit {_slimeSlime = r} -> fromIntegral r / 1000
BeeCrit {_beeSlime = x} -> 3 + fromIntegral x / 100
HiveCrit {} -> 100
+2 -2
View File
@@ -64,7 +64,7 @@ drawSlimeCrit cr = colorSH green
& each %~ rotateV (-cr ^. crDir)
& each %~ (((r-cr^?!crType.slimeRadWobble)/r) *^)
where
r = cr ^?! crType . slimeRad
r = cr ^?! crType . slimeSlime . to slimeToRad
p = cr ^?! crType . slimeCompression
d = normalize p
s = norm p / r
@@ -131,7 +131,7 @@ drawBeeCrit cr = colorSH col
col | cr ^?! crType . beeAggro > 0 = red
| otherwise = yellow
f | Mounted {} <- cr ^. crStance . carriage
= each . sfVs . each . _xy %~ scaleAlong (V2 0 1) (1 + g ( modTo 1 (cr ^?! crType . beeSlime)))
= each . sfVs . each . _xy %~ scaleAlong (V2 0 1) (1 + g ( modTo 1 (cr ^?! crType . beeSlime . to ((/100) . fromIntegral))))
| otherwise = id
g x | x > 0.5 = 1 - x
| otherwise = x
+2 -2
View File
@@ -11,11 +11,11 @@ crRad = \case
ChaseCrit {} -> 10
CrabCrit {} -> 10
HoverCrit {} -> 8
BeeCrit {_beeSlime = x} -> sqrt $ 2^(2::Int) + x
BeeCrit {_beeSlime = x} -> sqrt $ 4 + (fromIntegral x / 100)
SwarmCrit -> 2
AutoCrit -> 10
BarrelCrit{} -> 10
LampCrit {} -> 3
SlinkCrit {} -> 10
HiveCrit {} -> 20
SlimeCrit {_slimeRad = r,_slimeRadWobble = x} -> r - x
SlimeCrit {_slimeSlime = r,_slimeRadWobble = x} -> slimeToRad r - x
+1 -1
View File
@@ -57,7 +57,7 @@ updateCarriage' cid cr w = \case
mcr <- w ^? cWorld . lWorld . creatures . ix mid
mp <- mcr ^? crPos
d <- mcr ^? crType . slimeCompression
r <- mcr ^? crType . slimeRad
r <- mcr ^? crType . slimeSlime . to slimeToRad
return $ w & tocr . crPos .~ mp + (p & _xy %~ compressionScale ((1/r) *^ d))
where
tocr = cWorld . lWorld . creatures . ix cid
+44 -19
View File
@@ -84,16 +84,20 @@ updateHiveCrit cr cid w
| Just x <- cr ^? crType . hiveChildren . to IS.size
, x < nbees
, Just y <- cr ^? crType . hiveGestation
, y == 0 = w
, y == 0
, Just z <- cr ^? crType . hiveSlime
, z >= 400
= w
& tocr . crType . hiveChildren %~ IS.insert nid
& tocr . crType . hiveGestation .~ 50
& cWorld . lWorld . creatures . at nid ?~ ncr
& tocr . crType . hiveSlime -~ 400
| Just x <- cr ^? crType . hiveChildren . to IS.size
, x < nbees = w
& tocr . crType . hiveGestation %~ (max 0 . subtract 1)
| otherwise = w
where
nbees = 25
nbees = 15
tocr = cWorld . lWorld . creatures . ix cid
nid = IM.newKey $ w ^. cWorld . lWorld . creatures
ncr = beeCrit & crPos .~ (cr ^. crPos + (0 & _xy +~ 25))
@@ -108,9 +112,18 @@ updateBeeFromPheremones cr cid w
f bp = distance (cr ^. crPos . _xy) (bp ^. bpPos . _xy) < 20
updateBeeCrit :: Creature -> Int -> World -> World
updateBeeCrit cr
| cr ^?! crType . beeAggro > 0 = updateAggroBee cr
| otherwise = updateCalmBee cr
updateBeeCrit cr cid
| cr ^?! crType . beeAggro > 0 = updateAggroBee cr cid
| otherwise = beeLifespanCheck cr cid . updateCalmBee cr cid
beeLifespanCheck :: Creature -> Int -> World -> World
beeLifespanCheck cr cid
| Just ls <- cr ^? crType . beeLifespan
, Just x <- cr ^? crType . beeSlime
, ls < 1
, x < 5
= cWorld . lWorld . creatures . ix cid . crHP . _HP -~ 1
| otherwise = id
updateAggroBee :: Creature -> Int -> World -> World
updateAggroBee cr cid w
@@ -158,15 +171,19 @@ updateCalmBee cr cid w
| Just hcr <- gethive
, distance (cr ^. crPos . _xy) (hcr ^. crPos . _xy) < 30
, Just x <- cr ^? crType . beeSlime
, x >= 0.5 = w & tocr . crType . beeSlime -~ 0.5
, x >= 50 = w
& tocr . crType . beeSlime -~ 50
& cWorld . lWorld . creatures . ix (hcr ^. crID) . crType . hiveSlime +~ 50
| Just x <- cr ^? crType . beeSlime
, x < 0.5
, x < 50
, Just hcr <- gethive
, distance (cr ^. crPos . _xy) (hcr ^. crPos . _xy) < 30
, Just ReturnToHive <- cr ^? crActionPlan . apStrategy = startsearch
| Just ReturnToHive <- cr ^? crActionPlan . apStrategy = w
| Just x <- cr ^? crType . beeSlime
, x >= 15 = starthivereturn
, x >= 1500 = starthivereturn
& randGen .~ gsa
& tocr . crType . beeLifespan %~ max 0 . subtract sa
| Just mid <- cr ^? crStance . carriage . mountID
, mountshakeoff mid = startsearch
| Nothing <- cr ^? crActionPlan . apStrategy . harvestTarget
@@ -177,10 +194,11 @@ updateCalmBee cr cid w
| Just tid <- cr ^? crStance . carriage . mountID
, Just SlimeCrit{} <- w ^? cWorld . lWorld . creatures . ix tid . crType = w
& tocr . crType . beeSlime +~ sspeed
& cWorld . lWorld . creatures . ix tid . crType . slimeRad %~ (sqrt . subtract sspeed . (^(2::Int)))
-- & cWorld . lWorld . creatures . ix tid . crType . slimeRad %~ (sqrt . subtract sspeed . (^(2::Int)))
& cWorld . lWorld . creatures . ix tid . crType . slimeSlime -~ sspeed
| Just (tcr,ti) <- gettarg
, distance (cr ^. crPos . _xy) (tcr ^. crPos . _xy) < 0.8*crRad (tcr ^. crType)
, Just r <- tcr ^? crType . slimeRad
, 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)))
@@ -193,6 +211,7 @@ updateCalmBee cr cid w
& tocr . crActionPlan . apStrategy . searchTimer %~ (max 0 . subtract 1)
| otherwise = startsearch
where
(sa,gsa) = runState (takeOne [0,1]) (w ^. randGen)
starthivereturn = fromMaybe w $ do
hcr <- gethive
return $ w
@@ -213,11 +232,12 @@ updateCalmBee cr cid w
mcr <- w ^? cWorld . lWorld . creatures . ix mid
SlimeCrit {_slimeSplitTimer = x} <- mcr ^? crType
return $ x > 0
sspeed = 0.05
--sspeed = 0.05
sspeed = 5
gettarg = do
i <- cr ^? crActionPlan . apStrategy . harvestTarget
tcr <- w ^? cWorld . lWorld . creatures . ix i
x <- tcr ^? crType . slimeRad
x <- tcr ^? crType . slimeSlime . to slimeToRad
guard $ x > 12
return (tcr,i)
gethive = do
@@ -225,7 +245,7 @@ updateCalmBee cr cid w
w ^? cWorld . lWorld . creatures . ix i
tocr = cWorld . lWorld . creatures . ix cid
istarget tcr = fromMaybe False $ do
r <- tcr ^? crType . slimeRad
r <- tcr ^? crType . slimeSlime . to slimeToRad
return $ r > 12
slimeCritUpdate :: Int -> World -> World
@@ -260,7 +280,7 @@ slimeCritUpdate cid w
f' | norm p > 3*r/2 = const True
| otherwise = id
t = cr ^?! crType . slimeIsCompressing
r = cr ^?! crType . slimeRad
r = cr ^?! crType . slimeSlime . to slimeToRad
p = cr ^?! crType . slimeCompression
setSlimeDir :: Int -> Creature -> World -> State StdGen World
@@ -281,7 +301,7 @@ setSlimeDir cid cr w = do
tocr = cWorld . lWorld . creatures . ix cid
-- tocr' i = cWorld . lWorld . creatures . at i
cxy = cr ^. crPos . _xy
r = cr ^?! crType . slimeRad
r = cr ^?! crType . slimeSlime . to slimeToRad
doSlimeRadChange :: Creature -> Creature
@@ -314,18 +334,20 @@ splitSlimeCrit p v cr = do
| isLHS p (p+v) cxy = normalize (vNormal v)
| otherwise = - normalize (vNormal v)
return (cr' & crPos . _xy .~ mp + (r1 + 0.51) *^ mvdir
& crType . slimeRad .~ r1
-- & crType . slimeRad .~ r1
& crType . slimeSlime .~ round (r1 ^ (2 :: Int) * 100)
& crType . slimeCompression .~ rotateV (argV mvdir) (V2 r1 0)
& crDir .~ argV mvdir
,cr' & crPos . _xy .~ mp - (r2 + 0.51) *^ mvdir
& crType . slimeRad .~ r2
-- & crType . slimeRad .~ r2
& crType . slimeSlime .~ round (r2^(2::Int) * 100)
& crType . slimeCompression .~ rotateV (argV (-mvdir)) (V2 r2 0)
& crDir .~ argV (-mvdir)
& crType . slimeEngulfProgress .~ 0
)
where
cxy = cr ^. crPos . _xy
r = cr ^?! crType . slimeRad
r = cr ^?! crType . slimeSlime . to slimeToRad
cr' = cr & crDamage .~ []
& crType . slimeRadWobble .~ 0
& crType . slimeSplitTimer .~ 10
@@ -412,7 +434,10 @@ crDeathEffects cr w = case cr ^. crType of
return $ w & cWorld . lWorld . creatures . ix hid . crType . hiveChildren %~ IS.delete (cr ^. crID)
_ -> w
where
beepheremone = cWorld . lWorld . beePheremones .:~ BPheremone (cr ^. crPos) (cr ^. crPos - cr ^. crOldPos) 200
beepheremone
| Just x <- cr ^? crType . beeLifespan
, x < 1 = id
| otherwise = cWorld . lWorld . beePheremones .:~ BPheremone (cr ^. crPos) (cr ^. crPos - cr ^. crOldPos) 200
startDeathTimer :: Creature -> Creature
startDeathTimer cr = cr & crDeathTimer ?~ case cr ^. crType of
+7 -2
View File
@@ -78,7 +78,7 @@ data CreatureType
, _slinkHeadPos :: Point3Q
}
| SlimeCrit
{ _slimeRad :: Float
{ _slimeSlime :: Int -- note multiplied by 100
, _slimeRadWobble :: Float
, _slimeSplitTimer :: Int
, _slimeCompression :: Point2
@@ -86,22 +86,27 @@ data CreatureType
, _slimeEngulfProgress :: Float
}
| BeeCrit
{ _beeSlime :: Float
{ _beeSlime :: Int
, _beeHive :: Maybe Int
, _startStopMv :: Int
, _beeAggro :: Int
, _meleeCooldown :: Int
, _beeRandomMovement :: Maybe FootForward
, _beeLifespan :: Int
}
| HiveCrit
{ _hiveChildren :: IS.IntSet
, _hiveGestation :: Int
, _hiveSlime :: Int
}
| SwarmCrit
| AutoCrit
| BarrelCrit {_barrelType :: BarrelType}
| LampCrit {_lampHeight :: Float, _lampColor :: Point3, _lampLSID :: Maybe Int}
slimeToRad :: Int -> Float
slimeToRad x = sqrt $ fromIntegral x * 0.01
data AvatarPosture = AvPosture
data CreatureShape
+6 -3
View File
@@ -56,13 +56,16 @@ tutAnoTree :: State LayoutVars MTRS
tutAnoTree = do
foldMTRS
[ tToBTree "TutStartRez" . return . cleatOnward <$> tutRezBox
, corDoor
, chasmSpitTerminal
-- , corDoor
-- , chasmSpitTerminal
-- , tToBTree "" . return . cleatOnward <$> slowDoorRoom
, corDoor
--, tToBTree "" . return . cleatOnward <$> (xChasm 200 200
, tToBTree "" . return . cleatOnward <$> ((putSingleLight =<< roomRectAutoLights 300 300)
<&> rmPmnts <>~ [sps0 (PutCrit slimeCrit) & plSpot . psPos .~ V2 150 100
<&> rmPmnts <>~
[sps0 (PutCrit slimeCrit) & plSpot . psPos .~ V2 150 100
,sps0 (PutCrit slimeCrit) & plSpot . psPos .~ V2 50 50
,sps0 (PutCrit slimeCrit) & plSpot . psPos .~ V2 50 150
, sps0 (PutCrit hiveCrit) & plSpot . psPos .~ V2 250 50
, sps0 (PutCrit chaseCrit) & plSpot . psPos .~ V2 250 100
]
+11 -1
View File
@@ -47,8 +47,18 @@ isBee cr = case cr ^. crType of
BeeCrit{} -> True
_ -> False
crslime :: Creature -> Int
crslime cr = case cr ^. crType of
SlimeCrit {_slimeSlime=r} | HP{} <- cr ^. crHP -> r -- r ^ (2::Int)
HiveCrit {_hiveSlime=x} -> x
BeeCrit {_beeSlime=x} -> 400 + x
_ -> 0
crs :: Universe -> [Creature]
crs u = u ^.. uvWorld . cWorld . lWorld . creatures . each
testStringInit :: Universe -> [String]
testStringInit _ = mempty
testStringInit u = [show . getSum $ foldMap (Sum . crslime) (crs u)]
--u = u ^.. tocrs . each . filtered isBee . crActionPlan . apStrategy . to show
-- u ^.. tocrs . ix 1 . crPos . _xy . to show
-- <> u ^.. tocrs . ix 1 . crType . slimeCompression . to show
+12 -6
View File
@@ -1076,6 +1076,7 @@ slimeFood cr = case cr ^. crType of
Avatar{} -> True
ChaseCrit{} -> True
CrabCrit {} -> True
BeeCrit{} | CrIsCorpse{} <- cr ^. crHP -> True
_ -> False
feedSlime :: Creature -> Creature -> World -> World
@@ -1090,10 +1091,12 @@ feedSlime s c w = fromMaybe w $ do
& cWorld . lWorld . creatures . ix (s ^. crID) %~ f
& slimeEatSound (s ^. crID) (s ^. crPos . _xy)
where
f cr = cr & crType . slimeRad .~ r
f cr = cr -- & crType . slimeRad .~ r
& crType . slimeSlime .~ round (r^(2::Int) * 100)
& crType . slimeRadWobble +~ r - r1
& crType . slimeCompression %~ ((r/r1) *^)
r1 = s ^?! crType . slimeRad
--r1 = s ^?! crType . slimeRad
r1 = s ^?! crType . slimeSlime . to slimeToRad
r2 = c ^. crType . to crRad
r = sqrt (r1*r1 + r2*r2)
@@ -1102,18 +1105,21 @@ fuseSlimes c1 c2 = (cWorld . lWorld . creatures . ix mini .~ c)
. (cWorld . lWorld . creatures . at maxi .~ Nothing)
. slimeEatSound i1 (c ^. crPos . _xy)
where
c' | c1 ^?! crType . slimeRad > c2 ^?! crType . slimeRad = c1
--c' | c1 ^?! crType . slimeRad > c2 ^?! crType . slimeRad = c1
c' | c1 ^?! crType . slimeSlime > c2 ^?! crType . slimeSlime = c1
| otherwise = c2
mini = min i1 i2
maxi = max i1 i2
i1 = c1 ^. crID
i2 = c2 ^. crID
c = c' & crType . slimeRad .~ r
c = c' & crType . slimeSlime .~ round (r^(2::Int) * 100)
& crType . slimeRadWobble +~ r - max r1 r2
& crType . slimeCompression %~ ((r/max r1 r2) *^)
& crID .~ mini
r1 = c1 ^?! crType . slimeRad
r2 = c2 ^?! crType . slimeRad
-- r1 = c1 ^?! crType . slimeRad
-- r2 = c2 ^?! crType . slimeRad
r1 = c1 ^?! crType . slimeSlime . to slimeToRad
r2 = c2 ^?! crType . slimeSlime . to slimeToRad
r = sqrt (r1*r1 + r2*r2)
slimeEatSound :: Int -> Point2 -> World -> World