Package squidpony.squidgrid.mapping
Class FantasyPoliticalMapper
java.lang.Object
squidpony.squidgrid.mapping.FantasyPoliticalMapper
- All Implemented Interfaces:
Serializable
public class FantasyPoliticalMapper extends Object implements Serializable
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
WorldMapGenerator.BiomeMapper
to allocate biomes and height/moisture info.
The WorldMapGenerator is commonly a WorldMapGenerator.SphereMap
or a
WorldMapGenerator.EllipticalMap
for a world map because they are fairly familiar
map projections (WorldMapGenerator.HyperellipticalMap
can look better if
important areas are in the corners of the rectangular area, but it's less familiar). If you're making a political map
for an island or isolated area, then you may want WorldMapGenerator.LocalMap
or
WorldMapGenerator.LocalMimicMap
instead, which don't have world-scale features
like polar ice caps or a warm equator.- See Also:
- Serialized Form
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FantasyPoliticalMapper.Faction
Represents a group that claims territory on a world-map, such as a nation. -
Field Summary
Fields Modifier and Type Field Description OrderedMap<Character,FantasyPoliticalMapper.Faction>
atlas
Maps chars, as found in the returned array from generate(), to Strings that store the full name of nations.WorldMapGenerator.BiomeMapper
biomeMapper
int
height
String
name
char[][]
politicalMap
StatefulRNG
rng
int
width
WorldMapGenerator
wmg
char[][]
zoomedMap
-
Constructor Summary
Constructors Constructor Description FantasyPoliticalMapper()
Constructs a FantasyPoliticalMapper, but doesn't do anything with a map; you need to callgenerate(long, WorldMapGenerator, WorldMapGenerator.BiomeMapper, Collection, int, double)
for results. -
Method Summary
Modifier and Type Method Description char[][]
adjustZoom()
If the WorldMapGenerator used bygenerate(long, WorldMapGenerator, WorldMapGenerator.BiomeMapper, Collection, int, double)
zooms in or out, you can call this method to make thezoomedMap
2D char array match its zoom.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 128x128WorldMapGenerator.TilingMap
world map with aWorldMapGenerator.SimpleBiomeMapper
biome mapper, filling it with 30 random Factions and trying to avoid unclaimed land.char[][]
generate(long seed, WorldMapGenerator wmg, WorldMapGenerator.BiomeMapper biomeMapper, int factionCount)
Generates a 2D char array that represents the claims to the land described by the WorldMapGeneratorwmg
and the BiomeMapperbiomeMapper
by various Factions, whereFantasyPoliticalMapper.Faction
is an inner class.char[][]
generate(long seed, WorldMapGenerator wmg, WorldMapGenerator.BiomeMapper biomeMapper, int factionCount, double controlledFraction)
Generates a 2D char array that represents the claims to the land described by the WorldMapGeneratorwmg
and the BiomeMapperbiomeMapper
by various Factions, whereFantasyPoliticalMapper.Faction
is an inner class.char[][]
generate(long seed, WorldMapGenerator wmg, WorldMapGenerator.BiomeMapper biomeMapper, Collection<FantasyPoliticalMapper.Faction> factions, int factionCount, double controlledFraction)
Generates a 2D char array that represents the claims to the land described by the WorldMapGeneratorwmg
and the BiomeMapperbiomeMapper
by various Factions, whereFantasyPoliticalMapper.Faction
is an inner class.
-
Field Details
-
width
-
height
-
rng
-
name
-
politicalMap
-
zoomedMap
-
wmg
-
biomeMapper
-
atlas
Maps chars, as found in the returned array from generate(), to Strings that store the full name of nations.
-
-
Constructor Details
-
FantasyPoliticalMapper
public FantasyPoliticalMapper()Constructs a FantasyPoliticalMapper, but doesn't do anything with a map; you need to callgenerate(long, WorldMapGenerator, WorldMapGenerator.BiomeMapper, Collection, int, double)
for results.
-
-
Method Details
-
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 128x128WorldMapGenerator.TilingMap
world map with aWorldMapGenerator.SimpleBiomeMapper
biome mapper, filling it with 30 random Factions and trying to avoid unclaimed land. You may need to useatlas
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, WorldMapGenerator.BiomeMapper biomeMapper, int factionCount)Generates a 2D char array that represents the claims to the land described by the WorldMapGeneratorwmg
and the BiomeMapperbiomeMapper
by various Factions, whereFantasyPoliticalMapper.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 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
atlas
to find the Faction that claims it
-
generate
public char[][] generate(long seed, WorldMapGenerator wmg, WorldMapGenerator.BiomeMapper biomeMapper, int factionCount, double controlledFraction)Generates a 2D char array that represents the claims to the land described by the WorldMapGeneratorwmg
and the BiomeMapperbiomeMapper
by various Factions, whereFantasyPoliticalMapper.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 calladjustZoom()
to get a different 2D char array that represents the zoomed-in area. This overload tries to claim the givencontrolledFraction
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 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
atlas
to find the Faction that claims it
-
generate
public char[][] generate(long seed, WorldMapGenerator wmg, WorldMapGenerator.BiomeMapper biomeMapper, Collection<FantasyPoliticalMapper.Faction> factions, int factionCount, double controlledFraction)Generates a 2D char array that represents the claims to the land described by the WorldMapGeneratorwmg
and the BiomeMapperbiomeMapper
by various Factions, whereFantasyPoliticalMapper.Faction
is an inner class. This starts with two default Factions for "Ocean" and "Wilderness" (unclaimed land) and adds all offactions
untilfactionCount
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 calladjustZoom()
to get a different 2D char array that represents the zoomed-in area. This overload tries to claim the givencontrolledFraction
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 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 ofFantasyPoliticalMapper.Faction
that 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
atlas
to find the Faction that claims it
-
adjustZoom
If the WorldMapGenerator used bygenerate(long, WorldMapGenerator, WorldMapGenerator.BiomeMapper, Collection, int, double)
zooms in or out, you can call this method to make thezoomedMap
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 withGreasedRegion.fray(double)
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
-