uchicago-cs / chiventure

A text adventure game engine developed in UChicago's CMSC 22000 - Introduction to Software Development
40 stars 13 forks source link

Integrate rooms-npc module with the npc module in accordance with issue #836 #879

Closed torresszy closed 3 years ago

torresszy commented 3 years ago

Based on the proposals in issue #836, we will try to integrate the rooms-npc module into the npc module as well as update some functions in rooms-npc.c that are left unfinished from the previous year

torresszy commented 3 years ago

I have created a branch called npc/mov-integration and am currently working on integrating npc_mov struct in rooms-npc.h into the npc struct in npc.h

torresszy commented 3 years ago

I have made an initial push under the branch npc/mov-integration, in this push I updated the npc struct with an additional field npc_mov_t and removed the npc_id field from npc_mov_t struct since this struct will be part of the npc struct that includes the id anyways.

The new npc struct looks like:

typedef struct npc {
    /* hh is used for hashtable, as provided in uthash.h */
    UT_hash_handle hh;

    /* 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;

    /* the npcs class */
    class_t *npc_class;

    int health;

    /* 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 exisitng npc_move struct */
    npc_mov_t *movement;
} npc_t;

The new npc_mov_t sturct looks like:

typedef struct npc_mov {
    npc_mov_type_t npc_mov_type;
    npc_mov_enum_t mov_type;
    char *track;
} npc_mov_t;

Relevant functions relating to these two structs are also updated

torresszy commented 3 years ago

I also added a delete_npc_from_room function in rooms-npc.c since there was only a function that adds a npc to a room. The function looks like:

int delete_npc_from_room(npcs_in_room_t *npcs_in_room, npc_t *npc)
{
    npc_t *check;
    HASH_FIND(hh, npcs_in_room->npc_list, npc->npc_id, strlen(npc->npc_id),
             check);

    if (check == NULL)
    {
        return FAILURE;
    }
    HASH_DELETE(hh, npcs_in_room->npc_list, check);
    npcs_in_room->num_of_npcs--;

    return SUCCESS;
}
torresszy commented 3 years ago

I have also updated the Wiki page "RPG NPC: Independent Feature: NPC Movement Design Document" to include the modification we have made. I will keep updating this page as new features are coming out.

torresszy commented 3 years ago

In order to solve the problem of circular dependencies between npc.h and rooms-npc.h, I have splittd rooms-npc into two modules, npc_move and rooms_npc. npc_move contains the npc_mov struct and relevant methods, and rooms-npc now only has npcs_in_room struct and related methods

torresszy commented 3 years ago

Another problem is to update all the tests related to the npc and npc_mov structs since they are modified. I have already created another issue for that and it is in the backlog now.

xlewellen commented 3 years ago

I have updated the Wiki page "NPC Design and Planning" to better reflect the changes in the NPC struct we have made, and will update to reflect future changes once the npc and npc_mov structs are fully integrated.

mbutera17 commented 3 years ago

The existing NPC Movement Design wiki was outdated, and I updated it to reflect progress made during this sprint detailed in Torres' comment above. These updates can be seen here. Further, on the NPC Design and Planning Wiki, there was no existing mention or link to the NPC Movement Design wiki (which I added).

lilyehsani commented 3 years ago

Issue Score: ✔️++

Comments: Great work overall! The updates of this issue are very thorough.