OSDN Git Service

Refactor quest completion code
authorhabu <habu@0568b783-4c39-0410-ac80-bf13821ea2a2>
Tue, 19 Feb 2013 12:32:40 +0000 (12:32 +0000)
committerhabu <habu@0568b783-4c39-0410-ac80-bf13821ea2a2>
Tue, 19 Feb 2013 12:32:40 +0000 (12:32 +0000)
src/cmd1.c
src/cmd3.c
src/externs.h
src/xtra2.c

index 65d1a69..ae05fa4 100644 (file)
@@ -577,25 +577,7 @@ void py_pickup_aux(int o_idx)
        record_turn = turn;
 
 
-       /* Check if completed a quest */
-       for (i = 0; i < max_quests; i++)
-       {
-               if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
-                   (quest[i].status == QUEST_STATUS_TAKEN) &&
-                          (quest[i].k_idx == o_ptr->name1))
-               {
-                       if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
-                       quest[i].status = QUEST_STATUS_COMPLETED;
-                       quest[i].complev = (byte)p_ptr->lev;
-#ifdef JP
-                       msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
-#else
-                       msg_print("You completed your quest!");
-#endif
-
-                       msg_print(NULL);
-               }
-       }
+       check_find_art_quest_completion(o_ptr);
 }
 
 
@@ -3357,16 +3339,7 @@ bool move_player_effect(int ny, int nx, u32b mpe_mode)
        {
                if (quest[p_ptr->inside_quest].type == QUEST_TYPE_FIND_EXIT)
                {
-                       if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, p_ptr->inside_quest, NULL);
-                       quest[p_ptr->inside_quest].status = QUEST_STATUS_COMPLETED;
-                       quest[p_ptr->inside_quest].complev = (byte)p_ptr->lev;
-#ifdef JP
-                       msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
-#else
-                       msg_print("You accomplished your quest!");
-#endif
-
-                       msg_print(NULL);
+                       complete_quest(p_ptr->inside_quest);
                }
 
                leave_quest_check();
index 0db84ac..48b94a5 100644 (file)
@@ -465,25 +465,7 @@ sprintf(dummy, "%s
                slot = need_switch_wielding;
        }
 
-       /* Check if completed a quest */
-       for (i = 0; i < max_quests; i++)
-       {
-               if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
-                   (quest[i].status == QUEST_STATUS_TAKEN) &&
-                   (quest[i].k_idx == o_ptr->name1))
-               {
-                       if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
-                       quest[i].status = QUEST_STATUS_COMPLETED;
-                       quest[i].complev = (byte)p_ptr->lev;
-#ifdef JP
-msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
-#else
-                       msg_print("You completed the quest!");
-#endif
-
-                       msg_print(NULL);
-               }
-       }
+       check_find_art_quest_completion(o_ptr);
 
        if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
        {
index 1884626..42269d7 100644 (file)
@@ -1472,7 +1472,9 @@ extern bool set_superstealth(bool set);
 
 /* xtra2.c */
 extern void check_experience(void);
+extern void complete_quest(int quest_num);
 extern void check_quest_completion(monster_type *m_ptr);
+extern void check_find_art_quest_completion(object_type *o_ptr);
 extern cptr extract_note_dies(monster_race *r_ptr);
 extern void monster_death(int m_idx, bool drop_item);
 extern bool mon_take_hit(int m_idx, int dam, bool *fear, cptr note);
index 38aefd1..4bd12d2 100644 (file)
@@ -377,12 +377,55 @@ static bool kind_is_hafted(int k_idx)
 }
 
 
