OSDN Git Service

Merge pull request #932 from sikabane-works/release/3.0.0Alpha20
[hengbandforosx/hengbandosx.git] / src / dungeon / quest.cpp
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 "grid/grid.h"
13 #include "io/write-diary.h"
14 #include "locale/english.h"
15 #include "main/music-definitions-table.h"
16 #include "main/sound-of-music.h"
17 #include "monster-race/monster-race-hook.h"
18 #include "monster-race/monster-race.h"
19 #include "monster-race/race-flags1.h"
20 #include "monster-race/race-flags7.h"
21 #include "monster-race/race-flags8.h"
22 #include "monster/monster-info.h"
23 #include "monster/monster-list.h"
24 #include "monster/monster-util.h"
25 #include "monster/smart-learn-types.h"
26 #include "object-enchant/item-apply-magic.h"
27 #include "object-enchant/trg-types.h"
28 #include "object/object-generator.h"
29 #include "player/player-personalities-types.h"
30 #include "player/player-status.h"
31 #include "system/artifact-type-definition.h"
32 #include "system/floor-type-definition.h"
33 #include "system/system-variables.h"
34 #include "util/bit-flags-calculator.h"
35 #include "view/display-messages.h"
36 #include "world/world.h"
37
38 quest_type *quest; /*!< Quest info */
39 QUEST_IDX max_q_idx; /*!< Maximum number of quests */
40 char quest_text[10][80]; /*!< Quest text */
41 int quest_text_line; /*!< Current line of the quest text */
42 int leaving_quest = 0;
43
44 /*!
45  * @brief クエスト突入時のメッセージテーブル / Array of places to find an inscription
46  */
47 static concptr find_quest[] = {
48     _("床にメッセージが刻まれている:", "You find the following inscription in the floor"),
49     _("壁にメッセージが刻まれている:", "You see a message inscribed in the wall"),
50     _("メッセージを見つけた:", "There is a sign saying"),
51     _("何かが階段の上に書いてある:", "Something is written on the staircase"),
52     _("巻物を見つけた。メッセージが書いてある:", "You find a scroll with the following message"),
53 };
54
55 /*!
56  * @brief ランダムクエストの討伐ユニークを決める / Determine the random quest uniques
57  * @param q_ptr クエスト構造体の参照ポインタ
58  * @return なし
59  */
60 void determine_random_questor(player_type *player_ptr, quest_type *q_ptr)
61 {
62     get_mon_num_prep(player_ptr, mon_hook_quest, NULL);
63
64     MONRACE_IDX r_idx;
65     while (TRUE) {
66         /*
67          * Random monster 5 - 10 levels out of depth
68          * (depending on level)
69          */
70         r_idx = get_mon_num(player_ptr, 0, q_ptr->level + 5 + randint1(q_ptr->level / 10), GMN_ARENA);
71         monster_race *r_ptr;
72         r_ptr = &r_info[r_idx];
73
74         if (!(r_ptr->flags1 & RF1_UNIQUE))
75             continue;
76         if (r_ptr->flags1 & RF1_QUESTOR)
77             continue;
78         if (r_ptr->rarity > 100)
79             continue;
80         if (r_ptr->flags7 & RF7_FRIENDLY)
81             continue;
82         if (r_ptr->flags7 & RF7_AQUATIC)
83             continue;
84         if (r_ptr->flags8 & RF8_WILD_ONLY)
85             continue;
86         if (no_questor_or_bounty_uniques(r_idx))
87             continue;
88
89         /*
90          * Accept monsters that are 2 - 6 levels
91          * out of depth depending on the quest level
92          */
93         if (r_ptr->level > (q_ptr->level + (q_ptr->level / 20)))
94             break;
95     }
96
97     q_ptr->r_idx = r_idx;
98 }
99
100 /*!
101  * @brief クエストの最終状態を記録する(成功or失敗、時間)
102  * @param player_type プレイヤー情報への参照ポインタ
103  * @param q_ptr クエスト情報への参照ポインタ
104  * @param stat ステータス(成功or失敗)
105  * @return なし
106  */
107 void record_quest_final_status(quest_type *q_ptr, PLAYER_LEVEL lev, QUEST_STATUS stat)
108 {
109     q_ptr->status = stat;
110     q_ptr->complev = lev;
111     update_playtime();
112     q_ptr->comptime = current_world_ptr->play_time;
113 }
114
115 /*!
116  * @brief クエストを達成状態にする /
117  * @param player_ptr プレーヤーへの参照ポインタ
118  * @param quest_num 達成状態にしたいクエストのID
119  * @return なし
120  */
121 void complete_quest(player_type *player_ptr, QUEST_IDX quest_num)
122 {
123     quest_type *const q_ptr = &quest[quest_num];
124
125     switch (q_ptr->type) {
126     case QUEST_TYPE_RANDOM:
127         if (record_rand_quest)
128             exe_write_diary(player_ptr, DIARY_RAND_QUEST_C, quest_num, NULL);
129         break;
130     default:
131         if (record_fix_quest)
132             exe_write_diary(player_ptr, DIARY_FIX_QUEST_C, quest_num, NULL);
133         break;
134     }
135
136     record_quest_final_status(q_ptr, player_ptr->lev, QUEST_STATUS_COMPLETED);
137
138     if (q_ptr->flags & QUEST_FLAG_SILENT)
139         return;
140
141     play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
142     msg_print(_("クエストを達成した!", "You just completed your quest!"));
143     msg_print(NULL);
144 }
145
146 /*!
147  * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
148  * Check for "Quest" completion when a quest monster is killed or charmed.
149  * @param player_ptr プレーヤーへの参照ポインタ
150  * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
151  * @return なし
152  */
153 void check_find_art_quest_completion(player_type *player_ptr, object_type *o_ptr)
154 {
155     /* Check if completed a quest */
156     for (QUEST_IDX i = 0; i < max_q_idx; i++) {
157         if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) && (quest[i].status == QUEST_STATUS_TAKEN) && (quest[i].k_idx == o_ptr->name1)) {
158             complete_quest(player_ptr, i);
159         }
160     }
161 }
162
163 /*!
164  * @brief クエストの導入メッセージを表示する / Discover quest
165  * @param q_idx 開始されたクエストのID
166  */
167 void quest_discovery(QUEST_IDX q_idx)
168 {
169     quest_type *q_ptr = &quest[q_idx];
170     monster_race *r_ptr = &r_info[q_ptr->r_idx];
171     MONSTER_NUMBER q_num = q_ptr->max_num;
172
173     if (!q_idx)
174         return;
175
176     GAME_TEXT name[MAX_NLEN];
177     strcpy(name, (r_ptr->name.c_str()));
178
179     msg_print(find_quest[rand_range(0, 4)]);
180     msg_print(NULL);
181
182     if (q_num != 1) {
183 #ifdef JP
184 #else
185         plural_aux(name);
186 #endif
187         msg_format(_("注意しろ!この階は%d体の%sによって守られている!", "Be warned, this level is guarded by %d %s!"), q_num, name);
188         return;
189     }
190
191     bool is_random_quest_skipped = (r_ptr->flags1 & RF1_UNIQUE) != 0;
192     is_random_quest_skipped &= r_ptr->max_num == 0;
193     if (!is_random_quest_skipped) {
194         msg_format(_("注意せよ!この階は%sによって守られている!", "Beware, this level is protected by %s!"), name);
195         return;
196     }
197
198     msg_print(_("この階は以前は誰かによって守られていたようだ…。", "It seems that this level was protected by someone before..."));
199     record_quest_final_status(q_ptr, 0, QUEST_STATUS_FINISHED);
200 }
201
202 /*!
203  * @brief 新しく入ったダンジョンの階層に固定されている一般のクエストを探し出しIDを返す。
204  * / Hack -- Check if a level is a "quest" level
205  * @param player_ptr プレーヤーへの参照ポインタ
206  * @param level 検索対象になる階
207  * @return クエストIDを返す。該当がない場合0を返す。
208  */
209 QUEST_IDX quest_number(player_type *player_ptr, DEPTH level)
210 {
211     floor_type *floor_ptr = player_ptr->current_floor_ptr;
212     if (floor_ptr->inside_quest)
213         return (floor_ptr->inside_quest);
214
215     for (QUEST_IDX i = 0; i < max_q_idx; i++) {
216         if (quest[i].status != QUEST_STATUS_TAKEN)
217             continue;
218
219         if ((quest[i].type == QUEST_TYPE_KILL_LEVEL) && !(quest[i].flags & QUEST_FLAG_PRESET) && (quest[i].level == level)
220             && (quest[i].dungeon == player_ptr->dungeon_idx))
221             return i;
222     }
223
224     return random_quest_number(player_ptr, level);
225 }
226
227 /*!
228  * @brief 新しく入ったダンジョンの階層に固定されているランダムクエストを探し出しIDを返す。
229  * @param player_ptr プレーヤーへの参照ポインタ
230  * @param level 検索対象になる階
231  * @return クエストIDを返す。該当がない場合0を返す。
232  */
233 QUEST_IDX random_quest_number(player_type *player_ptr, DEPTH level)
234 {
235     if (player_ptr->dungeon_idx != DUNGEON_ANGBAND)
236         return 0;
237
238     for (QUEST_IDX i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++) {
239         if ((quest[i].type == QUEST_TYPE_RANDOM) && (quest[i].status == QUEST_STATUS_TAKEN) && (quest[i].level == level)
240             && (quest[i].dungeon == DUNGEON_ANGBAND)) {
241             return i;
242         }
243     }
244
245     return 0;
246 }
247
248 /*!
249  * @brief クエスト階層から離脱する際の処理
250  * @param player_ptr プレーヤーへの参照ポインタ
251  * @return なし
252  */
253 void leave_quest_check(player_type *player_ptr)
254 {
255     leaving_quest = player_ptr->current_floor_ptr->inside_quest;
256     if (!leaving_quest)
257         return;
258
259     quest_type *const q_ptr = &quest[leaving_quest];
260     bool is_one_time_quest = ((q_ptr->flags & QUEST_FLAG_ONCE) || (q_ptr->type == QUEST_TYPE_RANDOM)) && (q_ptr->status == QUEST_STATUS_TAKEN);
261     if (!is_one_time_quest)
262         return;
263
264     record_quest_final_status(q_ptr, player_ptr->lev, QUEST_STATUS_FAILED);
265
266     /* Additional settings */
267     switch (q_ptr->type) {
268     case QUEST_TYPE_TOWER:
269         quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
270         quest[QUEST_TOWER1].complev = player_ptr->lev;
271         break;
272     case QUEST_TYPE_FIND_ARTIFACT:
273         a_info[q_ptr->k_idx].gen_flags.reset(TRG::QUESTITEM);
274         break;
275     case QUEST_TYPE_RANDOM:
276         r_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
277
278         /* Floor of random quest will be blocked */
279         prepare_change_floor_mode(player_ptr, CFM_NO_RETURN);
280         break;
281     }
282
283     /* Record finishing a quest */
284     if (q_ptr->type == QUEST_TYPE_RANDOM) {
285         if (record_rand_quest)
286             exe_write_diary(player_ptr, DIARY_RAND_QUEST_F, leaving_quest, NULL);
287         return;
288     }
289
290     if (record_fix_quest)
291         exe_write_diary(player_ptr, DIARY_FIX_QUEST_F, leaving_quest, NULL);
292 }
293
294 /*!
295  * @brief 「塔」クエストの各階層から離脱する際の処理
296  * @return なし
297  */
298 void leave_tower_check(player_type *player_ptr)
299 {
300     leaving_quest = player_ptr->current_floor_ptr->inside_quest;
301     bool is_leaving_from_tower = leaving_quest != 0;
302     is_leaving_from_tower &= quest[leaving_quest].type == QUEST_TYPE_TOWER;
303     is_leaving_from_tower &= quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED;
304     if (!is_leaving_from_tower)
305         return;
306     if (quest[leaving_quest].type != QUEST_TYPE_TOWER)
307         return;
308
309     quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
310     quest[QUEST_TOWER1].complev = player_ptr->lev;
311     update_playtime();
312     quest[QUEST_TOWER1].comptime = current_world_ptr->play_time;
313 }
314
315 /*!
316  * @brief クエスト入り口にプレイヤーが乗った際の処理 / Do building commands
317  * @param player_ptr プレーヤーへの参照ポインタ
318  * @return なし
319  */
320 void do_cmd_quest(player_type *player_ptr)
321 {
322     if (player_ptr->wild_mode)
323         return;
324
325     take_turn(player_ptr, 100);
326
327     if (!cave_has_flag_bold(player_ptr->current_floor_ptr, player_ptr->y, player_ptr->x, FF_QUEST_ENTER)) {
328         msg_print(_("ここにはクエストの入口はない。", "You see no quest level here."));
329         return;
330     }
331
332     msg_print(_("ここにはクエストへの入口があります。", "There is an entry of a quest."));
333     if (!get_check(_("クエストに入りますか?", "Do you enter? ")))
334         return;
335     if (is_echizen(player_ptr))
336         msg_print(_("『とにかく入ってみようぜぇ。』", "\"Let's go in anyway.\""));
337     else if (player_ptr->pseikaku == PERSONALITY_CHARGEMAN)
338         msg_print(_("『全滅してやるぞ!』", "\"I'll annihilate THEM!\""));
339
340     /* Player enters a new quest */
341     player_ptr->oldpy = 0;
342     player_ptr->oldpx = 0;
343
344     leave_quest_check(player_ptr);
345
346     if (quest[player_ptr->current_floor_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
347         player_ptr->current_floor_ptr->dun_level = 1;
348     player_ptr->current_floor_ptr->inside_quest = player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].special;
349
350     player_ptr->leaving = TRUE;
351 }