Make chasms remove RoomPos within their boundaries
This commit is contained in:
+24
-24
@@ -1,9 +1,9 @@
|
||||
--{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
module Dodge.PlacementSpot (
|
||||
atFstLnkOut,
|
||||
atNthLnkOutShiftBy,
|
||||
rpIsOnGrid,
|
||||
rpIsOffPath,
|
||||
rpIsOffGrid,
|
||||
rpOffPathFromEdge,
|
||||
useUnusedLnk,
|
||||
psRandRanges,
|
||||
@@ -59,35 +59,35 @@ randDirPS ps = do
|
||||
return $ setDirPS a ps
|
||||
|
||||
isUnusedLnk :: RoomPos -> Room -> Bool
|
||||
isUnusedLnk rp _ = case _rpLinkStatus rp of
|
||||
isUnusedLnk rp _ = case _rpType rp of
|
||||
UnusedLink{} -> null $ _rpPlacementUse rp
|
||||
_ -> False
|
||||
|
||||
anyUnusedSpot :: PlacementSpot
|
||||
anyUnusedSpot = rprBool $ \rp _ -> _rpLinkStatus rp == NotLink && null (_rpPlacementUse rp)
|
||||
anyUnusedSpot = rprBool $ \rp _ -> notLink (_rpType rp) && null (_rpPlacementUse rp)
|
||||
|
||||
psposAddLabel :: RoomPosType -> PlacementSpot -> PlacementSpot
|
||||
psposAddLabel lab = psSelect %~ (\f rp r -> f rp r & _Just . _2 . rpType %~ S.insert lab)
|
||||
psposAddLabel :: RoomPosFlag -> PlacementSpot -> PlacementSpot
|
||||
psposAddLabel lab = psSelect %~ (\f rp r -> f rp r & _Just . _2 . rpFlags %~ S.insert lab)
|
||||
|
||||
rprBool :: (RoomPos -> Room -> Bool) -> PlacementSpot
|
||||
rprBool t = PSPos (useRoomPosRoomCond (S.singleton UsedPosLow) t) (const id) Nothing
|
||||
|
||||
rpIsOnGrid :: RoomPos -> Bool
|
||||
rpIsOnGrid = any f . _rpType
|
||||
rpIsOnGrid = any f . _rpFlags
|
||||
where
|
||||
f RoomPosOnGrid{} = True
|
||||
f _ = False
|
||||
|
||||
rpIsOffPath :: RoomPos -> Bool
|
||||
rpIsOffPath = any f . _rpType
|
||||
rpIsOffGrid :: RoomPos -> Bool
|
||||
rpIsOffGrid = any f . _rpFlags
|
||||
where
|
||||
f RoomPosOffGrid{} = True
|
||||
f _ = False
|
||||
|
||||
rpOffPathFromEdge :: PathFromEdge -> RoomPos -> Bool
|
||||
rpOffPathFromEdge pe = any f . _rpType
|
||||
rpOffPathFromEdge pe = any f . _rpFlags
|
||||
where
|
||||
f rt = maybe False (pe `elem`) (rt ^? offPathFromEdges)
|
||||
f rt = maybe False (pe `elem`) (rt ^? offGridFromEdges)
|
||||
|
||||
resetPLUse :: PlacementSpot -> PlacementSpot
|
||||
resetPLUse (PSPos f g fallback) = PSPos f' g fallback
|
||||
@@ -118,7 +118,7 @@ rprBoolShift t shift = PSPos f (const id) Nothing
|
||||
|
||||
unusedSpotAwayFromLink :: Float -> PlacementSpot
|
||||
unusedSpotAwayFromLink x = rprBool $ \rp r ->
|
||||
_rpLinkStatus rp == NotLink
|
||||
notLink (_rpType rp)
|
||||
&& null (_rpPlacementUse rp)
|
||||
&& all ((> x) . dist (_rpPos rp)) (usedRoomLinkPoss r)
|
||||
|
||||
@@ -132,11 +132,11 @@ unusedOffPathAwayFromLink :: Float -> PlacementSpot
|
||||
unusedOffPathAwayFromLink x = rprBool $ \rp r ->
|
||||
null (_rpPlacementUse rp)
|
||||
&& all ((> x) . dist (_rpPos rp)) (usedRoomLinkPoss r)
|
||||
&& rpIsOffPath rp
|
||||
&& rpIsOffGrid rp
|
||||
|
||||
unusedSpotAwayFromInLink :: Float -> PlacementSpot
|
||||
unusedSpotAwayFromInLink x = rprBool $ \rp r ->
|
||||
_rpLinkStatus rp == NotLink
|
||||
notLink (_rpType rp)
|
||||
&& null (_rpPlacementUse rp)
|
||||
&& all ((> x) . dist (_rpPos rp)) (usedRoomInLinkPoss r)
|
||||
|
||||
@@ -159,12 +159,12 @@ twoRoomPoss cond1 cond2 f = Placement (rprBool cond1) PutNothing Nothing Nothing
|
||||
-- _ -> False
|
||||
|
||||
isInLnk :: RoomPos -> Bool
|
||||
isInLnk rp = case _rpLinkStatus rp of
|
||||
isInLnk rp = case _rpType rp of
|
||||
UsedInLink{} -> null $ _rpPlacementUse rp
|
||||
_ -> False
|
||||
|
||||
isOutLnk :: RoomPos -> Bool
|
||||
isOutLnk rp = case _rpLinkStatus rp of
|
||||
isOutLnk rp = case _rpType rp of
|
||||
UsedOutLink{} -> null $ _rpPlacementUse rp
|
||||
_ -> False
|
||||
|
||||
@@ -172,7 +172,7 @@ useUnusedLnk :: PlacementSpot
|
||||
useUnusedLnk = rprBool isUnusedLnk
|
||||
|
||||
isUsedLnkUnplaced :: RoomPos -> Bool
|
||||
isUsedLnkUnplaced rp = case _rpLinkStatus rp of
|
||||
isUsedLnkUnplaced rp = case _rpType rp of
|
||||
UsedOutLink{} -> null (_rpPlacementUse rp)
|
||||
UsedInLink{} -> null (_rpPlacementUse rp)
|
||||
_ -> False
|
||||
@@ -188,28 +188,28 @@ useRoomPosRoomCond xs t rp r
|
||||
| otherwise = Nothing
|
||||
|
||||
isUnusedLnkType :: RoomLinkType -> RoomPos -> Room -> Bool
|
||||
isUnusedLnkType rlt rp _ = case _rpLinkStatus rp of
|
||||
isUnusedLnkType rlt rp _ = case _rpType rp of
|
||||
UnusedLink{_rplsType = rlts} -> rlt `S.member` rlts
|
||||
&& null (_rpPlacementUse rp)
|
||||
_ -> False
|
||||
|
||||
unusedSpotNearInLink :: Float -> PlacementSpot
|
||||
unusedSpotNearInLink x = rprBool $ \rp r ->
|
||||
_rpLinkStatus rp == NotLink
|
||||
notLink (_rpType rp)
|
||||
&& null (_rpPlacementUse rp)
|
||||
&& any ((< x) . dist (_rpPos rp)) (usedRoomInLinkPoss r)
|
||||
|
||||
usedRoomInLinkPoss :: Room -> [Point2]
|
||||
usedRoomInLinkPoss r = mapMaybe f $ _rmPos r
|
||||
where
|
||||
f rp = case _rpLinkStatus rp of
|
||||
f rp = case _rpType rp of
|
||||
UsedInLink{} -> Just $ _rpPos rp
|
||||
_ -> Nothing
|
||||
|
||||
usedRoomLinkPoss :: Room -> [Point2]
|
||||
usedRoomLinkPoss r = mapMaybe f $ _rmPos r
|
||||
where
|
||||
f rp = case _rpLinkStatus rp of
|
||||
f rp = case _rpType rp of
|
||||
UsedInLink{} -> Just $ _rpPos rp
|
||||
UsedOutLink{} -> Just $ _rpPos rp
|
||||
_ -> Nothing
|
||||
@@ -218,12 +218,12 @@ atFstLnkOut :: PlacementSpot
|
||||
atFstLnkOut = atNthLinkOut 0
|
||||
|
||||
atNthLinkOut :: Int -> PlacementSpot
|
||||
atNthLinkOut n = rprBool $ \rp _ -> rp ^? rpLinkStatus . rplsChildNum == Just n
|
||||
atNthLinkOut n = rprBool $ \rp _ -> rp ^? rpType . rplsChildNum == Just n
|
||||
|
||||
atNthLnkOutShiftBy :: Int -> ((Point2, Float) -> ((Point2, Float),S.Set UsedPos))
|
||||
-> PlacementSpot
|
||||
atNthLnkOutShiftBy n = rprBoolShift $
|
||||
\rp _ -> rp ^? rpLinkStatus . rplsChildNum == Just n
|
||||
\rp _ -> rp ^? rpType . rplsChildNum == Just n
|
||||
|
||||
--atNthLnkOutShiftBy n theshift = PSPos f (const id) Nothing
|
||||
-- where
|
||||
@@ -253,7 +253,7 @@ shiftByV2 x (p, a) = (p +.+ rotateV a x, a)
|
||||
-- this should probably check the placement use, but so should others: should
|
||||
-- unify these
|
||||
useLnkRoomPos :: S.Set UsedPos -> RoomPos -> Room -> Maybe (PlacementSpot, RoomPos)
|
||||
useLnkRoomPos xs rp _ = case _rpLinkStatus rp of
|
||||
useLnkRoomPos xs rp _ = case _rpType rp of
|
||||
UnusedLink{} -> Just (PS (_rpPos rp) (_rpDir rp), rp & rpPlacementUse <>~ xs)
|
||||
_ -> Nothing
|
||||
|
||||
|
||||
Reference in New Issue
Block a user