+void complete_quest(int quest_num)
+{
+       switch (quest[quest_num].type)
+       {
+       case QUEST_TYPE_RANDOM:
+               if (record_rand_quest) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, quest_num, NULL);
+               break;
+       default:
+               if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, quest_num, NULL);
+               break;
+       }
+
+       quest[quest_num].status = QUEST_STATUS_COMPLETED;
+       quest[quest_num].complev = (byte)p_ptr->lev;
+
+       if (!(quest[quest_num].flags & QUEST_FLAG_SILENT))
+       {
+               msg_print(_("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª", "You just completed your quest!"));
+               msg_print(NULL);
+       }
+}
+
+static int count_all_hostile_monsters(void)
+{
+       int x, y;
+       int number_mon = 0;
+
+       for (x = 0; x < cur_wid; ++ x)
+       {
+               for (y = 0; y < cur_hgt; ++ y)
+               {
+                       int m_idx = cave[y][x].m_idx;
+
+                       if (m_idx > 0 && is_hostile(&m_list[m_idx]))
+                       {
+                               ++ number_mon;
+                       }
+               }
+       }
+
+       return number_mon;
+}
+
 /*
  * Check for "Quest" completion when a quest monster is killed or charmed.
  */
 void check_quest_completion(monster_type *m_ptr)
 {
-       int i, j, y, x, ny, nx, i2, j2;
+       int i, j, y, x, ny, nx;
 
        int quest_num;
 
@@ -453,21 +496,7 @@ void check_quest_completion(monster_type *m_ptr)
 
                                if (quest[i].cur_num >= quest[i].num_mon)
                                {
-                                       if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
-                                       /* completed quest */
-                                       quest[i].status = QUEST_STATUS_COMPLETED;
-                                       quest[i].complev = (byte)p_ptr->lev;
-
-                                       if (!(quest[i].flags & QUEST_FLAG_SILENT))
-                                       {
-#ifdef JP
-msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
-#else
-                                               msg_print("You just completed your quest!");
-#endif
-
-                                               msg_print(NULL);
-                                       }
+                                       complete_quest(i);
 
                                        quest[i].cur_num = 0;
                                }
@@ -475,36 +504,17 @@ msg_print("
                        }
                        case QUEST_TYPE_KILL_ALL:
                        {
-                               int number_mon = 0;
-
                                if (!is_hostile(m_ptr)) break;
 
-                               /* Count all hostile monsters */
-                               for (i2 = 0; i2 < cur_wid; ++i2)
-                                       for (j2 = 0; j2 < cur_hgt; j2++)
-                                               if (cave[j2][i2].m_idx > 0)
-                                                       if (is_hostile(&m_list[cave[j2][i2].m_idx])) 
-                                                               number_mon++;
-
-                               if ((number_mon - 1) == 0)
+                               if (count_all_hostile_monsters() == 1)
                                {
-                                       if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
-                                       /* completed */
                                        if (quest[i].flags & QUEST_FLAG_SILENT)
                                        {
                                                quest[i].status = QUEST_STATUS_FINISHED;
                                        }
                                        else
                                        {
-                                               quest[i].status = QUEST_STATUS_COMPLETED;
-                                               quest[i].complev = (byte)p_ptr->lev;
-#ifdef JP
-msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
-#else
-                                               msg_print("You just completed your quest!");
-#endif
-
-                                               msg_print(NULL);
+                                               complete_quest(i);
                                        }
                                }
                                break;
@@ -520,28 +530,14 @@ msg_print("
 
                                if (quest[i].cur_num >= quest[i].max_num)
                                {
-                                       if (record_fix_quest && (quest[i].type == QUEST_TYPE_KILL_LEVEL)) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
-                                       if (record_rand_quest && (quest[i].type == QUEST_TYPE_RANDOM)) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, i, NULL);
-                                       /* completed quest */
-                                       quest[i].status = QUEST_STATUS_COMPLETED;
-                                       quest[i].complev = (byte)p_ptr->lev;
+                                       complete_quest(i);
+
                                        if (!(quest[i].flags & QUEST_FLAG_PRESET))
                                        {
                                                create_stairs = TRUE;
                                                p_ptr->inside_quest = 0;
                                        }
 
-                                       if (!(quest[i].flags & QUEST_FLAG_SILENT))
-                                       {
-#ifdef JP
-msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
-#else
-                                               msg_print("You just completed your quest!");
-#endif
-
-                                               msg_print(NULL);
-                                       }
-
                                        /* Finish the two main quests without rewarding */
                                        if ((i == QUEST_OBERON) || (i == QUEST_SERPENT))
                                        {
@@ -561,57 +557,25 @@ msg_print("
                                quest[i].cur_num++;
                                if (quest[i].cur_num >= quest[i].max_num)
                                {
-                                       if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
-                                        /* completed quest */
-                                       quest[i].status = QUEST_STATUS_COMPLETED;
-                                       quest[i].complev = (byte)p_ptr->lev;
-
-                                       if (!(quest[i].flags & QUEST_FLAG_SILENT))
-                                       {
-#ifdef JP
-msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
-#else
-                                               msg_print("You just completed your quest!");
-#endif
-
-                                               msg_print(NULL);
-                                       }
+                                       complete_quest(i);
                                        quest[i].cur_num = 0;
                                }
                                break;
                        }
                        case QUEST_TYPE_TOWER:
                        {
-                               int number_mon = 0;
-
                                if (!is_hostile(m_ptr)) break;
 
-                               /* Count all hostile monsters */
-                               for (i2 = 0; i2 < cur_wid; ++i2)
-                                       for (j2 = 0; j2 < cur_hgt; j2++)
-                                               if (cave[j2][i2].m_idx > 0)
-                                                       if (is_hostile(&m_list[cave[j2][i2].m_idx])) 
-                                                               number_mon++;
-
-                               if ((number_mon - 1) == 0)
+                               if (count_all_hostile_monsters() == 1)
                                {
-                                       if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
-                                       
                                        quest[i].status = QUEST_STATUS_STAGE_COMPLETED;
-                                       /* completed */
+
                                        if((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
                                           (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
                                           (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
                                        {
-                                               quest[QUEST_TOWER1].status = QUEST_STATUS_COMPLETED;
-                                               quest[QUEST_TOWER1].complev = (byte)p_ptr->lev;;
-                                                       
-#ifdef JP
-msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
-#else
-                                               msg_print("You just completed your quest!");
-#endif
-                                               msg_print(NULL);
+
+                                               complete_quest(QUEST_TOWER1);
                                        }
                                }
                                break;
@@ -670,6 +634,21 @@ msg_print("
 }
 
 
+void check_find_art_quest_completion(object_type *o_ptr)
+{
+       int i;
+       /* Check if completed a quest */
+       for (i = 0; i < max_quests; i++)
+       {
+               if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
+                   (quest[i].status == QUEST_STATUS_TAKEN) &&
+                          (quest[i].k_idx == o_ptr->name1))
+               {
+                       complete_quest(i);
+               }
+       }
+}
+
 /*
  * Return monster death string
  */