{-# OPTIONS_GHC -Wno-unused-imports #-}
{- |
The tree of rooms that make up a level. -}
module Dodge.Floor
    ( levx
    ) where
import Geometry.Data
--import Picture
import Dodge.Data
--import Dodge.Room
import Dodge.Creature.State.Data
--import Dodge.Creature.SwarmCrit
import Dodge.Room.Procedural
import Dodge.Room.RoadBlock
import Dodge.Room.Data
import Dodge.Room
--import Dodge.Room.Link
--import Dodge.Room.Door
import Dodge.Room.Branch
import Dodge.Room.Boss
--import Dodge.Room.Airlock
import Dodge.Room.LongDoor
import Dodge.Room.NoNeedWeapon
--import Dodge.Base
--import Dodge.Layout
import Dodge.Layout.Tree.Polymorphic
import Dodge.Layout.Tree.Either
--import Dodge.Layout.Tree.GenerateStructure
import Dodge.Layout.Tree.Annotate
import Dodge.Layout.Tree.Shift
import Dodge.Creature
--import Dodge.SoundLogic
--import Dodge.RandomHelp
--import Dodge.LightSources
import Dodge.LevelGen.Data
--import Dodge.LevelGen.SwarmPlacement
--import Dodge.Item.Weapon
import Dodge.Item.Weapon.Launcher

--import Data.Tree
--import Data.Maybe (fromJust,isNothing)
import Control.Lens
import Control.Monad.State
import Control.Monad.Loops
import System.Random
{- | A test level tree. -}
initialRoomTree :: RandomGen g => State g (Maybe [Room])
initialRoomTree = do
    let struct = treeFromPost [[Corridor,SpecificRoom $ fmap (pure . Right) randomFourCornerRoom]] [EndRoom]
    let t' = padCorridors struct
        t = treeFromTrunk 
            [[StartRoom]
            ,[Corridor]
            ,[Corridor]
            ,[SpecificRoom roomCCrits]
            ,[Corridor]
            ,[Corridor]
            ,[SpecificRoom . pure . pure . Right $ roomGlassOctogon 400 
                & rmPS %~ ([sPS (V2 0 50) 0 $ PutCrit armourChaseCrit 
                            ,sPS (V2 50 25) 0 $ PutCrit armourChaseCrit 
                            ,sPS (V2 50 0) 0 $ PutCrit armourChaseCrit 
                            ]++)
             ]
            --,[Corridor]
            --,[SpecificRoom . pure . pure . Right $ roomGlassOctogon 400 
            --    & rmPS %~ ([swarmPS 0 (x,y) 0 swarmCrit | x <- [-20,-19.5.. 20] , y <- [200,202] ]++)
            -- ]
            ,[SpecificRoom . pure . pure . Right $ roomGlassOctogon 400 
                & rmPS %~ ([sPS (V2 0 50) 0 $ PutCrit pistolCrit ]++)
             ]
            ,[Corridor]
            ,[Corridor]
--            --,[SpecificRoom $ pure . Right <$> twinSlowDoorChasers 30]
            ,[SpecificRoom $ pure $ (pure . Right) (twinSlowDoorRoom 30 80 200 40)]
            ,[Corridor]
            ,[DoorAno]
            ,[SpecificRoom $ pure . Right <$> centerVaultExplosiveExit 50]
            ,[SpecificRoom blockedCorridor]
            ,[OrAno [[DoorAno]
                    ,[Corridor]
                    ,[DoorNumAno 0,AirlockAno]] 
                    ]
            ,[FirstWeapon]
            ,[CorridorDebug]
            ,[SpecificRoom $ fmap (pure . Right) randomFourCornerRoom]
            ,[Corridor]
            ,[OrAno 
                [[SpecificRoom $ branchRectWith $ fmap (fmap Left) armouredChasers]
                ,[BossAno $ addArmour launcherCrit & crHP +~ 800
                    & crState . crDropsOnDeath .~ DropSpecific [0] ]
                ]
             ]
            ,[Corridor]
            ,[SpecificRoom $ fmap (pure . Right) armouredCorridor]
            ,[Corridor]
            ,[TreasureAno [addArmour autoCrit,addArmour autoCrit] [launcher]]
            ] 
            t'
    shiftExpandTree . expandTreeBy id <$> mapM annoToRoomTree t

levx :: RandomGen g => State g [Room]
levx = untilJust initialRoomTree
