Cleanup: broken pathfinding

This commit is contained in:
2021-11-16 18:05:47 +00:00
parent cb8cbe03a4
commit ebe9ad6b90
42 changed files with 491 additions and 301 deletions
+16 -1
View File
@@ -9,6 +9,8 @@ module Dodge.Room.Link
, shiftRoomBy
, shiftLinkBy
, doRoomShift
, sortOutLinksOn
, filterSortOutLinksOn
, randomiseAllLinks
, filterLinks
, changeLinkTo
@@ -18,7 +20,7 @@ module Dodge.Room.Link
, invShiftLinkBy
, finalLinksUpdate
) where
import Dodge.LevelGen
import Dodge.Placement.PlaceSpot
import Dodge.LevelGen.Data
import Dodge.RandomHelp
import Geometry
@@ -34,6 +36,19 @@ randomiseOutLinks r = do
newLinks <- shuffle $ init $ _rmLinks r
return $ r {_rmLinks = newLinks ++ [last $ _rmLinks r]}
sortOutLinksOn :: Ord b => ((Point2,Float) -> b) -> Room -> Room
sortOutLinksOn f = rmLinks %~ dosort
where
dosort [] = []
dosort xs = sortOn f (init xs) ++ [last xs]
filterSortOutLinksOn :: Ord b => ((Point2,Float) -> Bool) -> ((Point2,Float) -> b) -> Room -> Room
filterSortOutLinksOn test f = rmLinks %~ dosort
where
dosort [] = []
dosort xs = let (ys,zs) = partition test (init xs)
in sortOn f ys ++ zs ++ [last xs]
{- Shuffle all links of a room randomly. -}
randomiseAllLinks :: RandomGen g => Room -> State g Room
randomiseAllLinks r = do