OSDN Git Service

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