This commit is contained in:
2026-03-26 23:35:12 +00:00
parent 8b088425a9
commit fed607681b
6 changed files with 27 additions and 26 deletions
+18 -21
View File
@@ -966,43 +966,40 @@ radiusSpring r a b
simpleCrSprings :: World -> World
simpleCrSprings w =
IM.foldl' (flip crSpring) (w & cWorld . lWorld . lTestString .~ mempty) $
IM.filter (\cr -> cr ^. crPos . _z >= 0) $ w ^. cWorld . lWorld . creatures
IM.foldl' (flip crSpring) w $
IM.filter (canSpring) $ w ^. cWorld . lWorld . creatures
-- note that this may in rare cases not push creatures away from each other
crSpring :: Creature -> World -> World
crSpring c w =
foldl' (flip $ crCrSpring c) w $
crsNearCirc
(c ^. crPos . _xy)
(crRad $ c ^. crType)
w
IM.foldl' (flip $ crCrSpring c) w . IM.filter canSpring $
crsNearCirc (c ^. crPos . _xy) (crRad $ c ^. crType) w
canSpring :: Creature -> Bool
canSpring cr = cr ^. crPos . _z >= 0 && case cr ^. crHP of
HP{} -> True
CrIsCorpse{} -> True
CrIsGibs -> False
CrIsPitted -> False
crCrSpring :: Creature -> Creature -> World -> World
crCrSpring c1 c2
| id1 == id2 = id
| vec == V2 0 0 = id
| diff >= comRad || nopush c1 || nopush c2
= id
| diff >= comRad = id
| otherwise =
(cWorld . lWorld . creatures
%~ ( (ix id1 . crPos . _xy +~ overlap1)
. (ix id2 . crPos . _xy -~ overlap2)
))
. (cWorld . lWorld . lTestString .:~ show id1 <> " " <> show id2 )
( cWorld . lWorld . creatures
%~ ( (ix id1 . crPos . _xy +~ overlap c2)
. (ix id2 . crPos . _xy -~ overlap c1)
)
)
where
nopush cr = case cr ^. crHP of
HP {} -> False
CrIsCorpse {} -> False
CrIsGibs -> True
CrIsPitted -> True
id1 = _crID c1
id2 = _crID c2
vec = c1 ^. crPos . _xy - c2 ^. crPos . _xy
diff = magV vec
comRad = crRad (c1 ^. crType) + crRad (c2 ^. crType)
overlap1 = ((comRad - diff) * crMass (_crType c2) * 0.5 / massT) *^ signorm vec
overlap2 = ((comRad - diff) * crMass (_crType c1) * 0.5 / massT) *^ signorm vec
overlap c = ((comRad - diff) * crMass (_crType c) * 0.5 / massT) *^ signorm vec
massT = crMass (_crType c1) + crMass (_crType c2)
updateDelayedEvents :: World -> World