OSDN Git Service

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