OSDN Git Service

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