{- |
Rooms that contain valuable items, typically protected in some manner.
Typically dead ends.
-}
module Dodge.Room.Treasure
    where
import Dodge.Data
import Dodge.Room.Data
import Dodge.Room.Placement
import Dodge.Default.Room
import Dodge.LevelGen.Data
import Geometry

--import Data.List
import Control.Monad.State
--import Control.Lens
--import System.Random 
{- | A triangular room with loot at the top (with 'PutID' 2), 
creatures in the bottom two corners (with 'PutID' 0), 
and (single) entrance bottom middle.  -}
triLootRoom
    :: Float    -- Width
    -> Float    -- Height
    -> State g Room
triLootRoom w h = pure $ defaultRoom
    { _rmPolys  = [ tri
                  , base
                  ]
    , _rmLinks  = [(V2 0 (-80) , pi)]
    , _rmPath   = doublePair (V2 0 (-80) , V2 0 (h/2))
    , _rmPS     =
        [sPS (V2 (15-w)    15 )  0 $ PutID 0
        ,sPS (V2 (w-15)    15 ) pi $ PutID 0
        ,sPS (V2     0  (h-35))  0 $ PutID 2
        ,sPS (V2 (  -5) (h-10))  0 putLamp
        ,sPS (V2     5  (h-10))  0 putLamp
        ,sPS (V2     0  (h-15))  0 putLamp
        ,sPS (V2     0  ( -60))  0 putLamp
        ]
    , _rmBound  = [tri , base]
    }
  where
    tri = map toV2
        [ ( -w,30)
        , ( -w, 0)
        , (  w, 0)
        , (  w,30)
        , ( 20, h)
        , (-20, h)
        ]
    base = rectNSWE 20 (-80) (-20) 20 
{- | Create a random room with one entrance containing given creatures and items.  -}
lootRoom :: [Creature] -> [Item] -> State g Room
lootRoom crs itms = do
    let w = 300
        h = 700
    replacePutID 0 (map PutCrit crs) . replacePutID 2 (map PutFlIt itms) <$> triLootRoom w h
