Continue placement refactor
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
module Dodge.Default.Room
|
module Dodge.Default.Room
|
||||||
where
|
where
|
||||||
|
import Geometry.Data
|
||||||
import Dodge.Room.Data
|
import Dodge.Room.Data
|
||||||
|
|
||||||
defaultRoom :: Room
|
defaultRoom :: Room
|
||||||
@@ -11,4 +12,5 @@ defaultRoom = Room
|
|||||||
, _rmBound = []
|
, _rmBound = []
|
||||||
, _rmFloor = []
|
, _rmFloor = []
|
||||||
, _rmName = "defaultRoom"
|
, _rmName = "defaultRoom"
|
||||||
|
, _rmShift = (V2 0 0 , 0)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-20
@@ -31,7 +31,7 @@ import System.Random
|
|||||||
--import Data.List
|
--import Data.List
|
||||||
--import Data.Maybe
|
--import Data.Maybe
|
||||||
import Data.Tree
|
import Data.Tree
|
||||||
import Data.Graph.Inductive.Graph (labNodes)
|
--import Data.Graph.Inductive.Graph (labNodes)
|
||||||
--import qualified Data.Map as M
|
--import qualified Data.Map as M
|
||||||
import Data.Foldable
|
import Data.Foldable
|
||||||
import qualified Control.Foldl as L
|
import qualified Control.Foldl as L
|
||||||
@@ -43,7 +43,7 @@ generateLevelFromRoomList gr w
|
|||||||
. setupWorldBounds
|
. setupWorldBounds
|
||||||
-- . initializeStaticWalls
|
-- . initializeStaticWalls
|
||||||
-- . setupForegroundEdgeVerxs
|
-- . setupForegroundEdgeVerxs
|
||||||
. placeSpots plmnts
|
. flip (foldr placeSpot') plmnts
|
||||||
-- . addRoomPolyDecorations rs
|
-- . addRoomPolyDecorations rs
|
||||||
-- . addRoomLinkDecorations rs
|
-- . addRoomLinkDecorations rs
|
||||||
$ w { _walls = wallsFromRooms rs
|
$ w { _walls = wallsFromRooms rs
|
||||||
@@ -55,7 +55,7 @@ generateLevelFromRoomList gr w
|
|||||||
where
|
where
|
||||||
path = pairsToGraph dist pairPath
|
path = pairsToGraph dist pairPath
|
||||||
pairPath = concatMap _rmPath rs
|
pairPath = concatMap _rmPath rs
|
||||||
plmnts = concatMap _rmPS rs
|
plmnts = concat $ map (\r -> map ((,) (_rmShift r)) (_rmPS r)) rs
|
||||||
rs = zipWith addTile zs rs'
|
rs = zipWith addTile zs rs'
|
||||||
zs = map fromIntegral $ randomRs (0,63::Int) $ _randGen w
|
zs = map fromIntegral $ randomRs (0,63::Int) $ _randGen w
|
||||||
rs' = evalState gr $ _randGen w
|
rs' = evalState gr $ _randGen w
|
||||||
@@ -79,23 +79,6 @@ setupWorldBounds w = w
|
|||||||
polyhedrasToEdges :: [Polyhedra] -> [Point3]
|
polyhedrasToEdges :: [Polyhedra] -> [Point3]
|
||||||
polyhedrasToEdges = concatMap tflat4 . concatMap polyToEdges
|
polyhedrasToEdges = concatMap tflat4 . concatMap polyToEdges
|
||||||
|
|
||||||
-- | connects a collection (tree) of rooms together
|
|
||||||
generateFromTree :: State StdGen (Tree Room) -> World -> World
|
|
||||||
generateFromTree t w = updateWallZoning $ placeSpots plmnts
|
|
||||||
$ w {_walls = wallsFromTree tr
|
|
||||||
,_pathGraph = path
|
|
||||||
,_pathGraphP = pairGraph
|
|
||||||
,_pathPoints = foldl' (flip insertPoint) IM.empty (labNodes path)
|
|
||||||
}
|
|
||||||
where
|
|
||||||
tr = evalState t $ _randGen w
|
|
||||||
plmnts = concatMap _rmPS $ flatten tr
|
|
||||||
path = pairsToGraph dist pairGraph
|
|
||||||
pairGraph = makePath tr
|
|
||||||
insertPoint pp@(_,V2 x y) = insertInZoneWith (floorHun x) (floorHun y) (++) [pp]
|
|
||||||
--pinc = M.fromList $ pairsToIncidence pairGraph
|
|
||||||
|
|
||||||
|
|
||||||
updateWallZoning :: World -> World
|
updateWallZoning :: World -> World
|
||||||
updateWallZoning w = set (wallsZone . znObjects) (foldl' (flip wallInZone) IM.empty (_walls w)) w
|
updateWallZoning w = set (wallsZone . znObjects) (foldl' (flip wallInZone) IM.empty (_walls w)) w
|
||||||
where
|
where
|
||||||
|
|||||||
+10
-15
@@ -9,7 +9,6 @@ module Dodge.LevelGen
|
|||||||
, makeSwitch
|
, makeSwitch
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
--import Dodge.Room.Data
|
|
||||||
import Dodge.LevelGen.Block
|
import Dodge.LevelGen.Block
|
||||||
import Dodge.LevelGen.LineBlock
|
import Dodge.LevelGen.LineBlock
|
||||||
import Dodge.LevelGen.Pathing
|
import Dodge.LevelGen.Pathing
|
||||||
@@ -21,26 +20,22 @@ import Dodge.LevelGen.Data
|
|||||||
import Geometry
|
import Geometry
|
||||||
import Geometry.Vector3D
|
import Geometry.Vector3D
|
||||||
import Shape
|
import Shape
|
||||||
--import Geometry.Data
|
|
||||||
import Picture
|
import Picture
|
||||||
import qualified IntMapHelp as IM
|
import qualified IntMapHelp as IM
|
||||||
|
|
||||||
--import System.Random
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
--import Control.Applicative
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Data.List.Extra
|
|
||||||
--import Data.Function
|
|
||||||
--import Data.Maybe
|
|
||||||
--import qualified Data.Set as S
|
|
||||||
--import qualified Data.Map as M
|
|
||||||
|
|
||||||
placeSpots :: [Placement] -> World -> World
|
placeSpot' :: ((Point2,Float) , Placement) -> World -> World
|
||||||
placeSpots pss w = foldr (placeSpot . _placementSpot) w simplePlacements
|
placeSpot' (shift, plmnt) = placeSpot $ shiftPSBy' shift (_placementSpot plmnt)
|
||||||
where
|
|
||||||
(simplePlacements, idPlacements ) = partition isSimple pss
|
shiftPSBy'
|
||||||
isSimple SimplePlacement{} = True
|
:: (Point2,Float)
|
||||||
isSimple _ = False
|
-> PlacementSpot
|
||||||
|
-> PlacementSpot
|
||||||
|
shiftPSBy' (pos,rot) ps = ps
|
||||||
|
& psPos %~ shiftPointBy (pos,rot)
|
||||||
|
& psRot %~ (+ rot)
|
||||||
|
|
||||||
placeSpot :: PlacementSpot -> World -> World
|
placeSpot :: PlacementSpot -> World -> World
|
||||||
placeSpot ps w = case _psType ps of
|
placeSpot ps w = case _psType ps of
|
||||||
|
|||||||
@@ -49,16 +49,12 @@ data PlacementSpot = PS
|
|||||||
, _psRot :: Float
|
, _psRot :: Float
|
||||||
, _psType :: PSType
|
, _psType :: PSType
|
||||||
}
|
}
|
||||||
data Placement
|
data Placement = Placement
|
||||||
= SimplePlacement {_placementSpot :: PlacementSpot }
|
{ _placementSpot :: PlacementSpot
|
||||||
| IDPlacement {_placementSpot :: PlacementSpot, _idPlacement :: Int -> Placement }
|
, _idPlacement :: Int -> Maybe Placement
|
||||||
-- | GroupedPlacement
|
}
|
||||||
-- {_groupPlacementID :: Int
|
|
||||||
-- ,_groupUpdate :: World -> [Placement] -> World
|
|
||||||
-- ,_placementSpot :: PlacementSpot
|
|
||||||
-- }
|
|
||||||
sPS :: Point2 -> Float -> PSType -> Placement
|
sPS :: Point2 -> Float -> PSType -> Placement
|
||||||
sPS p a = SimplePlacement . PS p a
|
sPS p a pt = Placement (PS p a pt) (const Nothing)
|
||||||
makeLenses ''PSType
|
makeLenses ''PSType
|
||||||
makeLenses ''PlacementSpot
|
makeLenses ''PlacementSpot
|
||||||
makeLenses ''Placement
|
makeLenses ''Placement
|
||||||
|
|||||||
@@ -2,17 +2,17 @@ module Dodge.LevelGen.SwarmPlacement
|
|||||||
( --swarmPS
|
( --swarmPS
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Dodge.Data
|
--import Dodge.Data
|
||||||
import Dodge.LevelGen.Data
|
--import Dodge.LevelGen.Data
|
||||||
import Dodge.Creature.State.Data
|
--import Dodge.Creature.State.Data
|
||||||
--import Geometry
|
----import Geometry
|
||||||
import Geometry.ConvexPoly
|
--import Geometry.ConvexPoly
|
||||||
import Geometry.Data
|
--import Geometry.Data
|
||||||
import qualified IntMapHelp as IM
|
--import qualified IntMapHelp as IM
|
||||||
|
--
|
||||||
import Data.List
|
--import Data.List
|
||||||
import qualified Data.IntSet as IS
|
--import qualified Data.IntSet as IS
|
||||||
import Control.Lens
|
--import Control.Lens
|
||||||
|
|
||||||
--swarmPS :: Int -> Point2 -> Float -> Creature -> Placement
|
--swarmPS :: Int -> Point2 -> Float -> Creature -> Placement
|
||||||
--swarmPS i p a cr = GroupedPlacement
|
--swarmPS i p a cr = GroupedPlacement
|
||||||
|
|||||||
+2
-10
@@ -1,17 +1,8 @@
|
|||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
{-# LANGUAGE StrictData #-}
|
{-# LANGUAGE StrictData #-}
|
||||||
module Dodge.Room.Data
|
module Dodge.Room.Data
|
||||||
( Room (..)
|
where
|
||||||
, rmPolys
|
|
||||||
, rmLinks
|
|
||||||
, rmPath
|
|
||||||
, rmPS
|
|
||||||
, rmBound
|
|
||||||
, rmFloor
|
|
||||||
, rmName
|
|
||||||
) where
|
|
||||||
import Dodge.LevelGen.Data
|
import Dodge.LevelGen.Data
|
||||||
--import Geometry
|
|
||||||
import Geometry.Data
|
import Geometry.Data
|
||||||
import Data.Tile
|
import Data.Tile
|
||||||
|
|
||||||
@@ -33,5 +24,6 @@ data Room = Room
|
|||||||
, _rmBound :: [ [Point2] ]
|
, _rmBound :: [ [Point2] ]
|
||||||
, _rmFloor :: [Tile]
|
, _rmFloor :: [Tile]
|
||||||
, _rmName :: String
|
, _rmName :: String
|
||||||
|
, _rmShift :: (Point2, Float)
|
||||||
}
|
}
|
||||||
makeLenses ''Room
|
makeLenses ''Room
|
||||||
|
|||||||
@@ -63,14 +63,14 @@ shiftRoomToLink l r
|
|||||||
r
|
r
|
||||||
where
|
where
|
||||||
(p,a) = last $ _rmLinks r
|
(p,a) = last $ _rmLinks r
|
||||||
|
-- NOTE placements are shifted by the room shift
|
||||||
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)
|
& rmLinks %~ fmap (shiftLinkBy shift)
|
||||||
& rmPath %~ map (shiftPathPointBy shift)
|
& rmPath %~ map (shiftPathPointBy shift)
|
||||||
& rmPS %~ fmap (shiftPSBy shift)
|
|
||||||
& rmBound %~ fmap (map (shiftPointBy shift))
|
& rmBound %~ fmap (map (shiftPointBy shift))
|
||||||
|
& rmShift %~ shiftLinkBy shift
|
||||||
& rmFloor %~ map
|
& rmFloor %~ map
|
||||||
( (tilePoly %~ map (shiftPointBy shift))
|
( (tilePoly %~ map (shiftPointBy shift))
|
||||||
. (tileZero %~ shiftPointBy shift )
|
. (tileZero %~ shiftPointBy shift )
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import Control.Lens
|
|||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import Data.Tree
|
import Data.Tree
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import qualified Data.IntMap as IM
|
--import qualified Data.IntMap as IM
|
||||||
|
|
||||||
twinSlowDoorRoom
|
twinSlowDoorRoom
|
||||||
:: Int -- ^ Door id
|
:: Int -- ^ Door id
|
||||||
@@ -56,7 +56,7 @@ twinSlowDoorRoom drid w h x = defaultRoom
|
|||||||
, _rmName = "twinSlowDoorRoom"
|
, _rmName = "twinSlowDoorRoom"
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
drmoving w' = True -- DoorHalfway == _drStatus (_doors w' IM.! drid)
|
drmoving _ = True -- DoorHalfway == _drStatus (_doors w' IM.! drid)
|
||||||
lampHeight = 41
|
lampHeight = 41
|
||||||
ps =
|
ps =
|
||||||
[rectNSWE h 0 (-w) w
|
[rectNSWE h 0 (-w) w
|
||||||
|
|||||||
@@ -30,33 +30,33 @@ Places a line of blocks between two points.
|
|||||||
Width 9, also extends out from each point by 9.
|
Width 9, also extends out from each point by 9.
|
||||||
-}
|
-}
|
||||||
blockLine :: Point2 -> Point2 -> Placement
|
blockLine :: Point2 -> Point2 -> Placement
|
||||||
blockLine a b = SimplePlacement $ PS
|
blockLine a b = Placement PS
|
||||||
{ _psPos = V2 0 0
|
{ _psPos = V2 0 0
|
||||||
, _psRot = 0
|
, _psRot = 0
|
||||||
, _psType = PutLineBlock baseBlockPane 9 9 a b
|
, _psType = PutLineBlock baseBlockPane 9 9 a b
|
||||||
}
|
} (const Nothing)
|
||||||
|
|
||||||
{-
|
{-
|
||||||
Places an breakable window between two points.
|
Places an breakable window between two points.
|
||||||
Width 8, also extends out from each point by 8.
|
Width 8, also extends out from each point by 8.
|
||||||
-}
|
-}
|
||||||
windowLine :: Point2 -> Point2 -> Placement
|
windowLine :: Point2 -> Point2 -> Placement
|
||||||
windowLine a b = SimplePlacement $ PS
|
windowLine a b = Placement PS
|
||||||
{ _psPos = V2 0 0
|
{ _psPos = V2 0 0
|
||||||
, _psRot = 0
|
, _psRot = 0
|
||||||
, _psType = PutLineBlock baseWindowPane 8 8 a b
|
, _psType = PutLineBlock baseWindowPane 8 8 a b
|
||||||
}
|
} (const Nothing)
|
||||||
|
|
||||||
{-
|
{-
|
||||||
Places an unbreakable window between two points.
|
Places an unbreakable window between two points.
|
||||||
Width 7, also extends out from each point by 7.
|
Width 7, also extends out from each point by 7.
|
||||||
-}
|
-}
|
||||||
crystalLine :: Point2 -> Point2 -> Placement
|
crystalLine :: Point2 -> Point2 -> Placement
|
||||||
crystalLine a b = SimplePlacement $ PS
|
crystalLine a b = Placement PS
|
||||||
{ _psPos = V2 0 0
|
{ _psPos = V2 0 0
|
||||||
, _psRot = 0
|
, _psRot = 0
|
||||||
, _psType = PutWall ps defaultCrystalWall
|
, _psType = PutWall ps defaultCrystalWall
|
||||||
}
|
} (const Nothing)
|
||||||
where
|
where
|
||||||
ps =
|
ps =
|
||||||
[ a +.+ left +.+ up
|
[ a +.+ left +.+ up
|
||||||
@@ -70,11 +70,11 @@ crystalLine a b = SimplePlacement $ PS
|
|||||||
Depth 15, does not extend wider than points.
|
Depth 15, does not extend wider than points.
|
||||||
-}
|
-}
|
||||||
wallLine :: Point2 -> Point2 -> Placement
|
wallLine :: Point2 -> Point2 -> Placement
|
||||||
wallLine a b = SimplePlacement $ PS
|
wallLine a b = Placement PS
|
||||||
{ _psPos = V2 0 0
|
{ _psPos = V2 0 0
|
||||||
, _psRot = 0
|
, _psRot = 0
|
||||||
, _psType = PutWall ps defaultWall
|
, _psType = PutWall ps defaultWall
|
||||||
}
|
} (const Nothing)
|
||||||
where
|
where
|
||||||
ps =
|
ps =
|
||||||
[ a +.+ up
|
[ a +.+ up
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ fillNothingPlacement :: PSType -> Room -> Room
|
|||||||
fillNothingPlacement pst r =
|
fillNothingPlacement pst r =
|
||||||
r & rmPS %~ replaceNothingWith pst
|
r & rmPS %~ replaceNothingWith pst
|
||||||
where
|
where
|
||||||
replaceNothingWith x (SimplePlacement (PS p rot PutNothing): pss) = sPS p rot x : pss
|
replaceNothingWith x (Placement (PS p rot PutNothing) _: pss) = sPS p rot x : pss
|
||||||
replaceNothingWith x (ps:pss) = ps : replaceNothingWith x pss
|
replaceNothingWith x (ps:pss) = ps : replaceNothingWith x pss
|
||||||
replaceNothingWith _ [] = []
|
replaceNothingWith _ [] = []
|
||||||
{- | Successively fill 'PutNothing' placements with a list of given 'PSType's.
|
{- | Successively fill 'PutNothing' placements with a list of given 'PSType's.
|
||||||
|
|||||||
Reference in New Issue
Block a user