7 #include "floor-save.h"
8 #include "floor-events.h"
11 #include "monsterrace-hook.h"
13 #include "player-status.h"
14 #include "player-personality.h"
20 #include "view-mainwindow.h"
22 quest_type *quest; /*!< Quest info */
23 QUEST_IDX max_q_idx; /*!< Maximum number of quests */
24 char quest_text[10][80]; /*!< Quest text */
25 int quest_text_line; /*!< Current line of the quest text */
26 int leaving_quest = 0;
29 * @brief クエスト突入時のメッセージテーブル / Array of places to find an inscription
31 static concptr find_quest[] =
33 _("床にメッセージが刻まれている:", "You find the following inscription in the floor"),
34 _("壁にメッセージが刻まれている:", "You see a message inscribed in the wall"),
35 _("メッセージを見つけた:", "There is a sign saying"),
36 _("何かが階段の上に書いてある:", "Something is written on the staircase"),
37 _("巻物を見つけた。メッセージが書いてある:", "You find a scroll with the following message"),
42 * @brief ランダムクエストの討伐ユニークを決める / Determine the random quest uniques
43 * @param q_ptr クエスト構造体の参照ポインタ
46 void determine_random_questor(player_type *player_ptr, quest_type *q_ptr)
48 get_mon_num_prep(player_ptr, mon_hook_quest, NULL);
54 * Random monster 5 - 10 levels out of depth
55 * (depending on level)
57 r_idx = get_mon_num(player_ptr, q_ptr->level + 5 + randint1(q_ptr->level / 10));
59 r_ptr = &r_info[r_idx];
61 if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
62 if (r_ptr->flags1 & RF1_QUESTOR) continue;
63 if (r_ptr->rarity > 100) continue;
64 if (r_ptr->flags7 & RF7_FRIENDLY) continue;
65 if (r_ptr->flags7 & RF7_AQUATIC) continue;
66 if (r_ptr->flags8 & RF8_WILD_ONLY) continue;
67 if (no_questor_or_bounty_uniques(r_idx)) continue;
70 * Accept monsters that are 2 - 6 levels
71 * out of depth depending on the quest level
73 if (r_ptr->level > (q_ptr->level + (q_ptr->level / 20))) break;
81 * @brief クエストを達成状態にする /
82 * @param player_ptr プレーヤーへの参照ポインタ
83 * @param quest_num 達成状態にしたいクエストのID
86 void complete_quest(player_type *player_ptr, QUEST_IDX quest_num)
88 quest_type* const q_ptr = &quest[quest_num];
92 case QUEST_TYPE_RANDOM:
93 if (record_rand_quest) exe_write_diary(player_ptr, DIARY_RAND_QUEST_C, quest_num, NULL);
96 if (record_fix_quest) exe_write_diary(player_ptr, DIARY_FIX_QUEST_C, quest_num, NULL);
100 q_ptr->status = QUEST_STATUS_COMPLETED;
101 q_ptr->complev = player_ptr->lev;
103 q_ptr->comptime = current_world_ptr->play_time;
105 if (q_ptr->flags & QUEST_FLAG_SILENT) return;
107 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
108 msg_print(_("クエストを達成した!", "You just completed your quest!"));
114 * @brief 特定の敵を倒した際にクエスト達成処理 /
115 * Check for "Quest" completion when a quest monster is killed or charmed.
116 * @param player_ptr プレーヤーへの参照ポインタ
117 * @param m_ptr 撃破したモンスターの構造体参照ポインタ
120 void check_quest_completion(player_type *player_ptr, monster_type *m_ptr)
122 POSITION y = m_ptr->fy;
123 POSITION x = m_ptr->fx;
125 floor_type *floor_ptr = player_ptr->current_floor_ptr;
126 QUEST_IDX quest_num = floor_ptr->inside_quest;
128 /* Search for an active quest on this dungeon level */
132 for (i = max_q_idx - 1; i > 0; i--)
134 quest_type* const q_ptr = &quest[i];
136 /* Quest is not active */
137 if (q_ptr->status != QUEST_STATUS_TAKEN)
140 /* Quest is not a dungeon quest */
141 if (q_ptr->flags & QUEST_FLAG_PRESET)
144 /* Quest is not on this level */
145 if ((q_ptr->level != floor_ptr->dun_level) &&
146 (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
149 /* Not a "kill monster" quest */
150 if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
151 (q_ptr->type == QUEST_TYPE_FIND_EXIT))
154 /* Interesting quest */
155 if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
156 (q_ptr->type == QUEST_TYPE_TOWER) ||
157 (q_ptr->type == QUEST_TYPE_KILL_ALL))
160 /* Interesting quest */
161 if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
162 (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
163 (q_ptr->type == QUEST_TYPE_RANDOM)) &&
164 (q_ptr->r_idx == m_ptr->r_idx))
171 /* Handle the current quest */
172 bool create_stairs = FALSE;
174 if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
177 quest_type* const q_ptr = &quest[quest_num];
181 case QUEST_TYPE_KILL_NUMBER:
185 if (q_ptr->cur_num >= q_ptr->num_mon)
187 complete_quest(player_ptr, quest_num);
193 case QUEST_TYPE_KILL_ALL:
195 if (!is_hostile(m_ptr)) break;
197 if (count_all_hostile_monsters(floor_ptr) != 1) break;
199 if (q_ptr->flags & QUEST_FLAG_SILENT)
201 q_ptr->status = QUEST_STATUS_FINISHED;
205 complete_quest(player_ptr, quest_num);
210 case QUEST_TYPE_KILL_LEVEL:
211 case QUEST_TYPE_RANDOM:
213 /* Only count valid monsters */
214 if (q_ptr->r_idx != m_ptr->r_idx)
219 if (q_ptr->cur_num < q_ptr->max_num) break;
221 complete_quest(player_ptr, quest_num);
223 if (!(q_ptr->flags & QUEST_FLAG_PRESET))
225 create_stairs = TRUE;
226 floor_ptr->inside_quest = 0;
229 /* Finish the two main quests without rewarding */
230 if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
232 q_ptr->status = QUEST_STATUS_FINISHED;
235 if (q_ptr->type == QUEST_TYPE_RANDOM)
238 q_ptr->status = QUEST_STATUS_FINISHED;
243 case QUEST_TYPE_KILL_ANY_LEVEL:
246 if (q_ptr->cur_num >= q_ptr->max_num)
248 complete_quest(player_ptr, quest_num);
254 case QUEST_TYPE_TOWER:
256 if (!is_hostile(m_ptr)) break;
258 if (count_all_hostile_monsters(floor_ptr) == 1)
260 q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
262 if ((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
263 (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
264 (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
267 complete_quest(player_ptr, QUEST_TOWER1);
276 /* Create a magical staircase */
282 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))
284 /* Pick a location */
285 scatter(player_ptr, &ny, &nx, y, x, 1, 0);
291 /* Explain the staircase */
292 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
294 /* Create stairs down */
295 cave_set_feat(player_ptr, y, x, feat_down_stair);
297 /* Remember to update everything */
298 player_ptr->update |= (PU_FLOW);
305 for (int i = 0; i < (floor_ptr->dun_level / 15) + 1; i++)
310 /* Make a great object */
311 make_object(player_ptr, o_ptr, AM_GOOD | AM_GREAT);
312 (void)drop_near(player_ptr, o_ptr, -1, y, x);
318 * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
319 * Check for "Quest" completion when a quest monster is killed or charmed.
320 * @param player_ptr プレーヤーへの参照ポインタ
321 * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
324 void check_find_art_quest_completion(player_type *player_ptr, object_type *o_ptr)
326 /* Check if completed a quest */
327 for (QUEST_IDX i = 0; i < max_q_idx; i++)
329 if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
330 (quest[i].status == QUEST_STATUS_TAKEN) &&
331 (quest[i].k_idx == o_ptr->name1))
333 complete_quest(player_ptr, i);
340 * @brief クエストの導入メッセージを表示する / Discover quest
341 * @param q_idx 開始されたクエストのID
343 void quest_discovery(QUEST_IDX q_idx)
345 quest_type *q_ptr = &quest[q_idx];
346 monster_race *r_ptr = &r_info[q_ptr->r_idx];
347 MONSTER_NUMBER q_num = q_ptr->max_num;
351 GAME_TEXT name[MAX_NLEN];
352 strcpy(name, (r_name + r_ptr->name));
354 msg_print(find_quest[rand_range(0, 4)]);
363 msg_format(_("注意しろ!この階は%d体の%sによって守られている!", "Be warned, this level is guarded by %d %s!"), q_num, name);
367 bool is_random_quest_skipped = (r_ptr->flags1 & RF1_UNIQUE);
368 is_random_quest_skipped &= 0 == r_ptr->max_num;
369 if (!is_random_quest_skipped)
371 msg_format(_("注意せよ!この階は%sによって守られている!", "Beware, this level is protected by %s!"), name);
375 msg_print(_("この階は以前は誰かによって守られていたようだ…。", "It seems that this level was protected by someone before..."));
376 quest[q_idx].status = QUEST_STATUS_FINISHED;
379 q_ptr->comptime = current_world_ptr->play_time;
384 * @brief 新しく入ったダンジョンの階層に固定されている一般のクエストを探し出しIDを返す。
385 * / Hack -- Check if a level is a "quest" level
386 * @param player_ptr プレーヤーへの参照ポインタ
387 * @param level 検索対象になる階
388 * @return クエストIDを返す。該当がない場合0を返す。
390 QUEST_IDX quest_number(player_type *player_ptr, DEPTH level)
392 floor_type *floor_ptr = player_ptr->current_floor_ptr;
393 if (floor_ptr->inside_quest)
394 return (floor_ptr->inside_quest);
396 for (QUEST_IDX i = 0; i < max_q_idx; i++)
398 if (quest[i].status != QUEST_STATUS_TAKEN) continue;
400 if ((quest[i].type == QUEST_TYPE_KILL_LEVEL) &&
401 !(quest[i].flags & QUEST_FLAG_PRESET) &&
402 (quest[i].level == level) &&
403 (quest[i].dungeon == player_ptr->dungeon_idx))
407 return random_quest_number(player_ptr, level);
412 * @brief 新しく入ったダンジョンの階層に固定されているランダムクエストを探し出しIDを返す。
413 * @param player_ptr プレーヤーへの参照ポインタ
414 * @param level 検索対象になる階
415 * @return クエストIDを返す。該当がない場合0を返す。
417 QUEST_IDX random_quest_number(player_type *player_ptr, DEPTH level)
419 if (player_ptr->dungeon_idx != DUNGEON_ANGBAND) return 0;
421 for (QUEST_IDX i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
423 if ((quest[i].type == QUEST_TYPE_RANDOM) &&
424 (quest[i].status == QUEST_STATUS_TAKEN) &&
425 (quest[i].level == level) &&
426 (quest[i].dungeon == DUNGEON_ANGBAND))
437 * @brief クエスト階層から離脱する際の処理
438 * @param player_ptr プレーヤーへの参照ポインタ
441 void leave_quest_check(player_type *player_ptr)
443 leaving_quest = player_ptr->current_floor_ptr->inside_quest;
444 if (!leaving_quest) return;
446 quest_type* const q_ptr = &quest[leaving_quest];
447 bool is_one_time_quest = ((q_ptr->flags & QUEST_FLAG_ONCE) || (q_ptr->type == QUEST_TYPE_RANDOM)) &&
448 (q_ptr->status == QUEST_STATUS_TAKEN);
449 if (is_one_time_quest) return;
451 q_ptr->status = QUEST_STATUS_FAILED;
452 q_ptr->complev = player_ptr->lev;
454 q_ptr->comptime = current_world_ptr->play_time;
456 /* Additional settings */
459 case QUEST_TYPE_TOWER:
460 quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
461 quest[QUEST_TOWER1].complev = player_ptr->lev;
463 case QUEST_TYPE_FIND_ARTIFACT:
464 a_info[q_ptr->k_idx].gen_flags &= ~(TRG_QUESTITEM);
466 case QUEST_TYPE_RANDOM:
467 r_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
469 /* Floor of random quest will be blocked */
470 prepare_change_floor_mode(player_ptr, CFM_NO_RETURN);
474 /* Record finishing a quest */
475 if (q_ptr->type == QUEST_TYPE_RANDOM)
477 if (record_rand_quest)
478 exe_write_diary(player_ptr, DIARY_RAND_QUEST_F, leaving_quest, NULL);
482 if (record_fix_quest)
483 exe_write_diary(player_ptr, DIARY_FIX_QUEST_F, leaving_quest, NULL);
488 * @brief 「塔」クエストの各階層から離脱する際の処理
491 void leave_tower_check(player_type *player_ptr)
493 leaving_quest = player_ptr->current_floor_ptr->inside_quest;
494 bool is_leaving_from_tower = leaving_quest != 0;
495 is_leaving_from_tower &= quest[leaving_quest].type == QUEST_TYPE_TOWER;
496 is_leaving_from_tower &= quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED;
497 if (!is_leaving_from_tower) return;
498 if (quest[leaving_quest].type != QUEST_TYPE_TOWER) return;
500 quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
501 quest[QUEST_TOWER1].complev = player_ptr->lev;
503 quest[QUEST_TOWER1].comptime = current_world_ptr->play_time;
508 * @brief クエスト入り口にプレイヤーが乗った際の処理 / Do building commands
509 * @param player_ptr プレーヤーへの参照ポインタ
512 void do_cmd_quest(player_type *player_ptr)
514 if (player_ptr->wild_mode) return;
516 take_turn(player_ptr, 100);
518 if (!cave_have_flag_bold(player_ptr->current_floor_ptr, player_ptr->y, player_ptr->x, FF_QUEST_ENTER))
520 msg_print(_("ここにはクエストの入口はない。", "You see no quest level here."));
524 msg_print(_("ここにはクエストへの入口があります。", "There is an entry of a quest."));
525 if (!get_check(_("クエストに入りますか?", "Do you enter? "))) return;
526 if ((player_ptr->pseikaku == SEIKAKU_COMBAT) || (player_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
527 msg_print(_("『とにかく入ってみようぜぇ。』", ""));
528 else if (player_ptr->pseikaku == SEIKAKU_CHARGEMAN) msg_print("『全滅してやるぞ!』");
530 /* Player enters a new quest */
531 player_ptr->oldpy = 0;
532 player_ptr->oldpx = 0;
534 leave_quest_check(player_ptr);
536 if (quest[player_ptr->current_floor_ptr->inside_quest].type != QUEST_TYPE_RANDOM) player_ptr->current_floor_ptr->dun_level = 1;
537 player_ptr->current_floor_ptr->inside_quest = player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].special;
539 player_ptr->leaving = TRUE;