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 "dungeon/dungeon.h"
6 #include "floor/cave.h"
7 #include "floor/floor-events.h"
8 #include "floor/floor-mode-changer.h"
9 #include "floor/floor-object.h"
10 #include "game-option/play-record-options.h"
11 #include "grid/feature.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/floor-type-definition.h"
32 #include "system/grid-type-definition.h"
33 #include "system/monster-race-definition.h"
34 #include "system/player-type-definition.h"
35 #include "util/bit-flags-calculator.h"
36 #include "view/display-messages.h"
37 #include "world/world.h"
39 std::vector<quest_type> quest; /*!< Quest info */
40 int16_t max_q_idx; /*!< Maximum number of quests */
41 char quest_text[10][80]; /*!< Quest text */
42 int quest_text_line; /*!< Current line of the quest text */
43 QuestId leaving_quest = QuestId::NONE;
46 * @brief クエスト突入時のメッセージテーブル / Array of places to find an inscription
48 static concptr find_quest[] = {
49 _("床にメッセージが刻まれている:", "You find the following inscription in the floor"),
50 _("壁にメッセージが刻まれている:", "You see a message inscribed in the wall"),
51 _("メッセージを見つけた:", "There is a sign saying"),
52 _("何かが階段の上に書いてある:", "Something is written on the staircase"),
53 _("巻物を見つけた。メッセージが書いてある:", "You find a scroll with the following message"),
57 * @brief 該当IDが固定クエストかどうかを判定する.
58 * @param quest_idx クエストID
59 * @return 固定クエストならばTRUEを返す
61 bool quest_type::is_fixed(QuestId quest_idx)
63 return (enum2i(quest_idx) < MIN_RANDOM_QUEST) || (enum2i(quest_idx) > MAX_RANDOM_QUEST);
67 * @brief ランダムクエストの討伐ユニークを決める / Determine the random quest uniques
68 * @param q_ptr クエスト構造体の参照ポインタ
70 void determine_random_questor(PlayerType *player_ptr, quest_type *q_ptr)
72 get_mon_num_prep(player_ptr, mon_hook_quest, nullptr);
76 * Random monster 5 - 10 levels out of depth
77 * (depending on level)
79 r_idx = get_mon_num(player_ptr, 0, q_ptr->level + 5 + randint1(q_ptr->level / 10), GMN_ARENA);
81 r_ptr = &r_info[r_idx];
83 if (!(r_ptr->flags1 & RF1_UNIQUE))
85 if (r_ptr->flags8 & RF8_NO_QUEST)
87 if (r_ptr->flags1 & RF1_QUESTOR)
89 if (r_ptr->rarity > 100)
91 if (r_ptr->behavior_flags.has(MonsterBehaviorType::FRIENDLY))
93 if (r_ptr->flags7 & RF7_AQUATIC)
95 if (r_ptr->flags8 & RF8_WILD_ONLY)
97 if (no_questor_or_bounty_uniques(r_idx))
101 * Accept monsters that are 2 - 6 levels
102 * out of depth depending on the quest level
104 if (r_ptr->level > (q_ptr->level + (q_ptr->level / 20)))
108 q_ptr->r_idx = r_idx;
112 * @brief クエストの最終状態を記録する(成功or失敗、時間)
113 * @param PlayerType プレイヤー情報への参照ポインタ
114 * @param q_ptr クエスト情報への参照ポインタ
115 * @param stat ステータス(成功or失敗)
117 void record_quest_final_status(quest_type *q_ptr, PLAYER_LEVEL lev, QuestStatusType stat)
119 q_ptr->status = stat;
120 q_ptr->complev = lev;
122 q_ptr->comptime = w_ptr->play_time;
126 * @brief クエストを達成状態にする /
127 * @param player_ptr プレイヤーへの参照ポインタ
128 * @param quest_num 達成状態にしたいクエストのID
130 void complete_quest(PlayerType *player_ptr, QuestId quest_num)
132 quest_type *const q_ptr = &quest[enum2i(quest_num)];
134 switch (q_ptr->type) {
135 case QuestKindType::RANDOM:
136 if (record_rand_quest)
137 exe_write_diary(player_ptr, DIARY_RAND_QUEST_C, enum2i(quest_num), nullptr);
140 if (record_fix_quest)
141 exe_write_diary(player_ptr, DIARY_FIX_QUEST_C, enum2i(quest_num), nullptr);
145 record_quest_final_status(q_ptr, player_ptr->lev, QuestStatusType::COMPLETED);
147 if (q_ptr->flags & QUEST_FLAG_SILENT)
150 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
151 msg_print(_("クエストを達成した!", "You just completed your quest!"));
156 * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
157 * Check for "Quest" completion when a quest monster is killed or charmed.
158 * @param player_ptr プレイヤーへの参照ポインタ
159 * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
161 void check_find_art_quest_completion(PlayerType *player_ptr, ObjectType *o_ptr)
163 /* Check if completed a quest */
164 for (int16_t i = 0; i < max_q_idx; i++) {
165 if ((quest[i].type == QuestKindType::FIND_ARTIFACT) && (quest[i].status == QuestStatusType::TAKEN) && (quest[i].k_idx == o_ptr->name1)) {
166 complete_quest(player_ptr, i2enum<QuestId>(i));
172 * @brief クエストの導入メッセージを表示する / Discover quest
173 * @param q_idx 開始されたクエストのID
175 void quest_discovery(QuestId q_idx)
177 quest_type *q_ptr = &quest[enum2i(q_idx)];
178 auto *r_ptr = &r_info[q_ptr->r_idx];
179 MONSTER_NUMBER q_num = q_ptr->max_num;
181 if (!inside_quest(q_idx))
184 GAME_TEXT name[MAX_NLEN];
185 strcpy(name, (r_ptr->name.c_str()));
187 msg_print(find_quest[rand_range(0, 4)]);
195 msg_format(_("注意しろ!この階は%d体の%sによって守られている!", "Be warned, this level is guarded by %d %s!"), q_num, name);
199 bool is_random_quest_skipped = (r_ptr->flags1 & RF1_UNIQUE) != 0;
200 is_random_quest_skipped &= r_ptr->max_num == 0;
201 if (!is_random_quest_skipped) {
202 msg_format(_("注意せよ!この階は%sによって守られている!", "Beware, this level is protected by %s!"), name);
206 msg_print(_("この階は以前は誰かによって守られていたようだ…。", "It seems that this level was protected by someone before..."));
207 record_quest_final_status(q_ptr, 0, QuestStatusType::FINISHED);
211 * @brief 新しく入ったダンジョンの階層に固定されている一般のクエストを探し出しIDを返す。
212 * / Hack -- Check if a level is a "quest" level
213 * @param player_ptr プレイヤーへの参照ポインタ
214 * @param level 検索対象になる階
215 * @return クエストIDを返す。該当がない場合0を返す。
217 QuestId quest_number(PlayerType *player_ptr, DEPTH level)
219 auto *floor_ptr = player_ptr->current_floor_ptr;
220 if (inside_quest(floor_ptr->quest_number))
221 return (floor_ptr->quest_number);
223 for (int16_t i = 0; i < max_q_idx; i++) {
224 if (quest[i].status != QuestStatusType::TAKEN)
227 if ((quest[i].type == QuestKindType::KILL_LEVEL) && !(quest[i].flags & QUEST_FLAG_PRESET) && (quest[i].level == level) && (quest[i].dungeon == player_ptr->dungeon_idx))
228 return i2enum<QuestId>(i);
231 return random_quest_number(player_ptr, level);
235 * @brief 新しく入ったダンジョンの階層に固定されているランダムクエストを探し出しIDを返す。
236 * @param player_ptr プレイヤーへの参照ポインタ
237 * @param level 検索対象になる階
238 * @return クエストIDを返す。該当がない場合0を返す。
240 QuestId random_quest_number(PlayerType *player_ptr, DEPTH level)
242 if (player_ptr->dungeon_idx != DUNGEON_ANGBAND)
243 return QuestId::NONE;
245 for (int16_t i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++) {
246 if ((quest[i].type == QuestKindType::RANDOM) && (quest[i].status == QuestStatusType::TAKEN) && (quest[i].level == level) && (quest[i].dungeon == DUNGEON_ANGBAND)) {
247 return i2enum<QuestId>(i);
251 return QuestId::NONE;
255 * @brief クエスト階層から離脱する際の処理
256 * @param player_ptr プレイヤーへの参照ポインタ
258 void leave_quest_check(PlayerType *player_ptr)
260 leaving_quest = player_ptr->current_floor_ptr->quest_number;
261 if (!inside_quest(leaving_quest))
264 quest_type *const q_ptr = &quest[enum2i<QuestId>(leaving_quest)];
265 bool is_one_time_quest = ((q_ptr->flags & QUEST_FLAG_ONCE) || (q_ptr->type == QuestKindType::RANDOM)) && (q_ptr->status == QuestStatusType::TAKEN);
266 if (!is_one_time_quest)
269 record_quest_final_status(q_ptr, player_ptr->lev, QuestStatusType::FAILED);
271 /* Additional settings */
272 switch (q_ptr->type) {
273 case QuestKindType::TOWER:
274 quest[enum2i(QuestId::TOWER1)].status = QuestStatusType::FAILED;
275 quest[enum2i(QuestId::TOWER1)].complev = player_ptr->lev;
277 case QuestKindType::FIND_ARTIFACT:
278 a_info[q_ptr->k_idx].gen_flags.reset(ItemGenerationTraitType::QUESTITEM);
280 case QuestKindType::RANDOM:
281 r_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
282 prepare_change_floor_mode(player_ptr, CFM_NO_RETURN);
288 /* Record finishing a quest */
289 if (q_ptr->type == QuestKindType::RANDOM) {
290 if (record_rand_quest)
291 exe_write_diary(player_ptr, DIARY_RAND_QUEST_F, enum2i<QuestId>(leaving_quest), nullptr);
295 if (record_fix_quest)
296 exe_write_diary(player_ptr, DIARY_FIX_QUEST_F, enum2i<QuestId>(leaving_quest), nullptr);
300 * @brief 「塔」クエストの各階層から離脱する際の処理
302 void leave_tower_check(PlayerType *player_ptr)
304 leaving_quest = player_ptr->current_floor_ptr->quest_number;
305 bool is_leaving_from_tower = inside_quest(leaving_quest);
306 is_leaving_from_tower &= quest[enum2i<QuestId>(leaving_quest)].type == QuestKindType::TOWER;
307 is_leaving_from_tower &= quest[enum2i(QuestId::TOWER1)].status != QuestStatusType::COMPLETED;
308 if (!is_leaving_from_tower)
310 if (quest[enum2i<QuestId>(leaving_quest)].type != QuestKindType::TOWER)
313 quest[enum2i(QuestId::TOWER1)].status = QuestStatusType::FAILED;
314 quest[enum2i(QuestId::TOWER1)].complev = player_ptr->lev;
316 quest[enum2i(QuestId::TOWER1)].comptime = w_ptr->play_time;
320 * @brief Player enters a new quest
322 void exe_enter_quest(PlayerType *player_ptr, QuestId quest_idx)
324 if (quest[enum2i<QuestId>(quest_idx)].type != QuestKindType::RANDOM)
325 player_ptr->current_floor_ptr->dun_level = 1;
326 player_ptr->current_floor_ptr->quest_number = quest_idx;
328 player_ptr->leaving = true;
332 * @brief クエスト入り口にプレイヤーが乗った際の処理 / Do building commands
333 * @param player_ptr プレイヤーへの参照ポインタ
335 void do_cmd_quest(PlayerType *player_ptr)
337 if (player_ptr->wild_mode)
340 PlayerEnergy(player_ptr).set_player_turn_energy(100);
342 if (!cave_has_flag_bold(player_ptr->current_floor_ptr, player_ptr->y, player_ptr->x, FloorFeatureType::QUEST_ENTER)) {
343 msg_print(_("ここにはクエストの入口はない。", "You see no quest level here."));
347 msg_print(_("ここにはクエストへの入口があります。", "There is an entry of a quest."));
348 if (!get_check(_("クエストに入りますか?", "Do you enter? ")))
350 if (is_echizen(player_ptr))
351 msg_print(_("『とにかく入ってみようぜぇ。』", "\"Let's go in anyway.\""));
352 else if (is_chargeman(player_ptr))
353 msg_print(_("『全滅してやるぞ!』", "\"I'll annihilate THEM!\""));
355 player_ptr->oldpy = 0;
356 player_ptr->oldpx = 0;
357 leave_quest_check(player_ptr);
359 exe_enter_quest(player_ptr, i2enum<QuestId>(player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].special));
362 bool inside_quest(QuestId id)
364 return id != QuestId::NONE;