OSDN Git Service

da90f6826a6b227c377b31beebd5a4f10846910f
[hengband/hengband.git] / src / cmd2.c
1 /* File: cmd2.c */
2
3 /*
4  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
5  *
6  * This software may be copied and distributed for educational, research,
7  * and not for profit purposes provided that this copyright and statement
8  * are included in all such copies.  Other copyrights may also apply.
9  */
10
11 /* Purpose: Movement commands (part 2) */
12
13 #include "angband.h"
14
15
16 /*
17  * Go up one level
18  */
19 void do_cmd_go_up(void)
20 {
21         bool go_up = FALSE;
22
23         /* Player grid */
24         cave_type *c_ptr = &cave[py][px];
25         feature_type *f_ptr = &f_info[c_ptr->feat];
26
27         int up_num = 0;
28
29         if (p_ptr->special_defense & KATA_MUSOU)
30         {
31                 set_action(ACTION_NONE);
32         }
33
34         /* Verify stairs */
35         if (!have_flag(f_ptr->flags, FF_LESS))
36         {
37 #ifdef JP
38                 msg_print("¤³¤³¤Ë¤Ï¾å¤ê³¬Ãʤ¬¸«Åö¤¿¤é¤Ê¤¤¡£");
39 #else
40                 msg_print("I see no up staircase here.");
41 #endif
42
43                 return;
44         }
45
46         /* Quest up stairs */
47         if (have_flag(f_ptr->flags, FF_QUEST))
48         {
49                 /* Success */
50 #ifdef JP
51                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
52                         msg_print("¤Ê¤ó¤À¤³¤Î³¬Ãʤϡª");
53                 else
54                         msg_print("¾å¤Î³¬¤ËÅФä¿¡£");
55 #else
56                 msg_print("You enter the up staircase.");
57 #endif
58
59                 leave_quest_check();
60
61                 p_ptr->inside_quest = c_ptr->special;
62
63                 /* Activate the quest */
64                 if (!quest[p_ptr->inside_quest].status)
65                 {
66                         quest[p_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
67                 }
68
69                 /* Leaving a quest */
70                 if (!p_ptr->inside_quest)
71                 {
72                         dun_level = 0;
73                 }
74
75                 /* Leaving */
76                 p_ptr->leaving = TRUE;
77
78                 p_ptr->oldpx = 0;
79                 p_ptr->oldpy = 0;
80
81                 /* End the command */
82                 return;
83         }
84
85         if (!dun_level)
86         {
87                 go_up = TRUE;
88         }
89         else
90         {
91                 quest_type *q_ptr = &quest[p_ptr->inside_quest];
92
93                 /* Confirm leaving from once only quest */
94                 if (confirm_quest && p_ptr->inside_quest &&
95                     (q_ptr->type == QUEST_TYPE_RANDOM ||
96                      (q_ptr->flags & QUEST_FLAG_ONCE &&
97                       q_ptr->status != QUEST_STATUS_COMPLETED)))
98                 {
99 #ifdef JP
100                         msg_print("¤³¤Î³¬¤ò°ìÅÙµî¤ë¤ÈÆóÅÙ¤ÈÌá¤Ã¤ÆÍè¤é¤ì¤Þ¤»¤ó¡£");
101                         if (get_check("ËÜÅö¤Ë¤³¤Î³¬¤òµî¤ê¤Þ¤¹¤«¡©")) go_up = TRUE;
102 #else
103                         msg_print("You can't come back here once you leave this floor.");
104                         if (get_check("Really leave this floor? ")) go_up = TRUE;
105 #endif
106                 }
107                 else
108                 {
109                         go_up = TRUE;
110                 }
111         }
112
113         /* Cancel the command */
114         if (!go_up) return;
115
116         /* Hack -- take a turn */
117         energy_use = 100;
118
119         if (autosave_l) do_cmd_save_game(TRUE);
120
121         /* For a random quest */
122         if (p_ptr->inside_quest &&
123             quest[p_ptr->inside_quest].type == QUEST_TYPE_RANDOM)
124         {
125                 leave_quest_check();
126
127                 p_ptr->inside_quest = 0;
128         }
129
130         /* For a fixed quest */
131         if (p_ptr->inside_quest &&
132             quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
133         {
134                 leave_quest_check();
135
136                 p_ptr->inside_quest = c_ptr->special;
137                 dun_level = 0;
138                 up_num = 0;
139         }
140
141         /* For normal dungeon and random quest */
142         else
143         {
144                 /* New depth */
145                 if (have_flag(f_ptr->flags, FF_SHAFT))
146                 {
147                         /* Create a way back */
148                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP | CFM_SHAFT);
149
150                         up_num = 2;
151                 }
152                 else
153                 {
154                         /* Create a way back */
155                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP);
156
157                         up_num = 1;
158                 }
159
160                 /* Get out from current dungeon */
161                 if (dun_level - up_num < d_info[dungeon_type].mindepth)
162                         up_num = dun_level;
163         }
164
165 #ifdef JP
166         if (record_stair) do_cmd_write_nikki(NIKKI_STAIR, 0-up_num, "³¬Ãʤò¾å¤Ã¤¿");
167 #else
168         if (record_stair) do_cmd_write_nikki(NIKKI_STAIR, 0-up_num, "climbed up the stairs to");
169 #endif
170
171         /* Success */
172 #ifdef JP
173         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
174                 msg_print("¤Ê¤ó¤À¤³¤Î³¬Ãʤϡª");
175         else if (up_num == dun_level)
176                 msg_print("ÃϾå¤ËÌá¤Ã¤¿¡£");
177         else
178                 msg_print("³¬Ãʤò¾å¤Ã¤Æ¿·¤¿¤Ê¤ë̵ܤؤÈ­¤òƧ¤ßÆþ¤ì¤¿¡£");
179 #else
180         if (up_num == dun_level)
181                 msg_print("You go back to the surface.");
182         else
183                 msg_print("You enter a maze of up staircases.");
184 #endif
185
186         /* Leaving */
187         p_ptr->leaving = TRUE;
188 }
189
190
191 /*
192  * Go down one level
193  */
194 void do_cmd_go_down(void)
195 {
196         /* Player grid */
197         cave_type *c_ptr = &cave[py][px];
198         feature_type *f_ptr = &f_info[c_ptr->feat];
199
200         bool fall_trap = FALSE;
201         int down_num = 0;
202
203         if (p_ptr->special_defense & KATA_MUSOU)
204         {
205                 set_action(ACTION_NONE);
206         }
207
208         /* Verify stairs */
209         if (!have_flag(f_ptr->flags, FF_MORE))
210         {
211 #ifdef JP
212                 msg_print("¤³¤³¤Ë¤Ï²¼¤ê³¬Ãʤ¬¸«Åö¤¿¤é¤Ê¤¤¡£");
213 #else
214                 msg_print("I see no down staircase here.");
215 #endif
216
217                 return;
218         }
219
220         if (have_flag(f_ptr->flags, FF_TRAP)) fall_trap = TRUE;
221
222         /* Quest entrance */
223         if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
224         {
225                 do_cmd_quest();
226         }
227
228         /* Quest down stairs */
229         else if (have_flag(f_ptr->flags, FF_QUEST))
230         {
231 #ifdef JP
232                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
233                         msg_print("¤Ê¤ó¤À¤³¤Î³¬Ãʤϡª");
234                 else
235                         msg_print("²¼¤Î³¬¤Ë¹ß¤ê¤¿¡£");
236 #else
237                         msg_print("You enter the down staircase.");
238 #endif
239
240
241                 leave_quest_check();
242
243                 p_ptr->inside_quest = c_ptr->special;
244
245                 /* Activate the quest */
246                 if (!quest[p_ptr->inside_quest].status)
247                 {
248                         quest[p_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
249                 }
250
251                 /* Leaving a quest */
252                 if (!p_ptr->inside_quest)
253                 {
254                         dun_level = 0;
255                 }
256
257                 /* Leaving */
258                 p_ptr->leaving = TRUE;
259
260                 p_ptr->oldpx = 0;
261                 p_ptr->oldpy = 0;
262         }
263
264         else
265         {
266                 int target_dungeon = 0;
267
268                 if (!dun_level)
269                 {
270                         target_dungeon = have_flag(f_ptr->flags, FF_ENTRANCE) ? c_ptr->special : DUNGEON_ANGBAND;
271
272                         if (ironman_downward && (target_dungeon != DUNGEON_ANGBAND))
273                         {
274 #ifdef JP
275                                 msg_print("¥À¥ó¥¸¥ç¥ó¤ÎÆþ¸ý¤ÏºÉ¤¬¤ì¤Æ¤¤¤ë¡ª");
276 #else
277                                 msg_print("The entrance of this dungeon is closed!");
278 #endif
279                                 return;
280                         }
281                         if (!max_dlv[target_dungeon])
282                         {
283 #ifdef JP
284                                 msg_format("¤³¤³¤Ë¤Ï%s¤ÎÆþ¤ê¸ý(%d³¬ÁêÅö)¤¬¤¢¤ê¤Þ¤¹", d_name+d_info[target_dungeon].name, d_info[target_dungeon].mindepth);
285                                 if (!get_check("ËÜÅö¤Ë¤³¤Î¥À¥ó¥¸¥ç¥ó¤ËÆþ¤ê¤Þ¤¹¤«¡©")) return;
286 #else
287                                 msg_format("There is the entrance of %s (Danger level: %d)", d_name+d_info[target_dungeon].name, d_info[target_dungeon].mindepth);
288                                 if (!get_check("Do you really get in this dungeon? ")) return;
289 #endif
290                         }
291
292                         /* Save old player position */
293                         p_ptr->oldpx = px;
294                         p_ptr->oldpy = py;
295                         dungeon_type = (byte)target_dungeon;
296
297                         /*
298                          * Clear all saved floors
299                          * and create a first saved floor
300                          */
301                         prepare_change_floor_mode(CFM_FIRST_FLOOR);
302                 }
303
304                 /* Hack -- take a turn */
305                 energy_use = 100;
306
307                 if (autosave_l) do_cmd_save_game(TRUE);
308
309                 /* Go down */
310                 if (have_flag(f_ptr->flags, FF_SHAFT)) down_num += 2;
311                 else down_num += 1;
312
313                 if (!dun_level)
314                 {
315                         /* Enter the dungeon just now */
316                         p_ptr->enter_dungeon = TRUE;
317                         down_num = d_info[dungeon_type].mindepth;
318                 }
319
320                 if (record_stair)
321                 {
322 #ifdef JP
323                         if (fall_trap) do_cmd_write_nikki(NIKKI_STAIR, down_num, "Í¸Í¤ËÍî¤Á¤¿");
324                         else do_cmd_write_nikki(NIKKI_STAIR, down_num, "³¬Ãʤò²¼¤ê¤¿");
325 #else
326                         if (fall_trap) do_cmd_write_nikki(NIKKI_STAIR, down_num, "fell through a trap door");
327                         else do_cmd_write_nikki(NIKKI_STAIR, down_num, "climbed down the stairs to");
328 #endif
329                 }
330
331                 if (fall_trap)
332                 {
333 #ifdef JP
334                         msg_print("¤ï¤¶¤ÈÍ¸Í¤ËÍî¤Á¤¿¡£");
335 #else
336                         msg_print("You deliberately jump through the trap door.");
337 #endif
338                 }
339                 else
340                 {
341                         /* Success */
342                         if (target_dungeon)
343                         {
344 #ifdef JP
345                                 msg_format("%s¤ØÆþ¤Ã¤¿¡£", d_text + d_info[dungeon_type].text);
346 #else
347                                 msg_format("You entered %s.", d_text + d_info[dungeon_type].text);
348 #endif
349                         }
350                         else
351                         {
352 #ifdef JP
353                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
354                                         msg_print("¤Ê¤ó¤À¤³¤Î³¬Ãʤϡª");
355                                 else
356                                         msg_print("³¬Ãʤò²¼¤ê¤Æ¿·¤¿¤Ê¤ë̵ܤؤÈ­¤òƧ¤ßÆþ¤ì¤¿¡£");
357 #else
358                                 msg_print("You enter a maze of down staircases.");
359 #endif
360                         }
361                 }
362
363
364                 /* Leaving */
365                 p_ptr->leaving = TRUE;
366
367                 if (fall_trap)
368                 {
369                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
370                 }
371                 else
372                 {
373                         if (have_flag(f_ptr->flags, FF_SHAFT))
374                         {
375                                 /* Create a way back */
376                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_SHAFT);
377                         }
378                         else
379                         {
380                                 /* Create a way back */
381                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN);
382                         }
383                 }
384         }
385 }
386
387
388
389 /*
390  * Simple command to "search" for one turn
391  */
392 void do_cmd_search(void)
393 {
394         /* Allow repeated command */
395         if (command_arg)
396         {
397                 /* Set repeat count */
398                 command_rep = command_arg - 1;
399
400                 /* Redraw the state */
401                 p_ptr->redraw |= (PR_STATE);
402
403                 /* Cancel the arg */
404                 command_arg = 0;
405         }
406
407         /* Take a turn */
408         energy_use = 100;
409
410         /* Search */
411         search();
412 }
413
414
415 /*
416  * Determine if a grid contains a chest
417  */
418 static s16b chest_check(int y, int x)
419 {
420         cave_type *c_ptr = &cave[y][x];
421
422         s16b this_o_idx, next_o_idx = 0;
423
424
425         /* Scan all objects in the grid */
426         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
427         {
428                 object_type *o_ptr;
429
430                 /* Acquire object */
431                 o_ptr = &o_list[this_o_idx];
432
433                 /* Acquire next object */
434                 next_o_idx = o_ptr->next_o_idx;
435
436                 /* Skip unknown chests XXX XXX */
437                 /* if (!o_ptr->marked) continue; */
438
439                 /* Check for chest */
440                 if (o_ptr->tval == TV_CHEST) return (this_o_idx);
441         }
442
443         /* No chest */
444         return (0);
445 }
446
447
448 /*
449  * Allocates objects upon opening a chest    -BEN-
450  *
451  * Disperse treasures from the given chest, centered at (x,y).
452  *
453  * Small chests often contain "gold", while Large chests always contain
454  * items.  Wooden chests contain 2 items, Iron chests contain 4 items,
455  * and Steel chests contain 6 items.  The "value" of the items in a
456  * chest is based on the "power" of the chest, which is in turn based
457  * on the level on which the chest is generated.
458  */
459 static void chest_death(bool scatter, int y, int x, s16b o_idx)
460 {
461         int number;
462
463         bool small;
464         u32b mode = AM_GOOD;
465
466         object_type forge;
467         object_type *q_ptr;
468
469         object_type *o_ptr = &o_list[o_idx];
470
471
472         /* Small chests often hold "gold" */
473         small = (o_ptr->sval < SV_CHEST_MIN_LARGE);
474
475         /* Determine how much to drop (see above) */
476         number = (o_ptr->sval % SV_CHEST_MIN_LARGE) * 2;
477
478         if (o_ptr->sval == SV_CHEST_KANDUME)
479         {
480                 number = 5;
481                 small = FALSE;
482                 mode |= AM_GREAT;
483                 object_level = o_ptr->xtra3;
484         }
485         else
486         {
487                 /* Determine the "value" of the items */
488                 object_level = ABS(o_ptr->pval) + 10;
489         }
490
491         /* Zero pval means empty chest */
492         if (!o_ptr->pval) number = 0;
493
494         /* Opening a chest */
495         opening_chest = TRUE;
496
497         /* Drop some objects (non-chests) */
498         for (; number > 0; --number)
499         {
500                 /* Get local object */
501                 q_ptr = &forge;
502
503                 /* Wipe the object */
504                 object_wipe(q_ptr);
505
506                 /* Small chests often drop gold */
507                 if (small && (randint0(100) < 25))
508                 {
509                         /* Make some gold */
510                         if (!make_gold(q_ptr)) continue;
511                 }
512
513                 /* Otherwise drop an item */
514                 else
515                 {
516                         /* Make a good object */
517                         if (!make_object(q_ptr, mode)) continue;
518                 }
519
520                 /* If chest scatters its contents, pick any floor square. */
521                 if (scatter)
522                 {
523                         int i;
524                         for (i = 0; i < 200; i++)
525                         {
526                                 /* Pick a totally random spot. */
527                                 y = randint0(MAX_HGT);
528                                 x = randint0(MAX_WID);
529
530                                 /* Must be an empty floor. */
531                                 if (!cave_empty_bold(y, x)) continue;
532
533                                 /* Place the object there. */
534                                 drop_near(q_ptr, -1, y, x);
535
536                                 /* Done. */
537                                 break;
538                         }
539                 }
540                 /* Normally, drop object near the chest. */
541                 else drop_near(q_ptr, -1, y, x);
542         }
543
544         /* Reset the object level */
545         object_level = base_level;
546
547         /* No longer opening a chest */
548         opening_chest = FALSE;
549
550         /* Empty */
551         o_ptr->pval = 0;
552
553         /* Known */
554         object_known(o_ptr);
555 }
556
557
558 /*
559  * Chests have traps too.
560  *
561  * Exploding chest destroys contents (and traps).
562  * Note that the chest itself is never destroyed.
563  */
564 static void chest_trap(int y, int x, s16b o_idx)
565 {
566         int  i, trap;
567
568         object_type *o_ptr = &o_list[o_idx];
569
570         int mon_level = o_ptr->xtra3;
571
572         /* Ignore disarmed chests */
573         if (o_ptr->pval <= 0) return;
574
575         /* Obtain the traps */
576         trap = chest_traps[o_ptr->pval];
577
578         /* Lose strength */
579         if (trap & (CHEST_LOSE_STR))
580         {
581 #ifdef JP
582                 msg_print("»Å³Ý¤±¤é¤ì¤Æ¤¤¤¿¾®¤µ¤Ê¿Ë¤Ë»É¤µ¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª");
583                 take_hit(DAMAGE_NOESCAPE, damroll(1, 4), "ÆÇ¿Ë", -1);
584 #else
585                 msg_print("A small needle has pricked you!");
586                 take_hit(DAMAGE_NOESCAPE, damroll(1, 4), "a poison needle", -1);
587 #endif
588
589                 (void)do_dec_stat(A_STR);
590         }
591
592         /* Lose constitution */
593         if (trap & (CHEST_LOSE_CON))
594         {
595 #ifdef JP
596                 msg_print("»Å³Ý¤±¤é¤ì¤Æ¤¤¤¿¾®¤µ¤Ê¿Ë¤Ë»É¤µ¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª");
597                 take_hit(DAMAGE_NOESCAPE, damroll(1, 4), "ÆÇ¿Ë", -1);
598 #else
599                 msg_print("A small needle has pricked you!");
600                 take_hit(DAMAGE_NOESCAPE, damroll(1, 4), "a poison needle", -1);
601 #endif
602
603                 (void)do_dec_stat(A_CON);
604         }
605
606         /* Poison */
607         if (trap & (CHEST_POISON))
608         {
609 #ifdef JP
610                 msg_print("ÆÍÇ¡¿á¤­½Ð¤·¤¿Îп§¤Î¥¬¥¹¤ËÊñ¤ß¹þ¤Þ¤ì¤¿¡ª");
611 #else
612                 msg_print("A puff of green gas surrounds you!");
613 #endif
614
615                 if (!(p_ptr->resist_pois || IS_OPPOSE_POIS()))
616                 {
617                         (void)set_poisoned(p_ptr->poisoned + 10 + randint1(20));
618                 }
619         }
620
621         /* Paralyze */
622         if (trap & (CHEST_PARALYZE))
623         {
624 #ifdef JP
625                 msg_print("ÆÍÇ¡¿á¤­½Ð¤·¤¿²«¿§¤¤¥¬¥¹¤ËÊñ¤ß¹þ¤Þ¤ì¤¿¡ª");
626 #else
627                 msg_print("A puff of yellow gas surrounds you!");
628 #endif
629
630
631                 if (!p_ptr->free_act)
632                 {
633                         (void)set_paralyzed(p_ptr->paralyzed + 10 + randint1(20));
634                 }
635         }
636
637         /* Summon monsters */
638         if (trap & (CHEST_SUMMON))
639         {
640                 int num = 2 + randint1(3);
641 #ifdef JP
642                 msg_print("ÆÍÇ¡¿á¤­½Ð¤·¤¿±ì¤ËÊñ¤ß¹þ¤Þ¤ì¤¿¡ª");
643 #else
644                 msg_print("You are enveloped in a cloud of smoke!");
645 #endif
646
647
648                 for (i = 0; i < num; i++)
649                 {
650                         if (randint1(100)<dun_level)
651                                 activate_hi_summon(py, px, FALSE);
652                         else
653                                 (void)summon_specific(0, y, x, mon_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
654                 }
655         }
656
657         /* Elemental summon. */
658         if (trap & (CHEST_E_SUMMON))
659         {
660 #ifdef JP
661                 msg_print("Êõ¤ò¼é¤ë¤¿¤á¤Ë¥¨¥ì¥á¥ó¥¿¥ë¤¬¸½¤ì¤¿¡ª");
662 #else
663                 msg_print("Elemental beings appear to protect their treasures!");
664 #endif
665                 for (i = 0; i < randint1(3) + 5; i++)
666                 {
667                         (void)summon_specific(0, y, x, mon_level, SUMMON_ELEMENTAL, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
668                 }
669         }
670
671         /* Force clouds, then summon birds. */
672         if (trap & (CHEST_BIRD_STORM))
673         {
674 #ifdef JP
675                 msg_print("Ä»¤Î·²¤ì¤¬¤¢¤Ê¤¿¤ò¼è¤ê´¬¤¤¤¿¡ª");
676 #else
677                 msg_print("A storm of birds swirls around you!");
678 #endif
679
680                 for (i = 0; i < randint1(3) + 3; i++)
681                         (void)fire_meteor(-1, GF_FORCE, y, x, o_ptr->pval / 5, 7);
682
683                 for (i = 0; i < randint1(5) + o_ptr->pval / 5; i++)
684                 {
685                         (void)summon_specific(0, y, x, mon_level, SUMMON_BIRD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
686                 }
687         }
688
689         /* Various colorful summonings. */
690         if (trap & (CHEST_H_SUMMON))
691         {
692                 /* Summon demons. */
693                 if (one_in_(4))
694                 {
695 #ifdef JP
696                         msg_print("±ê¤Èⲫ¤Î±À¤ÎÃæ¤Ë°­Ë⤬»Ñ¤ò¸½¤·¤¿¡ª");
697 #else
698                         msg_print("Demons materialize in clouds of fire and brimstone!");
699 #endif
700
701                         for (i = 0; i < randint1(3) + 2; i++)
702                         {
703                                 (void)fire_meteor(-1, GF_FIRE, y, x, 10, 5);
704                                 (void)summon_specific(0, y, x, mon_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
705                         }
706                 }
707
708                 /* Summon dragons. */
709                 else if (one_in_(3))
710                 {
711 #ifdef JP
712                         msg_print("°Å°Ç¤Ë¥É¥é¥´¥ó¤Î±Æ¤¬¤Ü¤ó¤ä¤ê¤È¸½¤ì¤¿¡ª");
713 #else
714                         msg_print("Draconic forms loom out of the darkness!");
715 #endif
716
717                         for (i = 0; i < randint1(3) + 2; i++)
718                         {
719                                 (void)summon_specific(0, y, x, mon_level, SUMMON_DRAGON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
720                         }
721                 }
722
723                 /* Summon hybrids. */
724                 else if (one_in_(2))
725                 {
726 #ifdef JP
727                         msg_print("´ñ̯¤Ê»Ñ¤Î²øʪ¤¬½±¤Ã¤ÆÍ褿¡ª");
728 #else
729                         msg_print("Creatures strange and twisted assault you!");
730 #endif
731
732                         for (i = 0; i < randint1(5) + 3; i++)
733                         {
734                                 (void)summon_specific(0, y, x, mon_level, SUMMON_HYBRID, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
735                         }
736                 }
737
738                 /* Summon vortices (scattered) */
739                 else
740                 {
741 #ifdef JP
742                         msg_print("±²´¬¤«¹çÂΤ·¡¢ÇËÎö¤·¤¿¡ª");
743 #else
744                         msg_print("Vortices coalesce and wreak destruction!");
745 #endif
746
747                         for (i = 0; i < randint1(3) + 2; i++)
748                         {
749                                 (void)summon_specific(0, y, x, mon_level, SUMMON_VORTEX, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
750                         }
751                 }
752         }
753
754         /* Dispel player. */
755         if ((trap & (CHEST_RUNES_OF_EVIL)) && o_ptr->k_idx)
756         {
757                 /* Determine how many nasty tricks can be played. */
758                 int nasty_tricks_count = 4 + randint0(3);
759
760                 /* Message. */
761 #ifdef JP
762                 msg_print("¶²¤·¤¤À¼¤¬¶Á¤¤¤¿:  ¡Ö°Å°Ç¤¬Æò¤ò¤Ä¤Ä¤Þ¤ó¡ª¡×");
763 #else
764                 msg_print("Hideous voices bid:  'Let the darkness have thee!'");
765 #endif
766
767                 /* This is gonna hurt... */
768                 for (; nasty_tricks_count > 0; nasty_tricks_count--)
769                 {
770                         /* ...but a high saving throw does help a little. */
771                         if (randint1(100+o_ptr->pval*2) > p_ptr->skill_sav)
772                         {
773 #ifdef JP
774                                 if (one_in_(6)) take_hit(DAMAGE_NOESCAPE, damroll(5, 20), "ÇËÌǤΥȥé¥Ã¥×¤ÎÊõÈ¢", -1);
775 #else
776                                 if (one_in_(6)) take_hit(DAMAGE_NOESCAPE, damroll(5, 20), "a chest dispel-player trap", -1);
777 #endif
778                                 else if (one_in_(5)) (void)set_cut(p_ptr->cut + 200);
779                                 else if (one_in_(4))
780                                 {
781                                         if (!p_ptr->free_act) 
782                                                 (void)set_paralyzed(p_ptr->paralyzed + 2 + 
783                                                 randint0(6));
784                                         else 
785                                                 (void)set_stun(p_ptr->stun + 10 + 
786                                                 randint0(100));
787                                 }
788                                 else if (one_in_(3)) apply_disenchant(0);
789                                 else if (one_in_(2))
790                                 {
791                                         (void)do_dec_stat(A_STR);
792                                         (void)do_dec_stat(A_DEX);
793                                         (void)do_dec_stat(A_CON);
794                                         (void)do_dec_stat(A_INT);
795                                         (void)do_dec_stat(A_WIS);
796                                         (void)do_dec_stat(A_CHR);
797                                 }
798                                 else (void)fire_meteor(-1, GF_NETHER, y, x, 150, 1);
799                         }
800                 }
801         }
802
803         /* Aggravate monsters. */
804         if (trap & (CHEST_ALARM))
805         {
806 #ifdef JP
807                 msg_print("¤±¤¿¤¿¤Þ¤·¤¤²»¤¬ÌĤê¶Á¤¤¤¿¡ª");
808 #else
809                 msg_print("An alarm sounds!");
810 #endif
811                 aggravate_monsters(0);
812         }
813
814         /* Explode */
815         if ((trap & (CHEST_EXPLODE)) && o_ptr->k_idx)
816         {
817 #ifdef JP
818                 msg_print("ÆÍÁ³¡¢È¢¤¬Çúȯ¤·¤¿¡ª");
819                 msg_print("È¢¤ÎÃæ¤Îʪ¤Ï¤¹¤Ù¤ÆÊ´¡¹¤ËºÕ¤±»¶¤Ã¤¿¡ª");
820 #else
821                 msg_print("There is a sudden explosion!");
822                 msg_print("Everything inside the chest is destroyed!");
823 #endif
824
825                 o_ptr->pval = 0;
826                 sound(SOUND_EXPLODE);
827 #ifdef JP
828                 take_hit(DAMAGE_ATTACK, damroll(5, 8), "Çúȯ¤¹¤ëÈ¢", -1);
829 #else
830                 take_hit(DAMAGE_ATTACK, damroll(5, 8), "an exploding chest", -1);
831 #endif
832
833         }
834         /* Scatter contents. */
835         if ((trap & (CHEST_SCATTER)) && o_ptr->k_idx)
836         {
837 #ifdef JP
838                 msg_print("ÊõÈ¢¤ÎÃæ¿È¤Ï¥À¥ó¥¸¥ç¥ó¤¸¤å¤¦¤Ë»¶Í𤷤¿¡ª");
839 #else
840                 msg_print("The contents of the chest scatter all over the dungeon!");
841 #endif
842                 chest_death(TRUE, y, x, o_idx);
843                 o_ptr->pval = 0;
844         }
845 }
846
847
848 /*
849  * Attempt to open the given chest at the given location
850  *
851  * Assume there is no monster blocking the destination
852  *
853  * Returns TRUE if repeated commands may continue
854  */
855 static bool do_cmd_open_chest(int y, int x, s16b o_idx)
856 {
857         int i, j;
858
859         bool flag = TRUE;
860
861         bool more = FALSE;
862
863         object_type *o_ptr = &o_list[o_idx];
864
865
866         /* Take a turn */
867         energy_use = 100;
868
869         /* Attempt to unlock it */
870         if (o_ptr->pval > 0)
871         {
872                 /* Assume locked, and thus not open */
873                 flag = FALSE;
874
875                 /* Get the "disarm" factor */
876                 i = p_ptr->skill_dis;
877
878                 /* Penalize some conditions */
879                 if (p_ptr->blind || no_lite()) i = i / 10;
880                 if (p_ptr->confused || p_ptr->image) i = i / 10;
881
882                 /* Extract the difficulty */
883                 j = i - o_ptr->pval;
884
885                 /* Always have a small chance of success */
886                 if (j < 2) j = 2;
887
888                 /* Success -- May still have traps */
889                 if (randint0(100) < j)
890                 {
891 #ifdef JP
892                         msg_print("¸°¤ò¤Ï¤º¤·¤¿¡£");
893 #else
894                         msg_print("You have picked the lock.");
895 #endif
896
897                         gain_exp(1);
898                         flag = TRUE;
899                 }
900
901                 /* Failure -- Keep trying */
902                 else
903                 {
904                         /* We may continue repeating */
905                         more = TRUE;
906                         if (flush_failure) flush();
907 #ifdef JP
908                         msg_print("¸°¤ò¤Ï¤º¤»¤Ê¤«¤Ã¤¿¡£");
909 #else
910                         msg_print("You failed to pick the lock.");
911 #endif
912
913                 }
914         }
915
916         /* Allowed to open */
917         if (flag)
918         {
919                 /* Apply chest traps, if any */
920                 chest_trap(y, x, o_idx);
921
922                 /* Let the Chest drop items */
923                 chest_death(FALSE, y, x, o_idx);
924         }
925
926         /* Result */
927         return (more);
928 }
929
930
931 #if defined(ALLOW_EASY_OPEN) || defined(ALLOW_EASY_DISARM) /* TNB */
932
933 /*
934  * Return TRUE if the given feature is an open door
935  */
936 static bool is_open(int feat)
937 {
938         return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
939 }
940
941
942 /*
943  * Return the number of features around (or under) the character.
944  * Usually look for doors and floor traps.
945  */
946 static int count_dt(int *y, int *x, bool (*test)(int feat), bool under)
947 {
948         int d, count, xx, yy;
949
950         /* Count how many matches */
951         count = 0;
952
953         /* Check around (and under) the character */
954         for (d = 0; d < 9; d++)
955         {
956                 cave_type *c_ptr;
957                 s16b feat;
958
959                 /* if not searching under player continue */
960                 if ((d == 8) && !under) continue;
961
962                 /* Extract adjacent (legal) location */
963                 yy = py + ddy_ddd[d];
964                 xx = px + ddx_ddd[d];
965
966                 /* Get the cave */
967                 c_ptr = &cave[yy][xx];
968
969                 /* Must have knowledge */
970                 if (!(c_ptr->info & (CAVE_MARK))) continue;
971
972                 /* Feature code (applying "mimic" field) */
973                 feat = get_feat_mimic(c_ptr);
974
975                 /* Not looking for this feature */
976                 if (!((*test)(feat))) continue;
977
978                 /* OK */
979                 ++count;
980
981                 /* Remember the location. Only useful if only one match */
982                 *y = yy;
983                 *x = xx;
984         }
985
986         /* All done */
987         return count;
988 }
989
990
991 /*
992  * Return the number of chests around (or under) the character.
993  * If requested, count only trapped chests.
994  */
995 static int count_chests(int *y, int *x, bool trapped)
996 {
997         int d, count, o_idx;
998
999         object_type *o_ptr;
1000
1001         /* Count how many matches */
1002         count = 0;
1003
1004         /* Check around (and under) the character */
1005         for (d = 0; d < 9; d++)
1006         {
1007                 /* Extract adjacent (legal) location */
1008                 int yy = py + ddy_ddd[d];
1009                 int xx = px + ddx_ddd[d];
1010
1011                 /* No (visible) chest is there */
1012                 if ((o_idx = chest_check(yy, xx)) == 0) continue;
1013
1014                 /* Grab the object */
1015                 o_ptr = &o_list[o_idx];
1016
1017                 /* Already open */
1018                 if (o_ptr->pval == 0) continue;
1019
1020                 /* No (known) traps here */
1021                 if (trapped && (!object_is_known(o_ptr) ||
1022                         !chest_traps[o_ptr->pval])) continue;
1023
1024                 /* OK */
1025                 ++count;
1026
1027                 /* Remember the location. Only useful if only one match */
1028                 *y = yy;
1029                 *x = xx;
1030         }
1031
1032         /* All done */
1033         return count;
1034 }
1035
1036
1037 /*
1038  * Convert an adjacent location to a direction.
1039  */
1040 static int coords_to_dir(int y, int x)
1041 {
1042         int d[3][3] = { {7, 4, 1}, {8, 5, 2}, {9, 6, 3} };
1043         int dy, dx;
1044
1045         dy = y - py;
1046         dx = x - px;
1047
1048         /* Paranoia */
1049         if (ABS(dx) > 1 || ABS(dy) > 1) return (0);
1050
1051         return d[dx + 1][dy + 1];
1052 }
1053
1054 #endif /* defined(ALLOW_EASY_OPEN) || defined(ALLOW_EASY_DISARM) -- TNB */
1055
1056
1057 /*
1058  * Perform the basic "open" command on doors
1059  *
1060  * Assume destination is a closed/locked/jammed door
1061  *
1062  * Assume there is no monster blocking the destination
1063  *
1064  * Returns TRUE if repeated commands may continue
1065  */
1066 static bool do_cmd_open_aux(int y, int x)
1067 {
1068         int i, j;
1069
1070         /* Get requested grid */
1071         cave_type *c_ptr = &cave[y][x];
1072
1073         feature_type *f_ptr = &f_info[c_ptr->feat];
1074
1075         bool more = FALSE;
1076
1077
1078         /* Take a turn */
1079         energy_use = 100;
1080
1081         /* Seeing true feature code (ignore mimic) */
1082
1083         /* Jammed door */
1084         if (!have_flag(f_ptr->flags, FF_OPEN))
1085         {
1086                 /* Stuck */
1087 #ifdef JP
1088                 msg_format("%s¤Ï¤¬¤Ã¤Á¤ê¤ÈÊĤ¸¤é¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£", f_name + f_info[get_feat_mimic(c_ptr)].name);
1089 #else
1090                 msg_format("The %s appears to be stuck.", f_name + f_info[get_feat_mimic(c_ptr)].name);
1091 #endif
1092
1093         }
1094
1095         /* Locked door */
1096         else if (f_ptr->power)
1097         {
1098                 /* Disarm factor */
1099                 i = p_ptr->skill_dis;
1100
1101                 /* Penalize some conditions */
1102                 if (p_ptr->blind || no_lite()) i = i / 10;
1103                 if (p_ptr->confused || p_ptr->image) i = i / 10;
1104
1105                 /* Extract the lock power */
1106                 j = f_ptr->power;
1107
1108                 /* Extract the difficulty XXX XXX XXX */
1109                 j = i - (j * 4);
1110
1111                 /* Always have a small chance of success */
1112                 if (j < 2) j = 2;
1113
1114                 /* Success */
1115                 if (randint0(100) < j)
1116                 {
1117                         /* Message */
1118 #ifdef JP
1119                         msg_print("¸°¤ò¤Ï¤º¤·¤¿¡£");
1120 #else
1121                         msg_print("You have picked the lock.");
1122 #endif
1123
1124                         /* Open the door */
1125                         cave_alter_feat(y, x, FF_OPEN);
1126
1127                         /* Sound */
1128                         sound(SOUND_OPENDOOR);
1129
1130                         /* Experience */
1131                         gain_exp(1);
1132                 }
1133
1134                 /* Failure */
1135                 else
1136                 {
1137                         /* Failure */
1138                         if (flush_failure) flush();
1139
1140                         /* Message */
1141 #ifdef JP
1142                         msg_print("¸°¤ò¤Ï¤º¤»¤Ê¤«¤Ã¤¿¡£");
1143 #else
1144                         msg_print("You failed to pick the lock.");
1145 #endif
1146
1147
1148                         /* We may keep trying */
1149                         more = TRUE;
1150                 }
1151         }
1152
1153         /* Closed door */
1154         else
1155         {
1156                 /* Open the door */
1157                 cave_alter_feat(y, x, FF_OPEN);
1158
1159                 /* Sound */
1160                 sound(SOUND_OPENDOOR);
1161         }
1162
1163         /* Result */
1164         return (more);
1165 }
1166
1167
1168
1169 /*
1170  * Open a closed/locked/jammed door or a closed/locked chest.
1171  *
1172  * Unlocking a locked door/chest is worth one experience point.
1173  */
1174 void do_cmd_open(void)
1175 {
1176         int y, x, dir;
1177
1178         s16b o_idx;
1179
1180         bool more = FALSE;
1181
1182         if (p_ptr->special_defense & KATA_MUSOU)
1183         {
1184                 set_action(ACTION_NONE);
1185         }
1186
1187 #ifdef ALLOW_EASY_OPEN /* TNB */
1188
1189         /* Option: Pick a direction */
1190         if (easy_open)
1191         {
1192                 int num_doors, num_chests;
1193
1194                 /* Count closed doors (locked or jammed) */
1195                 num_doors = count_dt(&y, &x, is_closed_door, FALSE);
1196
1197                 /* Count chests (locked) */
1198                 num_chests = count_chests(&y, &x, FALSE);
1199
1200                 /* See if only one target */
1201                 if (num_doors || num_chests)
1202                 {
1203                         bool too_many = (num_doors && num_chests) || (num_doors > 1) ||
1204                             (num_chests > 1);
1205                         if (!too_many) command_dir = coords_to_dir(y, x);
1206                 }
1207         }
1208
1209 #endif /* ALLOW_EASY_OPEN -- TNB */
1210
1211         /* Allow repeated command */
1212         if (command_arg)
1213         {
1214                 /* Set repeat count */
1215                 command_rep = command_arg - 1;
1216
1217                 /* Redraw the state */
1218                 p_ptr->redraw |= (PR_STATE);
1219
1220                 /* Cancel the arg */
1221                 command_arg = 0;
1222         }
1223
1224         /* Get a "repeated" direction */
1225         if (get_rep_dir(&dir, TRUE))
1226         {
1227                 s16b feat;
1228                 cave_type *c_ptr;
1229
1230                 /* Get requested location */
1231                 y = py + ddy[dir];
1232                 x = px + ddx[dir];
1233
1234                 /* Get requested grid */
1235                 c_ptr = &cave[y][x];
1236
1237                 /* Feature code (applying "mimic" field) */
1238                 feat = get_feat_mimic(c_ptr);
1239
1240                 /* Check for chest */
1241                 o_idx = chest_check(y, x);
1242
1243                 /* Nothing useful */
1244                 if (!have_flag(f_info[feat].flags, FF_OPEN) && !o_idx)
1245                 {
1246                         /* Message */
1247 #ifdef JP
1248                 msg_print("¤½¤³¤Ë¤Ï³«¤±¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
1249 #else
1250                         msg_print("You see nothing there to open.");
1251 #endif
1252
1253                 }
1254
1255                 /* Monster in the way */
1256                 else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
1257                 {
1258                         /* Take a turn */
1259                         energy_use = 100;
1260
1261                         /* Message */
1262 #ifdef JP
1263                 msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
1264 #else
1265                         msg_print("There is a monster in the way!");
1266 #endif
1267
1268
1269                         /* Attack */
1270                         py_attack(y, x, 0);
1271                 }
1272
1273                 /* Handle chests */
1274                 else if (o_idx)
1275                 {
1276                         /* Open the chest */
1277                         more = do_cmd_open_chest(y, x, o_idx);
1278                 }
1279
1280                 /* Handle doors */
1281                 else
1282                 {
1283                         /* Open the door */
1284                         more = do_cmd_open_aux(y, x);
1285                 }
1286         }
1287
1288         /* Cancel repeat unless we may continue */
1289         if (!more) disturb(0, 0);
1290 }
1291
1292
1293
1294 /*
1295  * Perform the basic "close" command
1296  *
1297  * Assume destination is an open/broken door
1298  *
1299  * Assume there is no monster blocking the destination
1300  *
1301  * Returns TRUE if repeated commands may continue
1302  */
1303 static bool do_cmd_close_aux(int y, int x)
1304 {
1305         /* Get grid and contents */
1306         cave_type *c_ptr = &cave[y][x];
1307         s16b      old_feat = c_ptr->feat;
1308         bool      more = FALSE;
1309
1310         /* Take a turn */
1311         energy_use = 100;
1312
1313         /* Seeing true feature code (ignore mimic) */
1314
1315         /* Open door */
1316         if (have_flag(f_info[old_feat].flags, FF_CLOSE))
1317         {
1318                 s16b closed_feat = feat_state(old_feat, FF_CLOSE);
1319
1320                 /* Hack -- object in the way */
1321                 if ((c_ptr->o_idx || (c_ptr->info & CAVE_OBJECT)) &&
1322                     (closed_feat != old_feat) && !have_flag(f_info[closed_feat].flags, FF_DROP))
1323                 {
1324                         /* Message */
1325 #ifdef JP
1326                         msg_print("²¿¤«¤¬¤Ä¤Ã¤«¤¨¤ÆÊĤޤé¤Ê¤¤¡£");
1327 #else
1328                         msg_print("There seems stuck.");
1329 #endif
1330                 }
1331                 else
1332                 {
1333                         /* Close the door */
1334                         cave_alter_feat(y, x, FF_CLOSE);
1335
1336                         /* Broken door */
1337                         if (old_feat == c_ptr->feat)
1338                         {
1339                                 /* Message */
1340 #ifdef JP
1341                                 msg_print("¥É¥¢¤Ï²õ¤ì¤Æ¤·¤Þ¤Ã¤Æ¤¤¤ë¡£");
1342 #else
1343                                 msg_print("The door appears to be broken.");
1344 #endif
1345                         }
1346                         else
1347                         {
1348                                 /* Sound */
1349                                 sound(SOUND_SHUTDOOR);
1350                         }
1351                 }
1352         }
1353
1354         /* Result */
1355         return (more);
1356 }
1357
1358
1359 /*
1360  * Close an open door.
1361  */
1362 void do_cmd_close(void)
1363 {
1364         int y, x, dir;
1365
1366         bool more = FALSE;
1367
1368         if (p_ptr->special_defense & KATA_MUSOU)
1369         {
1370                 set_action(ACTION_NONE);
1371         }
1372
1373 #ifdef ALLOW_EASY_OPEN /* TNB */
1374
1375         /* Option: Pick a direction */
1376         if (easy_open)
1377         {
1378                 /* Count open doors */
1379                 if (count_dt(&y, &x, is_open, FALSE) == 1)
1380                 {
1381                         command_dir = coords_to_dir(y, x);
1382                 }
1383         }
1384
1385 #endif /* ALLOW_EASY_OPEN -- TNB */
1386
1387         /* Allow repeated command */
1388         if (command_arg)
1389         {
1390                 /* Set repeat count */
1391                 command_rep = command_arg - 1;
1392
1393                 /* Redraw the state */
1394                 p_ptr->redraw |= (PR_STATE);
1395
1396                 /* Cancel the arg */
1397                 command_arg = 0;
1398         }
1399
1400         /* Get a "repeated" direction */
1401         if (get_rep_dir(&dir,FALSE))
1402         {
1403                 cave_type *c_ptr;
1404                 s16b feat;
1405
1406                 /* Get requested location */
1407                 y = py + ddy[dir];
1408                 x = px + ddx[dir];
1409
1410                 /* Get grid and contents */
1411                 c_ptr = &cave[y][x];
1412
1413                 /* Feature code (applying "mimic" field) */
1414                 feat = get_feat_mimic(c_ptr);
1415
1416                 /* Require open/broken door */
1417                 if (!have_flag(f_info[feat].flags, FF_CLOSE))
1418                 {
1419                         /* Message */
1420 #ifdef JP
1421                         msg_print("¤½¤³¤Ë¤ÏÊĤ¸¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
1422 #else
1423                         msg_print("You see nothing there to close.");
1424 #endif
1425                 }
1426
1427                 /* Monster in the way */
1428                 else if (c_ptr->m_idx)
1429                 {
1430                         /* Take a turn */
1431                         energy_use = 100;
1432
1433                         /* Message */
1434 #ifdef JP
1435                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
1436 #else
1437                         msg_print("There is a monster in the way!");
1438 #endif
1439
1440                         /* Attack */
1441                         py_attack(y, x, 0);
1442                 }
1443
1444                 /* Close the door */
1445                 else
1446                 {
1447                         /* Close the door */
1448                         more = do_cmd_close_aux(y, x);
1449                 }
1450         }
1451
1452         /* Cancel repeat unless we may continue */
1453         if (!more) disturb(0, 0);
1454 }
1455
1456
1457 /*
1458  * Determine if a given grid may be "tunneled"
1459  */
1460 static bool do_cmd_tunnel_test(int y, int x)
1461 {
1462         cave_type *c_ptr = &cave[y][x];
1463
1464         /* Must have knowledge */
1465         if (!(c_ptr->info & CAVE_MARK))
1466         {
1467                 /* Message */
1468 #ifdef JP
1469                 msg_print("¤½¤³¤Ë¤Ï²¿¤â¸«Åö¤¿¤é¤Ê¤¤¡£");
1470 #else
1471                 msg_print("You see nothing there.");
1472 #endif
1473
1474                 /* Nope */
1475                 return (FALSE);
1476         }
1477
1478         /* Must be a wall/door/etc */
1479         if (!cave_have_flag_grid(c_ptr, FF_TUNNEL))
1480         {
1481                 /* Message */
1482 #ifdef JP
1483                 msg_print("¤½¤³¤Ë¤Ï·¡¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
1484 #else
1485                 msg_print("You see nothing there to tunnel.");
1486 #endif
1487
1488                 /* Nope */
1489                 return (FALSE);
1490         }
1491
1492         /* Okay */
1493         return (TRUE);
1494 }
1495
1496
1497 /*
1498  * Perform the basic "tunnel" command
1499  *
1500  * Assumes that no monster is blocking the destination
1501  *
1502  * Do not use twall anymore
1503  *
1504  * Returns TRUE if repeated commands may continue
1505  */
1506 static bool do_cmd_tunnel_aux(int y, int x)
1507 {
1508         cave_type *c_ptr;
1509         feature_type *f_ptr, *mimic_f_ptr;
1510         int power;
1511         cptr name;
1512         bool more = FALSE;
1513
1514         /* Verify legality */
1515         if (!do_cmd_tunnel_test(y, x)) return (FALSE);
1516
1517         /* Take a turn */
1518         energy_use = 100;
1519
1520         /* Get grid */
1521         c_ptr = &cave[y][x];
1522         f_ptr = &f_info[c_ptr->feat];
1523         power = f_ptr->power;
1524
1525         /* Feature code (applying "mimic" field) */
1526         mimic_f_ptr = &f_info[get_feat_mimic(c_ptr)];
1527
1528         name = f_name + mimic_f_ptr->name;
1529
1530         /* Sound */
1531         sound(SOUND_DIG);
1532
1533         if (have_flag(f_ptr->flags, FF_PERMANENT))
1534         {
1535                 /* Titanium */
1536                 if (have_flag(mimic_f_ptr->flags, FF_PERMANENT))
1537                 {
1538 #ifdef JP
1539                         msg_print("¤³¤Î´ä¤Ï¹Å¤¹¤®¤Æ·¡¤ì¤Ê¤¤¤è¤¦¤À¡£");
1540 #else
1541                         msg_print("This seems to be permanent rock.");
1542 #endif
1543                 }
1544
1545                 /* Map border (mimiccing Permanent wall) */
1546                 else
1547                 {
1548 #ifdef JP
1549                         msg_print("¤½¤³¤Ï·¡¤ì¤Ê¤¤!");
1550 #else
1551                         msg_print("You can't tunnel through that!");
1552 #endif
1553                 }
1554         }
1555
1556         /* Dig or tunnel */
1557         else if (have_flag(f_ptr->flags, FF_CAN_DIG))
1558         {
1559                 /* Dig */
1560                 if (p_ptr->skill_dig > randint0(20 * power))
1561                 {
1562                         /* Message */
1563 #ifdef JP
1564                         msg_format("%s¤ò¤¯¤º¤·¤¿¡£", name);
1565 #else
1566                         msg_format("You have removed the %s.", name);
1567 #endif
1568
1569                         /* Remove the feature */
1570                         cave_alter_feat(y, x, FF_TUNNEL);
1571
1572                         /* Update some things */
1573                         p_ptr->update |= (PU_FLOW);
1574                 }
1575                 else
1576                 {
1577                         /* Message, keep digging */
1578 #ifdef JP
1579                         msg_format("%s¤ò¤¯¤º¤·¤Æ¤¤¤ë¡£", name);
1580 #else
1581                         msg_format("You dig into the %s.", name);
1582 #endif
1583
1584                         more = TRUE;
1585                 }
1586         }
1587
1588         else
1589         {
1590                 bool tree = have_flag(mimic_f_ptr->flags, FF_TREE);
1591
1592                 /* Tunnel */
1593                 if (p_ptr->skill_dig > power + randint0(40 * power))
1594                 {
1595 #ifdef JP
1596                         if (tree) msg_format("%s¤òÀÚ¤êʧ¤Ã¤¿¡£", name);
1597                         else
1598                         {
1599                                 msg_print("·ê¤ò·¡¤ê½ª¤¨¤¿¡£");
1600                                 p_ptr->update |= (PU_FLOW);
1601                         }
1602 #else
1603                         if (tree) msg_format("You have cleared away the %s.", name);
1604                         else
1605                         {
1606                                 msg_print("You have finished the tunnel.");
1607                                 p_ptr->update |= (PU_FLOW);
1608                         }
1609 #endif
1610
1611                         /* Remove the feature */
1612                         cave_alter_feat(y, x, FF_TUNNEL);
1613
1614                         chg_virtue(V_DILIGENCE, 1);
1615                         chg_virtue(V_NATURE, -1);
1616                 }
1617
1618                 /* Keep trying */
1619                 else
1620                 {
1621                         if (tree)
1622                         {
1623                                 /* We may continue chopping */
1624 #ifdef JP
1625                                 msg_format("%s¤òÀڤäƤ¤¤ë¡£", name);
1626 #else
1627                                 msg_format("You chop away at the %s.", name);
1628 #endif
1629                                 /* Occasional Search XXX XXX */
1630                                 if (randint0(100) < 25) search();
1631                         }
1632                         else
1633                         {
1634                                 /* We may continue tunelling */
1635 #ifdef JP
1636                                 msg_format("%s¤Ë·ê¤ò·¡¤Ã¤Æ¤¤¤ë¡£", name);
1637 #else
1638                                 msg_format("You tunnel into the %s.", name);
1639 #endif
1640                         }
1641
1642                         more = TRUE;
1643                 }
1644         }
1645
1646         if (is_hidden_door(c_ptr))
1647         {
1648                 /* Occasional Search XXX XXX */
1649                 if (randint0(100) < 25) search();
1650         }
1651
1652         /* Result */
1653         return more;
1654 }
1655
1656
1657 /*
1658  * Tunnels through "walls" (including rubble and closed doors)
1659  *
1660  * Note that you must tunnel in order to hit invisible monsters
1661  * in walls, though moving into walls still takes a turn anyway.
1662  *
1663  * Digging is very difficult without a "digger" weapon, but can be
1664  * accomplished by strong players using heavy weapons.
1665  */
1666 void do_cmd_tunnel(void)
1667 {
1668         int                     y, x, dir;
1669
1670         cave_type       *c_ptr;
1671         s16b feat;
1672
1673         bool            more = FALSE;
1674
1675
1676         if (p_ptr->special_defense & KATA_MUSOU)
1677         {
1678                 set_action(ACTION_NONE);
1679         }
1680
1681         /* Allow repeated command */
1682         if (command_arg)
1683         {
1684                 /* Set repeat count */
1685                 command_rep = command_arg - 1;
1686
1687                 /* Redraw the state */
1688                 p_ptr->redraw |= (PR_STATE);
1689
1690                 /* Cancel the arg */
1691                 command_arg = 0;
1692         }
1693
1694         /* Get a direction to tunnel, or Abort */
1695         if (get_rep_dir(&dir,FALSE))
1696         {
1697                 /* Get location */
1698                 y = py + ddy[dir];
1699                 x = px + ddx[dir];
1700
1701                 /* Get grid */
1702                 c_ptr = &cave[y][x];
1703
1704                 /* Feature code (applying "mimic" field) */
1705                 feat = get_feat_mimic(c_ptr);
1706
1707                 /* No tunnelling through doors */
1708                 if (have_flag(f_info[feat].flags, FF_DOOR))
1709                 {
1710                         /* Message */
1711 #ifdef JP
1712                         msg_print("¥É¥¢¤Ï·¡¤ì¤Ê¤¤¡£");
1713 #else
1714                         msg_print("You cannot tunnel through doors.");
1715 #endif
1716                 }
1717
1718                 /* No tunnelling through most features */
1719                 else if (!have_flag(f_info[feat].flags, FF_TUNNEL))
1720                 {
1721 #ifdef JP
1722                         msg_print("¤½¤³¤Ï·¡¤ì¤Ê¤¤¡£");
1723 #else
1724                         msg_print("You can't tunnel through that.");
1725 #endif
1726                 }
1727
1728                 /* A monster is in the way */
1729                 else if (c_ptr->m_idx)
1730                 {
1731                         /* Take a turn */
1732                         energy_use = 100;
1733
1734                         /* Message */
1735 #ifdef JP
1736                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
1737 #else
1738                         msg_print("There is a monster in the way!");
1739 #endif
1740
1741                         /* Attack */
1742                         py_attack(y, x, 0);
1743                 }
1744
1745                 /* Try digging */
1746                 else
1747                 {
1748                         /* Tunnel through walls */
1749                         more = do_cmd_tunnel_aux(y, x);
1750                 }
1751         }
1752
1753         /* Cancel repetition unless we can continue */
1754         if (!more) disturb(0, 0);
1755 }
1756
1757
1758 #ifdef ALLOW_EASY_OPEN /* TNB */
1759
1760 /*
1761  * easy_open_door --
1762  *
1763  *      If there is a jammed/closed/locked door at the given location,
1764  *      then attempt to unlock/open it. Return TRUE if an attempt was
1765  *      made (successful or not), otherwise return FALSE.
1766  *
1767  *      The code here should be nearly identical to that in
1768  *      do_cmd_open_test() and do_cmd_open_aux().
1769  */
1770 bool easy_open_door(int y, int x)
1771 {
1772         int i, j;
1773
1774         cave_type *c_ptr = &cave[y][x];
1775         feature_type *f_ptr = &f_info[c_ptr->feat];
1776
1777         /* Must be a closed door */
1778         if (!is_closed_door(c_ptr->feat))
1779         {
1780                 /* Nope */
1781                 return (FALSE);
1782         }
1783
1784         /* Jammed door */
1785         if (!have_flag(f_ptr->flags, FF_OPEN))
1786         {
1787                 /* Stuck */
1788 #ifdef JP
1789                 msg_format("%s¤Ï¤¬¤Ã¤Á¤ê¤ÈÊĤ¸¤é¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£", f_name + f_info[get_feat_mimic(c_ptr)].name);
1790 #else
1791                 msg_format("The %s appears to be stuck.", f_name + f_info[get_feat_mimic(c_ptr)].name);
1792 #endif
1793
1794         }
1795
1796         /* Locked door */
1797         else if (f_ptr->power)
1798         {
1799                 /* Disarm factor */
1800                 i = p_ptr->skill_dis;
1801
1802                 /* Penalize some conditions */
1803                 if (p_ptr->blind || no_lite()) i = i / 10;
1804                 if (p_ptr->confused || p_ptr->image) i = i / 10;
1805
1806                 /* Extract the lock power */
1807                 j = f_ptr->power;
1808
1809                 /* Extract the difficulty XXX XXX XXX */
1810                 j = i - (j * 4);
1811
1812                 /* Always have a small chance of success */
1813                 if (j < 2) j = 2;
1814
1815                 /* Success */
1816                 if (randint0(100) < j)
1817                 {
1818                         /* Message */
1819 #ifdef JP
1820                         msg_print("¸°¤ò¤Ï¤º¤·¤¿¡£");
1821 #else
1822                         msg_print("You have picked the lock.");
1823 #endif
1824
1825                         /* Open the door */
1826                         cave_alter_feat(y, x, FF_OPEN);
1827
1828                         /* Sound */
1829                         sound(SOUND_OPENDOOR);
1830
1831                         /* Experience */
1832                         gain_exp(1);
1833                 }
1834
1835                 /* Failure */
1836                 else
1837                 {
1838                         /* Failure */
1839                         if (flush_failure) flush();
1840
1841                         /* Message */
1842 #ifdef JP
1843                         msg_print("¸°¤ò¤Ï¤º¤»¤Ê¤«¤Ã¤¿¡£");
1844 #else
1845                         msg_print("You failed to pick the lock.");
1846 #endif
1847
1848                 }
1849         }
1850
1851         /* Closed door */
1852         else
1853         {
1854                 /* Open the door */
1855                 cave_alter_feat(y, x, FF_OPEN);
1856
1857                 /* Sound */
1858                 sound(SOUND_OPENDOOR);
1859         }
1860
1861         /* Result */
1862         return (TRUE);
1863 }
1864
1865 #endif /* ALLOW_EASY_OPEN -- TNB */
1866
1867
1868 /*
1869  * Perform the basic "disarm" command
1870  *
1871  * Assume destination is a visible trap
1872  *
1873  * Assume there is no monster blocking the destination
1874  *
1875  * Returns TRUE if repeated commands may continue
1876  */
1877 static bool do_cmd_disarm_chest(int y, int x, s16b o_idx)
1878 {
1879         int i, j;
1880
1881         bool more = FALSE;
1882
1883         object_type *o_ptr = &o_list[o_idx];
1884
1885
1886         /* Take a turn */
1887         energy_use = 100;
1888
1889         /* Get the "disarm" factor */
1890         i = p_ptr->skill_dis;
1891
1892         /* Penalize some conditions */
1893         if (p_ptr->blind || no_lite()) i = i / 10;
1894         if (p_ptr->confused || p_ptr->image) i = i / 10;
1895
1896         /* Extract the difficulty */
1897         j = i - o_ptr->pval;
1898
1899         /* Always have a small chance of success */
1900         if (j < 2) j = 2;
1901
1902         /* Must find the trap first. */
1903         if (!object_is_known(o_ptr))
1904         {
1905 #ifdef JP
1906                 msg_print("¥È¥é¥Ã¥×¤¬¸«¤¢¤¿¤é¤Ê¤¤¡£");
1907 #else
1908                 msg_print("I don't see any traps.");
1909 #endif
1910
1911         }
1912
1913         /* Already disarmed/unlocked */
1914         else if (o_ptr->pval <= 0)
1915         {
1916 #ifdef JP
1917                 msg_print("È¢¤Ë¤Ï¥È¥é¥Ã¥×¤¬»Å³Ý¤±¤é¤ì¤Æ¤¤¤Ê¤¤¡£");
1918 #else
1919                 msg_print("The chest is not trapped.");
1920 #endif
1921
1922         }
1923
1924         /* No traps to find. */
1925         else if (!chest_traps[o_ptr->pval])
1926         {
1927 #ifdef JP
1928                 msg_print("È¢¤Ë¤Ï¥È¥é¥Ã¥×¤¬»Å³Ý¤±¤é¤ì¤Æ¤¤¤Ê¤¤¡£");
1929 #else
1930                 msg_print("The chest is not trapped.");
1931 #endif
1932
1933         }
1934
1935         /* Success (get a lot of experience) */
1936         else if (randint0(100) < j)
1937         {
1938 #ifdef JP
1939                 msg_print("È¢¤Ë»Å³Ý¤±¤é¤ì¤Æ¤¤¤¿¥È¥é¥Ã¥×¤ò²ò½ü¤·¤¿¡£");
1940 #else
1941                 msg_print("You have disarmed the chest.");
1942 #endif
1943
1944                 gain_exp(o_ptr->pval);
1945                 o_ptr->pval = (0 - o_ptr->pval);
1946         }
1947
1948         /* Failure -- Keep trying */
1949         else if ((i > 5) && (randint1(i) > 5))
1950         {
1951                 /* We may keep trying */
1952                 more = TRUE;
1953                 if (flush_failure) flush();
1954 #ifdef JP
1955                 msg_print("È¢¤Î¥È¥é¥Ã¥×²ò½ü¤Ë¼ºÇÔ¤·¤¿¡£");
1956 #else
1957                 msg_print("You failed to disarm the chest.");
1958 #endif
1959
1960         }
1961
1962         /* Failure -- Set off the trap */
1963         else
1964         {
1965 #ifdef JP
1966                 msg_print("¥È¥é¥Ã¥×¤òºîÆ°¤µ¤»¤Æ¤·¤Þ¤Ã¤¿¡ª");
1967 #else
1968                 msg_print("You set off a trap!");
1969 #endif
1970
1971                 sound(SOUND_FAIL);
1972                 chest_trap(y, x, o_idx);
1973         }
1974
1975         /* Result */
1976         return (more);
1977 }
1978
1979
1980 /*
1981  * Perform the basic "disarm" command
1982  *
1983  * Assume destination is a visible trap
1984  *
1985  * Assume there is no monster blocking the destination
1986  *
1987  * Returns TRUE if repeated commands may continue
1988  */
1989 #ifdef ALLOW_EASY_DISARM /* TNB */
1990
1991 bool do_cmd_disarm_aux(int y, int x, int dir)
1992
1993 #else /* ALLOW_EASY_DISARM -- TNB */
1994
1995 static bool do_cmd_disarm_aux(int y, int x, int dir)
1996
1997 #endif /* ALLOW_EASY_DISARM -- TNB */
1998 {
1999         /* Get grid and contents */
2000         cave_type *c_ptr = &cave[y][x];
2001
2002         /* Get feature */
2003         feature_type *f_ptr = &f_info[c_ptr->feat];
2004
2005         /* Access trap name */
2006         cptr name = (f_name + f_ptr->name);
2007
2008         /* Extract trap "power" */
2009         int power = f_ptr->power;
2010
2011         bool more = FALSE;
2012
2013         /* Get the "disarm" factor */
2014         int i = p_ptr->skill_dis;
2015
2016         int j;
2017
2018         /* Take a turn */
2019         energy_use = 100;
2020
2021         /* Penalize some conditions */
2022         if (p_ptr->blind || no_lite()) i = i / 10;
2023         if (p_ptr->confused || p_ptr->image) i = i / 10;
2024
2025         /* Extract the difficulty */
2026         j = i - power;
2027
2028         /* Always have a small chance of success */
2029         if (j < 2) j = 2;
2030
2031         /* Success */
2032         if (randint0(100) < j)
2033         {
2034                 /* Message */
2035 #ifdef JP
2036                 msg_format("%s¤ò²ò½ü¤·¤¿¡£", name);
2037 #else
2038                 msg_format("You have disarmed the %s.", name);
2039 #endif
2040
2041                 /* Reward */
2042                 gain_exp(power);
2043
2044                 /* Remove the trap */
2045                 cave_alter_feat(y, x, FF_DISARM);
2046
2047 #ifdef ALLOW_EASY_DISARM /* TNB */
2048
2049                 /* Move the player onto the trap */
2050                 move_player(dir, easy_disarm, FALSE);
2051
2052 #else /* ALLOW_EASY_DISARM -- TNB */
2053
2054                 /* move the player onto the trap grid */
2055                 move_player(dir, FALSE, FALSE);
2056
2057 #endif /* ALLOW_EASY_DISARM -- TNB */
2058         }
2059
2060         /* Failure -- Keep trying */
2061         else if ((i > 5) && (randint1(i) > 5))
2062         {
2063                 /* Failure */
2064                 if (flush_failure) flush();
2065
2066                 /* Message */
2067 #ifdef JP
2068                 msg_format("%s¤Î²ò½ü¤Ë¼ºÇÔ¤·¤¿¡£", name);
2069 #else
2070                 msg_format("You failed to disarm the %s.", name);
2071 #endif
2072
2073                 /* We may keep trying */
2074                 more = TRUE;
2075         }
2076
2077         /* Failure -- Set off the trap */
2078         else
2079         {
2080                 /* Message */
2081 #ifdef JP
2082                 msg_format("%s¤òºîÆ°¤µ¤»¤Æ¤·¤Þ¤Ã¤¿¡ª", name);
2083 #else
2084                 msg_format("You set off the %s!", name);
2085 #endif
2086
2087 #ifdef ALLOW_EASY_DISARM /* TNB */
2088
2089                 /* Move the player onto the trap */
2090                 move_player(dir, easy_disarm, FALSE);
2091
2092 #else /* ALLOW_EASY_DISARM -- TNB */
2093
2094                 /* Move the player onto the trap */
2095                 move_player(dir, FALSE, FALSE);
2096
2097 #endif /* ALLOW_EASY_DISARM -- TNB */
2098         }
2099
2100         /* Result */
2101         return (more);
2102 }
2103
2104
2105 /*
2106  * Disarms a trap, or chest
2107  */
2108 void do_cmd_disarm(void)
2109 {
2110         int y, x, dir;
2111
2112         s16b o_idx;
2113
2114         bool more = FALSE;
2115
2116         if (p_ptr->special_defense & KATA_MUSOU)
2117         {
2118                 set_action(ACTION_NONE);
2119         }
2120
2121 #ifdef ALLOW_EASY_DISARM /* TNB */
2122
2123         /* Option: Pick a direction */
2124         if (easy_disarm)
2125         {
2126                 int num_traps, num_chests;
2127
2128                 /* Count visible traps */
2129                 num_traps = count_dt(&y, &x, is_trap, TRUE);
2130
2131                 /* Count chests (trapped) */
2132                 num_chests = count_chests(&y, &x, TRUE);
2133
2134                 /* See if only one target */
2135                 if (num_traps || num_chests)
2136                 {
2137                         bool too_many = (num_traps && num_chests) || (num_traps > 1) ||
2138                             (num_chests > 1);
2139                         if (!too_many) command_dir = coords_to_dir(y, x);
2140                 }
2141         }
2142
2143 #endif /* ALLOW_EASY_DISARM -- TNB */
2144
2145         /* Allow repeated command */
2146         if (command_arg)
2147         {
2148                 /* Set repeat count */
2149                 command_rep = command_arg - 1;
2150
2151                 /* Redraw the state */
2152                 p_ptr->redraw |= (PR_STATE);
2153
2154                 /* Cancel the arg */
2155                 command_arg = 0;
2156         }
2157
2158         /* Get a direction (or abort) */
2159         if (get_rep_dir(&dir,TRUE))
2160         {
2161                 cave_type *c_ptr;
2162                 s16b feat;
2163
2164                 /* Get location */
2165                 y = py + ddy[dir];
2166                 x = px + ddx[dir];
2167
2168                 /* Get grid and contents */
2169                 c_ptr = &cave[y][x];
2170
2171                 /* Feature code (applying "mimic" field) */
2172                 feat = get_feat_mimic(c_ptr);
2173
2174                 /* Check for chests */
2175                 o_idx = chest_check(y, x);
2176
2177                 /* Disarm a trap */
2178                 if (!is_trap(feat) && !o_idx)
2179                 {
2180                         /* Message */
2181 #ifdef JP
2182                         msg_print("¤½¤³¤Ë¤Ï²ò½ü¤¹¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
2183 #else
2184                         msg_print("You see nothing there to disarm.");
2185 #endif
2186
2187                 }
2188
2189                 /* Monster in the way */
2190                 else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
2191                 {
2192                         /* Message */
2193 #ifdef JP
2194                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
2195 #else
2196                         msg_print("There is a monster in the way!");
2197 #endif
2198
2199
2200                         /* Attack */
2201                         py_attack(y, x, 0);
2202                 }
2203
2204                 /* Disarm chest */
2205                 else if (o_idx)
2206                 {
2207                         /* Disarm the chest */
2208                         more = do_cmd_disarm_chest(y, x, o_idx);
2209                 }
2210
2211                 /* Disarm trap */
2212                 else
2213                 {
2214                         /* Disarm the trap */
2215                         more = do_cmd_disarm_aux(y, x, dir);
2216                 }
2217         }
2218
2219         /* Cancel repeat unless told not to */
2220         if (!more) disturb(0, 0);
2221 }
2222
2223
2224 /*
2225  * Perform the basic "bash" command
2226  *
2227  * Assume destination is a closed/locked/jammed door
2228  *
2229  * Assume there is no monster blocking the destination
2230  *
2231  * Returns TRUE if repeated commands may continue
2232  */
2233 static bool do_cmd_bash_aux(int y, int x, int dir)
2234 {
2235         /* Get grid */
2236         cave_type       *c_ptr = &cave[y][x];
2237
2238         /* Hack -- Bash power based on strength */
2239         /* (Ranges from 3 to 20 to 100 to 200) */
2240         int bash = adj_str_blow[p_ptr->stat_ind[A_STR]];
2241
2242         /* Extract door power */
2243         int temp = f_info[c_ptr->feat].power;
2244
2245         bool            more = FALSE;
2246
2247         cptr name = f_name + f_info[get_feat_mimic(c_ptr)].name;
2248
2249         /* Take a turn */
2250         energy_use = 100;
2251
2252         /* Message */
2253 #ifdef JP
2254         msg_format("%s¤ËÂÎÅö¤¿¤ê¤ò¤·¤¿¡ª", name);
2255 #else
2256         msg_format("You smash into the %s!", name);
2257 #endif
2258
2259         /* Compare bash power to door power XXX XXX XXX */
2260         temp = (bash - (temp * 10));
2261
2262         if (p_ptr->pclass == CLASS_BERSERKER) temp *= 2;
2263
2264         /* Hack -- always have a chance */
2265         if (temp < 1) temp = 1;
2266
2267         /* Hack -- attempt to bash down the door */
2268         if (randint0(100) < temp)
2269         {
2270                 /* Message */
2271 #ifdef JP
2272                 msg_format("%s¤ò²õ¤·¤¿¡ª", name);
2273 #else
2274                 msg_format("The %s crashes open!", name);
2275 #endif
2276
2277
2278                 /* Break down the door */
2279                 if ((randint0(100) < 50) || (feat_state(c_ptr->feat, FF_OPEN) == c_ptr->feat))
2280                 {
2281                         cave_alter_feat(y, x, FF_BASH);
2282                 }
2283
2284                 /* Open the door */
2285                 else
2286                 {
2287                         cave_alter_feat(y, x, FF_OPEN);
2288                 }
2289
2290                 /* Sound */
2291                 sound(SOUND_OPENDOOR);
2292
2293                 /* Hack -- Fall through the door */
2294                 move_player(dir, FALSE, FALSE);
2295         }
2296
2297         /* Saving throw against stun */
2298         else if (randint0(100) < adj_dex_safe[p_ptr->stat_ind[A_DEX]] +
2299                  p_ptr->lev)
2300         {
2301                 /* Message */
2302 #ifdef JP
2303                 msg_format("¤³¤Î%s¤Ï´è¾æ¤À¡£", name);
2304 #else
2305                 msg_format("The %s holds firm.", name);
2306 #endif
2307
2308
2309                 /* Allow repeated bashing */
2310                 more = TRUE;
2311         }
2312
2313         /* High dexterity yields coolness */
2314         else
2315         {
2316                 /* Message */
2317 #ifdef JP
2318                 msg_print("ÂΤΥХé¥ó¥¹¤ò¤¯¤º¤·¤Æ¤·¤Þ¤Ã¤¿¡£");
2319 #else
2320                 msg_print("You are off-balance.");
2321 #endif
2322
2323
2324                 /* Hack -- Lose balance ala paralysis */
2325                 (void)set_paralyzed(p_ptr->paralyzed + 2 + randint0(2));
2326         }
2327
2328         /* Result */
2329         return (more);
2330 }
2331
2332
2333 /*
2334  * Bash open a door, success based on character strength
2335  *
2336  * For a closed door, pval is positive if locked; negative if stuck.
2337  *
2338  * For an open door, pval is positive for a broken door.
2339  *
2340  * A closed door can be opened - harder if locked. Any door might be
2341  * bashed open (and thereby broken). Bashing a door is (potentially)
2342  * faster! You move into the door way. To open a stuck door, it must
2343  * be bashed. A closed door can be jammed (see do_cmd_spike()).
2344  *
2345  * Creatures can also open or bash doors, see elsewhere.
2346  */
2347 void do_cmd_bash(void)
2348 {
2349         int                     y, x, dir;
2350
2351         cave_type       *c_ptr;
2352
2353         bool            more = FALSE;
2354
2355
2356         if (p_ptr->special_defense & KATA_MUSOU)
2357         {
2358                 set_action(ACTION_NONE);
2359         }
2360
2361         /* Allow repeated command */
2362         if (command_arg)
2363         {
2364                 /* Set repeat count */
2365                 command_rep = command_arg - 1;
2366
2367                 /* Redraw the state */
2368                 p_ptr->redraw |= (PR_STATE);
2369
2370                 /* Cancel the arg */
2371                 command_arg = 0;
2372         }
2373
2374         /* Get a "repeated" direction */
2375         if (get_rep_dir(&dir,FALSE))
2376         {
2377                 s16b feat;
2378
2379                 /* Bash location */
2380                 y = py + ddy[dir];
2381                 x = px + ddx[dir];
2382
2383                 /* Get grid */
2384                 c_ptr = &cave[y][x];
2385
2386                 /* Feature code (applying "mimic" field) */
2387                 feat = get_feat_mimic(c_ptr);
2388
2389                 /* Nothing useful */
2390                 if (!have_flag(f_info[feat].flags, FF_BASH))
2391                 {
2392                         /* Message */
2393 #ifdef JP
2394                         msg_print("¤½¤³¤Ë¤ÏÂÎÅö¤¿¤ê¤¹¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
2395 #else
2396                         msg_print("You see nothing there to bash.");
2397 #endif
2398
2399                 }
2400
2401                 /* Monster in the way */
2402                 else if (c_ptr->m_idx)
2403                 {
2404                         /* Take a turn */
2405                         energy_use = 100;
2406
2407                         /* Message */
2408 #ifdef JP
2409                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
2410 #else
2411                         msg_print("There is a monster in the way!");
2412 #endif
2413
2414
2415                         /* Attack */
2416                         py_attack(y, x, 0);
2417                 }
2418
2419                 /* Bash a closed door */
2420                 else
2421                 {
2422                         /* Bash the door */
2423                         more = do_cmd_bash_aux(y, x, dir);
2424                 }
2425         }
2426
2427         /* Unless valid action taken, cancel bash */
2428         if (!more) disturb(0, 0);
2429 }
2430
2431
2432 /*
2433  * Manipulate an adjacent grid in some way
2434  *
2435  * Attack monsters, tunnel through walls, disarm traps, open doors.
2436  *
2437  * Consider confusion XXX XXX XXX
2438  *
2439  * This command must always take a turn, to prevent free detection
2440  * of invisible monsters.
2441  */
2442 void do_cmd_alter(void)
2443 {
2444         int                     y, x, dir;
2445
2446         cave_type       *c_ptr;
2447
2448         bool            more = FALSE;
2449
2450
2451         if (p_ptr->special_defense & KATA_MUSOU)
2452         {
2453                 set_action(ACTION_NONE);
2454         }
2455
2456         /* Allow repeated command */
2457         if (command_arg)
2458         {
2459                 /* Set repeat count */
2460                 command_rep = command_arg - 1;
2461
2462                 /* Redraw the state */
2463                 p_ptr->redraw |= (PR_STATE);
2464
2465                 /* Cancel the arg */
2466                 command_arg = 0;
2467         }
2468
2469         /* Get a direction */
2470         if (get_rep_dir(&dir,TRUE))
2471         {
2472                 s16b feat;
2473                 feature_type *f_ptr;
2474
2475                 /* Get location */
2476                 y = py + ddy[dir];
2477                 x = px + ddx[dir];
2478
2479                 /* Get grid */
2480                 c_ptr = &cave[y][x];
2481
2482                 /* Feature code (applying "mimic" field) */
2483                 feat = get_feat_mimic(c_ptr);
2484                 f_ptr = &f_info[feat];
2485
2486                 /* Take a turn */
2487                 energy_use = 100;
2488
2489                 /* Attack monsters */
2490                 if (c_ptr->m_idx)
2491                 {
2492                         /* Attack */
2493                         py_attack(y, x, 0);
2494                 }
2495
2496                 /* Locked doors */
2497                 else if (have_flag(f_ptr->flags, FF_OPEN))
2498                 {
2499                         more = do_cmd_open_aux(y, x);
2500                 }
2501
2502                 /* Bash jammed doors */
2503                 else if (have_flag(f_ptr->flags, FF_BASH))
2504                 {
2505                         more = do_cmd_bash_aux(y, x, dir);
2506                 }
2507
2508                 /* Tunnel through walls */
2509                 else if (have_flag(f_ptr->flags, FF_TUNNEL))
2510                 {
2511                         more = do_cmd_tunnel_aux(y, x);
2512                 }
2513
2514                 /* Close open doors */
2515                 else if (have_flag(f_ptr->flags, FF_CLOSE))
2516                 {
2517                         more = do_cmd_close_aux(y, x);
2518                 }
2519
2520                 /* Disarm traps */
2521                 else if (have_flag(f_ptr->flags, FF_DISARM))
2522                 {
2523                         more = do_cmd_disarm_aux(y, x, dir);
2524                 }
2525
2526                 /* Oops */
2527                 else
2528                 {
2529                         /* Oops */
2530 #ifdef JP
2531                         msg_print("²¿¤â¤Ê¤¤¶õÃæ¤ò¹¶·â¤·¤¿¡£");
2532 #else
2533                         msg_print("You attack the empty air.");
2534 #endif
2535
2536                 }
2537         }
2538
2539         /* Cancel repetition unless we can continue */
2540         if (!more) disturb(0, 0);
2541 }
2542
2543
2544 /*
2545  * Find the index of some "spikes", if possible.
2546  *
2547  * XXX XXX XXX Let user choose a pile of spikes, perhaps?
2548  */
2549 static bool get_spike(int *ip)
2550 {
2551         int i;
2552
2553         /* Check every item in the pack */
2554         for (i = 0; i < INVEN_PACK; i++)
2555         {
2556                 object_type *o_ptr = &inventory[i];
2557
2558                 /* Skip non-objects */
2559                 if (!o_ptr->k_idx) continue;
2560
2561                 /* Check the "tval" code */
2562                 if (o_ptr->tval == TV_SPIKE)
2563                 {
2564                         /* Save the spike index */
2565                         (*ip) = i;
2566
2567                         /* Success */
2568                         return (TRUE);
2569                 }
2570         }
2571
2572         /* Oops */
2573         return (FALSE);
2574 }
2575
2576
2577 /*
2578  * Jam a closed door with a spike
2579  *
2580  * This command may NOT be repeated
2581  */
2582 void do_cmd_spike(void)
2583 {
2584         int dir;
2585
2586         if (p_ptr->special_defense & KATA_MUSOU)
2587         {
2588                 set_action(ACTION_NONE);
2589         }
2590
2591         /* Get a "repeated" direction */
2592         if (get_rep_dir(&dir,FALSE))
2593         {
2594                 int y, x, item;
2595                 cave_type *c_ptr;
2596                 s16b feat;
2597
2598                 /* Get location */
2599                 y = py + ddy[dir];
2600                 x = px + ddx[dir];
2601
2602                 /* Get grid and contents */
2603                 c_ptr = &cave[y][x];
2604
2605                 /* Feature code (applying "mimic" field) */
2606                 feat = get_feat_mimic(c_ptr);
2607
2608                 /* Require closed door */
2609                 if (!have_flag(f_info[feat].flags, FF_SPIKE))
2610                 {
2611                         /* Message */
2612 #ifdef JP
2613                         msg_print("¤½¤³¤Ë¤Ï¤¯¤µ¤Ó¤òÂǤƤë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
2614 #else
2615                         msg_print("You see nothing there to spike.");
2616 #endif
2617
2618                 }
2619
2620                 /* Get a spike */
2621                 else if (!get_spike(&item))
2622                 {
2623                         /* Message */
2624 #ifdef JP
2625                         msg_print("¤¯¤µ¤Ó¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡ª");
2626 #else
2627                         msg_print("You have no spikes!");
2628 #endif
2629                 }
2630
2631                 /* Is a monster in the way? */
2632                 else if (c_ptr->m_idx)
2633                 {
2634                         /* Take a turn */
2635                         energy_use = 100;
2636
2637                         /* Message */
2638 #ifdef JP
2639                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
2640 #else
2641                         msg_print("There is a monster in the way!");
2642 #endif
2643
2644                         /* Attack */
2645                         py_attack(y, x, 0);
2646                 }
2647
2648                 /* Go for it */
2649                 else
2650                 {
2651                         /* Take a turn */
2652                         energy_use = 100;
2653
2654                         /* Successful jamming */
2655 #ifdef JP
2656                         msg_format("%s¤Ë¤¯¤µ¤Ó¤òÂǤÁ¹þ¤ó¤À¡£", f_name + f_info[feat].name);
2657 #else
2658                         msg_format("You jam the %s with a spike.", f_name + f_info[feat].name);
2659 #endif
2660
2661                         cave_alter_feat(y, x, FF_SPIKE);
2662
2663                         /* Use up, and describe, a single spike, from the bottom */
2664                         inven_item_increase(item, -1);
2665                         inven_item_describe(item);
2666                         inven_item_optimize(item);
2667                 }
2668         }
2669 }
2670
2671
2672
2673 /*
2674  * Support code for the "Walk" and "Jump" commands
2675  */
2676 void do_cmd_walk(bool pickup)
2677 {
2678         int dir;
2679
2680         bool more = FALSE;
2681
2682
2683         /* Allow repeated command */
2684         if (command_arg)
2685         {
2686                 /* Set repeat count */
2687                 command_rep = command_arg - 1;
2688
2689                 /* Redraw the state */
2690                 p_ptr->redraw |= (PR_STATE);
2691
2692                 /* Cancel the arg */
2693                 command_arg = 0;
2694         }
2695
2696         /* Get a "repeated" direction */
2697         if (get_rep_dir(&dir,FALSE))
2698         {
2699                 /* Take a turn */
2700                 energy_use = 100;
2701
2702                 if ((dir != 5) && (p_ptr->special_defense & KATA_MUSOU))
2703                 {
2704                         set_action(ACTION_NONE);
2705                 }
2706
2707                 /* Hack -- In small scale wilderness it takes MUCH more time to move */
2708                 if (p_ptr->wild_mode) energy_use *= ((MAX_HGT + MAX_WID) / 2);
2709                 if (p_ptr->action == ACTION_HAYAGAKE) energy_use = energy_use * (45-(p_ptr->lev/2)) / 100;
2710
2711                 /* Actually move the character */
2712                 move_player(dir, pickup, FALSE);
2713
2714                 /* Allow more walking */
2715                 more = TRUE;
2716         }
2717
2718         /* Hack again -- Is there a special encounter ??? */
2719         if (p_ptr->wild_mode && !cave_have_flag_bold(py, px, FF_TOWN))
2720         {
2721                 int tmp = 120 + p_ptr->lev*10 - wilderness[py][px].level + 5;
2722                 if (tmp < 1) 
2723                         tmp = 1;
2724                 if (((wilderness[py][px].level + 5) > (p_ptr->lev / 2)) && randint0(tmp) < (21-p_ptr->skill_stl))
2725                 {
2726                         /* Inform the player of his horrible fate :=) */
2727 #ifdef JP
2728                         msg_print("½±·â¤À¡ª");
2729 #else
2730                         msg_print("You are ambushed !");
2731 #endif
2732
2733                         /* Go into large wilderness view */
2734                         p_ptr->oldpy = randint1(MAX_HGT-2);
2735                         p_ptr->oldpx = randint1(MAX_WID-2);
2736                         change_wild_mode();
2737
2738                         /* Give first move to monsters */
2739                         energy_use = 100;
2740
2741                         /* HACk -- set the encouter flag for the wilderness generation */
2742                         generate_encounter = TRUE;
2743                 }
2744         }
2745
2746         /* Cancel repeat unless we may continue */
2747         if (!more) disturb(0, 0);
2748 }
2749
2750
2751
2752 /*
2753  * Start running.
2754  */
2755 void do_cmd_run(void)
2756 {
2757         int dir;
2758
2759         /* Hack -- no running when confused */
2760         if (p_ptr->confused)
2761         {
2762 #ifdef JP
2763                 msg_print("º®Í𤷤Ƥ¤¤ÆÁö¤ì¤Ê¤¤¡ª");
2764 #else
2765                 msg_print("You are too confused!");
2766 #endif
2767
2768                 return;
2769         }
2770
2771         if (p_ptr->special_defense & KATA_MUSOU)
2772         {
2773                 set_action(ACTION_NONE);
2774         }
2775
2776         /* Get a "repeated" direction */
2777         if (get_rep_dir(&dir,FALSE))
2778         {
2779                 /* Hack -- Set the run counter */
2780                 running = (command_arg ? command_arg : 1000);
2781
2782                 /* First step */
2783                 run_step(dir);
2784         }
2785 }
2786
2787
2788
2789 /*
2790  * Stay still.  Search.  Enter stores.
2791  * Pick up treasure if "pickup" is true.
2792  */
2793 void do_cmd_stay(bool pickup)
2794 {
2795         u32b mpe_mode = MPE_STAYING | MPE_ENERGY_USE;
2796
2797         /* Allow repeated command */
2798         if (command_arg)
2799         {
2800                 /* Set repeat count */
2801                 command_rep = command_arg - 1;
2802
2803                 /* Redraw the state */
2804                 p_ptr->redraw |= (PR_STATE);
2805
2806                 /* Cancel the arg */
2807                 command_arg = 0;
2808         }
2809
2810         /* Take a turn */
2811         energy_use = 100;
2812
2813         if (pickup) mpe_mode |= MPE_DO_PICKUP;
2814         (void)move_player_effect(py, px, mpe_mode);
2815 }
2816
2817
2818
2819 /*
2820  * Resting allows a player to safely restore his hp     -RAK-
2821  */
2822 void do_cmd_rest(void)
2823 {
2824
2825         set_action(ACTION_NONE);
2826
2827         if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] || p_ptr->magic_num1[1]))
2828         {
2829                 stop_singing();
2830         }
2831
2832         /* Prompt for time if needed */
2833         if (command_arg <= 0)
2834         {
2835 #ifdef JP
2836                 cptr p = "µÙ·Æ (0-9999, '*' ¤Ç HP/MPÁ´²÷, '&' ¤ÇɬÍפʤÀ¤±): ";
2837 #else
2838                 cptr p = "Rest (0-9999, '*' for HP/SP, '&' as needed): ";
2839 #endif
2840
2841
2842                 char out_val[80];
2843
2844                 /* Default */
2845                 strcpy(out_val, "&");
2846
2847                 /* Ask for duration */
2848                 if (!get_string(p, out_val, 4)) return;
2849
2850                 /* Rest until done */
2851                 if (out_val[0] == '&')
2852                 {
2853                         command_arg = (-2);
2854                 }
2855
2856                 /* Rest a lot */
2857                 else if (out_val[0] == '*')
2858                 {
2859                         command_arg = (-1);
2860                 }
2861
2862                 /* Rest some */
2863                 else
2864                 {
2865                         command_arg = atoi(out_val);
2866                         if (command_arg <= 0) return;
2867                 }
2868         }
2869
2870
2871         /* Paranoia */
2872         if (command_arg > 9999) command_arg = 9999;
2873
2874         if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
2875
2876         /* Take a turn XXX XXX XXX (?) */
2877         energy_use = 100;
2878
2879         /* The sin of sloth */
2880         if (command_arg > 100)
2881                 chg_virtue(V_DILIGENCE, -1);
2882         
2883         /* Why are you sleeping when there's no need?  WAKE UP!*/
2884         if ((p_ptr->chp == p_ptr->mhp) &&
2885             (p_ptr->csp == p_ptr->msp) &&
2886             !p_ptr->blind && !p_ptr->confused &&
2887             !p_ptr->poisoned && !p_ptr->afraid &&
2888             !p_ptr->stun && !p_ptr->cut &&
2889             !p_ptr->slow && !p_ptr->paralyzed &&
2890             !p_ptr->image && !p_ptr->word_recall &&
2891             !p_ptr->alter_reality)
2892                         chg_virtue(V_DILIGENCE, -1);
2893
2894         /* Save the rest code */
2895         resting = command_arg;
2896         p_ptr->action = ACTION_REST;
2897
2898         /* Recalculate bonuses */
2899         p_ptr->update |= (PU_BONUS);
2900
2901         /* Redraw the state */
2902         p_ptr->redraw |= (PR_STATE);
2903
2904         /* Handle stuff */
2905         handle_stuff();
2906
2907         /* Refresh */
2908         Term_fresh();
2909 }
2910
2911
2912 /*
2913  * Determines the odds of an object breaking when thrown at a monster
2914  *
2915  * Note that artifacts never break, see the "drop_near()" function.
2916  */
2917 static int breakage_chance(object_type *o_ptr)
2918 {
2919         int archer_bonus = (p_ptr->pclass == CLASS_ARCHER ? (p_ptr->lev-1)/7 + 4: 0);
2920
2921         /* Examine the item type */
2922         switch (o_ptr->tval)
2923         {
2924                 /* Always break */
2925                 case TV_FLASK:
2926                 case TV_POTION:
2927                 case TV_BOTTLE:
2928                 case TV_FOOD:
2929                 case TV_JUNK:
2930                         return (100);
2931
2932                 /* Often break */
2933                 case TV_LITE:
2934                 case TV_SCROLL:
2935                 case TV_SKELETON:
2936                         return (50);
2937
2938                 /* Sometimes break */
2939                 case TV_WAND:
2940                 case TV_SPIKE:
2941                         return (25);
2942                 case TV_ARROW:
2943                         return (20 - archer_bonus * 2);
2944
2945                 /* Rarely break */
2946                 case TV_SHOT:
2947                 case TV_BOLT:
2948                         return (10 - archer_bonus);
2949                 default:
2950                         return (10);
2951         }
2952 }
2953
2954
2955 static s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
2956 {
2957         int mult = 10;
2958
2959         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2960
2961         u32b flgs[TR_FLAG_SIZE];
2962
2963         /* Extract the flags */
2964         object_flags(o_ptr, flgs);
2965
2966         /* Some "weapons" and "ammo" do extra damage */
2967         switch (o_ptr->tval)
2968         {
2969                 case TV_SHOT:
2970                 case TV_ARROW:
2971                 case TV_BOLT:
2972                 {
2973                         /* Slay Animal */
2974                         if ((have_flag(flgs, TR_SLAY_ANIMAL)) &&
2975                             (r_ptr->flags3 & RF3_ANIMAL))
2976                         {
2977                                 if (is_original_ap_and_seen(m_ptr))
2978                                 {
2979                                         r_ptr->r_flags3 |= RF3_ANIMAL;
2980                                 }
2981
2982                                 if (mult < 17) mult = 17;
2983                         }
2984
2985                         /* Kill Animal */
2986                         if ((have_flag(flgs, TR_KILL_ANIMAL)) &&
2987                             (r_ptr->flags3 & RF3_ANIMAL))
2988                         {
2989                                 if (is_original_ap_and_seen(m_ptr))
2990                                 {
2991                                         r_ptr->r_flags3 |= RF3_ANIMAL;
2992                                 }
2993
2994                                 if (mult < 27) mult = 27;
2995                         }
2996
2997                         /* Slay Evil */
2998                         if ((have_flag(flgs, TR_SLAY_EVIL)) &&
2999                             (r_ptr->flags3 & RF3_EVIL))
3000                         {
3001                                 if (is_original_ap_and_seen(m_ptr))
3002                                 {
3003                                         r_ptr->r_flags3 |= RF3_EVIL;
3004                                 }
3005
3006                                 if (mult < 15) mult = 15;
3007                         }
3008
3009                         /* Kill Evil */
3010                         if ((have_flag(flgs, TR_KILL_EVIL)) &&
3011                             (r_ptr->flags3 & RF3_EVIL))
3012                         {
3013                                 if (is_original_ap_and_seen(m_ptr))
3014                                 {
3015                                         r_ptr->r_flags3 |= RF3_EVIL;
3016                                 }
3017
3018                                 if (mult < 25) mult = 25;
3019                         }
3020
3021                         /* Slay Human */
3022                         if ((have_flag(flgs, TR_SLAY_HUMAN)) &&
3023                             (r_ptr->flags2 & RF2_HUMAN))
3024                         {
3025                                 if (is_original_ap_and_seen(m_ptr))
3026                                 {
3027                                         r_ptr->r_flags2 |= RF2_HUMAN;
3028                                 }
3029
3030                                 if (mult < 17) mult = 17;
3031                         }
3032
3033                         /* Kill Human */
3034                         if ((have_flag(flgs, TR_KILL_HUMAN)) &&
3035                             (r_ptr->flags2 & RF2_HUMAN))
3036                         {
3037                                 if (is_original_ap_and_seen(m_ptr))
3038                                 {
3039                                         r_ptr->r_flags2 |= RF2_HUMAN;
3040                                 }
3041
3042                                 if (mult < 27) mult = 27;
3043                         }
3044
3045                         /* Slay Undead */
3046                         if ((have_flag(flgs, TR_SLAY_UNDEAD)) &&
3047                             (r_ptr->flags3 & RF3_UNDEAD))
3048                         {
3049                                 if (is_original_ap_and_seen(m_ptr))
3050                                 {
3051                                         r_ptr->r_flags3 |= RF3_UNDEAD;
3052                                 }
3053
3054                                 if (mult < 20) mult = 20;
3055                         }
3056
3057                         /* Kill Undead */
3058                         if ((have_flag(flgs, TR_KILL_UNDEAD)) &&
3059                             (r_ptr->flags3 & RF3_UNDEAD))
3060                         {
3061                                 if (is_original_ap_and_seen(m_ptr))
3062                                 {
3063                                         r_ptr->r_flags3 |= RF3_UNDEAD;
3064                                 }
3065
3066                                 if (mult < 30) mult = 30;
3067                         }
3068
3069                         /* Slay Demon */
3070                         if ((have_flag(flgs, TR_SLAY_DEMON)) &&
3071                             (r_ptr->flags3 & RF3_DEMON))
3072                         {
3073                                 if (is_original_ap_and_seen(m_ptr))
3074                                 {
3075                                         r_ptr->r_flags3 |= RF3_DEMON;
3076                                 }
3077
3078                                 if (mult < 20) mult = 20;
3079                         }
3080
3081                         /* Kill Demon */
3082                         if ((have_flag(flgs, TR_KILL_DEMON)) &&
3083                             (r_ptr->flags3 & RF3_DEMON))
3084                         {
3085                                 if (is_original_ap_and_seen(m_ptr))
3086                                 {
3087                                         r_ptr->r_flags3 |= RF3_DEMON;
3088                                 }
3089
3090                                 if (mult < 30) mult = 30;
3091                         }
3092
3093                         /* Slay Orc */
3094                         if ((have_flag(flgs, TR_SLAY_ORC)) &&
3095                             (r_ptr->flags3 & RF3_ORC))
3096                         {
3097                                 if (is_original_ap_and_seen(m_ptr))
3098                                 {
3099                                         r_ptr->r_flags3 |= RF3_ORC;
3100                                 }
3101
3102                                 if (mult < 20) mult = 20;
3103                         }
3104
3105                         /* Kill Orc */
3106                         if ((have_flag(flgs, TR_KILL_ORC)) &&
3107                             (r_ptr->flags3 & RF3_ORC))
3108                         {
3109                                 if (is_original_ap_and_seen(m_ptr))
3110                                 {
3111                                         r_ptr->r_flags3 |= RF3_ORC;
3112                                 }
3113
3114                                 if (mult < 30) mult = 30;
3115                         }
3116
3117                         /* Slay Troll */
3118                         if ((have_flag(flgs, TR_SLAY_TROLL)) &&
3119                             (r_ptr->flags3 & RF3_TROLL))
3120                         {
3121                                 if (is_original_ap_and_seen(m_ptr))
3122                                 {
3123                                         r_ptr->r_flags3 |= RF3_TROLL;
3124                                 }
3125
3126                                 if (mult < 20) mult = 20;
3127                         }
3128
3129                         /* Kill Troll */
3130                         if ((have_flag(flgs, TR_KILL_TROLL)) &&
3131                             (r_ptr->flags3 & RF3_TROLL))
3132                         {
3133                                 if (is_original_ap_and_seen(m_ptr))
3134                                 {
3135                                         r_ptr->r_flags3 |= RF3_TROLL;
3136                                 }
3137
3138                                 if (mult < 30) mult = 30;
3139                         }
3140
3141                         /* Slay Giant */
3142                         if ((have_flag(flgs, TR_SLAY_GIANT)) &&
3143                             (r_ptr->flags3 & RF3_GIANT))
3144                         {
3145                                 if (is_original_ap_and_seen(m_ptr))
3146                                 {
3147                                         r_ptr->r_flags3 |= RF3_GIANT;
3148                                 }
3149
3150                                 if (mult < 20) mult = 20;
3151                         }
3152
3153                         /* Kill Giant */
3154                         if ((have_flag(flgs, TR_KILL_GIANT)) &&
3155                             (r_ptr->flags3 & RF3_GIANT))
3156                         {
3157                                 if (is_original_ap_and_seen(m_ptr))
3158                                 {
3159                                         r_ptr->r_flags3 |= RF3_GIANT;
3160                                 }
3161
3162                                 if (mult < 30) mult = 30;
3163                         }
3164
3165                         /* Slay Dragon  */
3166                         if ((have_flag(flgs, TR_SLAY_DRAGON)) &&
3167                             (r_ptr->flags3 & RF3_DRAGON))
3168                         {
3169                                 if (is_original_ap_and_seen(m_ptr))
3170                                 {
3171                                         r_ptr->r_flags3 |= RF3_DRAGON;
3172                                 }
3173
3174                                 if (mult < 20) mult = 20;
3175                         }
3176
3177                         /* Execute Dragon */
3178                         if ((have_flag(flgs, TR_KILL_DRAGON)) &&
3179                             (r_ptr->flags3 & RF3_DRAGON))
3180                         {
3181                                 if (is_original_ap_and_seen(m_ptr))
3182                                 {
3183                                         r_ptr->r_flags3 |= RF3_DRAGON;
3184                                 }
3185
3186                                 if (mult < 30) mult = 30;
3187
3188                                 if ((o_ptr->name1 == ART_BARD_ARROW) &&
3189                                     (m_ptr->r_idx == MON_SMAUG) &&
3190                                     (inventory[INVEN_BOW].name1 == ART_BARD))
3191                                         mult *= 5;
3192                         }
3193
3194                         /* Brand (Acid) */
3195                         if (have_flag(flgs, TR_BRAND_ACID))
3196                         {
3197                                 /* Notice immunity */
3198                                 if (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK)
3199                                 {
3200                                         if (is_original_ap_and_seen(m_ptr))
3201                                         {
3202                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK);
3203                                         }
3204                                 }
3205
3206                                 /* Otherwise, take the damage */
3207                                 else
3208                                 {
3209                                         if (mult < 17) mult = 17;
3210                                 }
3211                         }
3212
3213                         /* Brand (Elec) */
3214                         if (have_flag(flgs, TR_BRAND_ELEC))
3215                         {
3216                                 /* Notice immunity */
3217                                 if (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)
3218                                 {
3219                                         if (is_original_ap_and_seen(m_ptr))
3220                                         {
3221                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
3222                                         }
3223                                 }
3224
3225                                 /* Otherwise, take the damage */
3226                                 else
3227                                 {
3228                                         if (mult < 17) mult = 17;
3229                                 }
3230                         }
3231
3232                         /* Brand (Fire) */
3233                         if (have_flag(flgs, TR_BRAND_FIRE))
3234                         {
3235                                 /* Notice immunity */
3236                                 if (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)
3237                                 {
3238                                         if (is_original_ap_and_seen(m_ptr))
3239                                         {
3240                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
3241                                         }
3242                                 }
3243
3244                                 /* Otherwise, take the damage */
3245                                 else
3246                                 {
3247                                         if (r_ptr->flags3 & RF3_HURT_FIRE)
3248                                         {
3249                                                 if (mult < 25) mult = 25;
3250                                                 if (is_original_ap_and_seen(m_ptr))
3251                                                 {
3252                                                         r_ptr->r_flags3 |= RF3_HURT_FIRE;
3253                                                 }
3254                                         }
3255                                         else if (mult < 17) mult = 17;
3256                                 }
3257                         }
3258
3259                         /* Brand (Cold) */
3260                         if (have_flag(flgs, TR_BRAND_COLD))
3261                         {
3262                                 /* Notice immunity */
3263                                 if (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)
3264                                 {
3265                                         if (is_original_ap_and_seen(m_ptr))
3266                                         {
3267                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
3268                                         }
3269                                 }
3270                                 /* Otherwise, take the damage */
3271                                 else
3272                                 {
3273                                         if (r_ptr->flags3 & RF3_HURT_COLD)
3274                                         {
3275                                                 if (mult < 25) mult = 25;
3276                                                 if (is_original_ap_and_seen(m_ptr))
3277                                                 {
3278                                                         r_ptr->r_flags3 |= RF3_HURT_COLD;
3279                                                 }
3280                                         }
3281                                         else if (mult < 17) mult = 17;
3282                                 }
3283                         }
3284
3285                         /* Brand (Poison) */
3286                         if (have_flag(flgs, TR_BRAND_POIS))
3287                         {
3288                                 /* Notice immunity */
3289                                 if (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)
3290                                 {
3291                                         if (is_original_ap_and_seen(m_ptr))
3292                                         {
3293                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK);
3294                                         }
3295                                 }
3296
3297                                 /* Otherwise, take the damage */
3298                                 else
3299                                 {
3300                                         if (mult < 17) mult = 17;
3301                                 }
3302                         }
3303
3304                         if ((have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (p_ptr->msp / 30)))
3305                         {
3306                                 p_ptr->csp -= (1+(p_ptr->msp / 30));
3307                                 p_ptr->redraw |= (PR_MANA);
3308                                 mult = mult * 5 / 2;
3309                         }
3310                         break;
3311                 }
3312         }
3313
3314         /* Return the total damage */
3315         return (tdam * mult / 10);
3316 }
3317
3318
3319 /*
3320  * Fire an object from the pack or floor.
3321  *
3322  * You may only fire items that "match" your missile launcher.
3323  *
3324  * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
3325  *
3326  * See "calc_bonuses()" for more calculations and such.
3327  *
3328  * Note that "firing" a missile is MUCH better than "throwing" it.
3329  *
3330  * Note: "unseen" monsters are very hard to hit.
3331  *
3332  * Objects are more likely to break if they "attempt" to hit a monster.
3333  *
3334  * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
3335  *
3336  * The "extra shot" code works by decreasing the amount of energy
3337  * required to make each shot, spreading the shots out over time.
3338  *
3339  * Note that when firing missiles, the launcher multiplier is applied
3340  * after all the bonuses are added in, making multipliers very useful.
3341  *
3342  * Note that Bows of "Extra Might" get extra range and an extra bonus
3343  * for the damage multiplier.
3344  *
3345  * Note that Bows of "Extra Shots" give an extra shot.
3346  */
3347 void do_cmd_fire_aux(int item, object_type *j_ptr)
3348 {
3349         int dir;
3350         int j, y, x, ny, nx, ty, tx, prev_y, prev_x;
3351         int tdam, tdis, thits, tmul;
3352         int bonus, chance;
3353         int cur_dis, visible;
3354
3355         object_type forge;
3356         object_type *q_ptr;
3357
3358         object_type *o_ptr;
3359
3360         bool hit_body = FALSE;
3361
3362         char o_name[MAX_NLEN];
3363
3364         int msec = delay_factor * delay_factor * delay_factor;
3365
3366         /* STICK TO */
3367         bool stick_to = FALSE;
3368
3369         /* Access the item (if in the pack) */
3370         if (item >= 0)
3371         {
3372                 o_ptr = &inventory[item];
3373         }
3374         else
3375         {
3376                 o_ptr = &o_list[0 - item];
3377         }
3378
3379         /* Describe the object */
3380         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
3381
3382
3383         /* Use the proper number of shots */
3384         thits = p_ptr->num_fire;
3385
3386         /* Use a base distance */
3387         tdis = 10;
3388
3389         /* Base damage from thrown object plus launcher bonus */
3390         tdam = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
3391
3392         /* Actually "fire" the object */
3393         bonus = (p_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
3394         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
3395                 chance = (p_ptr->skill_thb + (p_ptr->weapon_exp[0][j_ptr->sval] / 400 + bonus) * BTH_PLUS_ADJ);
3396         else
3397                 chance = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
3398
3399         energy_use = bow_energy(j_ptr->sval);
3400         tmul = bow_tmul(j_ptr->sval);
3401
3402         /* Get extra "power" from "extra might" */
3403         if (p_ptr->xtra_might) tmul++;
3404
3405         tmul = tmul * (100 + (int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
3406
3407         /* Boost the damage */
3408         tdam *= tmul;
3409         tdam /= 100;
3410
3411         /* Base range */
3412         tdis = 10 + tmul/40;
3413         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
3414                 tdis -= 5;
3415
3416         project_length = tdis + 1;
3417
3418         /* Get a direction (or cancel) */
3419         if (!get_aim_dir(&dir))
3420         {
3421                 energy_use = 0;
3422
3423                 /* need not to reset project_length (already did)*/
3424
3425                 return;
3426         }
3427
3428         /* Start at the player */
3429         y = py;
3430         x = px;
3431
3432         /* Predict the "target" location */
3433         tx = px + 99 * ddx[dir];
3434         ty = py + 99 * ddy[dir];
3435
3436         /* Check for "target request" */
3437         if ((dir == 5) && target_okay())
3438         {
3439                 tx = target_col;
3440                 ty = target_row;
3441         }
3442
3443         project_length = 0; /* reset to default */
3444
3445         /* Don't shoot at my feet */
3446         if (tx == px && ty == py)
3447         {
3448                 energy_use = 0;
3449
3450                 /* project_length is already reset to 0 */
3451
3452                 return;
3453         }
3454
3455
3456         /* Get local object */
3457         q_ptr = &forge;
3458
3459         /* Obtain a local object */
3460         object_copy(q_ptr, o_ptr);
3461
3462         /* Single object */
3463         q_ptr->number = 1;
3464
3465         /* Reduce and describe inventory */
3466         if (item >= 0)
3467         {
3468                 inven_item_increase(item, -1);
3469                 inven_item_describe(item);
3470                 inven_item_optimize(item);
3471         }
3472
3473         /* Reduce and describe floor item */
3474         else
3475         {
3476                 floor_item_increase(0 - item, -1);
3477                 floor_item_optimize(0 - item);
3478         }
3479
3480
3481         /* Sound */
3482         sound(SOUND_SHOOT);
3483
3484
3485         /* Take a (partial) turn */
3486         energy_use = (energy_use / thits);
3487
3488
3489         /* Hack -- Handle stuff */
3490         handle_stuff();
3491
3492         /* Save the old location */
3493         prev_y = y;
3494         prev_x = x;
3495
3496         /* Travel until stopped */
3497         for (cur_dis = 0; cur_dis <= tdis; )
3498         {
3499                 /* Hack -- Stop at the target */
3500                 if ((y == ty) && (x == tx)) break;
3501
3502                 /* Calculate the new location (see "project()") */
3503                 ny = y;
3504                 nx = x;
3505                 mmove2(&ny, &nx, py, px, ty, tx);
3506
3507                 /* Stopped by walls/doors */
3508                 if (!cave_have_flag_bold(ny, nx, FF_PROJECT) && !cave[ny][nx].m_idx) break;
3509
3510                 /* Advance the distance */
3511                 cur_dis++;
3512
3513
3514                 /* The player can see the (on screen) missile */
3515                 if (panel_contains(ny, nx) && player_can_see_bold(ny, nx))
3516                 {
3517                         char c = object_char(q_ptr);
3518                         byte a = object_attr(q_ptr);
3519
3520                         /* Draw, Hilite, Fresh, Pause, Erase */
3521                         print_rel(c, a, ny, nx);
3522                         move_cursor_relative(ny, nx);
3523                         Term_fresh();
3524                         Term_xtra(TERM_XTRA_DELAY, msec);
3525                         lite_spot(ny, nx);
3526                         Term_fresh();
3527                 }
3528
3529                 /* The player cannot see the missile */
3530                 else
3531                 {
3532                         /* Pause anyway, for consistancy */
3533                         Term_xtra(TERM_XTRA_DELAY, msec);
3534                 }
3535
3536                 /* Save the old location */
3537                 prev_y = y;
3538                 prev_x = x;
3539
3540                 /* Save the new location */
3541                 x = nx;
3542                 y = ny;
3543
3544
3545                 /* Monster here, Try to hit it */
3546                 if (cave[y][x].m_idx)
3547                 {
3548                         cave_type *c_ptr = &cave[y][x];
3549
3550                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
3551                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
3552
3553                         /* Check the visibility */
3554                         visible = m_ptr->ml;
3555
3556                         /* Note the collision */
3557                         hit_body = TRUE;
3558
3559                         if (m_ptr->csleep)
3560                         {
3561                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_COMPASSION, -1);
3562                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_HONOUR, -1);
3563                         }
3564
3565                         if ((r_ptr->level + 10) > p_ptr->lev)
3566                         {
3567                                 int now_exp = p_ptr->weapon_exp[0][j_ptr->sval];
3568                                 if (now_exp < s_info[p_ptr->pclass].w_max[0][j_ptr->sval])
3569                                 {
3570                                         int amount = 0;
3571                                         if (now_exp < WEAPON_EXP_BEGINNER) amount = 80;
3572                                         else if (now_exp < WEAPON_EXP_SKILLED) amount = 25;
3573                                         else if ((now_exp < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19)) amount = 10;
3574                                         else if (p_ptr->lev > 34) amount = 2;
3575                                         p_ptr->weapon_exp[0][j_ptr->sval] += amount;
3576                                         p_ptr->update |= (PU_BONUS);
3577                                 }
3578                         }
3579
3580                         if (p_ptr->riding)
3581                         {
3582                                 if ((p_ptr->skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING])
3583                                         && ((p_ptr->skill_exp[GINOU_RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 < r_info[m_list[p_ptr->riding].r_idx].level)
3584                                         && one_in_(2))
3585                                 {
3586                                         p_ptr->skill_exp[GINOU_RIDING] += 1;
3587                                         p_ptr->update |= (PU_BONUS);
3588                                 }
3589                         }
3590
3591                         /* Did we hit it (penalize range) */
3592                         if (test_hit_fire(chance - cur_dis, r_ptr->ac, m_ptr->ml))
3593                         {
3594                                 bool fear = FALSE;
3595
3596                                 /* Handle unseen monster */
3597                                 if (!visible)
3598                                 {
3599                                         /* Invisible monster */
3600 #ifdef JP
3601                                         msg_format("%s¤¬Å¨¤òÊ᪤·¤¿¡£", o_name);
3602 #else
3603                                         msg_format("The %s finds a mark.", o_name);
3604 #endif
3605
3606                                 }
3607
3608                                 /* Handle visible monster */
3609                                 else
3610                                 {
3611                                         char m_name[80];
3612
3613                                         /* Get "the monster" or "it" */
3614                                         monster_desc(m_name, m_ptr, 0);
3615
3616                                         /* Message */
3617 #ifdef JP
3618                                         msg_format("%s¤¬%s¤ËÌ¿Ã椷¤¿¡£", o_name, m_name);
3619 #else
3620                                         msg_format("The %s hits %s.", o_name, m_name);
3621 #endif
3622
3623
3624                                         /* Hack -- Track this monster race */
3625                                         if (m_ptr->ml) monster_race_track(m_ptr->ap_r_idx);
3626
3627                                         /* Hack -- Track this monster */
3628                                         if (m_ptr->ml) health_track(c_ptr->m_idx);
3629                                 }
3630
3631                                 /* Apply special damage XXX XXX XXX */
3632                                 tdam = tot_dam_aux_shot(q_ptr, tdam, m_ptr);
3633                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, tdam);
3634
3635                                 /* No negative damage */
3636                                 if (tdam < 0) tdam = 0;
3637
3638                                 /* Modify the damage */
3639                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
3640
3641                                 /* Complex message */
3642                                 if (p_ptr->wizard || cheat_xtra)
3643                                 {
3644 #ifdef JP
3645                                         msg_format("%d/%d ¤Î¥À¥á¡¼¥¸¤òÍ¿¤¨¤¿¡£",
3646                                                    tdam, m_ptr->hp);
3647 #else
3648                                         msg_format("You do %d (out of %d) damage.",
3649                                                    tdam, m_ptr->hp);
3650 #endif
3651
3652                                 }
3653
3654                                 /* Hit the monster, check for death */
3655                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
3656                                 {
3657                                         /* Dead monster */
3658                                 }
3659
3660                                 /* No death */
3661                                 else
3662                                 {
3663                                         /* STICK TO */
3664                                         if (object_is_fixed_artifact(q_ptr))
3665                                         {
3666                                                 char m_name[80];
3667
3668                                                 monster_desc(m_name, m_ptr, 0);
3669
3670                                                 stick_to = TRUE;
3671 #ifdef JP
3672                                                 msg_format("%s¤Ï%s¤ËÆͤ­»É¤µ¤Ã¤¿¡ª",o_name, m_name);
3673 #else
3674                                                 msg_format("%^s have stuck into %s!",o_name, m_name);
3675 #endif
3676                                         }
3677
3678                                         /* Message */
3679                                         message_pain(c_ptr->m_idx, tdam);
3680
3681                                         /* Anger the monster */
3682                                         if (tdam > 0) anger_monster(m_ptr);
3683
3684                                         /* Take note */
3685                                         if (fear && m_ptr->ml)
3686                                         {
3687                                                 char m_name[80];
3688
3689                                                 /* Sound */
3690                                                 sound(SOUND_FLEE);
3691
3692                                                 /* Get the monster name (or "it") */
3693                                                 monster_desc(m_name, m_ptr, 0);
3694
3695                                                 /* Message */
3696 #ifdef JP
3697                                                 msg_format("%^s¤Ï¶²Éݤ·¤Æƨ¤²½Ð¤·¤¿¡ª", m_name);
3698 #else
3699                                                 msg_format("%^s flees in terror!", m_name);
3700 #endif
3701
3702                                         }
3703                                         if (!projectable(m_ptr->fy, m_ptr->fx, py, px))
3704                                         {
3705                                                 set_target(m_ptr, py, px);
3706                                         }
3707                                 }
3708                         }
3709
3710                         /* Stop looking */
3711                         break;
3712                 }
3713         }
3714
3715         /* Chance of breakage (during attacks) */
3716         j = (hit_body ? breakage_chance(q_ptr) : 0);
3717
3718         if (stick_to)
3719         {
3720                 int m_idx = cave[y][x].m_idx;
3721                 monster_type *m_ptr = &m_list[m_idx];
3722                 int o_idx = o_pop();
3723
3724                 if (!o_idx)
3725                 {
3726 #ifdef JP
3727                         msg_format("%s¤Ï¤É¤³¤«¤Ø¹Ô¤Ã¤¿¡£", o_name);
3728 #else
3729                         msg_format("The %s have gone to somewhere.", o_name);
3730 #endif
3731                         if (object_is_fixed_artifact(q_ptr))
3732                         {
3733                                 a_info[j_ptr->name1].cur_num = 0;
3734                         }
3735                         return;
3736                 }
3737
3738                 o_ptr = &o_list[o_idx];
3739                 object_copy(o_ptr, q_ptr);
3740
3741                 /* Forget mark */
3742                 o_ptr->marked = 0;
3743
3744                 /* Forget location */
3745                 o_ptr->iy = o_ptr->ix = 0;
3746
3747                 /* Memorize monster */
3748                 o_ptr->held_m_idx = m_idx;
3749
3750                 /* Build a stack */
3751                 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3752
3753                 /* Carry object */
3754                 m_ptr->hold_o_idx = o_idx;
3755         }
3756         else if (cave_have_flag_bold(y, x, FF_PROJECT))
3757         {
3758                 /* Drop (or break) near that location */
3759                 (void)drop_near(q_ptr, j, y, x);
3760         }
3761         else
3762         {
3763                 /* Drop (or break) near that location */
3764                 (void)drop_near(q_ptr, j, prev_y, prev_x);
3765         }
3766 }
3767
3768
3769 void do_cmd_fire(void)
3770 {
3771         int item;
3772         object_type *j_ptr;
3773         cptr q, s;
3774
3775         /* Get the "bow" (if any) */
3776         j_ptr = &inventory[INVEN_BOW];
3777
3778         /* Require a launcher */
3779         if (!j_ptr->tval)
3780         {
3781 #ifdef JP
3782                 msg_print("¼Í·âÍѤÎÉð´ï¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£");
3783 #else
3784                 msg_print("You have nothing to fire with.");
3785 #endif
3786                 flush();
3787                 return;
3788         }
3789
3790         if (j_ptr->sval == SV_CRIMSON)
3791         {
3792 #ifdef JP
3793                 msg_print("¤³¤ÎÉð´ï¤Ïȯư¤·¤Æ»È¤¦¤â¤Î¤Î¤è¤¦¤À¡£");
3794 #else
3795                 msg_print("Do activate.");
3796 #endif
3797                 flush();
3798                 return;
3799         }
3800
3801
3802         if (p_ptr->special_defense & KATA_MUSOU)
3803         {
3804                 set_action(ACTION_NONE);
3805         }
3806
3807         /* Require proper missile */
3808         item_tester_tval = p_ptr->tval_ammo;
3809
3810         /* Get an item */
3811 #ifdef JP
3812         q = "¤É¤ì¤ò·â¤Á¤Þ¤¹¤«? ";
3813         s = "ȯ¼Í¤µ¤ì¤ë¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
3814 #else
3815         q = "Fire which item? ";
3816         s = "You have nothing to fire.";
3817 #endif
3818
3819         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
3820         {
3821                 flush();
3822                 return;
3823         }
3824
3825         /* Fire the item */
3826         do_cmd_fire_aux(item, j_ptr);
3827 }
3828
3829
3830 static bool item_tester_hook_boomerang(object_type *o_ptr)
3831 {
3832         if ((o_ptr->tval==TV_DIGGING) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM) || (o_ptr->tval == TV_HAFTED)) return (TRUE);
3833
3834         /* Assume not */
3835         return (FALSE);
3836 }
3837
3838
3839 /*
3840  * Throw an object from the pack or floor.
3841  *
3842  * Note: "unseen" monsters are very hard to hit.
3843  *
3844  * Should throwing a weapon do full damage?  Should it allow the magic
3845  * to hit bonus of the weapon to have an effect?  Should it ever cause
3846  * the item to be destroyed?  Should it do any damage at all?
3847  */
3848 bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
3849 {
3850         int dir, item;
3851         int i, j, y, x, ty, tx, prev_y, prev_x;
3852         int ny[19], nx[19];
3853         int chance, tdam, tdis;
3854         int mul, div;
3855         int cur_dis, visible;
3856
3857         object_type forge;
3858         object_type *q_ptr;
3859
3860         object_type *o_ptr;
3861
3862         bool hit_body = FALSE;
3863         bool hit_wall = FALSE;
3864         bool equiped_item = FALSE;
3865         bool return_when_thrown = FALSE;
3866
3867         char o_name[MAX_NLEN];
3868
3869         int msec = delay_factor * delay_factor * delay_factor;
3870
3871         u32b flgs[TR_FLAG_SIZE];
3872         cptr q, s;
3873         bool come_back = FALSE;
3874         bool do_drop = TRUE;
3875
3876
3877         if (p_ptr->special_defense & KATA_MUSOU)
3878         {
3879                 set_action(ACTION_NONE);
3880         }
3881
3882         if (shuriken)
3883         {
3884                 item = shuriken;
3885         }
3886         else if (boomerang)
3887         {
3888                 if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
3889                 {
3890                         item_tester_hook = item_tester_hook_boomerang;
3891 #ifdef JP
3892                         q = "¤É¤ÎÉð´ï¤òÅꤲ¤Þ¤¹¤«? ";
3893                         s = "Åꤲ¤ëÉð´ï¤¬¤Ê¤¤¡£";
3894 #else
3895                         q = "Throw which item? ";
3896                         s = "You have nothing to throw.";
3897 #endif
3898
3899                         if (!get_item(&item, q, s, (USE_EQUIP)))
3900                         {
3901                                 flush();
3902                                 return FALSE;
3903                         }
3904                 }
3905                 else if (buki_motteruka(INVEN_LARM)) item = INVEN_LARM;
3906                 else item = INVEN_RARM;
3907         }
3908         else
3909         {
3910                 /* Get an item */
3911 #ifdef JP
3912                 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅꤲ¤Þ¤¹¤«? ";
3913                 s = "Åꤲ¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
3914 #else
3915                 q = "Throw which item? ";
3916                 s = "You have nothing to throw.";
3917 #endif
3918
3919                 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP)))
3920                 {
3921                         flush();
3922                         return FALSE;
3923                 }
3924         }
3925
3926         /* Access the item (if in the pack) */
3927         if (item >= 0)
3928         {
3929                 o_ptr = &inventory[item];
3930         }
3931         else
3932         {
3933                 o_ptr = &o_list[0 - item];
3934         }
3935
3936
3937         /* Item is cursed */
3938         if (object_is_cursed(o_ptr) && (item >= INVEN_RARM))
3939         {
3940                 /* Oops */
3941 #ifdef JP
3942                 msg_print("¤Õ¡¼¤à¡¢¤É¤¦¤ä¤é¼ö¤ï¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£");
3943 #else
3944                 msg_print("Hmmm, it seems to be cursed.");
3945 #endif
3946
3947                 /* Nope */
3948                 return FALSE;
3949         }
3950
3951         if (p_ptr->inside_arena && !boomerang)
3952         {
3953                 if (o_ptr->tval != TV_SPIKE)
3954                 {
3955 #ifdef JP
3956                         msg_print("¥¢¥ê¡¼¥Ê¤Ç¤Ï¥¢¥¤¥Æ¥à¤ò»È¤¨¤Ê¤¤¡ª");
3957 #else
3958                         msg_print("You're in the arena now. This is hand-to-hand!");
3959 #endif
3960                         msg_print(NULL);
3961
3962                         /* Nope */
3963                         return FALSE;
3964                 }
3965         }
3966
3967         /* Get local object */
3968         q_ptr = &forge;
3969
3970         /* Obtain a local object */
3971         object_copy(q_ptr, o_ptr);
3972
3973         /* Extract the thrown object's flags. */
3974         object_flags(q_ptr, flgs);
3975
3976         /* Distribute the charges of rods/wands between the stacks */
3977         distribute_charges(o_ptr, q_ptr, 1);
3978
3979         /* Single object */
3980         q_ptr->number = 1;
3981
3982         /* Description */
3983         object_desc(o_name, q_ptr, OD_OMIT_PREFIX);
3984
3985         if (p_ptr->mighty_throw) mult += 3;
3986
3987         /* Extract a "distance multiplier" */
3988         /* Changed for 'launcher' mutation */
3989         mul = 10 + 2 * (mult - 1);
3990
3991         /* Enforce a minimum "weight" of one pound */
3992         div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
3993         if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
3994
3995         /* Hack -- Distance -- Reward strength, penalize weight */
3996         tdis = (adj_str_blow[p_ptr->stat_ind[A_STR]] + 20) * mul / div;
3997
3998         /* Max distance of 10-18 */
3999         if (tdis > mul) tdis = mul;
4000
4001         if (shuriken)
4002         {
4003                 ty = randint0(101)-50+py;
4004                 tx = randint0(101)-50+px;
4005         }
4006         else
4007         {
4008                 project_length = tdis + 1;
4009
4010                 /* Get a direction (or cancel) */
4011                 if (!get_aim_dir(&dir)) return FALSE;
4012
4013                 /* Predict the "target" location */
4014                 tx = px + 99 * ddx[dir];
4015                 ty = py + 99 * ddy[dir];
4016
4017                 /* Check for "target request" */
4018                 if ((dir == 5) && target_okay())
4019                 {
4020                         tx = target_col;
4021                         ty = target_row;
4022                 }
4023
4024                 project_length = 0;  /* reset to default */
4025         }
4026
4027         if ((q_ptr->name1 == ART_MJOLLNIR) ||
4028             (q_ptr->name1 == ART_AEGISFANG) || boomerang)
4029                 return_when_thrown = TRUE;
4030
4031         /* Reduce and describe inventory */
4032         if (item >= 0)
4033         {
4034                 inven_item_increase(item, -1);
4035                 if (!return_when_thrown)
4036                         inven_item_describe(item);
4037                 inven_item_optimize(item);
4038         }
4039
4040         /* Reduce and describe floor item */
4041         else
4042         {
4043                 floor_item_increase(0 - item, -1);
4044                 floor_item_optimize(0 - item);
4045         }
4046         if (item >= INVEN_RARM)
4047         {
4048                 equiped_item = TRUE;
4049                 p_ptr->redraw |= (PR_EQUIPPY);
4050         }
4051
4052         /* Take a turn */
4053         energy_use = 100;
4054
4055         /* Rogue and Ninja gets bonus */
4056         if ((p_ptr->pclass == CLASS_ROGUE) || (p_ptr->pclass == CLASS_NINJA))
4057                 energy_use -= p_ptr->lev;
4058
4059         /* Start at the player */
4060         y = py;
4061         x = px;
4062
4063
4064         /* Hack -- Handle stuff */
4065         handle_stuff();
4066
4067         if ((p_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
4068         else shuriken = FALSE;
4069
4070         /* Chance of hitting */
4071         if (have_flag(flgs, TR_THROW)) chance = ((p_ptr->skill_tht) +
4072                 ((p_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
4073         else chance = (p_ptr->skill_tht + (p_ptr->to_h_b * BTH_PLUS_ADJ));
4074
4075         if (shuriken) chance *= 2;
4076
4077         /* Save the old location */
4078         prev_y = y;
4079         prev_x = x;
4080
4081         /* Travel until stopped */
4082         for (cur_dis = 0; cur_dis <= tdis; )
4083         {
4084                 /* Hack -- Stop at the target */
4085                 if ((y == ty) && (x == tx)) break;
4086
4087                 /* Calculate the new location (see "project()") */
4088                 ny[cur_dis] = y;
4089                 nx[cur_dis] = x;
4090                 mmove2(&ny[cur_dis], &nx[cur_dis], py, px, ty, tx);
4091
4092                 /* Stopped by walls/doors */
4093                 if (!cave_have_flag_bold(ny[cur_dis], nx[cur_dis], FF_PROJECT))
4094                 {
4095                         hit_wall = TRUE;
4096                         if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !cave[ny[cur_dis]][nx[cur_dis]].m_idx) break;
4097                 }
4098
4099                 /* The player can see the (on screen) missile */
4100                 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(ny[cur_dis], nx[cur_dis]))
4101                 {
4102                         char c = object_char(q_ptr);
4103                         byte a = object_attr(q_ptr);
4104
4105                         /* Draw, Hilite, Fresh, Pause, Erase */
4106                         print_rel(c, a, ny[cur_dis], nx[cur_dis]);
4107                         move_cursor_relative(ny[cur_dis], nx[cur_dis]);
4108                         Term_fresh();
4109                         Term_xtra(TERM_XTRA_DELAY, msec);
4110                         lite_spot(ny[cur_dis], nx[cur_dis]);
4111                         Term_fresh();
4112                 }
4113
4114                 /* The player cannot see the missile */
4115                 else
4116                 {
4117                         /* Pause anyway, for consistancy */
4118                         Term_xtra(TERM_XTRA_DELAY, msec);
4119                 }
4120
4121                 /* Save the old location */
4122                 prev_y = y;
4123                 prev_x = x;
4124
4125                 /* Save the new location */
4126                 x = nx[cur_dis];
4127                 y = ny[cur_dis];
4128
4129                 /* Advance the distance */
4130                 cur_dis++;
4131
4132                 /* Monster here, Try to hit it */
4133                 if (cave[y][x].m_idx)
4134                 {
4135                         cave_type *c_ptr = &cave[y][x];
4136
4137                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
4138                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4139
4140                         /* Check the visibility */
4141                         visible = m_ptr->ml;
4142
4143                         /* Note the collision */
4144                         hit_body = TRUE;
4145
4146                         /* Did we hit it (penalize range) */
4147                         if (test_hit_fire(chance - cur_dis, r_ptr->ac, m_ptr->ml))
4148                         {
4149                                 bool fear = FALSE;
4150
4151                                 /* Handle unseen monster */
4152                                 if (!visible)
4153                                 {
4154                                         /* Invisible monster */
4155 #ifdef JP
4156                                         msg_format("%s¤¬Å¨¤òÊ᪤·¤¿¡£", o_name);
4157 #else
4158                                         msg_format("The %s finds a mark.", o_name);
4159 #endif
4160
4161                                 }
4162
4163                                 /* Handle visible monster */
4164                                 else
4165                                 {
4166                                         char m_name[80];
4167
4168                                         /* Get "the monster" or "it" */
4169                                         monster_desc(m_name, m_ptr, 0);
4170
4171                                         /* Message */
4172 #ifdef JP
4173                                         msg_format("%s¤¬%s¤ËÌ¿Ã椷¤¿¡£", o_name, m_name);
4174 #else
4175                                         msg_format("The %s hits %s.", o_name, m_name);
4176 #endif
4177
4178
4179                                         /* Hack -- Track this monster race */
4180                                         if (m_ptr->ml) monster_race_track(m_ptr->ap_r_idx);
4181
4182                                         /* Hack -- Track this monster */
4183                                         if (m_ptr->ml) health_track(c_ptr->m_idx);
4184                                 }
4185
4186                                 /* Hack -- Base damage from thrown object */
4187                                 tdam = damroll(q_ptr->dd, q_ptr->ds);
4188                                 /* Apply special damage XXX XXX XXX */
4189                                 tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0, TRUE);
4190                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, tdam);
4191                                 if (q_ptr->to_d > 0)
4192                                         tdam += q_ptr->to_d;
4193                                 else
4194                                         tdam += -q_ptr->to_d;
4195
4196                                 if (boomerang)
4197                                 {
4198                                         tdam *= (mult+p_ptr->num_blow[item - INVEN_RARM]);
4199                                         tdam += p_ptr->to_d_m;
4200                                 }
4201                                 else if (have_flag(flgs, TR_THROW))
4202                                 {
4203                                         tdam *= (3+mult);
4204                                         tdam += p_ptr->to_d_m;
4205                                 }
4206                                 else
4207                                 {
4208                                         tdam *= mult;
4209                                 }
4210                                 if (shuriken)
4211                                 {
4212                                         tdam += ((p_ptr->lev+30)*(p_ptr->lev+30)-900)/55;
4213                                 }
4214
4215                                 /* No negative damage */
4216                                 if (tdam < 0) tdam = 0;
4217
4218                                 /* Modify the damage */
4219                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
4220
4221                                 /* Complex message */
4222                                 if (p_ptr->wizard)
4223                                 {
4224 #ifdef JP
4225                                         msg_format("%d/%d¤Î¥À¥á¡¼¥¸¤òÍ¿¤¨¤¿¡£",
4226                                                    tdam, m_ptr->hp);
4227 #else
4228                                         msg_format("You do %d (out of %d) damage.",
4229                                                    tdam, m_ptr->hp);
4230 #endif
4231
4232                                 }
4233
4234                                 /* Hit the monster, check for death */
4235                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
4236                                 {
4237                                         /* Dead monster */
4238                                 }
4239
4240                                 /* No death */
4241                                 else
4242                                 {
4243                                         /* Message */
4244                                         message_pain(c_ptr->m_idx, tdam);
4245
4246                                         /* Anger the monster */
4247                                         if ((tdam > 0) && !object_is_potion(q_ptr))
4248                                                 anger_monster(m_ptr);
4249
4250                                         /* Take note */
4251                                         if (fear && m_ptr->ml)
4252                                         {
4253                                                 char m_name[80];
4254
4255                                                 /* Sound */
4256                                                 sound(SOUND_FLEE);
4257
4258                                                 /* Get the monster name (or "it") */
4259                                                 monster_desc(m_name, m_ptr, 0);
4260
4261                                                 /* Message */
4262 #ifdef JP
4263                                                 msg_format("%^s¤Ï¶²Éݤ·¤Æƨ¤²½Ð¤·¤¿¡ª", m_name);
4264 #else
4265                                                 msg_format("%^s flees in terror!", m_name);
4266 #endif
4267
4268                                         }
4269                                 }
4270                         }
4271
4272                         /* Stop looking */
4273                         break;
4274                 }
4275         }
4276
4277         /* Chance of breakage (during attacks) */
4278         j = (hit_body ? breakage_chance(q_ptr) : 0);
4279
4280         /* Figurines transform */
4281         if ((q_ptr->tval == TV_FIGURINE) && !(p_ptr->inside_arena))
4282         {
4283                 j = 100;
4284
4285                 if (!(summon_named_creature(0, y, x, q_ptr->pval,
4286                                             !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
4287 #ifdef JP
4288 msg_print("¿Í·Á¤ÏDZ¤¸¶Ê¤¬¤êºÕ¤±»¶¤Ã¤Æ¤·¤Þ¤Ã¤¿¡ª");
4289 #else
4290                         msg_print("The Figurine writhes and then shatters.");
4291 #endif
4292
4293                 else if (object_is_cursed(q_ptr))
4294 #ifdef JP
4295 msg_print("¤³¤ì¤Ï¤¢¤Þ¤êÎɤ¯¤Ê¤¤µ¤¤¬¤¹¤ë¡£");
4296 #else
4297                         msg_print("You have a bad feeling about this.");
4298 #endif
4299
4300         }
4301
4302
4303         /* Potions smash open */
4304         if (object_is_potion(q_ptr))
4305         {
4306                 if (hit_body || hit_wall || (randint1(100) < j))
4307                 {
4308                         /* Message */
4309 #ifdef JP
4310                         msg_format("%s¤ÏºÕ¤±»¶¤Ã¤¿¡ª", o_name);
4311 #else
4312                         msg_format("The %s shatters!", o_name);
4313 #endif
4314
4315
4316                         if (potion_smash_effect(0, y, x, q_ptr->k_idx))
4317                         {
4318                                 monster_type *m_ptr = &m_list[cave[y][x].m_idx];
4319
4320                                 /* ToDo (Robert): fix the invulnerability */
4321                                 if (cave[y][x].m_idx &&
4322                                     is_friendly(&m_list[cave[y][x].m_idx]) &&
4323                                     !(m_ptr->invulner))
4324                                 {
4325                                         char m_name[80];
4326                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
4327 #ifdef JP
4328                                         msg_format("%s¤ÏÅܤä¿¡ª", m_name);
4329 #else
4330                                         msg_format("%^s gets angry!", m_name);
4331 #endif
4332
4333                                         set_hostile(&m_list[cave[y][x].m_idx]);
4334                                 }
4335                         }
4336                         do_drop = FALSE;
4337                 }
4338                 else
4339                 {
4340                         j = 0;
4341                 }
4342         }
4343
4344         if (return_when_thrown)
4345         {
4346                 int back_chance = randint1(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4347                 char o2_name[MAX_NLEN];
4348                 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
4349
4350                 j = -1;
4351                 if (boomerang) back_chance += 4+randint1(5);
4352                 if (super_boomerang) back_chance += 100;
4353                 object_desc(o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4354
4355                 if((back_chance > 30) && (!one_in_(100) || super_boomerang))
4356                 {
4357                         for (i = cur_dis - 1; i > 0; i--)
4358                         {
4359                                 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(ny[i], nx[i]))
4360                                 {
4361                                         char c = object_char(q_ptr);
4362                                         byte a = object_attr(q_ptr);
4363
4364                                         /* Draw, Hilite, Fresh, Pause, Erase */
4365                                         print_rel(c, a, ny[i], nx[i]);
4366                                         move_cursor_relative(ny[i], nx[i]);
4367                                         Term_fresh();
4368                                         Term_xtra(TERM_XTRA_DELAY, msec);
4369                                         lite_spot(ny[i], nx[i]);
4370                                         Term_fresh();
4371                                 }
4372                                 else
4373                                 {
4374                                         /* Pause anyway, for consistancy */
4375                                         Term_xtra(TERM_XTRA_DELAY, msec);
4376                                 }
4377                         }
4378                         if((back_chance > 37) && !p_ptr->blind && (item >= 0))
4379                         {
4380 #ifdef JP
4381                                 msg_format("%s¤¬¼ê¸µ¤ËÊ֤äƤ­¤¿¡£", o2_name);
4382 #else
4383                                 msg_format("%s comes back to you.", o2_name);
4384 #endif
4385                                 come_back = TRUE;
4386                         }
4387                         else
4388                         {
4389                                 if (item >= 0)
4390                                 {
4391 #ifdef JP
4392                                         msg_format("%s¤ò¼õ¤±Â»¤Í¤¿¡ª", o2_name);
4393 #else
4394                                         msg_format("%s backs, but you can't catch!", o2_name);
4395 #endif
4396                                 }
4397                                 else
4398                                 {
4399 #ifdef JP
4400                                         msg_format("%s¤¬Ê֤äƤ­¤¿¡£", o2_name);
4401 #else
4402                                         msg_format("%s comes back.", o2_name);
4403 #endif
4404                                 }
4405                                 y = py;
4406                                 x = px;
4407                         }
4408                 }
4409                 else
4410                 {
4411 #ifdef JP
4412                         msg_format("%s¤¬Ê֤äƤ³¤Ê¤«¤Ã¤¿¡ª", o2_name);
4413 #else
4414                         msg_format("%s doesn't back!", o2_name);
4415 #endif
4416                 }
4417         }
4418
4419         if (come_back)
4420         {
4421                 if (item == INVEN_RARM || item == INVEN_LARM)
4422                 {
4423                         /* Access the wield slot */
4424                         o_ptr = &inventory[item];
4425
4426                         /* Wear the new stuff */
4427                         object_copy(o_ptr, q_ptr);
4428
4429                         /* Increase the weight */
4430                         p_ptr->total_weight += q_ptr->weight;
4431
4432                         /* Increment the equip counter by hand */
4433                         equip_cnt++;
4434
4435                         /* Recalculate bonuses */
4436                         p_ptr->update |= (PU_BONUS);
4437
4438                         /* Recalculate torch */
4439                         p_ptr->update |= (PU_TORCH);
4440
4441                         /* Recalculate mana XXX */
4442                         p_ptr->update |= (PU_MANA);
4443
4444                         /* Window stuff */
4445                         p_ptr->window |= (PW_EQUIP);
4446                 }
4447                 else
4448                 {
4449                         inven_carry(q_ptr);
4450                 }
4451                 do_drop = FALSE;
4452         }
4453         else if (equiped_item)
4454         {
4455                 kamaenaoshi(item);
4456                 calc_android_exp();
4457         }
4458
4459         /* Drop (or break) near that location */
4460         if (do_drop)
4461         {
4462                 if (cave_have_flag_bold(y, x, FF_PROJECT))
4463                 {
4464                         /* Drop (or break) near that location */
4465                         (void)drop_near(q_ptr, j, y, x);
4466                 }
4467                 else
4468                 {
4469                         /* Drop (or break) near that location */
4470                         (void)drop_near(q_ptr, j, prev_y, prev_x);
4471                 }
4472         }
4473
4474         return TRUE;
4475 }
4476
4477
4478 /*
4479  * Throw an object from the pack or floor.
4480  */
4481 void do_cmd_throw(void)
4482 {
4483         do_cmd_throw_aux(1, FALSE, 0);
4484 }