Fix bug not adding last positioned room to list

This commit is contained in:
2021-11-23 12:50:15 +00:00
parent 05bb1961c0
commit f51a6a7216
6 changed files with 33 additions and 21 deletions
+3
View File
@@ -34,6 +34,9 @@ safeHead :: [a] -> Maybe a
safeHead (x:_) = Just x
safeHead _ = Nothing
errorHead :: String -> [a] -> a
errorHead _ (x:_) = x
errorHead s [] = error s
you :: World -> Creature
you w = _creatures w IM.! _yourID w
+8 -7
View File
@@ -36,7 +36,7 @@ initialAnoTree :: RandomGen g => Tree [Annotation g]
initialAnoTree = padSucWithCorridors $ treeFromTrunk
[[AnoApplyInt 0 startRoom]
, [PassthroughLockKeyLists 2 lockRoomKeyItems itemRooms]
--, [AnoApplyInt 1 lasSensorTurretTest]
-- , [AnoApplyInt 1 lasSensorTurretTest]
-- ,[ChainAnos
-- [[SetLabel 0 $ return $ roomRectAutoLinks 200 200
-- & rmExtPmnt ?~ triggerSwitchSPicLight (drawSwitchWire red red)
@@ -47,12 +47,12 @@ initialAnoTree = padSucWithCorridors $ treeFromTrunk
-- ]
-- ]
-- ,[SpecificRoom $ return $ connectRoom lasTunnel ]
,[SpecificRoom $ fmap singleUseAll slowDoorRoom ]
,[Corridor]
,[Corridor]
,[SpecificRoom $ fmap singleUseAll roomCCrits]
,[AirlockAno]
,[Corridor]
-- ,[SpecificRoom $ fmap singleUseAll slowDoorRoom ]
-- ,[Corridor]
-- ,[Corridor]
-- ,[SpecificRoom $ fmap singleUseAll roomCCrits]
-- ,[AirlockAno]
-- ,[Corridor]
------ ,[SpecificRoom roomCCrits]
------ ,[Corridor]
------ ,[SpecificRoom . pure . pure . UseAll $ roomGlassOctogon 400
@@ -113,6 +113,7 @@ layoutLevelFromSeed i seed = do
++ " attempt(s), Successful generation of level with seed "
++ show seed
--return (fmap setLastLinkToUsed rs)
putStrLn $ show (Prelude.length rs) ++ " rooms in total"
return rs
Nothing -> do
putStr $ "Level generation with seed " ++ show seed ++ " failed: "
+4 -1
View File
@@ -16,11 +16,14 @@ import Control.Monad.State
lockRoomKeyItems :: RandomGen g => [ (Int -> State g (SubCompTree Room) , State g ItemIdentity ) ]
lockRoomKeyItems =
[ (lasCenSensEdge, takeOne [Launcher] )
-- , (const $ fmap singleUseAll slowDoorRoom, return MiniGun)
]
itemRooms :: RandomGen g => [(ItemIdentity, State g (SubCompTree Room))]
itemRooms =
[ (Launcher , corridorBoss launcherCrit ) ]
[ (Launcher , corridorBoss launcherCrit )
-- , (MiniGun , join $ takeOne [roomMiniIntro, minigunFakeout] )
]
corridorBoss :: RandomGen g => Creature -> State g (SubCompTree Room)
corridorBoss cr = do
+2 -2
View File
@@ -32,8 +32,8 @@ import Control.Lens
import System.Random
--import qualified Data.IntMap.Strict as IM
minigunfakeout :: RandomGen g => State g (SubCompTree Room)
minigunfakeout = do
minigunFakeout :: RandomGen g => State g (SubCompTree Room)
minigunFakeout = do
rcol <- rezColor
ncor <- state $ randomR (0,2)
roomwithmini <- randomiseAllLinks $ roomRectAutoLinks 150 150
+3 -1
View File
@@ -11,6 +11,7 @@ module Dodge.Tree.Compose
) where
import Dodge.Tree.Compose.Data
import Dodge.Tree.Polymorphic
import Dodge.Base
import Data.Tree
expandTree :: CompTree a -> Tree a
@@ -24,7 +25,8 @@ expandTree (Node root extChildren) = case root of
$ map (:[]) extChildren ++ repeat []
overwriteLabel :: Int -> (a -> ComposingNode a) -> SubCompTree a -> [SubCompTree a] -> SubCompTree a
overwriteLabel i f t ts = head $ updateSingleNode islabel update t
overwriteLabel i f t ts = errorHead ("tried to overwriteLabel " ++ show i)
$ updateSingleNode islabel update t
where
islabel (UseLabel j _) | i == j = True
islabel _ = False
+13 -10
View File
@@ -29,16 +29,13 @@ posRms :: [ConvexPoly]
-> Seq (Tree RoomInt)
-> IO (Maybe [Room])
posRms bounds (parent,_) _ [] st = case st of
Empty -> return $ Just []
Empty -> return $ Just [parent]
Node childi ts :<| tseq
-> fmap (finalLinksUpdate parent:) <$> posRms bounds childi 0 ts tseq
posRms bounds parenti@(pr,i) numChild (t@(Node (cr,i') _):ts) tseq = do
putStr $ rpns 20 (_rmName cr ++ "-" ++ show i')
++ rpns 9 (" child " ++ show numChild )
++ rpns 25 (" of " ++ _rmName pr ++ "-" ++ show i )
posRms bounds parenti numChild (t@(Node childi _):ts) tseq = do
printInfo parenti numChild childi
tryLinks (0::Int) (init $ _rmLinks parent)
where
rpns x s = rightPadNoSquash x ' ' s
parent = fst parenti
tryLinks _ [] = putStrLn "all links tried" >> return Nothing
tryLinks j (l:ls)
@@ -48,11 +45,9 @@ posRms bounds parenti@(pr,i) numChild (t@(Node (cr,i') _):ts) tseq = do
mayrs <- posRms (convexBounds ++ bounds)
(first upr parenti) (numChild + 1) ts (tseq |> shiftedt)
case mayrs of
--Nothing -> putStr ("Backtracking to room " ++ show i' ++ ": ") >> tryLinks (j+1) ls
Nothing -> do
putStr $ "Backtracking to " ++ rpns 20 (_rmName cr ++ "-" ++ show i')
++ rpns 9 (" child " ++ show numChild )
++ rpns 25 (" of " ++ _rmName pr ++ "-" ++ show i )
putStr "Backtrack: "
printInfo parenti numChild childi
tryLinks (j+1) ls
Just rs -> return (Just rs)
where
@@ -63,6 +58,14 @@ posRms bounds parenti@(pr,i) numChild (t@(Node (cr,i') _):ts) tseq = do
r' = doRoomShift . fst $ rootLabel shiftedt
shiftedt = applyToRoot (first $ shiftRoomShiftToLink l') t
printInfo :: RoomInt -> Int -> RoomInt -> IO ()
printInfo (parentrm,parenti) childn (childrm,childi) = do
putStr $ rpns 20 (_rmName childrm ++ "-" ++ show childi)
++ rpns 9 (" child " ++ show childn )
++ rpns 25 (" of " ++ _rmName parentrm ++ "-" ++ show parenti )
where
rpns x s = rightPadNoSquash x ' ' s
doLnkEff :: (Point2,Float) -> Room -> Room
doLnkEff x rm = case _rmLinkEff rm of
(eff:effs) -> eff x $ rm & rmLinkEff .~ effs