Class PoliticalMapper

java.lang.Object
squidpony.squidgrid.mapping.PoliticalMapper

public class PoliticalMapper
extends Object
When you have a world map as produced by WorldMapGenerator or some other source, you may want to fill it with claims by various nations/factions, possibly procedural or possibly hand-made. This can assign contiguous areas of land to various factions, while ignoring some amount of "wild" land if desired, and keeping oceans unclaimed. The factions can be given procedural names in an atlas that is linked to the chars used by the world map. Uses MultiSpill internally to produce the semi-random nation shapes. Stores an atlas that can be used to figure out what a char in a produced 2D char array means for its claiming nation, a briefAtlas that will have short, identifiable parts of generated names corresponding to the same chars as in atlas, and an OrderedMap of spokenLanguages that contains any randomly generated languages produced for nations. Example output of a related class.
See Also:
There's also an alternative for cases where non-human species compete for specific areas.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    OrderedMap<Character,​String> atlas
    Maps chars, as found in the returned array from generate(), to Strings that store the full name of nations.
    OrderedMap<Character,​String> briefAtlas
    Maps chars, as found in the returned array from generate(), to Strings that store the short name of nations.
    int height  
    static char[] letters  
    String name  
    char[][] politicalMap  
    StatefulRNG rng  
    OrderedMap<Character,​List<FakeLanguageGen>> spokenLanguages
    Maps chars, as found in the returned array from generate(), to Strings that store the languages spoken in those nations, which could be user-assigned, unassigned, or randomly-generated.
    int width  
  • Constructor Summary

    Constructors 
    Constructor Description
    PoliticalMapper()  
    PoliticalMapper​(String worldName)
    Constructs a SpillWorldMap using the given world name, and uses the world name as the basis for all future random generation in this object.
    PoliticalMapper​(IRNG random)
    Constructs a SpillWorldMap using the given world name, and uses the world name as the basis for all future random generation in this object.
  • Method Summary

    Modifier and Type Method Description
    char[][] generate​(WorldMapGenerator wmg, int factionCount, double controlledFraction)
    Produces a political map for the land stored in the given WorldMapGenerator, with the given number of factions trying to take land in the world (essentially, nations).
    char[][] generate​(WorldMapGenerator wmg, Map<Character,​String> existingAtlas, double controlledFraction)
    Produces a political map for the land stored in the given WorldMapGenerator, with the given number of factions trying to take land in the world (essentially, nations).
    char[][] generate​(WorldMapGenerator wmg, OrderedMap<Character,​FakeLanguageGen> atlasLanguages, double controlledFraction)
    Produces a political map for the land stored in the given WorldMapGenerator, with the given number of factions trying to take land in the world (essentially, nations).
    char[][] generate​(GreasedRegion land, int factionCount, double controlledFraction)
    Produces a political map for the land stored in the "on" cells of the given GreasedRegion, with the given number of factions trying to take land in the world (essentially, nations).
    char[][] generate​(GreasedRegion land, Map<Character,​String> existingAtlas, double controlledFraction)
    Produces a political map for the land stored in the "on" cells of the given GreasedRegion, with the given number of factions trying to take land in the world (essentially, nations).
    char[][] generate​(GreasedRegion land, OrderedMap<Character,​FakeLanguageGen> atlasLanguages, double controlledFraction)
    Produces a political map for the land stored in the "on" cells of the given GreasedRegion, with the given number of factions trying to take land in the world (essentially, nations).

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • PoliticalMapper

      public PoliticalMapper()
    • PoliticalMapper

      public PoliticalMapper​(String worldName)
      Constructs a SpillWorldMap using the given world name, and uses the world name as the basis for all future random generation in this object.
      Parameters:
      worldName - a String name for the world that will be used as a seed for all random generation here
    • PoliticalMapper

      public PoliticalMapper​(IRNG random)
      Constructs a SpillWorldMap using the given world name, and uses the world name as the basis for all future random generation in this object.
      Parameters:
      random - an RNG to generate the name for the world in a random language, which will also serve as a seed
  • Method Details

    • generate

      public char[][] generate​(WorldMapGenerator wmg, int factionCount, double controlledFraction)
      Produces a political map for the land stored in the given WorldMapGenerator, with the given number of factions trying to take land in the world (essentially, nations). The output is a 2D char array where each letter char is tied to a different faction, while '~' is always water, and '%' is always wilderness or unclaimed land. The amount of unclaimed land is determined by the controlledFraction parameter, which will be clamped between 0.0 and 1.0, with higher numbers resulting in more land owned by factions and lower numbers meaning more wilderness. This version generates an atlas with the procedural names of all the factions and a mapping to the chars used in the output; the atlas will be in the atlas member of this object. For every Character key in atlas, there will be a String value in atlas that is the name of the nation, and for the same key in spokenLanguages, there will be a non-empty List of FakeLanguageGen languages (usually one, sometimes two) that should match any names generated for the nation. Ocean and Wilderness get the default FakeLanguageGen instances "ELF" and "DEMONIC", in case you need languages for those areas for some reason.
      Parameters:
      wmg - a WorldMapGenerator that has produced a map; this gets the land parts of the map to assign claims to, including rivers and lakes as part of nations but not oceans
      factionCount - the number of factions to have claiming land, cannot be negative or more than 255
      controlledFraction - between 0.0 and 1.0 inclusive; higher means more land has a letter, lower has more '%'
      Returns:
      a 2D char array where letters represent the claiming faction, '~' is water, and '%' is unclaimed
    • generate

      public char[][] generate​(GreasedRegion land, int factionCount, double controlledFraction)
      Produces a political map for the land stored in the "on" cells of the given GreasedRegion, with the given number of factions trying to take land in the world (essentially, nations). The output is a 2D char array where each letter char is tied to a different faction, while '~' is always water, and '%' is always wilderness or unclaimed land. The amount of unclaimed land is determined by the controlledFraction parameter, which will be clamped between 0.0 and 1.0, with higher numbers resulting in more land owned by factions and lower numbers meaning more wilderness. This version generates an atlas with the procedural names of all the factions and a mapping to the chars used in the output; the atlas will be in the atlas member of this object. For every Character key in atlas, there will be a String value in atlas that is the name of the nation, and for the same key in spokenLanguages, there will be a non-empty List of FakeLanguageGen languages (usually one, sometimes two) that should match any names generated for the nation. Ocean and Wilderness get the default FakeLanguageGen instances "ELF" and "DEMONIC", in case you need languages for those areas for some reason.
      Parameters:
      land - a GreasedRegion that stores "on" cells for land and "off" cells for anything un-claimable, like ocean
      factionCount - the number of factions to have claiming land, cannot be negative or more than 255
      controlledFraction - between 0.0 and 1.0 inclusive; higher means more land has a letter, lower has more '%'
      Returns:
      a 2D char array where letters represent the claiming faction, '~' is water, and '%' is unclaimed
    • generate

      public char[][] generate​(WorldMapGenerator wmg, Map<Character,​String> existingAtlas, double controlledFraction)
      Produces a political map for the land stored in the given WorldMapGenerator, with the given number of factions trying to take land in the world (essentially, nations). The output is a 2D char array where each letter char is tied to a different faction, while '~' is always water, and '%' is always wilderness or unclaimed land. The amount of unclaimed land is determined by the controlledFraction parameter, which will be clamped between 0.0 and 1.0, with higher numbers resulting in more land owned by factions and lower numbers meaning more wilderness. This version uses an existing atlas and does not assign to spokenLanguages; it does not alter the existingAtlas parameter but uses it to determine what should be in this class' atlas field. The atlas field will always contain '~' as the first key in its ordering (with value "Ocean" if no value was already assigned in existingAtlas to that key), and '%' as the second key (with value "Wilderness" if not already assigned); later entries will be taken from existingAtlas (not duplicating '~' or '%', but using the rest).
      Parameters:
      wmg - a WorldMapGenerator that has produced a map; this gets the land parts of the map to assign claims to, including rivers and lakes as part of nations but not oceans
      existingAtlas - a Map (ideally an OrderedMap) of Character keys to be used in the 2D array, to String values that are the names of nations; should not have size greater than 255
      controlledFraction - between 0.0 and 1.0 inclusive; higher means more land has a letter, lower has more '%'
      Returns:
      a 2D char array where letters represent the claiming faction, '~' is water, and '%' is unclaimed
    • generate

      public char[][] generate​(GreasedRegion land, Map<Character,​String> existingAtlas, double controlledFraction)
      Produces a political map for the land stored in the "on" cells of the given GreasedRegion, with the given number of factions trying to take land in the world (essentially, nations). The output is a 2D char array where each letter char is tied to a different faction, while '~' is always water, and '%' is always wilderness or unclaimed land. The amount of unclaimed land is determined by the controlledFraction parameter, which will be clamped between 0.0 and 1.0, with higher numbers resulting in more land owned by factions and lower numbers meaning more wilderness. This version uses an existing atlas and does not assign to spokenLanguages; it does not alter the existingAtlas parameter but uses it to determine what should be in this class' atlas field. The atlas field will always contain '~' as the first key in its ordering (with value "Ocean" if no value was already assigned in existingAtlas to that key), and '%' as the second key (with value "Wilderness" if not already assigned); later entries will be taken from existingAtlas (not duplicating '~' or '%', but using the rest).
      Parameters:
      land - a GreasedRegion that stores "on" cells for land and "off" cells for anything un-claimable, like ocean
      existingAtlas - a Map (ideally an OrderedMap) of Character keys to be used in the 2D array, to String values that are the names of nations; should not have size greater than 255
      controlledFraction - between 0.0 and 1.0 inclusive; higher means more land has a letter, lower has more '%'
      Returns:
      a 2D char array where letters represent the claiming faction, '~' is water, and '%' is unclaimed
    • generate

      public char[][] generate​(WorldMapGenerator wmg, OrderedMap<Character,​FakeLanguageGen> atlasLanguages, double controlledFraction)
      Produces a political map for the land stored in the given WorldMapGenerator, with the given number of factions trying to take land in the world (essentially, nations). The output is a 2D char array where each letter char is tied to a different faction, while '~' is always water, and '%' is always wilderness or unclaimed land. The amount of unclaimed land is determined by the controlledFraction parameter, which will be clamped between 0.0 and 1.0, with higher numbers resulting in more land owned by factions and lower numbers meaning more wilderness. This version uses a "recipe for an atlas" instead of a complete atlas; this is an OrderedMap of Character keys to FakeLanguageGen values, where each key represents a faction and each value is the language to use to generate names for that faction. This does assign to spokenLanguages, but it doesn't change the actual FakeLanguageGen objects, since they are immutable. It may add some "factions" if not present to represent oceans and unclaimed land. The atlas field will always contain '~' as the first key in its ordering (with value "Ocean" if no value was already assigned in existingAtlas to that key, or a random nation name in the language that was mapped if there is one), and '%' as the second key (with value "Wilderness" if not already assigned, or a similar random nation name if there is one); later entries will be taken from existingAtlas (not duplicating '~' or '%', but using the rest).
      Parameters:
      wmg - a WorldMapGenerator that has produced a map; this gets the land parts of the map to assign claims to, including rivers and lakes as part of nations but not oceans
      atlasLanguages - an OrderedMap of Character keys to be used in the 2D array, to FakeLanguageGen objects that will be used to generate names; should not have size greater than 255
      controlledFraction - between 0.0 and 1.0 inclusive; higher means more land has a letter, lower has more '%'
      Returns:
      a 2D char array where letters represent the claiming faction, '~' is water, and '%' is unclaimed
    • generate

      public char[][] generate​(GreasedRegion land, OrderedMap<Character,​FakeLanguageGen> atlasLanguages, double controlledFraction)
      Produces a political map for the land stored in the "on" cells of the given GreasedRegion, with the given number of factions trying to take land in the world (essentially, nations). The output is a 2D char array where each letter char is tied to a different faction, while '~' is always water, and '%' is always wilderness or unclaimed land. The amount of unclaimed land is determined by the controlledFraction parameter, which will be clamped between 0.0 and 1.0, with higher numbers resulting in more land owned by factions and lower numbers meaning more wilderness. This version uses a "recipe for an atlas" instead of a complete atlas; this is an OrderedMap of Character keys to FakeLanguageGen values, where each key represents a faction and each value is the language to use to generate names for that faction. This does assign to spokenLanguages, but it doesn't change the actual FakeLanguageGen objects, since they are immutable. It may add some "factions" if not present to represent oceans and unclaimed land. The atlas field will always contain '~' as the first key in its ordering (with value "Ocean" if no value was already assigned in existingAtlas to that key, or a random nation name in the language that was mapped if there is one), and '%' as the second key (with value "Wilderness" if not already assigned, or a similar random nation name if there is one); later entries will be taken from existingAtlas (not duplicating '~' or '%', but using the rest).
      Parameters:
      land - a GreasedRegion that stores "on" cells for land and "off" cells for anything un-claimable, like ocean
      atlasLanguages - an OrderedMap of Character keys to be used in the 2D array, to FakeLanguageGen objects that will be used to generate names; should not have size greater than 255
      controlledFraction - between 0.0 and 1.0 inclusive; higher means more land has a letter, lower has more '%'
      Returns:
      a 2D char array where letters represent the claiming faction, '~' is water, and '%' is unclaimed