Procedurally generating enemies, places, and loot in State of Decay 2

April 16, 2018
Procedurally generating enemies, places, and loot in State of Decay 2
Game Developer logo in a gray background | Game Developer

One of the trickiest challenges of building an open world game is populating it.

Defining the boundaries and laying out terrain is the easy bit — the real work begins when you need to fill all that vast, empty terrain with life and loot and interesting things to do and see.

It’s an issue that Undead Labs found itself grappling with on a large scale with their upcoming open world zombie survival game, State of Decay 2, and fellow devs may appreciate hearing about how the studio tackled it.

With that in mind, Gamasutra reached out to the studio to see how they handled placing gear, materials, and enemies in a way that felt interesting and intentional without having to do all of the grunt work by hand.

The procedures of generation

Loot in State of Decay 2 is distributed through a few different procedural systems, each of which serves its own purpose,” says Brian Giaime, State of Decay 2’s systems designer.

“Containers where loot can be procedurally populated are placed by hand, but no loot drop itself on any location is ‘hand placed’. Every time we generate a map, a variety of items and resources and loot and vehicles are distributed according to this process."

 

"Rather than use pure random odds, we use a ‘deck of cards’ setup, to ensure that, say, out of ten restaurant sites, exactly seven will have one rucksack of food...which helps enormously with long term economy balance."

"Some elements will be the same across multiple instances of the same map; every map guarantees that every Gas Station site has at least one gas can," he continues. "Some elements will be very different. Say for example that across the whole map, we want to drop, say 25 normal melee weapons. These aren’t guaranteed to show up in certain sites, but are instead distributed procedurally across all sites, into containers whitelisted to make sense dropping items of certain implied physical sizes which make sense for them.”

Giaime and his team ensure that while there’s a random element to the procedural population systems, the loot itself is distributed in intelligent ways according to a number of different filters and constraints. One of these filters is determined by the site type that’s being populated. 

“Site type guarantees are used to ensure we match player expectations when they go to loot sites that strongly telegraph certain kinds of loot. Construction sites will always have at least one Rucksack of Materials, and Gas Stations will always have at least one gas can item that can be used to refuel a car. This system allows us to precisely dictate what percentage of sites of a given user-facing type drop items of a certain type. Rather than use pure random odds, we use a ‘deck of cards’ setup, to ensure that, say, out of ten restaurant sites, exactly seven will have one rucksack of food. Which seven will be different every time the map is instantiated, but we can rely on seven rucksacks of food being available to the player on each map, which helps enormously with long term economy balance.”

A secondary system influencing drops involves quotas. Every location may have a quota of weapons, for instance, and then each container with a loot table that contains weapons has a random chance of fulfilling that quota, after which no further weapons will drop at that site. Some of this data is then fed back to players as they explore an environment.

“Between quotas and site type guarantees, we fill in data on the map the player sees for any site they’ve scouted, telling them if there exists any potential to find certain resources there,” Giaime told us. “This lets players self-select what resources to pursue with a reasonable amount of confidence that they’ll find what they seek. Rarely 100%, but high enough that the cost in time, health, items, and danger should feel worthwhile.”

In multiplayer, additional loot is distributed in containers that aren’t openable in single player. In an effort to encourage cooperation over competition, the game only allows the player a lootable object belongs to to open it (after which they can share out its contents if they feel so inclined). The team also focused on trying to equally distribute containers throughout larger structures.

“We try to massage loot distribution into multi-room structures by ensuring the total amount of containers we want to activate are spread somewhat evenly through its rooms, and will try and find the next container we need in another room before checking a room with an active container again.”

The clockwork population systems also play a role in the game’s narrative progression.

“Missions in State of Decay 2 try to tell heavily contextualized stories, and the loot system is called upon to help deliver on this,” Giaime explains. “To do so, when missions need to put an item in a site, we use the same whitelists we’d use to decide if the containers in that site would be able to drop that item - so a baseball bat comes out of large storage and not an end table, for example. On the off chance nothing is appropriate to find the loot you seek, all sites have what’s called a ‘fallback’ container - often a large cardboard box, which we can use to supply an item called for by a specific narrative into any site that lacks a more appropriate container.”

Giving your game teeth

Jason Hail, one of State of Decay 2’s gameplay engineers, chimes in to talk about how enemies were placed in relation to structures and loot.

“We have several systems that contribute to the on-going, ambient zombie population in the world of State of Decay 2,” Hail says. “The largest one of these is the Ambient Population Manager. Not surprisingly for an open world zombie game, this was one of our earliest prototypes when we started working in Unreal Engine 4. It has evolved continuously over the entire development process, keeping flexibility and rapid experimentation as our highest priorities. As such we built it in (or at least exposed to) Unreal’s Blueprint system so we could tweak pretty much any aspect of it within a single editor session. We also leveraged another very powerful tool built into Unreal called the Environment Query System, or EQS.”

EQS is a visual tool that enables designers to built spatial queries employed by the game’s AI.

“For example, if you want to create an NPC’s cover-using behavior, you might build the query as ‘find all spots on the navigation mesh, within 20 meters of my current position, and score the ones the highest that cannot be seen/aimed at from any of my enemy’s point-of-view’," Hall continues. 

"You can then ask EQS to obtain either the best result, a random result from the top percentile, or just an aggregate list of every location that satisfies the query. The system is very performant since out of the box it is capped on how much processing time it uses per tick, so EQS will never tank your frame rate. The key feature of EQS, though, and the one that enables us to iterate quickly is that it all previews from within editor. You can add, remove, or adjust new queries, filters, or the parameters on either and preview the results on-the-fly.”

The Ambient Population Manager is a workhorse that does a tremendous amount of the labor involved in placing zombies and determining where and when special infected will appear to challenge players.

“Like most open world games, State of Decay 2 maintains an active ‘simulation bubble’ around each player,” Hail adds. “Full-fledged zombies don’t exist everywhere in the world at all times, since that would be a waste of resources. Instead, we only spawn zombies as you move into a new unpopulated area, or kill existing zombies in your current location. As you leave the area, we reduce most zombies to a “probability cloud”, for respawning them when you return to the area. Special infected Freaks and hordes of zombies are an exception to this: we remember exactly where they were last seen, so you can come back to that challenging Juggernaut once you’ve found a grenade launcher and are ready to deal with him. To pull this all together, the system needs to evaluate what you’re doing (walking, driving, etc), evaluate a huge number of locations in the world to find the best spawn points for zombies based on that context, and finally sunset zombies that are no longer within your simulation bubble. All of this work is orchestrated by the Ambient Population Manager.”

 

"Full-fledged zombies don’t exist everywhere in the world at all times, since that would be a waste of resources. Instead, we only spawn zombies as you move into a new unpopulated area, or kill existing zombies in your current location. As you leave the area, we reduce most zombies to a 'probability cloud.'"

The population manager relies on EQS queries to do its work. Early in development, Hail and the team used two primary queries, one when the player was on foot and one when the player was in a vehicle. Further queries were then layered in for more specific scenarios, like when a player was exploring a dangerous building on foot. Queries were customized to suit the context: in buildings, the priority was spawning zombies outside of the player’s view, for instance.

“It also is

Tags:

No tags.

JikGuard.com, a high-tech security service provider focusing on game protection and anti-cheat, is committed to helping game companies solve the problem of cheats and hacks, and providing deeply integrated encryption protection solutions for games.

Explore Features>>