OSDN Git Service

[Refactor] #37353 determine_random_questor() を quest.c へ移動。 / Move determine_random_q...
[hengbandforosx/hengbandosx.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 ランダムクエストの討伐ユニークを決める / Determine the random quest uniques
9  * @param q_ptr クエスト構造体の参照ポインタ
10  * @return なし
11  */
12 void determine_random_questor(quest_type *q_ptr)
13 {
14         MONRACE_IDX r_idx;
15         monster_race *r_ptr;
16
17         get_mon_num_prep(mon_hook_quest, NULL);
18
19         while (1)
20         {
21                 /*
22                  * Random monster 5 - 10 levels out of depth
23                  * (depending on level)
24                  */
25                 r_idx = get_mon_num(q_ptr->level + 5 + randint1(q_ptr->level / 10));
26                 r_ptr = &r_info[r_idx];
27
28                 if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
29                 if (r_ptr->flags1 & RF1_QUESTOR) continue;
30                 if (r_ptr->rarity > 100) continue;
31                 if (r_ptr->flags7 & RF7_FRIENDLY) continue;
32                 if (r_ptr->flags7 & RF7_AQUATIC) continue;
33                 if (r_ptr->flags8 & RF8_WILD_ONLY) continue;
34                 if (no_questor_or_bounty_uniques(r_idx)) continue;
35
36                 /*
37                  * Accept monsters that are 2 - 6 levels
38                  * out of depth depending on the quest level
39                  */
40                 if (r_ptr->level > (q_ptr->level + (q_ptr->level / 20))) break;
41         }
42
43         q_ptr->r_idx = r_idx;
44 }
45
46 /*!
47  * @brief クエストを達成状態にする /
48  * @param quest_num 達成状態にしたいクエストのID
49  * @return なし
50  */
51 void complete_quest(QUEST_IDX quest_num)
52 {
53         quest_type* const q_ptr = &quest[quest_num];
54
55         switch (q_ptr->type)
56         {
57         case QUEST_TYPE_RANDOM:
58                 if (record_rand_quest) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, quest_num, NULL);
59                 break;
60         default:
61                 if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, quest_num, NULL);
62                 break;
63         }
64
65         q_ptr->status = QUEST_STATUS_COMPLETED;
66         q_ptr->complev = p_ptr->lev;
67         update_playtime();
68         q_ptr->comptime = playtime;
69
70         if (!(q_ptr->flags & QUEST_FLAG_SILENT))
71         {
72                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
73                 msg_print(_("クエストを達成した!", "You just completed your quest!"));
74                 msg_print(NULL);
75         }
76 }
77
78
79
80 /*!
81  * @brief 特定の敵を倒した際にクエスト達成処理 /
82  * Check for "Quest" completion when a quest monster is killed or charmed.
83  * @param m_ptr 撃破したモンスターの構造体参照ポインタ
84  * @return なし
85  */
86 void check_quest_completion(monster_type *m_ptr)
87 {
88         POSITION y, x;
89         QUEST_IDX quest_num;
90
91         bool create_stairs = FALSE;
92         bool reward = FALSE;
93
94         object_type forge;
95         object_type *o_ptr;
96
97         y = m_ptr->fy;
98         x = m_ptr->fx;
99
100         /* Inside a quest */
101         quest_num = p_ptr->inside_quest;
102
103         /* Search for an active quest on this dungeon level */
104         if (!quest_num)
105         {
106                 QUEST_IDX i;
107
108                 for (i = max_q_idx - 1; i > 0; i--)
109                 {
110                         quest_type* const q_ptr = &quest[i];
111
112                         /* Quest is not active */
113                         if (q_ptr->status != QUEST_STATUS_TAKEN)
114                                 continue;
115
116                         /* Quest is not a dungeon quest */
117                         if (q_ptr->flags & QUEST_FLAG_PRESET)
118                                 continue;
119
120                         /* Quest is not on this level */
121                         if ((q_ptr->level != dun_level) &&
122                                 (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
123                                 continue;
124
125                         /* Not a "kill monster" quest */
126                         if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
127                                 (q_ptr->type == QUEST_TYPE_FIND_EXIT))
128                                 continue;
129
130                         /* Interesting quest */
131                         if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
132                                 (q_ptr->type == QUEST_TYPE_TOWER) ||
133                                 (q_ptr->type == QUEST_TYPE_KILL_ALL))
134                                 break;
135
136                         /* Interesting quest */
137                         if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
138                                 (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
139                                 (q_ptr->type == QUEST_TYPE_RANDOM)) &&
140                                 (q_ptr->r_idx == m_ptr->r_idx))
141                                 break;
142                 }
143
144                 quest_num = i;
145         }
146
147         /* Handle the current quest */
148         if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
149         {
150                 /* Current quest */
151                 quest_type* const q_ptr = &quest[quest_num];
152
153                 switch (q_ptr->type)
154                 {
155                 case QUEST_TYPE_KILL_NUMBER:
156                 {
157                         q_ptr->cur_num++;
158
159                         if (q_ptr->cur_num >= q_ptr->num_mon)
160                         {
161                                 complete_quest(quest_num);
162
163                                 q_ptr->cur_num = 0;
164                         }
165                         break;
166                 }
167                 case QUEST_TYPE_KILL_ALL:
168                 {
169                         if (!is_hostile(m_ptr)) break;
170
171                         if (count_all_hostile_monsters() == 1)
172                         {
173                                 if (q_ptr->flags & QUEST_FLAG_SILENT)
174                                 {
175                                         q_ptr->status = QUEST_STATUS_FINISHED;
176                                 }
177                                 else
178                                 {
179                                         complete_quest(quest_num);
180                                 }
181                         }
182                         break;
183                 }
184                 case QUEST_TYPE_KILL_LEVEL:
185                 case QUEST_TYPE_RANDOM:
186                 {
187                         /* Only count valid monsters */
188                         if (q_ptr->r_idx != m_ptr->r_idx)
189                                 break;
190
191                         q_ptr->cur_num++;
192
193                         if (q_ptr->cur_num >= q_ptr->max_num)
194                         {
195                                 complete_quest(quest_num);
196
197                                 if (!(q_ptr->flags & QUEST_FLAG_PRESET))
198                                 {
199                                         create_stairs = TRUE;
200                                         p_ptr->inside_quest = 0;
201                                 }
202
203                                 /* Finish the two main quests without rewarding */
204                                 if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
205                                 {
206                                         q_ptr->status = QUEST_STATUS_FINISHED;
207                                 }
208
209                                 if (q_ptr->type == QUEST_TYPE_RANDOM)
210                                 {
211                                         reward = TRUE;
212                                         q_ptr->status = QUEST_STATUS_FINISHED;
213                                 }
214                         }
215                         break;
216                 }
217                 case QUEST_TYPE_KILL_ANY_LEVEL:
218                 {
219                         q_ptr->cur_num++;
220                         if (q_ptr->cur_num >= q_ptr->max_num)
221                         {
222                                 complete_quest(quest_num);
223                                 q_ptr->cur_num = 0;
224                         }
225                         break;
226                 }
227                 case QUEST_TYPE_TOWER:
228                 {
229                         if (!is_hostile(m_ptr)) break;
230
231                         if (count_all_hostile_monsters() == 1)
232                         {
233                                 q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
234
235                                 if ((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
236                                         (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
237                                         (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
238                                 {
239
240                                         complete_quest(QUEST_TOWER1);
241                                 }
242                         }
243                         break;
244                 }
245                 }
246         }
247
248         /* Create a magical staircase */
249         if (create_stairs)
250         {
251                 POSITION ny, nx;
252
253                 /* Stagger around */
254                 while (cave_perma_bold(y, x) || cave[y][x].o_idx || (cave[y][x].info & CAVE_OBJECT))
255                 {
256                         /* Pick a location */
257                         scatter(&ny, &nx, y, x, 1, 0);
258
259                         /* Stagger */
260                         y = ny; x = nx;
261                 }
262
263                 /* Explain the staircase */
264                 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
265
266                 /* Create stairs down */
267                 cave_set_feat(y, x, feat_down_stair);
268
269                 /* Remember to update everything */
270                 p_ptr->update |= (PU_FLOW);
271         }
272
273         /*
274          * Drop quest reward
275          */
276         if (reward)
277         {
278                 int i;
279
280                 for (i = 0; i < (dun_level / 15) + 1; i++)
281                 {
282                         o_ptr = &forge;
283                         object_wipe(o_ptr);
284
285                         /* Make a great object */
286                         make_object(o_ptr, AM_GOOD | AM_GREAT);
287                         (void)drop_near(o_ptr, -1, y, x);
288                 }
289         }
290 }
291
292 /*!
293  * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
294  * Check for "Quest" completion when a quest monster is killed or charmed.
295  * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
296  * @return なし
297  */
298 void check_find_art_quest_completion(object_type *o_ptr)
299 {
300         QUEST_IDX i;
301         /* Check if completed a quest */
302         for (i = 0; i < max_q_idx; i++)
303         {
304                 if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
305                         (quest[i].status == QUEST_STATUS_TAKEN) &&
306                         (quest[i].k_idx == o_ptr->name1))
307                 {
308                         complete_quest(i);
309                 }
310         }
311 }
312