Thursday, January 28, 2016

Programmable NPCs

I love programming games. In theory.

In practice, programming games are too esoteric, too separated from anything that feels meaty and fun. In the real world, the "programming" games I love run without any programming at all, and I wedge programming in for extra fun. Kerbal, Space Engineers, and so on: all work fine with no complex staging or programming.

I've been analyzing the concept. Thinking a lot. I think what we need is a way to allow the player to program easily and freely, but more than that, to smoothly slide in and out of non-programming, full-programming, and simple scripting elements.

What do I mean?

Imagine a game like Minecraft or Medieval Engineers, except that you have an unlimited number of NPCs to help you out. The idea is that they can help you build, operate, and maintain your world. You can create villages and so on and so forth. But the implementation is more open-ended: these aren't people with set jobs. They're state machines.

There are a few ways to let players program NPCs. Since AI is complex and depends on wrangling thousands of inputs, most of those methods revolve around picking big chunks of functionality. This NPC is a guard. This NPC is a farmer. This NPC lives here. This NPC lives there.

Let's turn that around a bit. The big difficulty is the huge number of inputs. NPCs need to analyze the terrain, their resources, threats and opportunities, their tiered goals, pre-established schedules, the weather, their equipment, alert/damage states... programming for all these things is why AI is normally supplied by the dev rather than given to the player to fuss with.

But what if we stop thinking of an NPC as an independent agent? What if the NPC is considered as part of the player, augmenting the player's capabilities?

Overlord was a good example of this, allowing you to point and send off your minions in a very easy, fluid way. However, those NPCs are a bit too simplistic and the gameplay was not constructive. Is it possible to do something like this, but with radically more complex, programmable NPCs?

One challenge is how the player interacts with the world. For example, in Minecraft you can build a house, it's very constructive. But building the house is very low-constraint: you rapidly plonk down voxels in any configuration you want, and you can even have a physically impossible floating house without difficulty. Having assistants wouldn't help in this situation, because there's not really any pattern for the NPCs to work on. They can't tell what you intend to build based on what you have built so far, so they can't help.

We could exchange the player's actions and require NPCs to execute them. For example, the player just puts down virtual blueprint voxels and the NPCs have to do the work. But this isn't any better at making complex, programmable NPCs, it just makes the game slower and the player unable to directly affect the world, both of which are bad.

Instead, what if we designed our creative systems specifically to have patterns? Then, when the player starts to create, the NPCs would be able to predict what the player is doing and build as well.

For example, if you build a road, you probably want to build another segment of road one road-segment along the path.

The road example is an easy, clear example. Let's say you dress an NPC up in road-worker costume and link them to you. Now they follow you and read your activities as their input. When you build a section of road, they read your vector and the position of the road, and move one unit further in that direction and build another segment.

Now you have augmented your power. When you build a road, two road segments get built.

You can extend this. What if you link another 50 road workers to yourself? Well... they still only try to build one block along, so you still only have two blocks of road per one block you build.

One way to fix this is to have them move N blocks ahead instead of 1, and then specify each individually. However, a more interesting option is to simply daisy-chain. The NPC's activities are also readable as inputs, so you make the second worker link to the first worker instead of you. And the third worker links to the second, and so on. Now, when you build a road segment, each worker moves along in a chain of single steps, and you can break the chain by simply unlinking the Nth worker.

This works great, especially since there's an obvious physical representation of who is linked to who: a line. The workers form a line. All linked to you, they cluster in your wake as a chaotic mishmash. But daisy-chained, they stretch behind you like a conga line.

Of course, this is really wasteful. In reality you only need one worker, as long as you're patient.

See, like any Turing machine, our workers have an input stack - a "tape" to read. When we linked them to us, we simply put ourselves in the first spot on that tape. We can add themselves as additional entries on the tape, and tweak the road-builder state to move to the next input on the tape.

This means that we build a road segment. This triggers them to build a road segment and also move their input tape, making themselves their own input. Since they just built a road, this triggers them to build a road and move their input tape... it's not an infinite loop because the tape eventually wraps back around to using us as an input.

