uchicago-cs / chiventure

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

Abstract action functions to work with items and NPCs #990

Open andrewg23 opened 3 years ago

andrewg23 commented 3 years ago

The current action functions only take in items. In order to implement NPC actions we will abstract these functions so that they can act on both items and NPCs.

We will also update the NPC: Player Interaction Design and Planning wiki page to reflect these new design choices.

andrewg23 commented 3 years ago

Moved game_action and game_action_effect struct out of item.h and into action_structs.h. Also created a union type of agent that can be either an item or an NPC. Agents are things that the player can perform actions on.

matiasp-10 commented 3 years ago

Adjusted functions in game_action.h to take in the new agent union type. Changed the action and action kind enums in action_structs.h to reflect actions for both items and NPCs.

andrewg23 commented 3 years ago

Created agent tags and added them to the game action struct as an indicator of whether an item or an NPC is being acted upon. We will have to update the implementation of the action functions to check what agent each action acts on.

matiasp-10 commented 3 years ago

Added do_all_effects implementation for agents. Added add_action functionality for NPCs. Finished up leftover elements of interface for game_action.h.

MaDDylan commented 3 years ago

do_npc_action (kind 4 action) was implemented in /actionmangement.c as well as a kind4_action_operation in the cli operations.c file. The functions are implemented in a skeleton manner, still requiring a technical implementation of global NPC dialogue.

matiasp-10 commented 3 years ago

After a discussion, we decided to leave action attribute conditions and action inventory conditions functions in game_action just for items, as it is currently uncertain whether NPCs will have attributed conditions or have stats as players do. This decision was made taking into account the currently available NPC action functions and in drawing lines in terms of necessary abstraction for both items and NPCs.

matiasp-10 commented 3 years ago

Reorganized game_action files to match each other. Finished up last few implementation details for game_action.c to work with NPCs as well.

MaDDylan commented 3 years ago

Abstractions into action management are complete, the module requires a testing suite, especially for the new implementations of kind 4, 5, and 6 which have been completed within action management (actionmanagement.c) and cli (operations.c.) modules.

andrewg23 commented 3 years ago

After merging the dev branch into the npc/actions branch, there were many errors when building chiventure. We found the problem to come from the many circular dependencies that exist. Issue #1112 addresses fixing these circular dependencies. We implemented a temporary fix by adding many forward declarations to many header files. The forward declarations removed the errors but there are still many warnings that need to be addressed.

MaDDylan commented 3 years ago

The current state of the action abstraction causes the agent_t union type, test_item_item.c and test_item.c to no longer pass. The union type was defined to abstract action-specific functions (previously only utilized for items) to also work with NPCs. Although for the abstraction to be completed, all instances of items in item-specific action functions must also be passed by agent_t. The abstractions are currently restricted to the action functions used by items and NPCs. This is causing segfaults when other item helper functions augment the item, causing a duplication with incomplete fields.

MaDDylan commented 3 years ago

Continuing NPC actions abstraction: Pay close attention to how WDL, Game_State, CLI, NPC and Action management exchange and update npcs/items to assure that no instances lead to duplicated and incomplete items or NPCs. Changes that seem natural are often more complicated then they seem. Consider the tests as well as the implementation when refactoring item/npc parameters to agent_t

Recomended restructuring for agent_t: typedef union agent_type { item_t item; npc_t npc; } agent_type_t; enum agent_tag {ITEMS, NPCS}; typedef struct agent { enum agent_tag tag; agent_type_t agent_type; } agent_t;

matiasp-10 commented 3 years ago

I believe this was intended to be moved to the backlog by Dylan two days ago, but it is still showing up as being on Sprint 3 for me, so I'll move the "Milestone" to Backlog as well to stay consistent.