Refactor creature zoning
This commit is contained in:
@@ -11,15 +11,19 @@ module Dodge.WorldEvent.ThingsHit
|
||||
, wlsHitRadial
|
||||
)
|
||||
where
|
||||
import Dodge.Zoning.Creature
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Zone
|
||||
import Geometry
|
||||
|
||||
--import Data.Maybe
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
import Data.List (sortOn)
|
||||
import Data.Functor
|
||||
import Data.Bifunctor
|
||||
import StreamingHelp
|
||||
import qualified Data.IntSet as IS
|
||||
import qualified Streaming.Prelude as S
|
||||
|
||||
{- List those objects that appear on a line. -}
|
||||
@@ -29,15 +33,18 @@ thingsHit
|
||||
-> World
|
||||
-> StreamOf (Point2, Either Creature Wall)
|
||||
thingsHit sp ep w = void $ S.mergeOn (dist sp . fst)
|
||||
(S.map (second Left) (crsHit sp ep w))
|
||||
(S.map (second Left) (S.each $ crsHit sp ep w))
|
||||
(S.map (second Right) (wlsHit sp ep w))
|
||||
|
||||
crsHit :: Point2 -> Point2 -> World -> StreamOf (Point2, Creature)
|
||||
crsHit sp ep
|
||||
| sp == ep = const mempty
|
||||
| otherwise = sortStreamOn (dist sp . fst)
|
||||
crsHit :: Point2 -> Point2 -> World -> [(Point2, Creature)]
|
||||
crsHit sp ep w
|
||||
| sp == ep = mempty
|
||||
| otherwise = sortOn (dist sp . fst)
|
||||
. overlap1SegCrs sp ep
|
||||
. mapMaybe (\cid -> w ^? creatures . ix cid)
|
||||
. IS.toList
|
||||
. crsNearSeg sp ep
|
||||
$ w
|
||||
|
||||
thingHitFilt :: (Creature -> Bool) -> (Wall -> Bool)
|
||||
-> Point2 -> Point2 -> World -> Maybe (Point2, Either Creature Wall)
|
||||
@@ -77,8 +84,8 @@ wlsHitRadial p r = S.mapMaybe f . wlsInsideCirc p r
|
||||
where
|
||||
v = normalizeV $ vNormal $ uncurry (-.-) $ _wlLine wl
|
||||
|
||||
crsHitRadial :: Point2 -> Float -> World -> StreamOf (Point2, Creature)
|
||||
crsHitRadial p r = S.mapMaybe f . crsInsideCirc p r
|
||||
crsHitRadial :: Point2 -> Float -> World -> [(Point2, Creature)]
|
||||
crsHitRadial p r = mapMaybe f . crsNearCirc p r
|
||||
where
|
||||
f cr
|
||||
| dist cpos p <= r = Just (cpos +.+ r *.* normalizeV (p -.- cpos), cr)
|
||||
|
||||
Reference in New Issue
Block a user