This works, but the worker will have to complete each segment before moving on to the next, which might be too slow for your taste. It's already a relatively interesting space, with tradeoffs built right in. We're touching on the concept of parallel processing, Turing machines, IO...

Roads are an easy example, easy to use as a demonstration. But they are fundamentally pretty straightforward. While you might like a wider road, or a road that curves, it's pretty "flat" and there's no real constraints on it.

So let's talk about walls.

Rather than the physics-free voxel walls of Minecraft, what if our walls have physical presence, and roofing is actually a challenge? Sort of like Medieval Engineers?

If we we want to build a three-high wall, it's not just plonk-plonk-plonk. We need to have the resources lying around nearby. We need to build a scaffold so we can reach the upper wall areas. We need to lift the resources up the scaffold. The player can do these steps on their own, manually, but it makes sense to use NPCs to help.

For example, you build a wall, and then NPCs are set up to build a scaffold, lift resources up the scaffold, build a wall, build another scaffold, lift resources... you can do this with daisy-chaining, input cycling, or a combination of the two.

To use only one worker, you would equip the worker with gear/clothes representing scaffold-building, wall-building, and resource-toting. You would make yourself the first notch in his input tape, then himself. The order of the states is determined by the order you equip the gear, so the last one on would be the scaffold-building equipment - say, a hat. He sees you build a wall, builds a scaffold - then moves the input tape (to target himself) and switches to the next state - hauling. He saw himself build a scaffold, so he now hauls materials and switches to the next state - wall-building. He saw himself haul materials, so he builds a wall, then loops back to the first state - scaffold-building. He saw himself build a wall, so he builds a scaffold, etc, etc.

This kind of dependency simply makes the world more annoying rather than more complex, but it's a good example of the concept. In reality, the constraints I would want to introduce would be more than mindless busywork.

For example, if you want to build a 20m-high wall, the wall material will tip over under its own weight. So you have to shore it up. You could simply build it thicker, but a clever designer will instead build it banded - some areas have large windows to lighten the wall, and others have flying buttresses and thicker columns. How about supporting the tall wall with scaffolding, knowing it will fall over when the scaffolding is removed... and then putting in crossbeams before removing the scaffolding?

Multiphase and open-pattern construction are powerful features. Not only do they make programming the NPCs more interesting, they also make the world more interesting to inhabit. A skilled player will come up with interesting ways to build taller, wider, deeper, more interesting structures. Another skilled player will come up with a way to build hundreds of miles of structure, although perhaps not as impressive per meter. Yet another player will build something that isn't technically challenging, but feels real and inhabited because the NPCs are programmed to live life convincingly instead of build walls convincingly.

I've left out some details. For example, location flags/vectors are pretty important, and I didn't mention them at all. I didn't talk about how to build or edit gear to perfectly suit your needs. I didn't talk about the idea of maybe building ships, or setting it in space. I didn't talk about harvesting and transporting materials.

But I think I talked about enough. What do you think?

I think the concreteness of allowing the player to physically build things makes the game easy to get into. Combined with easy basic state editing, the player can ease into the idea of telling a wall builder or stack of road workers to follow along and help them. The more complex powers of NPCs with multiple states, state tweaking, recursive NPCs - those can be left for the people who actually want to do them.

Moreover, this makes for a truly excellent semi-shared world. Import a wall crew from your friend Alice, she's programmed them to build that 80m-high megawall wherever you plant a blue flag. Import a city from your buddy Barry. Import a ship - no, a whole shipping lane - from your half-cousin Chip. It can be done automatically, manually, or half-automatically (for example, an in-world "for hire" bulletin board).

That's what I envision.

Monday, January 25, 2016

Construction Genre

So, I just backed another "survival construction" game on Kickstarter. "Survive a crash landing on an alien planet and build-"

Beautiful game. BAD GENRE.

Since Minecraft came out, the "survival construction" genre has been booming. Unfortunately, it's a terrible genre, since it's at war with itself. Minecraft's success is not a sign that it is well-designed, it's just a sign that it had great timing and positioning.

