1 #include "dungeon/quest.h"
2 #include "cmd-io/cmd-dump.h"
3 #include "core/asking-player.h"
4 #include "core/player-update-types.h"
5 #include "floor/cave.h"
6 #include "floor/floor-events.h"
7 #include "floor/floor-mode-changer.h"
8 #include "floor/floor-object.h"
9 #include "game-option/play-record-options.h"
10 #include "grid/feature.h"
11 #include "info-reader/fixed-map-parser.h"
12 #include "io/write-diary.h"
13 #include "locale/english.h"
14 #include "main/music-definitions-table.h"
15 #include "main/sound-of-music.h"
16 #include "monster-race/monster-race-hook.h"
17 #include "monster-race/monster-race.h"
18 #include "monster-race/race-flags1.h"
19 #include "monster-race/race-flags7.h"
20 #include "monster-race/race-flags8.h"
21 #include "monster/monster-info.h"
22 #include "monster/monster-list.h"
23 #include "monster/monster-util.h"
24 #include "monster/smart-learn-types.h"
25 #include "object-enchant/item-apply-magic.h"
26 #include "object-enchant/trg-types.h"
27 #include "player-status/player-energy.h"
28 #include "player/player-personality-types.h"
29 #include "player/player-status.h"
30 #include "system/artifact-type-definition.h"
31 #include "system/dungeon-info.h"
32 #include "system/floor-type-definition.h"
33 #include "system/grid-type-definition.h"
34 #include "system/monster-race-definition.h"
35 #include "system/player-type-definition.h"
36 #include "util/bit-flags-calculator.h"
37 #include "view/display-messages.h"
38 #include "world/world.h"
42 char quest_text[10][80]; /*!< Quest text */
43 int quest_text_line; /*!< Current line of the quest text */
44 QuestId leaving_quest = QuestId::NONE;
47 * @brief クエスト突入時のメッセージテーブル / Array of places to find an inscription
49 static concptr find_quest_map[] = {
50 _("床にメッセージが刻まれている:", "You find the following inscription in the floor"),
51 _("壁にメッセージが刻まれている:", "You see a message inscribed in the wall"),
52 _("メッセージを見つけた:", "There is a sign saying"),
53 _("何かが階段の上に書いてある:", "Something is written on the staircase"),
54 _("巻物を見つけた。メッセージが書いてある:", "You find a scroll with the following message"),
57 QuestList &QuestList::get_instance()
59 static QuestList instance{};
63 quest_type &QuestList::operator[](QuestId id)
65 return this->quest_data.at(id);
68 const quest_type &QuestList::operator[](QuestId id) const
70 return this->quest_data.at(id);
73 QuestList::iterator QuestList::begin()
75 return this->quest_data.begin();
78 QuestList::const_iterator QuestList::begin() const
80 return this->quest_data.cbegin();
83 QuestList::iterator QuestList::end()
85 return this->quest_data.end();
88 QuestList::const_iterator QuestList::end() const
90 return this->quest_data.cend();
93 QuestList::reverse_iterator QuestList::rbegin()
95 return this->quest_data.rbegin();
98 QuestList::const_reverse_iterator QuestList::rbegin() const
100 return this->quest_data.crbegin();
103 QuestList::reverse_iterator QuestList::rend()
105 return this->quest_data.rend();
108 QuestList::const_reverse_iterator QuestList::rend() const
110 return this->quest_data.crend();
113 QuestList::iterator QuestList::find(QuestId id)
115 return this->quest_data.find(id);
118 QuestList::const_iterator QuestList::find(QuestId id) const
120 return this->quest_data.find(id);
123 size_t QuestList::size() const
125 return this->quest_data.size();
129 * @brief クエスト情報初期化のメインルーチン /
130 * Initialize quest array
132 void QuestList::initialize()
138 auto quest_numbers = parse_quest_info(QUEST_DEFINITION_LIST);
139 quest_type init_quest{};
140 init_quest.status = QuestStatusType::UNTAKEN;
141 this->quest_data.insert({ QuestId::NONE, init_quest });
142 for (auto q : quest_numbers) {
143 this->quest_data.insert({ q, init_quest });
146 } catch (const std::runtime_error &r) {
147 std::stringstream ss;
148 ss << _("ファイル読み込みエラー: ", "File loading error: ") << r.what();
152 quit(_("クエスト初期化エラー", "Error of quests initializing"));
157 * @brief 該当IDが固定クエストかどうかを判定する.
158 * @param quest_idx クエストID
159 * @return 固定クエストならばTRUEを返す
161 bool quest_type::is_fixed(QuestId quest_idx)
163 return (enum2i(quest_idx) < MIN_RANDOM_QUEST) || (enum2i(quest_idx) > MAX_RANDOM_QUEST);
167 * @brief ランダムクエストの討伐ユニークを決める / Determine the random quest uniques
168 * @param q_ptr クエスト構造体の参照ポインタ
170 void determine_random_questor(PlayerType *player_ptr, quest_type *q_ptr)
172 get_mon_num_prep(player_ptr, mon_hook_quest, nullptr);
176 * Random monster 5 - 10 levels out of depth
177 * (depending on level)
179 r_idx = get_mon_num(player_ptr, 0, q_ptr->level + 5 + randint1(q_ptr->level / 10), GMN_ARENA);
181 r_ptr = &monraces_info[r_idx];
183 if (r_ptr->kind_flags.has_not(MonsterKindType::UNIQUE)) {
186 if (r_ptr->flags8 & RF8_NO_QUEST) {
189 if (r_ptr->flags1 & RF1_QUESTOR) {
192 if (r_ptr->rarity > 100) {
195 if (r_ptr->behavior_flags.has(MonsterBehaviorType::FRIENDLY)) {
198 if (r_ptr->feature_flags.has(MonsterFeatureType::AQUATIC)) {
201 if (r_ptr->wilderness_flags.has(MonsterWildernessType::WILD_ONLY)) {
204 if (no_questor_or_bounty_uniques(r_idx)) {
209 * Accept monsters that are 2 - 6 levels
210 * out of depth depending on the quest level
212 if (r_ptr->level > (q_ptr->level + (q_ptr->level / 20))) {
217 q_ptr->r_idx = r_idx;
221 * @brief クエストの最終状態を記録する(成功or失敗、時間)
222 * @param PlayerType プレイヤー情報への参照ポインタ
223 * @param q_ptr クエスト情報への参照ポインタ
224 * @param stat ステータス(成功or失敗)
226 void record_quest_final_status(quest_type *q_ptr, PLAYER_LEVEL lev, QuestStatusType stat)
228 q_ptr->status = stat;
229 q_ptr->complev = lev;
231 q_ptr->comptime = w_ptr->play_time;
235 * @brief クエストを達成状態にする /
236 * @param player_ptr プレイヤーへの参照ポインタ
237 * @param quest_num 達成状態にしたいクエストのID
239 void complete_quest(PlayerType *player_ptr, QuestId quest_num)
241 auto &quest_list = QuestList::get_instance();
242 auto *const q_ptr = &quest_list[quest_num];
244 switch (q_ptr->type) {
245 case QuestKindType::RANDOM:
246 if (record_rand_quest) {
247 exe_write_diary_quest(player_ptr, DIARY_RAND_QUEST_C, quest_num);
251 if (record_fix_quest) {
252 exe_write_diary_quest(player_ptr, DIARY_FIX_QUEST_C, quest_num);
257 record_quest_final_status(q_ptr, player_ptr->lev, QuestStatusType::COMPLETED);
259 if (q_ptr->flags & QUEST_FLAG_SILENT) {
263 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
264 msg_print(_("クエストを達成した!", "You just completed your quest!"));
269 * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
270 * Check for "Quest" completion when a quest monster is killed or charmed.
271 * @param player_ptr プレイヤーへの参照ポインタ
272 * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
274 void check_find_art_quest_completion(PlayerType *player_ptr, ObjectType *o_ptr)
276 const auto &quest_list = QuestList::get_instance();
277 /* Check if completed a quest */
278 for (const auto &[q_idx, q_ref] : quest_list) {
279 auto found_artifact = (q_ref.type == QuestKindType::FIND_ARTIFACT);
280 found_artifact &= (q_ref.status == QuestStatusType::TAKEN);
281 found_artifact &= (q_ref.reward_artifact_idx == o_ptr->fixed_artifact_idx);
282 if (found_artifact) {
283 complete_quest(player_ptr, q_idx);
289 * @brief クエストの導入メッセージを表示する / Discover quest
290 * @param q_idx 開始されたクエストのID
292 void quest_discovery(QuestId q_idx)
294 auto &quest_list = QuestList::get_instance();
295 auto *q_ptr = &quest_list[q_idx];
296 auto *r_ptr = &monraces_info[q_ptr->r_idx];
297 MONSTER_NUMBER q_num = q_ptr->max_num;
299 if (!inside_quest(q_idx)) {
303 GAME_TEXT name[MAX_NLEN];
304 strcpy(name, (r_ptr->name.c_str()));
306 msg_print(find_quest_map[rand_range(0, 4)]);
314 msg_format(_("注意しろ!この階は%d体の%sによって守られている!", "Be warned, this level is guarded by %d %s!"), q_num, name);
318 bool is_random_quest_skipped = r_ptr->kind_flags.has(MonsterKindType::UNIQUE);
319 is_random_quest_skipped &= r_ptr->max_num == 0;
320 if (!is_random_quest_skipped) {
321 msg_format(_("注意せよ!この階は%sによって守られている!", "Beware, this level is protected by %s!"), name);
325 msg_print(_("この階は以前は誰かによって守られていたようだ…。", "It seems that this level was protected by someone before..."));
326 record_quest_final_status(q_ptr, 0, QuestStatusType::FINISHED);
330 * @brief 新しく入ったダンジョンの階層に固定されている一般のクエストを探し出しIDを返す。
331 * / Hack -- Check if a level is a "quest" level
332 * @param player_ptr プレイヤーへの参照ポインタ
333 * @param level 検索対象になる階
334 * @return クエストIDを返す。該当がない場合0を返す。
336 QuestId quest_number(PlayerType *player_ptr, DEPTH level)
338 auto *floor_ptr = player_ptr->current_floor_ptr;
339 const auto &quest_list = QuestList::get_instance();
340 if (inside_quest(floor_ptr->quest_number)) {
341 return floor_ptr->quest_number;
344 for (const auto &[q_idx, q_ref] : quest_list) {
345 if (q_ref.status != QuestStatusType::TAKEN) {
348 auto depth_quest = (q_ref.type == QuestKindType::KILL_LEVEL);
349 depth_quest &= !(q_ref.flags & QUEST_FLAG_PRESET);
350 depth_quest &= (q_ref.level == level);
351 depth_quest &= (q_ref.dungeon == player_ptr->dungeon_idx);
357 return random_quest_number(player_ptr, level);
361 * @brief 新しく入ったダンジョンの階層に固定されているランダムクエストを探し出しIDを返す。
362 * @param player_ptr プレイヤーへの参照ポインタ
363 * @param level 検索対象になる階
364 * @return クエストIDを返す。該当がない場合0を返す。
366 QuestId random_quest_number(PlayerType *player_ptr, DEPTH level)
368 if (player_ptr->dungeon_idx != DUNGEON_ANGBAND) {
369 return QuestId::NONE;
372 const auto &quest_list = QuestList::get_instance();
373 for (auto q_idx : EnumRange(QuestId::RANDOM_QUEST1, QuestId::RANDOM_QUEST10)) {
374 const auto &q_ref = quest_list[q_idx];
375 auto is_random_quest = (q_ref.type == QuestKindType::RANDOM);
376 is_random_quest &= (q_ref.status == QuestStatusType::TAKEN);
377 is_random_quest &= (q_ref.level == level);
378 is_random_quest &= (q_ref.dungeon == DUNGEON_ANGBAND);
379 if (is_random_quest) {
384 return QuestId::NONE;
388 * @brief クエスト階層から離脱する際の処理
389 * @param player_ptr プレイヤーへの参照ポインタ
391 void leave_quest_check(PlayerType *player_ptr)
393 leaving_quest = player_ptr->current_floor_ptr->quest_number;
394 if (!inside_quest(leaving_quest)) {
398 auto &quest_list = QuestList::get_instance();
399 auto *q_ptr = &quest_list[leaving_quest];
400 bool is_one_time_quest = ((q_ptr->flags & QUEST_FLAG_ONCE) || (q_ptr->type == QuestKindType::RANDOM)) && (q_ptr->status == QuestStatusType::TAKEN);
401 if (!is_one_time_quest) {
405 record_quest_final_status(q_ptr, player_ptr->lev, QuestStatusType::FAILED);
407 /* Additional settings */
408 switch (q_ptr->type) {
409 case QuestKindType::TOWER:
410 quest_list[QuestId::TOWER1].status = QuestStatusType::FAILED;
411 quest_list[QuestId::TOWER1].complev = player_ptr->lev;
413 case QuestKindType::FIND_ARTIFACT:
414 artifacts_info.at(q_ptr->reward_artifact_idx).gen_flags.reset(ItemGenerationTraitType::QUESTITEM);
416 case QuestKindType::RANDOM:
417 monraces_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
418 prepare_change_floor_mode(player_ptr, CFM_NO_RETURN);
424 /* Record finishing a quest */
425 if (q_ptr->type == QuestKindType::RANDOM) {
426 if (record_rand_quest) {
427 exe_write_diary_quest(player_ptr, DIARY_RAND_QUEST_F, leaving_quest);
432 if (record_fix_quest) {
433 exe_write_diary_quest(player_ptr, DIARY_FIX_QUEST_F, leaving_quest);
438 * @brief 「塔」クエストの各階層から離脱する際の処理
440 void leave_tower_check(PlayerType *player_ptr)
442 auto &quest_list = QuestList::get_instance();
443 leaving_quest = player_ptr->current_floor_ptr->quest_number;
445 auto &tower1 = quest_list[QuestId::TOWER1];
446 bool is_leaving_from_tower = inside_quest(leaving_quest);
447 is_leaving_from_tower &= quest_list[leaving_quest].type == QuestKindType::TOWER;
448 is_leaving_from_tower &= tower1.status != QuestStatusType::COMPLETED;
449 if (!is_leaving_from_tower) {
452 if (quest_list[leaving_quest].type != QuestKindType::TOWER) {
455 tower1.status = QuestStatusType::FAILED;
456 tower1.complev = player_ptr->lev;
458 tower1.comptime = w_ptr->play_time;
462 * @brief Player enters a new quest
464 void exe_enter_quest(PlayerType *player_ptr, QuestId quest_idx)
466 const auto &quest_list = QuestList::get_instance();
467 if (quest_list[quest_idx].type != QuestKindType::RANDOM) {
468 player_ptr->current_floor_ptr->dun_level = 1;
470 player_ptr->current_floor_ptr->quest_number = quest_idx;
472 player_ptr->leaving = true;
476 * @brief クエスト入り口にプレイヤーが乗った際の処理 / Do building commands
477 * @param player_ptr プレイヤーへの参照ポインタ
479 void do_cmd_quest(PlayerType *player_ptr)
481 if (player_ptr->wild_mode) {
485 PlayerEnergy(player_ptr).set_player_turn_energy(100);
487 if (!cave_has_flag_bold(player_ptr->current_floor_ptr, player_ptr->y, player_ptr->x, FloorFeatureType::QUEST_ENTER)) {
488 msg_print(_("ここにはクエストの入口はない。", "You see no quest level here."));
492 msg_print(_("ここにはクエストへの入口があります。", "There is an entry of a quest."));
493 if (!get_check(_("クエストに入りますか?", "Do you enter? "))) {
496 if (is_echizen(player_ptr)) {
497 msg_print(_("『とにかく入ってみようぜぇ。』", "\"Let's go in anyway.\""));
498 } else if (is_chargeman(player_ptr)) {
499 msg_print(_("『全滅してやるぞ!』", "\"I'll annihilate THEM!\""));
502 player_ptr->oldpy = 0;
503 player_ptr->oldpx = 0;
504 leave_quest_check(player_ptr);
506 exe_enter_quest(player_ptr, i2enum<QuestId>(player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].special));
509 bool inside_quest(QuestId id)
511 return id != QuestId::NONE;