Allow for yet more complex placement positioning

This commit is contained in:
2021-11-24 21:31:19 +00:00
parent 1c80f1a681
commit 2c759cb40e
2 changed files with 27 additions and 13 deletions
+20 -11
View File
@@ -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
+7 -2
View File
@@ -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