Modeling conversation flow: types of NPC Initiative

In Galatea, one of the things I wanted to do, but managed very badly, was to have Galatea continue the conversation herself if you stopped to listen to her rather than talking. But the number of such things she had to say was pretty sparse, so it wasn’t worth stopping to wait after every turn, and there wasn’t always any clear sign when she was likely to continue. Moreover, the mechanism for this was very hacky and didn’t allow her to have more than one thing planned to say at a time.

Alabaster does this much better. Instead of having the NPC’s speech be part of the player’s action, the NPC actually has a separate action in which he speaks, and he has a list of quips to say next. He will go on saying things from this list if the player is silent, or if the current conversation thread has come to an end and it’s time to change the subject to keep conversation flowing. (Galatea has no model of when conversation threads have ended, either.)

New quips added to the list have two kinds of priority. They can be marked either “obligatory” or “optional”, and either “immediate” or “postponed”. Obligatory quips are things the NPC definitely means to say sooner or later, even if the player interrupts with some other comments first; optional quips are things he might say, but is equally happy to skip if the conversation moves in another direction instead. Similarly, “immediate” means he’ll say this next even if there are other things on the list — it goes in at first position — while “postponed” means the quip should instead go at the end of the list.

Between them, these cover a number of different ways an NPC could want to go on with the conversation:

Responses to direct stimulus. Immediate obligatory is the status given to quips that answer whatever the player just said (or something the player just did, such as interacting with an object that belongs to the NPC, attempting to go through a door he’s guarding, etc): we want the NPC to start by replying to the player before going on to any other topics.

Immediate obligatory quips should be added to the list on a turn by turn basis by the player’s actions.

Continuations of earlier speech. Immediate optional is good for offhand remarks that follow up on the conversation but that aren’t critical to it. The NPC will say these if he gets a chance to do so on the next turn; otherwise, they’re removed from the list.

Postponed optional can be used for an NPC’s casual follow-up to something the player had said earlier, where it’s not important that the follow-up be instant. If the player changes the subject (defined as moving significantly away from the conversational thread he was on), the NPC throws away all the optional remarks from his list on the grounds that they’re likely not to be relevant any more.

Both kinds of optional quip are most often added to an NPC’s list by something else the NPC has himself said: for instance, we might have the sequence

-> player asks about the murder [plan immediate reply about Ms Dunbar]
-> NPC replies by saying he suspects Ms Dunbar [plan immediate optional comment about Ms Dunbar’s fashion sense]
-> player is silent for a turn, perhaps doing something else
-> NPC mentions Ms Dunbar’s fashion sense

Planned sequences. Postponed obligatory is good for setting up stories, interrogations, and mission instructions where the NPC will keep coming back to a main sequence of conversation until the player has learned everything he needs to know. Even if the player changes the subject, postponed obligatory quips stay on the list.

The player’s questions can potentially make pieces of this sequence occur out of order if the author wants to allow this — for instance, the NPC might be planning to talk about the poison ring after talking about why Duke Orsini must die, and the player might pre-empt the sequence by asking about the ring first. But the author only needs to cede as much control as he wants, since he could make the poison ring quips off-limits until the proper time. Personally, I like setting up scenes like this so that they have some fluidity, and the player feels that he’s not just being shouted at from a list, even if he’s guaranteed to get all the same information in the end.

I typically set up a whole planned sequence of postponed obligatory quips at the beginning of a scene and let it play out.


The mechanisms here can be overridden. For instance, if the player asks a question, the NPC might plan his response as immediate obligatory; but we might have a rule that intervenes and prevents him from giving the answer right now, like:

Instead of Paul discussing something which mentions the secret door when Paul does not trust the player:
say "Paul looks shifty. 'I'd rather not discuss that.'"

Or maybe, if we’ve previously defined the idea of “safe topic” as one of Paul’s quips that starts an innocuous conversation:

Instead of Paul discussing something which mentions the secret door when Paul does not trust the player:
say "He looks uncomfortable. [run paragraph on]";
try Paul discussing a random safe topic instead.

if what we wanted was

“Hey, Paul, isn’t it strange that there seems to be some dead space behind the fireplace?”

He looks uncomfortable. “…say, did you catch the game last night?”

Thus the player has the option of asking Paul the question even when it’s not going to get an answer. The quip just won’t count as “used” until Paul trusts the player enough to give a reply. (I find that’s usually preferable to hiding quips until the NPC is ready to answer them: it lets the player know that those conversation directions will eventually become worthwhile, even if they aren’t when he first thinks of them. Of course it is always possible to hide quips as well.)

Finally, the whole system of choosing what to say next by picking a quip from the list can be replaced with different logic. We might do this if we wanted to de-couple the player’s remarks from the NPC’s responses, so that instead of having prewritten PC comments with prewritten NPC responses, we have various NPC utterances that can be dynamically selected based on their greatest relevance. This would, of course, require a lot more logic (and probably a lot more work writing content), and for most conversations of the style already existing in IF, the pre-scripted approach will be fine — but I wanted the system to be flexible enough to allow the same basic structures of data to be used with other kinds of AI.

12 thoughts on “Modeling conversation flow: types of NPC Initiative”

Leave a Reply to Conrad Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s