Tuesday, September 6, 2011

Terraria's spawn design

Lately I've been getting back into Terraria. I'd already played it when it was first released on steam, got hellstone armor, made herb farms, etc. So I started all over again, new character, new world! Such a fun game.

Something in the game that I think is really nifty is that it all seems to be driven by the grass. :o Or if there's no grass, by what type of rock is on the screen. In areas with normal grass, you get slimes. In areas with jungle grass, you get jungle music and hornets. In areas with corrupted grass, you get corruption music and eaters of the dead. The nifty part of it is that it's the grass/rock that drives the areas, not the areas that cause the grass. I could easily imagine a design where you have a jungle area and when plants grow in the jungle they're most likely to be jungle plants. But instead, plants just grow, and where the jungle grass grows is what defines the jungle area. That's awesome. If I want to, I can make my own jungle area, by laying down a lot of mud and planting jungle grass.

I'd love to see that approach more commonly used in other games. You don't have to define the world, you just sort of let it become. Like I've been playing fallout new vegas. There's a random house in the first town. Some game designer when through that house, carefully placing all the items in it, crafting the house to provide exactly the experience they want, laying out all the trash items so they make sense. There's much to say about that approach that's good. It does give you a crafted world, that probably is more immersive. But what a huge cost, to spend all this time on a random house that many players won't even bother to enter! And because it is such a cost, there's only like 3 houses in the whole town. So the town population has to be like 12 people total. Which is boring. And what's in each house for my playthrough is the same that everyone else got in their playthroughs. Go to goodsprings house 1 to get a 9mm pistol on the third shelf to right of the door.

What if a developer never had to actually go into a house? Suppose we say a house is either wealthy, normal, or poor, and then associate it with one of say 10 factions. Every house needs to have a food place, a sleeping place, and a bathroom. So you've got 4 walls. Roll a random number based on the house's wealth to find out if each wall will expand into another room, where each expand eats into the overall wealth rating, repeat until you have your house size. Now divide your food/sleep/bath requirements into however many rooms were generated, perhaps with some modifier to make them avoid overlapping when possible. Adjust the size of each room for the number of functions it's covering. Now place objects against each wall of each room, where we're choosing randomly from among all those objects in that wealth band, room function, and faction. So a bedroom has like a 90% chance to spawn a bed if there isn't one already, then an even chance to spawn some number of desks, tables, chests, wardrobes, etc. A food room has a very high chance of spawning a fridge, then an oven, then a dining set, then a counter, etc. Now for each spawned object, fill that object with random items that total up to the wealth rating of the house. A table gains a set of plates and silverware. A shelf gains books or some random items. All that.

Now, instead of an game designer needing to place 5k objects in perhaps 300 houses, the game designer can say he wants 10 low wealth, NCR houses, 15 medium wealth scavenger houses, etc, place them in the world and not only will they all fill themselves, but it'll be different on each playthrough. You'll actually want to explore and find interesting stuff. As long as you have enough art assets and a decently complex room generator/filler, you could easily have 10-20k houses with hundreds of thousands of objects.

Maybe there are other issues besides development time that I'm not seeing. Perhaps storing all that info would be crazy, but I could imagine a house's contents not generating until you actually step into that house. Ah well. :o

No comments:

Post a Comment