Update stack lts

This commit is contained in:
2024-10-22 10:07:13 +01:00
parent f6e32ff6ef
commit e2330618f2
24 changed files with 222 additions and 71 deletions
+1
View File
@@ -1,5 +1,6 @@
module Dodge.Block where
import Control.Monad
import Data.Set (Set)
import Dodge.Data.MountedObject
import Control.Lens
+1 -1
View File
@@ -19,7 +19,7 @@ import qualified IntMapHelp as IM
import Data.List (sortOn)
import Control.Applicative
import LensHelp
--import Control.Monad
import Control.Monad
import Data.Bifunctor
import Data.Maybe
import Dodge.Base
+1
View File
@@ -3,6 +3,7 @@ module Dodge.Creature.State (
doDamage,
) where
import Control.Monad
import Dodge.Targeting.Draw
import Dodge.Data.DoubleTree
import qualified Data.Map.Strict as M
+1
View File
@@ -5,6 +5,7 @@ module Dodge.HeldUse (
mcUseHeld,
) where
import Control.Monad
import Color
import Data.Maybe
import Dodge.Base.Collide
+1
View File
@@ -7,6 +7,7 @@ import Dodge.Item
import Dodge.Room
import Dodge.Tree
import RandomHelp
import Control.Monad
bossKeyItems :: RandomGen g => [(State g (Tree Room), State g ItemType)]
bossKeyItems = [(return . cleatOnward <$> bossRoom autoCrit, takeOne [HELD PISTOL])]
+1 -1
View File
@@ -84,7 +84,7 @@ placeSpotRoomRand ::
GenWorld ->
((GenWorld, Room), [Placement])
placeSpotRoomRand rm i f plmnt w =
let (ps, g) = runState (_rmRandPSs rm !! i) $_randGen (_gwWorld w)
let (ps, g) = runState (_rmRandPSs rm !! i) $ w ^. gwWorld . randGen
in placeSpot (w & gwWorld . randGen .~ g, rm) (plmnt & plSpot .~ f ps)
placeSpotID :: PlacementSpot -> PSType -> GenWorld -> (Int, GenWorld)
+1
View File
@@ -3,6 +3,7 @@ module Dodge.Projectile.Update
( updateProjectile
) where
import Control.Monad
import Dodge.Movement.Turn
import NewInt
import Dodge.Payload
+1
View File
@@ -1,5 +1,6 @@
module Dodge.Prop.Gib where
import Control.Monad
import Color
import Data.Foldable
import Data.List (zip4)
+1
View File
@@ -16,6 +16,7 @@ import Dodge.Tree
import Geometry
import LensHelp
import RandomHelp
import Control.Monad
roomGlassOctogon ::
-- | Size
+1
View File
@@ -15,6 +15,7 @@ import Dodge.Tree
import Geometry
import LensHelp
import RandomHelp
import Control.Monad
roomsContaining :: RandomGen g => [Creature] -> [Item] -> State g (MetaTree Room String)
roomsContaining crs its = tToBTree str <$> roomsContaining' crs its
+1
View File
@@ -18,6 +18,7 @@ import Dodge.Tree
import Geometry
import LensHelp
import RandomHelp
import Control.Monad
glassLesson :: RandomGen g => State g (Tree Room)
glassLesson = do
+1
View File
@@ -1,6 +1,7 @@
-- | Rooms containing long doors, probably with a big reveal behind them.
module Dodge.Room.LongDoor where
import Control.Monad
import Dodge.LevelGen.Switch
import Data.Maybe
import qualified Data.Set as S
+1
View File
@@ -1,5 +1,6 @@
module Dodge.Room.LongRoom where
import Control.Monad
import qualified Data.Set as S
import Data.Tile
import Dodge.Cleat
+1
View File
@@ -10,6 +10,7 @@ module Dodge.Room.Procedural (
makeGrid,
) where
import Control.Monad
import Tile
import qualified Data.Set as S
import Data.Tile
+1
View File
@@ -18,6 +18,7 @@ import Geometry
import LensHelp
import Padding
import RandomHelp
import Control.Monad
rezBox :: LightSource -> Room
rezBox ls =
+1
View File
@@ -19,6 +19,7 @@ import Dodge.Room.Room
import Dodge.Room.RunPast
import Dodge.Tree
import RandomHelp
import Control.Monad
powerFakeout' :: RandomGen g => State g (MetaTree Room String)
powerFakeout' = tToBTree "powerFakeout'" <$> powerFakeout
+1 -4
View File
@@ -14,10 +14,7 @@ import Geometry
import LensHelp
import RandomHelp
import Shape
--import Data.Maybe
--import Data.Tree
--import qualified Data.Set as S
import Control.Monad
randomTank :: RandomGen g => State g Placement
randomTank =
+1
View File
@@ -6,6 +6,7 @@ A /trunk/ refers to the successive first nodes in lists of children.
module Dodge.Tree.GenerateStructure
where
import RandomHelp
import Control.Monad
import Data.Tree
{- Single branched tree (a trunk). -}
+1
View File
@@ -12,6 +12,7 @@ module Dodge.WorldEvent.Explosion (
--import Geometry.Vector3D
import Control.Monad
import Data.List
import Dodge.Base.Collide
import Dodge.Data.World
+58 -55
View File
@@ -1,59 +1,61 @@
{- Helpers for random generation. -}
module RandomHelp
( module System.Random
, module Control.Monad.State
, module RandomHelp
) where
import Geometry
import StrictHelp
module RandomHelp (
module System.Random,
module Control.Monad.State,
module RandomHelp,
) where
import System.Random
import Control.Monad
import Control.Monad.State
import Data.List
import Geometry
import StrictHelp
import System.Random
randomRanges :: (Random a,RandomGen g) => [a] -> State g a
randomRanges :: (Random a, RandomGen g) => [a] -> State g a
randomRanges = join . takeOne . f
where
f (x:y:ys) = state (randomR (x,y)) : f ys
f _ = []
where
f (x : y : ys) = state (randomR (x, y)) : f ys
f _ = []
takeOne :: RandomGen g => [a] -> State g a
takeOne xs = state (randomR (0,length xs - 1)) >>= (\i -> return (xs !! i))
takeOne xs = state (randomR (0, length xs - 1)) >>= (\i -> return (xs !! i))
takeOneWeighted :: (RandomGen g, Random b, Ord b, Num b) => [b] -> [a] -> State g a
takeOneWeighted ws xs = state (randomR (0, sum ws)) >>= (\w -> return (xs !! i w ws))
where
i y (z:zs)
where
i y (z : zs)
| y <= z = 0
| otherwise = 1 + i (y-z) zs
| otherwise = 1 + i (y - z) zs
i _ _ = 0
takeOneMore :: RandomGen g => ([a],[a]) -> State g ([a],[a])
takeOneMore ( _,[]) = error "trying to takeOneMore from empty list"
takeOneMore (xs,ys) = do
i <- state $ randomR (0,length ys - 1)
let (zs, w:ws) = splitAt i ys
return (w:xs, zs ++ ws)
takeOneMore :: RandomGen g => ([a], [a]) -> State g ([a], [a])
takeOneMore (_, []) = error "trying to takeOneMore from empty list"
takeOneMore (xs, ys) = do
i <- state $ randomR (0, length ys - 1)
let (zs, w : ws) = splitAt i ys
return (w : xs, zs ++ ws)
takeNMore :: RandomGen g => Int -> ([a],[a]) -> State g ([a],[a])
takeNMore n p = foldl' (flip $ const (>>= takeOneMore)) (return p) [1..n]
takeNMore :: RandomGen g => Int -> ([a], [a]) -> State g ([a], [a])
takeNMore n p = foldl' (flip $ const (>>= takeOneMore)) (return p) [1 .. n]
takeN :: RandomGen g => Int -> [a] -> State g [a]
takeN 0 _ = return []
takeN i xs = fst <$> takeNMore i ([],xs)
takeN 0 _ = return []
takeN i xs = fst <$> takeNMore i ([], xs)
-- | Randomly shuffle a list.
shuffle :: RandomGen g => [a] -> State g [a]
shuffle xs = do
rands <- forM [0..length xs-1] $ \i -> state $ randomR (0,i)
let f ys rand = let (as,b:bs) = splitAt rand ys
in (as ++ bs, b)
let (_,zs) = mapAccumR f xs rands
shuffle xs = do
rands <- forM [0 .. length xs -1] $ \i -> state $ randomR (0, i)
let f ys rand =
let (as, b : bs) = splitAt rand ys
in (as ++ bs, b)
let (_, zs) = mapAccumR f xs rands
return $ forceElements zs `seq` zs
-- | Randomly shuffle the tail of a list, not safe.
shuffleTail :: RandomGen g => [a] -> State g [a]
shuffleTail (x:xs) = (x :) <$> shuffle xs
shuffleTail (x : xs) = (x :) <$> shuffle xs
shuffleTail _ = undefined
-- select elements from a list randomly
@@ -62,61 +64,62 @@ randomSelectionFromList :: RandomGen g => Float -> [a] -> State g [a]
randomSelectionFromList = filterM . const . randProb
randProb :: RandomGen g => Float -> State g Bool
randProb p = do
p1 <- state $ randomR (0,1)
randProb p = do
p1 <- state $ randomR (0, 1)
return (p1 < p)
randInCirc :: RandomGen g => Float -> State g Point2
randInCirc = flip randInArc (2*pi)
randInCirc = flip randInArc (2 * pi)
randInArc :: RandomGen g => Float -> Float -> State g Point2
randInArc = randInArcStrip 0
randInArcStrip :: RandomGen g => Float -> Float -> Float -> State g Point2
randInArcStrip minrad maxRad maxangle = do
rad <- state $ randomR (minrad,maxRad)
ang <- state $ randomR (0,maxangle)
randInArcStrip minrad maxRad maxangle = do
rad <- state $ randomR (minrad, maxRad)
ang <- state $ randomR (0, maxangle)
return $ rad *.* unitVectorAtAngle ang
randOnUnitSphere :: RandomGen g => State g Point3
randOnUnitSphere = do
z <- state $ randomR (negate 1,1)
longitude <- state $ randomR (0, 2*pi)
let (V2 x y) = sqrt (1 - z^(2::Int)) *.* unitVectorAtAngle longitude
z <- state $ randomR (negate 1, 1)
longitude <- state $ randomR (0, 2 * pi)
let (V2 x y) = sqrt (1 - z ^ (2 :: Int)) *.* unitVectorAtAngle longitude
return (V3 x y z)
randOnHemisphere :: RandomGen g => State g Point3
randOnHemisphere = do
z <- state $ randomR (0,1)
longitude <- state $ randomR (0, 2*pi)
let (V2 x y) = sqrt (1 - z^(2::Int)) *.* unitVectorAtAngle longitude
z <- state $ randomR (0, 1)
longitude <- state $ randomR (0, 2 * pi)
let (V2 x y) = sqrt (1 - z ^ (2 :: Int)) *.* unitVectorAtAngle longitude
return (V3 x y z)
randInHemisphere :: RandomGen g => State g Point3
randInHemisphere = do
p <- randOnHemisphere
r <- state $ randomR (0,1)
r <- state $ randomR (0, 1)
return $ r *.*.* p
randInRect :: RandomGen g => Float -> Float -> State g Point2
randInRect w h = do
x <- state $ randomR (0,w)
y <- state $ randomR (0,h)
randInRect w h = do
x <- state $ randomR (0, w)
y <- state $ randomR (0, h)
return (V2 x y)
maybeTakeOne :: RandomGen g => [a] -> State g (Maybe a)
maybeTakeOne [] = return Nothing
maybeTakeOne xs = state (randomR (0,length xs - 1)) >>= (\i -> return (Just (xs !! i)))
maybeTakeOne xs = state (randomR (0, length xs - 1)) >>= (\i -> return (Just (xs !! i)))
randsSpread :: RandomGen g => (Float,Float) -> Int -> State g [Float]
randsSpread (a,b) i
| i <= 0 = error "tried to take <= 0 randsSpread"
| otherwise = zipWith (+) [a+x,a+2*x..] <$> replicateM i (state $ randomR (0,x))
randsSpread :: RandomGen g => (Float, Float) -> Int -> State g [Float]
randsSpread (a, b) i
| i <= 0 = error "tried to take <= 0 randsSpread"
| otherwise = zipWith (+) [a + x, a + 2 * x ..] <$> replicateM i (state $ randomR (0, x))
where
x = (b-a)/fromIntegral i
x = (b - a) / fromIntegral i
randsOnCirc :: RandomGen g => Int -> State g [Float]
randsOnCirc = randsSpread (0,2*pi)
randsOnCirc = randsSpread (0, 2 * pi)
--randsOnCirc i
-- | i <= 0 = error "tried to take <= 0 randsOnCirc"
-- | otherwise = zipWith (+) [x,2*x..] <$> replicateM i (state $ randomR (0,x))