• R/O
  • HTTP
  • SSH
  • HTTPS

hengband: Commit

変愚蛮怒のメインリポジトリです


Commit MetaInfo

Revision02e318147cdf701af36371a67bfc2a86311afeec (tree)
Time2013-02-19 21:32:40
Authorhabu <habu@0568...>
Commiterhabu

Log Message

Refactor quest completion code

Change Summary

Incremental Difference

--- a/src/cmd1.c
+++ b/src/cmd1.c
@@ -577,25 +577,7 @@ void py_pickup_aux(int o_idx)
577577 record_turn = turn;
578578
579579
580- /* Check if completed a quest */
581- for (i = 0; i < max_quests; i++)
582- {
583- if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
584- (quest[i].status == QUEST_STATUS_TAKEN) &&
585- (quest[i].k_idx == o_ptr->name1))
586- {
587- if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
588- quest[i].status = QUEST_STATUS_COMPLETED;
589- quest[i].complev = (byte)p_ptr->lev;
590-#ifdef JP
591- msg_print("クエストを達成した!");
592-#else
593- msg_print("You completed your quest!");
594-#endif
595-
596- msg_print(NULL);
597- }
598- }
580+ check_find_art_quest_completion(o_ptr);
599581 }
600582
601583
@@ -3357,16 +3339,7 @@ bool move_player_effect(int ny, int nx, u32b mpe_mode)
33573339 {
33583340 if (quest[p_ptr->inside_quest].type == QUEST_TYPE_FIND_EXIT)
33593341 {
3360- if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, p_ptr->inside_quest, NULL);
3361- quest[p_ptr->inside_quest].status = QUEST_STATUS_COMPLETED;
3362- quest[p_ptr->inside_quest].complev = (byte)p_ptr->lev;
3363-#ifdef JP
3364- msg_print("クエストを達成した!");
3365-#else
3366- msg_print("You accomplished your quest!");
3367-#endif
3368-
3369- msg_print(NULL);
3342+ complete_quest(p_ptr->inside_quest);
33703343 }
33713344
33723345 leave_quest_check();
--- a/src/cmd3.c
+++ b/src/cmd3.c
@@ -465,25 +465,7 @@ sprintf(dummy, "%s
465465 slot = need_switch_wielding;
466466 }
467467
468- /* Check if completed a quest */
469- for (i = 0; i < max_quests; i++)
470- {
471- if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
472- (quest[i].status == QUEST_STATUS_TAKEN) &&
473- (quest[i].k_idx == o_ptr->name1))
474- {
475- if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
476- quest[i].status = QUEST_STATUS_COMPLETED;
477- quest[i].complev = (byte)p_ptr->lev;
478-#ifdef JP
479-msg_print("クエストを達成した!");
480-#else
481- msg_print("You completed the quest!");
482-#endif
483-
484- msg_print(NULL);
485- }
486- }
468+ check_find_art_quest_completion(o_ptr);
487469
488470 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
489471 {
--- a/src/externs.h
+++ b/src/externs.h
@@ -1472,7 +1472,9 @@ extern bool set_superstealth(bool set);
14721472
14731473 /* xtra2.c */
14741474 extern void check_experience(void);
1475+extern void complete_quest(int quest_num);
14751476 extern void check_quest_completion(monster_type *m_ptr);
1477+extern void check_find_art_quest_completion(object_type *o_ptr);
14761478 extern cptr extract_note_dies(monster_race *r_ptr);
14771479 extern void monster_death(int m_idx, bool drop_item);
14781480 extern bool mon_take_hit(int m_idx, int dam, bool *fear, cptr note);
--- a/src/xtra2.c
+++ b/src/xtra2.c
@@ -377,12 +377,55 @@ static bool kind_is_hafted(int k_idx)
377377 }
378378
379379
380+void complete_quest(int quest_num)
381+{
382+ switch (quest[quest_num].type)
383+ {
384+ case QUEST_TYPE_RANDOM:
385+ if (record_rand_quest) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, quest_num, NULL);
386+ break;
387+ default:
388+ if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, quest_num, NULL);
389+ break;
390+ }
391+
392+ quest[quest_num].status = QUEST_STATUS_COMPLETED;
393+ quest[quest_num].complev = (byte)p_ptr->lev;
394+
395+ if (!(quest[quest_num].flags & QUEST_FLAG_SILENT))
396+ {
397+ msg_print(_("クエストを達成した!", "You just completed your quest!"));
398+ msg_print(NULL);
399+ }
400+}
401+
402+static int count_all_hostile_monsters(void)
403+{
404+ int x, y;
405+ int number_mon = 0;
406+
407+ for (x = 0; x < cur_wid; ++ x)
408+ {
409+ for (y = 0; y < cur_hgt; ++ y)
410+ {
411+ int m_idx = cave[y][x].m_idx;
412+
413+ if (m_idx > 0 && is_hostile(&m_list[m_idx]))
414+ {
415+ ++ number_mon;
416+ }
417+ }
418+ }
419+
420+ return number_mon;
421+}
422+
380423 /*
381424 * Check for "Quest" completion when a quest monster is killed or charmed.
382425 */
383426 void check_quest_completion(monster_type *m_ptr)
384427 {
385- int i, j, y, x, ny, nx, i2, j2;
428+ int i, j, y, x, ny, nx;
386429
387430 int quest_num;
388431
@@ -453,21 +496,7 @@ void check_quest_completion(monster_type *m_ptr)
453496
454497 if (quest[i].cur_num >= quest[i].num_mon)
455498 {
456- if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
457- /* completed quest */
458- quest[i].status = QUEST_STATUS_COMPLETED;
459- quest[i].complev = (byte)p_ptr->lev;
460-
461- if (!(quest[i].flags & QUEST_FLAG_SILENT))
462- {
463-#ifdef JP
464-msg_print("クエストを達成した!");
465-#else
466- msg_print("You just completed your quest!");
467-#endif
468-
469- msg_print(NULL);
470- }
499+ complete_quest(i);
471500
472501 quest[i].cur_num = 0;
473502 }
@@ -475,36 +504,17 @@ msg_print("
475504 }
476505 case QUEST_TYPE_KILL_ALL:
477506 {
478- int number_mon = 0;
479-
480507 if (!is_hostile(m_ptr)) break;
481508
482- /* Count all hostile monsters */
483- for (i2 = 0; i2 < cur_wid; ++i2)
484- for (j2 = 0; j2 < cur_hgt; j2++)
485- if (cave[j2][i2].m_idx > 0)
486- if (is_hostile(&m_list[cave[j2][i2].m_idx]))
487- number_mon++;
488-
489- if ((number_mon - 1) == 0)
509+ if (count_all_hostile_monsters() == 1)
490510 {
491- if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
492- /* completed */
493511 if (quest[i].flags & QUEST_FLAG_SILENT)
494512 {
495513 quest[i].status = QUEST_STATUS_FINISHED;
496514 }
497515 else
498516 {
499- quest[i].status = QUEST_STATUS_COMPLETED;
500- quest[i].complev = (byte)p_ptr->lev;
501-#ifdef JP
502-msg_print("クエストを達成した!");
503-#else
504- msg_print("You just completed your quest!");
505-#endif
506-
507- msg_print(NULL);
517+ complete_quest(i);
508518 }
509519 }
510520 break;
@@ -520,28 +530,14 @@ msg_print("
520530
521531 if (quest[i].cur_num >= quest[i].max_num)
522532 {
523- if (record_fix_quest && (quest[i].type == QUEST_TYPE_KILL_LEVEL)) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
524- if (record_rand_quest && (quest[i].type == QUEST_TYPE_RANDOM)) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, i, NULL);
525- /* completed quest */
526- quest[i].status = QUEST_STATUS_COMPLETED;
527- quest[i].complev = (byte)p_ptr->lev;
533+ complete_quest(i);
534+
528535 if (!(quest[i].flags & QUEST_FLAG_PRESET))
529536 {
530537 create_stairs = TRUE;
531538 p_ptr->inside_quest = 0;
532539 }
533540
534- if (!(quest[i].flags & QUEST_FLAG_SILENT))
535- {
536-#ifdef JP
537-msg_print("クエストを達成した!");
538-#else
539- msg_print("You just completed your quest!");
540-#endif
541-
542- msg_print(NULL);
543- }
544-
545541 /* Finish the two main quests without rewarding */
546542 if ((i == QUEST_OBERON) || (i == QUEST_SERPENT))
547543 {
@@ -561,57 +557,25 @@ msg_print("
561557 quest[i].cur_num++;
562558 if (quest[i].cur_num >= quest[i].max_num)
563559 {
564- if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
565- /* completed quest */
566- quest[i].status = QUEST_STATUS_COMPLETED;
567- quest[i].complev = (byte)p_ptr->lev;
568-
569- if (!(quest[i].flags & QUEST_FLAG_SILENT))
570- {
571-#ifdef JP
572-msg_print("クエストを達成した!");
573-#else
574- msg_print("You just completed your quest!");
575-#endif
576-
577- msg_print(NULL);
578- }
560+ complete_quest(i);
579561 quest[i].cur_num = 0;
580562 }
581563 break;
582564 }
583565 case QUEST_TYPE_TOWER:
584566 {
585- int number_mon = 0;
586-
587567 if (!is_hostile(m_ptr)) break;
588568
589- /* Count all hostile monsters */
590- for (i2 = 0; i2 < cur_wid; ++i2)
591- for (j2 = 0; j2 < cur_hgt; j2++)
592- if (cave[j2][i2].m_idx > 0)
593- if (is_hostile(&m_list[cave[j2][i2].m_idx]))
594- number_mon++;
595-
596- if ((number_mon - 1) == 0)
569+ if (count_all_hostile_monsters() == 1)
597570 {
598- if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
599-
600571 quest[i].status = QUEST_STATUS_STAGE_COMPLETED;
601- /* completed */
572+
602573 if((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
603574 (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
604575 (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
605576 {
606- quest[QUEST_TOWER1].status = QUEST_STATUS_COMPLETED;
607- quest[QUEST_TOWER1].complev = (byte)p_ptr->lev;;
608-
609-#ifdef JP
610-msg_print("クエストを達成した!");
611-#else
612- msg_print("You just completed your quest!");
613-#endif
614- msg_print(NULL);
577+
578+ complete_quest(QUEST_TOWER1);
615579 }
616580 }
617581 break;
@@ -670,6 +634,21 @@ msg_print("
670634 }
671635
672636
637+void check_find_art_quest_completion(object_type *o_ptr)
638+{
639+ int i;
640+ /* Check if completed a quest */
641+ for (i = 0; i < max_quests; i++)
642+ {
643+ if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
644+ (quest[i].status == QUEST_STATUS_TAKEN) &&
645+ (quest[i].k_idx == o_ptr->name1))
646+ {
647+ complete_quest(i);
648+ }
649+ }
650+}
651+
673652 /*
674653 * Return monster death string
675654 */
Show on old repository browser