Cleanup
This commit is contained in:
@@ -106,6 +106,7 @@ flockACC w cr = fromMaybe cr $ do
|
||||
macr =
|
||||
safeMinimumOn (dist cpos . (^. crPos . _xy))
|
||||
. filter isFarACC
|
||||
. IM.elems
|
||||
$ crsNearCirc cpos 50 w
|
||||
return $ case macr of
|
||||
Nothing -> cr
|
||||
|
||||
@@ -4,6 +4,7 @@ module Dodge.Creature.State (
|
||||
invItemEffs,
|
||||
) where
|
||||
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Linear
|
||||
import NewInt
|
||||
import Control.Applicative
|
||||
@@ -296,6 +297,7 @@ setRBCreatureTargeting cr w ituse
|
||||
newtarg =
|
||||
safeMinimumOn (dist mwp . (^. crPos . _xy))
|
||||
. filter (canseepos . (^. crPos . _xy))
|
||||
. IM.elems
|
||||
$ crsNearCirc mwp 40 w
|
||||
canseepos p = hasLOS ((^. crPos . _xy) cr) p w
|
||||
mwp = w ^. cWorld . lWorld . lAimPos
|
||||
|
||||
+18
-21
@@ -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
|
||||
|
||||
@@ -181,7 +181,7 @@ wlsHitRadial p r = IM.mapMaybe f . wlsNearCirc p r
|
||||
-- v = normalizeV . vNormal . uncurry (-) $ _wlLine wl
|
||||
|
||||
crsHitRadial :: Point2 -> Float -> World -> [(Point2, Creature)]
|
||||
crsHitRadial p r = mapMaybe f . crsNearCirc p r
|
||||
crsHitRadial p r = mapMaybe f . IM.elems . crsNearCirc p r
|
||||
where
|
||||
f cr = do
|
||||
let cp = cr ^. crPos . _xy
|
||||
|
||||
@@ -33,8 +33,8 @@ crixsNearSeg = nearSeg crZoneSize _crZoning
|
||||
crIXsNearCirc :: Point2 -> Float -> World -> IS.IntSet
|
||||
crIXsNearCirc p r = crsNearRect (p + V2 r r) (p - V2 r r)
|
||||
|
||||
crsNearCirc :: Point2 -> Float -> World -> [Creature]
|
||||
crsNearCirc p r w = mapMaybe (\cid -> w ^? cWorld . lWorld . creatures . ix cid) . IS.toList
|
||||
crsNearCirc :: Point2 -> Float -> World -> IM.IntMap Creature
|
||||
crsNearCirc p r w = IM.restrictKeys (w ^. cWorld . lWorld . creatures)
|
||||
$ crIXsNearCirc p r w
|
||||
|
||||
crsNearRect :: Point2 -> Point2 -> World -> IS.IntSet
|
||||
|
||||
Reference in New Issue
Block a user