Randomly generating entity data on new games
In Part 1, I talked about building the terrain and in Part 2, I talked about placing entity locations on the map. But when the player starts a new game and is randomly slotted into a starting location, what happens with the enemies? All enemy troops and bases are defined on the map as just locations, so the game needs to assign what type of enemy gets slotted into these locations when the game starts.
All of this will be calculated based upon the enemy spawn location distance from the player starting location!
When the starting location is chosen, every enemy troop and base location will be placed in a list and sorted based upon their distance to the starting location. The game will then set the closest enemy as the Tutorial Wolf which is super easy and is always next to the player base, due to how we generate starting location data. All other enemies will be separated into some tiers, with tier 1 enemies being close by, and tier 5 enemies being the furthest from the player.
These tiers are used for deciding what troops can exist in the pool of enemies we will select from. Tier 1 will have very weak enemies, namely wolves and hyenas, and tier 5 will have a majority of very strong enemies with some easier enemies sprinkled in. Each enemy type has weighted odds based upon the tier they are in, so tier 1 might have a lot of 10-200 strength enemies, but occasionally a 400 strength enemy might be pulled to shake things up.
Once an enemy is randomly picked in the tier, the game will set the strength of the enemy based upon its min and max strength. Just because you found a wolf doesn’t mean it will always have a strength of 5. It might have a strength of 50 and you’ll need to bring more troops to defeat it. Likewise, you might find a wolf in tier 5 territory and will be treated with an easy victory.
The same technique is applied to the enemy bases, but since there are fewer types of bases, it basically breaks the map down into easy, medium, and hard areas for the enemy bases, radiating out from the starting location.
By generating enemies and bases in this way, the player is faced with incremental difficulty as they expand past their initial base, no matter where their starting location appears on the map. With the occasional sprinkling in of easier enemies in the higher tiers, the outer areas will appear more diverse and the difficulty might be hidden a little bit.
That wraps up the three part series about how maps are generated for Idle Realm!