OSDN Git Service

7704764b204cca8ac330a7793d97f7a5b588aaaf
[hengband/hengband.git] / src / quest.c
1 #include "angband.h"
2 #include "util.h"
3
4 #include "core.h"
5 #include "dungeon.h"
6 #include "floor.h"
7 #include "floor-save.h"
8 #include "floor-events.h"
9 #include "grid.h"
10 #include "quest.h"
11 #include "monsterrace-hook.h"
12 #include "monster.h"
13 #include "player-status.h"
14 #include "player-personality.h"
15 #include "artifact.h"
16 #include "feature.h"
17 #include "world.h"
18 #include "cmd-dump.h"
19 #include "english.h"
20
21 quest_type *quest; /*!< Quest info */
22 QUEST_IDX max_q_idx; /*!< Maximum number of quests */
23 char quest_text[10][80]; /*!< Quest text */
24 int quest_text_line; /*!< Current line of the quest text */
25 int leaving_quest = 0;
26
27 /*!
28  * @brief クエスト突入時のメッセージテーブル / Array of places to find an inscription
29  */
30 static concptr find_quest[] =
31 {
32         _("床にメッセージが刻まれている:", "You find the following inscription in the floor"),
33         _("壁にメッセージが刻まれている:", "You see a message inscribed in the wall"),
34         _("メッセージを見つけた:", "There is a sign saying"),
35         _("何かが階段の上に書いてある:", "Something is written on the staircase"),
36         _("巻物を見つけた。メッセージが書いてある:", "You find a scroll with the following message"),
37 };
38
39 /*!
40  * @brief ランダムクエストの討伐ユニークを決める / Determine the random quest uniques
41  * @param q_ptr クエスト構造体の参照ポインタ
42  * @return なし
43  */
44 void determine_random_questor(quest_type *q_ptr)
45 {
46         MONRACE_IDX r_idx;
47         monster_race *r_ptr;
48
49         get_mon_num_prep(mon_hook_quest, NULL);
50
51         while (1)
52         {
53                 /*
54                  * Random monster 5 - 10 levels out of depth
55                  * (depending on level)
56                  */
57                 r_idx = get_mon_num(q_ptr->level + 5 + randint1(q_ptr->level / 10));
58                 r_ptr = &r_info[r_idx];
59
60                 if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
61                 if (r_ptr->flags1 & RF1_QUESTOR) continue;
62                 if (r_ptr->rarity > 100) continue;
63                 if (r_ptr->flags7 & RF7_FRIENDLY) continue;
64                 if (r_ptr->flags7 & RF7_AQUATIC) continue;
65                 if (r_ptr->flags8 & RF8_WILD_ONLY) continue;
66                 if (no_questor_or_bounty_uniques(r_idx)) continue;
67
68                 /*
69                  * Accept monsters that are 2 - 6 levels
70                  * out of depth depending on the quest level
71                  */
72                 if (r_ptr->level > (q_ptr->level + (q_ptr->level / 20))) break;
73         }
74
75         q_ptr->r_idx = r_idx;
76 }
77
78 /*!
79  * @brief クエストを達成状態にする /
80  * @param quest_num 達成状態にしたいクエストのID
81  * @return なし
82  */
83 void complete_quest(QUEST_IDX quest_num)
84 {
85         quest_type* const q_ptr = &quest[quest_num];
86
87         switch (q_ptr->type)
88         {
89         case QUEST_TYPE_RANDOM:
90                 if (record_rand_quest) exe_write_diary(p_ptr, NIKKI_RAND_QUEST_C, quest_num, NULL);
91                 break;
92         default:
93                 if (record_fix_quest) exe_write_diary(p_ptr, NIKKI_FIX_QUEST_C, quest_num, NULL);
94                 break;
95         }
96
97         q_ptr->status = QUEST_STATUS_COMPLETED;
98         q_ptr->complev = p_ptr->lev;
99         update_playtime();
100         q_ptr->comptime = current_world_ptr->play_time;
101
102         if (!(q_ptr->flags & QUEST_FLAG_SILENT))
103         {
104                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
105                 msg_print(_("クエストを達成した!", "You just completed your quest!"));
106                 msg_print(NULL);
107         }
108 }
109
110
111
112 /*!
113  * @brief 特定の敵を倒した際にクエスト達成処理 /
114  * Check for "Quest" completion when a quest monster is killed or charmed.
115  * @param m_ptr 撃破したモンスターの構造体参照ポインタ
116  * @return なし
117  */
118 void check_quest_completion(monster_type *m_ptr)
119 {
120         POSITION y, x;
121         QUEST_IDX quest_num;
122
123         bool create_stairs = FALSE;
124         bool reward = FALSE;
125
126         object_type forge;
127         object_type *o_ptr;
128
129         y = m_ptr->fy;
130         x = m_ptr->fx;
131
132         /* Inside a quest */
133         quest_num = p_ptr->inside_quest;
134
135         /* Search for an active quest on this dungeon level */
136         if (!quest_num)
137         {
138                 QUEST_IDX i;
139
140                 for (i = max_q_idx - 1; i > 0; i--)
141                 {
142                         quest_type* const q_ptr = &quest[i];
143
144                         /* Quest is not active */
145                         if (q_ptr->status != QUEST_STATUS_TAKEN)
146                                 continue;
147
148                         /* Quest is not a dungeon quest */
149                         if (q_ptr->flags & QUEST_FLAG_PRESET)
150                                 continue;
151
152                         /* Quest is not on this level */
153                         if ((q_ptr->level != current_floor_ptr->dun_level) &&
154                                 (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
155                                 continue;
156
157                         /* Not a "kill monster" quest */
158                         if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
159                                 (q_ptr->type == QUEST_TYPE_FIND_EXIT))
160                                 continue;
161
162                         /* Interesting quest */
163                         if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
164                                 (q_ptr->type == QUEST_TYPE_TOWER) ||
165                                 (q_ptr->type == QUEST_TYPE_KILL_ALL))
166                                 break;
167
168                         /* Interesting quest */
169                         if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
170                                 (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
171                                 (q_ptr->type == QUEST_TYPE_RANDOM)) &&
172                                 (q_ptr->r_idx == m_ptr->r_idx))
173                                 break;
174                 }
175
176                 quest_num = i;
177         }
178
179         /* Handle the current quest */
180         if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
181         {
182                 /* Current quest */
183                 quest_type* const q_ptr = &quest[quest_num];
184
185                 switch (q_ptr->type)
186                 {
187                 case QUEST_TYPE_KILL_NUMBER:
188                 {
189                         q_ptr->cur_num++;
190
191                         if (q_ptr->cur_num >= q_ptr->num_mon)
192                         {
193                                 complete_quest(quest_num);
194
195                                 q_ptr->cur_num = 0;
196                         }
197                         break;
198                 }
199                 case QUEST_TYPE_KILL_ALL:
200                 {
201                         if (!is_hostile(m_ptr)) break;
202
203                         if (count_all_hostile_monsters(current_floor_ptr) == 1)
204                         {
205                                 if (q_ptr->flags & QUEST_FLAG_SILENT)
206                                 {
207                                         q_ptr->status = QUEST_STATUS_FINISHED;
208                                 }
209                                 else
210                                 {
211                                         complete_quest(quest_num);
212                                 }
213                         }
214                         break;
215                 }
216                 case QUEST_TYPE_KILL_LEVEL:
217                 case QUEST_TYPE_RANDOM:
218                 {
219                         /* Only count valid monsters */
220                         if (q_ptr->r_idx != m_ptr->r_idx)
221                                 break;
222
223                         q_ptr->cur_num++;
224
225                         if (q_ptr->cur_num >= q_ptr->max_num)
226                         {
227                                 complete_quest(quest_num);
228
229                                 if (!(q_ptr->flags & QUEST_FLAG_PRESET))
230                                 {
231                                         create_stairs = TRUE;
232                                         p_ptr->inside_quest = 0;
233                                 }
234
235                                 /* Finish the two main quests without rewarding */
236                                 if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
237                                 {
238                                         q_ptr->status = QUEST_STATUS_FINISHED;
239                                 }
240
241                                 if (q_ptr->type == QUEST_TYPE_RANDOM)
242                                 {
243                                         reward = TRUE;
244                                         q_ptr->status = QUEST_STATUS_FINISHED;
245                                 }
246                         }
247                         break;
248                 }
249                 case QUEST_TYPE_KILL_ANY_LEVEL:
250                 {
251                         q_ptr->cur_num++;
252                         if (q_ptr->cur_num >= q_ptr->max_num)
253                         {
254                                 complete_quest(quest_num);
255                                 q_ptr->cur_num = 0;
256                         }
257                         break;
258                 }
259                 case QUEST_TYPE_TOWER:
260                 {
261                         if (!is_hostile(m_ptr)) break;
262
263                         if (count_all_hostile_monsters(current_floor_ptr) == 1)
264                         {
265                                 q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
266
267                                 if ((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
268                                         (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
269                                         (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
270                                 {
271
272                                         complete_quest(QUEST_TOWER1);
273                                 }
274                         }
275                         break;
276                 }
277                 }
278         }
279
280         /* Create a magical staircase */
281         if (create_stairs)
282         {
283                 POSITION ny, nx;
284
285                 /* Stagger around */
286                 while (cave_perma_bold(y, x) || current_floor_ptr->grid_array[y][x].o_idx || (current_floor_ptr->grid_array[y][x].info & CAVE_OBJECT))
287                 {
288                         /* Pick a location */
289                         scatter(&ny, &nx, y, x, 1, 0);
290
291                         /* Stagger */
292                         y = ny; x = nx;
293                 }
294
295                 /* Explain the staircase */
296                 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
297
298                 /* Create stairs down */
299                 cave_set_feat(y, x, feat_down_stair);
300
301                 /* Remember to update everything */
302                 p_ptr->update |= (PU_FLOW);
303         }
304
305         /*
306          * Drop quest reward
307          */
308         if (reward)
309         {
310                 int i;
311
312                 for (i = 0; i < (current_floor_ptr->dun_level / 15) + 1; i++)
313                 {
314                         o_ptr = &forge;
315                         object_wipe(o_ptr);
316
317                         /* Make a great object */
318                         make_object(o_ptr, AM_GOOD | AM_GREAT);
319                         (void)drop_near(o_ptr, -1, y, x);
320                 }
321         }
322 }
323
324 /*!
325  * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
326  * Check for "Quest" completion when a quest monster is killed or charmed.
327  * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
328  * @return なし
329  */
330 void check_find_art_quest_completion(object_type *o_ptr)
331 {
332         QUEST_IDX i;
333         /* Check if completed a quest */
334         for (i = 0; i < max_q_idx; i++)
335         {
336                 if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
337                         (quest[i].status == QUEST_STATUS_TAKEN) &&
338                         (quest[i].k_idx == o_ptr->name1))
339                 {
340                         complete_quest(i);
341                 }
342         }
343 }
344
345
346 /*!
347  * @brief クエストの導入メッセージを表示する / Discover quest
348  * @param q_idx 開始されたクエストのID
349  */
350 void quest_discovery(QUEST_IDX q_idx)
351 {
352         quest_type *q_ptr = &quest[q_idx];
353         monster_race *r_ptr = &r_info[q_ptr->r_idx];
354         MONSTER_NUMBER q_num = q_ptr->max_num;
355         GAME_TEXT name[MAX_NLEN];
356
357         if (!q_idx) return;
358
359         strcpy(name, (r_name + r_ptr->name));
360
361         msg_print(find_quest[rand_range(0, 4)]);
362         msg_print(NULL);
363
364         if (q_num == 1)
365         {
366                 if ((r_ptr->flags1 & RF1_UNIQUE) && (0 == r_ptr->max_num))
367                 {
368                         msg_print(_("この階は以前は誰かによって守られていたようだ…。", "It seems that this level was protected by someone before..."));
369                         /* The unique is already dead */
370                         quest[q_idx].status = QUEST_STATUS_FINISHED;
371                         q_ptr->complev = 0;
372                         update_playtime();
373                         q_ptr->comptime = current_world_ptr->play_time;
374                 }
375                 else
376                 {
377                         msg_format(_("注意せよ!この階は%sによって守られている!", "Beware, this level is protected by %s!"), name);
378                 }
379         }
380         else
381         {
382 #ifndef JP
383                 plural_aux(name);
384 #endif
385                 msg_format(_("注意しろ!この階は%d体の%sによって守られている!", "Be warned, this level is guarded by %d %s!"), q_num, name);
386
387         }
388 }
389
390
391 /*!
392  * @brief 新しく入ったダンジョンの階層に固定されている一般のクエストを探し出しIDを返す。
393  * / Hack -- Check if a level is a "quest" level
394  * @param level 検索対象になる階
395  * @return クエストIDを返す。該当がない場合0を返す。
396  */
397 QUEST_IDX quest_number(DEPTH level)
398 {
399         QUEST_IDX i;
400
401         /* Check quests */
402         if (p_ptr->inside_quest)
403                 return (p_ptr->inside_quest);
404
405         for (i = 0; i < max_q_idx; i++)
406         {
407                 if (quest[i].status != QUEST_STATUS_TAKEN) continue;
408
409                 if ((quest[i].type == QUEST_TYPE_KILL_LEVEL) &&
410                         !(quest[i].flags & QUEST_FLAG_PRESET) &&
411                         (quest[i].level == level) &&
412                         (quest[i].dungeon == p_ptr->dungeon_idx))
413                         return (i);
414         }
415
416         /* Check for random quest */
417         return (random_quest_number(level));
418 }
419
420 /*!
421  * @brief 新しく入ったダンジョンの階層に固定されているランダムクエストを探し出しIDを返す。
422  * @param level 検索対象になる階
423  * @return クエストIDを返す。該当がない場合0を返す。
424  */
425 QUEST_IDX random_quest_number(DEPTH level)
426 {
427         QUEST_IDX i;
428
429         if (p_ptr->dungeon_idx != DUNGEON_ANGBAND) return 0;
430
431         for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
432         {
433                 if ((quest[i].type == QUEST_TYPE_RANDOM) &&
434                         (quest[i].status == QUEST_STATUS_TAKEN) &&
435                         (quest[i].level == level) &&
436                         (quest[i].dungeon == DUNGEON_ANGBAND))
437                 {
438                         return i;
439                 }
440         }
441
442         return 0;
443 }
444
445 /*!
446  * @brief クエスト階層から離脱する際の処理
447  * @return なし
448  */
449 void leave_quest_check(void)
450 {
451         /* Save quest number for dungeon pref file ($LEAVING_QUEST) */
452         leaving_quest = p_ptr->inside_quest;
453
454         /* Leaving an 'only once' quest marks it as failed */
455         if (leaving_quest)
456         {
457                 quest_type* const q_ptr = &quest[leaving_quest];
458
459                 if (((q_ptr->flags & QUEST_FLAG_ONCE) || (q_ptr->type == QUEST_TYPE_RANDOM)) &&
460                         (q_ptr->status == QUEST_STATUS_TAKEN))
461                 {
462                         q_ptr->status = QUEST_STATUS_FAILED;
463                         q_ptr->complev = p_ptr->lev;
464                         update_playtime();
465                         q_ptr->comptime = current_world_ptr->play_time;
466
467                         /* Additional settings */
468                         switch (q_ptr->type)
469                         {
470                         case QUEST_TYPE_TOWER:
471                                 quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
472                                 quest[QUEST_TOWER1].complev = p_ptr->lev;
473                                 break;
474                         case QUEST_TYPE_FIND_ARTIFACT:
475                                 a_info[q_ptr->k_idx].gen_flags &= ~(TRG_QUESTITEM);
476                                 break;
477                         case QUEST_TYPE_RANDOM:
478                                 r_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
479
480                                 /* Floor of random quest will be blocked */
481                                 prepare_change_floor_mode(CFM_NO_RETURN);
482                                 break;
483                         }
484
485                         /* Record finishing a quest */
486                         if (q_ptr->type == QUEST_TYPE_RANDOM)
487                         {
488                                 if (record_rand_quest) exe_write_diary(p_ptr, NIKKI_RAND_QUEST_F, leaving_quest, NULL);
489                         }
490                         else
491                         {
492                                 if (record_fix_quest) exe_write_diary(p_ptr, NIKKI_FIX_QUEST_F, leaving_quest, NULL);
493                         }
494                 }
495         }
496 }
497
498 /*!
499  * @brief 「塔」クエストの各階層から離脱する際の処理
500  * @return なし
501  */
502 void leave_tower_check(void)
503 {
504         leaving_quest = p_ptr->inside_quest;
505         /* Check for Tower Quest */
506         if (leaving_quest &&
507                 (quest[leaving_quest].type == QUEST_TYPE_TOWER) &&
508                 (quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED))
509         {
510                 if (quest[leaving_quest].type == QUEST_TYPE_TOWER)
511                 {
512                         quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
513                         quest[QUEST_TOWER1].complev = p_ptr->lev;
514                         update_playtime();
515                         quest[QUEST_TOWER1].comptime = current_world_ptr->play_time;
516                 }
517         }
518 }
519
520
521 /*!
522  * @brief クエスト入り口にプレイヤーが乗った際の処理 / Do building commands
523  * @return なし
524  */
525 void do_cmd_quest(void)
526 {
527         if (p_ptr->wild_mode) return;
528
529         take_turn(p_ptr, 100);
530
531         if (!cave_have_flag_bold(p_ptr->y, p_ptr->x, FF_QUEST_ENTER))
532         {
533                 msg_print(_("ここにはクエストの入口はない。", "You see no quest level here."));
534                 return;
535         }
536         else
537         {
538                 msg_print(_("ここにはクエストへの入口があります。", "There is an entry of a quest."));
539                 if (!get_check(_("クエストに入りますか?", "Do you enter? "))) return;
540                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
541                         msg_print(_("『とにかく入ってみようぜぇ。』", ""));
542                 else if (p_ptr->pseikaku == SEIKAKU_CHARGEMAN) msg_print("『全滅してやるぞ!』");
543
544                 /* Player enters a new quest */
545                 p_ptr->oldpy = 0;
546                 p_ptr->oldpx = 0;
547
548                 leave_quest_check();
549
550                 if (quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM) current_floor_ptr->dun_level = 1;
551                 p_ptr->inside_quest = current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].special;
552
553                 p_ptr->leaving = TRUE;
554         }
555 }
556