Improve placementspots

This commit is contained in:
2022-03-12 10:35:14 +00:00
parent 33718ea94b
commit d340fd73c3
4 changed files with 29 additions and 11 deletions
+2 -1
View File
@@ -128,7 +128,8 @@ doAfterPlacement pmntis gw = gRandify gw $ do
return $ newgw & gRooms . ix i .~ rm return $ newgw & gRooms . ix i .~ rm
doInPlacements :: ( IM.IntMap [Placement],GenWorld) -> GenWorld doInPlacements :: ( IM.IntMap [Placement],GenWorld) -> GenWorld
doInPlacements (im,w) = let (gw,rms) = mapAccumR (doRoomInPlacements im) w (_gRooms w) doInPlacements (im,w) =
let (gw,rms) = mapAccumR (doRoomInPlacements im) w (_gRooms w)
in gw {_gRooms = rms} in gw {_gRooms = rms}
doRoomInPlacements :: IM.IntMap [Placement] -> GenWorld -> Room -> (GenWorld, Room) doRoomInPlacements :: IM.IntMap [Placement] -> GenWorld -> Room -> (GenWorld, Room)
@@ -49,7 +49,6 @@ moveLSThen posf off sh = propLSThen propupdate lsupdate thels theprop
, _prToggle = True , _prToggle = True
} }
-- | mount a light source on a shape -- | mount a light source on a shape
mntLSOn mntLSOn
:: (Point2 -> Point3 -> Shape) -- ^ function describing the mount shape :: (Point2 -> Point3 -> Shape) -- ^ function describing the mount shape
+24 -8
View File
@@ -8,6 +8,7 @@ module Dodge.PlacementSpot
, anyUnusedSpot , anyUnusedSpot
, unusedSpotAwayFromLink , unusedSpotAwayFromLink
, isUnusedLnk , isUnusedLnk
, isInLnk
, unusedLnkToPS , unusedLnkToPS
, unusedSpotNearInLink , unusedSpotNearInLink
, randDirPS , randDirPS
@@ -20,6 +21,8 @@ module Dodge.PlacementSpot
, setFallback , setFallback
, twoRoomPoss , twoRoomPoss
, isUnusedLinkType , isUnusedLinkType
, roomPosRoomBoolShift
, shiftInBy
) where ) where
import Dodge.LevelGen.Data import Dodge.LevelGen.Data
import Geometry import Geometry
@@ -52,6 +55,17 @@ anyUnusedSpot = roomPosBool $ \rp -> _rpLinkStatus rp == NotLink && _rpPlacement
roomPosRoomBool :: (RoomPos -> Room -> Bool) -> PlacementSpot roomPosRoomBool :: (RoomPos -> Room -> Bool) -> PlacementSpot
roomPosRoomBool t = PSPos (useRoomPosRoomCond t) (const id) Nothing roomPosRoomBool t = PSPos (useRoomPosRoomCond t) (const id) Nothing
roomPosRoomBoolShift :: (RoomPos -> Room -> Bool)
-> ((Point2,Float) -> (Point2,Float))
-> PlacementSpot
roomPosRoomBoolShift t shift = PSPos f (const id) Nothing
where
f rp r
| t rp r = Just (PS p a, rp & rpPlacementUse +~ 1)
| otherwise = Nothing
where
(p,a) = shift (_rpPos rp, _rpDir rp)
unusedSpotAwayFromLink :: Float -> PlacementSpot unusedSpotAwayFromLink :: Float -> PlacementSpot
unusedSpotAwayFromLink x = roomPosRoomBool $ \rp r -> _rpLinkStatus rp == NotLink unusedSpotAwayFromLink x = roomPosRoomBool $ \rp r -> _rpLinkStatus rp == NotLink
&& _rpPlacementUse rp == 0 && _rpPlacementUse rp == 0
@@ -88,6 +102,11 @@ isUnusedLnk rp = case _rpLinkStatus rp of
UnusedLink {} -> _rpPlacementUse rp == 0 UnusedLink {} -> _rpPlacementUse rp == 0
_ -> False _ -> False
isInLnk :: RoomPos -> Bool
isInLnk rp = case _rpLinkStatus rp of
UsedInLink {} -> _rpPlacementUse rp == 0
_ -> False
useUnusedLnk :: PlacementSpot useUnusedLnk :: PlacementSpot
useUnusedLnk = roomPosBool isUnusedLnk useUnusedLnk = roomPosBool isUnusedLnk
@@ -99,19 +118,13 @@ isUsedLnkUnplaced rp = case _rpLinkStatus rp of
useRoomPosCond :: (RoomPos -> Bool) -> RoomPos -> Room -> Maybe (PlacementSpot,RoomPos) useRoomPosCond :: (RoomPos -> Bool) -> RoomPos -> Room -> Maybe (PlacementSpot,RoomPos)
useRoomPosCond t rp _ useRoomPosCond t rp _
| t rp = Just (PS p a, rp & rpPlacementUse +~ 1) | t rp = Just (PS (_rpPos rp) (_rpDir rp), rp & rpPlacementUse +~ 1)
| otherwise = Nothing | otherwise = Nothing
where
p = _rpPos rp
a = _rpDir rp
useRoomPosRoomCond :: (RoomPos -> Room -> Bool) -> RoomPos -> Room -> Maybe (PlacementSpot,RoomPos) useRoomPosRoomCond :: (RoomPos -> Room -> Bool) -> RoomPos -> Room -> Maybe (PlacementSpot,RoomPos)
useRoomPosRoomCond t rp r useRoomPosRoomCond t rp r
| t rp r = Just (PS p a, rp & rpPlacementUse +~ 1) | t rp r = Just (PS (_rpPos rp) (_rpDir rp), rp & rpPlacementUse +~ 1)
| otherwise = Nothing | otherwise = Nothing
where
p = _rpPos rp
a = _rpDir rp
unusedLnkToPS :: RoomPos -> Room -> Maybe (PlacementSpot,RoomPos) unusedLnkToPS :: RoomPos -> Room -> Maybe (PlacementSpot,RoomPos)
unusedLnkToPS = useRoomPosCond $ \rp -> case _rpLinkStatus rp of unusedLnkToPS = useRoomPosCond $ \rp -> case _rpLinkStatus rp of
@@ -172,6 +185,9 @@ atNthLnkOutShiftInward n x = atNthLnkOutShiftBy n f
where where
f (p,a) = (p +.+ rotateV a (V2 0 (negate x)),a) f (p,a) = (p +.+ rotateV a (V2 0 (negate x)),a)
shiftInBy :: Float -> (Point2,Float) -> (Point2,Float)
shiftInBy x (p,a) = (p +.+ rotateV a (V2 0 (negate x)),a)
--anyLnkInPS :: Float -- ^ amount to shift inward --anyLnkInPS :: Float -- ^ amount to shift inward
-- -> PlacementSpot -- -> PlacementSpot
--anyLnkInPS x = PSPos f (const id) Nothing --anyLnkInPS x = PSPos f (const id) Nothing
+3 -1
View File
@@ -33,9 +33,11 @@ import System.Random
cenLasTur :: Room cenLasTur :: Room
cenLasTur = roomNgon 8 200 & rmPmnts .~ cenLasTur = roomNgon 8 200 & rmPmnts .~
[ putLasTurret 0.02 [ putLasTurret 0.02
, heightWall 30 (rectNSEW (-90) (-110) 20 (-20)) , heightWallPS (roomPosRoomBoolShift (\rp _ -> isInLnk rp) (shiftInBy 100)) 30 covershape
, mntLightLnkCond unusedLnkToPS , mntLightLnkCond unusedLnkToPS
] ]
where
covershape = rectNSEW 10 (-10) 20 (-20)
lightSensInsideDoor :: Int -> Room -> Room lightSensInsideDoor :: Int -> Room -> Room
lightSensInsideDoor outplid rm = rm lightSensInsideDoor outplid rm = rm