tracer/src/Types/Interior.hs
2019-01-18 19:02:45 +01:00

281 lines
8.3 KiB
Haskell

{-# LANGUAGE FlexibleInstances #-}
module Types.Interior where
import qualified Affection as A
import Data.Matrix as M
import Linear.V2
import System.Random (StdGen, randomR)
-- internal imports
import Types.Map
import Types.ReachPoint
import Types.ImgId
import Types.Direction
data Cluster
= ClusterBox1
| ClusterTableSW
| ClusterTableNW
| ClusterTableNE
| ClusterTableSE
| ClusterCornerTable
| ClusterTableGroup
| ClusterCopier
| ClusterFlipchart
| ClusterConferenceTable
| ClusterPlant1
| ClusterPlant2
| ClusterToilet
| ClusterWatercooler
| ClusterVending
| ClusterCabinets
deriving (Enum, Bounded, Show)
-- row -> NS; col -> WE
clusterMatWithRPs :: Cluster -> (Int, Int) -> StdGen -> (Matrix (Maybe ImgId), [ReachPoint])
clusterMatWithRPs ClusterBox1 dim _ =
( M.fromLists
[ [Just ImgMiscBox1]
]
, clusterPoints ClusterBox1 dim
)
clusterMatWithRPs ClusterTableSW dim@(h, _) _ =
( M.fromLists $ replicate h
[Just ImgEmpty, Just ImgTableSW]
, clusterPoints ClusterTableSW dim
)
clusterMatWithRPs ClusterTableSE dim@(_, w) _ =
( M.fromLists $
[ replicate w (Just ImgTableSE)
, replicate w (Just ImgEmpty)
]
, clusterPoints ClusterTableSE dim
)
clusterMatWithRPs ClusterTableNE dim@(h, _) _ =
( M.fromLists $ replicate h
[Just ImgTableNE, Just ImgEmpty]
, clusterPoints ClusterTableNE dim
)
clusterMatWithRPs ClusterTableNW dim@(_, w) _ =
( M.fromLists $
[ replicate w (Just ImgEmpty)
, replicate w (Just ImgTableNW)
]
, clusterPoints ClusterTableNW dim
)
clusterMatWithRPs ClusterCornerTable dim _ =
( M.fromLists
[ [Just ImgTableSE, Just ImgTableCorner]
, [Just ImgEmpty, Just ImgTableSW]
]
, clusterPoints ClusterCornerTable dim
)
clusterMatWithRPs ClusterTableGroup dim _ =
( M.fromLists
[ [ Just ImgEmpty, Just ImgTableSE, Just ImgTableCorner
, Just ImgEmpty, Just ImgTableSE, Just ImgTableCorner
]
, [ Just ImgEmpty, Just ImgEmpty, Just ImgTableSW
, Just ImgEmpty, Just ImgEmpty, Just ImgTableSW
]
, [ Just ImgEmpty, Just ImgEmpty, Just ImgEmpty
, Just ImgEmpty, Just ImgEmpty, Just ImgEmpty
]
, [ Nothing, Nothing, Nothing
, Just ImgEmpty, Just ImgTableSE, Just ImgTableCorner
]
, [ Nothing, Nothing, Nothing
, Just ImgEmpty, Just ImgEmpty, Just ImgTableSW
]
]
, clusterPoints ClusterTableGroup dim
)
clusterMatWithRPs ClusterCopier dim _ =
( M.fromLists
[ [ Just ImgEmptyNoWalk]
, [ Just ImgEmpty]
]
, clusterPoints ClusterCopier dim
)
clusterMatWithRPs ClusterFlipchart dim _ =
( M.fromLists
[ [ Just ImgMiscFlipchart]
, [ Just ImgEmpty]
]
, clusterPoints ClusterFlipchart dim
)
clusterMatWithRPs ClusterConferenceTable dim@(h, w) _ =
let mw = max 4 w
mh = max 4 h
in
( M.fromLists $
[ replicate mw (Just ImgEmpty)
, [ Just ImgEmpty, Just ImgTableC4] ++ replicate (mw-4) (Just ImgTableNW) ++
[ Just ImgTableC3, Just ImgEmpty ]
] ++
replicate (mh-4) ([ Just ImgEmpty, Just ImgTableSW] ++ replicate (mw-4) (Just ImgEmpty) ++
[ Just ImgTableNE, Just ImgEmpty ]) ++
[ [ Just ImgEmpty, Just ImgTableC1] ++ replicate (mw-4) (Just ImgTableSE) ++
[ Just ImgTableC2, Just ImgEmpty ]
, replicate mw (Just ImgEmpty)
]
, clusterPoints ClusterConferenceTable dim
)
clusterMatWithRPs ClusterPlant1 dim _ =
( M.fromLists
[ [ Just ImgMiscPlant1 ] ]
, clusterPoints ClusterPlant1 dim
)
clusterMatWithRPs ClusterPlant2 dim _ =
( M.fromLists
[ [ Just ImgMiscPlant2 ] ]
, clusterPoints ClusterPlant2 dim
)
clusterMatWithRPs ClusterToilet dim _ =
( M.fromLists
[ [ Just ImgEmpty, Just ImgEmptyNoWalk] ]
, clusterPoints ClusterToilet dim
)
clusterMatWithRPs ClusterWatercooler dim _ =
( M.fromLists
[ [ Just ImgMiscWatercooler ]
, [ Just ImgEmpty ]
]
, clusterPoints ClusterWatercooler dim
)
clusterMatWithRPs ClusterVending dim _ =
( M.fromLists
[ [ Just ImgMiscVending ]
, [ Just ImgEmpty ]
]
, clusterPoints ClusterVending dim
)
clusterMatWithRPs ClusterCabinets dim@(h, w) g =
let iw = max 2 w
ih = max 2 h
rw = min 5 iw
rh = min 5 ih
selses =
[ ImgCabinetCoffeeSE
, ImgCabinetSinkSE
, ImgCabinetStoveSE
]
selsws =
[ ImgCabinetCoffeeSW
, ImgCabinetSinkSW
, ImgCabinetStoveSW
]
(g1, ses, seps) = foldl
(\(gen, lsi, lsr) a ->
let (switch, gf1) = randomR (1, 3) gen :: (Int, StdGen)
in if switch == 1
then
let (typ, gf2) = randomR (0, length selses - 1) gf1
img = selses !! typ
rp i
| i == ImgCabinetCoffeeSE = ReachPoint Drink (V2 2 a) NW
| i == ImgCabinetSinkSE = ReachPoint Drink (V2 2 a) NW
| i == ImgCabinetStoveSE = ReachPoint Eat (V2 2 a) NW
in (gf2, Just img : lsi, rp img : lsr)
else
(gf1, Just ImgCabinetSE : lsi, lsr)
)
(g, [], [])
(reverse [1 .. rw - 1])
(g2, sws, swps) = foldl
(\(gen, lsi, lsr) a ->
let (switch, gf1) = randomR (1, 3) gen :: (Int, StdGen)
in if switch == 1
then
let (typ, gf2) = randomR (0, length selsws - 1) gf1
img = selsws !! typ
rp i
| i == ImgCabinetCoffeeSW = ReachPoint Drink (V2 a (rw - 1)) NE
| i == ImgCabinetSinkSW = ReachPoint Drink (V2 a (rw - 1)) NE
| i == ImgCabinetStoveSW = ReachPoint Eat (V2 a (rw - 1)) NE
in (gf2, Just img : lsi, rp img : lsr)
else
(gf1, Just ImgCabinetSW : lsi, lsr)
)
(g1, [], [])
(reverse [1 .. rh - 1])
outmat =
(M.fromLists [ses] M.<|> M.fromLists [[ Just ImgCabinetCorner ]])
M.<->
(M.fromList (rh - 1) (rw - 1) (repeat $ Just ImgEmpty)
M.<|>
M.fromLists (map (\a -> [a]) sws)
)
in (outmat, (seps ++ swps))
clusterRoom :: Cluster -> [TileState]
clusterRoom ClusterBox1 = [Offi]
clusterRoom ClusterTableSW = [Offi]
clusterRoom ClusterTableNW = [Offi]
clusterRoom ClusterTableNE = [Offi]
clusterRoom ClusterTableSE = [Offi]
clusterRoom ClusterCornerTable = [Offi]
clusterRoom ClusterTableGroup = [Offi]
clusterRoom ClusterCopier = [Offi]
clusterRoom ClusterFlipchart = [Offi]
clusterRoom ClusterConferenceTable = [Offi]
clusterRoom ClusterPlant1 = [Offi]
clusterRoom ClusterPlant2 = [Offi]
clusterRoom ClusterToilet = [Toil]
clusterRoom ClusterWatercooler = [Kitc, Offi]
clusterRoom ClusterVending = [Kitc]
clusterRoom ClusterCabinets = [Kitc]
clusterPoints :: Cluster -> (Int, Int) -> [ReachPoint]
clusterPoints ClusterBox1 _ = []
clusterPoints ClusterTableNE (h, _) =
[ ReachPoint Table (V2 r 2) SW | r <- [1..h] ]
clusterPoints ClusterTableNW (_, w) =
[ ReachPoint Table (V2 1 c) SE | c <- [1..w] ]
clusterPoints ClusterTableSW (h, _) =
[ ReachPoint Table (V2 r 1) NE | r <- [1..h] ]
clusterPoints ClusterTableSE (_, w) =
[ ReachPoint Table (V2 2 c) NW | c <- [1..w] ]
clusterPoints ClusterCornerTable _ =
[ ReachPoint Computer (V2 2 1) N
]
clusterPoints ClusterTableGroup _ =
[ ReachPoint Computer (V2 2 2) N
, ReachPoint Computer (V2 2 5) N
, ReachPoint Computer (V2 5 5) N
]
clusterPoints ClusterCopier _ =
[ ReachPoint Copier (V2 2 1) NW
]
clusterPoints ClusterFlipchart _ =
[ ReachPoint Table (V2 2 1) NW
]
clusterPoints ClusterConferenceTable (h, w) =
let mw = max 4 w
mh = max 4 h
in
[ ReachPoint Table (V2 1 c) SE | c <- [2..mw-1] ] ++
[ ReachPoint Table (V2 r 1) NE | r <- [2..mh-1] ] ++
[ ReachPoint Table (V2 r mw) SW | r <- [2..mh-1] ] ++
[ ReachPoint Table (V2 mh c) NW | c <- [2..mw-1] ]
clusterPoints ClusterToilet _ =
[ ReachPoint Toilet (V2 1 1) NE
]
clusterPoints ClusterWatercooler _ =
[ ReachPoint Drink (V2 2 1) NW
]
clusterPoints ClusterVending _ =
[ ReachPoint Eat (V2 2 1) NW
]
clusterPoints _ _ = []
instance Size (Cluster, (Int, Int), StdGen) where
size (c, dim, gen) =
let mat = fst $ clusterMatWithRPs c dim gen
in fromIntegral ((nrows mat) * (ncols mat))