Class PoliticalMapper
java.lang.Object
com.github.yellowstonegames.world.PoliticalMapper
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a group that claims territory on a world-map, such as a nation. -
Field Summary
FieldsModifier and TypeFieldDescriptioncom.github.tommyettinger.ds.IntObjectOrderedMap<PoliticalMapper.Faction> Maps chars, as found in the returned array from generate(), to Strings that store the full name of nations.This is usually stored whengenerate(long, WorldMapGenerator, BiomeMapper, int)is called, and can be reused whenadjustZoom()is called, if ever.The name of the world, like "Earth" or "Terra".char[][]Stores individual Unicode chars per cell on the map's grid; each char will correspond to a Faction inatlasaftergenerate(long, WorldMapGenerator, BiomeMapper, int)is called.com.github.tommyettinger.random.EnhancedRandomUsed for all random decisions this makes, including generating random Factions if needed.Stored whengenerate(long, WorldMapGenerator, BiomeMapper, int)is called, and is later reused ifadjustZoom()is called.char[][]Aftergenerate(long, WorldMapGenerator, BiomeMapper, int)is called, this is identical topoliticalMap, but ifadjustZoom()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. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a PoliticalMapper with a random seed, but doesn't do anything with a map; you need to callgenerate(long, WorldMapGenerator, BiomeMapper, Collection, int, float)for results.PoliticalMapper(com.github.tommyettinger.random.EnhancedRandom random) Constructs a PoliticalMapper with the givenEnhancedRandom, but doesn't do anything with a map; you need to callgenerate(long, WorldMapGenerator, BiomeMapper, Collection, int, float)for results. -
Method Summary
Modifier and TypeMethodDescriptionchar[][]If the WorldMapGenerator used bygenerate(long, WorldMapGenerator, BiomeMapper, Collection, int, float)zooms in or out, you can call this method to make thezoomedMap2D char array match its zoom.final booleanchar[][]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 128x128LocalMapworld map with aBiomeMapper.SimpleBiomeMapperbiome mapper, filling it with 30 random Factions and trying to avoid unclaimed land.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 WorldMapGeneratorwmgand the BiomeMapperbiomeMapperby various Factions, wherePoliticalMapper.Factionis an inner class.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 WorldMapGeneratorwmgand the BiomeMapperbiomeMapperby various Factions, wherePoliticalMapper.Factionis an inner class.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 WorldMapGeneratorwmgand the BiomeMapperbiomeMapperby various Factions, wherePoliticalMapper.Factionis an inner class.inthashCode()toString()
-
Field Details
-
rng
public com.github.tommyettinger.random.EnhancedRandom rngUsed for all random decisions this makes, including generating random Factions if needed. -
name
The name of the world, like "Earth" or "Terra". -
politicalMap
public char[][] politicalMapStores individual Unicode chars per cell on the map's grid; each char will correspond to a Faction inatlasaftergenerate(long, WorldMapGenerator, BiomeMapper, int)is called. You can look up any char present in this 2D array to find what Faction it means by consultingatlas. -
zoomedMap
public char[][] zoomedMapAftergenerate(long, WorldMapGenerator, BiomeMapper, int)is called, this is identical topoliticalMap, but ifadjustZoom()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
Stored whengenerate(long, WorldMapGenerator, BiomeMapper, int)is called, and is later reused ifadjustZoom()is called. This does not need to be set manually as a field. -
biomeMapper
This is usually stored whengenerate(long, WorldMapGenerator, BiomeMapper, int)is called, and can be reused whenadjustZoom()is called, if ever. This does not need to be set manually as a field. -
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 callgenerate(long, WorldMapGenerator, BiomeMapper, Collection, int, float)for results. -
PoliticalMapper
public PoliticalMapper(com.github.tommyettinger.random.EnhancedRandom random) Constructs a PoliticalMapper with the givenEnhancedRandom, but doesn't do anything with a map; you need to callgenerate(long, WorldMapGenerator, BiomeMapper, Collection, int, float)for results. Therandomparameter's initial state usually doesn't matter unless you usegenerate()with no arguments; in most cases the EnhancedRandom has itsseed setwith 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 128x128LocalMapworld map with aBiomeMapper.SimpleBiomeMapperbiome mapper, filling it with 30 random Factions and trying to avoid unclaimed land. You may need to useatlasto 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
atlasto 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 WorldMapGeneratorwmgand the BiomeMapperbiomeMapperby various Factions, wherePoliticalMapper.Factionis 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 calladjustZoom()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 worldwmg- a WorldMapGenerator, which must have produced a map by calling its generate() methodbiomeMapper- a WorldMapGenerator.BiomeMapper, which must have been initialized with wmg and refer to the same worldfactionCount- 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
atlasto 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 WorldMapGeneratorwmgand the BiomeMapperbiomeMapperby various Factions, wherePoliticalMapper.Factionis 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 calladjustZoom()to get a different 2D char array that represents the zoomed-in area. This overload tries to claim the givencontrolledFractionof 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 worldwmg- a WorldMapGenerator, which must have produced a map by calling its generate() methodbiomeMapper- a WorldMapGenerator.BiomeMapper, which must have been initialized with wmg and refer to the same worldfactionCount- the number of factions to have claiming land; cannot be negative or more than 253controlledFraction- 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
atlasto 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 WorldMapGeneratorwmgand the BiomeMapperbiomeMapperby various Factions, wherePoliticalMapper.Factionis an inner class. This starts with two default Factions for "Ocean" and "Wilderness" (unclaimed land) and adds all offactionsuntilfactionCountis 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 calladjustZoom()to get a different 2D char array that represents the zoomed-in area. This overload tries to claim the givencontrolledFractionof 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 worldwmg- a WorldMapGenerator, which must have produced a map by calling its generate() methodbiomeMapper- a WorldMapGenerator.BiomeMapper, which must have been initialized with wmg and refer to the same worldfactions- a Collection ofPoliticalMapper.Factionthat will be copied, shuffled and used before adding any random FactionsfactionCount- the number of factions to have claiming land; cannot be negative or more than 253controlledFraction- 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
atlasto find the Faction that claims it
-
adjustZoom
public char[][] adjustZoom()If the WorldMapGenerator used bygenerate(long, WorldMapGenerator, BiomeMapper, Collection, int, float)zooms in or out, you can call this method to make thezoomedMap2D 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 withRegion.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 ofpoliticalMap
-
equals
-
hashCode
-
toString
-