OSDN Git Service

[Refactor] #37287 #37353 型の置換。 / Type replacement.
[hengband/hengband.git] / src / cmd-zapwand.c
1 #include "angband.h"
2
3
4 /*!
5 * @brief \96\82\96@\96_\82Ì\8cø\89Ê\82ð\94­\93®\82·\82é
6 * @param sval \83I\83u\83W\83F\83N\83g\82Ìsval
7 * @param dir \94­\93®\82Ì\95û\8cüID
8 * @param powerful \8b­\97Í\94­\93®\8fã\82Ì\8f\88\97\9d\82È\82ç\82ÎTRUE
9 * @param magic \96\82\93¹\8bï\8fp\8fã\82Ì\8f\88\97\9d\82È\82ç\82ÎTRUE
10 * @return \94­\93®\82É\82æ\82è\8cø\89Ê\93à\97e\82ª\8am\92è\82µ\82½\82È\82ç\82ÎTRUE\82ð\95Ô\82·
11 */
12 int wand_effect(OBJECT_SUBTYPE_VALUE sval, int dir, bool powerful, bool magic)
13 {
14         int ident = FALSE;
15         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
16         int rad = powerful ? 3 : 2;
17
18         /* XXX Hack -- Wand of wonder can do anything before it */
19         if (sval == SV_WAND_WONDER)
20         {
21                 int vir = virtue_number(V_CHANCE);
22                 sval = (OBJECT_SUBTYPE_VALUE)randint0(SV_WAND_WONDER);
23
24                 if (vir)
25                 {
26                         if (p_ptr->virtues[vir - 1] > 0)
27                         {
28                                 while (randint1(300) < p_ptr->virtues[vir - 1]) sval++;
29                                 if (sval > SV_WAND_COLD_BALL) sval = randint0(4) + SV_WAND_ACID_BALL;
30                         }
31                         else
32                         {
33                                 while (randint1(300) < (0 - p_ptr->virtues[vir - 1])) sval--;
34                                 if (sval < SV_WAND_HEAL_MONSTER) sval = randint0(3) + SV_WAND_HEAL_MONSTER;
35                         }
36                 }
37                 if (sval < SV_WAND_TELEPORT_AWAY)
38                         chg_virtue(V_CHANCE, 1);
39         }
40
41         /* Analyze the wand */
42         switch (sval)
43         {
44         case SV_WAND_HEAL_MONSTER:
45         {
46                 HIT_POINT dam = damroll((powerful ? 20 : 10), 10);
47                 if (heal_monster(dir, dam)) ident = TRUE;
48                 break;
49         }
50
51         case SV_WAND_HASTE_MONSTER:
52         {
53                 if (speed_monster(dir, lev)) ident = TRUE;
54                 break;
55         }
56
57         case SV_WAND_CLONE_MONSTER:
58         {
59                 if (clone_monster(dir)) ident = TRUE;
60                 break;
61         }
62
63         case SV_WAND_TELEPORT_AWAY:
64         {
65                 int distance = MAX_SIGHT * (powerful ? 8 : 5);
66                 if (teleport_monster(dir, distance)) ident = TRUE;
67                 break;
68         }
69
70         case SV_WAND_DISARMING:
71         {
72                 if (disarm_trap(dir)) ident = TRUE;
73                 if (powerful && disarm_traps_touch()) ident = TRUE;
74                 break;
75         }
76
77         case SV_WAND_TRAP_DOOR_DEST:
78         {
79                 if (destroy_door(dir)) ident = TRUE;
80                 if (powerful && destroy_doors_touch()) ident = TRUE;
81                 break;
82         }
83
84         case SV_WAND_STONE_TO_MUD:
85         {
86                 HIT_POINT dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
87                 if (wall_to_mud(dir, dam)) ident = TRUE;
88                 break;
89         }
90
91         case SV_WAND_LITE:
92         {
93                 HIT_POINT dam = damroll((powerful ? 12 : 6), 8);
94                 msg_print(_("\90Â\82­\8bP\82­\8cõ\90ü\82ª\95ú\82½\82ê\82½\81B", "A line of blue shimmering light appears."));
95                 (void)lite_line(dir, dam);
96                 ident = TRUE;
97                 break;
98         }
99
100         case SV_WAND_SLEEP_MONSTER:
101         {
102                 if (sleep_monster(dir, lev)) ident = TRUE;
103                 break;
104         }
105
106         case SV_WAND_SLOW_MONSTER:
107         {
108                 if (slow_monster(dir, lev)) ident = TRUE;
109                 break;
110         }
111
112         case SV_WAND_CONFUSE_MONSTER:
113         {
114                 if (confuse_monster(dir, lev)) ident = TRUE;
115                 break;
116         }
117
118         case SV_WAND_FEAR_MONSTER:
119         {
120                 if (fear_monster(dir, lev)) ident = TRUE;
121                 break;
122         }
123
124         case SV_WAND_HYPODYNAMIA:
125         {
126                 if (hypodynamic_bolt(dir, 80 + lev)) ident = TRUE;
127                 break;
128         }
129
130         case SV_WAND_POLYMORPH:
131         {
132                 if (poly_monster(dir, lev)) ident = TRUE;
133                 break;
134         }
135
136         case SV_WAND_STINKING_CLOUD:
137         {
138                 fire_ball(GF_POIS, dir, 12 + lev / 4, rad);
139                 ident = TRUE;
140                 break;
141         }
142
143         case SV_WAND_MAGIC_MISSILE:
144         {
145                 fire_bolt_or_beam(20, GF_MISSILE, dir, damroll(2 + lev / 10, 6));
146                 ident = TRUE;
147                 break;
148         }
149
150         case SV_WAND_ACID_BOLT:
151         {
152                 fire_bolt_or_beam(20, GF_ACID, dir, damroll(6 + lev / 7, 8));
153                 ident = TRUE;
154                 break;
155         }
156
157         case SV_WAND_CHARM_MONSTER:
158         {
159                 if (charm_monster(dir, MAX(20, lev)))
160                         ident = TRUE;
161                 break;
162         }
163
164         case SV_WAND_FIRE_BOLT:
165         {
166                 fire_bolt_or_beam(20, GF_FIRE, dir, damroll(7 + lev / 6, 8));
167                 ident = TRUE;
168                 break;
169         }
170
171         case SV_WAND_COLD_BOLT:
172         {
173                 fire_bolt_or_beam(20, GF_COLD, dir, damroll(5 + lev / 8, 8));
174                 ident = TRUE;
175                 break;
176         }
177
178         case SV_WAND_ACID_BALL:
179         {
180                 fire_ball(GF_ACID, dir, 60 + 3 * lev / 4, rad);
181                 ident = TRUE;
182                 break;
183         }
184
185         case SV_WAND_ELEC_BALL:
186         {
187                 fire_ball(GF_ELEC, dir, 40 + 3 * lev / 4, rad);
188                 ident = TRUE;
189                 break;
190         }
191
192         case SV_WAND_FIRE_BALL:
193         {
194                 fire_ball(GF_FIRE, dir, 70 + 3 * lev / 4, rad);
195                 ident = TRUE;
196                 break;
197         }
198
199         case SV_WAND_COLD_BALL:
200         {
201                 fire_ball(GF_COLD, dir, 50 + 3 * lev / 4, rad);
202                 ident = TRUE;
203                 break;
204         }
205
206         case SV_WAND_WONDER:
207         {
208                 msg_print(_("\82¨\82Á\82Æ\81A\93ä\82Ì\96\82\96@\96_\82ð\8en\93®\82³\82¹\82½\81B", "Oops.  Wand of wonder activated."));
209                 break;
210         }
211
212         case SV_WAND_DRAGON_FIRE:
213         {
214                 fire_breath(GF_FIRE, dir, (powerful ? 300 : 200), 3);
215                 ident = TRUE;
216                 break;
217         }
218
219         case SV_WAND_DRAGON_COLD:
220         {
221                 fire_breath(GF_COLD, dir, (powerful ? 270 : 180), 3);
222                 ident = TRUE;
223                 break;
224         }
225
226         case SV_WAND_DRAGON_BREATH:
227         {
228                 HIT_POINT dam;
229                 int typ;
230
231                 switch (randint1(5))
232                 {
233                 case 1:
234                         dam = 240;
235                         typ = GF_ACID;
236                         break;
237                 case 2:
238                         dam = 210;
239                         typ = GF_ELEC;
240                         break;
241                 case 3:
242                         dam = 240;
243                         typ = GF_FIRE;
244                         break;
245                 case 4:
246                         dam = 210;
247                         typ = GF_COLD;
248                         break;
249                 default:
250                         dam = 180;
251                         typ = GF_POIS;
252                         break;
253                 }
254
255                 if (powerful) dam = (dam * 3) / 2;
256
257                 fire_breath(typ, dir, dam, 3);
258
259                 ident = TRUE;
260                 break;
261         }
262
263         case SV_WAND_DISINTEGRATE:
264         {
265                 fire_ball(GF_DISINTEGRATE, dir, 200 + randint1(lev * 2), rad);
266                 ident = TRUE;
267                 break;
268         }
269
270         case SV_WAND_ROCKETS:
271         {
272                 msg_print(_("\83\8d\83P\83b\83g\82ð\94­\8eË\82µ\82½\81I", "You launch a rocket!"));
273                 fire_rocket(GF_ROCKET, dir, 250 + lev * 3, rad);
274                 ident = TRUE;
275                 break;
276         }
277
278         case SV_WAND_STRIKING:
279         {
280                 fire_bolt(GF_METEOR, dir, damroll(15 + lev / 3, 13));
281                 ident = TRUE;
282                 break;
283         }
284
285         case SV_WAND_GENOCIDE:
286         {
287                 fire_ball_hide(GF_GENOCIDE, dir, magic ? lev + 50 : 250, 0);
288                 ident = TRUE;
289                 break;
290         }
291         }
292         return ident;
293 }
294
295 /*!
296 * @brief \96\82\96@\96_\82ð\8eg\82¤\83R\83}\83\93\83h\82Ì\83T\83u\83\8b\81[\83`\83\93 /
297 * Aim a wand (from the pack or floor).
298 * @param item \8eg\82¤\83I\83u\83W\83F\83N\83g\82Ì\8f\8a\8e\9d\95iID
299 * @return \82È\82µ
300 * @details
301 * <pre>
302 * Use a single charge from a single item.
303 * Handle "unstacking" in a logical manner.
304 * For simplicity, you cannot use a stack of items from the
305 * ground.  This would require too much nasty code.
306 * There are no wands which can "destroy" themselves, in the inventory
307 * or on the ground, so we can ignore this possibility.  Note that this
308 * required giving "wand of wonder" the ability to ignore destruction
309 * by electric balls.
310 * All wands can be "cancelled" at the "Direction?" prompt for free.
311 * Note that the basic "bolt" wands do slightly less damage than the
312 * basic "bolt" rods, but the basic "ball" wands do the same damage
313 * as the basic "ball" rods.
314 * </pre>
315 */
316 void do_cmd_aim_wand_aux(int item)
317 {
318         int         lev, ident, chance, dir;
319         object_type *o_ptr;
320         bool old_target_pet = target_pet;
321
322         /* Get the item (in the pack) */
323         if (item >= 0)
324         {
325                 o_ptr = &inventory[item];
326         }
327
328         /* Get the item (on the floor) */
329         else
330         {
331                 o_ptr = &o_list[0 - item];
332         }
333
334         /* Mega-Hack -- refuse to aim a pile from the ground */
335         if ((item < 0) && (o_ptr->number > 1))
336         {
337                 msg_print(_("\82Ü\82¸\82Í\96\82\96@\96_\82ð\8fE\82í\82È\82¯\82ê\82Î\81B", "You must first pick up the wands."));
338                 return;
339         }
340
341
342         /* Allow direction to be cancelled for free */
343         if (object_is_aware(o_ptr) && (o_ptr->sval == SV_WAND_HEAL_MONSTER
344                 || o_ptr->sval == SV_WAND_HASTE_MONSTER))
345                 target_pet = TRUE;
346         if (!get_aim_dir(&dir))
347         {
348                 target_pet = old_target_pet;
349                 return;
350         }
351         target_pet = old_target_pet;
352
353         /* Take a turn */
354         p_ptr->energy_use = 100;
355
356         /* Get the level */
357         lev = k_info[o_ptr->k_idx].level;
358         if (lev > 50) lev = 50 + (lev - 50) / 2;
359
360         /* Base chance of success */
361         chance = p_ptr->skill_dev;
362
363         /* Confusion hurts skill */
364         if (p_ptr->confused) chance = chance / 2;
365
366         /* Hight level objects are harder */
367         chance = chance - lev;
368
369         /* Give everyone a (slight) chance */
370         if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
371         {
372                 chance = USE_DEVICE;
373         }
374
375         if (world_player)
376         {
377                 if (flush_failure) flush();
378                 msg_print(_("\8e~\82Ü\82Á\82½\8e\9e\82Ì\92\86\82Å\82Í\82¤\82Ü\82­\93­\82©\82È\82¢\82æ\82¤\82¾\81B", "Nothing happen. Maybe this wand is freezing too."));
379                 sound(SOUND_FAIL);
380                 return;
381         }
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(_("\96\82\96@\96_\82ð\82¤\82Ü\82­\8eg\82¦\82È\82©\82Á\82½\81B", "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(_("\82±\82Ì\96\82\96@\96_\82É\82Í\82à\82¤\96\82\97Í\82ª\8ec\82Á\82Ä\82¢\82È\82¢\81B", "The wand has no charges left."));
397                 o_ptr->ident |= (IDENT_EMPTY);
398
399                 /* Combine / Reorder the pack (later) */
400                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
401                 p_ptr->window |= (PW_INVEN);
402
403                 return;
404         }
405
406         /* Sound */
407         sound(SOUND_ZAP);
408
409         ident = wand_effect(o_ptr->sval, dir, FALSE, FALSE);
410
411         /* Combine / Reorder the pack (later) */
412         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
413
414         if (!(object_is_aware(o_ptr)))
415         {
416                 chg_virtue(V_PATIENCE, -1);
417                 chg_virtue(V_CHANCE, 1);
418                 chg_virtue(V_KNOWLEDGE, -1);
419         }
420
421         /* Mark it as tried */
422         object_tried(o_ptr);
423
424         /* Apply identification */
425         if (ident && !object_is_aware(o_ptr))
426         {
427                 object_aware(o_ptr);
428                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
429         }
430
431         /* Window stuff */
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 \96\82\96@\96_\82ð\8eg\82¤\83R\83}\83\93\83h\82Ì\83\81\83C\83\93\83\8b\81[\83`\83\93 /
453 * @return \82È\82µ
454 */
455 void do_cmd_aim_wand(void)
456 {
457         OBJECT_IDX item;
458         cptr    q, s;
459
460         /* Restrict choices to wands */
461         item_tester_tval = TV_WAND;
462
463         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
464         {
465                 set_action(ACTION_NONE);
466         }
467
468         /* Get an item */
469         q = _("\82Ç\82Ì\96\82\96@\96_\82Å\91_\82¢\82Ü\82·\82©? ", "Aim which wand? ");
470         s = _("\8eg\82¦\82é\96\82\96@\96_\82ª\82È\82¢\81B", "You have no wand to aim.");
471
472         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
473
474         /* Aim the wand */
475         do_cmd_aim_wand_aux(item);
476 }