Test of lock and key system
This commit is contained in:
+14
-7
@@ -11,7 +11,8 @@ import Dodge.Annotation.Data
|
|||||||
import Data.Tree
|
import Data.Tree
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import System.Random
|
import System.Random
|
||||||
import Control.Lens
|
--import Control.Lens
|
||||||
|
import Data.Maybe
|
||||||
|
|
||||||
addLock :: RandomGen g => Int -> Tree [Annotation g] -> State g (Tree [Annotation g])
|
addLock :: RandomGen g => Int -> Tree [Annotation g] -> State g (Tree [Annotation g])
|
||||||
addLock i t = do
|
addLock i t = do
|
||||||
@@ -43,15 +44,21 @@ roomThenCorridor theRoom = fmap (\r -> Node (PassDown theRoom) [(pure . UseAll)
|
|||||||
anoToRoomTree :: RandomGen g => [Annotation g] -> State g (SubCompTree Room)
|
anoToRoomTree :: RandomGen g => [Annotation g] -> State g (SubCompTree Room)
|
||||||
anoToRoomTree anos = case anos of
|
anoToRoomTree anos = case anos of
|
||||||
[AnoApplyInt i f] -> f i
|
[AnoApplyInt i f] -> f i
|
||||||
[SetLabel i randrm] -> do
|
-- [SetLabel i randrm] -> do
|
||||||
rm <- randrm
|
-- rm <- randrm
|
||||||
return . singleUseAll $ rm & rmLabel ?~ i
|
-- return . singleUseAll $ rm & rmLabel ?~ i
|
||||||
[UseLabel i randrm] -> do
|
-- [UseLabel i randrm] -> do
|
||||||
rm <- randrm
|
-- rm <- randrm
|
||||||
return $ singleUseAll $ rm & rmTakeFrom ?~ i
|
-- return $ singleUseAll $ rm & rmTakeFrom ?~ i
|
||||||
[ChainAnos ass] -> do
|
[ChainAnos ass] -> do
|
||||||
rms <- mapM anoToRoomTree ass
|
rms <- mapM anoToRoomTree ass
|
||||||
return $ chainUses rms
|
return $ chainUses rms
|
||||||
|
[PassthroughLockKeyLists i ls ks] -> do
|
||||||
|
(functionlockroom,randomitemidentity) <- takeOne ls
|
||||||
|
lr <- functionlockroom i
|
||||||
|
ii <- randomitemidentity
|
||||||
|
keyroom <- fromJust $ lookup ii ks
|
||||||
|
return $ overwriteLabel 0 UseNone lr [keyroom]
|
||||||
[OrAno as] -> do
|
[OrAno as] -> do
|
||||||
a <- takeOne as
|
a <- takeOne as
|
||||||
anoToRoomTree a
|
anoToRoomTree a
|
||||||
|
|||||||
@@ -19,8 +19,11 @@ data Annotation g
|
|||||||
| BossAno Creature
|
| BossAno Creature
|
||||||
| TreasureAno [Creature] [Item]
|
| TreasureAno [Creature] [Item]
|
||||||
| AnoApplyInt Int (Int -> State g (SubCompTree Room))
|
| AnoApplyInt Int (Int -> State g (SubCompTree Room))
|
||||||
| SetLabel Int (State g Room)
|
| PassthroughLockKeyLists Int
|
||||||
| UseLabel Int (State g Room)
|
[(Int -> State g (SubCompTree Room), State g ItemIdentity)]
|
||||||
|
[(ItemIdentity, State g (SubCompTree Room))]
|
||||||
|
-- | SetLabel Int (State g Room)
|
||||||
|
-- | UseLabel Int (State g Room)
|
||||||
| ChainAnos [[Annotation g]]
|
| ChainAnos [[Annotation g]]
|
||||||
|
|
||||||
makeLenses ''Annotation
|
makeLenses ''Annotation
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ module Dodge.Floor
|
|||||||
) where
|
) where
|
||||||
import Geometry.Data
|
import Geometry.Data
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
|
import Dodge.LockAndKey
|
||||||
import Dodge.Creature.State.Data
|
import Dodge.Creature.State.Data
|
||||||
import Dodge.Room
|
import Dodge.Room
|
||||||
import Dodge.Room
|
import Dodge.Room
|
||||||
@@ -35,6 +36,7 @@ import qualified Data.IntMap.Strict as IM
|
|||||||
initialAnoTree :: RandomGen g => Tree [Annotation g]
|
initialAnoTree :: RandomGen g => Tree [Annotation g]
|
||||||
initialAnoTree = padSucWithCorridors $ treeFromTrunk
|
initialAnoTree = padSucWithCorridors $ treeFromTrunk
|
||||||
[[AnoApplyInt 0 startRoom]
|
[[AnoApplyInt 0 startRoom]
|
||||||
|
, [PassthroughLockKeyLists 2 lockRoomKeyItems itemRooms]
|
||||||
, [AnoApplyInt 2 room2]
|
, [AnoApplyInt 2 room2]
|
||||||
, [AnoApplyInt 1 lasSensorTurretTest]
|
, [AnoApplyInt 1 lasSensorTurretTest]
|
||||||
-- ,[ChainAnos
|
-- ,[ChainAnos
|
||||||
|
|||||||
+17
-5
@@ -3,16 +3,28 @@ import Dodge.Data
|
|||||||
import Dodge.Tree
|
import Dodge.Tree
|
||||||
import Dodge.LevelGen.Data
|
import Dodge.LevelGen.Data
|
||||||
import Dodge.Room
|
import Dodge.Room
|
||||||
|
import Dodge.RandomHelp
|
||||||
|
import Dodge.Creature
|
||||||
--import Dodge.Item.Equipment
|
--import Dodge.Item.Equipment
|
||||||
|
|
||||||
import System.Random
|
import System.Random
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
|
|
||||||
lockRoomKeyItems :: RandomGen g => [ (Int -> State g (SubCompTree Room) , [ItemIdentity] ) ]
|
-- (const $ return $ chainUses $ map singleUseAll [door,lasTunnel,door] , return FlatShield )
|
||||||
|
-- ,
|
||||||
|
|
||||||
|
lockRoomKeyItems :: RandomGen g => [ (Int -> State g (SubCompTree Room) , State g ItemIdentity ) ]
|
||||||
lockRoomKeyItems =
|
lockRoomKeyItems =
|
||||||
[ (const $ return $ chainUses $ map singleUseAll [door,lasTunnel,door] , [FlatShield] )
|
[ (lasCenSensEdge, takeOne [Launcher] )
|
||||||
, (lasCenSensEdge, [FlatShield,Launcher,TeslaGun] )
|
|
||||||
]
|
]
|
||||||
|
|
||||||
itemRooms :: [(ItemIdentity, Room)]
|
itemRooms :: RandomGen g => [(ItemIdentity, State g (SubCompTree Room))]
|
||||||
itemRooms = []
|
itemRooms =
|
||||||
|
[ (Launcher , corridorBoss launcherCrit ) ]
|
||||||
|
|
||||||
|
corridorBoss :: RandomGen g => Creature -> State g (SubCompTree Room)
|
||||||
|
corridorBoss cr = do
|
||||||
|
endroom <- bossRoom cr
|
||||||
|
return $ treeFromPost (replicate 5 $ PassDown corridor)
|
||||||
|
(PassDown endroom)
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ roomGlassOctogon x = createPathGrid $ defaultRoom
|
|||||||
,blockLine (V2 (-40) (50-x)) (V2 40 (50-x))
|
,blockLine (V2 (-40) (50-x)) (V2 40 (50-x))
|
||||||
]
|
]
|
||||||
, _rmBound = [rectNSWE x (-x) (-x) x]
|
, _rmBound = [rectNSWE x (-x) (-x) x]
|
||||||
|
, _rmName = "glass8gon"
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
fx = 4 * x / 5
|
fx = 4 * x / 5
|
||||||
@@ -101,6 +102,7 @@ roomCross x y = defaultRoom
|
|||||||
[rectNSWE y (-y) (-x) x
|
[rectNSWE y (-y) (-x) x
|
||||||
,rectNSWE x (-x) (-y) y
|
,rectNSWE x (-x) (-y) y
|
||||||
]
|
]
|
||||||
|
, _rmName = "cross"
|
||||||
}
|
}
|
||||||
{- | TODO: pathing -}
|
{- | TODO: pathing -}
|
||||||
roomShuriken
|
roomShuriken
|
||||||
@@ -121,7 +123,8 @@ roomShuriken x y =
|
|||||||
, _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
|
||||||
}
|
}
|
||||||
in foldr1 combineRooms $ map (\r -> shiftRoomBy (V2 0 0, r) corner) [0,pi/2,pi,3*pi/2]
|
in (foldr1 combineRooms $ map (\r -> shiftRoomBy (V2 0 0, r) corner) [0,pi/2,pi,3*pi/2])
|
||||||
|
{_rmName = "shuriken"}
|
||||||
{- | TODO: pathing
|
{- | TODO: pathing
|
||||||
Precondition: first float is less than the second by at least 40. -}
|
Precondition: first float is less than the second by at least 40. -}
|
||||||
roomTwistCross
|
roomTwistCross
|
||||||
@@ -145,4 +148,5 @@ roomTwistCross x y z =
|
|||||||
, _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 = ps
|
, _rmBound = ps
|
||||||
}
|
}
|
||||||
in foldr1 combineRooms $ map (\r -> shiftRoomBy (V2 0 0, r) corner) [0,pi/2,pi,3*pi/2]
|
in (foldr1 combineRooms $ map (\r -> shiftRoomBy (V2 0 0, r) corner) [0,pi/2,pi,3*pi/2])
|
||||||
|
{_rmName = "twistCross" }
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ lightSensByDoor rm = rm
|
|||||||
& rmPmnts %~ (
|
& rmPmnts %~ (
|
||||||
[ psPt atFstLnkOut $ PutForeground $ colorSH yellow
|
[ psPt atFstLnkOut $ PutForeground $ colorSH yellow
|
||||||
$ barPP 1.5 (V3 20 (-1) 0) (V3 20 (-1) 80)
|
$ barPP 1.5 (V3 20 (-1) 0) (V3 20 (-1) 80)
|
||||||
, heightWallPS (atNthLnkOutShiftInward 1 50) 30 (rectNSEW (10) (-10) 20 (-20))
|
, heightWallPS (atNthLnkOutShiftInward 1 100) 30 (rectNSEW (10) (-10) 20 (-20))
|
||||||
, heightWallPS (atFstLnkOutShiftInward 100) 30 (rectNSEW (10) (-10) 20 (-20))
|
, heightWallPS (atFstLnkOutShiftInward 100) 30 (rectNSEW (10) (-10) 20 (-20))
|
||||||
] ++ )
|
] ++ )
|
||||||
& rmExtPmnt ?~
|
& rmExtPmnt ?~
|
||||||
@@ -76,6 +76,6 @@ lasCenSensEdge n = do
|
|||||||
cenroom <- randomiseOutLinks $ (lightSensByDoor cenLasTur) {_rmLabel = Just n}
|
cenroom <- randomiseOutLinks $ (lightSensByDoor cenLasTur) {_rmLabel = Just n}
|
||||||
let doorroom = switchDoorRoom {_rmTakeFrom = Just n}
|
let doorroom = switchDoorRoom {_rmTakeFrom = Just n}
|
||||||
return $ treeFromTrunk [PassDown door] (Node (PassDown cenroom)
|
return $ treeFromTrunk [PassDown door] (Node (PassDown cenroom)
|
||||||
[treeFromPost [PassDown doorroom] (UseAll door), treeFromPost [UseNone door] (UseNone corridor)
|
[treeFromPost [PassDown doorroom] (UseAll door), treeFromPost [PassDown door] (UseLabel 0 corridor)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
module Dodge.RoomComplex where
|
module Dodge.RoomComplex where
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,19 +7,29 @@ module Dodge.Tree.Compose
|
|||||||
, chainUses
|
, chainUses
|
||||||
, useAllAtEnd
|
, useAllAtEnd
|
||||||
, changeToPassDown
|
, changeToPassDown
|
||||||
|
, overwriteLabel
|
||||||
) where
|
) where
|
||||||
import Dodge.Tree.Compose.Data
|
import Dodge.Tree.Compose.Data
|
||||||
|
import Dodge.Tree.Polymorphic
|
||||||
import Data.Tree
|
import Data.Tree
|
||||||
|
|
||||||
expandTree :: CompTree a -> Tree a
|
expandTree :: CompTree a -> Tree a
|
||||||
expandTree (Node root extChildren) = case root of
|
expandTree (Node root extChildren) = case root of
|
||||||
Node (UseAll x) _ -> Node x (map expandTree extChildren)
|
Node (UseAll x) _ -> Node x (map expandTree extChildren)
|
||||||
Node (UseSome is x) _ -> Node x (map (expandTree . \i -> extChildren !! i) is)
|
Node (UseSome is x) _ -> Node x (map (expandTree . \i -> extChildren !! i) is)
|
||||||
Node (UseNone _) _ -> fmap _unCompose root
|
Node (UseNone _) _ -> fmap _unCompose root
|
||||||
|
Node (UseLabel _ _) _ -> fmap _unCompose root
|
||||||
Node (PassDown x) xs -> Node x $ map (expandTree . (`Node` extChildren)) xs
|
Node (PassDown x) xs -> Node x $ map (expandTree . (`Node` extChildren)) xs
|
||||||
Node (SplitDown x) xs -> Node x $ map expandTree $ zipWith Node xs
|
Node (SplitDown x) xs -> Node x $ map expandTree $ zipWith Node xs
|
||||||
$ map (:[]) extChildren ++ repeat []
|
$ map (:[]) extChildren ++ repeat []
|
||||||
|
|
||||||
|
overwriteLabel :: Int -> (a -> ComposingNode a) -> SubCompTree a -> [SubCompTree a] -> SubCompTree a
|
||||||
|
overwriteLabel i f t ts = head $ updateSingleNode islabel update t
|
||||||
|
where
|
||||||
|
islabel (UseLabel j _) | i == j = True
|
||||||
|
islabel _ = False
|
||||||
|
update (Node cr _) = Node (f $ _unCompose cr) ts
|
||||||
|
|
||||||
passUntilUseAll :: SubCompTree a -> [SubCompTree a] -> SubCompTree a
|
passUntilUseAll :: SubCompTree a -> [SubCompTree a] -> SubCompTree a
|
||||||
passUntilUseAll (Node (UseAll x) _) ts' = Node (PassDown x) ts'
|
passUntilUseAll (Node (UseAll x) _) ts' = Node (PassDown x) ts'
|
||||||
passUntilUseAll (Node cn ts) ts' = Node (PassDown (_unCompose cn)) $ map (`passUntilUseAll` ts') ts
|
passUntilUseAll (Node cn ts) ts' = Node (PassDown (_unCompose cn)) $ map (`passUntilUseAll` ts') ts
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ data ComposingNode a
|
|||||||
| UseAll {_unCompose :: a}
|
| UseAll {_unCompose :: a}
|
||||||
| UseSome {_composeIndices :: [Int], _unCompose :: a}
|
| UseSome {_composeIndices :: [Int], _unCompose :: a}
|
||||||
| UseNone {_unCompose :: a}
|
| UseNone {_unCompose :: a}
|
||||||
|
| UseLabel {_composeIndex :: Int, _unCompose :: a} -- defaults to using no children
|
||||||
type SubCompTree a = Tree (ComposingNode a)
|
type SubCompTree a = Tree (ComposingNode a)
|
||||||
type CompTree a = Tree (Tree (ComposingNode a))
|
type CompTree a = Tree (Tree (ComposingNode a))
|
||||||
makeLenses ''ComposingNode
|
makeLenses ''ComposingNode
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ module Dodge.Tree.Polymorphic
|
|||||||
, applyToRandomNode
|
, applyToRandomNode
|
||||||
, addToTrunk
|
, addToTrunk
|
||||||
, inorderNumberTree
|
, inorderNumberTree
|
||||||
|
, updateSingleNode
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Dodge.RandomHelp
|
import Dodge.RandomHelp
|
||||||
@@ -22,6 +23,7 @@ import Dodge.RandomHelp
|
|||||||
import Data.Tree
|
import Data.Tree
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import System.Random
|
import System.Random
|
||||||
|
import Control.Lens
|
||||||
|
|
||||||
{- |
|
{- |
|
||||||
Creates a linear tree.
|
Creates a linear tree.
|
||||||
@@ -73,6 +75,22 @@ applyToNode (i:is) f (Node x xs) = Node x (ys ++ [applyToNode is f z] ++ zs)
|
|||||||
-- | otherwise = Node x (applyToSubTrunkBy cond f t : ts)
|
-- | otherwise = Node x (applyToSubTrunkBy cond f t : ts)
|
||||||
--applyToSubTrunkBy _ _ t = t
|
--applyToSubTrunkBy _ _ t = t
|
||||||
|
|
||||||
|
-- gives the list of all updates to a single node
|
||||||
|
updateSingleNode :: (a -> Bool) -> (Tree a -> Tree a) -> Tree a -> [Tree a]
|
||||||
|
updateSingleNode f update t@(Node x ts)
|
||||||
|
| f x = update t : updateChildren
|
||||||
|
| otherwise = updateChildren
|
||||||
|
where
|
||||||
|
updateChildren = map (Node x) (subMap (updateSingleNode f update) ts)
|
||||||
|
|
||||||
|
subMap :: (a -> [a]) -> [a] -> [[a]]
|
||||||
|
subMap f (x:xs) = (f x <&> (: xs)) ++ ( (x :) <$> (subMap f xs) )
|
||||||
|
subMap _ [] = []
|
||||||
|
|
||||||
|
--subMap' :: Monad m => (a -> m a) -> [a] -> m [a]
|
||||||
|
--subMap' f (x:xs) = (f x <&> (: xs)) ++ ( (x :) <$> (subMap f xs) )
|
||||||
|
--subMap' f [] =
|
||||||
|
|
||||||
-- find use for?
|
-- find use for?
|
||||||
--zipTree :: Tree a -> Tree b -> Tree (a,b)
|
--zipTree :: Tree a -> Tree b -> Tree (a,b)
|
||||||
--zipTree (Node x xs) (Node y ys) = Node (x,y) $ zipWith zipTree xs ys
|
--zipTree (Node x xs) (Node y ys) = Node (x,y) $ zipWith zipTree xs ys
|
||||||
|
|||||||
@@ -48,7 +48,12 @@ posRms bounds parenti@(pr,i) numChild (t@(Node (cr,i') _):ts) tseq = do
|
|||||||
mayrs <- posRms (convexBounds ++ bounds)
|
mayrs <- posRms (convexBounds ++ bounds)
|
||||||
(first upr parenti) (numChild + 1) ts (tseq |> shiftedt)
|
(first upr parenti) (numChild + 1) ts (tseq |> shiftedt)
|
||||||
case mayrs of
|
case mayrs of
|
||||||
Nothing -> putStr ("Backtracking to room " ++ show i' ++ ": ") >> tryLinks (j+1) ls
|
--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 ))
|
||||||
|
tryLinks (j+1) ls
|
||||||
Just rs -> return (Just rs)
|
Just rs -> return (Just rs)
|
||||||
where
|
where
|
||||||
convexBounds = map pointsToPoly $ _rmBound r'
|
convexBounds = map pointsToPoly $ _rmBound r'
|
||||||
|
|||||||
Reference in New Issue
Block a user