Hey there folks, Alex and Jason here!
In this update, we talk about how our procedural maps are generated. They may be "procedural," but there's a lot of intention and planning under the hood. Read on to learn what we're talking about!
Procedural maps in Spy DNA
At this point, our game can generate a terrain up to 2x2k meters, and more or less cover it with trees,bushes, and grasses. We're talking literal thousands of them per square kilometer, with wind animation, and for trees also collision, so they can be used for cover.
But we thought our players would like to do a bit more than just run around in the woods each mission, so we added buildings.
That in turn means, taking another pass at the terrain and smoothing it under buildings, and removing vegetation on each plot designated for a building, because having a Douglas fir in the middle of your living room isn't everyone's taste. Also, having to go through literal bushes on the way to the bathroom may be a bit much to ask, even of an NPC.
Additionally, we have to make sure that the locations defined in the mission are all placed on the map in a way that makes the mission flow better for the player. The "location" in this context means anything from a building where the objectives are (item to be retrieved, hostage to be saved, etc.), to a place on the map where the player starts, or an item for the player to pick up.
Over the past weeks, Jason's been working on improving the code that interprets the mission description from our Editor tool, and generates a level from that. Now we have the ability to place locations within a certain distance from another location, to make sure that things that need to be close together stay that way, such as office buildings on a campus for example.
Another thing we can do now is group buildings by type, so that if we've got some residential houses and some industrial buildings, they will be placed on different blocks of the map, like one would expect. Jason implemented a sort of "zoning code" for the map generation, so that a block can be zoned residential, commercial, etc. and only the buildings suited for that zone can be placed there.
Locations that are most important for the mission must be placed on the map, while filler buildings can be optional. This is why we spawn our locations in order, according to what Alex has set in the Editor. This way we can be sure that locations such as the building where the objective is hidden, or the extraction vehicle you need to reach to escape the enemies, are placed on the map before a filler building that's only there to make the map look good.
Read on about how we create blocks of buildings
A peek under the hood
In the past we would generate a map when loading it. This meant that if you took a mission at the base, saved the game, and then went on the mission, you might see a different map if you reloaded your game and tried the mission again. With the new code the map is fully generated up-front, so if you want to replay a mission, the map will not change when you reload. This was also an important step as we work towards supporting saving mid-mission.
Several things need to happen when generating a new map. Anyone who wants to create a custom mission for Spy DNA will want to understand how we do this in order to be able to create a map description in the mission editor that fits the scenario they had in mind.
1: We start by generating the terrain height map based on the size of the map, the amount of hills specified, and the roughness of the map
2: We place the main roads (if any) based on the map settings
3: We divide the map up into blocks. The size of the blocks depends on the setting (Ex: Urban, Suburban, etc)
4: We place the locations specified in the mission. These may require placement of buildings or other items. If buildings are placed, the blocks in which they are placed will be zoned (commercial, residential, industrial) to match the type of buildings being placed.
5: We fill in the map with "decor" buildings. They provide cover, hiding places, and also enhance the overall look of the map
6: Secondary roads are added
7: Map decor is added. These are things such as trees, grass, street signs, and other things you expect to see in the setting
At this point, steps 1-5 in the map generation are fully implemented. Step 7 is also partially done, and we will be adding the decor you expect to see along roads soon.
At this point the maps are complete for going to early access. The cosmetic Steps 6 and 7 will be refined during the early access period.
The next update will talk about the progress we are making with AI and dealing with larger numbers of NPCs on the map.
See additional pictures on our blog