Randomise enemies and floor items

This commit is contained in:
2021-04-24 18:25:09 +02:00
parent a409ddc8a7
commit 9af7dbda56
+24 -3
View File
@@ -6,13 +6,17 @@ module Dodge.Room.Procedural
, roomRectAutoLinks , roomRectAutoLinks
, testRoom , testRoom
) where ) where
import Dodge.Data
import Dodge.Room.Data import Dodge.Room.Data
import Dodge.Room.Placement import Dodge.Room.Placement
import Dodge.Room.Link import Dodge.Room.Link
import Dodge.Item.Consumable
import Dodge.Item.Weapon
import Dodge.RandomHelp import Dodge.RandomHelp
import Dodge.LevelGen import Dodge.LevelGen
import Dodge.LevelGen.Data import Dodge.LevelGen.Data
import Dodge.Creature import Dodge.Creature
import Dodge.Default
import Geometry import Geometry
import Data.List (nub,nubBy,sortBy) import Data.List (nub,nubBy,sortBy)
@@ -199,12 +203,29 @@ fillNothingPlacement pst r =
replaceNothingWith x (ps:pss) = ps : replaceNothingWith x pss replaceNothingWith x (ps:pss) = ps : replaceNothingWith x pss
replaceNothingWith _ [] = [] replaceNothingWith _ [] = []
fillNothingPlacements :: [PSType] -> Room -> Room
fillNothingPlacements pst r = foldr fillNothingPlacement r pst
shufflePlacements :: RandomGen g => Room -> State g Room
shufflePlacements r = do
newPSs <- shuffle $ _rmPS r
return $ r & rmPS .~ newPSs
putDefaultFlIt :: Item -> PSType
putDefaultFlIt itm = PutFlIt $ defaultFlIt { _flItRot = 0, _flIt = itm }
testRoom :: RandomGen g => State g Room testRoom :: RandomGen g => State g Room
testRoom = do testRoom = do
corners <- replicateM 4 . join $ takeOne [fourthWall 100, fourthCornerWall 100] corners <- replicateM 4 . join $ takeOne [fourthWall 100, fourthCornerWall 100]
-- corners <- replicateM 4 (fourthCornerWall 100) nItms <- state $ randomR (1,2)
randomiseAllLinks itms <- takeN nItms $ fmap putDefaultFlIt $ [autoRadar,autoSonar,remoteLauncher,jetPack,blinkGun] ++ replicate 5 (medkit 500)
. fillNothingPlacement (PutCrit chaseCrit) nCrits <- state $ randomR (1,3)
crits <- takeN nCrits $ fmap PutCrit $ [spreadGunCrit,pistolCrit,autoCrit,armourChaseCrit]
++ replicate 20 chaseCrit
randomiseAllLinks =<<
( fmap (fillNothingPlacements $ crits ++ itms)
. shufflePlacements
. foldr1 combineRooms . foldr1 combineRooms
$ zipWith (\r a -> shiftRoomBy ((0,0),a) r) corners [0,pi/2,pi,3*pi/2] $ zipWith (\r a -> shiftRoomBy ((0,0),a) r) corners [0,pi/2,pi,3*pi/2]
)