From 4ad02f29b2ab2fe273dcaef44923b1ba36bc5d22 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 24 Nov 2021 22:13:42 +0000 Subject: [PATCH] Improve starting weapon rooms --- src/Dodge/LevelGen/Data.hs | 1 + src/Dodge/Room/Link.hs | 4 ++++ src/Dodge/Room/Procedural.hs | 2 +- src/Dodge/Room/Room.hs | 30 ++++++++++-------------------- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/Dodge/LevelGen/Data.hs b/src/Dodge/LevelGen/Data.hs index 20eb23da5..c37ee5793 100644 --- a/src/Dodge/LevelGen/Data.hs +++ b/src/Dodge/LevelGen/Data.hs @@ -35,6 +35,7 @@ data PSType = PutCrit {_unPutCrit :: Creature} | PutNothing | PutID { _putID :: Int} -- maybe there is a monadic implementation of this? +-- add room effect for any placement spot? data PlacementSpot = PS { _psPos :: Point2 , _psRot :: Float } | PSPos diff --git a/src/Dodge/Room/Link.hs b/src/Dodge/Room/Link.hs index 84312224f..6b456ea8e 100644 --- a/src/Dodge/Room/Link.hs +++ b/src/Dodge/Room/Link.hs @@ -17,6 +17,7 @@ module Dodge.Room.Link , changeLinkFrom , randomiseOutLinks , chooseOneInLink + , restrictRMInLinksPD ) where import Dodge.Placement.PlaceSpot import Dodge.LevelGen.Data @@ -35,6 +36,9 @@ import qualified Data.Set as S chooseOneInLink :: RandomGen g => Room -> State g Room chooseOneInLink r = restrictToFstInLink <$> shuffleLinks r +restrictRMInLinksPD :: ((Point2,Float) -> Bool) -> Room -> Room +restrictRMInLinksPD f = rmLinks %~ restrictLinkType InLink f + restrictToFstInLink :: Room -> Room restrictToFstInLink = rmLinks %~ f where diff --git a/src/Dodge/Room/Procedural.hs b/src/Dodge/Room/Procedural.hs index ceea6bb6f..a47de60dc 100644 --- a/src/Dodge/Room/Procedural.hs +++ b/src/Dodge/Room/Procedural.hs @@ -70,7 +70,7 @@ roomRect x y xn yn = defaultRoom lnks = m North nlnks ++ m East elnks ++ m West wlnks ++ m South slnks m edge = map (lnkBothAnd (OnEdge edge)) pth = linksAndPath' lnks $ map (bimap (+.+ V2 20 20) (+.+ V2 20 20)) (makeGrid xd xn yd yn) - posps = map (+.+ V2 20 20) $ gridPoints xd xn yd yn + posps = map (+.+ V2 20 20) $ gridPoints xd (xn+1) yd (yn+1) {- Creates a rectangular room, automatically creates links and pathfinding graph at a sensible size. -} -- it is not clear to me that this works for very small rooms (but it does seem -- to do so) diff --git a/src/Dodge/Room/Room.hs b/src/Dodge/Room/Room.hs index b68ebb1d6..859e23189 100644 --- a/src/Dodge/Room/Room.hs +++ b/src/Dodge/Room/Room.hs @@ -255,7 +255,6 @@ randFirstWeapon = do ++ replicate 2 autoGun ++ [launcher] - weaponEmptyRoom :: RandomGen g => State g (SubCompTree Room) weaponEmptyRoom = do w <- state $ randomR (220,300) @@ -267,10 +266,9 @@ weaponEmptyRoom = do --,sPS (V2 (w/2) (h/2)) 0 putLamp ,mntLightLnkCond unusedLnkToPS ] - treeFromTrunk [PassDown corridor] - <$> ((fmap singleUseAll . randomiseOutLinks) =<< - changeLinkTo ((\p -> dist p (V2 (w/2) 0) < 10) . fst) (set rmPmnts plmnts $ roomRect w h 2 2) - ) + f (V2 x y,a) = (a == pi && x > 25 && x < w - 25) || (a /= 0 && y > w - 30) + rm <- shuffleLinks $ restrictRMInLinksPD f (roomRect w h 2 2 & rmPmnts .~ plmnts) + return $ treeFromTrunk [PassDown corridor] (singleUseAll rm ) weaponUnderCrits :: RandomGen g => State g (SubCompTree Room) weaponUnderCrits = do @@ -312,18 +310,10 @@ weaponBehindPillar = do weaponBetweenPillars :: RandomGen g => State g (SubCompTree Room) weaponBetweenPillars = do wpPos <- takeOne [V2 x y | x <- [20,120,220], y <- [20,120,220]] - (ps,_) <- takeNMore 2 ([], [V2 x y | x <- [20,220], y <- [20,120,220]]) - let crPos1:crPos2:_ = ps - d p = argV $ V2 120 120 -.- p - plmnts = - [sPS wpPos 0 $ RandPS randFirstWeapon - , sps (unusedSpotAwayFromInLink 150) randC1 - , sps (unusedSpotAwayFromInLink 150) randC1 - , sps (unusedSpotAwayFromInLink 150) randC1 - , sps (unusedSpotAwayFromInLink 150) randC1 - --,sPS crPos1 (d crPos1) randC1 - --,sPS crPos2 (d crPos2) randC1 - ] + critPlacementSpots <- replicateM 2 $ randDirPS $ unusedSpotAwayFromInLink 100 + let plmnts = + sPS wpPos 0 (RandPS randFirstWeapon) : + map (\ps -> sps ps randC1) critPlacementSpots theRoom = roomPillars & rmPmnts %~ (++ plmnts) (fmap singleUseAll . randomiseOutLinks) =<< filterLinks f theRoom where @@ -362,9 +352,9 @@ deadEndRoom = defaultRoom weaponRoom :: RandomGen g => State g (SubCompTree Room) weaponRoom = join $ takeOne [-- weaponEmptyRoom - --, weaponUnderCrits - --, weaponBehindPillar - weaponBetweenPillars + weaponUnderCrits + -- weaponBehindPillar + -- weaponBetweenPillars --, weaponLongCorridor ]