OSDN Git Service

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