Hello everyone!
It’s been a while since last dev blog. Much has changed since the start of the year, some of them are good, some of them are bad, but overall there seems to be an upward trend so far. Most of the systems have been either rewritten or redesigned completely. AI, dialog system, city management, kingdom management, building system, foliage system and even the map itself has quite significant changes. Starting with this one, there will be a new series of dev blogs coming out every 1-2 weeks, describing the changes and the mechanics in detail. There is also a new forum on the website, you can join the discussion here.
Changes weren’t limited to the game only. There were also structural changes on dev team as well. Taner has left the development late January this year, I’ve been working on the game solo since then.
Before getting into the meat of the blog, I’ll answer the most frequently asked question: When is the release? It is a bit complicated. As I’ve mention above, there will be a series of new dev blogs about the changed mechanics of the game, after 2-3 of these blogs, I will make a gameplay video that further explains the mechanics in detail. After that, the release will be determined by the feedback that you’ll give.
Now, on to AI!
Usually in traditional RPGs non essential NPCs are treated as background decoration. For the purposes of those games, this makes perfect sense, both in narrative and gameplay wise. Once we start going into more sandbox (or open world) territories, NPCs start looking a little more interesting. They might move around and comment on the player.
Some of the more advanced types have daily routines, they wake up, go to work, talk with some people and so on. Even in those cases however, most NPCs are designed as background decoration. When you enter a city or a village, and see people moving around, merchants at their shops, kids running around, you don’t question any of it. Mainly because you have better things to do, important quests to finish, or a big armor to craft. These NPCs present just enough interactivity to let you fill in the blanks with your own imagination. This makes perfect sense, if the meat of the game is exploration, combat and then a narrative pay off at the end, the game doesn’t need more advanced forms of AI, in fact, that might even take away from the experience through the unpredictability of it.
Things are a bit different for Northern Shadow. World isn’t static, entire cities can be destroyed. NPCs need to be able to react to constantly changing situations. Since you can build your own cities unlike other RPGs, you end up having to pay a lot more attention to NPC behavior. Suddenly, techniques that would work on traditional open-world RPGs or city builder games end up being irritating and unrealistic, the illusion becomes immediately obvious. Fixing this was a big priority, solution was the complete rewrite of the Northern Shadow AI.
Start at the beginning. What are the requirements for the AI?
At minimum, it should be able keep itself alive. It should be able to know when it is hungry, know how to hunt or collect food. It should become tired as the day goes by, and eventually be required to find a safe spot for sleep. Should be able to recognize threats and defend itself.
That might work well for a cavemen, but not for medieval villagers. We need more advanced forms of interaction. It needs to be able to use currency to buy the food instead. Needs to be able to earn that currency through work. Know that cities are safe(r) places that offer shelter through housing.
That seems enough, but it can go one step further. Instead of reacting to hunger, it can buy the food in advance. Plan to refill its stocks once the food levels are low. Find jobs that cater to its skills and character. Interact with other villagers, form relationships. React to the events of the world around it.
Those are the requirements, lets get a bit in-depth.
Anatomy of an AI
Every AI character have a set of attributes, traits, skills, and feats that defines their character. Lets look at these one by one.
Traits List
Aimless – Ambitious
Unjust – Just
Cowardly – Courageous
Cruel – Merciful
Deceitful – Honest
Despairing – Hopeful
Emotional – Logical
Frugal – Generous
Lazy – Energetic
Proud – Humble
Obedient – Rebellious
Reckless – Prudent
Religious – Secular
Selfish – Selfless
Suspicious – Trusting
Vengeful – Forgiving
Violent – Pacifist
Jealous – Content
Attributes
Strength: Muscle mass
Dexterity: Hand-eye coordination
Agility: Balance and speed
Endurance: Physical stamina
Intelligence: Logic and reasoning
Willpower: Spiritual strength
Wisdom: Insight and intuition
Charisma: Confidence and leadership
Traits
A total of 100 points are split between opposing values. That means if a character 80 points to being generous, they will have 20 points in being frugal. If any value reaches 100 points, that character will become the embodiment of that value, and will never be able to act otherwise. Ie, if a character gets 100 points in pacifist, they will never use any weapons, even to defend themselves.
Feats
Quirks and feats that are specific to the character. Generally used to change or disregard attributes, traits, feats, needs, or skills on varying situations.
Skills
Way too many to list, so I will condense them to archetypes, ie plate, scale, chain, leather, cloth and naked armor skills will be just mentioned as one armor skill.
Armor
Weapon
Crafting
Divine
Lore
Magic
Sneaking
Speech
Work
Misc
A character has 3 sets of attributes, traits, skills, and feats (CharData for short) settings. Racial, Cultural and Personal. A final CharData is derived from these 3 sets of data, and that final data is used in both AI and the dialog systems. 3 stage character allows an NPC to be affected by its racial and cultural heritage. If Elves are arrogant/proud race, an elven NPC will inherit that from its racial CharData. If a town is known for its fishing skills, the NPC will inherit that with cultural CharData.
Throughout the game, all 3 sets of attributes, traits, skills, and feats can change to varying degrees. Racial is the most rigid one and it is very hard to change, as the changes affect the entire race. Cultural keeps slowly evolving by itself through the changes in the cities/kingdoms. Personal one can be influenced by AI (self and other) decisions or through dialog.
Next we have emotions. Emotions are derived from and affects moment to moment actions and AI decisions. If an AI can make a decision or action according to their own values, it will have a positive effect on the AI emotions. If not, it will have a negative effect. Accumulation of negative emotions will cause the character to act randomly sometimes even opposite to their own values.
Short term emotions shift constantly, and they get degraded through the day, degrades faster if the character sleeps or has an other emotional reset mechanic. Long term emotions degrade slowly (2 weeks in-game). A final emotional state is derived from both and used in decision making calculations.
Emotions List
Anger
Loathing
Sadness
Amazement
Fear
Admiration
Joy
Vigilance
300 points are divided between the 8. Increasing one emotional level decreases all others, highest one decreases the most. 100 is the maximum value for a single emotion.
We have bunch of variables for characters to make decisions with. Next we need some concepts so we can use them
Needs
All NPCs have some physiological and psychological needs. They try to fulfil them by selecting an action appropriate to their character. Once fulfilled, they directly affect the short and long term mood of the NPC. Lets look at some of them.
Primary: If any of its values reach 0, the NPC dies.
Secondary: NPCs won’t die if any category reaches negative values, but it will have a profound effect on their state if they do. In this category, sub-needs do not have values of their own. They only serve as a guidance to the NPC on how to fulfil that specific need.
Primary
Food
Water
Temperature
Excretion
Secondaries
Protection:
Shelter
Health
Participation:
Duty
Work
Identity:
Community
Culture
Religion
Affection:
Relationships
Intimacy
Leisure:
Games
Peace
Understanding:
Literature
Education
Community
Creation:
Crafting
Work
Each Need, has a set of tasks that one can take depending on the final CharData and final emotional state. An NPC can iterate over any of the tasks, but they will only affect the mood if they are in the planning stage.
Planning:
All NPCs have 3 different levels of decision making process. Short term, long term and currently executing.
Long term: Tasks that should be done within few weeks. These eventually fall into the short term or currently executing branches, depending on how long it takes to complete them, and how often it is needed to be done. Some may never be fulfilled. Iterating over this branch can cause small adjustments in the NPCs mood.
Short term: Stores the tasks that have very high chance of being completed. Once a task is here, it gets rechecked constantly so that NPC can react to changing situations better. It also acts as a safety net for the NPC, as they can revert a decision made by a previous emotion state.
Currently executing: Converts the high level task that is currently in the execution queue into low level series of actions, tracks the completion of them.
When an NPC executes an action significant enough, they generate an Info construct that gets broadcasted within a range depending on the type of Info. These objects holds facts about the action that just occurred. They hold:
What was the action/event
When did it happen
Who are the involved parties (positive or negative)
Where did it happen
Why did it happen
This info can then be transferred by NPCs talking to each other. NPCs process the info as they receive it, they adjust their emotional state and their needs, then archive that in their memory.
All NPCs have their own friends and acquaintances list, where they keep track of emotional impact that other NPCs caused, and the level of their relationships. They also have an info memory, where they keep a pointer to the original info (stored by the world state), and further specifiers about how much they know.
Infos can also be generated by the game state. A suspicious weather event can generate an info with massive range that changes the fear level of the affected NPCs. A building or a city burning down also generates an info. If an NPC with that info can reach another city, it can transfer the info to that city, which in turn can affect the AI decisions of that city, as a city entity or as an individual NPC. Items can store infos and spread them. These can be notes, books, items used for certain purposes, or legendary items.
Info acquisition and sharing by the NPCs is the primary way of getting information about the world state. You and NPCs can also fabricate info (lie essentially), but that is for the dialog system blog to explain.
Optimization
While infos are very small, they can still accumulate out of control. Most of the infos are very short lived. Only the actions that substantially change the world state or an NPC are stored permanently. Few examples; death, destruction of a structure, forest fire, extraordinary event, supernatural event, cheating, lying, treason, sacrifice and so on.
AI characters decision making can be a heavy process when there are many NPCs and many infos. This process gets spread across few seconds so that it doesn’t bog down the game thread. Also, different planning stages execute at different intervals, and some of the results are cached. A future optimization method could be the offloading this entirely on a new thread.
Well, that is about it. It touched almost every aspect of the AI and its decision making process. Next week, there should be a blog about the dialog system, and how it ties into the AI and some of the unexplained interaction.
Feel free to join in on the discussion on either all AI aspects, or this blog specifically!
Thanks for reading!