1 #include "dungeon/quest.h"
2 #include "cmd-io/cmd-dump.h"
3 #include "dungeon/dungeon.h"
4 #include "floor/floor-events.h"
5 #include "floor/floor-object.h"
6 #include "floor/floor-save.h"
7 #include "floor/floor.h"
8 #include "grid/feature.h"
10 #include "io/write-diary.h"
11 #include "locale/english.h"
12 #include "main/music-definitions-table.h"
13 #include "monster/monster-race-hook.h"
14 #include "monster/monster.h"
15 #include "object-enchant/artifact.h"
16 #include "object-enchant/item-apply-magic.h"
17 #include "object/object-generator.h"
18 #include "player/player-personalities-table.h"
19 #include "player/player-status.h"
20 #include "system/system-variables.h"
21 #include "util/util.h"
22 #include "view/display-main-window.h"
23 #include "world/world.h"
25 quest_type *quest; /*!< Quest info */
26 QUEST_IDX max_q_idx; /*!< Maximum number of quests */
27 char quest_text[10][80]; /*!< Quest text */
28 int quest_text_line; /*!< Current line of the quest text */
29 int leaving_quest = 0;
32 * @brief クエスト突入時のメッセージテーブル / Array of places to find an inscription
34 static concptr find_quest[] =
36 _("床にメッセージが刻まれている:", "You find the following inscription in the floor"),
37 _("壁にメッセージが刻まれている:", "You see a message inscribed in the wall"),
38 _("メッセージを見つけた:", "There is a sign saying"),
39 _("何かが階段の上に書いてある:", "Something is written on the staircase"),
40 _("巻物を見つけた。メッセージが書いてある:", "You find a scroll with the following message"),
45 * @brief ランダムクエストの討伐ユニークを決める / Determine the random quest uniques
46 * @param q_ptr クエスト構造体の参照ポインタ
49 void determine_random_questor(player_type *player_ptr, quest_type *q_ptr)
51 get_mon_num_prep(player_ptr, mon_hook_quest, NULL);
57 * Random monster 5 - 10 levels out of depth
58 * (depending on level)
60 r_idx = get_mon_num(player_ptr, q_ptr->level + 5 + randint1(q_ptr->level / 10), GMN_ARENA);
62 r_ptr = &r_info[r_idx];
64 if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
65 if (r_ptr->flags1 & RF1_QUESTOR) continue;
66 if (r_ptr->rarity > 100) continue;
67 if (r_ptr->flags7 & RF7_FRIENDLY) continue;
68 if (r_ptr->flags7 & RF7_AQUATIC) continue;
69 if (r_ptr->flags8 & RF8_WILD_ONLY) continue;
70 if (no_questor_or_bounty_uniques(r_idx)) continue;
73 * Accept monsters that are 2 - 6 levels
74 * out of depth depending on the quest level
76 if (r_ptr->level > (q_ptr->level + (q_ptr->level / 20))) break;
84 * @brief クエストを達成状態にする /
85 * @param player_ptr プレーヤーへの参照ポインタ
86 * @param quest_num 達成状態にしたいクエストのID
89 void complete_quest(player_type *player_ptr, QUEST_IDX quest_num)
91 quest_type* const q_ptr = &quest[quest_num];
95 case QUEST_TYPE_RANDOM:
96 if (record_rand_quest) exe_write_diary(player_ptr, DIARY_RAND_QUEST_C, quest_num, NULL);
99 if (record_fix_quest) exe_write_diary(player_ptr, DIARY_FIX_QUEST_C, quest_num, NULL);
103 q_ptr->status = QUEST_STATUS_COMPLETED;
104 q_ptr->complev = player_ptr->lev;
106 q_ptr->comptime = current_world_ptr->play_time;
108 if (q_ptr->flags & QUEST_FLAG_SILENT) return;
110 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
111 msg_print(_("クエストを達成した!", "You just completed your quest!"));
117 * @brief 特定の敵を倒した際にクエスト達成処理 /
118 * Check for "Quest" completion when a quest monster is killed or charmed.
119 * @param player_ptr プレーヤーへの参照ポインタ
120 * @param m_ptr 撃破したモンスターの構造体参照ポインタ
123 void check_quest_completion(player_type *player_ptr, monster_type *m_ptr)
125 POSITION y = m_ptr->fy;
126 POSITION x = m_ptr->fx;
128 floor_type *floor_ptr = player_ptr->current_floor_ptr;
129 QUEST_IDX quest_num = floor_ptr->inside_quest;
131 /* Search for an active quest on this dungeon level */
135 for (i = max_q_idx - 1; i > 0; i--)
137 quest_type* const q_ptr = &quest[i];
139 /* Quest is not active */
140 if (q_ptr->status != QUEST_STATUS_TAKEN)
143 /* Quest is not a dungeon quest */
144 if (q_ptr->flags & QUEST_FLAG_PRESET)
147 /* Quest is not on this level */
148 if ((q_ptr->level != floor_ptr->dun_level) &&
149 (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
152 /* Not a "kill monster" quest */
153 if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
154 (q_ptr->type == QUEST_TYPE_FIND_EXIT))
157 /* Interesting quest */
158 if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
159 (q_ptr->type == QUEST_TYPE_TOWER) ||
160 (q_ptr->type == QUEST_TYPE_KILL_ALL))
163 /* Interesting quest */
164 if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
165 (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
166 (q_ptr->type == QUEST_TYPE_RANDOM)) &&
167 (q_ptr->r_idx == m_ptr->r_idx))
174 /* Handle the current quest */
175 bool create_stairs = FALSE;
177 if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
180 quest_type* const q_ptr = &quest[quest_num];
184 case QUEST_TYPE_KILL_NUMBER:
188 if (q_ptr->cur_num >= q_ptr->num_mon)
190 complete_quest(player_ptr, quest_num);
196 case QUEST_TYPE_KILL_ALL:
198 if (!is_hostile(m_ptr)) break;
200 if (count_all_hostile_monsters(floor_ptr) != 1) break;
202 if (q_ptr->flags & QUEST_FLAG_SILENT)
204 q_ptr->status = QUEST_STATUS_FINISHED;
208 complete_quest(player_ptr, quest_num);
213 case QUEST_TYPE_KILL_LEVEL:
214 case QUEST_TYPE_RANDOM:
216 /* Only count valid monsters */
217 if (q_ptr->r_idx != m_ptr->r_idx)
222 if (q_ptr->cur_num < q_ptr->max_num) break;
224 complete_quest(player_ptr, quest_num);
226 if (!(q_ptr->flags & QUEST_FLAG_PRESET))
228 create_stairs = TRUE;
229 floor_ptr->inside_quest = 0;
232 /* Finish the two main quests without rewarding */
233 if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
235 q_ptr->status = QUEST_STATUS_FINISHED;
238 if (q_ptr->type == QUEST_TYPE_RANDOM)
241 q_ptr->status = QUEST_STATUS_FINISHED;
246 case QUEST_TYPE_KILL_ANY_LEVEL:
249 if (q_ptr->cur_num >= q_ptr->max_num)
251 complete_quest(player_ptr, quest_num);
257 case QUEST_TYPE_TOWER:
259 if (!is_hostile(m_ptr)) break;
261 if (count_all_hostile_monsters(floor_ptr) == 1)
263 q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
265 if ((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
266 (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
267 (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
270 complete_quest(player_ptr, QUEST_TOWER1);
279 /* Create a magical staircase */
285 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))
287 /* Pick a location */
288 scatter(player_ptr, &ny, &nx, y, x, 1, 0);
294 /* Explain the staircase */
295 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
297 /* Create stairs down */
298 cave_set_feat(player_ptr, y, x, feat_down_stair);
300 /* Remember to update everything */
301 player_ptr->update |= (PU_FLOW);
308 for (int i = 0; i < (floor_ptr->dun_level / 15) + 1; i++)
313 /* Make a great object */
314 make_object(player_ptr, o_ptr, AM_GOOD | AM_GREAT);
315 (void)drop_near(player_ptr, o_ptr, -1, y, x);
321 * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
322 * Check for "Quest" completion when a quest monster is killed or charmed.
323 * @param player_ptr プレーヤーへの参照ポインタ
324 * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
327 void check_find_art_quest_completion(player_type *player_ptr, object_type *o_ptr)
329 /* Check if completed a quest */
330 for (QUEST_IDX i = 0; i < max_q_idx; i++)
332 if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
333 (quest[i].status == QUEST_STATUS_TAKEN) &&
334 (quest[i].k_idx == o_ptr->name1))
336 complete_quest(player_ptr, i);
343 * @brief クエストの導入メッセージを表示する / Discover quest
344 * @param q_idx 開始されたクエストのID
346 void quest_discovery(QUEST_IDX q_idx)
348 quest_type *q_ptr = &quest[q_idx];
349 monster_race *r_ptr = &r_info[q_ptr->r_idx];
350 MONSTER_NUMBER q_num = q_ptr->max_num;
354 GAME_TEXT name[MAX_NLEN];
355 strcpy(name, (r_name + r_ptr->name));
357 msg_print(find_quest[rand_range(0, 4)]);
366 msg_format(_("注意しろ!この階は%d体の%sによって守られている!", "Be warned, this level is guarded by %d %s!"), q_num, name);
370 bool is_random_quest_skipped = (r_ptr->flags1 & RF1_UNIQUE) != 0;
371 is_random_quest_skipped &= r_ptr->max_num == 0;
372 if (!is_random_quest_skipped)
374 msg_format(_("注意せよ!この階は%sによって守られている!", "Beware, this level is protected by %s!"), name);
378 msg_print(_("この階は以前は誰かによって守られていたようだ…。", "It seems that this level was protected by someone before..."));
379 quest[q_idx].status = QUEST_STATUS_FINISHED;
382 q_ptr->comptime = current_world_ptr->play_time;
387 * @brief 新しく入ったダンジョンの階層に固定されている一般のクエストを探し出しIDを返す。
388 * / Hack -- Check if a level is a "quest" level
389 * @param player_ptr プレーヤーへの参照ポインタ
390 * @param level 検索対象になる階
391 * @return クエストIDを返す。該当がない場合0を返す。
393 QUEST_IDX quest_number(player_type *player_ptr, DEPTH level)
395 floor_type *floor_ptr = player_ptr->current_floor_ptr;
396 if (floor_ptr->inside_quest)
397 return (floor_ptr->inside_quest);
399 for (QUEST_IDX i = 0; i < max_q_idx; i++)
401 if (quest[i].status != QUEST_STATUS_TAKEN) continue;
403 if ((quest[i].type == QUEST_TYPE_KILL_LEVEL) &&
404 !(quest[i].flags & QUEST_FLAG_PRESET) &&
405 (quest[i].level == level) &&
406 (quest[i].dungeon == player_ptr->dungeon_idx))
410 return random_quest_number(player_ptr, level);
415 * @brief 新しく入ったダンジョンの階層に固定されているランダムクエストを探し出しIDを返す。
416 * @param player_ptr プレーヤーへの参照ポインタ
417 * @param level 検索対象になる階
418 * @return クエストIDを返す。該当がない場合0を返す。
420 QUEST_IDX random_quest_number(player_type *player_ptr, DEPTH level)
422 if (player_ptr->dungeon_idx != DUNGEON_ANGBAND) return 0;
424 for (QUEST_IDX i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
426 if ((quest[i].type == QUEST_TYPE_RANDOM) &&
427 (quest[i].status == QUEST_STATUS_TAKEN) &&
428 (quest[i].level == level) &&
429 (quest[i].dungeon == DUNGEON_ANGBAND))
440 * @brief クエスト階層から離脱する際の処理
441 * @param player_ptr プレーヤーへの参照ポインタ
444 void leave_quest_check(player_type *player_ptr)
446 leaving_quest = player_ptr->current_floor_ptr->inside_quest;
447 if (!leaving_quest) return;
449 quest_type* const q_ptr = &quest[leaving_quest];
450 bool is_one_time_quest = ((q_ptr->flags & QUEST_FLAG_ONCE) || (q_ptr->type == QUEST_TYPE_RANDOM)) &&
451 (q_ptr->status == QUEST_STATUS_TAKEN);
452 if (!is_one_time_quest) return;
454 q_ptr->status = QUEST_STATUS_FAILED;
455 q_ptr->complev = player_ptr->lev;
457 q_ptr->comptime = current_world_ptr->play_time;
459 /* Additional settings */
462 case QUEST_TYPE_TOWER:
463 quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
464 quest[QUEST_TOWER1].complev = player_ptr->lev;
466 case QUEST_TYPE_FIND_ARTIFACT:
467 a_info[q_ptr->k_idx].gen_flags &= ~(TRG_QUESTITEM);
469 case QUEST_TYPE_RANDOM:
470 r_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
472 /* Floor of random quest will be blocked */
473 prepare_change_floor_mode(player_ptr, CFM_NO_RETURN);
477 /* Record finishing a quest */
478 if (q_ptr->type == QUEST_TYPE_RANDOM)
480 if (record_rand_quest)
481 exe_write_diary(player_ptr, DIARY_RAND_QUEST_F, leaving_quest, NULL);
485 if (record_fix_quest)
486 exe_write_diary(player_ptr, DIARY_FIX_QUEST_F, leaving_quest, NULL);
491 * @brief 「塔」クエストの各階層から離脱する際の処理
494 void leave_tower_check(player_type *player_ptr)
496 leaving_quest = player_ptr->current_floor_ptr->inside_quest;
497 bool is_leaving_from_tower = leaving_quest != 0;
498 is_leaving_from_tower &= quest[leaving_quest].type == QUEST_TYPE_TOWER;
499 is_leaving_from_tower &= quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED;
500 if (!is_leaving_from_tower) return;
501 if (quest[leaving_quest].type != QUEST_TYPE_TOWER) return;
503 quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
504 quest[QUEST_TOWER1].complev = player_ptr->lev;
506 quest[QUEST_TOWER1].comptime = current_world_ptr->play_time;
511 * @brief クエスト入り口にプレイヤーが乗った際の処理 / Do building commands
512 * @param player_ptr プレーヤーへの参照ポインタ
515 void do_cmd_quest(player_type *player_ptr)
517 if (player_ptr->wild_mode) return;
519 take_turn(player_ptr, 100);
521 if (!cave_have_flag_bold(player_ptr->current_floor_ptr, player_ptr->y, player_ptr->x, FF_QUEST_ENTER))
523 msg_print(_("ここにはクエストの入口はない。", "You see no quest level here."));
527 msg_print(_("ここにはクエストへの入口があります。", "There is an entry of a quest."));
528 if (!get_check(_("クエストに入りますか?", "Do you enter? "))) return;
529 if (IS_ECHIZEN(player_ptr))
530 msg_print(_("『とにかく入ってみようぜぇ。』", ""));
531 else if (player_ptr->pseikaku == PERSONALITY_CHARGEMAN) msg_print("『全滅してやるぞ!』");
533 /* Player enters a new quest */
534 player_ptr->oldpy = 0;
535 player_ptr->oldpx = 0;
537 leave_quest_check(player_ptr);
539 if (quest[player_ptr->current_floor_ptr->inside_quest].type != QUEST_TYPE_RANDOM) player_ptr->current_floor_ptr->dun_level = 1;
540 player_ptr->current_floor_ptr->inside_quest = player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].special;
542 player_ptr->leaving = TRUE;