Store paths crossing block walls in block
This commit is contained in:
+23
-5
@@ -3,7 +3,8 @@ module Dodge.Path
|
||||
( pointTowardsImpulse
|
||||
, makePathBetween
|
||||
, makePathBetweenPs
|
||||
, removePathsCrossing
|
||||
-- , removePathsCrossing
|
||||
, obstructPathsCrossing
|
||||
, pairsToGraph
|
||||
, getNodePos
|
||||
, walkableNodeNear
|
||||
@@ -96,7 +97,7 @@ pointTowardsImpulse a b w = find (flip (isWalkable a) w) =<< makePathBetweenPs a
|
||||
-- [] -> return Nothing
|
||||
-- _ -> return $ Just $ ns !! i
|
||||
--
|
||||
pairsToGraph :: Set.Set (Point2,Point2) -> Gr Point2 PathEdge
|
||||
pairsToGraph :: Set.Set (Point2,Point2) -> (Map (V2 Point2) (Int,Int,PathEdge),Gr Point2 PathEdge)
|
||||
pairsToGraph pairs = addEdges nodemap gr $ S.each pairs
|
||||
where
|
||||
(nodemap,_,gr) = addNodes $ S.map fst (S.each pairs) <> S.map snd (S.each pairs)
|
||||
@@ -110,12 +111,29 @@ addNodes = runIdentity . S.fold_ f (mempty,0,Data.Graph.Inductive.empty) id
|
||||
f (nodemap,i,gr) p = case nodemap M.!? p of
|
||||
Just _ -> (nodemap,i,gr)
|
||||
Nothing -> (nodemap & at p ?~i ,i+1, insNode (i,p) gr)
|
||||
addEdges :: Map Point2 Int -> Gr Point2 PathEdge -> StreamOf (Point2,Point2) -> Gr Point2 PathEdge
|
||||
addEdges nodemap gr = runIdentity . S.fold_ f gr id
|
||||
addEdges :: Map Point2 Int -> Gr Point2 PathEdge -> StreamOf (Point2,Point2)
|
||||
-> (Map (V2 Point2) (Int,Int,PathEdge) , Gr Point2 PathEdge)
|
||||
addEdges nodemap gr = runIdentity . S.fold_ f (mempty,gr) id
|
||||
where
|
||||
f gr' (a,b) = insEdge (g a,g b,PathEdge a b (dist a b) mempty) gr'
|
||||
f (edgemap,gr') (a,b) = (M.insert (V2 a b) theedge edgemap
|
||||
, insEdge theedge gr'
|
||||
)
|
||||
where
|
||||
theedge = (g a,g b,PathEdge a b (dist a b) mempty)
|
||||
g a = nodemap M.! a
|
||||
|
||||
obstructPathsCrossing :: Point2 -> Point2 -> World -> ( World, [(Int,Int,PathEdge)])
|
||||
obstructPathsCrossing sp ep w =
|
||||
( w & pathGraph %~ updateedges
|
||||
, runIdentity $ S.toList_ edges
|
||||
)
|
||||
where
|
||||
edges = S.filter edgecrosses $ nearSeg _peZoning sp ep w
|
||||
edgecrosses (_,_,pe) = isJust $ intersectSegSeg sp ep (_peStart pe) (_peEnd pe)
|
||||
updateedges gr = runIdentity $ S.fold_ updateedge gr id edges
|
||||
updateedge gr (x,y,pe)
|
||||
= insEdge (x,y,pe & peObstacles . at BlockObstacle .~ Just ()) $ delEdge (x,y) gr
|
||||
|
||||
removePathsCrossing :: Point2 -> Point2 -> World -> World
|
||||
removePathsCrossing a b w = w
|
||||
-- & pathGraph .~ newGraph
|
||||
|
||||
Reference in New Issue
Block a user