World Design – Prefabs

Posted On 2 Oct, 2015

We originally promised a game that takes place in an infinite procedural world yet consists of lots of hand-mapped areas. Today I have successfully tested the system that will make that possible, read more to find out how it’s going to work.

Whats in a universe

There are no borders in the universe of Zero Falls aside from the boundary between your current sector and the next one. Everywhere you look in our infinite galaxy you will find stars, planets, asteroids, and empty space, and that’s about it. That’s the problem with procedurally generated infinite worlds, you often end up with an infinite scrolling backdrop of the same stuff over and over.

So why are they so popular then? We’re seeing a lot of games these days with infinite procedural universes, so there must be something to it. Well it’s because the prospect of infinity is so compelling, almost as compelling as the idea of not making any level files. Indeed the often overlooked aspect of designs which focus on procedural generation is that you don’t create any actual maps yourself, usually because you can’t. That’s because when you have a procedural algorithm that determines the shape of your world, it is often difficult if not impossible to take part of that world and sculpt it by hand, the two systems aren’t easily made compatible. Game designers often see this as a positive byproduct, because mapping every level by hand is a difficult and time consuming task.

Since I apparently don’t have any interest in doing things that are easy, I’ve decided to build a system that allows manual mapping inside an infinite procedural universe.

The design goals

In Zero Falls, and in any subsequent mods made for the Wayward Terran Frontier engine by the community we want the engine to handle a continuous blend from 100% procedural to 100% hand made at every level of detail and every order of scale across the entire game universe. A lofty goal. When perfecting the single player experience of Zero Falls, we will be using and improving this system, so effectively our goal is to make Zero Falls as if it were a mod for the Wayward Terran Frontier engine and as much as we can we are going to be trying to make our content using the same tools that will eventually be available to modders.

Our goal is to make every sector into an open canvas for anything to be created while retaining the convenience of procedural-by-default generation. We don’t want mod makers to worry about filling empty space, or how much texture memory they use, or how optimized their generation algorithms are, or comparability with other mods. We want them to be able to just create whatever they can imagine and have it show up in the world. In other words the universe will have infinite stuff in it already, and you can replace as much or as little of that as you like. Our hope is that different mods, campaigns, and stories can all coexist in the same universe by simply taking advantage of how huge it is. Just pick a spot in the galaxy and plop down your custom content.

Here’s what that would look like on each order of scale:

  • World map – You should have the ability to choose a sector of space and completely replace all of the generated stars, planets, belts, etc. with your own layout. It should be as easy as drawing an image. You should be able to decide (on a sector by sector basis) which are procedural and which are hand placed as easily as drawing a map of your custom sectors and saving it in the data directory.
  • Sector backdrops – You should have the ability to control the entire look by tweaking some or all of the built in variables for light settings, backdrop images, backdrop objects, parallax layers, planet generation, etc. or you can write your own shaders and provide your own art for each backdrop on a sector by sector basis by creating a sector extension and applying it to not only your own hand-placed world map objects but also to existing world map objects. Alternately you can just leave the default backdrops and focus on modifying other world elements.
  • Sector layouts – You will be able to tell sectors how and where to spawn game objects by either tweaking parameters of existing algorithms based on procedural generation, making your own algorithms based on procedural generation, or simply ignoring procedural generation to spawn exactly what you want where you want it. You will be able to spawn built in objects or create your own, or blend together new combinations of either.
  • Random vs mapped objects – you should be able to manually place every object or have every object be distributed for you based on noise and random sampling. Now with prefabs you have the option of using random noise sampling to place hand-mapped areas. Hand make elaborate super structures or dungeons or interesting layouts and then let the world generation algorithms distribute your creations randomly across the entire universe.
  • Game objects – putting a new type of asteroid or stellar object into either the foreground or background parallax layers should be as easy as converting your texture file into an xnb using the monogame content tool. The engine will handle texture loading and caching, per-pixel collision, even procedural interior mapping for asteroids that can be drilled into. When you can replace existing asteroids using stuff you drew in MS paint the galaxy really will be your canvas.
  • AI behavior – You should be able to embed cues into your sector generation that tells the AI how to interact with your map. What good is a space dungeon that doesn’t have bad guy spawnpoints in it?
  • Modules? – In the far future I may even make a mod API for the modules that make up ships. Since ships are just the sum of their modules you would be able to determine pretty much every aspect of gameplay though extensions. I’m not promising this will happen since it would be the hardest system to design by far, but it would certainly be neat.

The implementation

Almost all of the above is already possible in the existing extensions system. On loading, the game reads the data directory looking for map modifications which tells it what sectors to overwrite with what stuff. Each sector is simply given a unique value, (hint: it is a color) and then a series of extensions can be mapped to each color. So if you want a scary red sector with a scary red backdrop and scary red asteroids, you make your extension and map it to a color (like red) and draw it wherever you like across the galaxy. The result is those sectors will call up your custom extension any time the player goes into one of those red painted sectors, but sectors without any color will be generated by the procedural algorithm.

Today one of the final (and biggest) pieces came into place as I tested a prefab system which includes a custom prefab editor. I dragged some asteroid images into a folder that I wanted to use as brushes and using drag drop placement in the prefab editor I made myself a fancy arrangement in the shape of a beloved internet meme. I saved my work as a prefab file, and with a few lines of extension code I used the default terrain generation extension to randomly spawn my prefab across space. A mod maker would have to modify the following lines of code in their backdrop extension.

- Prefab myPrefab = new prefab(<name of file I created> <name of texture batch> <reference to texture batch>)
- SectorGenerator.addPrefab(myPrefab);
- SectorGenerator.minPrefabs = 5;
- SectorGenerator.maxPrefabs = 20;

To translate the above: I create a prefab object and tell it where to find the file I saved. I also tell it which set of textures will be used to render that file. These texture batches are already used by the backdrops so in my example I actually just passed the default texture batch that was already used by the existing extension. Note that in this case SectorGenerator is a built in class used by existing backdrops to create asteroid fields, so essentially I am just tweaking the parameters of a built in thing that mod makers will have access to. Then I tell the extension to place between 5 and 20 prefabs, and I give it my prefab as the only prefab to pick from when placing prefabs.

Here is the result.

results

Note that I used the same asteroids as would spawn in this sector naturally to make my prefab, but you can use any set of assets that you like including custom assets that aren’t part of the core game. The game builds a fancy manifest of the textures necessary to render everything in the sector so they can be automatically loaded as the player approaches, and automatically unloaded when the player leaves. Thus even with a very high density system full of large custom assets there should never be a loading screen, and nearly all of the machine’s memory can be dedicated to just the sector you are currently in.

This prefab system is a game-changer in terms of content creation. I have literally just built the map editor for the Wayward Terran Frontier engine, and it’s pretty easy to use. Maybe you aren’t too concerned about making mods yourself, but this is still exciting news because this is the tool we are going to be using to fill the game world with content and make space less empty and boring. As I seem to say with every big feature added to the game engine: Now we can add better content to the game, and we can add it faster and easier, so future patches should be more exciting. Yay!

Also we are certainly going to be using this system to include more content in the next patch, so expect us to be working on it for a bit (the next patch). We want the next patch to be a big improvement in overall content and gameplay depth. Prefabs was merely a prerequisite.

Note that all talk of mod API and modding tools such as map editors is speculative. We aren’t releasing these tools yet because they change every single day and are as yet very incomplete. I do enjoy ranting about what I’m working on though, and I’m willing to discuss potential future features with anyone who might be interested.