Class WildernessGenerator

java.lang.Object
com.github.yellowstonegames.place.WildernessGenerator
All Implemented Interfaces:
PlaceGenerator
Direct Known Subclasses:
WildernessGenerator.MixedWildernessGenerator

public class WildernessGenerator extends Object implements PlaceGenerator
A finite 2D area map for some kind of wilderness, adapting to different ecosystems by changing its output. Regional maps for wilderness areas have very different requirements from mostly-artificial dungeons. This is intended to work alongside the squidworld module to produce local outdoor maps for specified biomes in a large map, for example, very sparse maps with an occasional cactus in a desert, or very dense maps with many trees and shrubs for a forest.
Using this code mostly involves constructing a WildernessGenerator with a width, height, biome, and optionally a random number generator, an ObjectList of floor types (as Strings) that can appear, and an ObjectList of terrain content that can appear (also as Strings). Then you can call generate(), which assigns indices into content and floors, where an index can look up a value from contentTypes or floorTypes. The biome is currently an int; this will probably change to an enum. The contentTypes field is an ObjectList; you can have and are encouraged to have duplicates when an object should appear more often. An index of -1 in content indicates nothing of note is present there. There is also a String array of floorTypes that is not typically user-set unless you subclass WildernessGenerator yourself; it is used to look up the indices in floors. The floors are set to reasonable values for the particular biome, so a forest has "dirt" and "leaves" among others, while a desert might only have "sand". Again, only the indices matter, so you could change the values in floorTypes to match names of textures in a graphical game and make lookup easier, or to a char followed by the name of a color (as in SColor in the display module) for a text-based game.
This is marked Beta because there's still some work to be done, and the actual output will change even if the API doesn't have any breaks. While the wilderness maps this produces are usable, they don't have paths or areas that a character would have to find a way around (like a cliff). This is meant to be added at some point, probably in conjunction with some system for connecting WildernessGenerators.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A subclass of WildernessGenerator that serves as a ragged edge between 2, 3, or 4 WildernessGenerators in a square intersection.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    final int[][]
     
    final int[][]
     
    final int[][]
     
    com.github.tommyettinger.ds.ObjectList<String>
     
    final int[][]
     
    final int[][]
     
    com.github.tommyettinger.ds.ObjectList<String>
     
    final long[][]
     
    final char[][]
     
    final int
     
    com.github.tommyettinger.random.EnhancedRandom
     
    com.github.tommyettinger.ds.ObjectLongMap<String>
     
    final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    WildernessGenerator(int width, int height, Biome biome)
     
    WildernessGenerator(int width, int height, Biome biome, long seedA, long seedB)
     
    WildernessGenerator(int width, int height, Biome biome, com.github.tommyettinger.random.EnhancedRandom rng)
     
    WildernessGenerator(int width, int height, Biome biome, com.github.tommyettinger.random.EnhancedRandom rng, com.github.tommyettinger.ds.ObjectList<String> contentTypes)
     
    WildernessGenerator(int width, int height, Biome biome, com.github.tommyettinger.random.EnhancedRandom rng, com.github.tommyettinger.ds.ObjectList<String> floorTypes, com.github.tommyettinger.ds.ObjectList<String> contentTypes, com.github.tommyettinger.ds.ObjectLongMap<String> viewer)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int[][]
    blueSpill(int[][] toFill, int spillerLimit, com.github.tommyettinger.random.EnhancedRandom rng)
    Modifies toFill in-place by filling it with the (seeded variant) blue noise of this class, finding any points with values less than spillerLimit when brought into a 0-255 range, and then expanding those points pseudo-randomly while keeping the same value for any expanded range as its original point.
    static int[][]
    blueSpill(int[][] toFill, int spillerLimit, com.github.tommyettinger.random.EnhancedRandom rng, boolean triangular)
    Modifies toFill in-place by filling it with the (seeded variant) blue noise of this class, finding any points with values less than spillerLimit when brought into a 0-255 range, and then expanding those points pseudo-randomly while keeping the same value for any expanded range as its original point.
    static int[][]
    blueSpill(int width, int height, int spillerLimit, com.github.tommyettinger.random.EnhancedRandom rng)
    Generates a 2D int array (as with new int[width][height]) and fills it with the (seeded variant) blue noise of this class, finding any points with values less than spillerLimit when brought into a 0-255 range, and then expanding those points pseudo-randomly while keeping the same value for any expanded range as its original point.
    static com.github.tommyettinger.ds.ObjectList<String>
    contentByBiome(Biome biome, com.github.tommyettinger.random.EnhancedRandom rng)
    Gets a list of Strings that are really just the names of types of terrain feature for wilderness areas.
    static com.github.tommyettinger.ds.ObjectLongOrderedMap<String>
     
    static com.github.tommyettinger.ds.ObjectList<String>
    floorsByBiome(Biome biome, com.github.tommyettinger.random.EnhancedRandom rng)
    Gets a list of Strings that are really just the names of types of floor tile for wilderness areas.
    char[][]
    Produces a map by filling the floors 2D array with indices into floorTypes, and similarly filling the content 2D array with indices into contentTypes.
    int[][]
    Gets the most recently-produced place's environment as a 2D int array, where each int is typically a constant in DungeonTools like DungeonTools.NATURAL_WALL or DungeonTools.ROOM_FLOOR.
    char[][]
    Gets the most recently-produced place as a 2D char array, usually produced by calling generate() or some similar method present in a specific implementation.
    static com.github.tommyettinger.ds.ObjectList<String>
    Meant for generating large ObjectLists of Strings where an individual String may occur quite a few times.
    static com.github.tommyettinger.ds.ObjectList<String>
    makeShuffledRepeats(com.github.tommyettinger.random.EnhancedRandom rng, Object... rest)
     
    static com.github.tommyettinger.ds.ObjectList<String>
    Gets a list of Strings that are really just the names of types of path tile for wilderness areas.
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • width

      public final int width
    • height

      public final int height
    • biome

      public Biome biome
    • rng

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

      public com.github.tommyettinger.ds.ObjectList<String> contentTypes
    • floorTypes

      public com.github.tommyettinger.ds.ObjectList<String> floorTypes
    • viewer

      public com.github.tommyettinger.ds.ObjectLongMap<String> viewer
    • content

      public final int[][] content
    • floors

      public final int[][] floors
    • colors

      public final int[][] colors
    • colorsOklab

      public final int[][] colorsOklab
    • environment

      public final int[][] environment
    • grid

      public final char[][] grid
    • glyphs

      public final long[][] glyphs
  • Constructor Details

    • WildernessGenerator

      public WildernessGenerator()
    • WildernessGenerator

      public WildernessGenerator(int width, int height, Biome biome)
    • WildernessGenerator

      public WildernessGenerator(int width, int height, Biome biome, long seedA, long seedB)
    • WildernessGenerator

      public WildernessGenerator(int width, int height, Biome biome, com.github.tommyettinger.random.EnhancedRandom rng)
    • WildernessGenerator

      public WildernessGenerator(int width, int height, Biome biome, com.github.tommyettinger.random.EnhancedRandom rng, com.github.tommyettinger.ds.ObjectList<String> contentTypes)
    • WildernessGenerator

      public WildernessGenerator(int width, int height, Biome biome, com.github.tommyettinger.random.EnhancedRandom rng, com.github.tommyettinger.ds.ObjectList<String> floorTypes, com.github.tommyettinger.ds.ObjectList<String> contentTypes, com.github.tommyettinger.ds.ObjectLongMap<String> viewer)
  • Method Details

    • blueSpill

      public static int[][] blueSpill(int width, int height, int spillerLimit, com.github.tommyettinger.random.EnhancedRandom rng)
      Generates a 2D int array (as with new int[width][height]) and fills it with the (seeded variant) blue noise of this class, finding any points with values less than spillerLimit when brought into a 0-255 range, and then expanding those points pseudo-randomly while keeping the same value for any expanded range as its original point.
      Parameters:
      width - the width of the 2D array to return
      height - the height of the 2D array to return
      spillerLimit - the upper exclusive bound for the values that will be present in toFill when this finishes
      rng - an EnhancedRandom, such as a FlowRandom, to generate random values during expansion
      Returns:
      a 2D int array containing ints from 0 (inclusive) to spillerLimit (exclusive)
    • blueSpill

      public static int[][] blueSpill(int[][] toFill, int spillerLimit, com.github.tommyettinger.random.EnhancedRandom rng)
      Modifies toFill in-place by filling it with the (seeded variant) blue noise of this class, finding any points with values less than spillerLimit when brought into a 0-255 range, and then expanding those points pseudo-randomly while keeping the same value for any expanded range as its original point.
      Parameters:
      toFill - a 2D int array that will be modified in-place and entirely replaced; its contents don't matter
      spillerLimit - the upper exclusive bound for the values that will be present in toFill when this finishes
      rng - an EnhancedRandom, such as a FlowRandom, to generate random values during expansion
      Returns:
      toFill, after modifications
    • blueSpill

      public static int[][] blueSpill(int[][] toFill, int spillerLimit, com.github.tommyettinger.random.EnhancedRandom rng, boolean triangular)
      Modifies toFill in-place by filling it with the (seeded variant) blue noise of this class, finding any points with values less than spillerLimit when brought into a 0-255 range, and then expanding those points pseudo-randomly while keeping the same value for any expanded range as its original point.
      Parameters:
      toFill - a 2D int array that will be modified in-place and entirely replaced; its contents don't matter
      spillerLimit - the upper exclusive bound for the values that will be present in toFill when this finishes
      rng - an EnhancedRandom, such as a FlowRandom, to generate random values during expansion
      Returns:
      toFill, after modifications
    • makeRepeats

      public static com.github.tommyettinger.ds.ObjectList<String> makeRepeats(Object... rest)
      Meant for generating large ObjectLists of Strings where an individual String may occur quite a few times. The rest parameter is a vararg (it may also be an Object array) of alternating String and Integer values, where an Integer is how many times to repeat the preceding String in the returned ObjectList.
      Parameters:
      rest - a vararg (or Object array) of alternating String and Integer values
      Returns:
      an ObjectList of Strings, probably with some or most of them repeated; you may want to shuffle this result
    • makeShuffledRepeats

      public static com.github.tommyettinger.ds.ObjectList<String> makeShuffledRepeats(com.github.tommyettinger.random.EnhancedRandom rng, Object... rest)
    • floorsByBiome

      public static com.github.tommyettinger.ds.ObjectList<String> floorsByBiome(Biome biome, com.github.tommyettinger.random.EnhancedRandom rng)
      Gets a list of Strings that are really just the names of types of floor tile for wilderness areas.
      Parameters:
      biome - an index into some biome table, WIP
      rng - an EnhancedRandom, such as a FlowRandom, can be seeded
      Returns:
      a shuffled ObjectList that typically contains repeats of the kinds of floor that can appear here
    • pathsByBiome

      public static com.github.tommyettinger.ds.ObjectList<String> pathsByBiome(Biome biome)
      Gets a list of Strings that are really just the names of types of path tile for wilderness areas. Not currently used.
      Parameters:
      biome - an index into some biome table, WIP
      Returns:
      an ObjectList that typically contains just the one or few types of path that can appear here
    • contentByBiome

      public static com.github.tommyettinger.ds.ObjectList<String> contentByBiome(Biome biome, com.github.tommyettinger.random.EnhancedRandom rng)
      Gets a list of Strings that are really just the names of types of terrain feature for wilderness areas.
      Parameters:
      biome - an index into some biome table, WIP
      rng - an EnhancedRandom, such as a FlowRandom, can be seeded
      Returns:
      a shuffled ObjectList that typically contains repeats of the kinds of terrain feature that can appear here
    • defaultViewer

      public static com.github.tommyettinger.ds.ObjectLongOrderedMap<String> defaultViewer()
    • generate

      public char[][] generate()
      Produces a map by filling the floors 2D array with indices into floorTypes, and similarly filling the content 2D array with indices into contentTypes. You only need to call this method when you first generate a map with the specific parameters you want, such as biome, and later if you want another map with the same parameters.
      Virtually all of this method is a wrapper around functionality provided by BlueNoise, adjusted to fit wilderness maps slightly.
      Specified by:
      generate in interface PlaceGenerator
      Returns:
      a 2D char array representing some kind of map, probably using standard conventions for walls/floors
    • getPlaceGrid

      public char[][] getPlaceGrid()
      Gets the most recently-produced place 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 IPlaceGenerator.
      Specified by:
      getPlaceGrid in interface PlaceGenerator
      Returns:
      the most recently-produced dungeon/place as a 2D char array
    • getEnvironment

      public int[][] getEnvironment()
      Gets the most recently-produced place's environment as a 2D int array, where each int is typically a constant in DungeonTools like DungeonTools.NATURAL_WALL or DungeonTools.ROOM_FLOOR.
      Specified by:
      getEnvironment in interface PlaceGenerator
      Returns:
      the environment of the most recently-produced place, as a 2D int array
    • toString

      public String toString()
      Overrides:
      toString in class Object