diff --git a/src/Dodge/Creature/ReaderUpdate.hs b/src/Dodge/Creature/ReaderUpdate.hs index 68870b2b8..d51b16aa3 100644 --- a/src/Dodge/Creature/ReaderUpdate.hs +++ b/src/Dodge/Creature/ReaderUpdate.hs @@ -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 diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index 41d06901e..ad4f9b299 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -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 diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index 230874c6c..adadfa055 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -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 diff --git a/src/Dodge/WorldEvent/ThingsHit.hs b/src/Dodge/WorldEvent/ThingsHit.hs index e8754e961..20998f813 100644 --- a/src/Dodge/WorldEvent/ThingsHit.hs +++ b/src/Dodge/WorldEvent/ThingsHit.hs @@ -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 diff --git a/src/Dodge/Zoning/Creature.hs b/src/Dodge/Zoning/Creature.hs index e9232dcbb..ae8f49848 100644 --- a/src/Dodge/Zoning/Creature.hs +++ b/src/Dodge/Zoning/Creature.hs @@ -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 diff --git a/tags b/tags index b4a088674..b32dd006c 100644 --- a/tags +++ b/tags @@ -2779,6 +2779,7 @@ calcSmoothScroll src/Dodge/SmoothScroll.hs 11;" f calcTexCoord src/Tile.hs 19;" f canSee src/Dodge/Base/Collide.hs 321;" f canSeeIndirect src/Dodge/Base/Collide.hs 328;" f +canSpring src/Dodge/Update.hs 978;" f cancelExamineInventory src/Dodge/Item/BackgroundEffect.hs 23;" f capacitor src/Dodge/Item/Ammo.hs 67;" f card8Vec src/Dodge/Base/CardinalPoint.hs 17;" f @@ -2947,7 +2948,7 @@ crAwayFromPost src/Dodge/Creature/Test.hs 86;" f crBlips src/Dodge/RadarSweep.hs 88;" f crCamouflage src/Dodge/Creature/Picture.hs 33;" f crCanSeeCr src/Dodge/Creature/Test.hs 53;" f -crCrSpring src/Dodge/Update.hs 982;" f +crCrSpring src/Dodge/Update.hs 985;" f crCurrentEquipment src/Dodge/Creature/Statistics.hs 62;" f crDeathSounds src/Dodge/Creature/Vocalization.hs 45;" f crDexterity src/Dodge/Creature/Statistics.hs 19;" f @@ -5402,7 +5403,7 @@ updateCreatureStrides src/Dodge/Update.hs 370;" f updateDebris src/Dodge/Update.hs 665;" f updateDebrisChunk src/Dodge/Prop/Moving.hs 16;" f updateDebugMessageOffset src/Dodge/Update.hs 102;" f -updateDelayedEvents src/Dodge/Update.hs 1003;" f +updateDelayedEvents src/Dodge/Update.hs 1005;" f updateDisplaySections src/Dodge/DisplayInventory.hs 116;" f updateDistortion src/Dodge/Distortion.hs 8;" f updateDistortions src/Dodge/Update.hs 644;" f