From 2516f21b845df0f962e9db8140fab64db67d7130 Mon Sep 17 00:00:00 2001 From: Zachary Samuel Pizer Date: Tue, 1 Jun 2021 14:09:32 -0500 Subject: [PATCH 01/14] looking for bug --- tests/quests/test_quests_state.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/quests/test_quests_state.c b/tests/quests/test_quests_state.c index e4765a6fe1..11424015ee 100644 --- a/tests/quests/test_quests_state.c +++ b/tests/quests/test_quests_state.c @@ -7,6 +7,7 @@ #include "playerclass/class.h" #include "game-state/item.h" +//Trying to force a build /* Creates a sample class. Taken from test_class.c */ class_t* generate_test_class() { @@ -309,4 +310,4 @@ Test(quest,complete_quest) cr_assert_str_eq(res->item_id, "test_item", "quest_completed failed to reward the item"); -} \ No newline at end of file +} From db3aca05ffc139bde3829515f692fda7fc4e7ad0 Mon Sep 17 00:00:00 2001 From: Zachary Samuel Pizer Date: Tue, 1 Jun 2021 14:32:15 -0500 Subject: [PATCH 02/14] reverted comment --- tests/quests/test_quests_state.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/quests/test_quests_state.c b/tests/quests/test_quests_state.c index 11424015ee..962b99fce8 100644 --- a/tests/quests/test_quests_state.c +++ b/tests/quests/test_quests_state.c @@ -7,7 +7,6 @@ #include "playerclass/class.h" #include "game-state/item.h" -//Trying to force a build /* Creates a sample class. Taken from test_class.c */ class_t* generate_test_class() { From 89b0b7953864ca0996cc4d1a17bb77d973ec6f09 Mon Sep 17 00:00:00 2001 From: Zachary Samuel Pizer Date: Tue, 1 Jun 2021 19:07:40 -0500 Subject: [PATCH 03/14] initial changes to example --- src/quests/examples/quest-example.c | 80 +++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 17 deletions(-) diff --git a/src/quests/examples/quest-example.c b/src/quests/examples/quest-example.c index 5a963aa52c..764980d250 100644 --- a/src/quests/examples/quest-example.c +++ b/src/quests/examples/quest-example.c @@ -18,7 +18,7 @@ const char *banner = " | ╚═════╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ |\n" " | _________________________________________________________________________________|_____\n" " | / /\n" - " | / EXAMPLE PROGRAM - RPG-NPC TEAM /\n" + " | / EXAMPLE PROGRAM - QUESTS TEAM /\n" " \\_/______________________________________________________________________________________/\n"; quest_t *quest; @@ -43,15 +43,27 @@ chiventure_ctx_t *create_sample_ctx() game->curr_room = room1; create_connection(game, "room1", "room2", "NORTH"); create_connection(game, "room2", "room3", "EAST"); - create_connection(game, "room3", "room4", "EAST"); + create_connection(game, "room2", "room4", "WEST"); item_t *emerald = item_new("EMERALD","It is an emerald", "This item must be taken for the first mission. Steal it!"); add_item_to_room(room2, emerald); - item_t *POTION = item_new("POTION","It is a bottle that holds a mysterious liquid", + item_t *BLUEPOTION = item_new("BLUE POTION","It is a bottle that holds a mysterious blue liquid", "This item must be taken for second mission. Drink it!"); - add_item_to_room(room4, POTION); + add_item_to_room(room1, BLUEPOTION); + + item_t *GREENPOTION = item_new("GREEN POTION","It is a bottle that holds a mysterious green liquid", + "This item must be taken for second mission. Drink it!"); + add_item_to_room(room1, GREENPOTION); + + item_t *NECKLACE = item_new("ROYAL NECKLACE", "It is a diamond necklace that has royal significance", + "This item must be taken for another mission. Keep it!"); + add_item_to_room(room3, NECKLACE); + + item_t *HERB = item_new("HERB", "It is a herb plant that has medicinal properties", + "This item can cure a bad cough"); + add_item_to_room(room4, HERB); add_action(emerald, "STEAL", "[You take the Emerald] " "This is the object that the villager was talking about!", @@ -60,6 +72,7 @@ chiventure_ctx_t *create_sample_ctx() add_action(POTION, "SIP", "[You sip the Potion] Suddenly you realize how you got here.", "You can't drink the POTION."); + chiventure_ctx_t *ctx = chiventure_ctx_new(game); return ctx; @@ -84,7 +97,7 @@ char *start_quest_operation(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx if(quest->status == 1) { - return "You have started the quest. Begin by speaking to the villager over there."; + return "You have started the quest. There are two potions in front of you: BLUE and GREEN. Pick one"; } else { @@ -92,6 +105,29 @@ char *start_quest_operation(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx } } +char *take_potion(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) +{ + game_t *game = ctx->game; + if (game == NULL || game->curr_room == NULL) + { + return "Room not found! Error!\n"; + } + + /* This operation has to be called with one parameter */ + if (tokens[1] != NULL) + { + return "I do not know what you mean."; + } + + if (!strcmp(tokens[0], "BLUE")){ + return "You chose the BLUE potion. You feel strong. Outside, you hear a rumbling sound." + } else if (!strcmp(tokens[0], "GREEN")){ + return "You chose the GREEN potion. You feel clever. Outside you hear two people talking." + } else{ + return "I do not know what you mean."; + } +} + char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) { @@ -174,31 +210,41 @@ int main(int argc, char **argv) room_t *initial_room; HASH_FIND(hh, ctx->game->all_rooms, "room1", strlen("room1"), initial_room); + room_t *second_room; + HASH_FIND(hh, ctx->game->all_rooms, "room2", strlen("room2"), second_room); + room_t *third_room; HASH_FIND(hh, ctx->game->all_rooms, "room3", strlen("room3"), third_room); - room_t *last_room; - HASH_FIND(hh, ctx->game->all_rooms, "room4", strlen("room4"), last_room); + room_t *fourth_room; + HASH_FIND(hh, ctx->game->all_rooms, "room4", strlen("room4"), fourth_room); char *npc_id = "Villager-Jim"; - npc_mov_t* npc1_movement = npc_mov_new(NPC_MOV_DEFINITE, initial_room); - npc_t *npc1 = npc_new(npc_id,"first npc","this is the npc that holds the quest", - NULL, npc1_movement, false); - npcs_in_room_1 = npcs_in_room_new("room1"); - add_npc_to_room(npcs_in_room_1, npc1); - npcs_in_room_3 = npcs_in_room_new("room3"); - + npc_t *npc1 = npc_new(npc_id,"first npc","this is the npc that holds a branch of a quest", + NULL, NULL, false); + + char *npc_id = "Ogre-Rick"; + npc_t *npc1 = npc_new(npc_id,"second npc","this is the npc that holds a branch of a quest", + NULL, NULL, false); + + npcs_in_room_2 = npcs_in_room_new("room2"); + add_npc_to_room(npcs_in_room_2, npc1); + add_npc_to_room(npcs_in_room_2, npc2); + + npc1_movement = npc_mov_new("Villager-Jim",NPC_MOV_DEFINITE,initial_room); extend_path_definite(npc1->movement,third_room); - extend_path_definite(npc1->movement,last_room); + npc2_movement = npc_mov_new("Ogre-Rick",NPC_MOV_DEFINITE,initial_room); + extend_path_definite(npc2->movement,fourth_room); item_t *item1 = malloc(sizeof(item_t)); - HASH_FIND(hh, ctx->game->all_items, "EMERALD", strlen("EMERALD"), item1); + HASH_FIND(hh, ctx->game->all_items, "BLUEPOTION", strlen("BLUEPOTION"), item1); item_t *item2 = malloc(sizeof(item_t)); - HASH_FIND(hh, ctx->game->all_items, "POTION", strlen("POTION"), item2); + HASH_FIND(hh, ctx->game->all_items, "GREENPOTION", strlen("GREENPOTION"), item2); item_t *reward = item_new("KEY", "this is a key that unlocks all secrets", "Reward for completing the quest."); + quest = quest_new(1, NULL, reward); mission_t *mission1 = mission_new(item1,npc1); mission_t *mission2 = mission_new(item2,npc1); From 9aba95875c4e587db2178ef1285568355ec47d19 Mon Sep 17 00:00:00 2001 From: Zachary Samuel Pizer Date: Tue, 1 Jun 2021 22:21:29 -0500 Subject: [PATCH 04/14] working on example --- src/quests/examples/quest-example.c | 169 ++++++++++++++++++---------- 1 file changed, 111 insertions(+), 58 deletions(-) diff --git a/src/quests/examples/quest-example.c b/src/quests/examples/quest-example.c index 764980d250..cf57925b90 100644 --- a/src/quests/examples/quest-example.c +++ b/src/quests/examples/quest-example.c @@ -22,9 +22,16 @@ const char *banner = " \\_/______________________________________________________________________________________/\n"; quest_t *quest; -npcs_in_room_t *npcs_in_room_1; +npcs_in_room_t *npcs_in_room_2; npcs_in_room_t *npcs_in_room_3; +npcs_in_room_t *npcs_in_room_4; +npcs_in_room_t *npcs_in_room_5; npc_t *npc1; +npc_t *npc2; +npc_t *npc3; +npc_t *npc4; +npc_mov_t *npc1_movement; +npc_mov_t *npc2_movement; /* Creates a sample in-memory game */ chiventure_ctx_t *create_sample_ctx() @@ -36,14 +43,17 @@ chiventure_ctx_t *create_sample_ctx() room_t *room2 = room_new("room2", "This is room 2", "Truly, this is the second room."); room_t *room3 = room_new("room3", "This is room 3", "Exactly, this is the third room."); room_t *room4 = room_new("room4", "This is room 4", "Yes, this is the fourth room."); + room_t *room5 = room_new("room5", "This is room 5", "Indeed, this is the fifth room."); add_room_to_game(game, room1); add_room_to_game(game, room2); add_room_to_game(game, room3); add_room_to_game(game, room4); + add_room_to_game(game, room5); game->curr_room = room1; create_connection(game, "room1", "room2", "NORTH"); create_connection(game, "room2", "room3", "EAST"); create_connection(game, "room2", "room4", "WEST"); + create_connection(game, "room2", "room5", "SOUTH"); item_t *emerald = item_new("EMERALD","It is an emerald", "This item must be taken for the first mission. Steal it!"); @@ -53,11 +63,11 @@ chiventure_ctx_t *create_sample_ctx() "This item must be taken for second mission. Drink it!"); add_item_to_room(room1, BLUEPOTION); - item_t *GREENPOTION = item_new("GREEN POTION","It is a bottle that holds a mysterious green liquid", - "This item must be taken for second mission. Drink it!"); - add_item_to_room(room1, GREENPOTION); + item_t *GREENPILL = item_new("GREEN PILL","It is a green tablet. Could it be medicine?", + "This item must be taken for second mission. Take it!"); + add_item_to_room(room1, GREENPILL); - item_t *NECKLACE = item_new("ROYAL NECKLACE", "It is a diamond necklace that has royal significance", + item_t *NECKLACE = item_new("NECKLACE", "It is a diamond necklace that has royal significance", "This item must be taken for another mission. Keep it!"); add_item_to_room(room3, NECKLACE); @@ -69,8 +79,11 @@ chiventure_ctx_t *create_sample_ctx() "This is the object that the villager was talking about!", "You can't pickup the emerald."); - add_action(POTION, "SIP", "[You sip the Potion] Suddenly you realize how you got here.", + add_action(BLUEPOTION, "SIP", "[You sip the Potion] You feel strong.", "You can't drink the POTION."); + + add_action(GREENPILL, "CONSUME", "[You take the Pill] You feel clever.", + "You can't drink the PILL."); chiventure_ctx_t *ctx = chiventure_ctx_new(game); @@ -105,28 +118,6 @@ char *start_quest_operation(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx } } -char *take_potion(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) -{ - game_t *game = ctx->game; - if (game == NULL || game->curr_room == NULL) - { - return "Room not found! Error!\n"; - } - - /* This operation has to be called with one parameter */ - if (tokens[1] != NULL) - { - return "I do not know what you mean."; - } - - if (!strcmp(tokens[0], "BLUE")){ - return "You chose the BLUE potion. You feel strong. Outside, you hear a rumbling sound." - } else if (!strcmp(tokens[0], "GREEN")){ - return "You chose the GREEN potion. You feel clever. Outside you hear two people talking." - } else{ - return "I do not know what you mean."; - } -} char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) { @@ -143,13 +134,18 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) return "I do not know what you mean."; } - if (((strcmp(ctx->game->curr_room->room_id,"room1")) == 0) && ((get_quest_status(quest)) == 1)) + if (((strcmp(ctx->game->curr_room->room_id,"room2")) == 0) && ((get_quest_status(quest)) == 1)) { move_npc_definite(npc1->movement); - char* id = strcpy(id,npc1->npc_id); - char *output1 = strcat(id, - ": I see you have started the quest, go to room2 to find the secret item, then " - "come meet me in room3 to complete the first mission."); + move_npc_definite(npc2->movement); + char* id1 = strcpy(id1, npc1->npc_id); + char* id2 = strcpy(id2, npc2->npc_id); + char *output1 = strcat(id1, + ": Get away from me you ogre. Your army of cockroaches have eaten all of my bread.\n"); + char *output2 = strcat(id2, ": But, Sire! My wife is ill. She needs your medicine.\n"); + char *thoughts = "You wonder if there is a way to solve their problems. Try exploring."; + strcat(output1, output2); + strcat(output1, thoughts); return output1; } else if (((strcmp(ctx->game->curr_room->room_id,"room3")) == 0) && ((get_quest_status(quest)) == 1)) @@ -159,26 +155,24 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) HASH_FIND(hh, ctx->game->all_items, "EMERALD", strlen("EMERALD"), item); npc_t *npc = malloc(sizeof(npc_t)); - HASH_FIND(hh, npcs_in_room_1->npc_list, "Villager-Jim", strlen("Villager-Jim"), npc); + HASH_FIND(hh, npcs_in_room_2->npc_list, "Villager-Jim", strlen("Villager-Jim"), npc); //complete_achievement(quest, item, npc); quest->achievement_tree->achievement->completed = 1; quest->status = 2; char* id1 = strcpy(id1,npc1->npc_id); - char *output2 = strcat(id1,": Congratulations on completing " - "the first achievement of this quest. " - "Now onto the next, continue through that door into the next room " - "to continue."); + char *output2 = strcat(id1,": Thank you for helping me resupply my shop. " + "Those cockroaches are so pesky. For your efforts I'd like to give you this emerald. "); return output2; } - else if (((strcmp(ctx->game->curr_room->room_id,"room4")) == 0) && ((get_quest_status(quest)) == 2)) + else if (((strcmp(ctx->game->curr_room->room_id,"room4")) == 0) && ((get_quest_status(quest)) == 1)) { item_t *item = malloc(sizeof(item_t)); HASH_FIND(hh, ctx->game->all_items, "POTION", strlen("POTION"), item); npc_t *npc = malloc(sizeof(npc_t)); - HASH_FIND(hh, npcs_in_room_1->npc_list, "Villager-Jim", strlen("Villager-Jim"), npc); + HASH_FIND(hh, npcs_in_room_2->npc_list, "Villager-Jim", strlen("Villager-Jim"), npc); quest->achievement_tree->lmostchild->achievement->completed = 1; @@ -203,6 +197,42 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) } } + +quest_t *make_sample_quest(long int quest_id, item_t *reward, + npc_t *npc1, npc_t *npc2, npc_t *npc3, npc_t *npc4, + item_t *item1, item_t *item2, item_t *item3, + item_t *item4, item_t *item5) +{ + quest_t *quest = quest_new(quest_id, NULL, reward); + + + mission_t *kill_dragon = mission_new(NULL, npc1); // kill dragon + mission_t *stock_store = mission_new(item3, npc2); //stock store with bread + mission_t *give_herb = mission_new(item4, npc3); //give herb + mission_t *give_necklace = mission_new(item5, npc4); //give necklace + mission_t *take_blue_potion = mission_new(item1, NULL); + mission_t *take_green_pill = mission_new(item2, NULL); + + achievement_t *achievement1 = achievement_new(take_blue_potion, + "Take blue potion"); + achievement_t *achievement2 = achievement_new(take_green_pill, + "Take green pill"); + achievement_t *achievement3 = achievement_new(kill_dragon,"Kill the dragon"); + achievement_t *achievement4 = achievement_new(stock_store, "Stock the store"); + achievement_t *achievement5 = achievement_new(give_herb, "Heal the Sick"); + achievement_t *achievement6 = achievement_new(give_necklace, "Return the necklace"); + + add_achievement_to_quest(quest, achievement1, "The first mission"); + add_achievement_to_quest(quest, achievement2, "The first mission"); + add_achievement_to_quest(quest, achievement3, "Take blue potion"); + add_achievement_to_quest(quest, achievement4, "Take green pill"); + add_achievement_to_quest(quest, achievement5, "Take green pill"); + add_achievement_to_quest(quest, achievement6, "Take green pill"); + + return quest; +} + + int main(int argc, char **argv) { chiventure_ctx_t *ctx = create_sample_ctx(); @@ -219,50 +249,73 @@ int main(int argc, char **argv) room_t *fourth_room; HASH_FIND(hh, ctx->game->all_rooms, "room4", strlen("room4"), fourth_room); - char *npc_id = "Villager-Jim"; - npc_t *npc1 = npc_new(npc_id,"first npc","this is the npc that holds a branch of a quest", + room_t *fifth_room; + HASH_FIND(hh, ctx->game->all_rooms, "room5", strlen("room5"), fourth_room); + + + char *npc_id1 = "Puff-Dragon"; + npc_t *npc1 = npc_new(npc_id1,"first npc","this is the npc that holds a branch of a quest", + NULL, NULL, false); + + char *npc_id2 = "Villager-Jim"; + npc_t *npc2 = npc_new(npc_id2,"second npc","this is the npc that holds a branch of a quest", NULL, NULL, false); - char *npc_id = "Ogre-Rick"; - npc_t *npc1 = npc_new(npc_id,"second npc","this is the npc that holds a branch of a quest", + char *npc_id3 = "Ogre-Rick"; + npc_t *npc3 = npc_new(npc_id3,"third npc","this is the npc that holds a branch of a quest", + NULL, NULL, false); + + char *npc_id4 = "Princess Plum"; + npc_t *npc4 = npc_new(npc_id4,"fourth npc","this is the npc that holds a branch of a quest", NULL, NULL, false); + + npcs_in_room_2 = npcs_in_room_new("room2"); - add_npc_to_room(npcs_in_room_2, npc1); - add_npc_to_room(npcs_in_room_2, npc2); + add_npc_to_room(npcs_in_room_2, npc2); + add_npc_to_room(npcs_in_room_2, npc3); - npc1_movement = npc_mov_new("Villager-Jim",NPC_MOV_DEFINITE,initial_room); + npcs_in_room_5 = npcs_in_room_new("room5"); + add_npc_to_room(npcs_in_room_5, npc1); + add_npc_to_room(npcs_in_room_5, npc4); + + npc1_movement = npc_mov_new(NPC_MOV_DEFINITE,second_room); extend_path_definite(npc1->movement,third_room); - npc2_movement = npc_mov_new("Ogre-Rick",NPC_MOV_DEFINITE,initial_room); + npc2_movement = npc_mov_new(NPC_MOV_DEFINITE,second_room); extend_path_definite(npc2->movement,fourth_room); item_t *item1 = malloc(sizeof(item_t)); HASH_FIND(hh, ctx->game->all_items, "BLUEPOTION", strlen("BLUEPOTION"), item1); item_t *item2 = malloc(sizeof(item_t)); - HASH_FIND(hh, ctx->game->all_items, "GREENPOTION", strlen("GREENPOTION"), item2); + HASH_FIND(hh, ctx->game->all_items, "GREENPILL", strlen("GREENPILL"), item2); + + item_t *item3 = malloc(sizeof(item_t)); + HASH_FIND(hh, ctx->game->all_items, "BREAD", strlen("BREAD"), item3); + + item_t *item4 = malloc(sizeof(item_t)); + HASH_FIND(hh, ctx->game->all_items, "HERB", strlen("HERB"), item4); + + item_t *item5 = malloc(sizeof(item_t)); + HASH_FIND(hh, ctx->game->all_items, "NECKLACE", strlen("NECKLACE"), item5); item_t *reward = item_new("KEY", "this is a key that unlocks all secrets", "Reward for completing the quest."); - quest = quest_new(1, NULL, reward); - mission_t *mission1 = mission_new(item1,npc1); - mission_t *mission2 = mission_new(item2,npc1); - achievement_t *achievement1 = achievement_new(mission1, "a1"); - achievement_t *achievement2 = achievement_new(mission2, "a2"); - add_achievement_to_quest(quest, achievement1, NULL); - add_achievement_to_quest(quest, achievement2, "a1"); + quest_t *quest = make_sample_quest(1, reward, npc1, npc2, npc3, npc4, item1, item2, item3, item4, item5); add_entry("QUEST", start_quest_operation, NULL, ctx->cli_ctx->table); add_entry("TALK", talk_to_npc, NULL, ctx->cli_ctx->table); - action_type_t steal_action = {"STEAL", ITEM}; - add_entry(steal_action.c_name, kind1_action_operation, &steal_action, ctx->cli_ctx->table); + action_type_t consume_action = {"CONSUME", ITEM}; + add_entry(consume_action.c_name, kind1_action_operation, &consume_action, ctx->cli_ctx->table); action_type_t drink_action = {"SIP", ITEM}; add_entry(drink_action.c_name, kind1_action_operation, &drink_action, ctx->cli_ctx->table); + + /* Start chiventure */ start_ui(ctx, banner); From b4b2f11e767a2e6939ccc25288563a6e9ca8bfe7 Mon Sep 17 00:00:00 2001 From: Zachary Samuel Pizer Date: Wed, 2 Jun 2021 11:59:29 -0500 Subject: [PATCH 05/14] seg fault --- src/quests/examples/quest-example.c | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/quests/examples/quest-example.c b/src/quests/examples/quest-example.c index cf57925b90..a035a83560 100644 --- a/src/quests/examples/quest-example.c +++ b/src/quests/examples/quest-example.c @@ -30,7 +30,7 @@ npc_t *npc1; npc_t *npc2; npc_t *npc3; npc_t *npc4; -npc_mov_t *npc1_movement; +npc_mov_t *npc3_movement; npc_mov_t *npc2_movement; /* Creates a sample in-memory game */ @@ -136,13 +136,13 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) if (((strcmp(ctx->game->curr_room->room_id,"room2")) == 0) && ((get_quest_status(quest)) == 1)) { - move_npc_definite(npc1->movement); move_npc_definite(npc2->movement); - char* id1 = strcpy(id1, npc1->npc_id); + move_npc_definite(npc3->movement); char* id2 = strcpy(id2, npc2->npc_id); - char *output1 = strcat(id1, + char* id3 = strcpy(id3, npc3->npc_id); + char *output1 = strcat(id2, ": Get away from me you ogre. Your army of cockroaches have eaten all of my bread.\n"); - char *output2 = strcat(id2, ": But, Sire! My wife is ill. She needs your medicine.\n"); + char *output2 = strcat(id3, ": But, Sire! My wife is ill. She needs your medicine.\n"); char *thoughts = "You wonder if there is a way to solve their problems. Try exploring."; strcat(output1, output2); strcat(output1, thoughts); @@ -152,7 +152,7 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) { //move_npc_definite(npc1_movement); item_t *item = malloc(sizeof(item_t)); - HASH_FIND(hh, ctx->game->all_items, "EMERALD", strlen("EMERALD"), item); + HASH_FIND(hh, ctx->game->all_items, "BREAD", strlen("BREAD"), item); npc_t *npc = malloc(sizeof(npc_t)); HASH_FIND(hh, npcs_in_room_2->npc_list, "Villager-Jim", strlen("Villager-Jim"), npc); @@ -160,19 +160,19 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) //complete_achievement(quest, item, npc); quest->achievement_tree->achievement->completed = 1; quest->status = 2; - char* id1 = strcpy(id1,npc1->npc_id); - char *output2 = strcat(id1,": Thank you for helping me resupply my shop. " - "Those cockroaches are so pesky. For your efforts I'd like to give you this emerald. "); + char* id = strcpy(id,npc2->npc_id); + char *output = strcat(id,": Thank you for helping me resupply my shop. " + "Those cockroaches are so pesky. For your efforts I'd like to give you this key. "); - return output2; + return output; } else if (((strcmp(ctx->game->curr_room->room_id,"room4")) == 0) && ((get_quest_status(quest)) == 1)) { item_t *item = malloc(sizeof(item_t)); - HASH_FIND(hh, ctx->game->all_items, "POTION", strlen("POTION"), item); + HASH_FIND(hh, ctx->game->all_items, "HERB", strlen("HERB"), item); npc_t *npc = malloc(sizeof(npc_t)); - HASH_FIND(hh, npcs_in_room_2->npc_list, "Villager-Jim", strlen("Villager-Jim"), npc); + HASH_FIND(hh, npcs_in_room_2->npc_list, "Ogre-Rick", strlen("Ogre-Rick"), npc); quest->achievement_tree->lmostchild->achievement->completed = 1; @@ -279,10 +279,10 @@ int main(int argc, char **argv) add_npc_to_room(npcs_in_room_5, npc1); add_npc_to_room(npcs_in_room_5, npc4); - npc1_movement = npc_mov_new(NPC_MOV_DEFINITE,second_room); - extend_path_definite(npc1->movement,third_room); npc2_movement = npc_mov_new(NPC_MOV_DEFINITE,second_room); - extend_path_definite(npc2->movement,fourth_room); + extend_path_definite(npc2_movement,third_room); + npc3_movement = npc_mov_new(NPC_MOV_DEFINITE,second_room); + extend_path_definite(npc3_movement,fourth_room); item_t *item1 = malloc(sizeof(item_t)); HASH_FIND(hh, ctx->game->all_items, "BLUEPOTION", strlen("BLUEPOTION"), item1); From 90bcd4f15f6eb2fe6d589afceec42c87120bc779 Mon Sep 17 00:00:00 2001 From: Olivia Niena Jerdee Date: Wed, 2 Jun 2021 14:22:32 -0500 Subject: [PATCH 06/14] Changed example to try to simplify and get to run, currently segfaults at executable #1088 --- src/quests/examples/quest-example.c | 153 +++++++++------------------- 1 file changed, 50 insertions(+), 103 deletions(-) diff --git a/src/quests/examples/quest-example.c b/src/quests/examples/quest-example.c index a035a83560..7915174120 100644 --- a/src/quests/examples/quest-example.c +++ b/src/quests/examples/quest-example.c @@ -21,17 +21,14 @@ const char *banner = " | / EXAMPLE PROGRAM - QUESTS TEAM /\n" " \\_/______________________________________________________________________________________/\n"; +player_t *player; quest_t *quest; npcs_in_room_t *npcs_in_room_2; npcs_in_room_t *npcs_in_room_3; -npcs_in_room_t *npcs_in_room_4; -npcs_in_room_t *npcs_in_room_5; + npc_t *npc1; npc_t *npc2; -npc_t *npc3; -npc_t *npc4; -npc_mov_t *npc3_movement; -npc_mov_t *npc2_movement; + /* Creates a sample in-memory game */ chiventure_ctx_t *create_sample_ctx() @@ -43,21 +40,20 @@ chiventure_ctx_t *create_sample_ctx() room_t *room2 = room_new("room2", "This is room 2", "Truly, this is the second room."); room_t *room3 = room_new("room3", "This is room 3", "Exactly, this is the third room."); room_t *room4 = room_new("room4", "This is room 4", "Yes, this is the fourth room."); - room_t *room5 = room_new("room5", "This is room 5", "Indeed, this is the fifth room."); + //room_t *room5 = room_new("room5", "This is room 5", "Indeed, this is the fifth room."); + add_room_to_game(game, room1); add_room_to_game(game, room2); add_room_to_game(game, room3); add_room_to_game(game, room4); - add_room_to_game(game, room5); + //add_room_to_game(game, room5); + game->curr_room = room1; create_connection(game, "room1", "room2", "NORTH"); create_connection(game, "room2", "room3", "EAST"); create_connection(game, "room2", "room4", "WEST"); - create_connection(game, "room2", "room5", "SOUTH"); + //create_connection(game, "room2", "room5", "SOUTH"); - item_t *emerald = item_new("EMERALD","It is an emerald", - "This item must be taken for the first mission. Steal it!"); - add_item_to_room(room2, emerald); item_t *BLUEPOTION = item_new("BLUE POTION","It is a bottle that holds a mysterious blue liquid", "This item must be taken for second mission. Drink it!"); @@ -67,17 +63,13 @@ chiventure_ctx_t *create_sample_ctx() "This item must be taken for second mission. Take it!"); add_item_to_room(room1, GREENPILL); - item_t *NECKLACE = item_new("NECKLACE", "It is a diamond necklace that has royal significance", - "This item must be taken for another mission. Keep it!"); - add_item_to_room(room3, NECKLACE); - item_t *HERB = item_new("HERB", "It is a herb plant that has medicinal properties", "This item can cure a bad cough"); add_item_to_room(room4, HERB); - add_action(emerald, "STEAL", "[You take the Emerald] " - "This is the object that the villager was talking about!", - "You can't pickup the emerald."); + add_action(HERB, "TAKE", "[You take the Herb] " + "This is the herb that the ogre was talking about!", + "You can't pickup the herb."); add_action(BLUEPOTION, "SIP", "[You sip the Potion] You feel strong.", "You can't drink the POTION."); @@ -134,63 +126,35 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) return "I do not know what you mean."; } - if (((strcmp(ctx->game->curr_room->room_id,"room2")) == 0) && ((get_quest_status(quest)) == 1)) - { - move_npc_definite(npc2->movement); - move_npc_definite(npc3->movement); - char* id2 = strcpy(id2, npc2->npc_id); - char* id3 = strcpy(id3, npc3->npc_id); - char *output1 = strcat(id2, - ": Get away from me you ogre. Your army of cockroaches have eaten all of my bread.\n"); - char *output2 = strcat(id3, ": But, Sire! My wife is ill. She needs your medicine.\n"); - char *thoughts = "You wonder if there is a way to solve their problems. Try exploring."; - strcat(output1, output2); - strcat(output1, thoughts); - return output1; - } - else if (((strcmp(ctx->game->curr_room->room_id,"room3")) == 0) && ((get_quest_status(quest)) == 1)) - { - //move_npc_definite(npc1_movement); - item_t *item = malloc(sizeof(item_t)); - HASH_FIND(hh, ctx->game->all_items, "BREAD", strlen("BREAD"), item); + if (((strcmp(ctx->game->curr_room->room_id,"room2")) == 0) && ((quest->status == 2))) { - npc_t *npc = malloc(sizeof(npc_t)); - HASH_FIND(hh, npcs_in_room_2->npc_list, "Villager-Jim", strlen("Villager-Jim"), npc); + char *output1 = strcat("Ogre-Rick", + ": I see you ate that green pill I left to the south to alert someone about my wife's condition. She is very ill and needs help. Can you get an herb or find a doctor for her?"); + return output1; - //complete_achievement(quest, item, npc); quest->achievement_tree->achievement->completed = 1; - quest->status = 2; - char* id = strcpy(id,npc2->npc_id); - char *output = strcat(id,": Thank you for helping me resupply my shop. " - "Those cockroaches are so pesky. For your efforts I'd like to give you this key. "); + quest->status = 3; - return output; - } - else if (((strcmp(ctx->game->curr_room->room_id,"room4")) == 0) && ((get_quest_status(quest)) == 1)) - { - item_t *item = malloc(sizeof(item_t)); - HASH_FIND(hh, ctx->game->all_items, "HERB", strlen("HERB"), item); - - npc_t *npc = malloc(sizeof(npc_t)); - HASH_FIND(hh, npcs_in_room_2->npc_list, "Ogre-Rick", strlen("Ogre-Rick"), npc); + } + else if ((strcmp(ctx->game->curr_room->room_id,"room3") == 0) && (quest->status == 3)) { - quest->achievement_tree->lmostchild->achievement->completed = 1; + char *output2 = strcat("Doctor-Dave", + ": Ogre-Rick's wife is sick? I will head west now to treat her."); + return output2; + //complete_achievement(quest, item, npc); + quest->achievement_tree->achievement->completed = 1; if ((is_quest_completed(quest)) == 1) { item_t *reward = complete_quest(quest); add_item_to_player(ctx->game->curr_player, reward); - char* id2 = strcpy(id2,npc1->npc_id); - char* output3 = strcat(id2, ": Congratulations" + char* output3 = strcat("Ogre-Rick", ": Thanks so much for finding a doctor! Congratulations" " on completing the quest, your reward is a key that should " "help you on your adventure. You will find it in your inventory."); return output3; } - else - { - return "So close yet so far"; - } - } + + } else { return "There is no one to talk to!"; @@ -199,17 +163,16 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) quest_t *make_sample_quest(long int quest_id, item_t *reward, - npc_t *npc1, npc_t *npc2, npc_t *npc3, npc_t *npc4, - item_t *item1, item_t *item2, item_t *item3, - item_t *item4, item_t *item5) + npc_t *npc1, npc_t *npc2, + item_t *item1, item_t *item2, item_t *item3) { quest_t *quest = quest_new(quest_id, NULL, reward); - mission_t *kill_dragon = mission_new(NULL, npc1); // kill dragon - mission_t *stock_store = mission_new(item3, npc2); //stock store with bread - mission_t *give_herb = mission_new(item4, npc3); //give herb - mission_t *give_necklace = mission_new(item5, npc4); //give necklace + //mission_t *kill_dragon = mission_new(NULL, npc1); // kill dragon + mission_t *find_ogre = mission_new(NULL, npc1); //talk to ogre + mission_t *find_doctor = mission_new(NULL, npc2); //talk to doctor + mission_t *find_herb = mission_new(item3, NULL); //find herb mission_t *take_blue_potion = mission_new(item1, NULL); mission_t *take_green_pill = mission_new(item2, NULL); @@ -217,17 +180,17 @@ quest_t *make_sample_quest(long int quest_id, item_t *reward, "Take blue potion"); achievement_t *achievement2 = achievement_new(take_green_pill, "Take green pill"); - achievement_t *achievement3 = achievement_new(kill_dragon,"Kill the dragon"); - achievement_t *achievement4 = achievement_new(stock_store, "Stock the store"); - achievement_t *achievement5 = achievement_new(give_herb, "Heal the Sick"); - achievement_t *achievement6 = achievement_new(give_necklace, "Return the necklace"); + //achievement_t *achievement3 = achievement_new(kill_dragon,"Kill the dragon"); + achievement_t *achievement3 = achievement_new(find_ogre, "Talk to Ogre-Rick"); + achievement_t *achievement4 = achievement_new(find_doctor, "Find a Doctor"); + achievement_t *achievement5 = achievement_new(find_herb, "Find the Herb"); + add_achievement_to_quest(quest, achievement1, "The first mission"); add_achievement_to_quest(quest, achievement2, "The first mission"); add_achievement_to_quest(quest, achievement3, "Take blue potion"); add_achievement_to_quest(quest, achievement4, "Take green pill"); add_achievement_to_quest(quest, achievement5, "Take green pill"); - add_achievement_to_quest(quest, achievement6, "Take green pill"); return quest; } @@ -249,40 +212,30 @@ int main(int argc, char **argv) room_t *fourth_room; HASH_FIND(hh, ctx->game->all_rooms, "room4", strlen("room4"), fourth_room); - room_t *fifth_room; - HASH_FIND(hh, ctx->game->all_rooms, "room5", strlen("room5"), fourth_room); + //room_t *fifth_room; + //HASH_FIND(hh, ctx->game->all_rooms, "room5", strlen("room5"), fourth_room); - char *npc_id1 = "Puff-Dragon"; + /*char *npc_id1 = "Puff-Dragon"; npc_t *npc1 = npc_new(npc_id1,"first npc","this is the npc that holds a branch of a quest", - NULL, NULL, false); + NULL, NULL, false);*/ - char *npc_id2 = "Villager-Jim"; - npc_t *npc2 = npc_new(npc_id2,"second npc","this is the npc that holds a branch of a quest", - NULL, NULL, false); - char *npc_id3 = "Ogre-Rick"; - npc_t *npc3 = npc_new(npc_id3,"third npc","this is the npc that holds a branch of a quest", + char *npc_id1 = "Ogre-Rick"; + npc_t *npc1 = npc_new(npc_id1,"first npc","this is the npc that holds a branch of a quest", NULL, NULL, false); - char *npc_id4 = "Princess Plum"; - npc_t *npc4 = npc_new(npc_id4,"fourth npc","this is the npc that holds a branch of a quest", + char *npc_id2 = "Doctor-Dave"; + npc_t *npc2 = npc_new(npc_id2,"second npc","this is the npc that holds a branch of a quest", NULL, NULL, false); npcs_in_room_2 = npcs_in_room_new("room2"); - add_npc_to_room(npcs_in_room_2, npc2); - add_npc_to_room(npcs_in_room_2, npc3); + add_npc_to_room(npcs_in_room_2, npc1); - npcs_in_room_5 = npcs_in_room_new("room5"); - add_npc_to_room(npcs_in_room_5, npc1); - add_npc_to_room(npcs_in_room_5, npc4); - - npc2_movement = npc_mov_new(NPC_MOV_DEFINITE,second_room); - extend_path_definite(npc2_movement,third_room); - npc3_movement = npc_mov_new(NPC_MOV_DEFINITE,second_room); - extend_path_definite(npc3_movement,fourth_room); + npcs_in_room_3 = npcs_in_room_new("room3"); + add_npc_to_room(npcs_in_room_3, npc2); item_t *item1 = malloc(sizeof(item_t)); HASH_FIND(hh, ctx->game->all_items, "BLUEPOTION", strlen("BLUEPOTION"), item1); @@ -291,18 +244,12 @@ int main(int argc, char **argv) HASH_FIND(hh, ctx->game->all_items, "GREENPILL", strlen("GREENPILL"), item2); item_t *item3 = malloc(sizeof(item_t)); - HASH_FIND(hh, ctx->game->all_items, "BREAD", strlen("BREAD"), item3); - - item_t *item4 = malloc(sizeof(item_t)); - HASH_FIND(hh, ctx->game->all_items, "HERB", strlen("HERB"), item4); - - item_t *item5 = malloc(sizeof(item_t)); - HASH_FIND(hh, ctx->game->all_items, "NECKLACE", strlen("NECKLACE"), item5); + HASH_FIND(hh, ctx->game->all_items, "HERB", strlen("HERB"), item3); item_t *reward = item_new("KEY", "this is a key that unlocks all secrets", "Reward for completing the quest."); - quest_t *quest = make_sample_quest(1, reward, npc1, npc2, npc3, npc4, item1, item2, item3, item4, item5); + quest_t *quest = make_sample_quest(1, reward, npc1, npc2, item1, item2, item3); add_entry("QUEST", start_quest_operation, NULL, ctx->cli_ctx->table); From 5f666f9e0d4df98e653e3172a0df4e62b78c538c Mon Sep 17 00:00:00 2001 From: Zachary Samuel Pizer Date: Wed, 2 Jun 2021 15:17:07 -0500 Subject: [PATCH 07/14] fixed segfault --- src/quests/src/quests_state.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/quests/src/quests_state.c b/src/quests/src/quests_state.c index eb592bd6f3..ec8b624bc0 100644 --- a/src/quests/src/quests_state.c +++ b/src/quests/src/quests_state.c @@ -192,24 +192,22 @@ achievement_tree_t *find_parent(achievement_tree_t *tree, char *id) assert(tree != NULL); achievement_tree_t *cur = tree; - + cur = get_bottom_node(cur); while(cur != NULL) { - if(strcmp(cur->achievement->id, id) == 0) { return cur; } else if(cur->rsibling != NULL) { - cur = cur->rsibling; + cur = get_bottom_node(cur->rsibling); } - else if(cur->parent->rsibling != NULL) + else if(cur->parent != NULL) { - cur = cur->parent->rsibling; + cur = cur->parent; } - else - { + else{ return NULL; } } From 7f6f646a0a3cdb1570b49d67a30454ab99948a30 Mon Sep 17 00:00:00 2001 From: Olivia Niena Jerdee Date: Wed, 2 Jun 2021 16:12:51 -0500 Subject: [PATCH 08/14] Fixed assertion error but now doesn't run #1088 --- src/quests/examples/quest-example.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/quests/examples/quest-example.c b/src/quests/examples/quest-example.c index 7915174120..72f6b72fd8 100644 --- a/src/quests/examples/quest-example.c +++ b/src/quests/examples/quest-example.c @@ -166,8 +166,17 @@ quest_t *make_sample_quest(long int quest_id, item_t *reward, npc_t *npc1, npc_t *npc2, item_t *item1, item_t *item2, item_t *item3) { - quest_t *quest = quest_new(quest_id, NULL, reward); + mission_t *none = mission_new(NULL, NULL); + achievement_t *start = achievement_new(none, "The first mission"); + + /*achievement_tree_t *ach_tree = malloc(sizeof(achievement_tree_t)); + ach_tree->achievement = start; + ach_tree->parent = NULL; + ach_tree->rsibling = NULL; + ach_tree->lmostchild = NULL;*/ + quest_t *quest = quest_new(quest_id, NULL, reward); + add_achievement_to_quest(quest, start, "none"); //mission_t *kill_dragon = mission_new(NULL, npc1); // kill dragon mission_t *find_ogre = mission_new(NULL, npc1); //talk to ogre From 4abdabff45928ea62ba66a520b061000c723fb90 Mon Sep 17 00:00:00 2001 From: Olivia Niena Jerdee Date: Wed, 2 Jun 2021 16:31:51 -0500 Subject: [PATCH 09/14] Changed first mission to talking to witch #1088 --- src/quests/examples/quest-example.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/quests/examples/quest-example.c b/src/quests/examples/quest-example.c index 72f6b72fd8..3865c34b0e 100644 --- a/src/quests/examples/quest-example.c +++ b/src/quests/examples/quest-example.c @@ -23,11 +23,13 @@ const char *banner = player_t *player; quest_t *quest; +npcs_in_room_t *npcs_in_room_1; npcs_in_room_t *npcs_in_room_2; npcs_in_room_t *npcs_in_room_3; npc_t *npc1; npc_t *npc2; +npc_t *npc3; /* Creates a sample in-memory game */ @@ -126,7 +128,18 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) return "I do not know what you mean."; } - if (((strcmp(ctx->game->curr_room->room_id,"room2")) == 0) && ((quest->status == 2))) { + + if (((strcmp(ctx->game->curr_room->room_id,"room1")) == 0) && ((quest->status == 1))) { + + char *output0 = strcat("Witch-Eve", + ": Welcome, mortal! I have a quest for you! Consume the pill or drink the potion! Hehehehe..."); + return output0; + + quest->achievement_tree->achievement->completed = 1; + quest->status = 2; + + } + else if (((strcmp(ctx->game->curr_room->room_id,"room2")) == 0) && ((quest->status == 2))) { char *output1 = strcat("Ogre-Rick", ": I see you ate that green pill I left to the south to alert someone about my wife's condition. She is very ill and needs help. Can you get an herb or find a doctor for her?"); @@ -166,8 +179,8 @@ quest_t *make_sample_quest(long int quest_id, item_t *reward, npc_t *npc1, npc_t *npc2, item_t *item1, item_t *item2, item_t *item3) { - mission_t *none = mission_new(NULL, NULL); - achievement_t *start = achievement_new(none, "The first mission"); + mission_t *talk_to_witch = mission_new(NULL, npc3); // talk to Witch-Eve + achievement_t *start = achievement_new(talk_to_witch, "The first mission"); /*achievement_tree_t *ach_tree = malloc(sizeof(achievement_tree_t)); ach_tree->achievement = start; @@ -238,7 +251,12 @@ int main(int argc, char **argv) npc_t *npc2 = npc_new(npc_id2,"second npc","this is the npc that holds a branch of a quest", NULL, NULL, false); + char *npc_id3 = "Witch-Eve"; + npc_t *npc3 = npc_new(npc_id3,"third npc","this is the npc that holds a branch of a quest", + NULL, NULL, false); + npcs_in_room_1 = npcs_in_room_new("room1"); + add_npc_to_room(npcs_in_room_1, npc3); npcs_in_room_2 = npcs_in_room_new("room2"); add_npc_to_room(npcs_in_room_2, npc1); From cbbf91ab4a5b012d09c28e5153f9b8f46095fa11 Mon Sep 17 00:00:00 2001 From: Olivia Niena Jerdee Date: Wed, 2 Jun 2021 16:58:23 -0500 Subject: [PATCH 10/14] Changed add_achievement_to_quest #1088 --- src/quests/src/quests_state.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/quests/src/quests_state.c b/src/quests/src/quests_state.c index ec8b624bc0..d829619fe7 100644 --- a/src/quests/src/quests_state.c +++ b/src/quests/src/quests_state.c @@ -239,6 +239,7 @@ int add_achievement_to_quest(quest_t *quest, achievement_t *achievement_to_add, } else { + tree = tree->lmostchild; while (tree->rsibling != NULL) { tree = tree->rsibling; From e0436214f52882f84d1a8be7b01f1a053e7bd0d6 Mon Sep 17 00:00:00 2001 From: Olivia Niena Jerdee Date: Wed, 2 Jun 2021 17:14:12 -0500 Subject: [PATCH 11/14] Changed add_achievement_to_quest parameters #1088 --- src/quests/examples/quest-example.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/quests/examples/quest-example.c b/src/quests/examples/quest-example.c index 3865c34b0e..13985089b2 100644 --- a/src/quests/examples/quest-example.c +++ b/src/quests/examples/quest-example.c @@ -210,9 +210,9 @@ quest_t *make_sample_quest(long int quest_id, item_t *reward, add_achievement_to_quest(quest, achievement1, "The first mission"); add_achievement_to_quest(quest, achievement2, "The first mission"); - add_achievement_to_quest(quest, achievement3, "Take blue potion"); - add_achievement_to_quest(quest, achievement4, "Take green pill"); - add_achievement_to_quest(quest, achievement5, "Take green pill"); + add_achievement_to_quest(quest, achievement3, "Take green pill"); + add_achievement_to_quest(quest, achievement4, "Talk to Ogre-Rick"); + add_achievement_to_quest(quest, achievement5, "Talk to Ogre-Rick"); return quest; } From 3567563332cf4f0fb373e785e21667e991d611ae Mon Sep 17 00:00:00 2001 From: Olivia Niena Jerdee Date: Wed, 2 Jun 2021 19:48:50 -0500 Subject: [PATCH 12/14] Functional #1088 --- src/quests/examples/quest-example.c | 88 +++++++++++++++-------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/src/quests/examples/quest-example.c b/src/quests/examples/quest-example.c index 13985089b2..adf58402af 100644 --- a/src/quests/examples/quest-example.c +++ b/src/quests/examples/quest-example.c @@ -24,11 +24,11 @@ const char *banner = player_t *player; quest_t *quest; npcs_in_room_t *npcs_in_room_1; -npcs_in_room_t *npcs_in_room_2; -npcs_in_room_t *npcs_in_room_3; +//npcs_in_room_t *npcs_in_room_2; +//npcs_in_room_t *npcs_in_room_3; -npc_t *npc1; -npc_t *npc2; +//npc_t *npc1; +//npc_t *npc2; npc_t *npc3; @@ -41,37 +41,37 @@ chiventure_ctx_t *create_sample_ctx() room_t *room1 = room_new("room1", "This is room 1", "Verily, this is the first room."); room_t *room2 = room_new("room2", "This is room 2", "Truly, this is the second room."); room_t *room3 = room_new("room3", "This is room 3", "Exactly, this is the third room."); - room_t *room4 = room_new("room4", "This is room 4", "Yes, this is the fourth room."); + //room_t *room4 = room_new("room4", "This is room 4", "Yes, this is the fourth room."); //room_t *room5 = room_new("room5", "This is room 5", "Indeed, this is the fifth room."); add_room_to_game(game, room1); add_room_to_game(game, room2); add_room_to_game(game, room3); - add_room_to_game(game, room4); + //add_room_to_game(game, room4); //add_room_to_game(game, room5); game->curr_room = room1; create_connection(game, "room1", "room2", "NORTH"); - create_connection(game, "room2", "room3", "EAST"); - create_connection(game, "room2", "room4", "WEST"); + create_connection(game, "room1", "room3", "EAST"); + //create_connection(game, "room2", "room4", "WEST"); //create_connection(game, "room2", "room5", "SOUTH"); - item_t *BLUEPOTION = item_new("BLUE POTION","It is a bottle that holds a mysterious blue liquid", + item_t *BLUEPOTION = item_new("BLUEPOTION","It is a bottle that holds a mysterious blue liquid", "This item must be taken for second mission. Drink it!"); - add_item_to_room(room1, BLUEPOTION); + add_item_to_room(room2, BLUEPOTION); - item_t *GREENPILL = item_new("GREEN PILL","It is a green tablet. Could it be medicine?", + item_t *GREENPILL = item_new("GREENPILL","It is a green tablet. Could it be medicine?", "This item must be taken for second mission. Take it!"); - add_item_to_room(room1, GREENPILL); + add_item_to_room(room3, GREENPILL); - item_t *HERB = item_new("HERB", "It is a herb plant that has medicinal properties", + /*item_t *HERB = item_new("HERB", "It is a herb plant that has medicinal properties", "This item can cure a bad cough"); add_item_to_room(room4, HERB); add_action(HERB, "TAKE", "[You take the Herb] " "This is the herb that the ogre was talking about!", - "You can't pickup the herb."); + "You can't pickup the herb.");*/ add_action(BLUEPOTION, "SIP", "[You sip the Potion] You feel strong.", "You can't drink the POTION."); @@ -104,7 +104,7 @@ char *start_quest_operation(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx if(quest->status == 1) { - return "You have started the quest. There are two potions in front of you: BLUE and GREEN. Pick one"; + return "You have started the quest. There is a witch! Talk to her."; } else { @@ -115,7 +115,7 @@ char *start_quest_operation(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) { - + assert(ctx != NULL); game_t *game = ctx->game; if (game == NULL || game->curr_room == NULL) { @@ -128,18 +128,20 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) return "I do not know what you mean."; } - + assert(quest != NULL); + assert(ctx->game != NULL); + assert(ctx->game != NULL); + assert(ctx->game->curr_room != NULL); if (((strcmp(ctx->game->curr_room->room_id,"room1")) == 0) && ((quest->status == 1))) { - char *output0 = strcat("Witch-Eve", - ": Welcome, mortal! I have a quest for you! Consume the pill or drink the potion! Hehehehe..."); - return output0; - + char *output0 = "Witch-Eve: Welcome, mortal! I have a quest for you! Consume the pill or drink the potion! Hehehehe..."; + quest->achievement_tree->achievement->completed = 1; quest->status = 2; + return output0; } - else if (((strcmp(ctx->game->curr_room->room_id,"room2")) == 0) && ((quest->status == 2))) { + /*else if (((strcmp(ctx->game->curr_room->room_id,"room2")) == 0) && ((quest->status == 2))) { char *output1 = strcat("Ogre-Rick", ": I see you ate that green pill I left to the south to alert someone about my wife's condition. She is very ill and needs help. Can you get an herb or find a doctor for her?"); @@ -167,7 +169,7 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) return output3; } - } + } */ else { return "There is no one to talk to!"; @@ -176,8 +178,8 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) quest_t *make_sample_quest(long int quest_id, item_t *reward, - npc_t *npc1, npc_t *npc2, - item_t *item1, item_t *item2, item_t *item3) + /*npc_t *npc1, npc_t *npc2,*/ npc_t *npc3, + item_t *item1, item_t *item2)//, item_t *item3) { mission_t *talk_to_witch = mission_new(NULL, npc3); // talk to Witch-Eve achievement_t *start = achievement_new(talk_to_witch, "The first mission"); @@ -192,9 +194,9 @@ quest_t *make_sample_quest(long int quest_id, item_t *reward, add_achievement_to_quest(quest, start, "none"); //mission_t *kill_dragon = mission_new(NULL, npc1); // kill dragon - mission_t *find_ogre = mission_new(NULL, npc1); //talk to ogre - mission_t *find_doctor = mission_new(NULL, npc2); //talk to doctor - mission_t *find_herb = mission_new(item3, NULL); //find herb + //mission_t *find_ogre = mission_new(NULL, npc1); //talk to ogre + //mission_t *find_doctor = mission_new(NULL, npc2); //talk to doctor + //mission_t *find_herb = mission_new(item3, NULL); //find herb mission_t *take_blue_potion = mission_new(item1, NULL); mission_t *take_green_pill = mission_new(item2, NULL); @@ -203,16 +205,16 @@ quest_t *make_sample_quest(long int quest_id, item_t *reward, achievement_t *achievement2 = achievement_new(take_green_pill, "Take green pill"); //achievement_t *achievement3 = achievement_new(kill_dragon,"Kill the dragon"); - achievement_t *achievement3 = achievement_new(find_ogre, "Talk to Ogre-Rick"); - achievement_t *achievement4 = achievement_new(find_doctor, "Find a Doctor"); - achievement_t *achievement5 = achievement_new(find_herb, "Find the Herb"); + //achievement_t *achievement3 = achievement_new(find_ogre, "Talk to Ogre-Rick"); + //achievement_t *achievement4 = achievement_new(find_doctor, "Find a Doctor"); + //achievement_t *achievement5 = achievement_new(find_herb, "Find the Herb"); add_achievement_to_quest(quest, achievement1, "The first mission"); add_achievement_to_quest(quest, achievement2, "The first mission"); - add_achievement_to_quest(quest, achievement3, "Take green pill"); - add_achievement_to_quest(quest, achievement4, "Talk to Ogre-Rick"); - add_achievement_to_quest(quest, achievement5, "Talk to Ogre-Rick"); + //add_achievement_to_quest(quest, achievement3, "Take green pill"); + //add_achievement_to_quest(quest, achievement4, "Talk to Ogre-Rick"); + //add_achievement_to_quest(quest, achievement5, "Talk to Ogre-Rick"); return quest; } @@ -231,8 +233,8 @@ int main(int argc, char **argv) room_t *third_room; HASH_FIND(hh, ctx->game->all_rooms, "room3", strlen("room3"), third_room); - room_t *fourth_room; - HASH_FIND(hh, ctx->game->all_rooms, "room4", strlen("room4"), fourth_room); + //room_t *fourth_room; + //HASH_FIND(hh, ctx->game->all_rooms, "room4", strlen("room4"), fourth_room); //room_t *fifth_room; //HASH_FIND(hh, ctx->game->all_rooms, "room5", strlen("room5"), fourth_room); @@ -243,13 +245,13 @@ int main(int argc, char **argv) NULL, NULL, false);*/ - char *npc_id1 = "Ogre-Rick"; + /*char *npc_id1 = "Ogre-Rick"; npc_t *npc1 = npc_new(npc_id1,"first npc","this is the npc that holds a branch of a quest", NULL, NULL, false); char *npc_id2 = "Doctor-Dave"; npc_t *npc2 = npc_new(npc_id2,"second npc","this is the npc that holds a branch of a quest", - NULL, NULL, false); + NULL, NULL, false);*/ char *npc_id3 = "Witch-Eve"; npc_t *npc3 = npc_new(npc_id3,"third npc","this is the npc that holds a branch of a quest", @@ -258,11 +260,11 @@ int main(int argc, char **argv) npcs_in_room_1 = npcs_in_room_new("room1"); add_npc_to_room(npcs_in_room_1, npc3); - npcs_in_room_2 = npcs_in_room_new("room2"); + /*npcs_in_room_2 = npcs_in_room_new("room2"); add_npc_to_room(npcs_in_room_2, npc1); npcs_in_room_3 = npcs_in_room_new("room3"); - add_npc_to_room(npcs_in_room_3, npc2); + add_npc_to_room(npcs_in_room_3, npc2);*/ item_t *item1 = malloc(sizeof(item_t)); HASH_FIND(hh, ctx->game->all_items, "BLUEPOTION", strlen("BLUEPOTION"), item1); @@ -270,13 +272,13 @@ int main(int argc, char **argv) item_t *item2 = malloc(sizeof(item_t)); HASH_FIND(hh, ctx->game->all_items, "GREENPILL", strlen("GREENPILL"), item2); - item_t *item3 = malloc(sizeof(item_t)); - HASH_FIND(hh, ctx->game->all_items, "HERB", strlen("HERB"), item3); + //item_t *item3 = malloc(sizeof(item_t)); + //HASH_FIND(hh, ctx->game->all_items, "HERB", strlen("HERB"), item3); item_t *reward = item_new("KEY", "this is a key that unlocks all secrets", "Reward for completing the quest."); - quest_t *quest = make_sample_quest(1, reward, npc1, npc2, item1, item2, item3); + quest = make_sample_quest(1, reward, npc3,/*npc1, npc2,*/ item1, item2); add_entry("QUEST", start_quest_operation, NULL, ctx->cli_ctx->table); From 865498ed0f4858860a4b2cc8cc6cb027a1ffb02e Mon Sep 17 00:00:00 2001 From: Olivia Niena Jerdee Date: Wed, 2 Jun 2021 19:57:04 -0500 Subject: [PATCH 13/14] Working demo #1088 --- src/quests/examples/quest-example.c | 39 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/quests/examples/quest-example.c b/src/quests/examples/quest-example.c index adf58402af..71507723bb 100644 --- a/src/quests/examples/quest-example.c +++ b/src/quests/examples/quest-example.c @@ -24,11 +24,11 @@ const char *banner = player_t *player; quest_t *quest; npcs_in_room_t *npcs_in_room_1; -//npcs_in_room_t *npcs_in_room_2; -//npcs_in_room_t *npcs_in_room_3; +npcs_in_room_t *npcs_in_room_2; +npcs_in_room_t *npcs_in_room_3; -//npc_t *npc1; -//npc_t *npc2; +npc_t *npc1; +npc_t *npc2; npc_t *npc3; @@ -141,21 +141,22 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) return output0; } - /*else if (((strcmp(ctx->game->curr_room->room_id,"room2")) == 0) && ((quest->status == 2))) { - - char *output1 = strcat("Ogre-Rick", - ": I see you ate that green pill I left to the south to alert someone about my wife's condition. She is very ill and needs help. Can you get an herb or find a doctor for her?"); - return output1; + else if (((strcmp(ctx->game->curr_room->room_id,"room2")) == 0) && ((quest->status == 2))) { + quest->achievement_tree->achievement->completed = 1; quest->status = 3; + + if ((is_quest_completed(quest)) == 1) + { + item_t *reward = complete_quest(quest); + add_item_to_player(ctx->game->curr_player, reward); + char* output3 = "Ogre Rick: Wow, real adventurous of you to take that pill! Congrats you finished the quest you get a key!"; + return output3; + } } - else if ((strcmp(ctx->game->curr_room->room_id,"room3") == 0) && (quest->status == 3)) { - - char *output2 = strcat("Doctor-Dave", - ": Ogre-Rick's wife is sick? I will head west now to treat her."); - return output2; + else if ((strcmp(ctx->game->curr_room->room_id,"room3") == 0) && (quest->status == 2)) { //complete_achievement(quest, item, npc); quest->achievement_tree->achievement->completed = 1; @@ -163,13 +164,11 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) { item_t *reward = complete_quest(quest); add_item_to_player(ctx->game->curr_player, reward); - char* output3 = strcat("Ogre-Rick", ": Thanks so much for finding a doctor! Congratulations" - " on completing the quest, your reward is a key that should " - "help you on your adventure. You will find it in your inventory."); + char* output3 = "Doctor Dave: Tasty, huh? Nice job, here's the key to my pharmacy where you can have all the potions you want!"; return output3; } - } */ + } else { return "There is no one to talk to!"; @@ -245,13 +244,13 @@ int main(int argc, char **argv) NULL, NULL, false);*/ - /*char *npc_id1 = "Ogre-Rick"; + char *npc_id1 = "Ogre-Rick"; npc_t *npc1 = npc_new(npc_id1,"first npc","this is the npc that holds a branch of a quest", NULL, NULL, false); char *npc_id2 = "Doctor-Dave"; npc_t *npc2 = npc_new(npc_id2,"second npc","this is the npc that holds a branch of a quest", - NULL, NULL, false);*/ + NULL, NULL, false); char *npc_id3 = "Witch-Eve"; npc_t *npc3 = npc_new(npc_id3,"third npc","this is the npc that holds a branch of a quest", From 621dda949930c1895d646d1c1e1161ae5c6603cb Mon Sep 17 00:00:00 2001 From: Olivia Niena Jerdee Date: Wed, 2 Jun 2021 20:06:18 -0500 Subject: [PATCH 14/14] Different rewards --- src/quests/examples/quest-example.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/quests/examples/quest-example.c b/src/quests/examples/quest-example.c index 71507723bb..fb2f1fc563 100644 --- a/src/quests/examples/quest-example.c +++ b/src/quests/examples/quest-example.c @@ -53,6 +53,8 @@ chiventure_ctx_t *create_sample_ctx() game->curr_room = room1; create_connection(game, "room1", "room2", "NORTH"); create_connection(game, "room1", "room3", "EAST"); + create_connection(game, "room2", "room1", "SOUTH"); + create_connection(game, "room3", "room1", "WEST"); //create_connection(game, "room2", "room4", "WEST"); //create_connection(game, "room2", "room5", "SOUTH"); @@ -65,11 +67,9 @@ chiventure_ctx_t *create_sample_ctx() "This item must be taken for second mission. Take it!"); add_item_to_room(room3, GREENPILL); - /*item_t *HERB = item_new("HERB", "It is a herb plant that has medicinal properties", - "This item can cure a bad cough"); - add_item_to_room(room4, HERB); + - add_action(HERB, "TAKE", "[You take the Herb] " + /*add_action(HERB, "TAKE", "[You take the Herb] " "This is the herb that the ogre was talking about!", "You can't pickup the herb.");*/ @@ -141,7 +141,7 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) return output0; } - else if (((strcmp(ctx->game->curr_room->room_id,"room2")) == 0) && ((quest->status == 2))) { + else if (((strcmp(ctx->game->curr_room->room_id,"room3")) == 0) && ((quest->status == 2))) { quest->achievement_tree->achievement->completed = 1; @@ -149,14 +149,16 @@ char *talk_to_npc(char *tokens[TOKEN_LIST_SIZE], chiventure_ctx_t *ctx) if ((is_quest_completed(quest)) == 1) { + item_t *HERB = item_new("HERB", "It is a herb plant that has medicinal properties", + "This item can cure a bad cough"); item_t *reward = complete_quest(quest); - add_item_to_player(ctx->game->curr_player, reward); - char* output3 = "Ogre Rick: Wow, real adventurous of you to take that pill! Congrats you finished the quest you get a key!"; + add_item_to_player(ctx->game->curr_player, HERB); + char* output3 = "Ogre Rick: Wow, real adventurous of you to take that pill! Congrats you finished the quest you get an herb!"; return output3; } } - else if ((strcmp(ctx->game->curr_room->room_id,"room3") == 0) && (quest->status == 2)) { + else if ((strcmp(ctx->game->curr_room->room_id,"room2") == 0) && (quest->status == 2)) { //complete_achievement(quest, item, npc); quest->achievement_tree->achievement->completed = 1; @@ -277,6 +279,8 @@ int main(int argc, char **argv) item_t *reward = item_new("KEY", "this is a key that unlocks all secrets", "Reward for completing the quest."); + + quest = make_sample_quest(1, reward, npc3,/*npc1, npc2,*/ item1, item2); add_entry("QUEST", start_quest_operation, NULL, ctx->cli_ctx->table);