Have you ever wondered how creatures think in video games? Why did this orc decided to attack my warrior, while the other one decided to just hide behind cover? If you have, you came to the right place as I will be shedding some light on what sort of dark thoughts drive the AI of our vicious creatures.
When designing the AI system for Solasta, we wanted to make sure that it would best fit a set of objectives that crystallized what's important for us:
- The AI must be able to choose from a large variety of activities. SRD5 ruleset is quite expansive, and creatures can have a plethora of actions available to them at any given turn. Attacking, casting spells, getting to cover, dashing, dodging, disengaging, shoving are some examples.
- The AI must be able to evaluate its environment properly. The verticality of our levels, the importance of light and covers must all be considered thoroughly when making decisions.
- The AI must be easy to create and modify. We should not have to alter the code every time we want to tweak some creature’s behavior.
- The AI system must be usable in both turn-based combat and real-time exploration. Maintaining two separate systems should be avoided wherever possible.
- The AI must be adaptable to different creatures' behaviors. Intelligent creatures should not behave the same as creatures that are more feral and sensitive to light for instance.
Making good choices in life is important, such as avoiding to get on the wizard's nerves.
All those objectives made it clear that we would use a variant of Utility AI. Utility AIs are very popular in tactical RPGs, 4Xs, Grand Strategy games where large amounts of possibilities are offered to the agents.
Basically, what this system does is giving creatures a set of decisions to evaluate. Each decision will be scored independently following a set of designed rules. From these scores the AI will choose which decision best fits its current situation. The AI will then repeat that process until it runs out of options or until it decides that ending its turn is the best decision.
But let’s skip the theory, shall we? Let me show you what it means with a simplified example.
Do AI Orcs dream of AI adventurers?
Let’s say we have a very young and inexperienced orc that we’ll call Bob from now on. What decisions could Bob be faced with during battle? Being the newbie of the group, Bob is very eager to prove himself.
First things first, can Bob make use of his axe right now? If so, which foe would be the best target? Is said foe a real threat for Bob? Bob sure doesn't want to be made fun of for attacking the weak ones after all.
What about moving? Bob can move to all those places - how does he choose the best one? Being an aggressive fellow, Bob wants to prioritize locations where Bob can HIT PEOPLE IN THE FACE. And as stated earlier, preferably someone that is a match for his brute strength. Not only that, but Bob wants to show his valor - the more foes around, the happier Bob will be. Now Bob, some would tell you that it's dangerous and not very tactically sound - but you do you buddy.
As a last resort, Bob could make a ranged attack - he does have a javelin at hand after all. But that could be seen as cowardly, so Bob only does that if he can't reach anyone. And Bob never was that good at throwing javelins, so Bob will go for someone that's easy to hit instead of a target cowering being cover.
In truth, Bob is controlled by his AI overlord. But don't tell that to Bob, we don't want him to deal with an existential crisis as of now.
As you can see, there are a lot of things to consider for an AI in Solasta, and that was just a much-simplified example (no offense Bob). Giving the AI a correct set of rules, with the appropriate ways to score decisions is what makes or breaks a behavior. And the complexity does not end here as we also must balance the behaviors so that the AI does not become frustrating to fight against. That’s all the joy that’s AI design and programming!
I hoped you enjoy this sneak peek into our thought and design process, and I will see you soon for more.