Allow creatures to path around chasms
This commit is contained in:
@@ -5,6 +5,7 @@ module Dodge.Path (
|
||||
makePathBetweenPs,
|
||||
-- , removePathsCrossing
|
||||
obstructPathsCrossing,
|
||||
obstructPathsCrossing',
|
||||
pairsToGraph,
|
||||
getNodePos,
|
||||
walkableNodeNear,
|
||||
@@ -44,6 +45,7 @@ makePathBetween = makePathUsing $ not . pathEdgeObstructed
|
||||
|
||||
pathEdgeObstructed :: PathEdge -> Bool
|
||||
pathEdgeObstructed pe = DoorObstacle `Set.member` obs || BlockObstacle `Set.member` obs
|
||||
|| ChasmObstacle `Set.member` obs
|
||||
where
|
||||
obs = _peObstacles pe
|
||||
|
||||
@@ -158,6 +160,17 @@ obstructPathsCrossing obstacletype sp' ep w =
|
||||
updateedge gr (PathEdgeNodes x y pe) =
|
||||
insEdge (x, y, pe & peObstacles . at obstacletype ?~ ()) $ delEdge (x, y) gr
|
||||
|
||||
obstructPathsCrossing' :: EdgeObstacle -> Point2 -> Point2 -> World
|
||||
-> World
|
||||
obstructPathsCrossing' obstacletype sp' ep w =
|
||||
w & cWorld . pathGraph %~ updateedges
|
||||
where
|
||||
es = Set.filter edgecrosses $ pesNearSeg sp' ep w
|
||||
edgecrosses (PathEdgeNodes _ _ pe) = isJust $ intersectSegSeg sp' ep (_peStart pe) (_peEnd pe)
|
||||
updateedges gr = foldl' updateedge gr es
|
||||
updateedge gr (PathEdgeNodes x y pe) =
|
||||
insEdge (x, y, pe & peObstacles . at obstacletype ?~ ()) $ delEdge (x, y) gr
|
||||
|
||||
snapToGrid :: Set (Point2,Point2) -> Set (Point2, Point2)
|
||||
snapToGrid = Set.map (over each (fmap (fromIntegral . f)))
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user