52 lines
1.6 KiB
Haskell
52 lines
1.6 KiB
Haskell
{-# LANGUAGE TupleSections #-}
|
|
module Dodge.Room.Ngon where
|
|
|
|
import Dodge.Room.Path
|
|
import Data.List
|
|
import qualified Data.Set as S
|
|
import Data.Tile
|
|
import Dodge.Data.GenWorld
|
|
import Dodge.Default.Room
|
|
import Dodge.Placement.Instance
|
|
import Dodge.PlacementSpot
|
|
import Geometry
|
|
import RandomHelp
|
|
import Tile
|
|
|
|
roomNgon :: RandomGen g => Int -> Float -> State g Room
|
|
roomNgon n x = do
|
|
thelight <- mntLightLnkCond $ resetPLUse $ rprBool $ const . isInLnk
|
|
return
|
|
defaultRoom
|
|
{ _rmPolys = [poly]
|
|
, _rmLinks = map f lnks
|
|
, _rmPath = linksDAGToPath (map f lnks) path3
|
|
, _rmPmnts = [thelight]
|
|
, _rmBound = [poly]
|
|
, _rmFloor = Tiled [makeTileFromPoly poly 2]
|
|
, _rmType = RoomNgon n x
|
|
--, _rmFloor = InheritFloor
|
|
, _rmName = show n ++ "gon"
|
|
, _rmPos = poss
|
|
}
|
|
where
|
|
rot = 2 * pi / fromIntegral n
|
|
rots = map ((rot *) . fromIntegral) [0 .. n -1]
|
|
poly = polyOrthDist n x
|
|
path1 = polyOrthDist n (x-10)
|
|
path2 = concat $ zipWith g path1 (tail path1 <> [head path1])
|
|
path3 = loopPairs path2 <> fmap (,V2 0 0) path2
|
|
poss = map (\p -> RoomPos p 0 mempty (NotLink True) mempty)
|
|
(V2 0 0 : path1)
|
|
g z y = [z, 0.5 * (z + y)]
|
|
lnks =
|
|
sortOn ((\(V2 a b) -> (negate b, a)) . fst . snd)
|
|
. zip [0 ..]
|
|
$ map (\r -> (rotateV r (V2 0 x), r)) rots
|
|
f (i, (p, a)) =
|
|
RoomLink
|
|
{ _rlType = S.fromList [OutLink, InLink, PolyEdge i]
|
|
, _rlPos = p
|
|
, _rlDir = a
|
|
}
|