Allow creatures to path around chasms

This commit is contained in:
2025-10-16 23:52:25 +01:00
parent 0481f6e6f2
commit 5ba642c20a
4 changed files with 30 additions and 44 deletions
+13
View File
@@ -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