OSDN Git Service

[Refactor] #37353 型の置換。 / Type replacement.
[hengband/hengband.git] / src / chest.c
1 
2 #include "angband.h"
3
4 /*!
5 * @brief 箱からアイテムを引き出す /
6 * Allocates objects upon opening a chest    -BEN-
7 * @param scatter TRUEならばトラップによるアイテムの拡散処理
8 * @param y 箱の存在するマスのY座標
9 * @param x 箱の存在するマスのX座標
10 * @param o_idx 箱のオブジェクトID
11 * @return なし
12 * @details
13 * <pre>
14 * Disperse treasures from the given chest, centered at (x,y).
15 *
16 * Small chests often contain "gold", while Large chests always contain
17 * items.  Wooden chests contain 2 items, Iron chests contain 4 items,
18 * and Steel chests contain 6 items.  The "value" of the items in a
19 * chest is based on the "power" of the chest, which is in turn based
20 * on the level on which the chest is generated.
21 * </pre>
22 */
23 void chest_death(bool scatter, POSITION y, POSITION x, OBJECT_IDX o_idx)
24 {
25         int number;
26
27         bool small;
28         BIT_FLAGS mode = AM_GOOD;
29
30         object_type forge;
31         object_type *q_ptr;
32
33         object_type *o_ptr = &o_list[o_idx];
34
35
36         /* Small chests often hold "gold" */
37         small = (o_ptr->sval < SV_CHEST_MIN_LARGE);
38
39         /* Determine how much to drop (see above) */
40         number = (o_ptr->sval % SV_CHEST_MIN_LARGE) * 2;
41
42         if (o_ptr->sval == SV_CHEST_KANDUME)
43         {
44                 number = 5;
45                 small = FALSE;
46                 mode |= AM_GREAT;
47                 object_level = o_ptr->xtra3;
48         }
49         else
50         {
51                 /* Determine the "value" of the items */
52                 object_level = ABS(o_ptr->pval) + 10;
53         }
54
55         /* Zero pval means empty chest */
56         if (!o_ptr->pval) number = 0;
57
58         /* Opening a chest */
59         opening_chest = TRUE;
60
61         /* Drop some objects (non-chests) */
62         for (; number > 0; --number)
63         {
64                 q_ptr = &forge;
65                 object_wipe(q_ptr);
66
67                 /* Small chests often drop gold */
68                 if (small && (randint0(100) < 25))
69                 {
70                         /* Make some gold */
71                         if (!make_gold(q_ptr)) continue;
72                 }
73
74                 /* Otherwise drop an item */
75                 else
76                 {
77                         /* Make a good object */
78                         if (!make_object(q_ptr, mode)) continue;
79                 }
80
81                 /* If chest scatters its contents, pick any floor square. */
82                 if (scatter)
83                 {
84                         int i;
85                         for (i = 0; i < 200; i++)
86                         {
87                                 /* Pick a totally random spot. */
88                                 y = randint0(MAX_HGT);
89                                 x = randint0(MAX_WID);
90
91                                 /* Must be an empty floor. */
92                                 if (!cave_empty_bold(y, x)) continue;
93
94                                 /* Place the object there. */
95                                 (void)drop_near(q_ptr, -1, y, x);
96
97                                 /* Done. */
98                                 break;
99                         }
100                 }
101                 /* Normally, drop object near the chest. */
102                 else (void)drop_near(q_ptr, -1, y, x);
103         }
104
105         /* Reset the object level */
106         object_level = base_level;
107
108         /* No longer opening a chest */
109         opening_chest = FALSE;
110
111         /* Empty */
112         o_ptr->pval = 0;
113
114         /* Known */
115         object_known(o_ptr);
116 }
117
118
119 /*!
120 * @brief 箱のトラップ処理 /
121 * Chests have traps too.
122 * @param y 箱の存在するマスのY座標
123 * @param x 箱の存在するマスのX座標
124 * @param o_idx 箱のオブジェクトID
125 * @return なし
126 * @details
127 * <pre>
128 * Exploding chest destroys contents (and traps).
129 * Note that the chest itself is never destroyed.
130 * </pre>
131 */
132 void chest_trap(POSITION y, POSITION x, OBJECT_IDX o_idx)
133 {
134         int i, trap;
135
136         object_type *o_ptr = &o_list[o_idx];
137
138         int mon_level = o_ptr->xtra3;
139
140         /* Ignore disarmed chests */
141         if (o_ptr->pval <= 0) return;
142
143         /* Obtain the traps */
144         trap = chest_traps[o_ptr->pval];
145
146         /* Lose strength */
147         if (trap & (CHEST_LOSE_STR))
148         {
149                 msg_print(_("仕掛けられていた小さな針に刺されてしまった!", "A small needle has pricked you!"));
150                 take_hit(DAMAGE_NOESCAPE, damroll(1, 4), _("毒針", "a poison needle"), -1);
151                 (void)do_dec_stat(A_STR);
152         }
153
154         /* Lose constitution */
155         if (trap & (CHEST_LOSE_CON))
156         {
157                 msg_print(_("仕掛けられていた小さな針に刺されてしまった!", "A small needle has pricked you!"));
158                 take_hit(DAMAGE_NOESCAPE, damroll(1, 4), _("毒針", "a poison needle"), -1);
159                 (void)do_dec_stat(A_CON);
160         }
161
162         /* Poison */
163         if (trap & (CHEST_POISON))
164         {
165                 msg_print(_("突如吹き出した緑色のガスに包み込まれた!", "A puff of green gas surrounds you!"));
166                 if (!(p_ptr->resist_pois || IS_OPPOSE_POIS()))
167                 {
168                         (void)set_poisoned(p_ptr->poisoned + 10 + randint1(20));
169                 }
170         }
171
172         /* Paralyze */
173         if (trap & (CHEST_PARALYZE))
174         {
175                 msg_print(_("突如吹き出した黄色いガスに包み込まれた!", "A puff of yellow gas surrounds you!"));
176                 if (!p_ptr->free_act)
177                 {
178                         (void)set_paralyzed(p_ptr->paralyzed + 10 + randint1(20));
179                 }
180         }
181
182         /* Summon monsters */
183         if (trap & (CHEST_SUMMON))
184         {
185                 int num = 2 + randint1(3);
186                 msg_print(_("突如吹き出した煙に包み込まれた!", "You are enveloped in a cloud of smoke!"));
187                 for (i = 0; i < num; i++)
188                 {
189                         if (randint1(100)<dun_level)
190                                 activate_hi_summon(p_ptr->y, p_ptr->x, FALSE);
191                         else
192                                 (void)summon_specific(0, y, x, mon_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET), '\0');
193                 }
194         }
195
196         /* Elemental summon. */
197         if (trap & (CHEST_E_SUMMON))
198         {
199                 msg_print(_("宝を守るためにエレメンタルが現れた!", "Elemental beings appear to protect their treasures!"));
200                 for (i = 0; i < randint1(3) + 5; i++)
201                 {
202                         (void)summon_specific(0, y, x, mon_level, SUMMON_ELEMENTAL, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET), '\0');
203                 }
204         }
205
206         /* Force clouds, then summon birds. */
207         if (trap & (CHEST_BIRD_STORM))
208         {
209                 msg_print(_("鳥の群れがあなたを取り巻いた!", "A storm of birds swirls around you!"));
210
211                 for (i = 0; i < randint1(3) + 3; i++)
212                         (void)fire_meteor(-1, GF_FORCE, y, x, o_ptr->pval / 5, 7);
213
214                 for (i = 0; i < randint1(5) + o_ptr->pval / 5; i++)
215                 {
216                         (void)summon_specific(0, y, x, mon_level, SUMMON_BIRD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET), '\0');
217                 }
218         }
219
220         /* Various colorful summonings. */
221         if (trap & (CHEST_H_SUMMON))
222         {
223                 /* Summon demons. */
224                 if (one_in_(4))
225                 {
226                         msg_print(_("炎と硫黄の雲の中に悪魔が姿を現した!", "Demons materialize in clouds of fire and brimstone!"));
227                         for (i = 0; i < randint1(3) + 2; i++)
228                         {
229                                 (void)fire_meteor(-1, GF_FIRE, y, x, 10, 5);
230                                 (void)summon_specific(0, y, x, mon_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET), '\0');
231                         }
232                 }
233
234                 /* Summon dragons. */
235                 else if (one_in_(3))
236                 {
237                         msg_print(_("暗闇にドラゴンの影がぼんやりと現れた!", "Draconic forms loom out of the darkness!"));
238                         for (i = 0; i < randint1(3) + 2; i++)
239                         {
240                                 (void)summon_specific(0, y, x, mon_level, SUMMON_DRAGON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET), '\0');
241                         }
242                 }
243
244                 /* Summon hybrids. */
245                 else if (one_in_(2))
246                 {
247                         msg_print(_("奇妙な姿の怪物が襲って来た!", "Creatures strange and twisted assault you!"));
248                         for (i = 0; i < randint1(5) + 3; i++)
249                         {
250                                 (void)summon_specific(0, y, x, mon_level, SUMMON_HYBRID, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET), '\0');
251                         }
252                 }
253
254                 /* Summon vortices (scattered) */
255                 else
256                 {
257                         msg_print(_("渦巻が合体し、破裂した!", "Vortices coalesce and wreak destruction!"));
258                         for (i = 0; i < randint1(3) + 2; i++)
259                         {
260                                 (void)summon_specific(0, y, x, mon_level, SUMMON_VORTEX, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET), '\0');
261                         }
262                 }
263         }
264
265         /* Dispel player. */
266         if ((trap & (CHEST_RUNES_OF_EVIL)) && o_ptr->k_idx)
267         {
268                 /* Determine how many nasty tricks can be played. */
269                 int nasty_tricks_count = 4 + randint0(3);
270
271                 /* Message. */
272                 msg_print(_("恐ろしい声が響いた:  「暗闇が汝をつつまん!」", "Hideous voices bid:  'Let the darkness have thee!'"));
273                 /* This is gonna hurt... */
274                 for (; nasty_tricks_count > 0; nasty_tricks_count--)
275                 {
276                         /* ...but a high saving throw does help a little. */
277                         if (randint1(100 + o_ptr->pval * 2) > p_ptr->skill_sav)
278                         {
279                                 if (one_in_(6)) take_hit(DAMAGE_NOESCAPE, damroll(5, 20), _("破滅のトラップの宝箱", "a chest dispel-player trap"), -1);
280                                 else if (one_in_(5)) (void)set_cut(p_ptr->cut + 200);
281                                 else if (one_in_(4))
282                                 {
283                                         if (!p_ptr->free_act)
284                                                 (void)set_paralyzed(p_ptr->paralyzed + 2 +
285                                                         randint0(6));
286                                         else
287                                                 (void)set_stun(p_ptr->stun + 10 +
288                                                         randint0(100));
289                                 }
290                                 else if (one_in_(3)) apply_disenchant(0);
291                                 else if (one_in_(2))
292                                 {
293                                         (void)do_dec_stat(A_STR);
294                                         (void)do_dec_stat(A_DEX);
295                                         (void)do_dec_stat(A_CON);
296                                         (void)do_dec_stat(A_INT);
297                                         (void)do_dec_stat(A_WIS);
298                                         (void)do_dec_stat(A_CHR);
299                                 }
300                                 else (void)fire_meteor(-1, GF_NETHER, y, x, 150, 1);
301                         }
302                 }
303         }
304
305         /* Aggravate monsters. */
306         if (trap & (CHEST_ALARM))
307         {
308                 msg_print(_("けたたましい音が鳴り響いた!", "An alarm sounds!"));
309                 aggravate_monsters(0);
310         }
311
312         /* Explode */
313         if ((trap & (CHEST_EXPLODE)) && o_ptr->k_idx)
314         {
315                 msg_print(_("突然、箱が爆発した!", "There is a sudden explosion!"));
316                 msg_print(_("箱の中の物はすべて粉々に砕け散った!", "Everything inside the chest is destroyed!"));
317                 o_ptr->pval = 0;
318                 sound(SOUND_EXPLODE);
319                 take_hit(DAMAGE_ATTACK, damroll(5, 8), _("爆発する箱", "an exploding chest"), -1);
320         }
321         /* Scatter contents. */
322         if ((trap & (CHEST_SCATTER)) && o_ptr->k_idx)
323         {
324                 msg_print(_("宝箱の中身はダンジョンじゅうに散乱した!", "The contents of the chest scatter all over the dungeon!"));
325                 chest_death(TRUE, y, x, o_idx);
326                 o_ptr->pval = 0;
327         }
328 }
329