Transition to new room datatypes, first separate out/inlinks

This commit is contained in:
2021-11-23 17:27:33 +00:00
parent 67b0d694af
commit 0f4040807a
19 changed files with 119 additions and 87 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ addRoomLinkDecorations rms w = w & decorations %~
IM.insertWithNewKeys (map roomLinkDecorations rms) IM.insertWithNewKeys (map roomLinkDecorations rms)
roomLinkDecorations :: Room -> Picture roomLinkDecorations :: Room -> Picture
roomLinkDecorations rm = pictures . map linkDecoration $ _rmLinks rm roomLinkDecorations rm = pictures . map linkDecoration $ _rmOutLinks rm ++ _rmInLinks rm
linkDecoration :: (Point2,Float) -> Picture linkDecoration :: (Point2,Float) -> Picture
linkDecoration (p,a) = setLayer 1 . onLayer DebugLayer . color red $ line [p, p +.+ 20 *.* unitVectorAtAngle (a - pi/2)] linkDecoration (p,a) = setLayer 1 . onLayer DebugLayer . color red $ line [p, p +.+ 20 *.* unitVectorAtAngle (a - pi/2)]
+2 -1
View File
@@ -7,8 +7,9 @@ import qualified Data.IntMap.Strict as IM
defaultRoom :: Room defaultRoom :: Room
defaultRoom = Room defaultRoom = Room
{ _rmPolys = [] { _rmPolys = []
, _rmLinks = [] , _rmOutLinks = []
, _rmLinkEff = [] , _rmLinkEff = []
, _rmInLinks = []
, _rmPos = [] , _rmPos = []
, _rmPath = [] , _rmPath = []
, _rmPmnts = [] , _rmPmnts = []
+2 -1
View File
@@ -63,7 +63,8 @@ assigning no bounds will allow rooms to overlap.
-} -}
data Room = Room data Room = Room
{ _rmPolys :: [ [Point2] ] { _rmPolys :: [ [Point2] ]
, _rmLinks :: [(Point2,Float)] , _rmOutLinks :: [(Point2,Float)]
, _rmInLinks :: [(Point2,Float)]
-- update the room when assigning the next link to an adjacent room with the head of of this list, return the tail -- update the room when assigning the next link to an adjacent room with the head of of this list, return the tail
, _rmLinkEff :: [(Point2,Float) -> Room -> Room] , _rmLinkEff :: [(Point2,Float) -> Room -> Room]
, _rmPos :: [RoomPos] , _rmPos :: [RoomPos]
+10 -11
View File
@@ -23,7 +23,8 @@ airlock = takeOne [airlock0,airlock90,airlockCrystal,airlockZ]
airlock0 :: Room airlock0 :: Room
airlock0 = defaultRoom airlock0 = defaultRoom
{ _rmPolys = [ rectNSWE 100 0 0 40 , rectNSWE 65 35 (-40) 20 ] { _rmPolys = [ rectNSWE 100 0 0 40 , rectNSWE 65 35 (-40) 20 ]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = [(V2 20 95,V2 20 45) ,(V2 20 45,V2 20 5) ] , _rmPath = [(V2 20 95,V2 20 45) ,(V2 20 45,V2 20 5) ]
, _rmPmnts = , _rmPmnts =
[pContID (PS (V2 (-35) 50) (negate $ pi/2)) (PutButton $ makeSwitch col red id id) [pContID (PS (V2 (-35) 50) (negate $ pi/2)) (PutButton $ makeSwitch col red id id)
@@ -45,7 +46,8 @@ airlockSimple :: Room
airlockSimple = defaultRoom airlockSimple = defaultRoom
{ _rmPolys = { _rmPolys =
[ rectNSWE 120 0 0 180 ] [ rectNSWE 120 0 0 180 ]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = concatMap (doublePair. (V2 90 30,) . fst) lnks , _rmPath = concatMap (doublePair. (V2 90 30,) . fst) lnks
, _rmPmnts = , _rmPmnts =
[pContID (PS (V2 90 115) pi) (PutButton $ makeSwitch col red id id) [pContID (PS (V2 90 115) pi) (PutButton $ makeSwitch col red id id)
@@ -68,10 +70,8 @@ airlockZ :: Room
airlockZ = defaultRoom airlockZ = defaultRoom
{ _rmPolys = { _rmPolys =
[ rectNSWE 120 0 0 180 ] [ rectNSWE 120 0 0 180 ]
, _rmLinks = , _rmOutLinks = [(V2 0 30,pi/2)]
[(V2 0 30,pi/2) , _rmInLinks = [(V2 180 30,1.5*pi) ]
,(V2 180 30,1.5*pi)
]
, _rmPath = [] , _rmPath = []
-- [(V2 0 40,V2 40 0) -- [(V2 0 40,V2 40 0)
-- ,(V2 40 0,V2 0 40) -- ,(V2 40 0,V2 0 40)
@@ -108,10 +108,8 @@ airlock90 = defaultRoom
, (100,10) , (100,10)
] ]
] ]
, _rmLinks = , _rmOutLinks = [(V2 0 40,pi/2)]
[(V2 0 40,pi/2) , _rmInLinks = [(V2 40 0,pi) ]
,(V2 40 0,pi)
]
, _rmPath = , _rmPath =
[(V2 0 40,V2 40 0) [(V2 0 40,V2 40 0)
,(V2 40 0,V2 0 40) ,(V2 40 0,V2 0 40)
@@ -143,7 +141,8 @@ airlockCrystal = defaultRoom
[ rectNSWE 140 0 0 40 [ rectNSWE 140 0 0 40
, orderPolygon $ map toV2 [ (39,20) , (150,60) , (150,80) , (39,120) ] , orderPolygon $ map toV2 [ (39,20) , (150,60) , (150,80) , (39,120) ]
] ]
, _rmLinks = [(V2 20 130,0) ,(V2 20 0 ,pi) ] , _rmOutLinks = [(V2 20 130,0) ]
, _rmInLinks = [(V2 20 0 ,pi) ]
, _rmPath = [ ] , _rmPath = [ ]
, _rmPmnts = , _rmPmnts =
[pContID (PS (V2 145 70) (pi/2)) ( PutButton $ makeSwitch col red id id) [pContID (PS (V2 145 70) (pi/2)) ( PutButton $ makeSwitch col red id id)
+9 -6
View File
@@ -29,7 +29,8 @@ roomGlassOctogon x = createPathGrid $ defaultRoom
[rectNSWE x (-x) (-x) x [rectNSWE x (-x) (-x) x
,rectNSWE 0 (-(x + 40)) (-20) 20 ,rectNSWE 0 (-(x + 40)) (-20) 20
] ]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = linksAndPath lnks , _rmPath = linksAndPath lnks
[ ( V2 0 x , V2 0 (-(x+40))) [ ( V2 0 x , V2 0 (-(x+40)))
, ( V2 0 (-(x+40)), V2 0 x) , ( V2 0 (-(x+40)), V2 0 x)
@@ -84,15 +85,15 @@ roomCross x y = defaultRoom
{ _rmPolys = [rectNSWE y (-y) (-x) x { _rmPolys = [rectNSWE y (-y) (-x) x
,rectNSWE (-x) x y (-y) ,rectNSWE (-x) x y (-y)
] ]
, _rmLinks = , _rmOutLinks =
[(V2 x (y-20),negate $ pi/2) [(V2 x (y-20),negate $ pi/2)
,(V2 x (20-y),negate $ pi/2) ,(V2 x (20-y),negate $ pi/2)
,(V2 (20-y) x ,0) ,(V2 (20-y) x ,0)
,(V2 (y-20) x ,0) ,(V2 (y-20) x ,0)
,(V2 (-x) (y-20),pi/2) ,(V2 (-x) (y-20),pi/2)
,(V2 (-x) (20-y),pi/2) ,(V2 (-x) (20-y),pi/2)
,(V2 (20-y) (-x),pi) ,(V2 (20-y) (-x),pi) ]
,(V2 (y-20) (-x),pi) , _rmInLinks = [(V2 (y-20) (-x),pi)
] ]
, _rmPath = [] , _rmPath = []
, _rmPmnts = , _rmPmnts =
@@ -119,7 +120,8 @@ roomShuriken x y =
] ] ] ]
corner = defaultRoom corner = defaultRoom
{ _rmPolys = ps { _rmPolys = ps
, _rmLinks = [(V2 (x-1) (y-20),negate $ pi/2)] , _rmOutLinks = [(V2 (x-1) (y-20),negate $ pi/2)]
, _rmInLinks = [(V2 (x-1) (y-20),negate $ pi/2)]
, _rmPath = [] , _rmPath = []
, _rmPmnts = [mntLS iShape (V2 x x) (V3 (x-20) x 70)] , _rmPmnts = [mntLS iShape (V2 x x) (V3 (x-20) x 70)]
, _rmBound = ps , _rmBound = ps
@@ -144,7 +146,8 @@ roomTwistCross x y z =
] ]
corner = defaultRoom corner = defaultRoom
{ _rmPolys = ps { _rmPolys = ps
, _rmLinks = [(V2 z (y-20), pi/2)] , _rmOutLinks = [(V2 z (y-20), pi/2)]
, _rmInLinks = [(V2 z (y-20), pi/2)]
, _rmPath = [] , _rmPath = []
, _rmPmnts = [mntLS iShape (V2 x x) (V3 (x-20) (x-20) 70)] , _rmPmnts = [mntLS iShape (V2 x x) (V3 (x-20) (x-20) 70)]
, _rmBound = map (expandPolyCorners 10) ps , _rmBound = map (expandPolyCorners 10) ps
+1 -1
View File
@@ -6,7 +6,7 @@ import Dodge.Graph
linksOnPath :: Room -> Bool linksOnPath :: Room -> Bool
linksOnPath r = all pointOnPath linkPoints linksOnPath r = all pointOnPath linkPoints
where where
linkPoints = map fst $ _rmLinks r linkPoints = map fst $ _rmOutLinks r ++ _rmInLinks r
pointOnPath p = elem p $ concatMap flat2 $ _rmPath r pointOnPath p = elem p $ concatMap flat2 $ _rmPath r
flat2 (x,y) = [x,y] flat2 (x,y) = [x,y]
+10 -5
View File
@@ -16,7 +16,8 @@ import Data.Bifunctor
corridor :: Room corridor :: Room
corridor = defaultRoom corridor = defaultRoom
{ _rmPolys = [poly] { _rmPolys = [poly]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = concatMap (doublePair . (,) (V2 20 60) . fst) lnks , _rmPath = concatMap (doublePair . (,) (V2 20 60) . fst) lnks
, _rmPmnts = [ spanLightI (V2 0 40) (V2 40 40) ] , _rmPmnts = [ spanLightI (V2 0 40) (V2 40 40) ]
, _rmBound = [ rectNSWE 50 30 0 40 ] , _rmBound = [ rectNSWE 50 30 0 40 ]
@@ -47,7 +48,8 @@ corridorN :: Room
corridorN = defaultRoom corridorN = defaultRoom
{ _rmPolys = [rectNSWE 80 0 0 40 { _rmPolys = [rectNSWE 80 0 0 40
] ]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = pth , _rmPath = pth
, _rmPmnts = [] , _rmPmnts = []
, _rmBound = [ rectNSWE 50 30 0 40 ] , _rmBound = [ rectNSWE 50 30 0 40 ]
@@ -60,7 +62,8 @@ corridorWallN :: Room
corridorWallN = defaultRoom corridorWallN = defaultRoom
{ _rmPolys = [rectNSWE 70 0 0 40 { _rmPolys = [rectNSWE 70 0 0 40
] ]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = pth , _rmPath = pth
, _rmPmnts = [] , _rmPmnts = []
, _rmBound = [ rectNSWE 50 30 0 40 ] , _rmBound = [ rectNSWE 50 30 0 40 ]
@@ -75,7 +78,8 @@ tEast = defaultRoom
{ _rmPolys = [rectNSWE 80 0 (-20) 20 { _rmPolys = [rectNSWE 80 0 (-20) 20
,rectNSWE 80 40 (-40) 40 ,rectNSWE 80 40 (-40) 40
] ]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = concatMap (doublePair . (,) (V2 0 60) . fst) lnks , _rmPath = concatMap (doublePair . (,) (V2 0 60) . fst) lnks
, _rmPmnts = [] , _rmPmnts = []
, _rmBound = [ rectNSWE 70 10 0 40 ] , _rmBound = [ rectNSWE 70 10 0 40 ]
@@ -91,7 +95,8 @@ tWest = defaultRoom
{ _rmPolys = [rectNSWE 80 0 (-20) 20 { _rmPolys = [rectNSWE 80 0 (-20) 20
,rectNSWE 80 40 (-40) 40 ,rectNSWE 80 40 (-40) 40
] ]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = concatMap (doublePair . (,) (V2 0 60) . fst) lnks , _rmPath = concatMap (doublePair . (,) (V2 0 60) . fst) lnks
, _rmPmnts = [] , _rmPmnts = []
, _rmBound = [ rectNSWE 70 10 0 40 ] , _rmBound = [ rectNSWE 70 10 0 40 ]
+4 -2
View File
@@ -15,7 +15,8 @@ import Control.Lens
door :: Room door :: Room
door = defaultRoom door = defaultRoom
{ _rmPolys = [rectNSWE 40 0 0 40] { _rmPolys = [rectNSWE 40 0 0 40]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = [(V2 20 35,V2 20 5)] , _rmPath = [(V2 20 35,V2 20 5)]
-- door extends into side walls (for shadows as rendered 12/03) -- door extends into side walls (for shadows as rendered 12/03)
, _rmPmnts = [putAutoDoor (V2 0 20) (V2 40 20)] , _rmPmnts = [putAutoDoor (V2 0 20) (V2 40 20)]
@@ -29,7 +30,8 @@ door = defaultRoom
switchDoorRoom :: Room switchDoorRoom :: Room
switchDoorRoom = defaultRoom switchDoorRoom = defaultRoom
{ _rmPolys = [rectNSWE 40 0 0 40] { _rmPolys = [rectNSWE 40 0 0 40]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = [(V2 20 35,V2 20 5)] , _rmPath = [(V2 20 35,V2 20 5)]
, _rmPartPmnt = Just f , _rmPartPmnt = Just f
-- door extends into side walls (for shadows as rendered 12/03) -- door extends into side walls (for shadows as rendered 12/03)
+35 -28
View File
@@ -33,56 +33,60 @@ import Data.List
{- Shuffle the initial links of a room randomly. -} {- Shuffle the initial links of a room randomly. -}
randomiseOutLinks :: RandomGen g => Room -> State g Room randomiseOutLinks :: RandomGen g => Room -> State g Room
randomiseOutLinks r = do randomiseOutLinks r = do
newLinks <- shuffle $ init $ _rmLinks r newLinks <- shuffle $ _rmOutLinks r
return $ r {_rmLinks = newLinks ++ [last $ _rmLinks r]} return $ r {_rmOutLinks = newLinks }
sortOutLinksOn :: Ord b => ((Point2,Float) -> b) -> Room -> Room sortOutLinksOn :: Ord b => ((Point2,Float) -> b) -> Room -> Room
sortOutLinksOn f = rmLinks %~ dosort sortOutLinksOn f = rmOutLinks %~ sortOn f
where
dosort [] = []
dosort xs = sortOn f (init xs) ++ [last xs]
filterSortOutLinksOn :: Ord b => ((Point2,Float) -> Bool) -> ((Point2,Float) -> b) -> Room -> Room filterSortOutLinksOn :: Ord b => ((Point2,Float) -> Bool) -> ((Point2,Float) -> b) -> Room -> Room
filterSortOutLinksOn test f = rmLinks %~ dosort filterSortOutLinksOn test f = rmOutLinks %~ dosort
where where
dosort [] = [] dosort [] = []
dosort xs = let (ys,zs) = partition test (init xs) dosort xs = let (ys,zs) = partition test xs
in sortOn f ys ++ zs ++ [last xs] in sortOn f ys ++ zs
{- Shuffle all links of a room randomly. -} {- Shuffle all links of a room randomly. -}
randomiseAllLinks :: RandomGen g => Room -> State g Room randomiseAllLinks :: RandomGen g => Room -> State g Room
randomiseAllLinks r = do randomiseAllLinks r = do
newLinks <- shuffle $ _rmLinks r newLinks <- shuffle $ _rmOutLinks r ++ _rmInLinks r
return $ r {_rmLinks = newLinks} return $ r {_rmOutLinks = tail newLinks
, _rmInLinks = [head newLinks]
}
randomiseLinksBy randomiseLinksBy
:: ( [(Point2,Float)] -> State g [(Point2,Float)] ) :: ( [(Point2,Float)] -> State g [(Point2,Float)] )
-> Room -> Room
-> State g Room -> State g Room
randomiseLinksBy f r = do randomiseLinksBy f r = do
newLinks <- f $ _rmLinks r newLinks <- f $ _rmOutLinks r ++ _rmInLinks r
return $ r {_rmLinks = newLinks} return $ r {_rmOutLinks = init newLinks
, _rmInLinks = [last newLinks]
}
-- TODO rename to filterOutLinks
filterLinks :: RandomGen g => ((Point2,Float) -> Bool) -> Room -> State g Room filterLinks :: RandomGen g => ((Point2,Float) -> Bool) -> Room -> State g Room
filterLinks cond r = do filterLinks cond r = do
newLinks <- shuffle $ filter cond $ init $ _rmLinks r newLinks <- shuffle $ filter cond $ _rmOutLinks r
return $ r {_rmLinks = newLinks ++ [last $ _rmLinks r]} return $ r {_rmOutLinks = newLinks}
{- | Swaps the first link in the list with one that satisfies a given property. {- | Swaps the first link in the list with one that satisfies a given property.
- Does not change the last link in the list -} - Does not change the last link in the list -}
changeLinkFrom :: RandomGen g => ((Point2,Float) -> Bool) -> Room -> State g Room changeLinkFrom :: RandomGen g => ((Point2,Float) -> Bool) -> Room -> State g Room
changeLinkFrom cond r = do changeLinkFrom cond r = do
let (possibleLnks,otherLnks) = partition cond . init $ _rmLinks r let (possibleLnks,otherLnks) = partition cond $ _rmOutLinks r
newLnks <- shuffle possibleLnks newLnks <- shuffle possibleLnks
return $ r {_rmLinks = newLnks ++ otherLnks ++ [last $ _rmLinks r]} return $ r {_rmOutLinks = newLnks ++ otherLnks}
{- | Swaps the last link in the list with one that satisfies a given {- | Swaps the last link in the list with one that satisfies a given
- property (it might swap with itself). Unsafe. - property (it might swap with itself). Unsafe.
- Be careful about calling this after changeLinkFrom. -} - Be careful about calling this after changeLinkFrom. -}
changeLinkTo :: RandomGen g => ((Point2,Float) -> Bool) -> Room -> State g Room changeLinkTo :: RandomGen g => ((Point2,Float) -> Bool) -> Room -> State g Room
changeLinkTo cond r = do changeLinkTo cond r = do
l <- takeOne $ filter cond $ _rmLinks r let alllinks = _rmOutLinks r ++ _rmInLinks r
let newLinks = delete l (_rmLinks r) ++ [l] l <- takeOne $ filter cond alllinks
return $ r {_rmLinks = newLinks} let newLinks = delete l alllinks
{- | Move a room so that the last link in '_rmLinks' lines up to return $ r { _rmOutLinks = newLinks
,_rmInLinks = [l]}
{- | Move a room so that the first link in '_rmInLinks' lines up to
an external point and direction. an external point and direction.
This is intended to work when the external point is an outgoing link from another room. This is intended to work when the external point is an outgoing link from another room.
-} -}
@@ -93,7 +97,7 @@ shiftRoomToLink l r
$ shiftRoomBy (V2 0 0 -.- p , 0) $ shiftRoomBy (V2 0 0 -.- p , 0)
r r
where where
(p,a) = last $ _rmLinks r (p,a) = head $ _rmInLinks r
doRoomShift :: Room -> Room doRoomShift :: Room -> Room
doRoomShift rm = shiftRoomBy (_rmShift rm) rm & rmShift .~ _rmShift rm doRoomShift rm = shiftRoomBy (_rmShift rm) rm & rmShift .~ _rmShift rm
@@ -101,7 +105,8 @@ doRoomShift rm = shiftRoomBy (_rmShift rm) rm & rmShift .~ _rmShift rm
shiftRoomBy :: (Point2,Float) -> Room -> Room shiftRoomBy :: (Point2,Float) -> Room -> Room
shiftRoomBy shift r = r shiftRoomBy shift r = r
& rmPolys %~ fmap (map (shiftPointBy shift)) & rmPolys %~ fmap (map (shiftPointBy shift))
& rmLinks %~ fmap (shiftLinkBy shift) & rmOutLinks %~ fmap (shiftLinkBy shift)
& rmInLinks %~ fmap (shiftLinkBy shift)
& rmPath %~ map (shiftPathBy shift) & rmPath %~ map (shiftPathBy shift)
& rmBound %~ fmap (map (shiftPointBy shift)) & rmBound %~ fmap (map (shiftPointBy shift))
& rmShift %~ shiftLinkBy shift & rmShift %~ shiftLinkBy shift
@@ -118,7 +123,7 @@ shiftRoomShiftToLink l r
$ shiftRoomShiftBy (V2 0 0 -.- p , 0) $ shiftRoomShiftBy (V2 0 0 -.- p , 0)
r r
where where
(p,a) = last $ _rmLinks r (p,a) = head $ _rmInLinks r
-- NOTE placements, when placed, will be shifted by the value _rmShift -- NOTE placements, when placed, will be shifted by the value _rmShift
shiftRoomShiftBy :: (Point2,Float) -> Room -> Room shiftRoomShiftBy :: (Point2,Float) -> Room -> Room
shiftRoomShiftBy shift r = r shiftRoomShiftBy shift r = r
@@ -137,10 +142,12 @@ shiftPathBy
shiftPathBy s (p1,p2) = (shiftPointBy s p1, shiftPointBy s p2) shiftPathBy s (p1,p2) = (shiftPointBy s p1, shiftPointBy s p2)
finalLinksUpdate :: Room -> Room finalLinksUpdate :: Room -> Room
finalLinksUpdate rm = case _rmLinks rm of finalLinksUpdate rm = case _rmInLinks rm of
(_:_) -> rm (_:_) -> rm
& rmLinks %~ init & rmInLinks %~ tail
& rmPos %~ ( (uncurry UsedInLink (last thelnks) :) . (map (uncurry UnusedLink) (init thelnks) ++) ) & rmPos %~ ( (uncurry UsedInLink (head inlnks) :)
. (map (uncurry UnusedLink) (outlnks ++ tail inlnks) ++) )
_ -> rm _ -> rm
where where
thelnks = _rmLinks rm inlnks = _rmInLinks rm
outlnks = _rmOutLinks rm
+3 -4
View File
@@ -32,11 +32,10 @@ twinSlowDoorRoom
-> Room -> Room
twinSlowDoorRoom w h x = defaultRoom twinSlowDoorRoom w h x = defaultRoom
{ _rmPolys = ps { _rmPolys = ps
, _rmLinks = , _rmOutLinks =
[ (V2 w (h/2) , negate $ pi/2) [ (V2 w (h/2) , negate $ pi/2)
, (V2 (-w) (h/2) , pi/2) , (V2 (-w) (h/2) , pi/2) ]
, (V2 0 (-h), pi) , _rmInLinks = [ (V2 0 (-h), pi) ]
]
, _rmPath = [] , _rmPath = []
, _rmPmnts = , _rmPmnts =
[ pContID (PS (V2 0 (h-5)) pi) ( PutButton $ makeButton col id) [ pContID (PS (V2 0 (h-5)) pi) ( PutButton $ makeButton col id)
+1 -1
View File
@@ -34,4 +34,4 @@ centerVaultExplosiveExit = do
,sPS (V2 0 0) 0 $ PutCrit (cr & crState . crDropsOnDeath .~ DropAll) ,sPS (V2 0 0) 0 $ PutCrit (cr & crState . crDropsOnDeath .~ DropAll)
] ]
r <- centerVaultRoom 120 120 50 <&> rmPmnts %~ (extraPS ++) r <- centerVaultRoom 120 120 50 <&> rmPmnts %~ (extraPS ++)
randomiseLinksBy shuffleTail r <&> rmLinks %~ take 2 randomiseLinksBy shuffleTail r <&> rmOutLinks %~ take 2
+1 -1
View File
@@ -18,7 +18,7 @@ import qualified Control.Foldl as L
createPathGrid :: Room -> Room createPathGrid :: Room -> Room
createPathGrid rm = rm createPathGrid rm = rm
{ _rmPath = linksAndPath (_rmLinks rm) filterGrid } { _rmPath = linksAndPath (_rmOutLinks rm ++ _rmInLinks rm) filterGrid }
where where
filterGrid = filter (\p -> pairInPolys (_rmPolys rm) p && testCrossWalls outerWalls p) grid filterGrid = filter (\p -> pairInPolys (_rmPolys rm) p && testCrossWalls outerWalls p) grid
grid = fromMaybe [] $ shiftedGrid <$> minx <*> maxx <*> miny <*> maxy grid = fromMaybe [] $ shiftedGrid <$> minx <*> maxx <*> miny <*> maxy
+15 -7
View File
@@ -46,7 +46,8 @@ roomRect
-> Room -> Room
roomRect x y xn yn = defaultRoom roomRect x y xn yn = defaultRoom
{ _rmPolys = [rectNSWE y 0 0 x ] { _rmPolys = [rectNSWE y 0 0 x ]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = concatMap doublePair pth , _rmPath = concatMap doublePair pth
, _rmPmnts = [] , _rmPmnts = []
, _rmBound = [rectNSWE (y+5) (-5) (-5) (x+5)] , _rmBound = [rectNSWE (y+5) (-5) (-5) (x+5)]
@@ -78,11 +79,13 @@ roomRectAutoLinks x y = (roomRect x y xn yn)
yn = max 1 $ (ceiling y - 40) `div` 60 yn = max 1 $ (ceiling y - 40) `div` 60
plmnts = [mntLightLnkCond unusedLnkToPS ] plmnts = [mntLightLnkCond unusedLnkToPS ]
{- Combines two rooms into one room. {- Combines two rooms into one room.
- will have to work out exactly what to do with combining links
Mostly involves concatenation. -} Mostly involves concatenation. -}
combineRooms :: Room -> Room -> Room combineRooms :: Room -> Room -> Room
combineRooms r r' = defaultRoom combineRooms r r' = defaultRoom
{ _rmPolys = _rmPolys r ++ _rmPolys r' { _rmPolys = _rmPolys r ++ _rmPolys r'
, _rmLinks = _rmLinks r ++ _rmLinks r' , _rmOutLinks = _rmOutLinks r ++ _rmOutLinks r'
, _rmInLinks = _rmInLinks r ++ _rmInLinks r'
, _rmPath = map clampPath $ _rmPath r , _rmPath = map clampPath $ _rmPath r
++ _rmPath r' ++ _rmPath r'
, _rmPmnts = map (shiftPlacement $ _rmShift r) (_rmPmnts r) , _rmPmnts = map (shiftPlacement $ _rmShift r) (_rmPmnts r)
@@ -119,7 +122,8 @@ quarterRoomFlat w = do
] ]
pure $ defaultRoom pure $ defaultRoom
{ _rmPolys = [ [V2 0 0,V2 w w,V2 (-w) w] ] { _rmPolys = [ [V2 0 0,V2 w w,V2 (-w) w] ]
, _rmLinks = [(V2 0 w, 0)] , _rmOutLinks = [(V2 0 w, 0)]
, _rmInLinks = [(V2 0 w, 0)]
, _rmPath = concatMap doublePair , _rmPath = concatMap doublePair
[(V2 0 w,V2 0 (w-20)) [(V2 0 w,V2 0 (w-20))
,(V2 0 (w-20),V2 (w-20) (w-20)) ,(V2 0 (w-20),V2 (w-20) (w-20))
@@ -153,7 +157,11 @@ fourthCornerWall w = do
] ]
pure $ defaultRoom pure $ defaultRoom
{ _rmPolys = [ map toV2 [(0,0),(w,w),(0,2*w),(-w,w)] ] { _rmPolys = [ map toV2 [(0,0),(w,w),(0,2*w),(-w,w)] ]
, _rmLinks = , _rmOutLinks =
[(V2 (w/2) (3*w/2), negate $ pi/4)
,(V2 (negate $ w/2) (3*w/2), pi/4)
]
, _rmInLinks =
[(V2 (w/2) (3*w/2), negate $ pi/4) [(V2 (w/2) (3*w/2), negate $ pi/4)
,(V2 (negate $ w/2) (3*w/2), pi/4) ,(V2 (negate $ w/2) (3*w/2), pi/4)
] ]
@@ -216,11 +224,11 @@ centerVaultRoom
centerVaultRoom w h d = do centerVaultRoom w h d = do
return $ defaultRoom return $ defaultRoom
{ _rmPolys = [rectNSWE h (-h) (-w) w] { _rmPolys = [rectNSWE h (-h) (-w) w]
, _rmLinks = , _rmOutLinks =
[(V2 0 h , 0 ) [(V2 0 h , 0 )
,(V2 w 0 ,-pi/2) ,(V2 w 0 ,-pi/2)
,(V2 (-w) 0 , pi/2) ,(V2 (-w) 0 , pi/2) ]
,(V2 0 (-h), pi ) , _rmInLinks = [(V2 0 (-h), pi )
] ]
, _rmPath = [] , _rmPath = []
, _rmPmnts = , _rmPmnts =
+4 -4
View File
@@ -31,9 +31,8 @@ litCorridor90 = do
poly2 = rectNSWE (h-60) (h-100) (-60) 5 poly2 = rectNSWE (h-60) (h-100) (-60) 5
pure $ defaultRoom pure $ defaultRoom
{ _rmPolys = [poly,poly2] { _rmPolys = [poly,poly2]
, _rmLinks = [ (V2 40 (h - 80), -pi/2) , _rmOutLinks = [ (V2 40 (h - 80), -pi/2)]
, (V2 20 0 , pi ) , _rmInLinks = [ (V2 20 0 , pi ) ]
]
, _rmPath = concatMap doublePair , _rmPath = concatMap doublePair
[( V2 20 0 , V2 20 (h-40) ) [( V2 20 0 , V2 20 (h-40) )
,( V2 0 (h-40) , V2 20 (h-40) ) ,( V2 0 (h-40) , V2 20 (h-40) )
@@ -95,7 +94,8 @@ lasTunnel :: Room
lasTunnel = defaultRoom lasTunnel = defaultRoom
{ _rmPolys = polys { _rmPolys = polys
, _rmBound = polys , _rmBound = polys
, _rmLinks = [(V2 20 190,1.5* pi),(V2 0 20,0.5* pi)] , _rmOutLinks = [(V2 20 190,1.5* pi)]
, _rmInLinks = [(V2 0 20,0.5* pi)]
, _rmPmnts = [putLasTurret 0.005 & plSpot .~ PS (V2 10 240) (1.5*pi) , _rmPmnts = [putLasTurret 0.005 & plSpot .~ PS (V2 10 240) (1.5*pi)
, midWall (rectNSEW 65 40 0 25) , midWall (rectNSEW 65 40 0 25)
, mntLS vShape (V2 50 10) (V3 40 20 50) , mntLS vShape (V2 50 10) (V3 40 20 50)
+11 -6
View File
@@ -48,11 +48,13 @@ roomC w h = do
roomPadCut :: [Point2] -> Point2 -> Room roomPadCut :: [Point2] -> Point2 -> Room
roomPadCut ps p = defaultRoom roomPadCut ps p = defaultRoom
{ _rmPolys = [ps] { _rmPolys = [ps]
, _rmLinks = [(p,0),(V2 0 0,pi)] , _rmOutLinks = [(p,0)]
, _rmInLinks = [(V2 0 0,pi)]
, _rmPath = [(V2 0 0,p)] , _rmPath = [(V2 0 0,p)]
} }
roomPillars :: Room roomPillars :: Room
roomPillars = over rmLinks init $ set rmPmnts plmnts $ roomRect 240 240 2 2 roomPillars = --over rmLinks init $ -- it is unclear to me the purpose of this: perhaps to get the in link in the center?
set rmPmnts plmnts $ roomRect 240 240 2 2
where where
plmnts = spanLightI (V2 120 24) (V2 120 216) plmnts = spanLightI (V2 120 24) (V2 120 216)
: mntLS vShape (V2 12 12) (V3 25 25 70) : mntLS vShape (V2 12 12) (V3 25 25 70)
@@ -199,7 +201,8 @@ roomCenterPillar = changeLinkTo ((\p -> dist p (V2 120 0) < 10) . fst)
roomOctogon :: Room roomOctogon :: Room
roomOctogon = defaultRoom roomOctogon = defaultRoom
{ _rmPolys = [poly ] { _rmPolys = [poly ]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = allPairs $ map fst lnks -- this is too much , _rmPath = allPairs $ map fst lnks -- this is too much
, _rmPmnts = [] , _rmPmnts = []
, _rmBound = [map toV2 [(-20,30),(20,30),(60,70),(60,110),(20,150),(-20,150),(-60,110),(-60,70)] ] , _rmBound = [map toV2 [(-20,30),(20,30),(60,70),(60,110),(20,150),(-20,150),(-60,110),(-60,70)] ]
@@ -221,7 +224,8 @@ roomOctogon = defaultRoom
roomNgon :: Int -> Float -> Room roomNgon :: Int -> Float -> Room
roomNgon n x = defaultRoom roomNgon n x = defaultRoom
{ _rmPolys = [poly] { _rmPolys = [poly]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = [] -- TODO , _rmPath = [] -- TODO
, _rmPmnts = [] , _rmPmnts = []
, _rmBound = [poly] , _rmBound = [poly]
@@ -301,7 +305,7 @@ weaponBehindPillar = do
rcp <- roomCenterPillar rcp <- roomCenterPillar
return $ treeFromTrunk return $ treeFromTrunk
[PassDown corridor [PassDown corridor
,PassDown $ over rmLinks tail $ over rmPmnts (++ plmnts1) rcp ,PassDown $ over rmOutLinks tail $ over rmPmnts (++ plmnts1) rcp
] ]
(singleUseAll $ set rmPmnts [sPS (V2 20 60) (negate $ pi/2) randC1] corridorN) (singleUseAll $ set rmPmnts [sPS (V2 20 60) (negate $ pi/2) randC1] corridorN)
@@ -343,7 +347,8 @@ deadEndRoom :: Room
deadEndRoom = defaultRoom deadEndRoom = defaultRoom
{ _rmPolys = [rectNSWE 40 (-20) (-20) 20 { _rmPolys = [rectNSWE 40 (-20) (-20) 20
] ]
, _rmLinks = lnks , _rmOutLinks = init lnks
, _rmInLinks = [last lnks]
, _rmPath = [] , _rmPath = []
, _rmPmnts = [sPS (V2 0 (-10)) 0 putLamp] , _rmPmnts = [sPS (V2 0 (-10)) 0 putLamp]
, _rmBound = [rectNSWE 20 (-20) (-30) 30] , _rmBound = [rectNSWE 20 (-20) (-30) 30]
+1 -1
View File
@@ -70,7 +70,7 @@ runPastRoom i = do
,_rmPmnts = [] ,_rmPmnts = []
} }
switchdoor = switchDoorRoom & rmTakeFrom ?~ i switchdoor = switchDoorRoom & rmTakeFrom ?~ i
n = length $ filter theedgetest $ _rmLinks cenroom n = length $ filter theedgetest $ _rmOutLinks cenroom
controom = treeFromPost [PassDown switchdoor,PassDown linkcor] (UseAll door) controom = treeFromPost [PassDown switchdoor,PassDown linkcor] (UseAll door)
critrooms :: [SubCompTree Room] critrooms :: [SubCompTree Room]
critrooms = treeFromPost [PassDown switchdoor] (PassDown critroom) : critrooms = treeFromPost [PassDown switchdoor] (PassDown critroom) :
+5 -4
View File
@@ -5,6 +5,7 @@ import Dodge.Room.RunPast
import Dodge.Room.LasTurret import Dodge.Room.LasTurret
import Dodge.Data import Dodge.Data
import Dodge.Default import Dodge.Default
import Dodge.RoomLink
import Dodge.Tree import Dodge.Tree
import Dodge.RandomHelp import Dodge.RandomHelp
import Dodge.Room.Door import Dodge.Room.Door
@@ -98,7 +99,7 @@ rezColor = do
} }
rezInvBox :: LightSource -> Room rezInvBox :: LightSource -> Room
rezInvBox = (rmLinks %~ reverse) . rezBox rezInvBox = swapInOutLinks . rezBox
crAdd :: Room -> Room crAdd :: Room -> Room
crAdd = rmPmnts %~ (sPS (V2 20 10) (0.5*pi) randC1 :) crAdd = rmPmnts %~ (sPS (V2 20 10) (0.5*pi) randC1 :)
@@ -134,7 +135,7 @@ rezBoxesWpCrit = do
centralRoom <- filterSortOutLinksOn bottomEdgeTest ((\(V2 a b) -> (b,a)) . fst) <$> centralRoom <- filterSortOutLinksOn bottomEdgeTest ((\(V2 a b) -> (b,a)) . fst) <$>
(randomiseOutLinks =<< changeLinkTo bottomPassDownTest (randomiseOutLinks =<< changeLinkTo bottomPassDownTest
((roomRectAutoLinks w h) {_rmPmnts = []})) ((roomRectAutoLinks w h) {_rmPmnts = []}))
let n = length $ filter bottomEdgeTest $ _rmLinks centralRoom let n = length $ filter bottomEdgeTest $ _rmOutLinks centralRoom
i <- state $ randomR (0,n-3) i <- state $ randomR (0,n-3)
j <- state $ randomR (i,n-2) j <- state $ randomR (i,n-2)
blcor <- blockedCorridor' blcor <- blockedCorridor'
@@ -161,7 +162,7 @@ rezBoxesWp = do
centralRoom <- randomiseOutLinks =<< changeLinkTo bottomEdgeTest centralRoom <- randomiseOutLinks =<< changeLinkTo bottomEdgeTest
((roomRectAutoLinks w h) {_rmPmnts = []}) ((roomRectAutoLinks w h) {_rmPmnts = []})
blcor <- blockedCorridor' blcor <- blockedCorridor'
let n = length $ filter bottomEdgeTest $ _rmLinks centralRoom let n = length $ filter bottomEdgeTest $ _rmOutLinks centralRoom
let rezrooms = map adddoor let rezrooms = map adddoor
$ wpAdd theweapon aroom : replicate (n-2) aroom $ wpAdd theweapon aroom : replicate (n-2) aroom
centralRoom' <- changeLinkFrom bottomEdgeTest centralRoom centralRoom' <- changeLinkFrom bottomEdgeTest centralRoom
@@ -182,7 +183,7 @@ rezBoxes = do
dbox = treeFromPost [PassDown door] (PassDown $ rezInvBox thecol) dbox = treeFromPost [PassDown door] (PassDown $ rezInvBox thecol)
centralRoom <- randomiseOutLinks =<< changeLinkTo bottomEdgeTest centralRoom <- randomiseOutLinks =<< changeLinkTo bottomEdgeTest
((roomRectAutoLinks w h) {_rmPmnts = []}) ((roomRectAutoLinks w h) {_rmPmnts = []})
let n = length $ filter bottomEdgeTest $ _rmLinks centralRoom let n = length $ filter bottomEdgeTest $ _rmOutLinks centralRoom
centralRoom' <- changeLinkFrom bottomEdgeTest centralRoom centralRoom' <- changeLinkFrom bottomEdgeTest centralRoom
return $ treeFromTrunk [PassDown $ rezBox thecol return $ treeFromTrunk [PassDown $ rezBox thecol
, PassDown door , PassDown door
+2 -1
View File
@@ -25,7 +25,8 @@ triLootRoom w h = pure $ defaultRoom
{ _rmPolys = [ tri { _rmPolys = [ tri
, base , base
] ]
, _rmLinks = [(V2 0 (-80) , pi)] , _rmOutLinks = []
, _rmInLinks = [(V2 0 (-80) , pi)]
, _rmPath = doublePair (V2 0 (-80) , V2 0 (h/2)) , _rmPath = doublePair (V2 0 (-80) , V2 0 (h/2))
, _rmPmnts = , _rmPmnts =
[sPS (V2 (15-w) 15 ) 0 $ PutID 0 [sPS (V2 (15-w) 15 ) 0 $ PutID 0
+2 -2
View File
@@ -34,7 +34,7 @@ posRms bounds (parent,_) _ [] st = case st of
-> fmap (finalLinksUpdate parent:) <$> posRms bounds childi 0 ts tseq -> fmap (finalLinksUpdate parent:) <$> posRms bounds childi 0 ts tseq
posRms bounds parenti numChild (t@(Node childi _):ts) tseq = do posRms bounds parenti numChild (t@(Node childi _):ts) tseq = do
printInfo parenti numChild childi printInfo parenti numChild childi
tryLinks (0::Int) (init $ _rmLinks parent) tryLinks (0::Int) (_rmOutLinks parent)
where where
parent = fst parenti parent = fst parenti
tryLinks _ [] = putStrLn "all links tried" >> return Nothing tryLinks _ [] = putStrLn "all links tried" >> return Nothing
@@ -53,7 +53,7 @@ posRms bounds parenti numChild (t@(Node childi _):ts) tseq = do
where where
convexBounds = map pointsToPoly $ _rmBound r' convexBounds = map pointsToPoly $ _rmBound r'
clipping = or (convexPolysOverlap <$> convexBounds <*> bounds) clipping = or (convexPolysOverlap <$> convexBounds <*> bounds)
upr rm = doLnkEff l $ rm & rmLinks %~ delete l & rmPos %~ (uncurry (UsedOutLink numChild) l :) upr rm = doLnkEff l $ rm & rmOutLinks %~ delete l & rmPos %~ (uncurry (UsedOutLink numChild) l :)
l' = shiftLinkBy (_rmShift parent) l l' = shiftLinkBy (_rmShift parent) l
r' = doRoomShift . fst $ rootLabel shiftedt r' = doRoomShift . fst $ rootLabel shiftedt
shiftedt = applyToRoot (first $ shiftRoomShiftToLink l') t shiftedt = applyToRoot (first $ shiftRoomShiftToLink l') t