Stun turret turn with electrical damage

This commit is contained in:
2021-11-05 01:41:57 +00:00
parent 92026bf06a
commit 5cbfa6f1ff
24 changed files with 58 additions and 99 deletions
+11 -14
View File
@@ -1,10 +1,7 @@
{-
Helpers for random generation.
-}
{- Helpers for random generation. -}
module Dodge.RandomHelp where
import Geometry
import Geometry.Vector3D
--import Geometry.Data
import System.Random
import Control.Monad.State
@@ -20,8 +17,7 @@ takeOne :: RandomGen g => [a] -> State g a
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))
takeOneWeighted ws xs = state (randomR (0, sum ws)) >>= (\w -> return (xs !! i w ws))
where
i y (z:zs)
| y <= z = 0
@@ -45,8 +41,7 @@ takeN i xs = fst <$> takeNMore i ([],xs)
-- | Randomly shuffle a list.
shuffle :: RandomGen g => [a] -> State g [a]
shuffle xs = do
let l = length xs
rands <- forM [0..l-1] $ \i -> state $ randomR (0,i)
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
@@ -65,9 +60,10 @@ randProb p = do p1 <- state $ randomR (0,1)
return (p1 < p)
randInCirc :: RandomGen g => Float -> State g Point2
randInCirc maxRad = do rad <- state $ randomR (0,maxRad)
ang <- state $ randomR (0,2*pi)
return $ rad *.* unitVectorAtAngle ang
randInCirc maxRad = do
rad <- state $ randomR (0,maxRad)
ang <- state $ randomR (0,2*pi)
return $ rad *.* unitVectorAtAngle ang
randOnUnitSphere :: RandomGen g => State g Point3
randOnUnitSphere = do
@@ -90,9 +86,10 @@ randInHemisphere = do
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)
return (V2 x y)
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