Here's the heart of the problem: "survival" is a specific and shallow objective. Games which are about surviving require the game devs to constantly introduce new threats to you. Most games are about surviving, and the game devs spend a huge amount of effort on introducing those threats. That's the basic idea of "levels", after all.

Open-ended construction is fundamentally a player-driven kind of play. Trying to offer well-paced survival challenges to a player that is doing things at their own pace is very difficult, especially since so much of the player's resources will revolve around the specific things they've built and the specific way they've built them.

For example, in Minecraft, a player might build a wonderful base that is immune to creepers, but when you introduce those block-grabbing Endermen, it's a crapshoot. Some players, especially those that know what's coming, will have bases that don't get affected much at all. But other players, while their base is 100% proof against spiders and creepers, will collapse if even a few blocks are removed - torches go out, gaps for spiders and creepers are introduced...

This is nearly impossible to calibrate. Games where survival is key keep the calibration easy by not allowing the player to have different resources than the devs expect. You have access to X, Y, and Z guns. You have health, your speed is exactly this fast, you can see exactly this far. Because the devs know what you've got, they can present you with challenges. When the players build everything as they like, the devs have no idea what you've got!

Obviously, you can try to limit the player. But that's the opposite of what I would recommend. I like giving the player more freedom.

Letting the player construct whatever they want is really the heart of the construction genre. I don't mean constraint-free, I just mean letting the player create in the direction they want. Every player will approach the situation differently, and that's great.

But how do you create a compelling framework for this "construction" genre?

If you ask a normal dev, you'd hear two basic ideas. 1) Tiered resources: drive the player to find more useful resources in more dangerous places. 2) Phased challenges: introduce enemies, weather, and events on a schedule such that the player has to react to them.

These are good starts, but they're inherently "survivally". Let's look at a different way of thinking about it: optional constraints and challenges.

Kerbal is a good example of this. Putting aside the weird career mode they bunged in recently, there's no in-universe reason to go to any particular planet. But the fact that the planets exist is enough to make you want to go. Moreover, you can plan any kind of mission to the planet that you want, with any number of stages.

You don't simply decide to "go to Juul". You decide what kind of ship will go, manned or unmanned, what science stuff to include, whether it's a round trip or one way, what kind of landings you plan to try, whether to set up a permanent station in the area, whether to use a Kerbal-orbiting station to construct the ship and refuel before setting out, whether you want to take it slow or rush to Juul, whether you want to slingshot off the Mun or off of another planet on the way to Juul... and if you start including mods, the number of options goes up dramatically. How about an airship permanently stationed in Juul's atmosphere?

This freedom allows people to construct as they please. While it may not appeal to all players, I don't think the construction genre needs to appeal to everyone any more than the first person shooter genre does.

The way Kerbal is constructed is very clever, but there are a lot of things to learn from other games. For example, Space Engineers offers an options menu where every constraint is toggleable and tweakable. This includes things like inventory size, sure, but also things like whether there are days and how long they are. This complexity allows players to develop for radically different environments without actually having radically different environments in the game world. It also allows players to change those options during play, allowing them to develop in one set of constraints, then switch over to test or "play out" in another set of constraints, something made easier by blueprints which can be pasted into or built in other worlds.

This is a powerful concept: you can create a ship in "creative mode" with no enemies or materials requirements, then switch over to a hostile, limited world to test your ship. You can then copy it and go into a friend's server and paste it in and have a battle royale or a work together as a team...

This isn't a completed implementation. It's not very fluid, switching modes or transferring constructed content is a huge pain, and the multiplayer functionality is so bad it's actually hilarious. But it's easy to see the beginnings of a genre there.

And it's not a "survival construction" genre where you crash on a planet and have to build your own base to survive. That's just one vaguely-implemented scenario. The power of the game comes from the unfettered construction the player is allowed. Players will accept challenges and constraints just for the fun of it, and they'll come up with objectives and complex multi-phase missions that you never would have thought of and certainly couldn't organize.

So, that's my thought. If we're going to do construction games, we should have a flexible way to accept a variety of constraints and challenges, and allow players to pick and choose what they want to approach in what ways. A big part of this is making it easy to switch constraints and challenges midstream, since many players will want to build and test and iterate instead of just grinding it out in a survival challenge.

