OSDN Git Service

[Refactor] #37353 object-kind.c/h を作成して関連構造体と変数を移動.
[hengband/hengband.git] / src / cmd-zapwand.c
1 #include "angband.h"
2 #include "util.h"
3
4 #include "avatar.h"
5 #include "spells.h"
6 #include "spells-status.h"
7 #include "player-status.h"
8 #include "player-effects.h"
9 #include "objectkind.h"
10 #include "object-hook.h"
11 #include "cmd-basic.h"
12 #include "floor.h"
13
14
15 /*!
16 * @brief 魔法棒の効果を発動する
17 * @param sval オブジェクトのsval
18 * @param dir 発動の方向ID
19 * @param powerful 強力発動上の処理ならばTRUE
20 * @param magic 魔道具術上の処理ならばTRUE
21 * @return 発動により効果内容が確定したならばTRUEを返す
22 */
23 bool wand_effect(OBJECT_SUBTYPE_VALUE sval, DIRECTION dir, bool powerful, bool magic)
24 {
25         bool ident = FALSE;
26         PLAYER_LEVEL lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
27         POSITION rad = powerful ? 3 : 2;
28
29         /* XXX Hack -- Wand of wonder can do anything before it */
30         if (sval == SV_WAND_WONDER)
31         {
32                 int vir = virtue_number(V_CHANCE);
33                 sval = (OBJECT_SUBTYPE_VALUE)randint0(SV_WAND_WONDER);
34
35                 if (vir)
36                 {
37                         if (p_ptr->virtues[vir - 1] > 0)
38                         {
39                                 while (randint1(300) < p_ptr->virtues[vir - 1]) sval++;
40                                 if (sval > SV_WAND_COLD_BALL) sval = randint0(4) + SV_WAND_ACID_BALL;
41                         }
42                         else
43                         {
44                                 while (randint1(300) < (0 - p_ptr->virtues[vir - 1])) sval--;
45                                 if (sval < SV_WAND_HEAL_MONSTER) sval = randint0(3) + SV_WAND_HEAL_MONSTER;
46                         }
47                 }
48                 if (sval < SV_WAND_TELEPORT_AWAY)
49                         chg_virtue(V_CHANCE, 1);
50         }
51
52         /* Analyze the wand */
53         switch (sval)
54         {
55                 case SV_WAND_HEAL_MONSTER:
56                 {
57                         HIT_POINT dam = damroll((powerful ? 20 : 10), 10);
58                         if (heal_monster(dir, dam)) ident = TRUE;
59                         break;
60                 }
61
62                 case SV_WAND_HASTE_MONSTER:
63                 {
64                         if (speed_monster(dir, lev)) ident = TRUE;
65                         break;
66                 }
67
68                 case SV_WAND_CLONE_MONSTER:
69                 {
70                         if (clone_monster(dir)) ident = TRUE;
71                         break;
72                 }
73
74                 case SV_WAND_TELEPORT_AWAY:
75                 {
76                         int distance = MAX_SIGHT * (powerful ? 8 : 5);
77                         if (teleport_monster(dir, distance)) ident = TRUE;
78                         break;
79                 }
80
81                 case SV_WAND_DISARMING:
82                 {
83                         if (disarm_trap(dir)) ident = TRUE;
84                         if (powerful && disarm_traps_touch()) ident = TRUE;
85                         break;
86                 }
87
88                 case SV_WAND_TRAP_DOOR_DEST:
89                 {
90                         if (destroy_door(dir)) ident = TRUE;
91                         if (powerful && destroy_doors_touch()) ident = TRUE;
92                         break;
93                 }
94
95                 case SV_WAND_STONE_TO_MUD:
96                 {
97                         HIT_POINT dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
98                         if (wall_to_mud(dir, dam)) ident = TRUE;
99                         break;
100                 }
101
102                 case SV_WAND_LITE:
103                 {
104                         HIT_POINT dam = damroll((powerful ? 12 : 6), 8);
105                         msg_print(_("青く輝く光線が放たれた。", "A line of blue shimmering light appears."));
106                         (void)lite_line(dir, dam);
107                         ident = TRUE;
108                         break;
109                 }
110
111                 case SV_WAND_SLEEP_MONSTER:
112                 {
113                         if (sleep_monster(dir, lev)) ident = TRUE;
114                         break;
115                 }
116
117                 case SV_WAND_SLOW_MONSTER:
118                 {
119                         if (slow_monster(dir, lev)) ident = TRUE;
120                         break;
121                 }
122
123                 case SV_WAND_CONFUSE_MONSTER:
124                 {
125                         if (confuse_monster(dir, lev)) ident = TRUE;
126                         break;
127                 }
128
129                 case SV_WAND_FEAR_MONSTER:
130                 {
131                         if (fear_monster(dir, lev)) ident = TRUE;
132                         break;
133                 }
134
135                 case SV_WAND_HYPODYNAMIA:
136                 {
137                         if (hypodynamic_bolt(dir, 80 + lev)) ident = TRUE;
138                         break;
139                 }
140
141                 case SV_WAND_POLYMORPH:
142                 {
143                         if (poly_monster(dir, lev)) ident = TRUE;
144                         break;
145                 }
146
147                 case SV_WAND_STINKING_CLOUD:
148                 {
149                         fire_ball(GF_POIS, dir, 12 + lev / 4, rad);
150                         ident = TRUE;
151                         break;
152                 }
153
154                 case SV_WAND_MAGIC_MISSILE:
155                 {
156                         fire_bolt_or_beam(20, GF_MISSILE, dir, damroll(2 + lev / 10, 6));
157                         ident = TRUE;
158                         break;
159                 }
160
161                 case SV_WAND_ACID_BOLT:
162                 {
163                         fire_bolt_or_beam(20, GF_ACID, dir, damroll(6 + lev / 7, 8));
164                         ident = TRUE;
165                         break;
166                 }
167
168                 case SV_WAND_CHARM_MONSTER:
169                 {
170                         if (charm_monster(dir, MAX(20, lev)))
171                                 ident = TRUE;
172                         break;
173                 }
174
175                 case SV_WAND_FIRE_BOLT:
176                 {
177                         fire_bolt_or_beam(20, GF_FIRE, dir, damroll(7 + lev / 6, 8));
178                         ident = TRUE;
179                         break;
180                 }
181
182                 case SV_WAND_COLD_BOLT:
183                 {
184                         fire_bolt_or_beam(20, GF_COLD, dir, damroll(5 + lev / 8, 8));
185                         ident = TRUE;
186                         break;
187                 }
188
189                 case SV_WAND_ACID_BALL:
190                 {
191                         fire_ball(GF_ACID, dir, 60 + 3 * lev / 4, rad);
192                         ident = TRUE;
193                         break;
194                 }
195
196                 case SV_WAND_ELEC_BALL:
197                 {
198                         fire_ball(GF_ELEC, dir, 40 + 3 * lev / 4, rad);
199                         ident = TRUE;
200                         break;
201                 }
202
203                 case SV_WAND_FIRE_BALL:
204                 {
205                         fire_ball(GF_FIRE, dir, 70 + 3 * lev / 4, rad);
206                         ident = TRUE;
207                         break;
208                 }
209
210                 case SV_WAND_COLD_BALL:
211                 {
212                         fire_ball(GF_COLD, dir, 50 + 3 * lev / 4, rad);
213                         ident = TRUE;
214                         break;
215                 }
216
217                 case SV_WAND_WONDER:
218                 {
219                         msg_print(_("おっと、謎の魔法棒を始動させた。", "Oops.  Wand of wonder activated."));
220                         break;
221                 }
222
223                 case SV_WAND_DRAGON_FIRE:
224                 {
225                         fire_breath(GF_FIRE, dir, (powerful ? 300 : 200), 3);
226                         ident = TRUE;
227                         break;
228                 }
229
230                 case SV_WAND_DRAGON_COLD:
231                 {
232                         fire_breath(GF_COLD, dir, (powerful ? 270 : 180), 3);
233                         ident = TRUE;
234                         break;
235                 }
236
237                 case SV_WAND_DRAGON_BREATH:
238                 {
239                         HIT_POINT dam;
240                         EFFECT_ID typ;
241
242                         switch (randint1(5))
243                         {
244                         case 1:
245                                 dam = 240;
246                                 typ = GF_ACID;
247                                 break;
248                         case 2:
249                                 dam = 210;
250                                 typ = GF_ELEC;
251                                 break;
252                         case 3:
253                                 dam = 240;
254                                 typ = GF_FIRE;
255                                 break;
256                         case 4:
257                                 dam = 210;
258                                 typ = GF_COLD;
259                                 break;
260                         default:
261                                 dam = 180;
262                                 typ = GF_POIS;
263                                 break;
264                         }
265
266                         if (powerful) dam = (dam * 3) / 2;
267
268                         fire_breath(typ, dir, dam, 3);
269
270                         ident = TRUE;
271                         break;
272                 }
273
274                 case SV_WAND_DISINTEGRATE:
275                 {
276                         fire_ball(GF_DISINTEGRATE, dir, 200 + randint1(lev * 2), rad);
277                         ident = TRUE;
278                         break;
279                 }
280
281                 case SV_WAND_ROCKETS:
282                 {
283                         msg_print(_("ロケットを発射した!", "You launch a rocket!"));
284                         fire_rocket(GF_ROCKET, dir, 250 + lev * 3, rad);
285                         ident = TRUE;
286                         break;
287                 }
288
289                 case SV_WAND_STRIKING:
290                 {
291                         fire_bolt(GF_METEOR, dir, damroll(15 + lev / 3, 13));
292                         ident = TRUE;
293                         break;
294                 }
295
296                 case SV_WAND_GENOCIDE:
297                 {
298                         fire_ball_hide(GF_GENOCIDE, dir, magic ? lev + 50 : 250, 0);
299                         ident = TRUE;
300                         break;
301                 }
302         }
303         return ident;
304 }
305
306 /*!
307 * @brief 魔法棒を使うコマンドのサブルーチン /
308 * Aim a wand (from the pack or floor).
309 * @param item 使うオブジェクトの所持品ID
310 * @return なし
311 * @details
312 * <pre>
313 * Use a single charge from a single item.
314 * Handle "unstacking" in a logical manner.
315 * For simplicity, you cannot use a stack of items from the
316 * ground.  This would require too much nasty code.
317 * There are no wands which can "destroy" themselves, in the p_ptr->inventory_list
318 * or on the ground, so we can ignore this possibility.  Note that this
319 * required giving "wand of wonder" the ability to ignore destruction
320 * by electric balls.
321 * All wands can be "cancelled" at the "Direction?" prompt for free.
322 * Note that the basic "bolt" wands do slightly less damage than the
323 * basic "bolt" rods, but the basic "ball" wands do the same damage
324 * as the basic "ball" rods.
325 * </pre>
326 */
327 void do_cmd_aim_wand_aux(INVENTORY_IDX item)
328 {
329         DEPTH lev;
330         int ident, chance;
331         DIRECTION dir;
332         object_type *o_ptr;
333         bool old_target_pet = target_pet;
334
335         /* Get the item (in the pack) */
336         if (item >= 0)
337         {
338                 o_ptr = &p_ptr->inventory_list[item];
339         }
340
341         /* Get the item (on the floor) */
342         else
343         {
344                 o_ptr = &current_floor_ptr->o_list[0 - item];
345         }
346
347         /* Mega-Hack -- refuse to aim a pile from the ground */
348         if ((item < 0) && (o_ptr->number > 1))
349         {
350                 msg_print(_("まずは魔法棒を拾わなければ。", "You must first pick up the wands."));
351                 return;
352         }
353
354
355         /* Allow direction to be cancelled for free */
356         if (object_is_aware(o_ptr) && (o_ptr->sval == SV_WAND_HEAL_MONSTER
357                 || o_ptr->sval == SV_WAND_HASTE_MONSTER))
358                 target_pet = TRUE;
359         if (!get_aim_dir(&dir))
360         {
361                 target_pet = old_target_pet;
362                 return;
363         }
364         target_pet = old_target_pet;
365
366         take_turn(p_ptr, 100);
367
368         /* Get the level */
369         lev = k_info[o_ptr->k_idx].level;
370         if (lev > 50) lev = 50 + (lev - 50) / 2;
371
372         /* Base chance of success */
373         chance = p_ptr->skill_dev;
374
375         /* Confusion hurts skill */
376         if (p_ptr->confused) chance = chance / 2;
377
378         /* Hight level objects are harder */
379         chance = chance - lev;
380
381         /* Give everyone a (slight) chance */
382         if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
383         {
384                 chance = USE_DEVICE;
385         }
386
387         if (cmd_limit_time_walk(p_ptr)) return;
388
389         /* Roll for usage */
390         if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (p_ptr->pclass == CLASS_BERSERKER))
391         {
392                 if (flush_failure) flush();
393                 msg_print(_("魔法棒をうまく使えなかった。", "You failed to use the wand properly."));
394                 sound(SOUND_FAIL);
395                 return;
396         }
397
398         /* The wand is already empty! */
399         if (o_ptr->pval <= 0)
400         {
401                 if (flush_failure) flush();
402                 msg_print(_("この魔法棒にはもう魔力が残っていない。", "The wand has no charges left."));
403                 o_ptr->ident |= (IDENT_EMPTY);
404                 p_ptr->update |= (PU_COMBINE | PU_REORDER);
405                 p_ptr->window |= (PW_INVEN);
406
407                 return;
408         }
409
410         sound(SOUND_ZAP);
411
412         ident = wand_effect(o_ptr->sval, dir, FALSE, FALSE);
413         p_ptr->update |= (PU_COMBINE | PU_REORDER);
414
415         if (!(object_is_aware(o_ptr)))
416         {
417                 chg_virtue(V_PATIENCE, -1);
418                 chg_virtue(V_CHANCE, 1);
419                 chg_virtue(V_KNOWLEDGE, -1);
420         }
421
422         /* Mark it as tried */
423         object_tried(o_ptr);
424
425         /* Apply identification */
426         if (ident && !object_is_aware(o_ptr))
427         {
428                 object_aware(o_ptr);
429                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
430         }
431
432         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
433
434
435         /* Use a single charge */
436         o_ptr->pval--;
437
438         /* Describe the charges in the pack */
439         if (item >= 0)
440         {
441                 inven_item_charges(item);
442         }
443
444         /* Describe the charges on the floor */
445         else
446         {
447                 floor_item_charges(0 - item);
448         }
449 }
450
451 /*!
452 * @brief 魔法棒を使うコマンドのメインルーチン /
453 * @return なし
454 */
455 void do_cmd_aim_wand(void)
456 {
457         OBJECT_IDX item;
458         concptr q, s;
459
460         if (p_ptr->wild_mode) return;
461         if (cmd_limit_arena(p_ptr)) return;
462
463         /* Restrict choices to wands */
464         item_tester_tval = TV_WAND;
465
466         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
467         {
468                 set_action(ACTION_NONE);
469         }
470
471         q = _("どの魔法棒で狙いますか? ", "Aim which wand? ");
472         s = _("使える魔法棒がない。", "You have no wand to aim.");
473         if (!choose_object(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
474
475         do_cmd_aim_wand_aux(item);
476 }