3 #include "main/music-definitions-table.h"
8 #include "floor-save.h"
9 #include "floor-events.h"
12 #include "monsterrace-hook.h"
14 #include "player-status.h"
15 #include "player-personality.h"
19 #include "io/write-diary.h"
20 #include "cmd/cmd-dump.h"
22 #include "view-mainwindow.h"
24 quest_type *quest; /*!< Quest info */
25 QUEST_IDX max_q_idx; /*!< Maximum number of quests */
26 char quest_text[10][80]; /*!< Quest text */
27 int quest_text_line; /*!< Current line of the quest text */
28 int leaving_quest = 0;
31 * @brief クエスト突入時のメッセージテーブル / Array of places to find an inscription
33 static concptr find_quest[] =
35 _("床にメッセージが刻まれている:", "You find the following inscription in the floor"),
36 _("壁にメッセージが刻まれている:", "You see a message inscribed in the wall"),
37 _("メッセージを見つけた:", "There is a sign saying"),
38 _("何かが階段の上に書いてある:", "Something is written on the staircase"),
39 _("巻物を見つけた。メッセージが書いてある:", "You find a scroll with the following message"),
44 * @brief ランダムクエストの討伐ユニークを決める / Determine the random quest uniques
45 * @param q_ptr クエスト構造体の参照ポインタ
48 void determine_random_questor(player_type *player_ptr, quest_type *q_ptr)
50 get_mon_num_prep(player_ptr, mon_hook_quest, NULL);
56 * Random monster 5 - 10 levels out of depth
57 * (depending on level)
59 r_idx = get_mon_num(player_ptr, q_ptr->level + 5 + randint1(q_ptr->level / 10), GMN_ARENA);
61 r_ptr = &r_info[r_idx];
63 if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
64 if (r_ptr->flags1 & RF1_QUESTOR) continue;
65 if (r_ptr->rarity > 100) continue;
66 if (r_ptr->flags7 & RF7_FRIENDLY) continue;
67 if (r_ptr->flags7 & RF7_AQUATIC) continue;
68 if (r_ptr->flags8 & RF8_WILD_ONLY) continue;
69 if (no_questor_or_bounty_uniques(r_idx)) continue;
72 * Accept monsters that are 2 - 6 levels
73 * out of depth depending on the quest level
75 if (r_ptr->level > (q_ptr->level + (q_ptr->level / 20))) break;
83 * @brief クエストを達成状態にする /
84 * @param player_ptr プレーヤーへの参照ポインタ
85 * @param quest_num 達成状態にしたいクエストのID
88 void complete_quest(player_type *player_ptr, QUEST_IDX quest_num)
90 quest_type* const q_ptr = &quest[quest_num];
94 case QUEST_TYPE_RANDOM:
95 if (record_rand_quest) exe_write_diary(player_ptr, DIARY_RAND_QUEST_C, quest_num, NULL);
98 if (record_fix_quest) exe_write_diary(player_ptr, DIARY_FIX_QUEST_C, quest_num, NULL);
102 q_ptr->status = QUEST_STATUS_COMPLETED;
103 q_ptr->complev = player_ptr->lev;
105 q_ptr->comptime = current_world_ptr->play_time;
107 if (q_ptr->flags & QUEST_FLAG_SILENT) return;
109 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
110 msg_print(_("クエストを達成した!", "You just completed your quest!"));
116 * @brief 特定の敵を倒した際にクエスト達成処理 /
117 * Check for "Quest" completion when a quest monster is killed or charmed.
118 * @param player_ptr プレーヤーへの参照ポインタ
119 * @param m_ptr 撃破したモンスターの構造体参照ポインタ
122 void check_quest_completion(player_type *player_ptr, monster_type *m_ptr)
124 POSITION y = m_ptr->fy;
125 POSITION x = m_ptr->fx;
127 floor_type *floor_ptr = player_ptr->current_floor_ptr;
128 QUEST_IDX quest_num = floor_ptr->inside_quest;
130 /* Search for an active quest on this dungeon level */
134 for (i = max_q_idx - 1; i > 0; i--)
136 quest_type* const q_ptr = &quest[i];
138 /* Quest is not active */
139 if (q_ptr->status != QUEST_STATUS_TAKEN)
142 /* Quest is not a dungeon quest */
143 if (q_ptr->flags & QUEST_FLAG_PRESET)
146 /* Quest is not on this level */
147 if ((q_ptr->level != floor_ptr->dun_level) &&
148 (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
151 /* Not a "kill monster" quest */
152 if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
153 (q_ptr->type == QUEST_TYPE_FIND_EXIT))
156 /* Interesting quest */
157 if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
158 (q_ptr->type == QUEST_TYPE_TOWER) ||
159 (q_ptr->type == QUEST_TYPE_KILL_ALL))
162 /* Interesting quest */
163 if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
164 (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
165 (q_ptr->type == QUEST_TYPE_RANDOM)) &&
166 (q_ptr->r_idx == m_ptr->r_idx))
173 /* Handle the current quest */
174 bool create_stairs = FALSE;
176 if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
179 quest_type* const q_ptr = &quest[quest_num];
183 case QUEST_TYPE_KILL_NUMBER:
187 if (q_ptr->cur_num >= q_ptr->num_mon)
189 complete_quest(player_ptr, quest_num);
195 case QUEST_TYPE_KILL_ALL:
197 if (!is_hostile(m_ptr)) break;
199 if (count_all_hostile_monsters(floor_ptr) != 1) break;
201 if (q_ptr->flags & QUEST_FLAG_SILENT)
203 q_ptr->status = QUEST_STATUS_FINISHED;
207 complete_quest(player_ptr, quest_num);
212 case QUEST_TYPE_KILL_LEVEL:
213 case QUEST_TYPE_RANDOM:
215 /* Only count valid monsters */
216 if (q_ptr->r_idx != m_ptr->r_idx)
221 if (q_ptr->cur_num < q_ptr->max_num) break;
223 complete_quest(player_ptr, quest_num);
225 if (!(q_ptr->flags & QUEST_FLAG_PRESET))
227 create_stairs = TRUE;
228 floor_ptr->inside_quest = 0;
231 /* Finish the two main quests without rewarding */
232 if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
234 q_ptr->status = QUEST_STATUS_FINISHED;
237 if (q_ptr->type == QUEST_TYPE_RANDOM)
240 q_ptr->status = QUEST_STATUS_FINISHED;
245 case QUEST_TYPE_KILL_ANY_LEVEL:
248 if (q_ptr->cur_num >= q_ptr->max_num)
250 complete_quest(player_ptr, quest_num);
256 case QUEST_TYPE_TOWER:
258 if (!is_hostile(m_ptr)) break;
260 if (count_all_hostile_monsters(floor_ptr) == 1)
262 q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
264 if ((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
265 (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
266 (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
269 complete_quest(player_ptr, QUEST_TOWER1);
278 /* Create a magical staircase */
284 while (cave_perma_bold(floor_ptr, y, x) || floor_ptr->grid_array[y][x].o_idx || (floor_ptr->grid_array[y][x].info & CAVE_OBJECT))
286 /* Pick a location */
287 scatter(player_ptr, &ny, &nx, y, x, 1, 0);
293 /* Explain the staircase */
294 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
296 /* Create stairs down */
297 cave_set_feat(player_ptr, y, x, feat_down_stair);
299 /* Remember to update everything */
300 player_ptr->update |= (PU_FLOW);
307 for (int i = 0; i < (floor_ptr->dun_level / 15) + 1; i++)
312 /* Make a great object */
313 make_object(player_ptr, o_ptr, AM_GOOD | AM_GREAT);
314 (void)drop_near(player_ptr, o_ptr, -1, y, x);
320 * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
321 * Check for "Quest" completion when a quest monster is killed or charmed.
322 * @param player_ptr プレーヤーへの参照ポインタ
323 * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
326 void check_find_art_quest_completion(player_type *player_ptr, object_type *o_ptr)
328 /* Check if completed a quest */
329 for (QUEST_IDX i = 0; i < max_q_idx; i++)
331 if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
332 (quest[i].status == QUEST_STATUS_TAKEN) &&
333 (quest[i].k_idx == o_ptr->name1))
335 complete_quest(player_ptr, i);
342 * @brief クエストの導入メッセージを表示する / Discover quest
343 * @param q_idx 開始されたクエストのID
345 void quest_discovery(QUEST_IDX q_idx)
347 quest_type *q_ptr = &quest[q_idx];
348 monster_race *r_ptr = &r_info[q_ptr->r_idx];
349 MONSTER_NUMBER q_num = q_ptr->max_num;
353 GAME_TEXT name[MAX_NLEN];
354 strcpy(name, (r_name + r_ptr->name));
356 msg_print(find_quest[rand_range(0, 4)]);
365 msg_format(_("注意しろ!この階は%d体の%sによって守られている!", "Be warned, this level is guarded by %d %s!"), q_num, name);
369 bool is_random_quest_skipped = (r_ptr->flags1 & RF1_UNIQUE) != 0;
370 is_random_quest_skipped &= r_ptr->max_num == 0;
371 if (!is_random_quest_skipped)
373 msg_format(_("注意せよ!この階は%sによって守られている!", "Beware, this level is protected by %s!"), name);
377 msg_print(_("この階は以前は誰かによって守られていたようだ…。", "It seems that this level was protected by someone before..."));
378 quest[q_idx].status = QUEST_STATUS_FINISHED;
381 q_ptr->comptime = current_world_ptr->play_time;
386 * @brief 新しく入ったダンジョンの階層に固定されている一般のクエストを探し出しIDを返す。
387 * / Hack -- Check if a level is a "quest" level
388 * @param player_ptr プレーヤーへの参照ポインタ
389 * @param level 検索対象になる階
390 * @return クエストIDを返す。該当がない場合0を返す。
392 QUEST_IDX quest_number(player_type *player_ptr, DEPTH level)
394 floor_type *floor_ptr = player_ptr->current_floor_ptr;
395 if (floor_ptr->inside_quest)
396 return (floor_ptr->inside_quest);
398 for (QUEST_IDX i = 0; i < max_q_idx; i++)
400 if (quest[i].status != QUEST_STATUS_TAKEN) continue;
402 if ((quest[i].type == QUEST_TYPE_KILL_LEVEL) &&
403 !(quest[i].flags & QUEST_FLAG_PRESET) &&
404 (quest[i].level == level) &&
405 (quest[i].dungeon == player_ptr->dungeon_idx))
409 return random_quest_number(player_ptr, level);
414 * @brief 新しく入ったダンジョンの階層に固定されているランダムクエストを探し出しIDを返す。
415 * @param player_ptr プレーヤーへの参照ポインタ
416 * @param level 検索対象になる階
417 * @return クエストIDを返す。該当がない場合0を返す。
419 QUEST_IDX random_quest_number(player_type *player_ptr, DEPTH level)
421 if (player_ptr->dungeon_idx != DUNGEON_ANGBAND) return 0;
423 for (QUEST_IDX i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
425 if ((quest[i].type == QUEST_TYPE_RANDOM) &&
426 (quest[i].status == QUEST_STATUS_TAKEN) &&
427 (quest[i].level == level) &&
428 (quest[i].dungeon == DUNGEON_ANGBAND))
439 * @brief クエスト階層から離脱する際の処理
440 * @param player_ptr プレーヤーへの参照ポインタ
443 void leave_quest_check(player_type *player_ptr)
445 leaving_quest = player_ptr->current_floor_ptr->inside_quest;
446 if (!leaving_quest) return;
448 quest_type* const q_ptr = &quest[leaving_quest];
449 bool is_one_time_quest = ((q_ptr->flags & QUEST_FLAG_ONCE) || (q_ptr->type == QUEST_TYPE_RANDOM)) &&
450 (q_ptr->status == QUEST_STATUS_TAKEN);
451 if (!is_one_time_quest) return;
453 q_ptr->status = QUEST_STATUS_FAILED;
454 q_ptr->complev = player_ptr->lev;
456 q_ptr->comptime = current_world_ptr->play_time;
458 /* Additional settings */
461 case QUEST_TYPE_TOWER:
462 quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
463 quest[QUEST_TOWER1].complev = player_ptr->lev;
465 case QUEST_TYPE_FIND_ARTIFACT:
466 a_info[q_ptr->k_idx].gen_flags &= ~(TRG_QUESTITEM);
468 case QUEST_TYPE_RANDOM:
469 r_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
471 /* Floor of random quest will be blocked */
472 prepare_change_floor_mode(player_ptr, CFM_NO_RETURN);
476 /* Record finishing a quest */
477 if (q_ptr->type == QUEST_TYPE_RANDOM)
479 if (record_rand_quest)
480 exe_write_diary(player_ptr, DIARY_RAND_QUEST_F, leaving_quest, NULL);
484 if (record_fix_quest)
485 exe_write_diary(player_ptr, DIARY_FIX_QUEST_F, leaving_quest, NULL);
490 * @brief 「塔」クエストの各階層から離脱する際の処理
493 void leave_tower_check(player_type *player_ptr)
495 leaving_quest = player_ptr->current_floor_ptr->inside_quest;
496 bool is_leaving_from_tower = leaving_quest != 0;
497 is_leaving_from_tower &= quest[leaving_quest].type == QUEST_TYPE_TOWER;
498 is_leaving_from_tower &= quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED;
499 if (!is_leaving_from_tower) return;
500 if (quest[leaving_quest].type != QUEST_TYPE_TOWER) return;
502 quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
503 quest[QUEST_TOWER1].complev = player_ptr->lev;
505 quest[QUEST_TOWER1].comptime = current_world_ptr->play_time;
510 * @brief クエスト入り口にプレイヤーが乗った際の処理 / Do building commands
511 * @param player_ptr プレーヤーへの参照ポインタ
514 void do_cmd_quest(player_type *player_ptr)
516 if (player_ptr->wild_mode) return;
518 take_turn(player_ptr, 100);
520 if (!cave_have_flag_bold(player_ptr->current_floor_ptr, player_ptr->y, player_ptr->x, FF_QUEST_ENTER))
522 msg_print(_("ここにはクエストの入口はない。", "You see no quest level here."));
526 msg_print(_("ここにはクエストへの入口があります。", "There is an entry of a quest."));
527 if (!get_check(_("クエストに入りますか?", "Do you enter? "))) return;
528 if (IS_ECHIZEN(player_ptr))
529 msg_print(_("『とにかく入ってみようぜぇ。』", ""));
530 else if (player_ptr->pseikaku == SEIKAKU_CHARGEMAN) msg_print("『全滅してやるぞ!』");
532 /* Player enters a new quest */
533 player_ptr->oldpy = 0;
534 player_ptr->oldpx = 0;
536 leave_quest_check(player_ptr);
538 if (quest[player_ptr->current_floor_ptr->inside_quest].type != QUEST_TYPE_RANDOM) player_ptr->current_floor_ptr->dun_level = 1;
539 player_ptr->current_floor_ptr->inside_quest = player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].special;
541 player_ptr->leaving = TRUE;