Creating a needs framework for NPCs (And maybe even PCs)

So Ive been trying to conceptualize a more robust and flexible AI, and so Ive created a simplification of the Maslow’s hierarky of needs that I hope to implement as a better decision making routine for NPCs.

Here’s what I got:
This list goes from least priority to most priority

–GROWTH NEEDS–

==> Transcendance Needs:
-Basically become buda. The character will try to fulfill its most esoteric and high concept level goals and achieve
true hapiness with itself and the world.

==> Self-Actualization Needs:
-Achieving what the character thinks is it’s calling in life. Basically, the character will try to achieve its long term goals
and ambitions, possibly look to change the world in a way that it can feel proud of.

==> Aesthetic Needs:
-Shinies and pretties. The character will look for and appreciate things it finds beautiful.

==> Cognitive Needs:
-Knowledge. The character will seek to know itself, to know the world and its place in said world. Possibly start a cult.

–DEFICENCY NEEDS–

==> Esteem Needs:
-Social anxiety’s worst nightmare. The character will look to perform and act in ways that make it feel proud of itself
and unashamed. The character will also seek to perform tasks that will lead other characters to like and respect it.

==> Love needs:
-We all need love. The character will desire and search for fulfilling relationships with other characters, and will desire
touch and intimacy from others.

==> Security Needs:
-Safe and sound. The character will look for ways it can be safe from other characters that pose a threat to it, the elements,
injuries and will try to create some semblance of stable footing when possible.

==> Biological and Physiological Needs:
-The gross shit. The character will look for ways it can remain alive and functioning as a living organism. It will also look
for behaviors that satisfy basic instincts like sex or other things.

Im looking for feedback on the best way to implement a system like this and how it would work in the code. What do you think? A lot of these depend on personality of characters so I think this would also need to exist for this to function.

Kevin already did some implementation of needs and strategy for NPCs: see src/behavior* and data/json/npcs/npc_behavior.json

It’s not currently hooked up to the NPC tactical AI (src/npcmove.* mostly) because I’ve been working on other things and Kevin didn’t get that far.

You’re welcome to do some work on hooking the two together or expanding the NPC behavior hierarchy. Though expanding the hierarchy without hooking it to the tactical NPC AI is kind of a waste in my opinion.

1 Like

I agree Ill try to work on making NPCs actually react to their needs. Any suggestions for where I should focus? What files are most important and stuff. Im thinking of working up from the bottom, having each level in the hierarchy done before going higher.

I just listed all the relevant files. I would start by reading those and figuring out how to link the existing behavior hierarchy to the existing NPC tactical AI in src/npcmove.cpp.

1 Like

This is the initial issue I made: Maslow's Heirchial Finite State Machine · Issue #28681 · CleverRaven/Cataclysm-DDA · GitHub

An initial draft implementation is merged already. You can even check the output of the system by reconfiguring the sidebar to output the current goal.

Where I stalled on this was the difficulty in representing varying degrees of needs mostly within a single level.
So if you are just about to starve to death but you were a little bit thirsty you need to prioritize food over water even though normally in a behavior tree you would strictly prioritize a thirst need over a hunger need.

I have two ideas for what to do about it. One is add a simple “largest value” selector to the behavior tree implementation, and have the potentially lethal needs return a, “time until death if need is unmet” value, and the second is to add a utility curve selector and have the needs return a simple level value.

After that there’s probably some more tuning that needs to happen to get the lowest level needs acting as expected, then the whole system can be wired into the npc AI proper.

1 Like

I was thinking myself about modeling a desperation value. I think this could do 2 things: Make them prioritize the most pressing need and also determine what they are willing to do to satisfy it.

For example, if an NPC gets thirsty, it would look in the surrounding area for liquids in containers. If the desperation increases it might start roaming around to look for sources of water and if it gets really close to dying it might be willing to drink straight from a water tile.

I think slightly modifying the node structure so it can also hold a desperation value for the need in question could be very benefitial from a game point of view and a code point of view, because if every root of subtrees had the sum or mean of desperation values, it can optimize the tree checking process by pathfinding to the most desperate need in a short time.

I had a formal education in C for this kind of algorithm optimisation and I think I still have the books for it. What I dont have is the know how of the code, and what I would break if I started messing with it so Im only looking at it for now until Im reasonably sure Im not breaking something

The good news is you can’t really break anything since this code isn’t wired up to anything.

2 Likes