Assign used links during room generation
This commit is contained in:
@@ -7,6 +7,7 @@ defaultRoom :: Room
|
|||||||
defaultRoom = Room
|
defaultRoom = Room
|
||||||
{ _rmPolys = []
|
{ _rmPolys = []
|
||||||
, _rmLinks = []
|
, _rmLinks = []
|
||||||
|
, _rmUsedLinks = []
|
||||||
, _rmPath = []
|
, _rmPath = []
|
||||||
, _rmPS = []
|
, _rmPS = []
|
||||||
, _rmBound = []
|
, _rmBound = []
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ import qualified Data.Map as M
|
|||||||
|
|
||||||
firstWorld :: IO World
|
firstWorld :: IO World
|
||||||
firstWorld = do
|
firstWorld = do
|
||||||
-- i <- randomRIO (0,5000)
|
i <- randomRIO (0,5000)
|
||||||
let i = 2
|
-- let i = 2
|
||||||
putStrLn $ "Seed for level generation: " ++ show ( i :: Int)
|
putStrLn $ "Seed for level generation: " ++ show ( i :: Int)
|
||||||
return $ generateLevelFromRoomList (levx 1) $ initialWorld {_randGen = mkStdGen i}
|
return $ generateLevelFromRoomList (levx 1) $ initialWorld {_randGen = mkStdGen i}
|
||||||
|
|
||||||
|
|||||||
+3
-8
@@ -29,8 +29,6 @@ import Data.List (nubBy)
|
|||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import System.Random
|
import System.Random
|
||||||
--import Data.List
|
|
||||||
--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
|
||||||
@@ -42,11 +40,7 @@ generateLevelFromRoomList :: State StdGen [Room] -> World -> World
|
|||||||
generateLevelFromRoomList gr w
|
generateLevelFromRoomList gr w
|
||||||
= updateWallZoning
|
= updateWallZoning
|
||||||
. setupWorldBounds
|
. setupWorldBounds
|
||||||
-- . initializeStaticWalls
|
|
||||||
-- . setupForegroundEdgeVerxs
|
|
||||||
. flip (foldr $ flip placeSpot) plmnts
|
. flip (foldr $ flip placeSpot) plmnts
|
||||||
-- . addRoomPolyDecorations rs
|
|
||||||
-- . addRoomLinkDecorations rs
|
|
||||||
$ w { _walls = wallsFromRooms rs
|
$ w { _walls = wallsFromRooms rs
|
||||||
, _floorTiles = floorsFromRooms rs
|
, _floorTiles = floorsFromRooms rs
|
||||||
, _gameRooms = gameRoomsFromRooms rs
|
, _gameRooms = gameRoomsFromRooms rs
|
||||||
@@ -122,10 +116,11 @@ gameRoomsFromRooms = map f
|
|||||||
where
|
where
|
||||||
f rm = GameRoom
|
f rm = GameRoom
|
||||||
{ _grViewpoints = _rmViewpoints rm ++ (map fst . foldl' (flip cutWalls) [] $ _rmPolys rm)
|
{ _grViewpoints = _rmViewpoints rm ++ (map fst . foldl' (flip cutWalls) [] $ _rmPolys rm)
|
||||||
, _grViewpointsEx = map fst (_rmLinks rm)
|
++ map fst (_rmLinks rm)
|
||||||
|
, _grViewpointsEx = map fst (_rmUsedLinks rm)
|
||||||
, _grBound = expandPolyByFixed 100 . convexHullSafe . nubBy closePoints
|
, _grBound = expandPolyByFixed 100 . convexHullSafe . nubBy closePoints
|
||||||
. concat $ _rmBound rm ++ _rmPolys rm
|
. concat $ _rmBound rm ++ _rmPolys rm
|
||||||
, _grDir = snd . last $ _rmLinks rm
|
, _grDir = snd . head $ _rmUsedLinks rm
|
||||||
, _grName = _rmName rm
|
, _grName = _rmName rm
|
||||||
}
|
}
|
||||||
closePoints x y = roundPoint2 x == roundPoint2 y
|
closePoints x y = roundPoint2 x == roundPoint2 y
|
||||||
|
|||||||
@@ -27,16 +27,23 @@ shiftRoomTreeSearchAll bs (Node r ts :<| ts')
|
|||||||
| roomIsClipping = [] -- this is called too often, but whatever
|
| roomIsClipping = [] -- this is called too often, but whatever
|
||||||
| otherwise = case ts of
|
| otherwise = case ts of
|
||||||
[] -> (r :) <$> shiftRoomTreeSearchAll newBounds ts'
|
[] -> (r :) <$> shiftRoomTreeSearchAll newBounds ts'
|
||||||
(s:ss) -> concatMap (\l -> shiftRoomTreeSearchAll bs (Node (rm l) ss <| (ts' |> f l s))) ls
|
(s:ss) -> concatMap (\l -> shiftRoomTreeSearchAll bs (Node (useLink l) ss <| (ts' |> f l s))) ls
|
||||||
where
|
where
|
||||||
convexBounds = map pointsToPoly $ _rmBound r
|
convexBounds = map pointsToPoly $ _rmBound r
|
||||||
ls = init $ _rmLinks r
|
ls = init $ _rmLinks r
|
||||||
newBounds = convexBounds ++ bs
|
newBounds = convexBounds ++ bs
|
||||||
roomIsClipping = or (convexPolysOverlap <$> convexBounds <*> bs)
|
roomIsClipping = or (convexPolysOverlap <$> convexBounds <*> bs)
|
||||||
rm l = r & rmLinks %~ delete l
|
useLink l = r & rmLinks %~ delete l
|
||||||
|
& rmUsedLinks %~ (l :)
|
||||||
f l = applyToRoot (shiftRoomToLink l)
|
f l = applyToRoot (shiftRoomToLink l)
|
||||||
{- |
|
{- |
|
||||||
Depth first search of trees of rooms, maybe produces a list rooms that are not clipping.
|
Depth first search of trees of rooms, maybe produces a list rooms that are not clipping.
|
||||||
-}
|
-}
|
||||||
shiftExpandTree :: Tree Room -> Maybe [Room]
|
shiftExpandTree :: Tree Room -> Maybe [Room]
|
||||||
shiftExpandTree = listToMaybe . shiftRoomTreeSearchAll [] . singleton
|
shiftExpandTree = fmap (map setLastLinkToUsed) . listToMaybe . shiftRoomTreeSearchAll [] . singleton
|
||||||
|
where
|
||||||
|
setLastLinkToUsed rm = case _rmLinks rm of
|
||||||
|
(_:_) -> rm
|
||||||
|
& rmLinks %~ init
|
||||||
|
& rmUsedLinks %~ (last (_rmLinks rm) :)
|
||||||
|
_ -> rm
|
||||||
|
|||||||
@@ -23,10 +23,7 @@ damageSensor damF p r = Placement (PS p r) ( PutLS theLS)
|
|||||||
, _mcLSs = [lsid]
|
, _mcLSs = [lsid]
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
theLS = defaultLS
|
theLS = defaultLS { _lsPos = V3 0 0 30 , _lsIntensity = 0.1 }
|
||||||
{ _lsPos = V3 0 0 30
|
|
||||||
, _lsIntensity = 0.1
|
|
||||||
}
|
|
||||||
|
|
||||||
lightSensor :: Point2 -> Float -> Placement
|
lightSensor :: Point2 -> Float -> Placement
|
||||||
lightSensor = damageSensor senseLasering
|
lightSensor = damageSensor senseLasering
|
||||||
|
|||||||
@@ -19,6 +19,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)]
|
||||||
|
, _rmUsedLinks :: [(Point2,Float)]
|
||||||
, _rmPath :: [(Point2, Point2)]
|
, _rmPath :: [(Point2, Point2)]
|
||||||
, _rmPS :: [Placement]
|
, _rmPS :: [Placement]
|
||||||
, _rmBound :: [ [Point2] ]
|
, _rmBound :: [ [Point2] ]
|
||||||
|
|||||||
@@ -106,8 +106,12 @@ addButtonSlowDoor x h rm = do
|
|||||||
,( V2 (x/2+50) 5,0)
|
,( V2 (x/2+50) 5,0)
|
||||||
]
|
]
|
||||||
thePlacement <- takeOne [butDoor butPos butRot ]
|
thePlacement <- takeOne [butDoor butPos butRot ]
|
||||||
filterLinks aboveH =<< changeLinkTo belowH (rm & rmPS %~ (thePlacement :))
|
filterLinks aboveH =<< changeLinkTo belowH (rm
|
||||||
|
& rmPS %~ (thePlacement :)
|
||||||
|
& rmBound %~ (openDoorBound :)
|
||||||
|
)
|
||||||
where
|
where
|
||||||
|
openDoorBound = rectNSEW (h + 5) (h - 5) (-x/2) (3*x/2)
|
||||||
belowH y = (sndV2 . fst) y < h - 40
|
belowH y = (sndV2 . fst) y < h - 40
|
||||||
aboveH y = (sndV2 . fst) y > h + 40
|
aboveH y = (sndV2 . fst) y > h + 40
|
||||||
butDoor bpos brot = putLitButtonID col bpos brot
|
butDoor bpos brot = putLitButtonID col bpos brot
|
||||||
|
|||||||
Reference in New Issue
Block a user