Add fallback placement for falled link based placement spots
This commit is contained in:
+3
-37
@@ -7,8 +7,6 @@ import Dodge.LevelGen.Data
|
||||
import Dodge.LevelGen.StaticWalls
|
||||
import Dodge.LevelGen.Pathing
|
||||
import Dodge.Wall.Zone
|
||||
import Dodge.Placements.Spot
|
||||
import Dodge.RandomHelp
|
||||
import Dodge.Zone
|
||||
import Dodge.GameRoom
|
||||
import Dodge.Bounds
|
||||
@@ -28,7 +26,7 @@ import Tile
|
||||
import Polyhedra
|
||||
import Polyhedra.Data
|
||||
|
||||
import Data.List (nubBy, partition,mapAccumR)
|
||||
import Data.List (nubBy)
|
||||
import Control.Monad.State
|
||||
import Control.Lens
|
||||
import System.Random
|
||||
@@ -43,7 +41,8 @@ generateLevelFromRoomList :: State StdGen [Room] -> World -> World
|
||||
generateLevelFromRoomList gr w
|
||||
= initWallZoning
|
||||
. setupWorldBounds
|
||||
. flip (foldr $ flip placeSpot) plmnts
|
||||
-- . flip (foldr $ flip placeSpot) plmnts
|
||||
. flip (foldl' placeSpot) plmnts
|
||||
$ w { _walls = wallsFromRooms rs
|
||||
, _floorTiles = floorsFromRooms rs
|
||||
, _gameRooms = gameRoomsFromRooms rs
|
||||
@@ -54,42 +53,9 @@ generateLevelFromRoomList gr w
|
||||
path = pairsToGraph dist pairPath
|
||||
pairPath = concatMap _rmPath rs
|
||||
plmnts = concatMap (\rm -> map (rm,) (_rmPS rm)) rs
|
||||
--plmnts = concat . snd $ mapAccumR assignPlacementSpots (_randGen w) rs
|
||||
rs = zipWith addTile zs . evalState gr $ _randGen w
|
||||
zs = map fromIntegral $ randomRs (0,63::Int) $ _randGen w
|
||||
|
||||
-- the idea is to allow use of link coordinates for placements
|
||||
-- though the implementation is clunky
|
||||
-- this should PutNothing if there are no links available
|
||||
-- first it takes the random placements and derandomises them
|
||||
-- then it deals with link placement spots
|
||||
-- TODO use state monad here
|
||||
assignPlacementSpots :: StdGen -> Room -> (StdGen, [(Room,Placement)])
|
||||
assignPlacementSpots g rm = (g'
|
||||
, map (rm,)
|
||||
$ plmnts ++ updatedLnkPlmnts
|
||||
)
|
||||
where
|
||||
(unrandPlmnts, g'') = runState (mapM (derandPlacement rm) (_rmPS rm)) g
|
||||
(lnkplmnts, plmnts) = partition islnk unrandPlmnts
|
||||
islnk Placement{_placementSpot=PSLnk{}} = True
|
||||
islnk _ = False
|
||||
(shuffledLnks,g') = runState (shuffle $ _rmLinks rm) g''
|
||||
(_,updatedLnkPlmnts) = mapAccumR f (map (invShiftLinkBy $ _rmShift rm) shuffledLnks) lnkplmnts
|
||||
f lnks plmnt =
|
||||
let (x:xs,ys) = partition (_psLinkTest $ _placementSpot plmnt) lnks
|
||||
thepair = _psLinkShift (_placementSpot plmnt) x
|
||||
in (xs++ys, updatePS (updatePSLnkUsing thepair) plmnt)
|
||||
|
||||
-- I do not see an obvious way to push randomn placement spots down into recursive placements
|
||||
-- So these currently only work for the "top" level
|
||||
derandPlacement :: Room -> Placement -> State StdGen Placement
|
||||
derandPlacement rm (RandomPlacement x) = derandPlacement rm =<< x
|
||||
derandPlacement rm (Placement (PSRoomRand i) pstype cont) = do
|
||||
ps <- _rmRandPSs rm !! i
|
||||
return (Placement (uncurry PS ps) pstype cont)
|
||||
derandPlacement _ x = return x
|
||||
|
||||
updatePSLnkUsing :: (Point2,Float) -> PlacementSpot -> PlacementSpot
|
||||
updatePSLnkUsing pf PSLnk{_psLinkShift=f} = uncurry PS $ f pf
|
||||
updatePSLnkUsing _ ps = ps
|
||||
|
||||
Reference in New Issue
Block a user