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 "info-reader/fixed-map-parser.h"
11 #include "io/write-diary.h"
12 #include "locale/english.h"
13 #include "main/music-definitions-table.h"
14 #include "main/sound-of-music.h"
15 #include "monster-race/monster-race-hook.h"
16 #include "monster-race/monster-race.h"
17 #include "monster-race/race-flags1.h"
18 #include "monster-race/race-flags7.h"
19 #include "monster-race/race-flags8.h"
20 #include "monster/monster-info.h"
21 #include "monster/monster-list.h"
22 #include "monster/monster-util.h"
23 #include "monster/smart-learn-types.h"
24 #include "object-enchant/item-apply-magic.h"
25 #include "object-enchant/trg-types.h"
26 #include "player-status/player-energy.h"
27 #include "player/player-personality-types.h"
28 #include "player/player-status.h"
29 #include "system/artifact-type-definition.h"
30 #include "system/dungeon-info.h"
31 #include "system/floor-type-definition.h"
32 #include "system/grid-type-definition.h"
33 #include "system/item-entity.h"
34 #include "system/monster-race-info.h"
35 #include "system/player-type-definition.h"
36 #include "system/terrain-type-definition.h"
37 #include "util/bit-flags-calculator.h"
38 #include "view/display-messages.h"
39 #include "world/world.h"
43 char quest_text[10][80]; /*!< Quest text */
44 int quest_text_line; /*!< Current line of the quest text */
45 QuestId leaving_quest = QuestId::NONE;
48 * @brief クエスト突入時のメッセージテーブル / Array of places to find an inscription
50 static concptr find_quest_map[] = {
51 _("床にメッセージが刻まれている:", "You find the following inscription in the floor"),
52 _("壁にメッセージが刻まれている:", "You see a message inscribed in the wall"),
53 _("メッセージを見つけた:", "There is a sign saying"),
54 _("何かが階段の上に書いてある:", "Something is written on the staircase"),
55 _("巻物を見つけた。メッセージが書いてある:", "You find a scroll with the following message"),
58 QuestList &QuestList::get_instance()
60 static QuestList instance{};
64 QuestType &QuestList::operator[](QuestId id)
66 return this->quest_data.at(id);
69 const QuestType &QuestList::operator[](QuestId id) const
71 return this->quest_data.at(id);
74 QuestList::iterator QuestList::begin()
76 return this->quest_data.begin();
79 QuestList::const_iterator QuestList::begin() const
81 return this->quest_data.cbegin();
84 QuestList::iterator QuestList::end()
86 return this->quest_data.end();
89 QuestList::const_iterator QuestList::end() const
91 return this->quest_data.cend();
94 QuestList::reverse_iterator QuestList::rbegin()
96 return this->quest_data.rbegin();
99 QuestList::const_reverse_iterator QuestList::rbegin() const
101 return this->quest_data.crbegin();
104 QuestList::reverse_iterator QuestList::rend()
106 return this->quest_data.rend();
109 QuestList::const_reverse_iterator QuestList::rend() const
111 return this->quest_data.crend();
114 QuestList::iterator QuestList::find(QuestId id)
116 return this->quest_data.find(id);
119 QuestList::const_iterator QuestList::find(QuestId id) const
121 return this->quest_data.find(id);
124 size_t QuestList::size() const
126 return this->quest_data.size();
130 * @brief クエスト情報初期化のメインルーチン /
131 * Initialize quest array
133 void QuestList::initialize()
139 auto quest_numbers = parse_quest_info(QUEST_DEFINITION_LIST);
140 QuestType init_quest{};
141 init_quest.status = QuestStatusType::UNTAKEN;
142 this->quest_data.insert({ QuestId::NONE, init_quest });
143 for (auto q : quest_numbers) {
144 this->quest_data.insert({ q, init_quest });
147 } catch (const std::runtime_error &r) {
148 std::stringstream ss;
149 ss << _("ファイル読み込みエラー: ", "File loading error: ") << r.what();
153 quit(_("クエスト初期化エラー", "Error of quests initializing"));
158 * @brief 該当IDが固定クエストかどうかを判定する.
159 * @param quest_idx クエストID
160 * @return 固定クエストならばTRUEを返す
162 bool QuestType::is_fixed(QuestId quest_idx)
164 return (enum2i(quest_idx) < MIN_RANDOM_QUEST) || (enum2i(quest_idx) > MAX_RANDOM_QUEST);
167 ArtifactType &QuestType::get_reward() const
169 const auto &artifacts = ArtifactsInfo::get_instance();
170 return artifacts.get_artifact(this->reward_artifact_idx);
174 * @brief ランダムクエストの討伐ユニークを決める / Determine the random quest uniques
175 * @param q_ptr クエスト構造体の参照ポインタ
177 void determine_random_questor(PlayerType *player_ptr, QuestType *q_ptr)
179 get_mon_num_prep(player_ptr, mon_hook_quest, nullptr);
183 * Random monster 5 - 10 levels out of depth
184 * (depending on level)
186 r_idx = get_mon_num(player_ptr, 0, q_ptr->level + 5 + randint1(q_ptr->level / 10), GMN_ARENA);
187 MonsterRaceInfo *r_ptr;
188 r_ptr = &monraces_info[r_idx];
190 if (r_ptr->kind_flags.has_not(MonsterKindType::UNIQUE)) {
193 if (r_ptr->flags8 & RF8_NO_QUEST) {
196 if (r_ptr->flags1 & RF1_QUESTOR) {
199 if (r_ptr->rarity > 100) {
202 if (r_ptr->behavior_flags.has(MonsterBehaviorType::FRIENDLY)) {
205 if (r_ptr->feature_flags.has(MonsterFeatureType::AQUATIC)) {
208 if (r_ptr->wilderness_flags.has(MonsterWildernessType::WILD_ONLY)) {
211 if (no_questor_or_bounty_uniques(r_idx)) {
216 * Accept monsters that are 2 - 6 levels
217 * out of depth depending on the quest level
219 if (r_ptr->level > (q_ptr->level + (q_ptr->level / 20))) {
224 q_ptr->r_idx = r_idx;
228 * @brief クエストの最終状態を記録する(成功or失敗、時間)
229 * @param PlayerType プレイヤー情報への参照ポインタ
230 * @param q_ptr クエスト情報への参照ポインタ
231 * @param stat ステータス(成功or失敗)
233 void record_quest_final_status(QuestType *q_ptr, PLAYER_LEVEL lev, QuestStatusType stat)
235 q_ptr->status = stat;
236 q_ptr->complev = lev;
238 q_ptr->comptime = w_ptr->play_time;
242 * @brief クエストを達成状態にする /
243 * @param player_ptr プレイヤーへの参照ポインタ
244 * @param quest_num 達成状態にしたいクエストのID
246 void complete_quest(PlayerType *player_ptr, QuestId quest_num)
248 auto &quest_list = QuestList::get_instance();
249 auto *const q_ptr = &quest_list[quest_num];
251 switch (q_ptr->type) {
252 case QuestKindType::RANDOM:
253 if (record_rand_quest) {
254 exe_write_diary_quest(player_ptr, DIARY_RAND_QUEST_C, quest_num);
258 if (record_fix_quest) {
259 exe_write_diary_quest(player_ptr, DIARY_FIX_QUEST_C, quest_num);
264 record_quest_final_status(q_ptr, player_ptr->lev, QuestStatusType::COMPLETED);
266 if (q_ptr->flags & QUEST_FLAG_SILENT) {
270 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
271 msg_print(_("クエストを達成した!", "You just completed your quest!"));
276 * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
277 * Check for "Quest" completion when a quest monster is killed or charmed.
278 * @param player_ptr プレイヤーへの参照ポインタ
279 * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
281 void check_find_art_quest_completion(PlayerType *player_ptr, ItemEntity *o_ptr)
283 const auto &quest_list = QuestList::get_instance();
284 /* Check if completed a quest */
285 for (const auto &[q_idx, q_ref] : quest_list) {
286 auto found_artifact = (q_ref.type == QuestKindType::FIND_ARTIFACT);
287 found_artifact &= (q_ref.status == QuestStatusType::TAKEN);
288 found_artifact &= (o_ptr->is_specific_artifact(q_ref.reward_artifact_idx));
289 if (found_artifact) {
290 complete_quest(player_ptr, q_idx);
296 * @brief クエストの導入メッセージを表示する / Discover quest
297 * @param q_idx 開始されたクエストのID
299 void quest_discovery(QuestId q_idx)
301 auto &quest_list = QuestList::get_instance();
302 auto *q_ptr = &quest_list[q_idx];
303 auto *r_ptr = &monraces_info[q_ptr->r_idx];
304 MONSTER_NUMBER q_num = q_ptr->max_num;
306 if (!inside_quest(q_idx)) {
310 GAME_TEXT name[MAX_NLEN];
311 strcpy(name, (r_ptr->name.data()));
313 msg_print(find_quest_map[rand_range(0, 4)]);
321 msg_format(_("注意しろ!この階は%d体の%sによって守られている!", "Be warned, this level is guarded by %d %s!"), q_num, name);
325 bool is_random_quest_skipped = r_ptr->kind_flags.has(MonsterKindType::UNIQUE);
326 is_random_quest_skipped &= r_ptr->max_num == 0;
327 if (!is_random_quest_skipped) {
328 msg_format(_("注意せよ!この階は%sによって守られている!", "Beware, this level is protected by %s!"), name);
332 msg_print(_("この階は以前は誰かによって守られていたようだ…。", "It seems that this level was protected by someone before..."));
333 record_quest_final_status(q_ptr, 0, QuestStatusType::FINISHED);
337 * @brief 新しく入ったダンジョンの階層に固定されている一般のクエストを探し出しIDを返す。
338 * / Hack -- Check if a level is a "quest" level
339 * @param player_ptr プレイヤーへの参照ポインタ
340 * @param level 検索対象になる階
341 * @return クエストIDを返す。該当がない場合0を返す。
343 QuestId quest_number(PlayerType *player_ptr, DEPTH level)
345 auto *floor_ptr = player_ptr->current_floor_ptr;
346 const auto &quest_list = QuestList::get_instance();
347 if (inside_quest(floor_ptr->quest_number)) {
348 return floor_ptr->quest_number;
351 for (const auto &[q_idx, q_ref] : quest_list) {
352 if (q_ref.status != QuestStatusType::TAKEN) {
355 auto depth_quest = (q_ref.type == QuestKindType::KILL_LEVEL);
356 depth_quest &= !(q_ref.flags & QUEST_FLAG_PRESET);
357 depth_quest &= (q_ref.level == level);
358 depth_quest &= (q_ref.dungeon == player_ptr->dungeon_idx);
364 return random_quest_number(player_ptr, level);
368 * @brief 新しく入ったダンジョンの階層に固定されているランダムクエストを探し出しIDを返す。
369 * @param player_ptr プレイヤーへの参照ポインタ
370 * @param level 検索対象になる階
371 * @return クエストIDを返す。該当がない場合0を返す。
373 QuestId random_quest_number(PlayerType *player_ptr, DEPTH level)
375 if (player_ptr->dungeon_idx != DUNGEON_ANGBAND) {
376 return QuestId::NONE;
379 const auto &quest_list = QuestList::get_instance();
380 for (auto q_idx : EnumRange(QuestId::RANDOM_QUEST1, QuestId::RANDOM_QUEST10)) {
381 const auto &q_ref = quest_list[q_idx];
382 auto is_random_quest = (q_ref.type == QuestKindType::RANDOM);
383 is_random_quest &= (q_ref.status == QuestStatusType::TAKEN);
384 is_random_quest &= (q_ref.level == level);
385 is_random_quest &= (q_ref.dungeon == DUNGEON_ANGBAND);
386 if (is_random_quest) {
391 return QuestId::NONE;
395 * @brief クエスト階層から離脱する際の処理
396 * @param player_ptr プレイヤーへの参照ポインタ
398 void leave_quest_check(PlayerType *player_ptr)
400 leaving_quest = player_ptr->current_floor_ptr->quest_number;
401 if (!inside_quest(leaving_quest)) {
405 auto &quest_list = QuestList::get_instance();
406 auto *q_ptr = &quest_list[leaving_quest];
407 bool is_one_time_quest = ((q_ptr->flags & QUEST_FLAG_ONCE) || (q_ptr->type == QuestKindType::RANDOM)) && (q_ptr->status == QuestStatusType::TAKEN);
408 if (!is_one_time_quest) {
412 record_quest_final_status(q_ptr, player_ptr->lev, QuestStatusType::FAILED);
414 /* Additional settings */
415 switch (q_ptr->type) {
416 case QuestKindType::TOWER:
417 quest_list[QuestId::TOWER1].status = QuestStatusType::FAILED;
418 quest_list[QuestId::TOWER1].complev = player_ptr->lev;
420 case QuestKindType::FIND_ARTIFACT:
421 ArtifactsInfo::get_instance().get_artifact(q_ptr->reward_artifact_idx).gen_flags.reset(ItemGenerationTraitType::QUESTITEM);
423 case QuestKindType::RANDOM:
424 monraces_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
425 prepare_change_floor_mode(player_ptr, CFM_NO_RETURN);
431 /* Record finishing a quest */
432 if (q_ptr->type == QuestKindType::RANDOM) {
433 if (record_rand_quest) {
434 exe_write_diary_quest(player_ptr, DIARY_RAND_QUEST_F, leaving_quest);
439 if (record_fix_quest) {
440 exe_write_diary_quest(player_ptr, DIARY_FIX_QUEST_F, leaving_quest);
445 * @brief 「塔」クエストの各階層から離脱する際の処理
447 void leave_tower_check(PlayerType *player_ptr)
449 auto &quest_list = QuestList::get_instance();
450 leaving_quest = player_ptr->current_floor_ptr->quest_number;
452 auto &tower1 = quest_list[QuestId::TOWER1];
453 bool is_leaving_from_tower = inside_quest(leaving_quest);
454 is_leaving_from_tower &= quest_list[leaving_quest].type == QuestKindType::TOWER;
455 is_leaving_from_tower &= tower1.status != QuestStatusType::COMPLETED;
456 if (!is_leaving_from_tower) {
459 if (quest_list[leaving_quest].type != QuestKindType::TOWER) {
462 tower1.status = QuestStatusType::FAILED;
463 tower1.complev = player_ptr->lev;
465 tower1.comptime = w_ptr->play_time;
469 * @brief Player enters a new quest
471 void exe_enter_quest(PlayerType *player_ptr, QuestId quest_idx)
473 const auto &quest_list = QuestList::get_instance();
474 if (quest_list[quest_idx].type != QuestKindType::RANDOM) {
475 player_ptr->current_floor_ptr->dun_level = 1;
477 player_ptr->current_floor_ptr->quest_number = quest_idx;
479 player_ptr->leaving = true;
483 * @brief クエスト入り口にプレイヤーが乗った際の処理 / Do building commands
484 * @param player_ptr プレイヤーへの参照ポインタ
486 void do_cmd_quest(PlayerType *player_ptr)
488 if (player_ptr->wild_mode) {
492 PlayerEnergy(player_ptr).set_player_turn_energy(100);
494 if (!cave_has_flag_bold(player_ptr->current_floor_ptr, player_ptr->y, player_ptr->x, TerrainCharacteristics::QUEST_ENTER)) {
495 msg_print(_("ここにはクエストの入口はない。", "You see no quest level here."));
499 msg_print(_("ここにはクエストへの入口があります。", "There is an entry of a quest."));
500 if (!get_check(_("クエストに入りますか?", "Do you enter? "))) {
503 if (is_echizen(player_ptr)) {
504 msg_print(_("『とにかく入ってみようぜぇ。』", "\"Let's go in anyway.\""));
505 } else if (is_chargeman(player_ptr)) {
506 msg_print(_("『全滅してやるぞ!』", "\"I'll annihilate THEM!\""));
509 player_ptr->oldpy = 0;
510 player_ptr->oldpx = 0;
511 leave_quest_check(player_ptr);
513 exe_enter_quest(player_ptr, i2enum<QuestId>(player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].special));
516 bool inside_quest(QuestId id)
518 return id != QuestId::NONE;