Class FlowingCaveGenerator

java.lang.Object
com.github.yellowstonegames.place.FlowingCaveGenerator
All Implemented Interfaces:
PlaceGenerator

public class FlowingCaveGenerator extends Object implements PlaceGenerator
An IDungeonGenerator that distorts and smooths an ordinary dungeon map to make it appear like a cave complex. This usually exhibits the complex connectivity that dungeons made with a TilesetType like TilesetType.DEFAULT_DUNGEON have, but shouldn't have noticeable room/corridor areas, and should appear as all one cave.
An example map this can produce:

  ┌─────┐ ┌───────┬─┐ ┌───┐                ┌────┐   ┌────┐   ┌────┐    ┌──┐                  ┌───┐   ┌─────┐
 ┌┘.....└─┘.......│.└─┘...└─┐    ┌─┐    ┌──┘....│   │....└──┬┘....└┬───┘..└──┐  ┌───┐       ┌┘...│  ┌┘.....└┐
 │..........................└┐ ┌─┘.└┐   │.......└┐  │.......│......│.........└─┬┘...│  ┌───┬┘....│  │.......│
 └┐.........┌┐...............└─┘....└┐ ┌┘........│ ┌┘....│.....................│...─┤┌─┘...│.....│  │.......│
  │........┌┘│.......................└─┘.........└┐│.....│.....┌┐...................││...........│  │.......│
  │........│┌┘...............................#....││.....│.....│└┐..................└┘...........│  │.......└┐
  │.......┌┼┘.....┌┐............┌─┐..............┌┘│.....├─┐...│ │...............................│  │........│
  │......┌┘│....┌─┘└┐.........┌─┘ └──────┐.......│ │....┌┘ │...└─┤......#.......│................│  └┐.......│
  │.....┌┘ └┐.┌─┘   └┐.......┌┘          │......┌┘ │...┌┘  └─┐...│....│........┌┤........│.......│  ┌┘......┌┘
  └┐...─┤   └─┘      │......─┤  ┌──┐     │......│  │...│    ┌┘.......─┘.......┌┘└─┐....─┬┤.......└┐ │.......│
  ┌┘....└┐  ┌─┐  ┌───┘.......└──┘..└┐    └┐.....│ ┌┘...└┐ ┌─┘.................│  ┌┘.....│└┐.......└─┘.......└┐
 ┌┘......└──┘.└┐┌┘......─┐..........└─┐  ┌┘.....└─┘.....│┌┘...................│ ┌┘......│ │..................│
┌┘.............└┘........│............└┬─┘..│...........└┘.....│.........───..└┬┘.......│ │....┌┐............│
│........................│......┌─┐....│....├┐...............──┘...............│........└─┘....│└┐...........│
│...┌─┐........................┌┘ └┐.......┌┘└┐................................................│ └┐..........│
│..┌┘ └┐.....................┌─┘  ┌┘.......│  │...............................................┌┘  │..........│
└──┘   └┐...................┌┘   ┌┘........│  └─┐...│...─┐...........│........................│   └┐.........│
        │..................┌┘    │.........│ ┌─┐└───┴┐...│...........├─┐........│.............└─┐  │.........│
    ┌─┐ └──┐.....┌──┐......│    ┌┘...┌───┐.└─┘.└┐    └┐..├┐..........│ └┐......┌┤...............│  └─┐.......│
    │.└─┐  └┐...┌┘  └┐.....└┐   │....│  ┌┘......└┐    │..│└───┐.....┌┘  └┐....┌┘├─.....┌──┐.....│    │......┌┘
    │...└┐  └┐..│   ┌┘......└─┬─┘...─┤  │........└┐ ┌─┘.─┤    │.....│    │....│ │......└┐ └┐....│    └┐....─┤
    └┐...│  ┌┘..│   │.........│......│ ┌┘.........└─┘....└─┐ ┌┘.....│   ┌┘....├─┘.......└┐ │....│     │.....│
     └┐..│ ┌┘...│   │................│┌┘...................│ │......└───┘.....│..........│ │....└─┐   │...┌─┘
      │..├─┘...─┤  ┌┘................├┘....................└─┘................│..........└┬┘......└─┐┌┘...│
      ├─.│......│ ┌┘..<........│...#.│...........................┌┬─......................│.........└┘...┌┘
      │..│......│┌┘............│................................─┴┘......................................│
     ┌┘......┌──┘│....................┌─┐.....................................┌┐.........................│
     │....┌──┘   └─┐..................│ └─┐.┌─┐....┌─┐....┌─┐.........┌─┐.....│└─┐......┌─┐....┌──┐......│
     │...┌┘        └─┐...........┌────┘   └─┘┌┴─┬──┘ └────┘ │........┌┘ │....┌┘  │.....┌┘ └────┘  └──┐...│
     │..┌┘           └┐.....┌─┐..└┐          │..│   ┌──┐    └┐......┌┘ ┌┘....└┐  └┐....│    ┌────┐   │...└┐
    ┌┘..└┐ ┌─────┐   ┌┘....┌┘ └┐..└┐        ┌┘..│ ┌─┘..└─┐   └┐.....│  │......└───┘....└┐  ┌┘....└┐  └┐...│
   ┌┘....└─┘.....└┐ ┌┘.....└┐ ┌┘...└┐       │...│┌┘......│    │.....│  └┐..........#....│ ┌┘......└┐  │...│
  ┌┘..........│...└┬┘.......└┐│.....└─┐   ┌─┘...││.......├─┐  │.....│   │...............└─┘........└┐ └┐..└┐
 ┌┘.......┌───┴┐...│.........││.......│  ┌┘....┌┘│.......│.└──┼┬─...│  ┌┘...........................└┐ │...│
