Class PoliticalMapper

java.lang.Object
com.github.yellowstonegames.world.PoliticalMapper

public class PoliticalMapper extends Object
When you have a world map as produced by WorldMapGenerator, you may want to fill it with claims by various factions, where each faction may be hand-made and may consist of humans or some fantasy species, such as goblins, elves, or demons. This can assign contiguous areas of land to various factions, while acknowledging any preferences some species may have for specific types of land (elves may strongly prefer forest terrain, or flying demons may be the ideal residents for difficult mountainous terrain). This needs both a WorldMapGenerator and a BiomeMapper to allocate biomes and height/moisture info. If allocating human groups only, you might want to decide where a faction would settle by what technologies they use regularly; a seafaring culture would have a PoliticalMapper.Faction.preferredHeight that includes 4, so they can settle on shorelines, while a horse-riding culture might have PoliticalMapper.Faction.preferredBiomes that include "Grassland" and "Savanna" so they can ride easily. The WorldMapGenerator is commonly a LocalMap for continent/area maps, or a StretchWorldMap for a world map for a familiar shape for world maps, but an EllipticalWorldMap or HyperellipticalWorldMap can look better if important areas are in the corners of the rectangular area, though they are less familiar map shapes). LocalMap and MimicLocalMap may be better if you don't want world-scale features like polar ice caps or a warm equator. You probably don't want a GlobeMap or RotatingGlobeMap because those don't show the edges of the map with the same size as the center, and don't show the back of the globe at all.
  • Field Details

    • rng

      public com.github.tommyettinger.random.EnhancedRandom rng
      Used for all random decisions this makes, including generating random Factions if needed.
    • name

      public String name
      The name of the world, like "Earth" or "Terra".
    • politicalMap

      public char[][] politicalMap
      Stores individual Unicode chars per cell on the map's grid; each char will correspond to a Faction in atlas after generate(long, WorldMapGenerator, BiomeMapper, int) is called. You can look up any char present in this 2D array to find what Faction it means by consulting atlas.
    • zoomedMap

      public char[][] zoomedMap
      After generate(long, WorldMapGenerator, BiomeMapper, int) is called, this is identical to politicalMap, but if adjustZoom() is called after that, then this can be different from the normal politicalMap, and may refer to a different area of the map at a different scale.
    • wmg

      public WorldMapGenerator wmg
      Stored when generate(long, WorldMapGenerator, BiomeMapper, int) is called, and is later reused if adjustZoom() is called. This does not need to be set manually as a field.
    • biomeMapper

      public BiomeMapper biomeMapper
      This is usually stored when generate(long, WorldMapGenerator, BiomeMapper, int) is called, and can be reused when adjustZoom() is called, if ever. This does not need to be set manually as a field.
    • atlas

      public com.github.tommyettinger.ds.IntObjectOrderedMap<PoliticalMapper.Faction> atlas
      Maps chars, as found in the returned array from generate(), to Strings that store the full name of nations. Not related to the concept of a texture atlas, but actually an atlas as in cartography.
  • Constructor Details

    • PoliticalMapper

      public PoliticalMapper()
      Constructs a PoliticalMapper with a random seed, but doesn't do anything with a map; you need to call generate(long, WorldMapGenerator, BiomeMapper, Collection, int, float) for results.
    • PoliticalMapper

      public PoliticalMapper(com.github.tommyettinger.random.EnhancedRandom random)
      Constructs a PoliticalMapper with the given EnhancedRandom, but doesn't do anything with a map; you need to call generate(long, WorldMapGenerator, BiomeMapper, Collection, int, float) for results. The random parameter's initial state usually doesn't matter unless you use generate() with no arguments; in most cases the EnhancedRandom has its seed set with an argument to generate(). This constructor allows you to specify the EnhancedRandom implementation.
  • Method Details

    • generate

      public char[][] generate()
      For when you really don't care what arguments you give this, you can use this zero-parameter overload of generate() to produce a 128x128 LocalMap world map with a BiomeMapper.SimpleBiomeMapper biome mapper, filling it with 30 random Factions and trying to avoid unclaimed land. You may need to use atlas to make sense of the randomly generated Factions. The seed will be random here.
      Returns:
      a 2D char array where each char can be used as a key into atlas to find the Faction that claims it
    • generate

      public char[][] generate(long seed, WorldMapGenerator wmg, BiomeMapper biomeMapper, int factionCount)
      Generates a 2D char array that represents the claims to the land described by the WorldMapGenerator wmg and the BiomeMapper biomeMapper by various Factions, where PoliticalMapper.Faction is an inner class. This starts with two default Factions for "Ocean" and "Wilderness" (unclaimed land) and adds randomly generated Factions to fill factionCount (the two default factions aren't counted against this limit). These Factions typically claim contiguous spans of land stretching out from a starting point that matches the Faction's preferences for biome, land height, heat, and moisture. If a Faction requires a biome (like "TropicalRainforest") and the world has none of that type, then that Faction won't claim any land. If the WorldMapGenerator zooms in or out, you should call adjustZoom() to get a different 2D char array that represents the zoomed-in area. This overload tries to claim all land that can be reached by an existing Faction, though islands will often be unclaimed.
      Parameters:
      seed - the seed that determines how Factions will randomly spread around the world
      wmg - a WorldMapGenerator, which must have produced a map by calling its generate() method
      biomeMapper - a WorldMapGenerator.BiomeMapper, which must have been initialized with wmg and refer to the same world
      factionCount - the number of factions to have claiming land; cannot be negative or more than 253
      Returns:
      a 2D char array where each char can be used as a key into atlas to find the Faction that claims it
    • generate

      public char[][] generate(long seed, WorldMapGenerator wmg, BiomeMapper biomeMapper, int factionCount, float controlledFraction)
      Generates a 2D char array that represents the claims to the land described by the WorldMapGenerator wmg and the BiomeMapper biomeMapper by various Factions, where PoliticalMapper.Faction is an inner class. This starts with two default Factions for "Ocean" and "Wilderness" (unclaimed land) and adds randomly generated Factions to fill factionCount (the two default factions aren't counted against this limit). These Factions typically claim contiguous spans of land stretching out from a starting point that matches the Faction's preferences for biome, land height, heat, and moisture. If a Faction requires a biome (like "TropicalRainforest") and the world has none of that type, then that Faction won't claim any land. If the WorldMapGenerator zooms in or out, you should call adjustZoom() to get a different 2D char array that represents the zoomed-in area. This overload tries to claim the given controlledFraction of land in total, though 1.0 can rarely be reached unless there are many factions and few islands.
      Parameters:
      seed - the seed that determines how Factions will randomly spread around the world
      wmg - a WorldMapGenerator, which must have produced a map by calling its generate() method
      biomeMapper - a WorldMapGenerator.BiomeMapper, which must have been initialized with wmg and refer to the same world
      factionCount - the number of factions to have claiming land; cannot be negative or more than 253
      controlledFraction - between 0.0 and 1.0 inclusive; higher means more land has a letter, lower has more '%'
      Returns:
      a 2D char array where each char can be used as a key into atlas to find the Faction that claims it
    • generate

      public char[][] generate(long seed, WorldMapGenerator wmg, BiomeMapper biomeMapper, Collection<PoliticalMapper.Faction> factions, int factionCount, float controlledFraction)
      Generates a 2D char array that represents the claims to the land described by the WorldMapGenerator wmg and the BiomeMapper biomeMapper by various Factions, where PoliticalMapper.Faction is an inner class. This starts with two default Factions for "Ocean" and "Wilderness" (unclaimed land) and adds all of factions until factionCount is reached; if it isn't reached, random Factions will be generated to fill factionCount (the two default factions aren't counted against this limit). These Factions typically claim contiguous spans of land stretching out from a starting point that matches the Faction's preferences for biome, land height, heat, and moisture. If a Faction requires a biome (like "TropicalRainforest") and the world has none of that type, then that Faction won't claim any land. If the WorldMapGenerator zooms in or out, you should call adjustZoom() to get a different 2D char array that represents the zoomed-in area. This overload tries to claim the given controlledFraction of land in total, though 1.0 can rarely be reached unless there are many factions and few islands.
      Parameters:
      seed - the seed that determines how Factions will randomly spread around the world
      wmg - a WorldMapGenerator, which must have produced a map by calling its generate() method
      biomeMapper - a WorldMapGenerator.BiomeMapper, which must have been initialized with wmg and refer to the same world
      factions - a Collection of PoliticalMapper.Faction that will be copied, shuffled and used before adding any random Factions
      factionCount - the number of factions to have claiming land; cannot be negative or more than 253
      controlledFraction - between 0.0 and 1.0 inclusive; higher means more land has a letter, lower has more '%'
      Returns:
      a 2D char array where each char can be used as a key into atlas to find the Faction that claims it
    • adjustZoom

      public char[][] adjustZoom()
      If the WorldMapGenerator used by generate(long, WorldMapGenerator, BiomeMapper, Collection, int, float) zooms in or out, you can call this method to make the zoomedMap 2D char array match its zoom. The world-scale map, politicalMap, will remain unchanged unless generate() is called again, but zoomedMap will change each time either generate() or adjustZoom() is called. This method isn't 100% precise on how it places borders; for aesthetic reasons, the borders are tattered with Region.fray(float) so they don't look like a wall of angular bubbles. Using fray() at each level of zoom is quasi-random, so if you zoom in on the same sequence of points on two different occasions, the change from fray() will be the same, but it may be slightly different if any point of zoom is different.
      Returns:
      a direct reference to zoomedMap, which will hold the correctly-zoomed version of politicalMap
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object