Goal Selection & Planning

All artificial intelligence in OC is driven by a system that’s designed to make its NPCs behave in complex, interesting, and fun ways. In simplest terms, all entities select goals and devise plans to achieve results that they consider desirable. However, it’s the combination of this simple, underlying framework and the synergistic effects of many AIrelated subsystems that helps it achieve results beyond normal behavior scripting.

Mining_Plan

Summary

  • All NPCs in OC act in pursuit of goals.
  • Goals are expressed as conditions in the world that can be satisfied.
  • NPCs choose which goal to pursue by evaluating many factors and quantifying the benefit of each goal they can achieve.
    • If you’ve ever used a weighted pros and con’s chart to make a decision in real life, then you understand the general methodology OC’s NPCs employ. From a universe of goals they can pursue, they then choose whatever goal will yield the most beneficial outcome.
  • Chosen goals are achieved by devising and executing plans.
  • Plans are generated by means of search through a problem space. The sections below explain this in more detail.
  • Each plan consists of a sequence of actions.
  • Each action can cause a change that will satisfy some sort of condition. Any plan to achieve a goal has an end result that achieves the goal’s ultimate condition.
  • Each action that an NPC can undertake can have zero or more prerequisites. These are conditions that must be satisfied before the action can be executed.
  • The first action in a plan can be executed in the world’s current state, and each action yields a result (a changed condition) that enables later actions and ultimately achieves the goal.

That’s the general overview of how NPCs work in OC. Of course, this is a very high level overview and doesn’t cover details of the system, but the points above govern everything that every NPC in OC does.

Goal Selection

Everything an NPC does in OC is in pursuit of some goal, so goal selection is the start of the AI’s process. Each NPC’s AI is equipped with a goal selector, and the goal selector runs through a process that’s specific to the NPC in order to select its next goal. For example, while both creatures and humans have goal selectors, they behave differently and consider very different factors in their goal selection process. Wild creatures are driven entirely by primal needs – hunger, thirst, and the need to reproduce. For most creatures, those are the only objectives they can pursue. Which objective they select depends on their internal state. If the creature is on the verge of starvation, it will prioritize food acquisition over everything else. If it’s well fed, has had plenty to drink, has grown to maturity, and is in a healthy state, it’ll seek out a partner for reproduction.

Humans can do a great deal many more things than creatures, so a human’s universe of available actions is far more expansive than that of a creature. Humans can brew beverages. Humans can operate mining equipment. Humans can maintain nuclear reactors. Furthermore, humans aren’t slaves to primal needs. Hunger, thirst, and the need for sleep are very important to human goal selection, but these needs can be suppressed under many circumstances. As such, their goal selection process is more involved than that of creatures.

Human goal selection is driven by many factors, but one of the chief among these is the set of orders you’ve issued to your expedition. Humans will evaluate these orders that are applicable to them, based on their professions and enabled activities, and they’ll normally act in ways that pursue them. Extreme hunger, thirst, exhaustion, loneliness, or depression can cause humans to ignore or subvert your orders, but NPCs with non-extreme personalities that are reasonably cared for will try to satisfy your wishes during their work shifts.

During leisure shifts, the human goal selection process is much less constrained, and will pick out objectives that the NPC deems desirable, independent of any orders. NPCs will relax, eat, sleep, drink, pursue social relationships, and do other things that generally make them feel happy. It’s important to maintain a good balance of work and leisure time for your NPCs, as insufficient leisure time can result in health problems, decreased happiness, and general discontent, which can lead to unruly behavior.

World Conditions

Now that we’ve got a general idea about goal selection, it’s important to understand what goals are. Goals are expressed as conditional states that are to be achieved in the world. A goal is some condition that, when satisfied, signifies that the goal has been achieved.

Let’s consider a simple example, using the screenshot above. Zem Lub’s goal is to mine a specified area. An order was issued to mine a location, and Zeb is pursuing that order. The notion of “mining a specified area” is expressed as a condition that the world needs to be in. Zeb knows where he’s supposed to mine. That’s a part of the order he’s pursuing.

Mining_Order1

Zeb knows that when a location has been mined, its content has been removed, and the location is empty. He also knows that, right now, that is not the case. The location is filled with dirt, meaning that his goal’s end state is not satisfied. He needs to do something to change the state of the world from how it is now (with dirt at coordinate 1175, 137, 88) to how it should be (with dirt removed from 1175, 137, 88).

Actions

