Map Generation

Every game occurs on a unique, randomly generated square map. Maps come in six sizes and six water amounts. Terrain is spawned in proportions that vary by tribe. Each tribe has a unique set of spawn rates and unique aesthetics for terrain and resources. During the initial map generation, the land is distributed roughly equally between all tribes in the game.

## Map Size

There are six map sizes in Polytopia:

* Tiny: 121 tiles, 11x11
* Small: 196 tiles, 14x14
* Normal: 256 tiles, 16x16
* Large: 324 tiles, 18x18
* Huge: 400 tiles, 20x20
* Massive: 900 tiles, 30x30

Map size changes based on the game mode. Perfection games use a normal map. In Domination, the map size changes depending on the number of opponents: Games with one opponent are on a tiny map, two opponents on a 196-tile (14x14) map, three opponents on a normal map, and four or more on a large map.

In multiplayer and creative, map size is set by the host when creating a new game. Tiny maps support a maximum of nine players, while other maps support up to 16.

## Water Amount

*The following info pre-dates **Path of the Ocean** update and is no longer completely correct. The spawn rules still change from time to time while the devs finish their work on PotO. Please feel encouraged to update this if you know the exact rules.*

* Drylands: Entirely land. (Kickoo capital will include two water tiles with a fish in each.)
* Lakes: A border of land bridges will always generate on the edges of the map. Every player is guaranteed to spawn with land connections to at least two villages.
* Continents: Large but discrete landmasses. Most similar to pre-Moonrise maps. Every player is guaranteed to spawn with land connections to at least two villages.
* Pangea: A large landmass in the middle of the map surrounded by ocean on the outskirts.
* Archipelago: Misshapen and discontinuous landmasses. Almost every city is coastal.
* Water World: Small landmasses of one or two villages.

## Spawn Rates

The standard spawn rates for land tiles are listed in the table below. "Inner city" refers to tiles that are adjacent to a city or village, while "outer city" refers to those that are not.

Since update 2.0.58 (Balance Pass 2), terrain will always be generated in accordance with the percentage rates - for example, Luxidoor will always have 48% of their biome (or as close as possible) as field tiles.

The standard spawn rate for fish is 50% among shallow water tiles. Fish can also spawn in ocean tiles within a tribe's borders and some outside borders, which can be obtained with Border Growth. Starfish can spawn on any water tiles, and are scattered across the map.

All resources spawn only within two tiles of cities or villages. This fact can be used to locate villages and enemy cities.

### Spawn Rate Modifiers by Tribe

Modifiers by tribe are direct multipliers on the base rates. For example, Xin-xi has 1.5 times, or 50% more mountains compared to the base rate (Luxidoor). This will indirectly change the ration of the other resources. Modifiers are a little bit tricky to work with as not every modifier impacts all other terrain.

1. First the mountain modifier is checked. If this is not the base rate, it will affect both the forest and field rate. An increase of mountains will thus proportionally change the forest rate and field rate.
2. After this was changed, the forest multiplier is checked. Since this is checked after the mountain modifier, it will no longer impact the mountain rate, but only impact the fields.
3. Finally the field rate. There is no tribe that has a direct modifier for this and fields are thus just calculated via the simple 100% - Mountain% - Forest%.

Note that if forced in a 121 tile map, surrounding tribes can affect the spawn rates in the capital city. (ex. A naturally spawning Bardur crop.)

* Xin-xi: 1.5x mountain, 1.5x metal
* Imperius: 0.5x wild animal, 2.0x fruit
* Bardur: 1.5x fruit, 0x crop
* Oumaji: 0.2x forest, 0.2x wild animal, 0.5x mountain, 0.5x water
* Kickoo: 0.5x mountain, 1.5x fish, 2.0x water
* Hoodrick: 0.5x mountain, 1.5x forest
* Luxidoor: same as base rate
* Vengir: 2.0x metal, 0.1x wild animal, 0.1x fruit, 0.1x fish
* Zebasi: 0.5x mountain, 0.5x forest, 0.5x fruit
* Ai-Mo: 1.5x mountain, 0.1x crop
* Quetzali: 2.0x fruit, 0.1x crop
* Yădakk: 0.5x mountain, 0.5x forest, 1.5x fruit
* Aquarion: 0.5x forest, 1.5x water
* ∑∫ỹriȱŋ: 0.5x mountain, 1.5x crop
* Polaris: “alien”
* Cymanti: 1.2x mountain, crop rate replaced with spore rate, cannot spawn crop.

