OSDN Git Service

7590e1740c7d6d7c2cb84a070f310f0079501dee
[hengband/hengband.git] / src / quest.c
1 #include "angband.h"
2 #include "floor-events.h"
3 #include "quest.h"
4 #include "monsterrace-hook.h"
5
6
7 /*!
8  * @brief クエスト突入時のメッセージテーブル / Array of places to find an inscription
9  */
10 static concptr find_quest[] =
11 {
12         _("床にメッセージが刻まれている:", "You find the following inscription in the floor"),
13         _("壁にメッセージが刻まれている:", "You see a message inscribed in the wall"),
14         _("メッセージを見つけた:", "There is a sign saying"),
15         _("何かが階段の上に書いてある:", "Something is written on the staircase"),
16         _("巻物を見つけた。メッセージが書いてある:", "You find a scroll with the following message"),
17 };
18
19 /*!
20  * @brief ランダムクエストの討伐ユニークを決める / Determine the random quest uniques
21  * @param q_ptr クエスト構造体の参照ポインタ
22  * @return なし
23  */
24 void determine_random_questor(quest_type *q_ptr)
25 {
26         MONRACE_IDX r_idx;
27         monster_race *r_ptr;
28
29         get_mon_num_prep(mon_hook_quest, NULL);
30
31         while (1)
32         {
33                 /*
34                  * Random monster 5 - 10 levels out of depth
35                  * (depending on level)
36                  */
37                 r_idx = get_mon_num(q_ptr->level + 5 + randint1(q_ptr->level / 10));
38                 r_ptr = &r_info[r_idx];
39
40                 if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
41                 if (r_ptr->flags1 & RF1_QUESTOR) continue;
42                 if (r_ptr->rarity > 100) continue;
43                 if (r_ptr->flags7 & RF7_FRIENDLY) continue;
44                 if (r_ptr->flags7 & RF7_AQUATIC) continue;
45                 if (r_ptr->flags8 & RF8_WILD_ONLY) continue;
46                 if (no_questor_or_bounty_uniques(r_idx)) continue;
47
48                 /*
49                  * Accept monsters that are 2 - 6 levels
50                  * out of depth depending on the quest level
51                  */
52                 if (r_ptr->level > (q_ptr->level + (q_ptr->level / 20))) break;
53         }
54
55         q_ptr->r_idx = r_idx;
56 }
57
58 /*!
59  * @brief クエストを達成状態にする /
60  * @param quest_num 達成状態にしたいクエストのID
61  * @return なし
62  */
63 void complete_quest(QUEST_IDX quest_num)
64 {
65         quest_type* const q_ptr = &quest[quest_num];
66
67         switch (q_ptr->type)
68         {
69         case QUEST_TYPE_RANDOM:
70                 if (record_rand_quest) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, quest_num, NULL);
71                 break;
72         default:
73                 if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, quest_num, NULL);
74                 break;
75         }
76
77         q_ptr->status = QUEST_STATUS_COMPLETED;
78         q_ptr->complev = p_ptr->lev;
79         update_playtime();
80         q_ptr->comptime = playtime;
81
82         if (!(q_ptr->flags & QUEST_FLAG_SILENT))
83         {
84                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
85                 msg_print(_("クエストを達成した!", "You just completed your quest!"));
86                 msg_print(NULL);
87         }
88 }
89
90
91
92 /*!
93  * @brief 特定の敵を倒した際にクエスト達成処理 /
94  * Check for "Quest" completion when a quest monster is killed or charmed.
95  * @param m_ptr 撃破したモンスターの構造体参照ポインタ
96  * @return なし
97  */
98 void check_quest_completion(monster_type *m_ptr)
99 {
100         POSITION y, x;
101         QUEST_IDX quest_num;
102
103         bool create_stairs = FALSE;
104         bool reward = FALSE;
105
106         object_type forge;
107         object_type *o_ptr;
108
109         y = m_ptr->fy;
110         x = m_ptr->fx;
111
112         /* Inside a quest */
113         quest_num = p_ptr->inside_quest;
114
115         /* Search for an active quest on this dungeon level */
116         if (!quest_num)
117         {
118                 QUEST_IDX i;
119
120                 for (i = max_q_idx - 1; i > 0; i--)
121                 {
122                         quest_type* const q_ptr = &quest[i];
123
124                         /* Quest is not active */
125                         if (q_ptr->status != QUEST_STATUS_TAKEN)
126                                 continue;
127
128                         /* Quest is not a dungeon quest */
129                         if (q_ptr->flags & QUEST_FLAG_PRESET)
130                                 continue;
131
132                         /* Quest is not on this level */
133                         if ((q_ptr->level != dun_level) &&
134                                 (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
135                                 continue;
136
137                         /* Not a "kill monster" quest */
138                         if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
139                                 (q_ptr->type == QUEST_TYPE_FIND_EXIT))
140                                 continue;
141
142                         /* Interesting quest */
143                         if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
144                                 (q_ptr->type == QUEST_TYPE_TOWER) ||
145                                 (q_ptr->type == QUEST_TYPE_KILL_ALL))
146                                 break;
147
148                         /* Interesting quest */
149                         if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
150                                 (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
151                                 (q_ptr->type == QUEST_TYPE_RANDOM)) &&
152                                 (q_ptr->r_idx == m_ptr->r_idx))
153                                 break;
154                 }
155
156                 quest_num = i;
157         }
158
159         /* Handle the current quest */
160         if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
161         {
162                 /* Current quest */
163                 quest_type* const q_ptr = &quest[quest_num];
164
165                 switch (q_ptr->type)
166                 {
167                 case QUEST_TYPE_KILL_NUMBER:
168                 {
169                         q_ptr->cur_num++;
170
171                         if (q_ptr->cur_num >= q_ptr->num_mon)
172                         {
173                                 complete_quest(quest_num);
174
175                                 q_ptr->cur_num = 0;
176                         }
177                         break;
178                 }
179                 case QUEST_TYPE_KILL_ALL:
180                 {
181                         if (!is_hostile(m_ptr)) break;
182
183                         if (count_all_hostile_monsters() == 1)
184                         {
185                                 if (q_ptr->flags & QUEST_FLAG_SILENT)
186                                 {
187                                         q_ptr->status = QUEST_STATUS_FINISHED;
188                                 }
189                                 else
190                                 {
191                                         complete_quest(quest_num);
192                                 }
193                         }
194                         break;
195                 }
196                 case QUEST_TYPE_KILL_LEVEL:
197                 case QUEST_TYPE_RANDOM:
198                 {
199                         /* Only count valid monsters */
200                         if (q_ptr->r_idx != m_ptr->r_idx)
201                                 break;
202
203                         q_ptr->cur_num++;
204
205                         if (q_ptr->cur_num >= q_ptr->max_num)
206                         {
207                                 complete_quest(quest_num);
208
209                                 if (!(q_ptr->flags & QUEST_FLAG_PRESET))
210                                 {
211                                         create_stairs = TRUE;
212                                         p_ptr->inside_quest = 0;
213                                 }
214
215                                 /* Finish the two main quests without rewarding */
216                                 if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
217                                 {
218                                         q_ptr->status = QUEST_STATUS_FINISHED;
219                                 }
220
221                                 if (q_ptr->type == QUEST_TYPE_RANDOM)
222                                 {
223                                         reward = TRUE;
224                                         q_ptr->status = QUEST_STATUS_FINISHED;
225                                 }
226                         }
227                         break;
228                 }
229                 case QUEST_TYPE_KILL_ANY_LEVEL:
230                 {
231                         q_ptr->cur_num++;
232                         if (q_ptr->cur_num >= q_ptr->max_num)
233                         {
234                                 complete_quest(quest_num);
235                                 q_ptr->cur_num = 0;
236                         }
237                         break;
238                 }
239                 case QUEST_TYPE_TOWER:
240                 {
241                         if (!is_hostile(m_ptr)) break;
242
243                         if (count_all_hostile_monsters() == 1)
244                         {
245                                 q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
246
247                                 if ((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
248                                         (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
249                                         (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
250                                 {
251
252                                         complete_quest(QUEST_TOWER1);
253                                 }
254                         }
255                         break;
256                 }
257                 }
258         }
259
260         /* Create a magical staircase */
261         if (create_stairs)
262         {
263                 POSITION ny, nx;
264
265                 /* Stagger around */
266                 while (cave_perma_bold(y, x) || cave[y][x].o_idx || (cave[y][x].info & CAVE_OBJECT))
267                 {
268                         /* Pick a location */
269                         scatter(&ny, &nx, y, x, 1, 0);
270
271                         /* Stagger */
272                         y = ny; x = nx;
273                 }
274
275                 /* Explain the staircase */
276                 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
277
278                 /* Create stairs down */
279                 cave_set_feat(y, x, feat_down_stair);
280
281                 /* Remember to update everything */
282                 p_ptr->update |= (PU_FLOW);
283         }
284
285         /*
286          * Drop quest reward
287          */
288         if (reward)
289         {
290                 int i;
291
292                 for (i = 0; i < (dun_level / 15) + 1; i++)
293                 {
294                         o_ptr = &forge;
295                         object_wipe(o_ptr);
296
297                         /* Make a great object */
298                         make_object(o_ptr, AM_GOOD | AM_GREAT);
299                         (void)drop_near(o_ptr, -1, y, x);
300                 }
301         }
302 }
303
304 /*!
305  * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
306  * Check for "Quest" completion when a quest monster is killed or charmed.
307  * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
308  * @return なし
309  */
310 void check_find_art_quest_completion(object_type *o_ptr)
311 {
312         QUEST_IDX i;
313         /* Check if completed a quest */
314         for (i = 0; i < max_q_idx; i++)
315         {
316                 if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
317                         (quest[i].status == QUEST_STATUS_TAKEN) &&
318                         (quest[i].k_idx == o_ptr->name1))
319                 {
320                         complete_quest(i);
321                 }
322         }
323 }
324
325
326 /*!
327  * @brief クエストの導入メッセージを表示する / Discover quest
328  * @param q_idx 開始されたクエストのID
329  */
330 void quest_discovery(QUEST_IDX q_idx)
331 {
332         quest_type *q_ptr = &quest[q_idx];
333         monster_race *r_ptr = &r_info[q_ptr->r_idx];
334         MONSTER_NUMBER q_num = q_ptr->max_num;
335         GAME_TEXT name[MAX_NLEN];
336
337         /* No quest index */
338         if (!q_idx) return;
339
340         strcpy(name, (r_name + r_ptr->name));
341
342         msg_print(find_quest[rand_range(0, 4)]);
343         msg_print(NULL);
344
345         if (q_num == 1)
346         {
347                 /* Unique */
348
349                 /* Hack -- "unique" monsters must be "unique" */
350                 if ((r_ptr->flags1 & RF1_UNIQUE) && (0 == r_ptr->max_num))
351                 {
352                         msg_print(_("この階は以前は誰かによって守られていたようだ…。", "It seems that this level was protected by someone before..."));
353                         /* The unique is already dead */
354                         quest[q_idx].status = QUEST_STATUS_FINISHED;
355                         q_ptr->complev = 0;
356                         update_playtime();
357                         q_ptr->comptime = playtime;
358                 }
359                 else
360                 {
361                         msg_format(_("注意せよ!この階は%sによって守られている!", "Beware, this level is protected by %s!"), name);
362                 }
363         }
364         else
365         {
366                 /* Normal monsters */
367 #ifndef JP
368                 plural_aux(name);
369 #endif
370                 msg_format(_("注意しろ!この階は%d体の%sによって守られている!", "Be warned, this level is guarded by %d %s!"), q_num, name);
371
372         }
373 }
374
375
376 /*!
377  * @brief 新しく入ったダンジョンの階層に固定されている一般のクエストを探し出しIDを返す。
378  * / Hack -- Check if a level is a "quest" level
379  * @param level 検索対象になる階
380  * @return クエストIDを返す。該当がない場合0を返す。
381  */
382 QUEST_IDX quest_number(DEPTH level)
383 {
384         QUEST_IDX i;
385
386         /* Check quests */
387         if (p_ptr->inside_quest)
388                 return (p_ptr->inside_quest);
389
390         for (i = 0; i < max_q_idx; i++)
391         {
392                 if (quest[i].status != QUEST_STATUS_TAKEN) continue;
393
394                 if ((quest[i].type == QUEST_TYPE_KILL_LEVEL) &&
395                         !(quest[i].flags & QUEST_FLAG_PRESET) &&
396                         (quest[i].level == level) &&
397                         (quest[i].dungeon == dungeon_idx))
398                         return (i);
399         }
400
401         /* Check for random quest */
402         return (random_quest_number(level));
403 }
404
405 /*!
406  * @brief 新しく入ったダンジョンの階層に固定されているランダムクエストを探し出しIDを返す。
407  * @param level 検索対象になる階
408  * @return クエストIDを返す。該当がない場合0を返す。
409  */
410 QUEST_IDX random_quest_number(DEPTH level)
411 {
412         QUEST_IDX i;
413
414         if (dungeon_idx != DUNGEON_ANGBAND) return 0;
415
416         for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
417         {
418                 if ((quest[i].type == QUEST_TYPE_RANDOM) &&
419                         (quest[i].status == QUEST_STATUS_TAKEN) &&
420                         (quest[i].level == level) &&
421                         (quest[i].dungeon == DUNGEON_ANGBAND))
422                 {
423                         return i;
424                 }
425         }
426
427         return 0;
428 }