Advertisement

Yet Another NPC AI thread

Started by July 28, 2000 03:26 PM
28 comments, last by Diragor 24 years, 3 months ago
Looks like the last thread kind of wrapped up at the end there, and I want to get some opinions on a kind of new idea related to what was discussed in that post. I don''t know if that has already been done, but I haven''t heard anybody talking about anything quite like this. I haven''t put any of this to practical use yet, I''ve just been thinking about it and discussing it with someone by e-mail. The idea is a system for NPC behavior, probably most compatable with an adventure game or RPG. It''s pretty much like the "needs" stuff discussed in the previous thread, only more dynamic and complex. The system is based on something I guess you could call Priority objects. A Priority data structure would include information about a state of being, possible actions related to that state, and some kind of numerical expression that represents the relative importance of this Priority. Each NPC would have a list of priorities, starting with a "default" priority that gets carried out when nothing else is happening (eg. "whittle wood"). Most NPC''s will always have a self-preservation priority that will shoot to the top of the list in certain circumstances. In a given situation the priority list will be traversed from top (most important) to bottom, and each priority will have a chance to determine the actions of the NPC. Each priority will also have a chance to modify its own importance based on the situation. This idea can also use the scheduling ideas from the last thread to introduce new priorities to the queue. Here''s an example, using completely arbitrary numbers where necessary. Our NPC is Bob. It''s about 9pm and Bob is sitting in a pub having a drink. We go through the priority queue and the first time we go through the list and reassign priorities. The first priority is "get drunk" with a value of 15. Well, he''s already drunk and the more he drinks the less he cares about getting drunk. This priority has been decreasing for an hour or two and now it just removes itself from the list. This task is basically complete. Next in the list is "go home", which becomes more important the later it gets, so it increases its importance to 20. Bob''s personal schedule inserts a "sleep" priority in the queue at 9pm after he''s been awake for 16 hours (or something), and since he had a busy day and got drunk this priority will start at 10. After going through the list and assessing all of the values, now we start at the top again and act on the priorities. The top priority now is "go home", so we call the only associated action and Bob starts walking home. The action associated with "go home" will also look for faster modes of transportation, evaluating how much money he has and possibly checking against the value of an "actionless" priority such as "save money". There are obvious problems here and tricky situations to work around. Numeric values for the priorities will have to be carefully calculated. In the example if Bob is far enough away from his house then the calculations should have the priority of sleep overtake the "go home" priority, so Bob camps out or something. The self-incrementing and decrementing priorities can make for some very realistic behavior. For instance, the value of the sleep priority becomes higher and higher until you sleep, and while you''re sleeping it will decrease. In the morning the schedule (or alarm clock or something) will insert a "get up and go to work" priority of some sort, with a certain value. If you waited long enough to sleep then that priority will still be greater than the "get up" priority and the NPC won''t get up. Sooner or later though, the increasing "get up" priority will overtake the "sleep" priority and the NPC will get up. Priorities can be used to describe just about any possible situation and related actions. In combat priorities would include "kill enemy", "preserve self", "protect friends", all with changing values based on the situation (your health, the enemy''s might, your friends'' health). So, any comments, thoughts, suggestions?
That is a great idea, and I think that it could work rather well. The other thread didn't wrap up, we all just ended up being preoccupied with our e-mailing list at http://www.egroups.com/group/NPCAI/ and haven't really discussed anything over here since. Your priority queue would need a full study, need to have increment and decrement values stored with it, so one need can increase faster than another. I am thinking that some would need to follow a function such as x^2 or somehting. I think this effect might still seem the same as if you have most values decreasing at the same time as another that is increasing.

It's a little too early in the morning for a formal oppinion, so I am just churning out ideas at the moment . The effects of this system could be quite believable, maybe you should post this to our e-mailing list (NPCAI@egroups.com) so that the rest of the crew can make their voices known


-Chris Bennett ("Insanity" of Dwarfsoft)

Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet

Edited by - dwarfsoft on July 28, 2000 5:38:00 PM
Advertisement
Diragor,
That's a really great idea and has a lot of potential.


