Generalise path generation for arbitrary rooms
This commit is contained in:
+7
-14
@@ -14,25 +14,18 @@ import Data.Maybe
|
||||
--import Data.Graph.Inductive.PatriciaTree
|
||||
import Data.Graph.Inductive.Query.SP
|
||||
import Data.Graph.Inductive.Graph hiding ((&))
|
||||
import Control.Monad
|
||||
--import Control.Monad.State
|
||||
--import System.Random
|
||||
|
||||
-- ok, astar or something like it
|
||||
|
||||
makePathBetween :: Point2 -> Point2 -> World -> Maybe [Int]
|
||||
makePathBetween a b w = join $ sp <$> fmap fst a' <*> fmap fst b' <*> return g'
|
||||
makePathBetween a b w = do -- join $ sp <$> a' <*> b' <*> return (_pathGraph w)
|
||||
na <- walkableNodeNear a
|
||||
nb <- walkableNodeNear b
|
||||
sp na nb (_pathGraph w)
|
||||
where
|
||||
g' = _pathGraph w
|
||||
nsa = concat $ lookLookups (zoneAroundPoint a) (_pathPoints w)
|
||||
nsb = concat $ lookLookups (zoneAroundPoint b) (_pathPoints w)
|
||||
a' = find (flip (isWalkable a) w . snd) nsa
|
||||
b' = find (flip (isWalkable b) w . snd) nsb
|
||||
nodesNear p = concat $ lookLookups (zoneAroundPoint p) (_pathPoints w)
|
||||
walkableNodeNear p = fmap fst . find (flip (isWalkable p) w . snd) $ nodesNear p
|
||||
|
||||
makePathBetweenPs :: Point2 -> Point2 -> World -> Maybe [Point2]
|
||||
makePathBetweenPs a b w = mapMaybe (lab g') <$> makePathBetween b a w
|
||||
where
|
||||
g' = _pathGraph w
|
||||
makePathBetweenPs a b w = mapMaybe (lab $ _pathGraph w) <$> makePathBetween b a w
|
||||
|
||||
pointTowardsImpulse :: Point2 -> Point2 -> World -> Maybe Point2
|
||||
pointTowardsImpulse a b w = find (flip (isWalkable a) w) =<< makePathBetweenPs a b w
|
||||
|
||||
Reference in New Issue
Block a user