┌┘.......┌┘    │.............└┘.......└┐ │...┌─┘ │...│.#......└┘....│ ┌┘........................│....└─┴─..└┐
│........│    ┌┘.......................│ │..┌┘   └┐..│..............└─┘......──.................│...........│
│........│   ┌┘..........┌─┐..........┌┘ │..│     └┐.............................┌─┐........................└┐
│........│  ┌┘.....┌─────┘ └──┐.......│  │..│      │.........................┌───┘ ├─...┌────┐...............│
│........│  │.....┌┘          └┐.....┌┘  └┐.└┐     └┐......┌─┬─┐....┌──┐.....│    ┌┘...┌┘    │....┌─┐........│
└┐......┌┘  │.....│    ┌────┐  │.....│   ┌┘..└┐     └┐....┌┘┌┘.│....│  └┐....│   ┌┘....│     │....│ │........│
 │....┌─┘   │.....└┐ ┌─┘....│  └┐...─┤  ┌┘....│      └┐...└┬┘.......│   │....└┐ ┌┘.....│  ┌──┘....└┬┘........│
 │....└─┐   └┐.....└─┘......└┐  │....└──┘.....└─┐  ┌─┬┘....│........└┐ ┌┘.....└┐│......└──┘........│.........│
 └┐.....└┐ ┌─┴─..............│ ┌┘...............└──┘.│...............│┌┘.......└┘......................┌┐....│
  │......└─┘.................└┐│.....................................└┘...............................─┤└┐...│
 ┌┘.........│.................└┘.........................│................┌──┐.#.#.....................│ └┐.┌┘
 │..........│..........................................──┼──┐.....#......┌┘  │....................│....└┐ ├─┤
 └┐.........│.....................┌─┐....................│  └─┐..........│   └─┐................#.├─┐...└─┘.└┐
  │....┌┐.........┌─┐.........│..┌┘ └─┐..................│    │...┌───┐..└┐    │..................│ │........│
  └┐...│└─┐.....┌─┘ └┐......┌─┴┐.└┐   └─┐..........│.....│    │...└┐  └┐..└─┐  └─┐....┌──┐.......┌┘ └┐.......│
  ┌┘..┌┘  └┐...┌┘    └┐.....│  │..│ ┌─┐ └┐.......┌─┤....┌┘    └┐...└─┬─┘....└─┐  └┐...└┐ └┐......│   │......┌┘
  │...│    │...└───┐  │.....└┐┌┘..│┌┘.└┐ └┐.....┌┘ │....│      ├─....│........│   └┐...└┐ └┐.....└┐ ┌┘......│
 ┌┘..┌┘   ┌┘.......│  │......└┘...││...└┐ │.....└┐┌┘....└┐┌────┘.........┌─┐..└┐   └┐...└┐ └┐.....└─┘.......└┐
┌┘..┌┘    │........│  └┐..........└┘....└─┘......└┘......└┘..............│ └┐..└┐   │....│ ┌┘................│
│...│    ┌┘....┌───┘   └┐...............................................─┤  └┐..└┐  └┐...└─┤.................│
│..┌┘   ┌┘....┌┘        │..........................................┌┐....│   │...└┐  │.....│.................│
│.┌┘   ┌┘.....└┐        │..........................................│└─┐.┌┘  ┌┘....└─┐│.......................│
│.└┐  ┌┘.......└───┐   ┌┘.......┌┐......┌─┐..................│.....│  └─┘   │.......└┘.....>.........#.......│
│..└┬─┘............│┌──┘......┌─┘└┐.....│ └┐..─┐.............│.....│        │.............┌─┐...............┌┘
│...│..┌──┐........││........┌┘   └┐...┌┘  └┐..├───┐..............┌┘        │..┌─┐......┌─┘ ├─....┌┐........│
│......│  └┐......┌┘└┐......┌┘     └───┘    └──┘   └┐....┌──┐....┌┘       ┌─┴─┬┘ │.....┌┘   │....┌┘└┐......┌┘
└─┐....│   ├─.....└┐ │......└┐     ┌──┐             │....│  └┐..┌┘       ┌┘...└┐ │.....│   ┌┘....│  └┐.....│
  ├─..┌┘  ┌┘.......│ └┐......└┐   ┌┘..│             └┐...│   └──┘       ┌┘.....└─┘.....└─┐┌┘.....└┐  │.....│
