Add fallback placement for falled link based placement spots

This commit is contained in:
2021-11-08 11:16:08 +00:00
parent 2d98c74ab3
commit 28f8ac1fbd
7 changed files with 52 additions and 88 deletions
+11 -5
View File
@@ -26,6 +26,8 @@ import Control.Monad.State
import Control.Lens
import qualified Data.IntSet as IS
-- potential failure cases: randomising using an already set link position
-- others?
placeSpot :: World -> (Room , Placement) -> World
placeSpot w (rm, plmnt@Placement{_placementSpot=PSRoomRand i}) =
let (ps,g) = runState (_rmRandPSs rm !! i) $_randGen w
@@ -40,20 +42,24 @@ placeSpot w (rm, plmnt@Placement{}) =
placeSpot w (rm, PlacementUsingPos p subpl) = placeSpot w (rm, subpl (shiftPoint3By shift p))
where
shift = _rmShift rm
-- random placements SHOULD be dealt with already (see assignPlacementSpots)
placeSpot w (rm, RandomPlacement rplmnt) = placeSpot (w & randGen .~ g) (rm, plmnt)
where
(plmnt, g) = runState rplmnt (_randGen w)
-- ok, this is unsafe, but whatever
-- this should be woven into placeSpot
assignPSToLnk :: Room -> Placement -> World -> World
assignPSToLnk rm plmnt w = placeSpot (w & randGen .~ g) (rm, updatePS (f lnk) plmnt)
assignPSToLnk rm plmnt w = case lnks of
(lnk:_) -> placeSpot (w & randGen .~ g) (rm, updatePS (f lnk) plmnt)
[] -> case fallback of
Nothing -> w
Just plmnt' -> placeSpot w (rm,plmnt')
where
rps = _placementSpot plmnt
fallback = _psFallback rps
test = _psLinkTest rps
(lnk:_,g) = runState (shuffle $ filter test $ map (invShiftLinkBy $ _rmShift rm) $ _rmLinks rm)
(lnks,g) = runState (shuffle $ filter test $ map (invShiftLinkBy $ _rmShift rm) $ _rmLinks rm)
$ _randGen w
f x (PSLnk t s)
f x (PSLnk t s _)
| t x = uncurry PS $ s x
f _ ps = ps
invShiftLinkBy :: (Point2,Float) -> (Point2,Float) -> (Point2,Float)