1. ↑ Reductions to the amount of water are found in the source code but are not translated into the world generation and do not impact water rates.
2. ↑ 2.0 2.1 On continents, Kickoo and Aquarion should have 40% and 30%, respectively, of their tiles replaced with water after the initial map generation, but this effect is bugged and does not currently apply to map generation.
3. ↑ Polaris is unique in that it has neither its own specific resource spawn rates nor any terrain allotted to it during world generation. Instead, other tribes in the wild animal determine the land and resources, and Polaris simply freezes its territory in the same way as the Freeze Area unit ability. (When a Polaris city is captured, the city's terrain will be converted to the capturing tribe's terrain.) If all players play Polaris, Imperius land and the default spawn rate for all resources are used.

## Spawning Rules

Spawning rules can be used to predict the locations of ruins, villages, and cities.

* Villages do not spawn on the edges of the map, and no more than one village will spawn in any 3x3 area. Resources spawn only within a two tile radius from villages.
* Ruins do not spawn next to a capital city or next to another ruin.
* Any water tile that shares an edge with a land tile is a shallow water tile. Other water tiles, including those diagonal from land tiles, are Ocean tiles.
* Crop, metal, and starfish are not visible until Organization (or Farming), Climbing, or Fishing are researched, respectively.
* All tribes are guaranteed to have at least two identical resources in their capital. For Bardur, Imperius, Kickoo, Zebasi, ∑∫ỹriȱŋ, and Cymanti these are the resources linked to their starting tech. Xin-xi is guaranteed two metal, Oumaji two fruit, and Hoodrick two animals. All other tribes are guaranteed two of a random tier 1 resource (fish, animal, or fruit). Resources are force-spawned by replacing tiles with a tile containing the resource if the initial world generation does not provide at least two of the resources. Because of this, Kickoo's capital will always contain at least two water tiles with fish, even on drylands. In the latter case, only the two tiles with force-spawned fish will be water tiles.
* Starfish do not spawn next to another starfish. (This info might be incorrect)

## Map Generation Process

This page is currently **under construction**. It may be incomplete or inaccurate. Please help Polytopia Wiki by editing it.
In AIR, all cities were generated after the terrain generation, right? Now we generate a few cities before starting terrain generation. First capitals of course. Randomly within each player's domain. Then, on all map types except dryland and waterworld we generate 1-2 suburbs per capital. Those are villages as close as possible to the capital. We also make sure that you are landconnected to at least 2 villages (often these are the same as the generated suburbs, but this is not always the case). In situations where it's simply impossible to add another suburb for a capital, that capital is instead connected to someone elses's suburb or capital. In order to make sure we never get deserted islands. Then, we randomly place out about a third of the villages. The amount varies a bit per map type. Also before terrain generation, so the only thing we need to take into account when placing these is to make sure they're at least two tiles away from any other city. After this we generated terrain from smoothed noise (where the city tiles are forced to land values, and are thereby likely to spread land around them through the smoothing). This is also random, we find all the locations a city could go (no water or mountains, and at least 2 tiles away from other cities). We randomly place cities on such locations as long as there are any left or until we reach or number of max cities (e.g. on dryland we set max city count to a little bit lower than the potential max so that the map isn't a completely predictable pattern of villages) https://discord.com/channels/283436219780825088/561211722296197120/780824395504943124 main server seems to be quoted by Yakmilk

number of domains depend on number of players. 1-4 players -> 4 domains, 5-9 players, 9 domains, 10-16 players 16 domains. max villages is not deterministic, and is different depending on map. most map configs generate 30% of theoretical max villages before generating terrain, then attempt to assign 60% after terrain has been generated. Dryland does not make villages before terrain, but creates 80% of max after terrain gen. water world only assigns 10% before terrain gen, (Midjifawr on beta server https://discord.com/channels/274660262873661442/736249160591998987/796666971365572618)

Domains are not the same as climate. Domains are equal-sized squares, and there can be empty domains. Not all maps create the domains in the same way, but they all follow the same rules for their creation:

1. Take the length of the map (11, 14, 16, 18, 20 or 30 depending on the size) and see if it can be divided by the square root of the number of domains needed to spawn everyone (2, 3 or 4). If it can be divided the initial NxN domain will be set at this. If it can't be divided, the SW-SE border will be removed for the domain creation and it will be checked again if it is divisible. If it is still not possible, the NW-NE border will also be removed from the domain creation. This process will continue until it is divisible and the initial domain is created.
2. After we have the initial domain, tiles on the outer 2 rows of the border of this domain will be removed so that capitals don't spawn right next to eachother. If the domain would be too small after removing the outer 2 borders (minimum a 2x2 grid), only the outer border will be removed.
3. The rules for capital placement can also change the domain as the capital can never spawn within 2 tiles of the border.

yeah they're as big as they can be. so in a 11x11 map the domains are 5x5, in 14x14 maps they're 7x7, etc. (previous continued)https://discord.com/channels/274660262873661442/736249160591998987/797025879452155935

domains don't need to be perfectly aligned with each other; in that case we distribute no mans land between the domains as evenly as possible.

## References

1. ↑ Verified experimentally in version 2.0.49.