Implement randomness at the placement datatype level

This commit is contained in:
2021-11-04 18:13:19 +00:00
parent f0c56cbcac
commit 92026bf06a
7 changed files with 39 additions and 6 deletions
+10 -3
View File
@@ -59,15 +59,22 @@ generateLevelFromRoomList gr 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
assignPlacementSpots :: StdGen -> Room -> (StdGen, [((Point2,Float),Placement)])
assignPlacementSpots g rm = (g', map (_rmShift rm,) $ plmnts ++ plmnts')
where
(lnkplmnts, plmnts) = partition islnk (_rmPS rm)
(randPlmnts, detPlmnts) = partition isRand (_rmPS rm)
isRand RandomPlacement{} = True
isRand _ = False
(unrandPlmnts, g'') = runState (mapM _unRandomPlacement randPlmnts) g
(lnkplmnts, plmnts) = partition islnk (unrandPlmnts ++ detPlmnts)
islnk Placement{_placementSpot=PSLnk{}} = True
islnk _ = False
(shuffledLnks,g') = runState (shuffle $ _rmLinks rm) g
(shuffledLnks,g') = runState (shuffle $ _rmLinks rm) g''
(_,plmnts') = mapAccumR f (map (invShiftLinkBy $ _rmShift rm) shuffledLnks) lnkplmnts
f lnks plmnt =
f lnks plmnt =
let (x:xs,ys) = partition (_psLinkTest $ _placementSpot plmnt) lnks
thepair = _psLinkShift (_placementSpot plmnt) x
in (xs++ys, updatePS (updatePSLnkUsing thepair) plmnt)