From 2c759cb40ed3043d586a615c961d7d8409f6f625 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 24 Nov 2021 21:31:19 +0000 Subject: [PATCH] Allow for yet more complex placement positioning --- src/Dodge/PlacementSpot.hs | 31 ++++++++++++++++++++----------- src/Dodge/Room/Room.hs | 9 +++++++-- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/Dodge/PlacementSpot.hs b/src/Dodge/PlacementSpot.hs index 51679a71c..54d7c55e1 100644 --- a/src/Dodge/PlacementSpot.hs +++ b/src/Dodge/PlacementSpot.hs @@ -2,6 +2,7 @@ module Dodge.PlacementSpot where import Dodge.LevelGen.Data import Geometry +import Data.Maybe import Data.Bifunctor import Control.Monad.State import System.Random @@ -9,21 +10,29 @@ import System.Random setDirPS :: Float -> PlacementSpot -> PlacementSpot setDirPS a ps = case ps of PS p _ -> PS p a - PSPos f re fb -> undefined - _ -> error "TODO write this in" + PSPos f re fb -> PSPos (\rp r -> fmap (first (setDirPS a)) (f rp r)) re fb + PSRoomRand i f -> PSRoomRand i (fmap (setDirPS a) f) randDirPS :: RandomGen g => PlacementSpot -> State g PlacementSpot -randDirPS (PSPos f ef fb) = do +randDirPS ps = do a <- state $ randomR (0,pi*2) - return $ PSPos (g a) ef fb - where - g a rp r = fmap (first (setDirPS a)) $ f rp r + return $ setDirPS a ps ---unusedSpotAwayFromInLinkRD :: RandomGen g => Float -> State g PlacementSpot ---unusedSpotAwayFromInLinkRD x = do --- a <- state $ randomR (0.2*pi) --- return PSPos (f a) (const id) Nothing --- where +unusedSpotAwayFromInLink :: Float -> PlacementSpot +unusedSpotAwayFromInLink x = PSPos f (const id) Nothing + where + f rp r = case rp of + UnusedSpot p a | all ( (>x) . dist p ) inlinkposs -> Just (PS p a,UsedSpot p a) + _ -> Nothing + where + inlinkposs = usedRoomInLinkPoss r + +usedRoomInLinkPoss :: Room -> [Point2] +usedRoomInLinkPoss r = mapMaybe f $ _rmPos r + where + f rp = case rp of + UsedInLink {} -> Just $ _rpPos rp + _ -> Nothing -- TODO rename to any unused link facing out anyLnkOutPS :: PlacementSpot diff --git a/src/Dodge/Room/Room.hs b/src/Dodge/Room/Room.hs index 4f15b60fa..b68ebb1d6 100644 --- a/src/Dodge/Room/Room.hs +++ b/src/Dodge/Room/Room.hs @@ -1,5 +1,6 @@ module Dodge.Room.Room where import Dodge.Data +import Dodge.PlacementSpot import Dodge.RoomLink import Dodge.Default.Room import Dodge.Item.Weapon.BulletGuns @@ -316,8 +317,12 @@ weaponBetweenPillars = do d p = argV $ V2 120 120 -.- p plmnts = [sPS wpPos 0 $ RandPS randFirstWeapon - ,sPS crPos1 (d crPos1) randC1 - ,sPS crPos2 (d crPos2) randC1 + , 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 ] theRoom = roomPillars & rmPmnts %~ (++ plmnts) (fmap singleUseAll . randomiseOutLinks) =<< filterLinks f theRoom