OSDN Git Service

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