Action! That is precisely what Zeb needs to change the state of the world, and actions represent the things that NPCs in OC can do to cause change, thereby accomplishing goals. A good way to think of an action is a single step that an NPC can take to accomplish something. NPCs all know (most of) the results of actions, which are described in terms of the conditions they change. When a miner takes a pneumatic drill to a location of rock, the miner knows that the action (the drilling) will result in the clearing of the rock (an end state).

Zeb knows that to clear out the dirt at the designated location, he’s going to have to undertake an action that yields the desired state. Just like in real life, there are often many different ways to accomplish the same goal. Many different sequences of actions can yield the same end result, and planning is needed to decide which sequence of actions is best.

Planning

At this point, Zeb knows that he has to clear dirt from a location. Zeb is also aware of the universe of actions that he can take. He now needs to put together a string of actions that will take the world from how it is now to how it needs to be.

OC’s planning algorithm is used to decide which actions to ultimately take. Zeb knows that there are multiple different actions that will accomplish his end goal. One of these is to get down on the ground and to dig out all the dirt with his hands. Another action that’ll clear the dirt is to dig out the location with a digging tool, like a shovel. How does Zeb decide which approach is best?

To start in this decision making process, Zeb understands that some actions have prerequisite conditions of their own that have to be satisfied before they can be undertaken. Before he can dig with a shovel, he needs to have a shovel in his possession. In this case, Zeb does not have the shovel, so the prerequisite state for digging with a shovel is unsatisfied. He knows that getting a shovel will satisfy this prerequisite, and that the expedition has an unused shovel available in one of its stockpiles. To get the shovel from the stockpile, he’s got to walk over there, acquire the shovel, walk to the designated location, and then dig. This sequence of actions, satisfying ordered prerequisites that ultimately lead to the end goal, is what constitutes a plan.

So, now Zeb has two possible plans that will yield the desired result. One is to walk over to the site, get down on the ground, and painstakingly dig out the dirt with his bare hands. The other is to head to a stockpile, grab a shovel, go to the site, and dig using the shovel. The key to the planning process is that algorithms generate universally comparable weights for each action. Zeb knows that digging out the dirt by hand will take forever, while grabbing a shovel from a nearby stockpile is quick and easy. Then, digging with the shovel is a breeze compared to digging by hand.

The chosen plan is the one with actions that have the least cumulative cost. The system’s strength is based on its ability to judge the cost of actions, and each action has an algorithm for doing so. It’s a bit like real life. If you’ve got to move some dirt in your back yard, and you don’t have a shovel in your basement, how do you decide what to do? Well, getting a shovel is going to involve a drive to your hardware store and shelling out $20. But digging out dirt by hand is miserable. Is it just a small amount of dirt that can easily be dug? Is the hardware store located an hour away? Do you suffer from a personality disorder that makes you shy away from public places, like the hardware store? All these things play into how a person weighs their options, and OC’s underlying mechanisms are fundamentally similar.

Which approach is the “right” one? It depends on how you define “right”, and different people can make different choices in the same situations. The same holds true in OC.

Execution

Once an NPC has formulated a plan that they’ve deemed best, they’ll then execute its steps, moving the world from state to state until the end goal is achieved. The NPC will then select their next goal, based on the world’s new states, and they’ll repeat the process until they’re dead. That’s the life of an NPC in OC: picking out goals, working toward them, accomplishing them, and then picking out new ones.

Environmental Awareness & Reactions

One thing to bear in mind is that NPCs aren’t guaranteed to stick to a plan, just because they thought it the best thing to do at one point in time. The world is constantly changing. Things are happening everywhere, and as things happen, NPCs sense them. If, in the course of walking to the stockpile to grab the shovel, Zeb sees a large, ravenous, predatory animal start running toward him, he’s going to suddenly care a lot less about shovels and dirt. NPCs are constantly reassessing their situations and reacting to changing conditions as necessary. As such, plans shouldn’t be thought of as static courses of action that an NPC will undertake, but more along the lines of dynamic guidelines that represent a best figuring from a certain point in time.

Universality of System Fundamentals

Hunting_Frostbull

A frostbull’s (a carnivorous creature) plan for satisfying its hunger.

Finally, while the example covered most thoroughly in this article focuses on a human carrying out orders, bear in mind that the fundamental framework for AI in OC is universal. It applies to following orders, scavenging for food, finding a girlfriend, or committing arson. The screenshot above shows a hungry frostbull setting out to satisfy its hunger, and the notions of goals, actions, and plans apply to every actor, human or other, in OC.

Posted in NPCs