Fix incorrect creation of unused links pos

This commit is contained in:
2022-03-08 09:48:45 +00:00
parent 59e6f433ff
commit 8179a2aa4f
8 changed files with 35 additions and 35 deletions
+5 -4
View File
@@ -37,8 +37,9 @@ randomPadCorridors (Node x xs) = do
return $ treeFromTrunk (replicate n [Corridor]) (Node x xs') return $ treeFromTrunk (replicate n [Corridor]) (Node x xs')
{- | Add a corridor to a random out-link of a room. -} {- | Add a corridor to a random out-link of a room. -}
roomThenCorridor :: RandomGen g => Room -> State g (SubCompTree Room) roomThenCorridor :: RandomGen g => Room -> State g (SubCompTree Room)
roomThenCorridor theRoom = fmap (\r -> Node (PassDown theRoom) [(pure . UseAll) r]) roomThenCorridor theRoom = fmap
(randomiseOutLinks corridor) (\r -> Node (PassDown theRoom) [(pure . UseAll) r])
(shuffleLinks corridor)
{- | Create a random room tree structure from a list of annotations. -} {- | Create a random room tree structure from a list of annotations. -}
anoToRoomTree :: RandomGen g => [Annotation g] -> State g (SubCompTree Room) anoToRoomTree :: RandomGen g => [Annotation g] -> State g (SubCompTree Room)
@@ -62,7 +63,7 @@ anoToRoomTree anos = case anos of
[OrAno as] -> do [OrAno as] -> do
a <- takeOne as a <- takeOne as
anoToRoomTree a anoToRoomTree a
[Corridor] -> pure . UseAll <$> randomiseOutLinks corridor [Corridor] -> pure . UseAll <$> shuffleLinks corridor
[AirlockAno] -> airlock >>= roomThenCorridor [AirlockAno] -> airlock >>= roomThenCorridor
[FirstWeapon] -> do [FirstWeapon] -> do
branchWP <- branchRectWith weaponRoom branchWP <- branchRectWith weaponRoom
@@ -77,4 +78,4 @@ anoToRoomTree anos = case anos of
_ -> do _ -> do
w <- state $ randomR (100,400) w <- state $ randomR (100,400)
h <- state $ randomR (200,400) h <- state $ randomR (200,400)
fmap (pure . UseAll) . randomiseOutLinks $ roomRectAutoLinks w h fmap (pure . UseAll) . shuffleLinks $ roomRectAutoLinks w h
+2 -1
View File
@@ -207,7 +207,8 @@ psj ps pst plmnt = Placement ps pst Nothing (const $ Just plmnt)
-- the NoShiftCont is necessary when shifting then combining rooms -- the NoShiftCont is necessary when shifting then combining rooms
ps0jPushPS :: PSType -> Placement -> Placement ps0jPushPS :: PSType -> Placement -> Placement
ps0jPushPS pst plmnt = Placement (PSNoShiftCont (V2 0 0) 0) pst Nothing (\p -> Just $ plmnt & plSpot .~ _plSpot p) ps0jPushPS pst plmnt = Placement (PSNoShiftCont (V2 0 0) 0) pst Nothing
$ \p -> Just $ plmnt & plSpot .~ _plSpot p
addPlmnt :: Placement -> Placement -> Placement addPlmnt :: Placement -> Placement -> Placement
addPlmnt pl pl2 = case pl2 of addPlmnt pl pl2 = case pl2 of
+2 -1
View File
@@ -21,7 +21,6 @@ mntLSOn
-> LightSource -> Point2 -> Point3 -> (Placement -> Maybe Placement) -> Placement -> LightSource -> Point2 -> Point3 -> (Placement -> Maybe Placement) -> Placement
mntLSOn shapeF mcol ls wallp lsp@(V3 lx ly _) mntLSOn shapeF mcol ls wallp lsp@(V3 lx ly _)
= ps0jPushPS (PutShape . setCol $ shapeF wallp lsp) = ps0jPushPS (PutShape . setCol $ shapeF wallp lsp)
-- = ps0j (PutShape . setCol $ shapeF wallp lsp)
. pt0 (PutLS $ ls & lsParam . lsPos .~ lsp') . pt0 (PutLS $ ls & lsParam . lsPos .~ lsp')
where where
lsp' = lsp -.-.- V3 x y 1 lsp' = lsp -.-.- V3 x y 1
@@ -111,6 +110,8 @@ mntLightLnkCond f = RandomPlacement $ do
unusedLnkToPS :: RoomPos -> Room -> Maybe (PlacementSpot,RoomPos) unusedLnkToPS :: RoomPos -> Room -> Maybe (PlacementSpot,RoomPos)
unusedLnkToPS rp _ = case rp of unusedLnkToPS rp _ = case rp of
UnusedLink p a -> Just (PS p a,UsedSpot p a) UnusedLink p a -> Just (PS p a,UsedSpot p a)
-- UsedInLink _ p a -> Just (PS p a,UsedSpot p a)
-- UsedOutLink _ _ p a -> Just (PS p a,UsedSpot p a)
_ -> Nothing _ -> Nothing
spanLSLightI :: LightSource -> Float -> Point2 -> Point2 -> Placement spanLSLightI :: LightSource -> Float -> Point2 -> Point2 -> Placement
-1
View File
@@ -54,7 +54,6 @@ placePlainPSSpot :: GenWorld -> Room -> Placement -> DPoint2 -> ((GenWorld,Room)
placePlainPSSpot w rm plmnt shift = placePlainPSSpot w rm plmnt shift =
let (i,w') = placeSpotID (shiftPSBy shift (_plSpot plmnt)) (_plType plmnt) w let (i,w') = placeSpotID (shiftPSBy shift (_plSpot plmnt)) (_plType plmnt) w
newplmnt = plmnt & plMID ?~ i newplmnt = plmnt & plMID ?~ i
--in maybe ((w',rm),[newplmnt]) (recrPlace newplmnt w') (_plIDCont plmnt newplmnt)
in maybe ((w',rm),[newplmnt]) (recrPlace newplmnt w') (_plIDCont plmnt newplmnt) in maybe ((w',rm),[newplmnt]) (recrPlace newplmnt w') (_plIDCont plmnt newplmnt)
where where
recrPlace newplmnt w' pl = let (wr,newplmnts) = placeSpot (w',rm) pl recrPlace newplmnt w' pl = let (wr,newplmnts) = placeSpot (w',rm) pl
+5 -3
View File
@@ -20,6 +20,8 @@ branchRectWith t = do
x <- state $ randomR (100,200) x <- state $ randomR (100,200)
y <- state $ randomR (100,200) y <- state $ randomR (100,200)
b <- t b <- t
root <- randomiseOutLinks $ roomRectAutoLinks x y root <- shuffleLinks $ roomRectAutoLinks x y
return $ Node (PassDown root) [Node (UseAll door) [], changeToPassDown <$> return $ Node (PassDown root)
treeFromTrunk [PassDown door] b] [ Node (UseAll door) []
, changeToPassDown <$> treeFromTrunk [PassDown door] b
]
+1 -10
View File
@@ -14,7 +14,6 @@ module Dodge.Room.Link
, randomiseAllLinks , randomiseAllLinks
, shuffleLinks , shuffleLinks
, filterLinks , filterLinks
, randomiseOutLinks
, chooseOneInLink , chooseOneInLink
, restrictRMInLinksPD , restrictRMInLinksPD
) where ) where
@@ -47,13 +46,6 @@ restrictToFstInLink = rmLinks %~ f
| otherwise = rl : f xs | otherwise = rl : f xs
f [] = [] f [] = []
{- Shuffle the initial links of a room randomly. -}
randomiseOutLinks :: RandomGen g => Room -> State g Room
randomiseOutLinks r = do
let (outs,xs) = partition (S.member OutLink . _rlType) $ _rmLinks r
newLinks <- shuffle outs
return $ r {_rmLinks = newLinks ++ xs }
sortOutLinksOn :: Ord b => ((Point2,Float) -> b) -> Room -> Room sortOutLinksOn :: Ord b => ((Point2,Float) -> b) -> Room -> Room
sortOutLinksOn f = overLnkType OutLink $ sortOn (f . lnkPosDir) sortOutLinksOn f = overLnkType OutLink $ sortOn (f . lnkPosDir)
@@ -124,8 +116,7 @@ shiftRoomShiftToLink l inlink r
(p,a) = inlink (p,a) = inlink
-- 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 = rmShift %~ shiftPosDirBy shift
& rmShift %~ shiftPosDirBy shift
shiftPosDirBy :: (Point2,Float) -> (Point2,Float) -> (Point2,Float) shiftPosDirBy :: (Point2,Float) -> (Point2,Float) -> (Point2,Float)
shiftPosDirBy (pos,rot) (p,r) = (shiftPointBy (pos,rot) p, r + rot) shiftPosDirBy (pos,rot) (p,r) = (shiftPointBy (pos,rot) p, r + rot)
+3 -3
View File
@@ -25,7 +25,7 @@ import Dodge.Item.Weapon.Utility
import Geometry import Geometry
--import Padding --import Padding
import Color import Color
--import Shape import Shape
import LensHelp import LensHelp
--import Data.Maybe --import Data.Maybe
@@ -96,11 +96,11 @@ startRoom' = do
h <- state $ randomR (200,400) h <- state $ randomR (200,400)
let plmnts = let plmnts =
[ sPS (V2 0 0) 0 $ PutShape $ girderV 40 20 10 (V2 0 (h/2)) (V2 w (h/2)) [ sPS (V2 0 0) 0 $ PutShape $ girderV 40 20 10 (V2 0 (h/2)) (V2 w (h/2))
--, mntLS jShape (V2 0 (h/3)) (V3 40 (h/3) 70) -- , mntLS jShape (V2 0 (h/3)) (V3 40 (h/3) 70)
, tankSquareEmboss4 (dim orange) 50 (h-60) , tankSquareEmboss4 (dim orange) 50 (h-60)
, tankSquare (dim orange) 50 50 , tankSquare (dim orange) 50 50
, tankSquare (dim orange) 50 120 , tankSquare (dim orange) 50 120
--, sps0 $ PutShape $ colorSH orange $ pipePP 2 (V3 50 50 25) (V3 50 120 25) , sps0 $ PutShape $ colorSH orange $ pipePP 2 (V3 50 50 25) (V3 50 120 25)
] ]
thecol <- rezColor thecol <- rezColor
treeFromPost [PassDown $ rezBox thecol, PassDown door] . UseAll treeFromPost [PassDown $ rezBox thecol, PassDown door] . UseAll
+7 -2
View File
@@ -24,7 +24,8 @@ type RoomInt = (Room,Int)
positionRoomsFromTree :: Tree RoomInt -> IO (Maybe [RoomInt]) positionRoomsFromTree :: Tree RoomInt -> IO (Maybe [RoomInt])
positionRoomsFromTree (Node (r,i) ts) = printHeader positionRoomsFromTree (Node (r,i) ts) = printHeader
>> posRms (map pointsToPoly $ _rmBound r') (r',i) (zipCount ts) Empty >> (fmap (fmap (map $ first createUnusedLinkPos)))
(posRms (map pointsToPoly $ _rmBound r') (r',i) (zipCount ts) Empty)
where where
r' = r & rmMID ?~ 0 r' = r & rmMID ?~ 0
@@ -71,10 +72,14 @@ posRms bounds parenti@(parent,_) ( (numChild,t@(Node childi _) ):its) tseq = do
& rmMID ?~ snd childi & rmMID ?~ snd childi
& rmLinks %~ delete il & rmLinks %~ delete il
& rmPos %~ ( (uncurry (UsedInLink 0) (lnkPosDir il):) & rmPos %~ ( (uncurry (UsedInLink 0) (lnkPosDir il):)
. (map (uncurry UnusedLink . lnkPosDir) (delete il (_rmLinks rm)) ++) ) -- . (map (uncurry UnusedLink . lnkPosDir) (delete il (_rmLinks rm)) ++)
)
shiftedt = applyToRoot shiftedt = applyToRoot
(first $ updatechild . shiftRoomShiftToLink (lnkPosDir shiftedoutlink) (lnkPosDir il)) t (first $ updatechild . shiftRoomShiftToLink (lnkPosDir shiftedoutlink) (lnkPosDir il)) t
createUnusedLinkPos :: Room -> Room
createUnusedLinkPos rm = rm & rmPos .++~ map (uncurry UnusedLink . lnkPosDir) (_rmLinks rm)
zipCount :: [a] -> [(Int,a)] zipCount :: [a] -> [(Int,a)]
zipCount = Prelude.zip [0..] zipCount = Prelude.zip [0..]