┌─┘...└┐ ┌┘........└┐ │.......└───┘...│              │..┌┘              │................└┘.......│  └┐....└─┐
│......└─┘..........│ └─┐.............└─┬───┐       ┌┘.┌┘               │.........................└┐ ┌┘......│
│...................└┐  └───┐...........│...└───────┘..└┐               │.......┌─┐................│ │.......│
└┐...................│      │..........┌┴┐..............└┐              ├─......│ └┐...............└─┘.......│
 └┐.#................│      │..........│ └┐..............└┐         ┌───┘.....┌─┘  │.........................│
  └┐...............┌─┘      │.........┌┘  └┐.....┌───┐....│         │.........│    │......│....┌──────┐.....┌┘
   └┐.┌───┐........│        └───┐....┌┘    └─┐.┌─┘   └─┐.┌┘         └┐......┌─┘    └─┐...┌┴────┘      └─┐..┌┘
    └─┘   └────────┘            └────┘       └─┘       └─┘           └──────┘        └───┘              └──┘

  • Field Details

    • gen

      public DungeonBoneGen gen
    • width

      public final int width
    • height

      public final int height
    • type

      public TilesetType type
    • rng

      public com.github.tommyettinger.random.EnhancedRandom rng
    • environment

      public final int[][] environment
    • ca

      protected com.github.yellowstonegames.grid.CellularAutomaton ca
  • Constructor Details

    • FlowingCaveGenerator

      public FlowingCaveGenerator()
      Default constructor that makes a 80x80 cave map with a random seed.
    • FlowingCaveGenerator

      public FlowingCaveGenerator(int width, int height)
      Makes a cave map with the specified dimensions and a random seed.
      Parameters:
      width - the width of the dungeon map(s) to generate
      height - the height of the dungeon map(s) to generate
    • FlowingCaveGenerator

      public FlowingCaveGenerator(int width, int height, TilesetType type, com.github.tommyettinger.random.EnhancedRandom rng)
      Parameters:
      width - the width of the dungeon map(s) to generate
      height - the height of the dungeon map(s) to generate
      type - a TilesetType enum value; TilesetType.DEFAULT_DUNGEON is used if null or unspecified
      rng - a random number generator to use when generating the caves; if null this will use a default RNG
  • Method Details

    • generate

      public char[][] generate()
      Generates a flowing cave dungeon withthe same TilesetType this was made with, or TilesetType.DEFAULT_DUNGEON if none was specified. This uses the convention of '#' representing a wall and '.' representing a bare floor.
      Specified by:
      generate in interface PlaceGenerator
      Returns:
      a 2D char array representing a cave system with '#' for walls and '.' for floors
    • generate

      public char[][] generate(TilesetType type)
      Generates a flowing cave dungeon with a different TilesetType than this generator was made with. The default type is TilesetType.DEFAULT_DUNGEON if unspecified in the constructor.
      Parameters:
      type - a TilesetType enum value
      Returns:
      a 2D char array for the cave system
    • generate

      public char[][] generate(TilesetType type, double roomChance)
      Generates a flowing cave dungeon with a different TilesetType than this generator was made with, and specifying a chance to keep the original walls of rooms before the flowing smoothing step is performed. roomChance can be between 0.0 and 1.0, and if a room (identified with a similar technique to RoomFinder, but not using it directly) is randomly selected to be preserved (the probability per room is roomChance), then most of its walls will be kept in-place, generally with more right angles than the caves will have. It may be best to keep roomChance above 0.5 if you want the effect to be noticeable. Starting with TilesetType.DEFAULT_DUNGEON is a good choice for type.
      Parameters:
      type - a TilesetType enum value
      roomChance - the chance, from 0.0 to 1.0, to preserve each room, keeping its walls where they start
      Returns:
      a 2D char array for the cave system
    • getPlaceGrid

      public char[][] getPlaceGrid()
      Gets the most recently-produced dungeon as a 2D char array, usually produced by calling generate() or some similar method present in a specific implementation. This normally passes a direct reference and not a copy, so you can normally modify the returned array to propagate changes back into this IDungeonGenerator.
      Specified by:
      getPlaceGrid in interface PlaceGenerator
      Returns:
      the most recently-produced dungeon/map as a 2D char array
    • getEnvironment

      public int[][] getEnvironment()
      Gets an environment map as a 2D int array that DungeonProcessor can use along with the normal 2D char array dungeon map to add dungeon features. This marks cells as either DungeonTools.UNTOUCHED (equal to 0), DungeonTools.NATURAL_FLOOR (equal to 3), or DungeonTools.NATURAL_WALL (equal to 4). If the environment has not yet been retrieved since generate() was last called, this assigns the environment map to match the dungeon map; otherwise it uses the cached environment map.
      Specified by:
      getEnvironment in interface PlaceGenerator
      Returns:
      a 2D int array that can be used as an environment map with SectionDungeonGenerator.
    • toString

      public String toString()
      Overrides:
      toString in class Object