OSDN Git Service

Merge branch 'feature/bounty-endless-loop' into develop
[hengband/hengband.git] / src / dungeon / quest.c
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 クエストを達成状態にする /
102  * @param player_ptr プレーヤーへの参照ポインタ
103  * @param quest_num 達成状態にしたいクエストのID
104  * @return なし
105  */
106 void complete_quest(player_type *player_ptr, QUEST_IDX quest_num)
107 {
108     quest_type *const q_ptr = &quest[quest_num];
109
110     switch (q_ptr->type) {
111     case QUEST_TYPE_RANDOM:
112         if (record_rand_quest)
113             exe_write_diary(player_ptr, DIARY_RAND_QUEST_C, quest_num, NULL);
114         break;
115     default:
116         if (record_fix_quest)
117             exe_write_diary(player_ptr, DIARY_FIX_QUEST_C, quest_num, NULL);
118         break;
119     }
120
121     q_ptr->status = QUEST_STATUS_COMPLETED;
122     q_ptr->complev = player_ptr->lev;
123     update_playtime();
124     q_ptr->comptime = current_world_ptr->play_time;
125
126     if (q_ptr->flags & QUEST_FLAG_SILENT)
127         return;
128
129     play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
130     msg_print(_("クエストを達成した!", "You just completed your quest!"));
131     msg_print(NULL);
132 }
133
134 /*!
135  * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
136  * Check for "Quest" completion when a quest monster is killed or charmed.
137  * @param player_ptr プレーヤーへの参照ポインタ
138  * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
139  * @return なし
140  */
141 void check_find_art_quest_completion(player_type *player_ptr, object_type *o_ptr)
142 {
143     /* Check if completed a quest */
144     for (QUEST_IDX i = 0; i < max_q_idx; i++) {
145         if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) && (quest[i].status == QUEST_STATUS_TAKEN) && (quest[i].k_idx == o_ptr->name1)) {
146             complete_quest(player_ptr, i);
147         }
148     }
149 }
150
151 /*!
152  * @brief クエストの導入メッセージを表示する / Discover quest
153  * @param q_idx 開始されたクエストのID
154  */
155 void quest_discovery(QUEST_IDX q_idx)
156 {
157     quest_type *q_ptr = &quest[q_idx];
158     monster_race *r_ptr = &r_info[q_ptr->r_idx];
159     MONSTER_NUMBER q_num = q_ptr->max_num;
160
161     if (!q_idx)
162         return;
163
164     GAME_TEXT name[MAX_NLEN];
165     strcpy(name, (r_name + r_ptr->name));
166
167     msg_print(find_quest[rand_range(0, 4)]);
168     msg_print(NULL);
169
170     if (q_num != 1) {
171 #ifdef JP
172 #else
173         plural_aux(name);
174 #endif
175         msg_format(_("注意しろ!この階は%d体の%sによって守られている!", "Be warned, this level is guarded by %d %s!"), q_num, name);
176         return;
177     }
178
179     bool is_random_quest_skipped = (r_ptr->flags1 & RF1_UNIQUE) != 0;
180     is_random_quest_skipped &= r_ptr->max_num == 0;
181     if (!is_random_quest_skipped) {
182         msg_format(_("注意せよ!この階は%sによって守られている!", "Beware, this level is protected by %s!"), name);
183         return;
184     }
185
186     msg_print(_("この階は以前は誰かによって守られていたようだ…。", "It seems that this level was protected by someone before..."));
187     quest[q_idx].status = QUEST_STATUS_FINISHED;
188     q_ptr->complev = 0;
189     update_playtime();
190     q_ptr->comptime = current_world_ptr->play_time;
191 }
192
193 /*!
194  * @brief 新しく入ったダンジョンの階層に固定されている一般のクエストを探し出しIDを返す。
195  * / Hack -- Check if a level is a "quest" level
196  * @param player_ptr プレーヤーへの参照ポインタ
197  * @param level 検索対象になる階
198  * @return クエストIDを返す。該当がない場合0を返す。
199  */
200 QUEST_IDX quest_number(player_type *player_ptr, DEPTH level)
201 {
202     floor_type *floor_ptr = player_ptr->current_floor_ptr;
203     if (floor_ptr->inside_quest)
204         return (floor_ptr->inside_quest);
205
206     for (QUEST_IDX i = 0; i < max_q_idx; i++) {
207         if (quest[i].status != QUEST_STATUS_TAKEN)
208             continue;
209
210         if ((quest[i].type == QUEST_TYPE_KILL_LEVEL) && !(quest[i].flags & QUEST_FLAG_PRESET) && (quest[i].level == level)
211             && (quest[i].dungeon == player_ptr->dungeon_idx))
212             return i;
213     }
214
215     return random_quest_number(player_ptr, level);
216 }
217
218 /*!
219  * @brief 新しく入ったダンジョンの階層に固定されているランダムクエストを探し出しIDを返す。
220  * @param player_ptr プレーヤーへの参照ポインタ
221  * @param level 検索対象になる階
222  * @return クエストIDを返す。該当がない場合0を返す。
223  */
224 QUEST_IDX random_quest_number(player_type *player_ptr, DEPTH level)
225 {
226     if (player_ptr->dungeon_idx != DUNGEON_ANGBAND)
227         return 0;
228
229     for (QUEST_IDX i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++) {
230         if ((quest[i].type == QUEST_TYPE_RANDOM) && (quest[i].status == QUEST_STATUS_TAKEN) && (quest[i].level == level)
231             && (quest[i].dungeon == DUNGEON_ANGBAND)) {
232             return i;
233         }
234     }
235
236     return 0;
237 }
238
239 /*!
240  * @brief クエスト階層から離脱する際の処理
241  * @param player_ptr プレーヤーへの参照ポインタ
242  * @return なし
243  */
244 void leave_quest_check(player_type *player_ptr)
245 {
246     leaving_quest = player_ptr->current_floor_ptr->inside_quest;
247     if (!leaving_quest)
248         return;
249
250     quest_type *const q_ptr = &quest[leaving_quest];
251     bool is_one_time_quest = ((q_ptr->flags & QUEST_FLAG_ONCE) || (q_ptr->type == QUEST_TYPE_RANDOM)) && (q_ptr->status == QUEST_STATUS_TAKEN);
252     if (!is_one_time_quest)
253         return;
254
255     q_ptr->status = QUEST_STATUS_FAILED;
256     q_ptr->complev = player_ptr->lev;
257     update_playtime();
258     q_ptr->comptime = current_world_ptr->play_time;
259
260     /* Additional settings */
261     switch (q_ptr->type) {
262     case QUEST_TYPE_TOWER:
263         quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
264         quest[QUEST_TOWER1].complev = player_ptr->lev;
265         break;
266     case QUEST_TYPE_FIND_ARTIFACT:
267         a_info[q_ptr->k_idx].gen_flags &= ~(TRG_QUESTITEM);
268         break;
269     case QUEST_TYPE_RANDOM:
270         r_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
271
272         /* Floor of random quest will be blocked */
273         prepare_change_floor_mode(player_ptr, CFM_NO_RETURN);
274         break;
275     }
276
277     /* Record finishing a quest */
278     if (q_ptr->type == QUEST_TYPE_RANDOM) {
279         if (record_rand_quest)
280             exe_write_diary(player_ptr, DIARY_RAND_QUEST_F, leaving_quest, NULL);
281         return;
282     }
283
284     if (record_fix_quest)
285         exe_write_diary(player_ptr, DIARY_FIX_QUEST_F, leaving_quest, NULL);
286 }
287
288 /*!
289  * @brief 「塔」クエストの各階層から離脱する際の処理
290  * @return なし
291  */
292 void leave_tower_check(player_type *player_ptr)
293 {
294     leaving_quest = player_ptr->current_floor_ptr->inside_quest;
295     bool is_leaving_from_tower = leaving_quest != 0;
296     is_leaving_from_tower &= quest[leaving_quest].type == QUEST_TYPE_TOWER;
297     is_leaving_from_tower &= quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED;
298     if (!is_leaving_from_tower)
299         return;
300     if (quest[leaving_quest].type != QUEST_TYPE_TOWER)
301         return;
302
303     quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
304     quest[QUEST_TOWER1].complev = player_ptr->lev;
305     update_playtime();
306     quest[QUEST_TOWER1].comptime = current_world_ptr->play_time;
307 }
308
309 /*!
310  * @brief クエスト入り口にプレイヤーが乗った際の処理 / Do building commands
311  * @param player_ptr プレーヤーへの参照ポインタ
312  * @return なし
313  */
314 void do_cmd_quest(player_type *player_ptr)
315 {
316     if (player_ptr->wild_mode)
317         return;
318
319     take_turn(player_ptr, 100);
320
321     if (!cave_has_flag_bold(player_ptr->current_floor_ptr, player_ptr->y, player_ptr->x, FF_QUEST_ENTER)) {
322         msg_print(_("ここにはクエストの入口はない。", "You see no quest level here."));
323         return;
324     }
325
326     msg_print(_("ここにはクエストへの入口があります。", "There is an entry of a quest."));
327     if (!get_check(_("クエストに入りますか?", "Do you enter? ")))
328         return;
329     if (is_echizen(player_ptr))
330         msg_print(_("『とにかく入ってみようぜぇ。』", ""));
331     else if (player_ptr->pseikaku == PERSONALITY_CHARGEMAN)
332         msg_print("『全滅してやるぞ!』");
333
334     /* Player enters a new quest */
335     player_ptr->oldpy = 0;
336     player_ptr->oldpx = 0;
337
338     leave_quest_check(player_ptr);
339
340     if (quest[player_ptr->current_floor_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
341         player_ptr->current_floor_ptr->dun_level = 1;
342     player_ptr->current_floor_ptr->inside_quest = player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].special;
343
344     player_ptr->leaving = TRUE;
345 }