Class BiomeMapper.DetailedBiomeMapper

java.lang.Object
com.github.yellowstonegames.world.BiomeMapper.DetailedBiomeMapper
All Implemented Interfaces:
BiomeMapper
Enclosing interface:
BiomeMapper

public static class BiomeMapper.DetailedBiomeMapper extends Object implements BiomeMapper
A way to get biome information for the cells on a map when you want an area's biome to be a combination of two main biome types, such as "Grassland" or "TropicalRainforest", with the biomes varying in weight between areas.
To use: 1, Construct a DetailedBiomeMapper (constructor takes no arguments). 2, call makeBiomes(WorldMapGenerator) with a WorldMapGenerator that has already produced at least one world map. 3, get biome codes from the biomeCodeData field, where a code is an int that can be used with the extract methods in this class to get various information from it (these are extractBiomeA(int), extractBiomeB(int), extractPartA(int), extractPartB(int), and extractMixAmount(int)). You can get predefined Biomes using the extractBiome methods, or raw indices into some (usually 66-element) collection or array with the extractPart methods. The extractMixAmount() method gets a float that is the amount by which biome B affects biome A; if this is higher than 0.5f, then biome B is the "dominant" biome in the area.
  • Field Details

    • heatCodeData

      public int[][] heatCodeData
      The heat codes for the analyzed map, from 0 to 5 inclusive, with 0 coldest and 5 hottest.
    • moistureCodeData

      public int[][] moistureCodeData
      The heat codes for the analyzed map, from 0 to 5 inclusive, with 0 coldest and 5 hottest.
    • biomeCodeData

      public int[][] biomeCodeData
      The heat codes for the analyzed map, from 0 to 5 inclusive, with 0 coldest and 5 hottest.
    • coldestValueLower

      public static final float coldestValueLower
      See Also:
    • coldestValueUpper

      public static final float coldestValueUpper
      See Also:
    • colderValueLower

      public static final float colderValueLower
      See Also:
    • colderValueUpper

      public static final float colderValueUpper
      See Also:
    • coldValueLower

      public static final float coldValueLower
      See Also:
    • coldValueUpper

      public static final float coldValueUpper
      See Also:
    • warmValueLower

      public static final float warmValueLower
      See Also:
    • warmValueUpper

      public static final float warmValueUpper
      See Also:
    • warmerValueLower

      public static final float warmerValueLower
      See Also:
    • warmerValueUpper

      public static final float warmerValueUpper
      See Also:
    • warmestValueLower

      public static final float warmestValueLower
      See Also:
    • warmestValueUpper

      public static final float warmestValueUpper
      See Also:
    • driestValueLower

      public static final float driestValueLower
      See Also:
    • driestValueUpper

      public static final float driestValueUpper
      See Also:
    • drierValueLower

      public static final float drierValueLower
      See Also:
    • drierValueUpper

      public static final float drierValueUpper
      See Also:
    • dryValueLower

      public static final float dryValueLower
      See Also:
    • dryValueUpper

      public static final float dryValueUpper
      See Also:
    • wetValueLower

      public static final float wetValueLower
      See Also:
    • wetValueUpper

      public static final float wetValueUpper
      See Also:
    • wetterValueLower

      public static final float wetterValueLower
      See Also:
    • wetterValueUpper

      public static final float wetterValueUpper
      See Also:
    • wettestValueLower

      public static final float wettestValueLower
      See Also:
    • wettestValueUpper

      public static final float wettestValueUpper
      See Also:
  • Constructor Details

    • DetailedBiomeMapper

      public DetailedBiomeMapper()
      Simple constructor; pretty much does nothing. Make sure to call makeBiomes(WorldMapGenerator) before using fields like biomeCodeData.
    • DetailedBiomeMapper

      public DetailedBiomeMapper(String serialized)
      Creates a new generator from the given serialized String, produced by stringSerialize().
      Parameters:
      serialized - should have been produced by stringSerialize()
  • Method Details

    • getHeatCodeData

      public int[][] getHeatCodeData()
      Specified by:
      getHeatCodeData in interface BiomeMapper
    • getMoistureCodeData

      public int[][] getMoistureCodeData()
      Specified by:
      getMoistureCodeData in interface BiomeMapper
    • getBiomeCodeData

      public int[][] getBiomeCodeData()
      Specified by:
      getBiomeCodeData in interface BiomeMapper
    • getBiomeCode

      public int getBiomeCode(int x, int y)
      Gets the biome code for the dominant biome at a given x,y position. This is equivalent to getting the raw biome code from biomeCodeData, calling extractMixAmount(int) on that raw biome code, and chooosing whether to call extractPartA(int) or extractPartB(int) based on whether the mix amount is lower than 0.5f (yielding part A) or higher (yielding part B).
      Specified by:
      getBiomeCode in interface BiomeMapper
      Parameters:
      x - the x-coordinate on the map
      y - the y-coordinate on the map
      Returns:
      the biome code for the dominant biome part at the given location
    • getHeatCode

      public int getHeatCode(int x, int y)
      Description copied from interface: BiomeMapper
      Gets a heat code for a given x,y point on a map, usually as an int between 0 and 5 inclusive. Some implementations may use more or less detail for heat codes, but 0 is always the coldest code used, and the highest value this can return for a given implementation refers to the hottest code used.
      Specified by:
      getHeatCode in interface BiomeMapper
      Parameters:
      x - the x-coordinate on the map
      y - the y-coordinate on the map
      Returns:
      an int that can be used to categorize how hot an area is, with 0 as coldest
    • getMoistureCode

      public int getMoistureCode(int x, int y)
      Description copied from interface: BiomeMapper
      Gets a moisture code for a given x,y point on a map, usually as an int between 0 and 5 inclusive. Some implementations may use more or less detail for moisture codes, but 0 is always the driest code used, and the highest value this can return for a given implementation refers to the wettest code used. Some implementations may allow seasonal change in moisture, e.g. monsoon seasons, to be modeled differently from average precipitation in an area, but the default assumption is that this describes the average amount of moisture (rain, humidity, and possibly snow/hail or other precipitation) that an area receives annually.
      Specified by:
      getMoistureCode in interface BiomeMapper
      Parameters:
      x - the x-coordinate on the map
      y - the y-coordinate on the map
      Returns:
      an int that can be used to categorize how much moisture an area tends to receive, with 0 as driest
    • getBiomeTable

      public com.github.yellowstonegames.place.Biome[] getBiomeTable()
      Gets a String array where biome codes can be used as indices to look up a name for the biome they refer to. This table uses 6 levels of heat and 6 levels of moisture, and tracks rivers, coastlines, lakes, and oceans as potentially different types of terrain. Biome codes can be obtained with getBiomeCode(int, int). This method returns a direct reference to Biome.TABLE, so modifying the returned array is discouraged (you should implement BiomeMapper using this class as a basis if you want to change its size).
      Unlike with BiomeMapper.SimpleBiomeMapper, you cannot use a biome code directly from biomeCodeData as an index into this in almost any case; you should pass the biome code to one of the extract methods. extractBiomeA(int) or extractBiomeB(int) will work if you want a biome name, or extractPartA(int) or extractPartB(int) should be used if you want a non-coded int that represents one of the biomes' indices into something like this. You can also get the amount by which biome B is affecting biome A with extractMixAmount(int).
      Specified by:
      getBiomeTable in interface BiomeMapper
      Returns:
      a direct reference to Biome.TABLE, a Biome array with 66 items
    • extractPartA

      public int extractPartA(int biomeCode)
      Gets the int stored in part A of the given biome code, which can be used as an index into other collections. This int should almost always range from 0 to 65 (both inclusive), so collections this is used as an index for should have a length of at least 66.
      Parameters:
      biomeCode - a biome code that was probably received from biomeCodeData
      Returns:
      an int stored in the biome code's part A; almost always between 0 and 65, inclusive.
    • extractBiomeA

      public com.github.yellowstonegames.place.Biome extractBiomeA(int biomeCode)
      Gets a String from Biome.TABLE that names the appropriate biome in part A of the given biome code.
      Parameters:
      biomeCode - a biome code that was probably received from biomeCodeData
      Returns:
      a String that names the biome in part A of biomeCode, or "Space" if none can be found
    • extractPartB

      public int extractPartB(int biomeCode)
      Gets the int stored in part B of the given biome code, which can be used as an index into other collections. This int should almost always range from 0 to 65 (both inclusive), so collections this is used as an index for should have a length of at least 66.
      Parameters:
      biomeCode - a biome code that was probably received from biomeCodeData
      Returns:
      an int stored in the biome code's part B; almost always between 0 and 65, inclusive.
    • extractBiomeB

      public com.github.yellowstonegames.place.Biome extractBiomeB(int biomeCode)
      Gets a String from Biome.TABLE that names the appropriate biome in part B of the given biome code.
      Parameters:
      biomeCode - a biome code that was probably received from biomeCodeData
      Returns:
      a String that names the biome in part B of biomeCode, or "Ocean" if none can be found
    • extractMixAmount

      public float extractMixAmount(int biomeCode)
      This gets the portion of a biome code that represents the amount of mixing between two biomes. Biome codes are normally obtained from the biomeCodeData field, and aren't very usable on their own without calling methods like this, extractBiomeA(int), and extractBiomeB(int). This returns a float between 0.0f (inclusive) and 1.0f (exclusive), with 0.0f meaning biome B has no effect on an area and biome A is the only one used, 0.5f meaning biome A and biome B have equal effect, and 0.75f meaning biome B has most of the effect, three-fourths of the area, and biome A has less, one-fourth of the area.
      Parameters:
      biomeCode - a biome code that was probably received from biomeCodeData
      Returns:
      a float between 0.0f (inclusive) and 1.0f (exclusive) representing mixing of biome B into biome A
    • stringSerialize

      public String stringSerialize()
      Serializes this generator's entire state to a String; it can be read back when creating a new instance of this type with DetailedBiomeMapper(String) or recreateFromString(String). Uses Base.BASE86 to represent values very concisely, but not at all readably. The String this produces tends to be very long because it includes some 2D arrays as Strings.
      Specified by:
      stringSerialize in interface BiomeMapper
      Returns:
      a String that stores the entire state of this generator
    • recreateFromString

      public static BiomeMapper.DetailedBiomeMapper recreateFromString(String data)
      Creates a new instance of this class from a serialized String produced by stringSerialize(). This is here for compatibility with other classes that use String serialization, but you can just use DetailedBiomeMapper(String) instead.
      Parameters:
      data - the output of stringSerialize()
      Returns:
      the map that was serialized, as a new generator
    • makeBiomes

      public void makeBiomes(WorldMapGenerator world)
      Analyzes the last world produced by the given WorldMapGenerator and uses all of its generated information to assign biome codes for each cell (along with heat and moisture codes). After calling this, biome codes can be taken from biomeCodeData and used with methods in this class like extractBiomeA(int), extractBiomeB(int), and extractMixAmount(int) to find the two dominant biomes in an area, called biome A and biome B, and the mix amount, for finding how much biome B affects biome A.
      Specified by:
      makeBiomes in interface BiomeMapper
      Parameters:
      world - a WorldMapGenerator that should have generated at least one map; it may be at any zoom
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface BiomeMapper
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object