You don't need to make the game about survival. It will naturally become about survival if and when the players want it to. It might also be about building cathedrals, or putting together a fleet for a dozen players to work together.

There's also no limit to the kinds of challenges and constraints you can offer. It's popular to just use the basic construction ideas - some facility-wide resources, some physical constraints, some topological challenges, and realtime combat.

But you can define your game with a lot more creativity if you offer a wider range right up front.

For example, what about if you could "weather" your facilities for N years, turning them into ruins or seeing them adapted by NPCs? What if you have missions other than fighting, such as transport, medical, research - if you make them as complex to manage in real-time as combat is, you can have compelling noncombat challenges. How about simulating the people inside the facility?

Any one of these additional "modes" would make your game unique on the marketplace today, but in ten years, I expect they'll all be considered standards in the genre.

That's what I think, anyway.

Tuesday, January 19, 2016

Game Systems and Reboots

Any of you ever play Rifts?

Now there was a tabletop game that creaked and clanged. A byzantine rule set full of weird exceptions, nonexistent balancing, and an endless parade of expensive expansion books.

Was it a bad game? Well...

Let's compare it to D&D. D&D underwent a series of reboots over the years.

While it's a bit uneven, D&D reboots about every five years, invalidating all the books of the previous version. This is a serious move for the creators, since it means all the expansion books to date are now worthless. Expansion books are a huge part of the income from that IP - core books are just the start.

But it looks like around five years after the core books come out, people stop caring to buy expansion books, so it's time to roll out some new core books and start again.

Each iteration of D&D uses new rules, and all the elements of the game (monsters, settings, treasure, classes, skills, etc) are rebalanced and recreated anew. While people have versions they prefer, by and large each version is cleaner than the last version, if just because it hasn't had time to accumulate much cruft.

Rifts didn't reboot. At all. For 25 years, Rifts has kept the same core rules, skills, classes, etc.

Why?

Because Palladium Books likes expansions. The idea of invalidating expansions is just not in their business plan, especially since their expansions are "half core" - nearly every Rifts setting book adds core features to the game's rule set. If you create a tattooed man or a blind warrior maiden or werewolf or Glitterboy pilot, you have a character with radically different rules from most other characters. If those expansions are invalidated, then those concepts don't even exist any more. It's not like invalidating an "elves in detail" book - if you do that, there are still elves.

This is not just speculation - Palladium Books insisted that EVERY expansion book from all settings was theoretically compatible with every system. So you could play a Teenage Mutant Ninja Turtle in Robotech.

This approach made reboots nearly impossible, and power creep inevitable. The best character to play in Rifts was whoever was in the most recent expansion book. The rules grew more cryptic and arcane as exceptions became the norm.

This is an interesting situation to compare. D&D, with its frequent reboots that recentralize and condense vs Rifts, with its infinite expansions, the only new versions being to rerelease the core book with some important expanded content stitched in. Comparing D&D 5e to Rifts is really revealing.

Now, the reason I bring it up is actually a bit different than you might expect.

See, each Rifts expansion book should have just been its own game.

The problem with tabletop publishing at the time is that people played games by having a group of dedicated nerds sit at the same table for years. If you played Rifts, you kept playing Rifts more or less forever. If it was D&D, you played D&D forever. You probably didn't even switch editions!

My opinion was always the opposite. Games should have an arc. They should have a finish. Whether it takes one session or twenty, there is a trajectory and the end is always drawing closer.

If you do this for a while, you notice that the rules and extraneous content make a huge difference. A game can be dramatically weakened by using a rule set that doesn't highlight the core draw of the game. A game can also be weakened if there's random content stuffed in that draws attention away from the core of the game.

Now, if you are playing in the way the old publishers decided everyone was, maybe that's not a big deal. You're attached to the characters and setting, rather than to the game or the core draw.

But if you play games that have an end, you quickly start to notice these things. And when someone says "hey, want to play this d20 game?" You find yourself shaking your head.

"D20 doesn't have much to say any more," you reply, and they stare at you blankly.