dwarfsoft,
Yeah I agree...some of them will have to jump up in the list faster than others...like eating and drinking would rise faster than most others...

Plus, maybe the environment could change the things on the list. Like, if it suddenly starts snowing, then the NPC may put "find shelter" on the list...

Also, it could add a lot of personality to each NPC. Like, Bob may have "getting drunk" high on the list while another NPC has "getting drunk" not even on the list. Obviously, Bob is a big drinker.

Very nice idea

It's a lot better than a hard-coded schedule like "go here at 9:00 and here at 10:00"

Although, do you think that there should be some sort of scheduled capabilities added?

Like, if the NPC had to meet the player at a certain time, you could put the meeting very high on the list...but I don't think that you could guarantee that the NPC would get there at the right time. The NPC then may be late which would actually make things more realistic, but may be annoying...especially if the NPC is a few hrs late.

For instance, if the NPC is supposed to meet the player at a certain place. So, that is put into the list at pretty high priority. On the way, the NPC gets hungry. Then the "eating" priority would probably be higher than the "meeting player" one.
Then, what if the NPC does not have food with him/her. Then, the NPC has to stop somewhere to get food, and is 1 or 2 hrs late (game-time) to meet the player. I suppose it depends on the game itself (how loose and non-linear it is) whether that's ok or not..but it could be a problem.





"The road of excess leads to the palace of wisdom." --William Blake

"The road of excess also just ends up making me tired because I'm too lazy" --Nazrix

Edited by - Nazrix on July 29, 2000 12:04:08 PM

Edited by - Nazrix on July 29, 2000 12:12:04 PM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
Its not too far off to take those needs and transform them into dynamic quests for those players that want to help out the NPCs. Again this applies to RPGs but could be used in other types of games as well.

Kressilac
Derek Licciardi (Kressilac)Elysian Productions Inc.
Yes Nazrix, scheduling is part of the idea. It gets a little complicated when it comes to that, though. Each character would need to keep his own personal schedule and there probably need to be a global schedule as well. The schedules, environmental effects and interactions with other characters could place priorities in a character''s queue.

Here''s an example that kind of incorporates all of those effects. An NPC (how about Bob again) meets another character in the morning and agrees to meet the character later that night at 9pm. The result of that interaction is a new item in Bob''s personal schedule that will insert a "meet person" priority in his queue a certain amount of time before the meeting is suppsoed to occur (to allow travel time, which is another matter). Depending on the importance of the meeting, a certain value will be assigned to that priority. Let''s say it''s a matter of fair importance, and we''ll give it an arbitrary value of 200. So Bob goes about his business for the day, and he has a lot of important work to get done. His "work" priority will stay at a high value until the work is completed. Let''s say the work value is 150, less important than the meeting but more important than everything else. Around 6pm Bob''s schedule inserts an "eat" priority (based on the calculated time since his last meal, not the clock time), and since it''s just dinner time it will be a fairly low priority because he won''t starve if he eats a little bit late. Let''s say the "eat" priority starts at about 40. The "eat" priority keeps increasing as time goes on, but his work priority stays at 150 until it''s complete.

Just before 8pm, Bob''s work is finished and his "eat" priority is getting up over 100, so it''s definitely the most important thing now. Bob runs across the street to get something to eat. If you want to micromanage here, you could always have a permanent "eat" priority in the queue and just have it reduce as food is consumed and increase by small amounts otherwise, but we''ll just say that he eats and that priority is taken out of the queue. Just as he finishes eating, some rowdy drunks start messing with him. Bob tries to avoid conflict, but these guys are hell bent on getting into it. He''s ushered outside for an all-out battle. As soon as the conflict starts, priorities such as "self-preservation" and "defeat opponents" (or whatever) get stuck in the queue at super-high priorities. There''s a whole mess of priorities and logic going on during something like this, and it could be handled in a number of ways, but anyway... in the middle of the battle Bob''s schedule inserts the "meet person" priority at 200, and absolutely nothing is done about it because of the huge importance of defending himself against injury and death. The importance of the meeting could increase as the time of the meeting gets closer, then when the fight ends he could possibly take certain steps to get there faster. Scheduled activities could also have a value that represents how long a priority will stick around after the scheduled time has passed. For instance, let''s say the fight ends half and hour after the scheduled event is supposed to take place, but the event is still in the queue, so he''ll go but he''ll be late. But if a scheduled event has a lapse time of one hour, then one hour after the scheduled time passes it will be removed from the queue whether the event has taken place or not.

