Dynamic dialogue roots

From Post-Apocalyptic RPG wiki

Jump to: navigation, search

Implemented code proposal.png This article features an already implemented code proposal.

Implemented Proposals have had code checked in to the SVN repository. The Implemented Proposals should serve as documentation for the actual implementation. Developers should strive to update these as needed.



Currently the starting section of dialog displayed when a dialog is initiated with an NPC (i.e. the NPC's greeting) is hard-coded and static - that is, NPCs will always greet the player with the same text, regardless of the player's actions. The proposed changes would add conditional statements to the START_SECTION tag which would be evaluated each time a dialog is initiated to determine an appropriate starting dialog section or root.


Although dialogs can already have complex branching behavior with conditional responses, the initial greeting is always the same. This leads to frequent, highly unrealistic situations, e.g. having stolen from a merchant and been caught, the player would still be greeted enthusiastically the next time he/she interacted with the merchant.

Pros and Cons


  • More realistic conversations that allow the NPC to greet the player according to his/her actions;


  • Dialogs would be considerably more complex with multiple conditional starting points and possibly independent branches to maintain;


YAML Dialog File Syntax Changes

The proposed changes would rename the START_SECTION tag to GREETINGS and modified so that a list of potential dialog greetings could be specified along with conditional statements. These conditional statements would be evaluated each time a dialog is initiated with the NPC and would be used to select a dialog greeting section from the list. Conditional statements are evaluated in the order specified under the GREETINGS tag (from first to last), so greeting sections specified earlier in the list are always selected before greeting sections later in the list provided both have conditional statements which evaluate to True.

Once implemented, the proposed syntax changes would look like the following:

AVATAR_PATH: some/path/to/image
    ID: main_dialog
    SAY: "Great day, isn't it?"
    -   REPLY: "Yeah, if you like snow."
        GOTO: end
    -   REPLY: "Still got that quest?"
        CONDITION: "not pc.hasQuest('some_quest') and pc.hasMet('mr_npc')"
        GOTO: start_quest
-   ID: continue_quest
    SAY: "Hey, you got the item! Great job"
    CONDITION: "pc.hasItem('some_quest_item') and pc.hasQuest('some_quest')"
    -   REPLY: "Your praise makes it all worthwhile."
        -   give_item: some_quest_item
        -   complete_quest: some_quest
        GOTO: end
-   ID: aggressive
    SAY: "Get your ugly face out of here!"
    CONDITION: "npc.favorability < 20"
    -   REPLY: "Hey! You ain't such a beauty queen either bub."
        GOTO: end
-   ID: drunk
    SAY: "Go sleep it off buddy."
    CONDITION: "pc.status['inebriated']"
    -   REPLY: "I don' need yar advice!"
        GOTO: end
-   ID: friendly_greeting
    SAY: "Hi there! Its nice to meet you."
    CONDITION: "not pc.hasMet('mr_npc')"
    -   meet: mr_npc
    -   REPLY: "Uhh, sure."
        GOTO: offer_quest
-   ID: offer_quest
    SAY: "I got a quest for you. Can you get me some_quest_item?"
    -   REPLY: "You know that I'd do anything for you."
        -   start_quest: some_quest
        GOTO: waiting_for_quest
    -   REPLY: "Umm, no."
        GOTO: end
-   ID: waiting_for_quest
    SAY: "Wonderful! I'll be here waiting for you."
    -   REPLY: "Whatever."
        GOTO: end

Notice the DEFAULT_GREETING tag: the dialog section indicated by this tag is the "fallback" section displayed when and if no other root dialog section conditional evaluates to True. This new tag is mostly to prevent errors in the dialog logic from blocking interaction with the NPC, and is thus mandatory.

Notice also that the quest-related greet section is specified first in the list so that it is evaluated first before any of the other start sections. This means that if the player has the quest item then the NPC will greet the player with the quest-related greeting, even if the player's favorability is low and is inebriated. This makes sure that the quest isn't broken should the player fall into disfavor with the NPC (or is hopelessly drunk all day!).

Personal tools