about summary refs log tree commit diff
path: root/users/glittershark/xanthous/src/Xanthous/Generators.hs
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-06-28T23·33-0400
committerglittershark <grfn@gws.fyi>2020-06-28T23·38+0000
commitbf9b09bd8c63261758140d51f24617c6f05af392 (patch)
tree4cf43fa084a73cc2e6b51e3f7c67ac1e6a80459b /users/glittershark/xanthous/src/Xanthous/Generators.hs
parent6c7e14d2dcd3a3b124dc035e8feb8e79534cd66a (diff)
feat(xan): Generate random villages r/1111
This algorithm is a little rough around the edges right now, but
generally the idea is we find a relatively closed-off region of the map,
and place rooms randomly on it, expanding them until they run into each
other, then we put doors in the walls of the rooms and a single door
opening into the region. Later on, we'll generate friendly (or
unfriendly!) NPCs to put in those rooms.

Change-Id: Ic989b9905f55ad92a01fdf6db11aa57afb4ce383
Reviewed-on: https://cl.tvl.fyi/c/depot/+/726
Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'users/glittershark/xanthous/src/Xanthous/Generators.hs')
-rw-r--r--users/glittershark/xanthous/src/Xanthous/Generators.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/users/glittershark/xanthous/src/Xanthous/Generators.hs b/users/glittershark/xanthous/src/Xanthous/Generators.hs
index 9b2b90e300..5bc8bcf035 100644
--- a/users/glittershark/xanthous/src/Xanthous/Generators.hs
+++ b/users/glittershark/xanthous/src/Xanthous/Generators.hs
@@ -6,7 +6,7 @@ module Xanthous.Generators
   ( generate
   , Generator(..)
   , SGenerator(..)
-  , GeneratorInput
+  , GeneratorInput(..)
   , generateFromInput
   , parseGeneratorInput
   , showCells
@@ -17,6 +17,7 @@ module Xanthous.Generators
   , levelDoors
   , levelCharacterPosition
   , levelTutorialMessage
+  , levelExtra
   , generateLevel
   , levelToEntityMap
   ) where
@@ -31,6 +32,7 @@ import qualified Xanthous.Generators.CaveAutomata as CaveAutomata
 import qualified Xanthous.Generators.Dungeon as Dungeon
 import           Xanthous.Generators.Util
 import           Xanthous.Generators.LevelContents
+import           Xanthous.Generators.Village as Village
 import           Xanthous.Data (Dimensions, Position'(Position), Position)
 import           Xanthous.Data.EntityMap (EntityMap, _EntityMap)
 import qualified Xanthous.Data.EntityMap as EntityMap
@@ -118,6 +120,7 @@ data Level = Level
   , _levelCreatures         :: !(EntityMap Creature)
   , _levelTutorialMessage   :: !(EntityMap GroundMessage)
   , _levelStaircases        :: !(EntityMap Staircase)
+  , _levelExtra             :: !(EntityMap SomeEntity) -- ^ TODO this is a bit of a hack...
   , _levelCharacterPosition :: !Position
   }
   deriving stock (Generic)
@@ -134,6 +137,8 @@ generateLevel gen ps dims = do
   rand <- mkStdGen <$> getRandom
   let cells = generate gen ps dims rand
       _levelWalls = cellsToWalls cells
+  village <- generateVillage cells gen
+  let _levelExtra = village
   _levelItems <- randomItems cells
   _levelCreatures <- randomCreatures cells
   _levelDoors <- randomDoors cells
@@ -152,3 +157,12 @@ levelToEntityMap level
   <> (SomeEntity <$> level ^. levelCreatures)
   <> (SomeEntity <$> level ^. levelTutorialMessage)
   <> (SomeEntity <$> level ^. levelStaircases)
+  <> (level ^. levelExtra)
+
+generateVillage
+  :: MonadRandom m
+  => Cells -- ^ Wall positions
+  -> SGenerator gen
+  -> m (EntityMap SomeEntity)
+generateVillage wallPositions SCaveAutomata = Village.fromCave wallPositions
+generateVillage _ _ = pure mempty