home Idle Realm, Map Generation Building the maps in Idle Realm (Part 2)

Building the maps in Idle Realm (Part 2)


Randomly generating entity locations

In Part 1, I talked about the creation of the map’s terrain. But that’s not all that the map has! The map data file also has player starting locations, enemy troop and base locations, as well as ruins locations. Dropping down all of these locations so that the enemy spread is pretty good is time consuming as well, with this process taking around 15 minutes to place 400 or so enemies.

Time for more randomization!

The map generator was modified to also grab every terrain type that a troop can be on and then apply a min and max fill percentage, dropping down all enemies on the map. With all enemy locations taken care of for me, I just need to drop down player starting locations, enemy bases and ruins, which is only about 50 items. These items I actually want to place by hand, making sure they appear in interesting or useful areas.

Although I am placing the player starting locations by hand, the terrain around them will typically not have the starting requirements I need, so more randomization to the rescue! Starting areas need specific counts of each type of land and they also need only one enemy troop touching the border. To take care of this, when I drop down the player starting location in the editor, it will apply a special starting location brush that will grab all the terrain within a 5 tile radius, convert it all to grass, and then populate the terrain types it needs at the distances required from the center of the location. We get mountains on the edges due to this. Any enemies in this range will be removed and one new enemy will be spawned on the edge of the starting location. This method ensures that every starting location is the same, functionally, and I don’t have to manually craft the starting location 10-12 times per map.

The great thing about the map generator is that it works for all map sizes I support, from 32×32 all the way up to 96×96. If I want to try a new map size, such as 32×96, I can just generate it, drop a couple starting locations and start testing that map in 2 minutes. If it works out, I can add details and make it final.

Generating player starting locations, enemy base locations and ruins locations can also be handled procedurally. Although I don’t need it right now, I might add that feature in the future if I want completely randomized maps generated on the client machine every time they start a new game instead of picking from pre-made maps.

For player locations, the generator could visit every land tile and do a search to find how many tiles away the closest water tile is, and possibly if any other starting location is within 15 tiles away. Then, build a list of all tiles that are at least 5-6 tiles away from water and pick a location from that list. Do this multiple times until all player locations are set, with the starting location check ensuring that no two locations overlap or are too close.

Enemy bases would do the same thing, but can relax some of the water tile requirements and also ensure they aren’t too close to another enemy base.

Ruins can be placed randomly, just like enemy troops, but they need to make sure they are not close to other ruins. Also, the land around a ruin should look interesting, so depending on the biome that it is generated in, perhaps it can have a preset ruins brush that affects the terrain at its location, so it looks more unique and special. Dropping it in the forest? Surround it by trees. In the mountains? Make it look like it is surrounded by mountains, with one tile open as if a path exists to the ruins. That type of thing.

In the end, thanks to lots of procedural generation and a little bit of hand crafting, terrain creation takes about 4 minutes and placing starting locations for entities also takes about 4 minutes. 8 minutes to generate a map is much better than over an hour.

Next time, I will talk about randomly generating the entity data when the player starts a new game!