Allow arbitrary changes to a room when using a link slot
This commit is contained in:
@@ -2,11 +2,13 @@ module Dodge.Default.Room
|
|||||||
where
|
where
|
||||||
import Geometry.Data
|
import Geometry.Data
|
||||||
import Dodge.LevelGen.Data
|
import Dodge.LevelGen.Data
|
||||||
|
import qualified Data.IntMap.Strict as IM
|
||||||
|
|
||||||
defaultRoom :: Room
|
defaultRoom :: Room
|
||||||
defaultRoom = Room
|
defaultRoom = Room
|
||||||
{ _rmPolys = []
|
{ _rmPolys = []
|
||||||
, _rmLinks = []
|
, _rmLinks = []
|
||||||
|
, _rmLinkEff = []
|
||||||
, _rmPos = []
|
, _rmPos = []
|
||||||
, _rmPath = []
|
, _rmPath = []
|
||||||
, _rmPmnts = []
|
, _rmPmnts = []
|
||||||
@@ -20,5 +22,6 @@ defaultRoom = Room
|
|||||||
, _rmRandPSs = []
|
, _rmRandPSs = []
|
||||||
, _rmLabel = Nothing
|
, _rmLabel = Nothing
|
||||||
, _rmTakeFrom = Nothing
|
, _rmTakeFrom = Nothing
|
||||||
, _rmWires = []
|
, _rmStartWires = IM.empty
|
||||||
|
, _rmEndWires = IM.empty
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-2
@@ -18,6 +18,7 @@ import Dodge.Item.Weapon.Launcher
|
|||||||
import MonadHelp
|
import MonadHelp
|
||||||
import Data.Tree
|
import Data.Tree
|
||||||
import Color
|
import Color
|
||||||
|
import Dodge.Wire
|
||||||
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
@@ -25,12 +26,18 @@ import Control.Monad.Loops
|
|||||||
import System.Random
|
import System.Random
|
||||||
import Data.Sequence hiding (zipWith)
|
import Data.Sequence hiding (zipWith)
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
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
|
||||||
[[StartRoom]
|
[[StartRoom]
|
||||||
,[ChainAnos [[SetLabel 0 $ return $ roomRectAutoLinks 100 100
|
,[ChainAnos
|
||||||
& rmExtPmnt ?~ externalButton red (anyLnkInPS 5) ]
|
[[SetLabel 0 $ return $ roomRectAutoLinks 100 100
|
||||||
|
& rmExtPmnt ?~ externalButton red (anyLnkInPS 5)
|
||||||
|
& rmStartWires .~ IM.fromList [(0,RoomWire 0 0)]
|
||||||
|
& rmLinkEff .~ [putWireEnd 0]
|
||||||
|
]
|
||||||
,[UseLabel 0 $ return switchDoorRoom]
|
,[UseLabel 0 $ return switchDoorRoom]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|||||||
+9
-6
@@ -7,11 +7,10 @@ import Dodge.LevelGen
|
|||||||
import Dodge.LevelGen.Data
|
import Dodge.LevelGen.Data
|
||||||
import Dodge.LevelGen.StaticWalls
|
import Dodge.LevelGen.StaticWalls
|
||||||
import Dodge.LevelGen.Pathing
|
import Dodge.LevelGen.Pathing
|
||||||
|
import Dodge.Room.Foreground
|
||||||
import Dodge.Wall.Zone
|
import Dodge.Wall.Zone
|
||||||
import Dodge.GameRoom
|
import Dodge.GameRoom
|
||||||
import Dodge.Bounds
|
import Dodge.Bounds
|
||||||
--import Dodge.LevelGen.Data
|
|
||||||
import Dodge.Room.Foreground
|
|
||||||
import Dodge.Default.Wall
|
import Dodge.Default.Wall
|
||||||
import Geometry
|
import Geometry
|
||||||
import qualified IntMapHelp as IM
|
import qualified IntMapHelp as IM
|
||||||
@@ -50,11 +49,15 @@ placeWires :: (World,[Room])-> World
|
|||||||
placeWires (w,rms) = foldr placeRoomWires w rms
|
placeWires (w,rms) = foldr placeRoomWires w rms
|
||||||
|
|
||||||
placeRoomWires :: Room -> World -> World
|
placeRoomWires :: Room -> World -> World
|
||||||
placeRoomWires rm w = foldr placeWire w (_rmWires rm)
|
placeRoomWires rm w = IM.foldr ($) w
|
||||||
|
$ IM.intersectionWith (placeWire rm) (_rmStartWires rm) (_rmEndWires rm)
|
||||||
|
|
||||||
placeWire :: RoomWire -> World -> World
|
placeWire :: Room -> RoomWire -> RoomWire -> World -> World
|
||||||
placeWire rw w = case rw of
|
placeWire rm (RoomWire p' _) (RoomWire q' _) w = w & foregroundShape %~ (thinHighBar 40 p q <>)
|
||||||
RoomWire (p,_) (q,_) -> w & foregroundShape %~ (thinHighBar 40 p q <>)
|
where
|
||||||
|
rs = _rmShift rm
|
||||||
|
p = shiftPointBy rs p'
|
||||||
|
q = shiftPointBy rs q'
|
||||||
|
|
||||||
doPartialPlacements :: ( (IM.IntMap [Placement],World) , [Room] ) -> (World,[Room])
|
doPartialPlacements :: ( (IM.IntMap [Placement],World) , [Room] ) -> (World,[Room])
|
||||||
doPartialPlacements ((im,w),rms) = mapAccumR (doPartialPlacement im) w rms
|
doPartialPlacements ((im,w),rms) = mapAccumR (doPartialPlacement im) w rms
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import Dodge.LevelGen.Data
|
|||||||
import Dodge.Room.Link
|
import Dodge.Room.Link
|
||||||
import Dodge.Layout.Tree.Polymorphic
|
import Dodge.Layout.Tree.Polymorphic
|
||||||
import Geometry.ConvexPoly
|
import Geometry.ConvexPoly
|
||||||
|
import Geometry.Data
|
||||||
|
|
||||||
import Data.Tree
|
import Data.Tree
|
||||||
import Data.Sequence hiding (zipWith)
|
import Data.Sequence hiding (zipWith)
|
||||||
@@ -40,13 +41,18 @@ posRms bounds (r,i) (t@(Node (_,i') _):ts) tseq = do
|
|||||||
| clipping = tryLinks (j+1) ls
|
| clipping = tryLinks (j+1) ls
|
||||||
| otherwise = do
|
| otherwise = do
|
||||||
putStrLn $ "placing at link " ++ show j
|
putStrLn $ "placing at link " ++ show j
|
||||||
mayrs <- posRms (convexBounds ++ bounds) useLink ts (tseq |> shiftedt)
|
mayrs <- posRms (convexBounds ++ bounds) newr ts (tseq |> shiftedt)
|
||||||
case mayrs of
|
case mayrs of
|
||||||
Nothing -> do putStr ("Backtracking to room " ++ show i' ++ ": ") >> tryLinks (j+1) ls
|
Nothing -> do putStr ("Backtracking to room " ++ 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'
|
||||||
clipping = or (convexPolysOverlap <$> convexBounds <*> bounds)
|
clipping = or (convexPolysOverlap <$> convexBounds <*> bounds)
|
||||||
useLink = (r & rmLinks %~ delete l & rmPos %~ (uncurry (OutLink (Prelude.length ts)) l :)
|
newr = (lnkEff l $ r & rmLinks %~ delete l & rmPos %~ (uncurry (OutLink j) l :)
|
||||||
, i)
|
, i)
|
||||||
shiftedt@(Node (r',_) _) = applyToRoot (first $ shiftRoomToLink l) t
|
shiftedt@(Node (r',_) _) = applyToRoot (first $ shiftRoomToLink l) t
|
||||||
|
|
||||||
|
lnkEff :: (Point2,Float) -> Room -> Room
|
||||||
|
lnkEff x rm = case _rmLinkEff rm of
|
||||||
|
(eff:effs) -> eff x $ rm & rmLinkEff .~ effs
|
||||||
|
_ -> rm
|
||||||
|
|||||||
@@ -48,19 +48,23 @@ placeSpot (w,rm) plmnt = case plmnt of
|
|||||||
where
|
where
|
||||||
shift = _rmShift rm
|
shift = _rmShift rm
|
||||||
|
|
||||||
|
-- this should be tidied up
|
||||||
placeSpotUsingLink :: World -> Room -> Placement -> ((World, Room), [Placement])
|
placeSpotUsingLink :: World -> Room -> Placement -> ((World, Room), [Placement])
|
||||||
placeSpotUsingLink w rm plmnt = case lnks of
|
placeSpotUsingLink w rm plmnt = case lnks of
|
||||||
((lnki,lnk):_) -> placeSpot (w & randGen .~ g,uselnk lnki) (updatePS (f lnk) plmnt)
|
((lnki,lnk):_) -> placeSpot (w & randGen .~ g,uselnk lnki lnk) (updatePS (f lnk) plmnt)
|
||||||
[] -> case fallback of
|
[] -> case fallback of
|
||||||
Nothing -> ((w,rm),[plmnt])
|
Nothing -> ((w,rm),[plmnt])
|
||||||
Just plmnt' -> placeSpot (w,rm) plmnt'
|
Just plmnt' -> placeSpot (w,rm) plmnt'
|
||||||
where
|
where
|
||||||
uselnk lnki = rm & rmLinks %~ deletei lnki
|
uselnk lnki lnk = _psLnkRoomEff rps (f' lnk rps) rm & rmLinks %~ deletei lnki
|
||||||
rps = _plSpot plmnt
|
rps = _plSpot plmnt
|
||||||
fallback = _psLnkFallback rps
|
fallback = _psLnkFallback rps
|
||||||
test = _psLnkTest rps
|
test = _psLnkTest rps
|
||||||
(lnks,g) = runState (shuffle $ filter (test . snd) $ zip [0..]
|
(lnks,g) = runState (shuffle $ filter (test . snd) $ zip [0..]
|
||||||
$ map (invShiftLinkBy $ _rmShift rm) $ _rmLinks rm) $ _randGen w
|
$ map (invShiftLinkBy $ _rmShift rm) $ _rmLinks rm) $ _randGen w
|
||||||
|
f' x (PSLnk t s _ _)
|
||||||
|
| t x = s x
|
||||||
|
f' _ _ = error "wrong type of link: something is wrong"
|
||||||
f x (PSLnk t s _ _)
|
f x (PSLnk t s _ _)
|
||||||
| t x = uncurry PS $ s x
|
| t x = uncurry PS $ s x
|
||||||
f _ ps = ps
|
f _ ps = ps
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import Control.Lens
|
|||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import System.Random
|
import System.Random
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import qualified Data.IntMap.Strict as IM
|
||||||
--import Data.Bifunctor
|
--import Data.Bifunctor
|
||||||
data PSType = PutCrit {_unPutCrit :: Creature}
|
data PSType = PutCrit {_unPutCrit :: Creature}
|
||||||
| PutMachine Color [Point2] Machine
|
| PutMachine Color [Point2] Machine
|
||||||
@@ -119,6 +120,7 @@ assigning no bounds will allow rooms to overlap.
|
|||||||
data Room = Room
|
data Room = Room
|
||||||
{ _rmPolys :: [ [Point2] ]
|
{ _rmPolys :: [ [Point2] ]
|
||||||
, _rmLinks :: [(Point2,Float)]
|
, _rmLinks :: [(Point2,Float)]
|
||||||
|
, _rmLinkEff :: [(Point2,Float) -> Room -> Room]
|
||||||
, _rmPos :: [RoomPos]
|
, _rmPos :: [RoomPos]
|
||||||
, _rmPath :: [(Point2, Point2)]
|
, _rmPath :: [(Point2, Point2)]
|
||||||
, _rmPmnts :: [Placement]
|
, _rmPmnts :: [Placement]
|
||||||
@@ -132,10 +134,11 @@ data Room = Room
|
|||||||
, _rmRandPSs :: [State StdGen (Point2,Float)]
|
, _rmRandPSs :: [State StdGen (Point2,Float)]
|
||||||
, _rmLabel :: Maybe Int
|
, _rmLabel :: Maybe Int
|
||||||
, _rmTakeFrom :: Maybe Int
|
, _rmTakeFrom :: Maybe Int
|
||||||
, _rmWires :: [RoomWire]
|
, _rmStartWires :: IM.IntMap RoomWire
|
||||||
|
, _rmEndWires :: IM.IntMap RoomWire
|
||||||
}
|
}
|
||||||
data RoomWire
|
data RoomWire
|
||||||
= RoomWire (Point2,Float) (Point2,Float)
|
= RoomWire Point2 Float
|
||||||
data RoomPos
|
data RoomPos
|
||||||
= OutLink Int Point2 Float
|
= OutLink Int Point2 Float
|
||||||
| InLink Point2 Float
|
| InLink Point2 Float
|
||||||
|
|||||||
@@ -39,4 +39,3 @@ putLitButtonID' col f subpl
|
|||||||
changeLight lsid = lightSources . ix lsid . lsIntensity .~ V3 0 0.5 0
|
changeLight lsid = lightSources . ix lsid . lsIntensity .~ V3 0 0.5 0
|
||||||
ls = defaultLS { _lsRad = 75 , _lsIntensity = V3 0.5 0 0 }
|
ls = defaultLS { _lsRad = 75 , _lsIntensity = V3 0.5 0 0 }
|
||||||
thePS = PSLnk f id (const id) Nothing
|
thePS = PSLnk f id (const id) Nothing
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
--{-# LANGUAGE TupleSections #-}
|
--{-# LANGUAGE TupleSections #-}
|
||||||
module Dodge.Room.Foreground
|
module Dodge.Room.Foreground where
|
||||||
where
|
|
||||||
import Picture
|
import Picture
|
||||||
import Geometry
|
import Geometry
|
||||||
import Geometry.Vector3D
|
import Geometry.Vector3D
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import Data.Tree
|
|||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import System.Random
|
import System.Random
|
||||||
|
import qualified Data.IntMap.Strict as IM
|
||||||
|
|
||||||
rezBox :: Room
|
rezBox :: Room
|
||||||
rezBox = shiftRoomBy (V2 (-20) (-10),0) $ roomRect 40 20 1 1
|
rezBox = shiftRoomBy (V2 (-20) (-10),0) $ roomRect 40 20 1 1
|
||||||
@@ -39,4 +40,6 @@ startRoom = do
|
|||||||
<$> randomiseOutLinks
|
<$> randomiseOutLinks
|
||||||
(shiftRoomBy (V2 (-20) (-20),0)
|
(shiftRoomBy (V2 (-20) (-20),0)
|
||||||
$ roomRectAutoLinks w h & rmPmnts %~ (plmnts ++)
|
$ roomRectAutoLinks w h & rmPmnts %~ (plmnts ++)
|
||||||
|
& rmStartWires .~ IM.fromList [(0,RoomWire (V2 0 0) 0)]
|
||||||
|
& rmEndWires .~ IM.fromList [(0,RoomWire (V2 (500) 500) 0)]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
module Dodge.Wire where
|
||||||
|
import Dodge.LevelGen.Data
|
||||||
|
import Dodge.Room.Link
|
||||||
|
import Geometry
|
||||||
|
|
||||||
|
import qualified Data.IntMap.Strict as IM
|
||||||
|
import Control.Lens
|
||||||
|
|
||||||
|
putWireEnd :: Int -> (Point2,Float) -> Room -> Room
|
||||||
|
putWireEnd i pos rm = rm & rmEndWires %~ IM.insert i (uncurry RoomWire $ invShiftLinkBy (_rmShift rm) pos)
|
||||||
Reference in New Issue
Block a user