From 75a98a572f784bd451b0e8b2e48898af255beb36 Mon Sep 17 00:00:00 2001 From: justin Date: Sat, 2 Jul 2022 12:14:31 +0100 Subject: [PATCH] Correct walkableNodeNear --- src/Dodge/Path.hs | 17 +++++++++++------ src/Dodge/Render/ShapePicture.hs | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Dodge/Path.hs b/src/Dodge/Path.hs index ceceb5712..246fcecf7 100644 --- a/src/Dodge/Path.hs +++ b/src/Dodge/Path.hs @@ -6,6 +6,7 @@ module Dodge.Path , removePathsCrossing , pairsToGraph , getNodePos + , walkableNodeNear ) where import Dodge.Data import Dodge.Base.Collide @@ -31,16 +32,20 @@ getNodePos i w = _pathGraph w `lab` i makePathBetween :: Point2 -> Point2 -> World -> Maybe [Int] makePathBetween a b w = do -- join $ sp <$> a' <*> b' <*> return (_pathGraph w) - na <- walkableNodeNear a - nb <- walkableNodeNear b + na <- walkableNodeNear w a + nb <- walkableNodeNear w b sp na nb (second _peDist (_pathGraph w)) where --nodesNear p = concat $ lookLookups (zoneNearPointIP p) (_pathPoints w) - nodesNear p = runIdentity . S.toList_ $ nearPoint _pnZoning p w - walkableNodeNear p = fmap fst . find (flip (isWalkable p) w . snd) $ nodesNear p +-- nodesNear p = runIdentity . S.toList_ $ nearPoint _pnZoning p w +-- walkableNodeNear p = fmap fst . find (flip (isWalkable p) w . snd) $ nodesNear p ---walkableNodeNear :: Point2 -> World -> Maybe Point2 ---walkableNodeNear p w = insideCirc +walkableNodeNear :: World -> Point2 -> Maybe Int +{-# INLINE walkableNodeNear #-} +walkableNodeNear w p = fmap fst . find (flip (isWalkable p) w . snd) $ nodesNear + where + --nodesNear = runIdentity . S.toList_ $ nearPoint _pnZoning p w + nodesNear = runIdentity . S.toList_ $ aroundPoint _pnZoning p w makePathBetweenPs :: Point2 -> Point2 -> World -> Maybe [Point2] makePathBetweenPs a b w = mapMaybe (lab $ _pathGraph w) <$> makePathBetween a b w diff --git a/src/Dodge/Render/ShapePicture.hs b/src/Dodge/Render/ShapePicture.hs index 53bc6574e..2a404da3c 100644 --- a/src/Dodge/Render/ShapePicture.hs +++ b/src/Dodge/Render/ShapePicture.hs @@ -122,8 +122,8 @@ drawCreatureDisplayTexts w = foldMap (creatureDisplayText w) (_creatures w) drawPathBetween :: World -> Picture drawPathBetween w = setLayer DebugLayer $ color yellow (foldMap (arrowPath . mapMaybe nodepos) nodelist) - <> foldMap (color green . arrow sp) (nodepos =<< nodelist ^? _Just . ix 0) - <> foldMap (color cyan . flip arrow ep) (nodepos =<< lastOf traverse =<< nodelist ^? _Just) + <> foldMap (color green . arrow sp) (nodepos =<< walkableNodeNear w sp) + <> foldMap (color cyan . flip arrow ep) (nodepos =<< walkableNodeNear w ep) where nodepos = (`getNodePos` w) nodelist = makePathBetween sp ep w