OSDN Git Service

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