NPC ~ NPC Dialogue Provocation Design Document - uchicago-cs/chiventure GitHub Wiki

Overview

New Structs

typedef enum {
    POSITIVE,
    NEGATIVE,
    NEUTRAL;
} tone_t;

Note: we added tone_t to the node struct so that NPC dialogue options can be coded by tone as well, facilitating the 2nd case of the two listed below (NPC provokes player).

HOSTILE nodes will always have the START_BATTLE action within their actions struct.

typedef struct node {
    tone_t tone;
    char *node_id;
    char *npc_dialogue;
    int num_edges;
    int num_available_edges;
    edge_list_t *edges;
    node_action_t *actions;
} node_t;
typedef struct edge {
    tone_t tone;
    char *quip;
    node_t *from, *to;
    condition_t *conditions;
} edge_t;
typedef struct npc {
    /* hh is used for hashtable, as provided in uthash.h */
    /* Second hash handle is for storing npcs in specific rooms */
    UT_hash_handle hh, hh_room;
    /* NPC identifier */
    char *npc_id;
    /* short description of the NPC, <51 chars */
    char *short_desc;
    /* long description of the NPC, <301 chars */
    char *long_desc;
    /* pointer to an existing convo struct */
    convo_t *dialogue;
    /* pointer to inventory hashtable */
    item_hash_t *inventory;
    /* pointer to an existing class struct */
    class_t *class;
    /* pointer to an existing npc_move struct */
    npc_mov_t *movement;
    /* enum indicating hostility level of the npc */
    hostility_t hostility_level;
    /* either NULL or a pointer to an existing npc_battle struct */
    npc_battle_t *npc_battle;
} npc_t;

New Functions

void convert_hostility(npc_t *npc, node_action_t *actions)
{
    assert(npc != NULL);
    assert(actions != NULL);

    if (actions->action == START_BATTLE && 
        npc->hostility_level == CONDITIONAL_FRIENDLY) {
        npc->hostility_level = HOSTILE;
    }
    return;
}

Player Provoking CONDITIONAL_FRIENDLY NPC

In this case, a FRIENDLY NPC is provoked through NEGATIVE-tone player dialogue and turned HOSTILE. A HOSTILE NPC will immediately initiate a battle.

When the player selects a NEGATIVE dialogue option (represented through the edge struct), convert_hostility will be called, which will update the NPC's hostility_level to HOSTILE. The convo_t will progress to the corresponding NPC node, now coded with a HOSTILE tone. convert_hostility will take the associated node_action_t actions from that node and check to ensure that START_BATTLE is present.

Then a battle will be initiated with (start battle function).

HOSTILE NPC Provoking Player

In this case, the NPC will say a NEGATIVE-tone dialogue, which will trigger the player to automatically join a battle. This is left as a future task as we are currently focused more on implementing a player's provocation of a CONDITIONAL_FRIENDLY NPC.