Oh, and if you were wondering what happens next, Bob bravely vanquishes his enemies and makes it to his meeting with seconds to spare . Hooray for Bob! Oh damn, I meant to have a snowstorm keep him from reaching his meeting to demonstrate weather effects. Oh well, you get the picture.
I have to say that this system is BRILLIANCE. There are obviously bugs that need to be ironed out of it (not that I can think of any off the top of my head ) but there are bugs none-the-less. I have forwarded this to NPCAI and so I will see what the others have to comment on your idea. The idea is sooo simple and yet so effective. I am just wondering at what increment/decrement abilities can you set.. ie, are the incrementing and decrementing of priorities variable and how would this be implemented. I am thinking of Character scripting (not as in the old scripting sense) where the priorities list that may interest that character are listed in their script and all of the variables that modify it (when and by how much) could be stored in their as well.

Hmmm


-Chris Bennett ("Insanity" of Dwarfsoft)

Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
Advertisement
I might actually get into starting some actual code using this stuff tomorrow, it''s getting really interesting.

I''m sure little bugs will crop up in the system but the only real issue I can think of so far is just balancing priorities. The inc/dec system for priority values just has to be carefully thought out so nobody ends up stopping to eat in the middle of a battle or something. As far as implementation goes, I''ve got a bunch of ideas but I''ve talked enough already . I think I''ll try a few things before I type any more novels on here.
One way to get around possibilities of the eating in battle glitch would be to have everything have a realm of 1000 points in its priority (we are using longs here ppl ). Basically, make it impossible for eating to increase more than xx and if it does then the PC would probably have starved to death by that time anyway. For the battle thing, have the priority at about 1000 times higher than the eating priority (we just want to disperse it to make it impossible for it to happen) while there is still anything hostile in the area. If it is only semi-hostile then you could probably halve the priority.

Basically I think there should be FLOOR and CEIL values for the priorities, ie, exception handled when it goes over CEIL (for eating: starvation, drinking: dehydration, etc.) or if it falls through the FLOOR then remove it from the queue.

Hope thats some food for thought... if the priority isn''t through the roof already


-Chris Bennett ("Insanity" of Dwarfsoft)

Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
Another thing which you might need to have is linking between
each attribute.
For example ( I''ll use Bob again), Bob needs to quickly get to his dying Uncle who''s filthy rich and who hasn''t yet given Bob the pin number to his bank account. Unfortuantely, Bob''s uncle
lives in another city, which is eight hours drive from where he is.
The priority to reach his uncle is something like 200. However,
he''s just finished the night shift and has been awake for 16
hours, so he''s pretty tired, and his tiredness is a priority of 20. Of course his uncle is more important, so he ignores sleeps
and its priority increments as time passes.

Now, I find if I stay up later than I should i start to get hungry. So, his lack of sleep should affect his hungriness.
He will be more hungrier than usual because he needs to replace
the energy needed to stay awake. So for every hour the sleep
attribute will add a modifier to hungriness..


The hunger should be based on the ammount of activity of a user, it could also be in the priority queue, but self modifying it, it decides what is currently happening (how much activity) modifies its own priority to suit and modifies other priorities (such as tiredness and hungriness). Seems fairly simple to implement, and of course some of the elements in the queues are going to be linked. It is simply impossible to implement completely arbitrary elements and expect it to work .

I think that the tiredness priority is rising, though the hungriness one has faded because of beloved skittles .


-Chris Bennett ("Insanity" of Dwarfsoft)

Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)

This topic is closed to new replies.

Advertisement