OSDN Git Service

閉じることのできる地形の上にアイテムがあって, 閉じた後の地形にDROPが
[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                         /* Update some things */
1128                         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MONSTERS | PU_MON_LITE);
1129
1130                         /* Sound */
1131                         sound(SOUND_OPENDOOR);
1132
1133                         /* Experience */
1134                         gain_exp(1);
1135                 }
1136
1137                 /* Failure */
1138                 else
1139                 {
1140                         /* Failure */
1141                         if (flush_failure) flush();
1142
1143                         /* Message */
1144 #ifdef JP
1145                         msg_print("¸°¤ò¤Ï¤º¤»¤Ê¤«¤Ã¤¿¡£");
1146 #else
1147                         msg_print("You failed to pick the lock.");
1148 #endif
1149
1150
1151                         /* We may keep trying */
1152                         more = TRUE;
1153                 }
1154         }
1155
1156         /* Closed door */
1157         else
1158         {
1159                 /* Open the door */
1160                 cave_alter_feat(y, x, FF_OPEN);
1161
1162                 /* Update some things */
1163                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MONSTERS | PU_MON_LITE);
1164
1165                 /* Sound */
1166                 sound(SOUND_OPENDOOR);
1167         }
1168
1169         /* Result */
1170         return (more);
1171 }
1172
1173
1174
1175 /*
1176  * Open a closed/locked/jammed door or a closed/locked chest.
1177  *
1178  * Unlocking a locked door/chest is worth one experience point.
1179  */
1180 void do_cmd_open(void)
1181 {
1182         int y, x, dir;
1183
1184         s16b o_idx;
1185
1186         bool more = FALSE;
1187
1188         if (p_ptr->special_defense & KATA_MUSOU)
1189         {
1190                 set_action(ACTION_NONE);
1191         }
1192
1193 #ifdef ALLOW_EASY_OPEN /* TNB */
1194
1195         /* Option: Pick a direction */
1196         if (easy_open)
1197         {
1198                 int num_doors, num_chests;
1199
1200                 /* Count closed doors (locked or jammed) */
1201                 num_doors = count_dt(&y, &x, is_closed_door, FALSE);
1202
1203                 /* Count chests (locked) */
1204                 num_chests = count_chests(&y, &x, FALSE);
1205
1206                 /* See if only one target */
1207                 if (num_doors || num_chests)
1208                 {
1209                         bool too_many = (num_doors && num_chests) || (num_doors > 1) ||
1210                             (num_chests > 1);
1211                         if (!too_many) command_dir = coords_to_dir(y, x);
1212                 }
1213         }
1214
1215 #endif /* ALLOW_EASY_OPEN -- TNB */
1216
1217         /* Allow repeated command */
1218         if (command_arg)
1219         {
1220                 /* Set repeat count */
1221                 command_rep = command_arg - 1;
1222
1223                 /* Redraw the state */
1224                 p_ptr->redraw |= (PR_STATE);
1225
1226                 /* Cancel the arg */
1227                 command_arg = 0;
1228         }
1229
1230         /* Get a "repeated" direction */
1231         if (get_rep_dir(&dir, TRUE))
1232         {
1233                 s16b feat;
1234                 cave_type *c_ptr;
1235
1236                 /* Get requested location */
1237                 y = py + ddy[dir];
1238                 x = px + ddx[dir];
1239
1240                 /* Get requested grid */
1241                 c_ptr = &cave[y][x];
1242
1243                 /* Feature code (applying "mimic" field) */
1244                 feat = get_feat_mimic(c_ptr);
1245
1246                 /* Check for chest */
1247                 o_idx = chest_check(y, x);
1248
1249                 /* Nothing useful */
1250                 if (!have_flag(f_info[feat].flags, FF_OPEN) && !o_idx)
1251                 {
1252                         /* Message */
1253 #ifdef JP
1254                 msg_print("¤½¤³¤Ë¤Ï³«¤±¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
1255 #else
1256                         msg_print("You see nothing there to open.");
1257 #endif
1258
1259                 }
1260
1261                 /* Monster in the way */
1262                 else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
1263                 {
1264                         /* Take a turn */
1265                         energy_use = 100;
1266
1267                         /* Message */
1268 #ifdef JP
1269                 msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
1270 #else
1271                         msg_print("There is a monster in the way!");
1272 #endif
1273
1274
1275                         /* Attack */
1276                         py_attack(y, x, 0);
1277                 }
1278
1279                 /* Handle chests */
1280                 else if (o_idx)
1281                 {
1282                         /* Open the chest */
1283                         more = do_cmd_open_chest(y, x, o_idx);
1284                 }
1285
1286                 /* Handle doors */
1287                 else
1288                 {
1289                         /* Open the door */
1290                         more = do_cmd_open_aux(y, x);
1291                 }
1292         }
1293
1294         /* Cancel repeat unless we may continue */
1295         if (!more) disturb(0, 0);
1296 }
1297
1298
1299
1300 /*
1301  * Perform the basic "close" command
1302  *
1303  * Assume destination is an open/broken door
1304  *
1305  * Assume there is no monster blocking the destination
1306  *
1307  * Returns TRUE if repeated commands may continue
1308  */
1309 static bool do_cmd_close_aux(int y, int x)
1310 {
1311         /* Get grid and contents */
1312         cave_type *c_ptr = &cave[y][x];
1313         s16b      old_feat = c_ptr->feat;
1314         bool      more = FALSE;
1315
1316         /* Take a turn */
1317         energy_use = 100;
1318
1319         /* Seeing true feature code (ignore mimic) */
1320
1321         /* Open door */
1322         if (have_flag(f_info[old_feat].flags, FF_CLOSE))
1323         {
1324                 s16b closed_feat = feat_state(old_feat, FF_CLOSE);
1325
1326                 /* Hack -- object in the way */
1327                 if ((c_ptr->o_idx || (c_ptr->info & CAVE_OBJECT)) &&
1328                     (closed_feat != old_feat) && !have_flag(f_info[closed_feat].flags, FF_DROP))
1329                 {
1330                         /* Message */
1331 #ifdef JP
1332                         msg_print("²¿¤«¤¬¤Ä¤Ã¤«¤¨¤ÆÊĤޤé¤Ê¤¤¡£");
1333 #else
1334                         msg_print("There seems stuck.");
1335 #endif
1336                 }
1337                 else
1338                 {
1339                         /* Close the door */
1340                         cave_alter_feat(y, x, FF_CLOSE);
1341
1342                         /* Broken door */
1343                         if (old_feat == c_ptr->feat)
1344                         {
1345                                 /* Message */
1346 #ifdef JP
1347                                 msg_print("¥É¥¢¤Ï²õ¤ì¤Æ¤·¤Þ¤Ã¤Æ¤¤¤ë¡£");
1348 #else
1349                                 msg_print("The door appears to be broken.");
1350 #endif
1351                         }
1352                         else
1353                         {
1354                                 /* Update some things */
1355                                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MONSTERS | PU_MON_LITE);
1356
1357                                 /* Sound */
1358                                 sound(SOUND_SHUTDOOR);
1359                         }
1360                 }
1361         }
1362
1363         /* Result */
1364         return (more);
1365 }
1366
1367
1368 /*
1369  * Close an open door.
1370  */
1371 void do_cmd_close(void)
1372 {
1373         int y, x, dir;
1374
1375         bool more = FALSE;
1376
1377         if (p_ptr->special_defense & KATA_MUSOU)
1378         {
1379                 set_action(ACTION_NONE);
1380         }
1381
1382 #ifdef ALLOW_EASY_OPEN /* TNB */
1383
1384         /* Option: Pick a direction */
1385         if (easy_open)
1386         {
1387                 /* Count open doors */
1388                 if (count_dt(&y, &x, is_open, FALSE) == 1)
1389                 {
1390                         command_dir = coords_to_dir(y, x);
1391                 }
1392         }
1393
1394 #endif /* ALLOW_EASY_OPEN -- TNB */
1395
1396         /* Allow repeated command */
1397         if (command_arg)
1398         {
1399                 /* Set repeat count */
1400                 command_rep = command_arg - 1;
1401
1402                 /* Redraw the state */
1403                 p_ptr->redraw |= (PR_STATE);
1404
1405                 /* Cancel the arg */
1406                 command_arg = 0;
1407         }
1408
1409         /* Get a "repeated" direction */
1410         if (get_rep_dir(&dir,FALSE))
1411         {
1412                 cave_type *c_ptr;
1413                 s16b feat;
1414
1415                 /* Get requested location */
1416                 y = py + ddy[dir];
1417                 x = px + ddx[dir];
1418
1419                 /* Get grid and contents */
1420                 c_ptr = &cave[y][x];
1421
1422                 /* Feature code (applying "mimic" field) */
1423                 feat = get_feat_mimic(c_ptr);
1424
1425                 /* Require open/broken door */
1426                 if (!have_flag(f_info[feat].flags, FF_CLOSE))
1427                 {
1428                         /* Message */
1429 #ifdef JP
1430                         msg_print("¤½¤³¤Ë¤ÏÊĤ¸¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
1431 #else
1432                         msg_print("You see nothing there to close.");
1433 #endif
1434                 }
1435
1436                 /* Monster in the way */
1437                 else if (c_ptr->m_idx)
1438                 {
1439                         /* Take a turn */
1440                         energy_use = 100;
1441
1442                         /* Message */
1443 #ifdef JP
1444                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
1445 #else
1446                         msg_print("There is a monster in the way!");
1447 #endif
1448
1449                         /* Attack */
1450                         py_attack(y, x, 0);
1451                 }
1452
1453                 /* Close the door */
1454                 else
1455                 {
1456                         /* Close the door */
1457                         more = do_cmd_close_aux(y, x);
1458                 }
1459         }
1460
1461         /* Cancel repeat unless we may continue */
1462         if (!more) disturb(0, 0);
1463 }
1464
1465
1466 /*
1467  * Determine if a given grid may be "tunneled"
1468  */
1469 static bool do_cmd_tunnel_test(int y, int x)
1470 {
1471         cave_type *c_ptr = &cave[y][x];
1472
1473         /* Must have knowledge */
1474         if (!(c_ptr->info & CAVE_MARK))
1475         {
1476                 /* Message */
1477 #ifdef JP
1478                 msg_print("¤½¤³¤Ë¤Ï²¿¤â¸«Åö¤¿¤é¤Ê¤¤¡£");
1479 #else
1480                 msg_print("You see nothing there.");
1481 #endif
1482
1483                 /* Nope */
1484                 return (FALSE);
1485         }
1486
1487         /* Must be a wall/door/etc */
1488         if (!cave_have_flag_grid(c_ptr, FF_TUNNEL))
1489         {
1490                 /* Message */
1491 #ifdef JP
1492                 msg_print("¤½¤³¤Ë¤Ï·¡¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
1493 #else
1494                 msg_print("You see nothing there to tunnel.");
1495 #endif
1496
1497                 /* Nope */
1498                 return (FALSE);
1499         }
1500
1501         /* Okay */
1502         return (TRUE);
1503 }
1504
1505
1506 /*
1507  * Perform the basic "tunnel" command
1508  *
1509  * Assumes that no monster is blocking the destination
1510  *
1511  * Do not use twall anymore
1512  *
1513  * Returns TRUE if repeated commands may continue
1514  */
1515 static bool do_cmd_tunnel_aux(int y, int x)
1516 {
1517         cave_type *c_ptr;
1518         feature_type *f_ptr, *mimic_f_ptr;
1519         int power;
1520         cptr name;
1521         bool more = FALSE;
1522
1523         /* Verify legality */
1524         if (!do_cmd_tunnel_test(y, x)) return (FALSE);
1525
1526         /* Take a turn */
1527         energy_use = 100;
1528
1529         /* Get grid */
1530         c_ptr = &cave[y][x];
1531         f_ptr = &f_info[c_ptr->feat];
1532         power = f_ptr->power;
1533
1534         /* Feature code (applying "mimic" field) */
1535         mimic_f_ptr = &f_info[get_feat_mimic(c_ptr)];
1536
1537         name = f_name + mimic_f_ptr->name;
1538
1539         /* Sound */
1540         sound(SOUND_DIG);
1541
1542         if (have_flag(f_ptr->flags, FF_PERMANENT))
1543         {
1544                 /* Titanium */
1545                 if (have_flag(mimic_f_ptr->flags, FF_PERMANENT))
1546                 {
1547 #ifdef JP
1548                         msg_print("¤³¤Î´ä¤Ï¹Å¤¹¤®¤Æ·¡¤ì¤Ê¤¤¤è¤¦¤À¡£");
1549 #else
1550                         msg_print("This seems to be permanent rock.");
1551 #endif
1552                 }
1553
1554                 /* Map border (mimiccing Permanent wall) */
1555                 else
1556                 {
1557 #ifdef JP
1558                         msg_print("¤½¤³¤Ï·¡¤ì¤Ê¤¤!");
1559 #else
1560                         msg_print("You can't tunnel through that!");
1561 #endif
1562                 }
1563         }
1564
1565         /* Dig or tunnel */
1566         else if (have_flag(f_ptr->flags, FF_CAN_DIG))
1567         {
1568                 /* Dig */
1569                 if (p_ptr->skill_dig > randint0(20 * power))
1570                 {
1571                         /* Message */
1572 #ifdef JP
1573                         msg_format("%s¤ò¤¯¤º¤·¤¿¡£", name);
1574 #else
1575                         msg_format("You have removed the %s.", name);
1576 #endif
1577
1578                         /* Remove the feature */
1579                         cave_alter_feat(y, x, FF_TUNNEL);
1580
1581                         /* Update some things */
1582                         p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MONSTERS | PU_MON_LITE);
1583                 }
1584                 else
1585                 {
1586                         /* Message, keep digging */
1587 #ifdef JP
1588                         msg_format("%s¤ò¤¯¤º¤·¤Æ¤¤¤ë¡£", name);
1589 #else
1590                         msg_format("You dig into the %s.", name);
1591 #endif
1592
1593                         more = TRUE;
1594                 }
1595         }
1596
1597         else
1598         {
1599                 bool tree = have_flag(mimic_f_ptr->flags, FF_TREE);
1600
1601                 /* Tunnel */
1602                 if (p_ptr->skill_dig > power + randint0(40 * power))
1603                 {
1604 #ifdef JP
1605                         if (tree) msg_format("%s¤òÀÚ¤êʧ¤Ã¤¿¡£", name);
1606                         else msg_print("·ê¤ò·¡¤ê½ª¤¨¤¿¡£");
1607 #else
1608                         if (tree) msg_format("You have cleared away the %s.", name);
1609                         else msg_print("You have finished the tunnel.");
1610 #endif
1611
1612                         /* Remove the feature */
1613                         cave_alter_feat(y, x, FF_TUNNEL);
1614
1615                         /* Update some things */
1616                         p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MONSTERS | PU_MON_LITE);
1617
1618                         chg_virtue(V_DILIGENCE, 1);
1619                         chg_virtue(V_NATURE, -1);
1620                 }
1621
1622                 /* Keep trying */
1623                 else
1624                 {
1625                         if (tree)
1626                         {
1627                                 /* We may continue chopping */
1628 #ifdef JP
1629                                 msg_format("%s¤òÀڤäƤ¤¤ë¡£", name);
1630 #else
1631                                 msg_format("You chop away at the %s.", name);
1632 #endif
1633                                 /* Occasional Search XXX XXX */
1634                                 if (randint0(100) < 25) search();
1635                         }
1636                         else
1637                         {
1638                                 /* We may continue tunelling */
1639 #ifdef JP
1640                                 msg_format("%s¤Ë·ê¤ò·¡¤Ã¤Æ¤¤¤ë¡£", name);
1641 #else
1642                                 msg_format("You tunnel into the %s.", name);
1643 #endif
1644                         }
1645
1646                         more = TRUE;
1647                 }
1648         }
1649
1650         if (is_hidden_door(c_ptr))
1651         {
1652                 /* Occasional Search XXX XXX */
1653                 if (randint0(100) < 25) search();
1654         }
1655
1656         /* Result */
1657         return more;
1658 }
1659
1660
1661 /*
1662  * Tunnels through "walls" (including rubble and closed doors)
1663  *
1664  * Note that you must tunnel in order to hit invisible monsters
1665  * in walls, though moving into walls still takes a turn anyway.
1666  *
1667  * Digging is very difficult without a "digger" weapon, but can be
1668  * accomplished by strong players using heavy weapons.
1669  */
1670 void do_cmd_tunnel(void)
1671 {
1672         int                     y, x, dir;
1673
1674         cave_type       *c_ptr;
1675         s16b feat;
1676
1677         bool            more = FALSE;
1678
1679
1680         if (p_ptr->special_defense & KATA_MUSOU)
1681         {
1682                 set_action(ACTION_NONE);
1683         }
1684
1685         /* Allow repeated command */
1686         if (command_arg)
1687         {
1688                 /* Set repeat count */
1689                 command_rep = command_arg - 1;
1690
1691                 /* Redraw the state */
1692                 p_ptr->redraw |= (PR_STATE);
1693
1694                 /* Cancel the arg */
1695                 command_arg = 0;
1696         }
1697
1698         /* Get a direction to tunnel, or Abort */
1699         if (get_rep_dir(&dir,FALSE))
1700         {
1701                 /* Get location */
1702                 y = py + ddy[dir];
1703                 x = px + ddx[dir];
1704
1705                 /* Get grid */
1706                 c_ptr = &cave[y][x];
1707
1708                 /* Feature code (applying "mimic" field) */
1709                 feat = get_feat_mimic(c_ptr);
1710
1711                 /* No tunnelling through doors */
1712                 if (have_flag(f_info[feat].flags, FF_DOOR))
1713                 {
1714                         /* Message */
1715 #ifdef JP
1716                         msg_print("¥É¥¢¤Ï·¡¤ì¤Ê¤¤¡£");
1717 #else
1718                         msg_print("You cannot tunnel through doors.");
1719 #endif
1720                 }
1721
1722                 /* No tunnelling through most features */
1723                 else if (!have_flag(f_info[feat].flags, FF_TUNNEL))
1724                 {
1725 #ifdef JP
1726                         msg_print("¤½¤³¤Ï·¡¤ì¤Ê¤¤¡£");
1727 #else
1728                         msg_print("You can't tunnel through that.");
1729 #endif
1730                 }
1731
1732                 /* A monster is in the way */
1733                 else if (c_ptr->m_idx)
1734                 {
1735                         /* Take a turn */
1736                         energy_use = 100;
1737
1738                         /* Message */
1739 #ifdef JP
1740                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
1741 #else
1742                         msg_print("There is a monster in the way!");
1743 #endif
1744
1745                         /* Attack */
1746                         py_attack(y, x, 0);
1747                 }
1748
1749                 /* Try digging */
1750                 else
1751                 {
1752                         /* Tunnel through walls */
1753                         more = do_cmd_tunnel_aux(y, x);
1754                 }
1755         }
1756
1757         /* Cancel repetition unless we can continue */
1758         if (!more) disturb(0, 0);
1759 }
1760
1761
1762 #ifdef ALLOW_EASY_OPEN /* TNB */
1763
1764 /*
1765  * easy_open_door --
1766  *
1767  *      If there is a jammed/closed/locked door at the given location,
1768  *      then attempt to unlock/open it. Return TRUE if an attempt was
1769  *      made (successful or not), otherwise return FALSE.
1770  *
1771  *      The code here should be nearly identical to that in
1772  *      do_cmd_open_test() and do_cmd_open_aux().
1773  */
1774 bool easy_open_door(int y, int x)
1775 {
1776         int i, j;
1777
1778         cave_type *c_ptr = &cave[y][x];
1779         feature_type *f_ptr = &f_info[c_ptr->feat];
1780
1781         /* Must be a closed door */
1782         if (!is_closed_door(c_ptr->feat))
1783         {
1784                 /* Nope */
1785                 return (FALSE);
1786         }
1787
1788         /* Jammed door */
1789         if (!have_flag(f_ptr->flags, FF_OPEN))
1790         {
1791                 /* Stuck */
1792 #ifdef JP
1793                 msg_format("%s¤Ï¤¬¤Ã¤Á¤ê¤ÈÊĤ¸¤é¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£", f_name + f_info[get_feat_mimic(c_ptr)].name);
1794 #else
1795                 msg_format("The %s appears to be stuck.", f_name + f_info[get_feat_mimic(c_ptr)].name);
1796 #endif
1797
1798         }
1799
1800         /* Locked door */
1801         else if (f_ptr->power)
1802         {
1803                 /* Disarm factor */
1804                 i = p_ptr->skill_dis;
1805
1806                 /* Penalize some conditions */
1807                 if (p_ptr->blind || no_lite()) i = i / 10;
1808                 if (p_ptr->confused || p_ptr->image) i = i / 10;
1809
1810                 /* Extract the lock power */
1811                 j = f_ptr->power;
1812
1813                 /* Extract the difficulty XXX XXX XXX */
1814                 j = i - (j * 4);
1815
1816                 /* Always have a small chance of success */
1817                 if (j < 2) j = 2;
1818
1819                 /* Success */
1820                 if (randint0(100) < j)
1821                 {
1822                         /* Message */
1823 #ifdef JP
1824                         msg_print("¸°¤ò¤Ï¤º¤·¤¿¡£");
1825 #else
1826                         msg_print("You have picked the lock.");
1827 #endif
1828
1829
1830                         /* Open the door */
1831                         cave_alter_feat(y, x, FF_OPEN);
1832
1833                         /* Update some things */
1834                         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MONSTERS | PU_MON_LITE);
1835
1836                         /* Sound */
1837                         sound(SOUND_OPENDOOR);
1838
1839                         /* Experience */
1840                         gain_exp(1);
1841                 }
1842
1843                 /* Failure */
1844                 else
1845                 {
1846                         /* Failure */
1847                         if (flush_failure) flush();
1848
1849                         /* Message */
1850 #ifdef JP
1851                         msg_print("¸°¤ò¤Ï¤º¤»¤Ê¤«¤Ã¤¿¡£");
1852 #else
1853                         msg_print("You failed to pick the lock.");
1854 #endif
1855
1856                 }
1857         }
1858
1859         /* Closed door */
1860         else
1861         {
1862                 /* Open the door */
1863                 cave_alter_feat(y, x, FF_OPEN);
1864
1865                 /* Update some things */
1866                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MONSTERS | PU_MON_LITE);
1867
1868                 /* Sound */
1869                 sound(SOUND_OPENDOOR);
1870         }
1871
1872         /* Result */
1873         return (TRUE);
1874 }
1875
1876 #endif /* ALLOW_EASY_OPEN -- TNB */
1877
1878
1879 /*
1880  * Perform the basic "disarm" command
1881  *
1882  * Assume destination is a visible trap
1883  *
1884  * Assume there is no monster blocking the destination
1885  *
1886  * Returns TRUE if repeated commands may continue
1887  */
1888 static bool do_cmd_disarm_chest(int y, int x, s16b o_idx)
1889 {
1890         int i, j;
1891
1892         bool more = FALSE;
1893
1894         object_type *o_ptr = &o_list[o_idx];
1895
1896
1897         /* Take a turn */
1898         energy_use = 100;
1899
1900         /* Get the "disarm" factor */
1901         i = p_ptr->skill_dis;
1902
1903         /* Penalize some conditions */
1904         if (p_ptr->blind || no_lite()) i = i / 10;
1905         if (p_ptr->confused || p_ptr->image) i = i / 10;
1906
1907         /* Extract the difficulty */
1908         j = i - o_ptr->pval;
1909
1910         /* Always have a small chance of success */
1911         if (j < 2) j = 2;
1912
1913         /* Must find the trap first. */
1914         if (!object_is_known(o_ptr))
1915         {
1916 #ifdef JP
1917                 msg_print("¥È¥é¥Ã¥×¤¬¸«¤¢¤¿¤é¤Ê¤¤¡£");
1918 #else
1919                 msg_print("I don't see any traps.");
1920 #endif
1921
1922         }
1923
1924         /* Already disarmed/unlocked */
1925         else if (o_ptr->pval <= 0)
1926         {
1927 #ifdef JP
1928                 msg_print("È¢¤Ë¤Ï¥È¥é¥Ã¥×¤¬»Å³Ý¤±¤é¤ì¤Æ¤¤¤Ê¤¤¡£");
1929 #else
1930                 msg_print("The chest is not trapped.");
1931 #endif
1932
1933         }
1934
1935         /* No traps to find. */
1936         else if (!chest_traps[o_ptr->pval])
1937         {
1938 #ifdef JP
1939                 msg_print("È¢¤Ë¤Ï¥È¥é¥Ã¥×¤¬»Å³Ý¤±¤é¤ì¤Æ¤¤¤Ê¤¤¡£");
1940 #else
1941                 msg_print("The chest is not trapped.");
1942 #endif
1943
1944         }
1945
1946         /* Success (get a lot of experience) */
1947         else if (randint0(100) < j)
1948         {
1949 #ifdef JP
1950                 msg_print("È¢¤Ë»Å³Ý¤±¤é¤ì¤Æ¤¤¤¿¥È¥é¥Ã¥×¤ò²ò½ü¤·¤¿¡£");
1951 #else
1952                 msg_print("You have disarmed the chest.");
1953 #endif
1954
1955                 gain_exp(o_ptr->pval);
1956                 o_ptr->pval = (0 - o_ptr->pval);
1957         }
1958
1959         /* Failure -- Keep trying */
1960         else if ((i > 5) && (randint1(i) > 5))
1961         {
1962                 /* We may keep trying */
1963                 more = TRUE;
1964                 if (flush_failure) flush();
1965 #ifdef JP
1966                 msg_print("È¢¤Î¥È¥é¥Ã¥×²ò½ü¤Ë¼ºÇÔ¤·¤¿¡£");
1967 #else
1968                 msg_print("You failed to disarm the chest.");
1969 #endif
1970
1971         }
1972
1973         /* Failure -- Set off the trap */
1974         else
1975         {
1976 #ifdef JP
1977                 msg_print("¥È¥é¥Ã¥×¤òºîÆ°¤µ¤»¤Æ¤·¤Þ¤Ã¤¿¡ª");
1978 #else
1979                 msg_print("You set off a trap!");
1980 #endif
1981
1982                 sound(SOUND_FAIL);
1983                 chest_trap(y, x, o_idx);
1984         }
1985
1986         /* Result */
1987         return (more);
1988 }
1989
1990
1991 /*
1992  * Perform the basic "disarm" command
1993  *
1994  * Assume destination is a visible trap
1995  *
1996  * Assume there is no monster blocking the destination
1997  *
1998  * Returns TRUE if repeated commands may continue
1999  */
2000 #ifdef ALLOW_EASY_DISARM /* TNB */
2001
2002 bool do_cmd_disarm_aux(int y, int x, int dir)
2003
2004 #else /* ALLOW_EASY_DISARM -- TNB */
2005
2006 static bool do_cmd_disarm_aux(int y, int x, int dir)
2007
2008 #endif /* ALLOW_EASY_DISARM -- TNB */
2009 {
2010         /* Get grid and contents */
2011         cave_type *c_ptr = &cave[y][x];
2012
2013         /* Get feature */
2014         feature_type *f_ptr = &f_info[c_ptr->feat];
2015
2016         /* Access trap name */
2017         cptr name = (f_name + f_ptr->name);
2018
2019         /* Extract trap "power" */
2020         int power = f_ptr->power;
2021
2022         bool more = FALSE;
2023
2024         /* Get the "disarm" factor */
2025         int i = p_ptr->skill_dis;
2026
2027         int j;
2028
2029         /* Take a turn */
2030         energy_use = 100;
2031
2032         /* Penalize some conditions */
2033         if (p_ptr->blind || no_lite()) i = i / 10;
2034         if (p_ptr->confused || p_ptr->image) i = i / 10;
2035
2036         /* Extract the difficulty */
2037         j = i - power;
2038
2039         /* Always have a small chance of success */
2040         if (j < 2) j = 2;
2041
2042         /* Success */
2043         if (randint0(100) < j)
2044         {
2045                 /* Message */
2046 #ifdef JP
2047                 msg_format("%s¤ò²ò½ü¤·¤¿¡£", name);
2048 #else
2049                 msg_format("You have disarmed the %s.", name);
2050 #endif
2051
2052                 /* Reward */
2053                 gain_exp(power);
2054
2055                 /* Remove the trap */
2056                 cave_alter_feat(y, x, FF_DISARM);
2057
2058 #ifdef ALLOW_EASY_DISARM /* TNB */
2059
2060                 /* Move the player onto the trap */
2061                 move_player(dir, easy_disarm, FALSE);
2062
2063 #else /* ALLOW_EASY_DISARM -- TNB */
2064
2065                 /* move the player onto the trap grid */
2066                 move_player(dir, FALSE, FALSE);
2067
2068 #endif /* ALLOW_EASY_DISARM -- TNB */
2069         }
2070
2071         /* Failure -- Keep trying */
2072         else if ((i > 5) && (randint1(i) > 5))
2073         {
2074                 /* Failure */
2075                 if (flush_failure) flush();
2076
2077                 /* Message */
2078 #ifdef JP
2079                 msg_format("%s¤Î²ò½ü¤Ë¼ºÇÔ¤·¤¿¡£", name);
2080 #else
2081                 msg_format("You failed to disarm the %s.", name);
2082 #endif
2083
2084                 /* We may keep trying */
2085                 more = TRUE;
2086         }
2087
2088         /* Failure -- Set off the trap */
2089         else
2090         {
2091                 /* Message */
2092 #ifdef JP
2093                 msg_format("%s¤òºîÆ°¤µ¤»¤Æ¤·¤Þ¤Ã¤¿¡ª", name);
2094 #else
2095                 msg_format("You set off the %s!", name);
2096 #endif
2097
2098 #ifdef ALLOW_EASY_DISARM /* TNB */
2099
2100                 /* Move the player onto the trap */
2101                 move_player(dir, easy_disarm, FALSE);
2102
2103 #else /* ALLOW_EASY_DISARM -- TNB */
2104
2105                 /* Move the player onto the trap */
2106                 move_player(dir, FALSE, FALSE);
2107
2108 #endif /* ALLOW_EASY_DISARM -- TNB */
2109         }
2110
2111         /* Result */
2112         return (more);
2113 }
2114
2115
2116 /*
2117  * Disarms a trap, or chest
2118  */
2119 void do_cmd_disarm(void)
2120 {
2121         int y, x, dir;
2122
2123         s16b o_idx;
2124
2125         bool more = FALSE;
2126
2127         if (p_ptr->special_defense & KATA_MUSOU)
2128         {
2129                 set_action(ACTION_NONE);
2130         }
2131
2132 #ifdef ALLOW_EASY_DISARM /* TNB */
2133
2134         /* Option: Pick a direction */
2135         if (easy_disarm)
2136         {
2137                 int num_traps, num_chests;
2138
2139                 /* Count visible traps */
2140                 num_traps = count_dt(&y, &x, is_trap, TRUE);
2141
2142                 /* Count chests (trapped) */
2143                 num_chests = count_chests(&y, &x, TRUE);
2144
2145                 /* See if only one target */
2146                 if (num_traps || num_chests)
2147                 {
2148                         bool too_many = (num_traps && num_chests) || (num_traps > 1) ||
2149                             (num_chests > 1);
2150                         if (!too_many) command_dir = coords_to_dir(y, x);
2151                 }
2152         }
2153
2154 #endif /* ALLOW_EASY_DISARM -- TNB */
2155
2156         /* Allow repeated command */
2157         if (command_arg)
2158         {
2159                 /* Set repeat count */
2160                 command_rep = command_arg - 1;
2161
2162                 /* Redraw the state */
2163                 p_ptr->redraw |= (PR_STATE);
2164
2165                 /* Cancel the arg */
2166                 command_arg = 0;
2167         }
2168
2169         /* Get a direction (or abort) */
2170         if (get_rep_dir(&dir,TRUE))
2171         {
2172                 cave_type *c_ptr;
2173                 s16b feat;
2174
2175                 /* Get location */
2176                 y = py + ddy[dir];
2177                 x = px + ddx[dir];
2178
2179                 /* Get grid and contents */
2180                 c_ptr = &cave[y][x];
2181
2182                 /* Feature code (applying "mimic" field) */
2183                 feat = get_feat_mimic(c_ptr);
2184
2185                 /* Check for chests */
2186                 o_idx = chest_check(y, x);
2187
2188                 /* Disarm a trap */
2189                 if (!is_trap(feat) && !o_idx)
2190                 {
2191                         /* Message */
2192 #ifdef JP
2193                         msg_print("¤½¤³¤Ë¤Ï²ò½ü¤¹¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
2194 #else
2195                         msg_print("You see nothing there to disarm.");
2196 #endif
2197
2198                 }
2199
2200                 /* Monster in the way */
2201                 else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
2202                 {
2203                         /* Message */
2204 #ifdef JP
2205                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
2206 #else
2207                         msg_print("There is a monster in the way!");
2208 #endif
2209
2210
2211                         /* Attack */
2212                         py_attack(y, x, 0);
2213                 }
2214
2215                 /* Disarm chest */
2216                 else if (o_idx)
2217                 {
2218                         /* Disarm the chest */
2219                         more = do_cmd_disarm_chest(y, x, o_idx);
2220                 }
2221
2222                 /* Disarm trap */
2223                 else
2224                 {
2225                         /* Disarm the trap */
2226                         more = do_cmd_disarm_aux(y, x, dir);
2227                 }
2228         }
2229
2230         /* Cancel repeat unless told not to */
2231         if (!more) disturb(0, 0);
2232 }
2233
2234
2235 /*
2236  * Perform the basic "bash" command
2237  *
2238  * Assume destination is a closed/locked/jammed door
2239  *
2240  * Assume there is no monster blocking the destination
2241  *
2242  * Returns TRUE if repeated commands may continue
2243  */
2244 static bool do_cmd_bash_aux(int y, int x, int dir)
2245 {
2246         /* Get grid */
2247         cave_type       *c_ptr = &cave[y][x];
2248
2249         /* Hack -- Bash power based on strength */
2250         /* (Ranges from 3 to 20 to 100 to 200) */
2251         int bash = adj_str_blow[p_ptr->stat_ind[A_STR]];
2252
2253         /* Extract door power */
2254         int temp = f_info[c_ptr->feat].power;
2255
2256         bool            more = FALSE;
2257
2258         cptr name = f_name + f_info[get_feat_mimic(c_ptr)].name;
2259
2260         /* Take a turn */
2261         energy_use = 100;
2262
2263         /* Message */
2264 #ifdef JP
2265         msg_format("%s¤ËÂÎÅö¤¿¤ê¤ò¤·¤¿¡ª", name);
2266 #else
2267         msg_format("You smash into the %s!", name);
2268 #endif
2269
2270         /* Compare bash power to door power XXX XXX XXX */
2271         temp = (bash - (temp * 10));
2272
2273         if (p_ptr->pclass == CLASS_BERSERKER) temp *= 2;
2274
2275         /* Hack -- always have a chance */
2276         if (temp < 1) temp = 1;
2277
2278         /* Hack -- attempt to bash down the door */
2279         if (randint0(100) < temp)
2280         {
2281                 /* Message */
2282 #ifdef JP
2283                 msg_format("%s¤ò²õ¤·¤¿¡ª", name);
2284 #else
2285                 msg_format("The %s crashes open!", name);
2286 #endif
2287
2288
2289                 /* Break down the door */
2290                 if ((randint0(100) < 50) || (feat_state(c_ptr->feat, FF_OPEN) == c_ptr->feat))
2291                 {
2292                         cave_alter_feat(y, x, FF_BASH);
2293                 }
2294
2295                 /* Open the door */
2296                 else
2297                 {
2298                         cave_alter_feat(y, x, FF_OPEN);
2299                 }
2300
2301                 /* Sound */
2302                 sound(SOUND_OPENDOOR);
2303
2304                 /* Hack -- Fall through the door */
2305                 move_player(dir, FALSE, FALSE);
2306
2307                 /* Update some things */
2308                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
2309                 p_ptr->update |= (PU_DISTANCE);
2310         }
2311
2312         /* Saving throw against stun */
2313         else if (randint0(100) < adj_dex_safe[p_ptr->stat_ind[A_DEX]] +
2314                  p_ptr->lev)
2315         {
2316                 /* Message */
2317 #ifdef JP
2318                 msg_format("¤³¤Î%s¤Ï´è¾æ¤À¡£", name);
2319 #else
2320                 msg_format("The %s holds firm.", name);
2321 #endif
2322
2323
2324                 /* Allow repeated bashing */
2325                 more = TRUE;
2326         }
2327
2328         /* High dexterity yields coolness */
2329         else
2330         {
2331                 /* Message */
2332 #ifdef JP
2333                 msg_print("ÂΤΥХé¥ó¥¹¤ò¤¯¤º¤·¤Æ¤·¤Þ¤Ã¤¿¡£");
2334 #else
2335                 msg_print("You are off-balance.");
2336 #endif
2337
2338
2339                 /* Hack -- Lose balance ala paralysis */
2340                 (void)set_paralyzed(p_ptr->paralyzed + 2 + randint0(2));
2341         }
2342
2343         /* Result */
2344         return (more);
2345 }
2346
2347
2348 /*
2349  * Bash open a door, success based on character strength
2350  *
2351  * For a closed door, pval is positive if locked; negative if stuck.
2352  *
2353  * For an open door, pval is positive for a broken door.
2354  *
2355  * A closed door can be opened - harder if locked. Any door might be
2356  * bashed open (and thereby broken). Bashing a door is (potentially)
2357  * faster! You move into the door way. To open a stuck door, it must
2358  * be bashed. A closed door can be jammed (see do_cmd_spike()).
2359  *
2360  * Creatures can also open or bash doors, see elsewhere.
2361  */
2362 void do_cmd_bash(void)
2363 {
2364         int                     y, x, dir;
2365
2366         cave_type       *c_ptr;
2367
2368         bool            more = FALSE;
2369
2370
2371         if (p_ptr->special_defense & KATA_MUSOU)
2372         {
2373                 set_action(ACTION_NONE);
2374         }
2375
2376         /* Allow repeated command */
2377         if (command_arg)
2378         {
2379                 /* Set repeat count */
2380                 command_rep = command_arg - 1;
2381
2382                 /* Redraw the state */
2383                 p_ptr->redraw |= (PR_STATE);
2384
2385                 /* Cancel the arg */
2386                 command_arg = 0;
2387         }
2388
2389         /* Get a "repeated" direction */
2390         if (get_rep_dir(&dir,FALSE))
2391         {
2392                 s16b feat;
2393
2394                 /* Bash location */
2395                 y = py + ddy[dir];
2396                 x = px + ddx[dir];
2397
2398                 /* Get grid */
2399                 c_ptr = &cave[y][x];
2400
2401                 /* Feature code (applying "mimic" field) */
2402                 feat = get_feat_mimic(c_ptr);
2403
2404                 /* Nothing useful */
2405                 if (!have_flag(f_info[feat].flags, FF_BASH))
2406                 {
2407                         /* Message */
2408 #ifdef JP
2409                         msg_print("¤½¤³¤Ë¤ÏÂÎÅö¤¿¤ê¤¹¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
2410 #else
2411                         msg_print("You see nothing there to bash.");
2412 #endif
2413
2414                 }
2415
2416                 /* Monster in the way */
2417                 else if (c_ptr->m_idx)
2418                 {
2419                         /* Take a turn */
2420                         energy_use = 100;
2421
2422                         /* Message */
2423 #ifdef JP
2424                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
2425 #else
2426                         msg_print("There is a monster in the way!");
2427 #endif
2428
2429
2430                         /* Attack */
2431                         py_attack(y, x, 0);
2432                 }
2433
2434                 /* Bash a closed door */
2435                 else
2436                 {
2437                         /* Bash the door */
2438                         more = do_cmd_bash_aux(y, x, dir);
2439                 }
2440         }
2441
2442         /* Unless valid action taken, cancel bash */
2443         if (!more) disturb(0, 0);
2444 }
2445
2446
2447 /*
2448  * Manipulate an adjacent grid in some way
2449  *
2450  * Attack monsters, tunnel through walls, disarm traps, open doors.
2451  *
2452  * Consider confusion XXX XXX XXX
2453  *
2454  * This command must always take a turn, to prevent free detection
2455  * of invisible monsters.
2456  */
2457 void do_cmd_alter(void)
2458 {
2459         int                     y, x, dir;
2460
2461         cave_type       *c_ptr;
2462
2463         bool            more = FALSE;
2464
2465
2466         if (p_ptr->special_defense & KATA_MUSOU)
2467         {
2468                 set_action(ACTION_NONE);
2469         }
2470
2471         /* Allow repeated command */
2472         if (command_arg)
2473         {
2474                 /* Set repeat count */
2475                 command_rep = command_arg - 1;
2476
2477                 /* Redraw the state */
2478                 p_ptr->redraw |= (PR_STATE);
2479
2480                 /* Cancel the arg */
2481                 command_arg = 0;
2482         }
2483
2484         /* Get a direction */
2485         if (get_rep_dir(&dir,TRUE))
2486         {
2487                 s16b feat;
2488                 feature_type *f_ptr;
2489
2490                 /* Get location */
2491                 y = py + ddy[dir];
2492                 x = px + ddx[dir];
2493
2494                 /* Get grid */
2495                 c_ptr = &cave[y][x];
2496
2497                 /* Feature code (applying "mimic" field) */
2498                 feat = get_feat_mimic(c_ptr);
2499                 f_ptr = &f_info[feat];
2500
2501                 /* Take a turn */
2502                 energy_use = 100;
2503
2504                 /* Attack monsters */
2505                 if (c_ptr->m_idx)
2506                 {
2507                         /* Attack */
2508                         py_attack(y, x, 0);
2509                 }
2510
2511                 /* Locked doors */
2512                 else if (have_flag(f_ptr->flags, FF_OPEN))
2513                 {
2514                         more = do_cmd_open_aux(y, x);
2515                 }
2516
2517                 /* Bash jammed doors */
2518                 else if (have_flag(f_ptr->flags, FF_BASH))
2519                 {
2520                         more = do_cmd_bash_aux(y, x, dir);
2521                 }
2522
2523                 /* Tunnel through walls */
2524                 else if (have_flag(f_ptr->flags, FF_TUNNEL))
2525                 {
2526                         more = do_cmd_tunnel_aux(y, x);
2527                 }
2528
2529                 /* Close open doors */
2530                 else if (have_flag(f_ptr->flags, FF_CLOSE))
2531                 {
2532                         more = do_cmd_close_aux(y, x);
2533                 }
2534
2535                 /* Disarm traps */
2536                 else if (have_flag(f_ptr->flags, FF_DISARM))
2537                 {
2538                         more = do_cmd_disarm_aux(y, x, dir);
2539                 }
2540
2541                 /* Oops */
2542                 else
2543                 {
2544                         /* Oops */
2545 #ifdef JP
2546                         msg_print("²¿¤â¤Ê¤¤¶õÃæ¤ò¹¶·â¤·¤¿¡£");
2547 #else
2548                         msg_print("You attack the empty air.");
2549 #endif
2550
2551                 }
2552         }
2553
2554         /* Cancel repetition unless we can continue */
2555         if (!more) disturb(0, 0);
2556 }
2557
2558
2559 /*
2560  * Find the index of some "spikes", if possible.
2561  *
2562  * XXX XXX XXX Let user choose a pile of spikes, perhaps?
2563  */
2564 static bool get_spike(int *ip)
2565 {
2566         int i;
2567
2568         /* Check every item in the pack */
2569         for (i = 0; i < INVEN_PACK; i++)
2570         {
2571                 object_type *o_ptr = &inventory[i];
2572
2573                 /* Skip non-objects */
2574                 if (!o_ptr->k_idx) continue;
2575
2576                 /* Check the "tval" code */
2577                 if (o_ptr->tval == TV_SPIKE)
2578                 {
2579                         /* Save the spike index */
2580                         (*ip) = i;
2581
2582                         /* Success */
2583                         return (TRUE);
2584                 }
2585         }
2586
2587         /* Oops */
2588         return (FALSE);
2589 }
2590
2591
2592 /*
2593  * Jam a closed door with a spike
2594  *
2595  * This command may NOT be repeated
2596  */
2597 void do_cmd_spike(void)
2598 {
2599         int dir;
2600
2601         if (p_ptr->special_defense & KATA_MUSOU)
2602         {
2603                 set_action(ACTION_NONE);
2604         }
2605
2606         /* Get a "repeated" direction */
2607         if (get_rep_dir(&dir,FALSE))
2608         {
2609                 int y, x, item;
2610                 cave_type *c_ptr;
2611                 s16b feat;
2612
2613                 /* Get location */
2614                 y = py + ddy[dir];
2615                 x = px + ddx[dir];
2616
2617                 /* Get grid and contents */
2618                 c_ptr = &cave[y][x];
2619
2620                 /* Feature code (applying "mimic" field) */
2621                 feat = get_feat_mimic(c_ptr);
2622
2623                 /* Require closed door */
2624                 if (!have_flag(f_info[feat].flags, FF_SPIKE))
2625                 {
2626                         /* Message */
2627 #ifdef JP
2628                         msg_print("¤½¤³¤Ë¤Ï¤¯¤µ¤Ó¤òÂǤƤë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
2629 #else
2630                         msg_print("You see nothing there to spike.");
2631 #endif
2632
2633                 }
2634
2635                 /* Get a spike */
2636                 else if (!get_spike(&item))
2637                 {
2638                         /* Message */
2639 #ifdef JP
2640                         msg_print("¤¯¤µ¤Ó¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡ª");
2641 #else
2642                         msg_print("You have no spikes!");
2643 #endif
2644                 }
2645
2646                 /* Is a monster in the way? */
2647                 else if (c_ptr->m_idx)
2648                 {
2649                         /* Take a turn */
2650                         energy_use = 100;
2651
2652                         /* Message */
2653 #ifdef JP
2654                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
2655 #else
2656                         msg_print("There is a monster in the way!");
2657 #endif
2658
2659                         /* Attack */
2660                         py_attack(y, x, 0);
2661                 }
2662
2663                 /* Go for it */
2664                 else
2665                 {
2666                         /* Take a turn */
2667                         energy_use = 100;
2668
2669                         /* Successful jamming */
2670 #ifdef JP
2671                         msg_format("%s¤Ë¤¯¤µ¤Ó¤òÂǤÁ¹þ¤ó¤À¡£", f_name + f_info[feat].name);
2672 #else
2673                         msg_format("You jam the %s with a spike.", f_name + f_info[feat].name);
2674 #endif
2675
2676                         cave_alter_feat(y, x, FF_SPIKE);
2677
2678                         /* Use up, and describe, a single spike, from the bottom */
2679                         inven_item_increase(item, -1);
2680                         inven_item_describe(item);
2681                         inven_item_optimize(item);
2682                 }
2683         }
2684 }
2685
2686
2687
2688 /*
2689  * Support code for the "Walk" and "Jump" commands
2690  */
2691 void do_cmd_walk(bool pickup)
2692 {
2693         int dir;
2694
2695         bool more = FALSE;
2696
2697
2698         /* Allow repeated command */
2699         if (command_arg)
2700         {
2701                 /* Set repeat count */
2702                 command_rep = command_arg - 1;
2703
2704                 /* Redraw the state */
2705                 p_ptr->redraw |= (PR_STATE);
2706
2707                 /* Cancel the arg */
2708                 command_arg = 0;
2709         }
2710
2711         /* Get a "repeated" direction */
2712         if (get_rep_dir(&dir,FALSE))
2713         {
2714                 /* Take a turn */
2715                 energy_use = 100;
2716
2717                 if ((dir != 5) && (p_ptr->special_defense & KATA_MUSOU))
2718                 {
2719                         set_action(ACTION_NONE);
2720                 }
2721
2722                 /* Hack -- In small scale wilderness it takes MUCH more time to move */
2723                 if (p_ptr->wild_mode) energy_use *= ((MAX_HGT + MAX_WID) / 2);
2724                 if (p_ptr->action == ACTION_HAYAGAKE) energy_use = energy_use * (45-(p_ptr->lev/2)) / 100;
2725
2726                 /* Actually move the character */
2727                 move_player(dir, pickup, FALSE);
2728
2729                 /* Allow more walking */
2730                 more = TRUE;
2731         }
2732
2733         /* Hack again -- Is there a special encounter ??? */
2734         if (p_ptr->wild_mode && !cave_have_flag_bold(py, px, FF_TOWN))
2735         {
2736                 int tmp = 120 + p_ptr->lev*10 - wilderness[py][px].level + 5;
2737                 if (tmp < 1) 
2738                         tmp = 1;
2739                 if (((wilderness[py][px].level + 5) > (p_ptr->lev / 2)) && randint0(tmp) < (21-p_ptr->skill_stl))
2740                 {
2741                         /* Inform the player of his horrible fate :=) */
2742 #ifdef JP
2743                         msg_print("½±·â¤À¡ª");
2744 #else
2745                         msg_print("You are ambushed !");
2746 #endif
2747
2748                         /* Go into large wilderness view */
2749                         p_ptr->oldpy = randint1(MAX_HGT-2);
2750                         p_ptr->oldpx = randint1(MAX_WID-2);
2751                         change_wild_mode();
2752
2753                         /* Give first move to monsters */
2754                         energy_use = 100;
2755
2756                         /* HACk -- set the encouter flag for the wilderness generation */
2757                         generate_encounter = TRUE;
2758                 }
2759         }
2760
2761         /* Cancel repeat unless we may continue */
2762         if (!more) disturb(0, 0);
2763 }
2764
2765
2766
2767 /*
2768  * Start running.
2769  */
2770 void do_cmd_run(void)
2771 {
2772         int dir;
2773
2774         /* Hack -- no running when confused */
2775         if (p_ptr->confused)
2776         {
2777 #ifdef JP
2778                 msg_print("º®Í𤷤Ƥ¤¤ÆÁö¤ì¤Ê¤¤¡ª");
2779 #else
2780                 msg_print("You are too confused!");
2781 #endif
2782
2783                 return;
2784         }
2785
2786         if (p_ptr->special_defense & KATA_MUSOU)
2787         {
2788                 set_action(ACTION_NONE);
2789         }
2790
2791         /* Get a "repeated" direction */
2792         if (get_rep_dir(&dir,FALSE))
2793         {
2794                 /* Hack -- Set the run counter */
2795                 running = (command_arg ? command_arg : 1000);
2796
2797                 /* First step */
2798                 run_step(dir);
2799         }
2800 }
2801
2802
2803
2804 /*
2805  * Stay still.  Search.  Enter stores.
2806  * Pick up treasure if "pickup" is true.
2807  */
2808 void do_cmd_stay(bool pickup)
2809 {
2810         u32b mpe_mode = MPE_STAYING | MPE_ENERGY_USE;
2811
2812         /* Allow repeated command */
2813         if (command_arg)
2814         {
2815                 /* Set repeat count */
2816                 command_rep = command_arg - 1;
2817
2818                 /* Redraw the state */
2819                 p_ptr->redraw |= (PR_STATE);
2820
2821                 /* Cancel the arg */
2822                 command_arg = 0;
2823         }
2824
2825         /* Take a turn */
2826         energy_use = 100;
2827
2828         if (pickup) mpe_mode |= MPE_DO_PICKUP;
2829         (void)move_player_effect(py, px, mpe_mode);
2830 }
2831
2832
2833
2834 /*
2835  * Resting allows a player to safely restore his hp     -RAK-
2836  */
2837 void do_cmd_rest(void)
2838 {
2839
2840         set_action(ACTION_NONE);
2841
2842         if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] || p_ptr->magic_num1[1]))
2843         {
2844                 stop_singing();
2845         }
2846
2847         /* Prompt for time if needed */
2848         if (command_arg <= 0)
2849         {
2850 #ifdef JP
2851                 cptr p = "µÙ·Æ (0-9999, '*' ¤Ç HP/MPÁ´²÷, '&' ¤ÇɬÍפʤÀ¤±): ";
2852 #else
2853                 cptr p = "Rest (0-9999, '*' for HP/SP, '&' as needed): ";
2854 #endif
2855
2856
2857                 char out_val[80];
2858
2859                 /* Default */
2860                 strcpy(out_val, "&");
2861
2862                 /* Ask for duration */
2863                 if (!get_string(p, out_val, 4)) return;
2864
2865                 /* Rest until done */
2866                 if (out_val[0] == '&')
2867                 {
2868                         command_arg = (-2);
2869                 }
2870
2871                 /* Rest a lot */
2872                 else if (out_val[0] == '*')
2873                 {
2874                         command_arg = (-1);
2875                 }
2876
2877                 /* Rest some */
2878                 else
2879                 {
2880                         command_arg = atoi(out_val);
2881                         if (command_arg <= 0) return;
2882                 }
2883         }
2884
2885
2886         /* Paranoia */
2887         if (command_arg > 9999) command_arg = 9999;
2888
2889         if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
2890
2891         /* Take a turn XXX XXX XXX (?) */
2892         energy_use = 100;
2893
2894         /* The sin of sloth */
2895         if (command_arg > 100)
2896                 chg_virtue(V_DILIGENCE, -1);
2897         
2898         /* Why are you sleeping when there's no need?  WAKE UP!*/
2899         if ((p_ptr->chp == p_ptr->mhp) &&
2900             (p_ptr->csp == p_ptr->msp) &&
2901             !p_ptr->blind && !p_ptr->confused &&
2902             !p_ptr->poisoned && !p_ptr->afraid &&
2903             !p_ptr->stun && !p_ptr->cut &&
2904             !p_ptr->slow && !p_ptr->paralyzed &&
2905             !p_ptr->image && !p_ptr->word_recall &&
2906             !p_ptr->alter_reality)
2907                         chg_virtue(V_DILIGENCE, -1);
2908
2909         /* Save the rest code */
2910         resting = command_arg;
2911         p_ptr->action = ACTION_REST;
2912
2913         /* Recalculate bonuses */
2914         p_ptr->update |= (PU_BONUS);
2915
2916         /* Redraw the state */
2917         p_ptr->redraw |= (PR_STATE);
2918
2919         /* Handle stuff */
2920         handle_stuff();
2921
2922         /* Refresh */
2923         Term_fresh();
2924 }
2925
2926
2927 /*
2928  * Determines the odds of an object breaking when thrown at a monster
2929  *
2930  * Note that artifacts never break, see the "drop_near()" function.
2931  */
2932 static int breakage_chance(object_type *o_ptr)
2933 {
2934         int archer_bonus = (p_ptr->pclass == CLASS_ARCHER ? (p_ptr->lev-1)/7 + 4: 0);
2935
2936         /* Examine the item type */
2937         switch (o_ptr->tval)
2938         {
2939                 /* Always break */
2940                 case TV_FLASK:
2941                 case TV_POTION:
2942                 case TV_BOTTLE:
2943                 case TV_FOOD:
2944                 case TV_JUNK:
2945                         return (100);
2946
2947                 /* Often break */
2948                 case TV_LITE:
2949                 case TV_SCROLL:
2950                 case TV_SKELETON:
2951                         return (50);
2952
2953                 /* Sometimes break */
2954                 case TV_WAND:
2955                 case TV_SPIKE:
2956                         return (25);
2957                 case TV_ARROW:
2958                         return (20 - archer_bonus * 2);
2959
2960                 /* Rarely break */
2961                 case TV_SHOT:
2962                 case TV_BOLT:
2963                         return (10 - archer_bonus);
2964                 default:
2965                         return (10);
2966         }
2967 }
2968
2969
2970 static s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
2971 {
2972         int mult = 10;
2973
2974         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2975
2976         u32b flgs[TR_FLAG_SIZE];
2977
2978         /* Extract the flags */
2979         object_flags(o_ptr, flgs);
2980
2981         /* Some "weapons" and "ammo" do extra damage */
2982         switch (o_ptr->tval)
2983         {
2984                 case TV_SHOT:
2985                 case TV_ARROW:
2986                 case TV_BOLT:
2987                 {
2988                         /* Slay Animal */
2989                         if ((have_flag(flgs, TR_SLAY_ANIMAL)) &&
2990                             (r_ptr->flags3 & RF3_ANIMAL))
2991                         {
2992                                 if (is_original_ap_and_seen(m_ptr))
2993                                 {
2994                                         r_ptr->r_flags3 |= RF3_ANIMAL;
2995                                 }
2996
2997                                 if (mult < 17) mult = 17;
2998                         }
2999
3000                         /* Kill Animal */
3001                         if ((have_flag(flgs, TR_KILL_ANIMAL)) &&
3002                             (r_ptr->flags3 & RF3_ANIMAL))
3003                         {
3004                                 if (is_original_ap_and_seen(m_ptr))
3005                                 {
3006                                         r_ptr->r_flags3 |= RF3_ANIMAL;
3007                                 }
3008
3009                                 if (mult < 27) mult = 27;
3010                         }
3011
3012                         /* Slay Evil */
3013                         if ((have_flag(flgs, TR_SLAY_EVIL)) &&
3014                             (r_ptr->flags3 & RF3_EVIL))
3015                         {
3016                                 if (is_original_ap_and_seen(m_ptr))
3017                                 {
3018                                         r_ptr->r_flags3 |= RF3_EVIL;
3019                                 }
3020
3021                                 if (mult < 15) mult = 15;
3022                         }
3023
3024                         /* Kill Evil */
3025                         if ((have_flag(flgs, TR_KILL_EVIL)) &&
3026                             (r_ptr->flags3 & RF3_EVIL))
3027                         {
3028                                 if (is_original_ap_and_seen(m_ptr))
3029                                 {
3030                                         r_ptr->r_flags3 |= RF3_EVIL;
3031                                 }
3032
3033                                 if (mult < 25) mult = 25;
3034                         }
3035
3036                         /* Slay Human */
3037                         if ((have_flag(flgs, TR_SLAY_HUMAN)) &&
3038                             (r_ptr->flags2 & RF2_HUMAN))
3039                         {
3040                                 if (is_original_ap_and_seen(m_ptr))
3041                                 {
3042                                         r_ptr->r_flags2 |= RF2_HUMAN;
3043                                 }
3044
3045                                 if (mult < 17) mult = 17;
3046                         }
3047
3048                         /* Kill Human */
3049                         if ((have_flag(flgs, TR_KILL_HUMAN)) &&
3050                             (r_ptr->flags2 & RF2_HUMAN))
3051                         {
3052                                 if (is_original_ap_and_seen(m_ptr))
3053                                 {
3054                                         r_ptr->r_flags2 |= RF2_HUMAN;
3055                                 }
3056
3057                                 if (mult < 27) mult = 27;
3058                         }
3059
3060                         /* Slay Undead */
3061                         if ((have_flag(flgs, TR_SLAY_UNDEAD)) &&
3062                             (r_ptr->flags3 & RF3_UNDEAD))
3063                         {
3064                                 if (is_original_ap_and_seen(m_ptr))
3065                                 {
3066                                         r_ptr->r_flags3 |= RF3_UNDEAD;
3067                                 }
3068
3069                                 if (mult < 20) mult = 20;
3070                         }
3071
3072                         /* Kill Undead */
3073                         if ((have_flag(flgs, TR_KILL_UNDEAD)) &&
3074                             (r_ptr->flags3 & RF3_UNDEAD))
3075                         {
3076                                 if (is_original_ap_and_seen(m_ptr))
3077                                 {
3078                                         r_ptr->r_flags3 |= RF3_UNDEAD;
3079                                 }
3080
3081                                 if (mult < 30) mult = 30;
3082                         }
3083
3084                         /* Slay Demon */
3085                         if ((have_flag(flgs, TR_SLAY_DEMON)) &&
3086                             (r_ptr->flags3 & RF3_DEMON))
3087                         {
3088                                 if (is_original_ap_and_seen(m_ptr))
3089                                 {
3090                                         r_ptr->r_flags3 |= RF3_DEMON;
3091                                 }
3092
3093                                 if (mult < 20) mult = 20;
3094                         }
3095
3096                         /* Kill Demon */
3097                         if ((have_flag(flgs, TR_KILL_DEMON)) &&
3098                             (r_ptr->flags3 & RF3_DEMON))
3099                         {
3100                                 if (is_original_ap_and_seen(m_ptr))
3101                                 {
3102                                         r_ptr->r_flags3 |= RF3_DEMON;
3103                                 }
3104
3105                                 if (mult < 30) mult = 30;
3106                         }
3107
3108                         /* Slay Orc */
3109                         if ((have_flag(flgs, TR_SLAY_ORC)) &&
3110                             (r_ptr->flags3 & RF3_ORC))
3111                         {
3112                                 if (is_original_ap_and_seen(m_ptr))
3113                                 {
3114                                         r_ptr->r_flags3 |= RF3_ORC;
3115                                 }
3116
3117                                 if (mult < 20) mult = 20;
3118                         }
3119
3120                         /* Kill Orc */
3121                         if ((have_flag(flgs, TR_KILL_ORC)) &&
3122                             (r_ptr->flags3 & RF3_ORC))
3123                         {
3124                                 if (is_original_ap_and_seen(m_ptr))
3125                                 {
3126                                         r_ptr->r_flags3 |= RF3_ORC;
3127                                 }
3128
3129                                 if (mult < 30) mult = 30;
3130                         }
3131
3132                         /* Slay Troll */
3133                         if ((have_flag(flgs, TR_SLAY_TROLL)) &&
3134                             (r_ptr->flags3 & RF3_TROLL))
3135                         {
3136                                 if (is_original_ap_and_seen(m_ptr))
3137                                 {
3138                                         r_ptr->r_flags3 |= RF3_TROLL;
3139                                 }
3140
3141                                 if (mult < 20) mult = 20;
3142                         }
3143
3144                         /* Kill Troll */
3145                         if ((have_flag(flgs, TR_KILL_TROLL)) &&
3146                             (r_ptr->flags3 & RF3_TROLL))
3147                         {
3148                                 if (is_original_ap_and_seen(m_ptr))
3149                                 {
3150                                         r_ptr->r_flags3 |= RF3_TROLL;
3151                                 }
3152
3153                                 if (mult < 30) mult = 30;
3154                         }
3155
3156                         /* Slay Giant */
3157                         if ((have_flag(flgs, TR_SLAY_GIANT)) &&
3158                             (r_ptr->flags3 & RF3_GIANT))
3159                         {
3160                                 if (is_original_ap_and_seen(m_ptr))
3161                                 {
3162                                         r_ptr->r_flags3 |= RF3_GIANT;
3163                                 }
3164
3165                                 if (mult < 20) mult = 20;
3166                         }
3167
3168                         /* Kill Giant */
3169                         if ((have_flag(flgs, TR_KILL_GIANT)) &&
3170                             (r_ptr->flags3 & RF3_GIANT))
3171                         {
3172                                 if (is_original_ap_and_seen(m_ptr))
3173                                 {
3174                                         r_ptr->r_flags3 |= RF3_GIANT;
3175                                 }
3176
3177                                 if (mult < 30) mult = 30;
3178                         }
3179
3180                         /* Slay Dragon  */
3181                         if ((have_flag(flgs, TR_SLAY_DRAGON)) &&
3182                             (r_ptr->flags3 & RF3_DRAGON))
3183                         {
3184                                 if (is_original_ap_and_seen(m_ptr))
3185                                 {
3186                                         r_ptr->r_flags3 |= RF3_DRAGON;
3187                                 }
3188
3189                                 if (mult < 20) mult = 20;
3190                         }
3191
3192                         /* Execute Dragon */
3193                         if ((have_flag(flgs, TR_KILL_DRAGON)) &&
3194                             (r_ptr->flags3 & RF3_DRAGON))
3195                         {
3196                                 if (is_original_ap_and_seen(m_ptr))
3197                                 {
3198                                         r_ptr->r_flags3 |= RF3_DRAGON;
3199                                 }
3200
3201                                 if (mult < 30) mult = 30;
3202
3203                                 if ((o_ptr->name1 == ART_BARD_ARROW) &&
3204                                     (m_ptr->r_idx == MON_SMAUG) &&
3205                                     (inventory[INVEN_BOW].name1 == ART_BARD))
3206                                         mult *= 5;
3207                         }
3208
3209                         /* Brand (Acid) */
3210                         if (have_flag(flgs, TR_BRAND_ACID))
3211                         {
3212                                 /* Notice immunity */
3213                                 if (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK)
3214                                 {
3215                                         if (is_original_ap_and_seen(m_ptr))
3216                                         {
3217                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK);
3218                                         }
3219                                 }
3220
3221                                 /* Otherwise, take the damage */
3222                                 else
3223                                 {
3224                                         if (mult < 17) mult = 17;
3225                                 }
3226                         }
3227
3228                         /* Brand (Elec) */
3229                         if (have_flag(flgs, TR_BRAND_ELEC))
3230                         {
3231                                 /* Notice immunity */
3232                                 if (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)
3233                                 {
3234                                         if (is_original_ap_and_seen(m_ptr))
3235                                         {
3236                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
3237                                         }
3238                                 }
3239
3240                                 /* Otherwise, take the damage */
3241                                 else
3242                                 {
3243                                         if (mult < 17) mult = 17;
3244                                 }
3245                         }
3246
3247                         /* Brand (Fire) */
3248                         if (have_flag(flgs, TR_BRAND_FIRE))
3249                         {
3250                                 /* Notice immunity */
3251                                 if (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)
3252                                 {
3253                                         if (is_original_ap_and_seen(m_ptr))
3254                                         {
3255                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
3256                                         }
3257                                 }
3258
3259                                 /* Otherwise, take the damage */
3260                                 else
3261                                 {
3262                                         if (r_ptr->flags3 & RF3_HURT_FIRE)
3263                                         {
3264                                                 if (mult < 25) mult = 25;
3265                                                 if (is_original_ap_and_seen(m_ptr))
3266                                                 {
3267                                                         r_ptr->r_flags3 |= RF3_HURT_FIRE;
3268                                                 }
3269                                         }
3270                                         else if (mult < 17) mult = 17;
3271                                 }
3272                         }
3273
3274                         /* Brand (Cold) */
3275                         if (have_flag(flgs, TR_BRAND_COLD))
3276                         {
3277                                 /* Notice immunity */
3278                                 if (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)
3279                                 {
3280                                         if (is_original_ap_and_seen(m_ptr))
3281                                         {
3282                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
3283                                         }
3284                                 }
3285                                 /* Otherwise, take the damage */
3286                                 else
3287                                 {
3288                                         if (r_ptr->flags3 & RF3_HURT_COLD)
3289                                         {
3290                                                 if (mult < 25) mult = 25;
3291                                                 if (is_original_ap_and_seen(m_ptr))
3292                                                 {
3293                                                         r_ptr->r_flags3 |= RF3_HURT_COLD;
3294                                                 }
3295                                         }
3296                                         else if (mult < 17) mult = 17;
3297                                 }
3298                         }
3299
3300                         /* Brand (Poison) */
3301                         if (have_flag(flgs, TR_BRAND_POIS))
3302                         {
3303                                 /* Notice immunity */
3304                                 if (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)
3305                                 {
3306                                         if (is_original_ap_and_seen(m_ptr))
3307                                         {
3308                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK);
3309                                         }
3310                                 }
3311
3312                                 /* Otherwise, take the damage */
3313                                 else
3314                                 {
3315                                         if (mult < 17) mult = 17;
3316                                 }
3317                         }
3318
3319                         if ((have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (p_ptr->msp / 30)))
3320                         {
3321                                 p_ptr->csp -= (1+(p_ptr->msp / 30));
3322                                 p_ptr->redraw |= (PR_MANA);
3323                                 mult = mult * 5 / 2;
3324                         }
3325                         break;
3326                 }
3327         }
3328
3329         /* Return the total damage */
3330         return (tdam * mult / 10);
3331 }
3332
3333
3334 /*
3335  * Fire an object from the pack or floor.
3336  *
3337  * You may only fire items that "match" your missile launcher.
3338  *
3339  * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
3340  *
3341  * See "calc_bonuses()" for more calculations and such.
3342  *
3343  * Note that "firing" a missile is MUCH better than "throwing" it.
3344  *
3345  * Note: "unseen" monsters are very hard to hit.
3346  *
3347  * Objects are more likely to break if they "attempt" to hit a monster.
3348  *
3349  * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
3350  *
3351  * The "extra shot" code works by decreasing the amount of energy
3352  * required to make each shot, spreading the shots out over time.
3353  *
3354  * Note that when firing missiles, the launcher multiplier is applied
3355  * after all the bonuses are added in, making multipliers very useful.
3356  *
3357  * Note that Bows of "Extra Might" get extra range and an extra bonus
3358  * for the damage multiplier.
3359  *
3360  * Note that Bows of "Extra Shots" give an extra shot.
3361  */
3362 void do_cmd_fire_aux(int item, object_type *j_ptr)
3363 {
3364         int dir;
3365         int j, y, x, ny, nx, ty, tx, prev_y, prev_x;
3366         int tdam, tdis, thits, tmul;
3367         int bonus, chance;
3368         int cur_dis, visible;
3369
3370         object_type forge;
3371         object_type *q_ptr;
3372
3373         object_type *o_ptr;
3374
3375         bool hit_body = FALSE;
3376
3377         char o_name[MAX_NLEN];
3378
3379         int msec = delay_factor * delay_factor * delay_factor;
3380
3381         /* STICK TO */
3382         bool stick_to = FALSE;
3383
3384         /* Access the item (if in the pack) */
3385         if (item >= 0)
3386         {
3387                 o_ptr = &inventory[item];
3388         }
3389         else
3390         {
3391                 o_ptr = &o_list[0 - item];
3392         }
3393
3394         /* Describe the object */
3395         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
3396
3397
3398         /* Use the proper number of shots */
3399         thits = p_ptr->num_fire;
3400
3401         /* Use a base distance */
3402         tdis = 10;
3403
3404         /* Base damage from thrown object plus launcher bonus */
3405         tdam = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
3406
3407         /* Actually "fire" the object */
3408         bonus = (p_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
3409         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
3410                 chance = (p_ptr->skill_thb + (p_ptr->weapon_exp[0][j_ptr->sval] / 400 + bonus) * BTH_PLUS_ADJ);
3411         else
3412                 chance = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
3413
3414         energy_use = bow_energy(j_ptr->sval);
3415         tmul = bow_tmul(j_ptr->sval);
3416
3417         /* Get extra "power" from "extra might" */
3418         if (p_ptr->xtra_might) tmul++;
3419
3420         tmul = tmul * (100 + (int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
3421
3422         /* Boost the damage */
3423         tdam *= tmul;
3424         tdam /= 100;
3425
3426         /* Base range */
3427         tdis = 10 + tmul/40;
3428         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
3429                 tdis -= 5;
3430
3431         project_length = tdis + 1;
3432
3433         /* Get a direction (or cancel) */
3434         if (!get_aim_dir(&dir))
3435         {
3436                 energy_use = 0;
3437
3438                 /* need not to reset project_length (already did)*/
3439
3440                 return;
3441         }
3442
3443         /* Start at the player */
3444         y = py;
3445         x = px;
3446
3447         /* Predict the "target" location */
3448         tx = px + 99 * ddx[dir];
3449         ty = py + 99 * ddy[dir];
3450
3451         /* Check for "target request" */
3452         if ((dir == 5) && target_okay())
3453         {
3454                 tx = target_col;
3455                 ty = target_row;
3456         }
3457
3458         project_length = 0; /* reset to default */
3459
3460         /* Don't shoot at my feet */
3461         if (tx == px && ty == py)
3462         {
3463                 energy_use = 0;
3464
3465                 /* project_length is already reset to 0 */
3466
3467                 return;
3468         }
3469
3470
3471         /* Get local object */
3472         q_ptr = &forge;
3473
3474         /* Obtain a local object */
3475         object_copy(q_ptr, o_ptr);
3476
3477         /* Single object */
3478         q_ptr->number = 1;
3479
3480         /* Reduce and describe inventory */
3481         if (item >= 0)
3482         {
3483                 inven_item_increase(item, -1);
3484                 inven_item_describe(item);
3485                 inven_item_optimize(item);
3486         }
3487
3488         /* Reduce and describe floor item */
3489         else
3490         {
3491                 floor_item_increase(0 - item, -1);
3492                 floor_item_optimize(0 - item);
3493         }
3494
3495
3496         /* Sound */
3497         sound(SOUND_SHOOT);
3498
3499
3500         /* Take a (partial) turn */
3501         energy_use = (energy_use / thits);
3502
3503
3504         /* Hack -- Handle stuff */
3505         handle_stuff();
3506
3507         /* Save the old location */
3508         prev_y = y;
3509         prev_x = x;
3510
3511         /* Travel until stopped */
3512         for (cur_dis = 0; cur_dis <= tdis; )
3513         {
3514                 /* Hack -- Stop at the target */
3515                 if ((y == ty) && (x == tx)) break;
3516
3517                 /* Calculate the new location (see "project()") */
3518                 ny = y;
3519                 nx = x;
3520                 mmove2(&ny, &nx, py, px, ty, tx);
3521
3522                 /* Stopped by walls/doors */
3523                 if (!cave_have_flag_bold(ny, nx, FF_PROJECT) && !cave[ny][nx].m_idx) break;
3524
3525                 /* Advance the distance */
3526                 cur_dis++;
3527
3528
3529                 /* The player can see the (on screen) missile */
3530                 if (panel_contains(ny, nx) && player_can_see_bold(ny, nx))
3531                 {
3532                         char c = object_char(q_ptr);
3533                         byte a = object_attr(q_ptr);
3534
3535                         /* Draw, Hilite, Fresh, Pause, Erase */
3536                         print_rel(c, a, ny, nx);
3537                         move_cursor_relative(ny, nx);
3538                         Term_fresh();
3539                         Term_xtra(TERM_XTRA_DELAY, msec);
3540                         lite_spot(ny, nx);
3541                         Term_fresh();
3542                 }
3543
3544                 /* The player cannot see the missile */
3545                 else
3546                 {
3547                         /* Pause anyway, for consistancy */
3548                         Term_xtra(TERM_XTRA_DELAY, msec);
3549                 }
3550
3551                 /* Save the old location */
3552                 prev_y = y;
3553                 prev_x = x;
3554
3555                 /* Save the new location */
3556                 x = nx;
3557                 y = ny;
3558
3559
3560                 /* Monster here, Try to hit it */
3561                 if (cave[y][x].m_idx)
3562                 {
3563                         cave_type *c_ptr = &cave[y][x];
3564
3565                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
3566                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
3567
3568                         /* Check the visibility */
3569                         visible = m_ptr->ml;
3570
3571                         /* Note the collision */
3572                         hit_body = TRUE;
3573
3574                         if (m_ptr->csleep)
3575                         {
3576                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_COMPASSION, -1);
3577                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_HONOUR, -1);
3578                         }
3579
3580                         if ((r_ptr->level + 10) > p_ptr->lev)
3581                         {
3582                                 int now_exp = p_ptr->weapon_exp[0][j_ptr->sval];
3583                                 if (now_exp < s_info[p_ptr->pclass].w_max[0][j_ptr->sval])
3584                                 {
3585                                         int amount = 0;
3586                                         if (now_exp < WEAPON_EXP_BEGINNER) amount = 80;
3587                                         else if (now_exp < WEAPON_EXP_SKILLED) amount = 25;
3588                                         else if ((now_exp < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19)) amount = 10;
3589                                         else if (p_ptr->lev > 34) amount = 2;
3590                                         p_ptr->weapon_exp[0][j_ptr->sval] += amount;
3591                                         p_ptr->update |= (PU_BONUS);
3592                                 }
3593                         }
3594
3595                         if (p_ptr->riding)
3596                         {
3597                                 if ((p_ptr->skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING])
3598                                         && ((p_ptr->skill_exp[GINOU_RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 < r_info[m_list[p_ptr->riding].r_idx].level)
3599                                         && one_in_(2))
3600                                 {
3601                                         p_ptr->skill_exp[GINOU_RIDING] += 1;
3602                                         p_ptr->update |= (PU_BONUS);
3603                                 }
3604                         }
3605
3606                         /* Did we hit it (penalize range) */
3607                         if (test_hit_fire(chance - cur_dis, r_ptr->ac, m_ptr->ml))
3608                         {
3609                                 bool fear = FALSE;
3610
3611                                 /* Handle unseen monster */
3612                                 if (!visible)
3613                                 {
3614                                         /* Invisible monster */
3615 #ifdef JP
3616                                         msg_format("%s¤¬Å¨¤òÊ᪤·¤¿¡£", o_name);
3617 #else
3618                                         msg_format("The %s finds a mark.", o_name);
3619 #endif
3620
3621                                 }
3622
3623                                 /* Handle visible monster */
3624                                 else
3625                                 {
3626                                         char m_name[80];
3627
3628                                         /* Get "the monster" or "it" */
3629                                         monster_desc(m_name, m_ptr, 0);
3630
3631                                         /* Message */
3632 #ifdef JP
3633                                         msg_format("%s¤¬%s¤ËÌ¿Ã椷¤¿¡£", o_name, m_name);
3634 #else
3635                                         msg_format("The %s hits %s.", o_name, m_name);
3636 #endif
3637
3638
3639                                         /* Hack -- Track this monster race */
3640                                         if (m_ptr->ml) monster_race_track(m_ptr->ap_r_idx);
3641
3642                                         /* Hack -- Track this monster */
3643                                         if (m_ptr->ml) health_track(c_ptr->m_idx);
3644                                 }
3645
3646                                 /* Apply special damage XXX XXX XXX */
3647                                 tdam = tot_dam_aux_shot(q_ptr, tdam, m_ptr);
3648                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, tdam);
3649
3650                                 /* No negative damage */
3651                                 if (tdam < 0) tdam = 0;
3652
3653                                 /* Modify the damage */
3654                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
3655
3656                                 /* Complex message */
3657                                 if (p_ptr->wizard || cheat_xtra)
3658                                 {
3659 #ifdef JP
3660                                         msg_format("%d/%d ¤Î¥À¥á¡¼¥¸¤òÍ¿¤¨¤¿¡£",
3661                                                    tdam, m_ptr->hp);
3662 #else
3663                                         msg_format("You do %d (out of %d) damage.",
3664                                                    tdam, m_ptr->hp);
3665 #endif
3666
3667                                 }
3668
3669                                 /* Hit the monster, check for death */
3670                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
3671                                 {
3672                                         /* Dead monster */
3673                                 }
3674
3675                                 /* No death */
3676                                 else
3677                                 {
3678                                         /* STICK TO */
3679                                         if (object_is_fixed_artifact(q_ptr))
3680                                         {
3681                                                 char m_name[80];
3682
3683                                                 monster_desc(m_name, m_ptr, 0);
3684
3685                                                 stick_to = TRUE;
3686 #ifdef JP
3687                                                 msg_format("%s¤Ï%s¤ËÆͤ­»É¤µ¤Ã¤¿¡ª",o_name, m_name);
3688 #else
3689                                                 msg_format("%^s have stuck into %s!",o_name, m_name);
3690 #endif
3691                                         }
3692
3693                                         /* Message */
3694                                         message_pain(c_ptr->m_idx, tdam);
3695
3696                                         /* Anger the monster */
3697                                         if (tdam > 0) anger_monster(m_ptr);
3698
3699                                         /* Take note */
3700                                         if (fear && m_ptr->ml)
3701                                         {
3702                                                 char m_name[80];
3703
3704                                                 /* Sound */
3705                                                 sound(SOUND_FLEE);
3706
3707                                                 /* Get the monster name (or "it") */
3708                                                 monster_desc(m_name, m_ptr, 0);
3709
3710                                                 /* Message */
3711 #ifdef JP
3712                                                 msg_format("%^s¤Ï¶²Éݤ·¤Æƨ¤²½Ð¤·¤¿¡ª", m_name);
3713 #else
3714                                                 msg_format("%^s flees in terror!", m_name);
3715 #endif
3716
3717                                         }
3718                                         if (!projectable(m_ptr->fy, m_ptr->fx, py, px))
3719                                         {
3720                                                 set_target(m_ptr, py, px);
3721                                         }
3722                                 }
3723                         }
3724
3725                         /* Stop looking */
3726                         break;
3727                 }
3728         }
3729
3730         /* Chance of breakage (during attacks) */
3731         j = (hit_body ? breakage_chance(q_ptr) : 0);
3732
3733         if (stick_to)
3734         {
3735                 int m_idx = cave[y][x].m_idx;
3736                 monster_type *m_ptr = &m_list[m_idx];
3737                 int o_idx = o_pop();
3738
3739                 if (!o_idx)
3740                 {
3741 #ifdef JP
3742                         msg_format("%s¤Ï¤É¤³¤«¤Ø¹Ô¤Ã¤¿¡£", o_name);
3743 #else
3744                         msg_format("The %s have gone to somewhere.", o_name);
3745 #endif
3746                         if (object_is_fixed_artifact(q_ptr))
3747                         {
3748                                 a_info[j_ptr->name1].cur_num = 0;
3749                         }
3750                         return;
3751                 }
3752
3753                 o_ptr = &o_list[o_idx];
3754                 object_copy(o_ptr, q_ptr);
3755
3756                 /* Forget mark */
3757                 o_ptr->marked = 0;
3758
3759                 /* Forget location */
3760                 o_ptr->iy = o_ptr->ix = 0;
3761
3762                 /* Memorize monster */
3763                 o_ptr->held_m_idx = m_idx;
3764
3765                 /* Build a stack */
3766                 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3767
3768                 /* Carry object */
3769                 m_ptr->hold_o_idx = o_idx;
3770         }
3771         else if (cave_have_flag_bold(y, x, FF_PROJECT))
3772         {
3773                 /* Drop (or break) near that location */
3774                 (void)drop_near(q_ptr, j, y, x);
3775         }
3776         else
3777         {
3778                 /* Drop (or break) near that location */
3779                 (void)drop_near(q_ptr, j, prev_y, prev_x);
3780         }
3781 }
3782
3783
3784 void do_cmd_fire(void)
3785 {
3786         int item;
3787         object_type *j_ptr;
3788         cptr q, s;
3789
3790         /* Get the "bow" (if any) */
3791         j_ptr = &inventory[INVEN_BOW];
3792
3793         /* Require a launcher */
3794         if (!j_ptr->tval)
3795         {
3796 #ifdef JP
3797                 msg_print("¼Í·âÍѤÎÉð´ï¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£");
3798 #else
3799                 msg_print("You have nothing to fire with.");
3800 #endif
3801                 flush();
3802                 return;
3803         }
3804
3805         if (j_ptr->sval == SV_CRIMSON)
3806         {
3807 #ifdef JP
3808                 msg_print("¤³¤ÎÉð´ï¤Ïȯư¤·¤Æ»È¤¦¤â¤Î¤Î¤è¤¦¤À¡£");
3809 #else
3810                 msg_print("Do activate.");
3811 #endif
3812                 flush();
3813                 return;
3814         }
3815
3816
3817         if (p_ptr->special_defense & KATA_MUSOU)
3818         {
3819                 set_action(ACTION_NONE);
3820         }
3821
3822         /* Require proper missile */
3823         item_tester_tval = p_ptr->tval_ammo;
3824
3825         /* Get an item */
3826 #ifdef JP
3827         q = "¤É¤ì¤ò·â¤Á¤Þ¤¹¤«? ";
3828         s = "ȯ¼Í¤µ¤ì¤ë¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
3829 #else
3830         q = "Fire which item? ";
3831         s = "You have nothing to fire.";
3832 #endif
3833
3834         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
3835         {
3836                 flush();
3837                 return;
3838         }
3839
3840         /* Fire the item */
3841         do_cmd_fire_aux(item, j_ptr);
3842 }
3843
3844
3845 static bool item_tester_hook_boomerang(object_type *o_ptr)
3846 {
3847         if ((o_ptr->tval==TV_DIGGING) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM) || (o_ptr->tval == TV_HAFTED)) return (TRUE);
3848
3849         /* Assume not */
3850         return (FALSE);
3851 }
3852
3853
3854 /*
3855  * Throw an object from the pack or floor.
3856  *
3857  * Note: "unseen" monsters are very hard to hit.
3858  *
3859  * Should throwing a weapon do full damage?  Should it allow the magic
3860  * to hit bonus of the weapon to have an effect?  Should it ever cause
3861  * the item to be destroyed?  Should it do any damage at all?
3862  */
3863 bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
3864 {
3865         int dir, item;
3866         int i, j, y, x, ty, tx, prev_y, prev_x;
3867         int ny[19], nx[19];
3868         int chance, tdam, tdis;
3869         int mul, div;
3870         int cur_dis, visible;
3871
3872         object_type forge;
3873         object_type *q_ptr;
3874
3875         object_type *o_ptr;
3876
3877         bool hit_body = FALSE;
3878         bool hit_wall = FALSE;
3879         bool equiped_item = FALSE;
3880         bool return_when_thrown = FALSE;
3881
3882         char o_name[MAX_NLEN];
3883
3884         int msec = delay_factor * delay_factor * delay_factor;
3885
3886         u32b flgs[TR_FLAG_SIZE];
3887         cptr q, s;
3888         bool come_back = FALSE;
3889         bool do_drop = TRUE;
3890
3891
3892         if (p_ptr->special_defense & KATA_MUSOU)
3893         {
3894                 set_action(ACTION_NONE);
3895         }
3896
3897         if (shuriken)
3898         {
3899                 item = shuriken;
3900         }
3901         else if (boomerang)
3902         {
3903                 if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
3904                 {
3905                         item_tester_hook = item_tester_hook_boomerang;
3906 #ifdef JP
3907                         q = "¤É¤ÎÉð´ï¤òÅꤲ¤Þ¤¹¤«? ";
3908                         s = "Åꤲ¤ëÉð´ï¤¬¤Ê¤¤¡£";
3909 #else
3910                         q = "Throw which item? ";
3911                         s = "You have nothing to throw.";
3912 #endif
3913
3914                         if (!get_item(&item, q, s, (USE_EQUIP)))
3915                         {
3916                                 flush();
3917                                 return FALSE;
3918                         }
3919                 }
3920                 else if (buki_motteruka(INVEN_LARM)) item = INVEN_LARM;
3921                 else item = INVEN_RARM;
3922         }
3923         else
3924         {
3925                 /* Get an item */
3926 #ifdef JP
3927                 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅꤲ¤Þ¤¹¤«? ";
3928                 s = "Åꤲ¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
3929 #else
3930                 q = "Throw which item? ";
3931                 s = "You have nothing to throw.";
3932 #endif
3933
3934                 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP)))
3935                 {
3936                         flush();
3937                         return FALSE;
3938                 }
3939         }
3940
3941         /* Access the item (if in the pack) */
3942         if (item >= 0)
3943         {
3944                 o_ptr = &inventory[item];
3945         }
3946         else
3947         {
3948                 o_ptr = &o_list[0 - item];
3949         }
3950
3951
3952         /* Item is cursed */
3953         if (object_is_cursed(o_ptr) && (item >= INVEN_RARM))
3954         {
3955                 /* Oops */
3956 #ifdef JP
3957                 msg_print("¤Õ¡¼¤à¡¢¤É¤¦¤ä¤é¼ö¤ï¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£");
3958 #else
3959                 msg_print("Hmmm, it seems to be cursed.");
3960 #endif
3961
3962                 /* Nope */
3963                 return FALSE;
3964         }
3965
3966         if (p_ptr->inside_arena && !boomerang)
3967         {
3968                 if (o_ptr->tval != TV_SPIKE)
3969                 {
3970 #ifdef JP
3971                         msg_print("¥¢¥ê¡¼¥Ê¤Ç¤Ï¥¢¥¤¥Æ¥à¤ò»È¤¨¤Ê¤¤¡ª");
3972 #else
3973                         msg_print("You're in the arena now. This is hand-to-hand!");
3974 #endif
3975                         msg_print(NULL);
3976
3977                         /* Nope */
3978                         return FALSE;
3979                 }
3980         }
3981
3982         /* Get local object */
3983         q_ptr = &forge;
3984
3985         /* Obtain a local object */
3986         object_copy(q_ptr, o_ptr);
3987
3988         /* Extract the thrown object's flags. */
3989         object_flags(q_ptr, flgs);
3990
3991         /* Distribute the charges of rods/wands between the stacks */
3992         distribute_charges(o_ptr, q_ptr, 1);
3993
3994         /* Single object */
3995         q_ptr->number = 1;
3996
3997         /* Description */
3998         object_desc(o_name, q_ptr, OD_OMIT_PREFIX);
3999
4000         if (p_ptr->mighty_throw) mult += 3;
4001
4002         /* Extract a "distance multiplier" */
4003         /* Changed for 'launcher' mutation */
4004         mul = 10 + 2 * (mult - 1);
4005
4006         /* Enforce a minimum "weight" of one pound */
4007         div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
4008         if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
4009
4010         /* Hack -- Distance -- Reward strength, penalize weight */
4011         tdis = (adj_str_blow[p_ptr->stat_ind[A_STR]] + 20) * mul / div;
4012
4013         /* Max distance of 10-18 */
4014         if (tdis > mul) tdis = mul;
4015
4016         if (shuriken)
4017         {
4018                 ty = randint0(101)-50+py;
4019                 tx = randint0(101)-50+px;
4020         }
4021         else
4022         {
4023                 project_length = tdis + 1;
4024
4025                 /* Get a direction (or cancel) */
4026                 if (!get_aim_dir(&dir)) return FALSE;
4027
4028                 /* Predict the "target" location */
4029                 tx = px + 99 * ddx[dir];
4030                 ty = py + 99 * ddy[dir];
4031
4032                 /* Check for "target request" */
4033                 if ((dir == 5) && target_okay())
4034                 {
4035                         tx = target_col;
4036                         ty = target_row;
4037                 }
4038
4039                 project_length = 0;  /* reset to default */
4040         }
4041
4042         if ((q_ptr->name1 == ART_MJOLLNIR) ||
4043             (q_ptr->name1 == ART_AEGISFANG) || boomerang)
4044                 return_when_thrown = TRUE;
4045
4046         /* Reduce and describe inventory */
4047         if (item >= 0)
4048         {
4049                 inven_item_increase(item, -1);
4050                 if (!return_when_thrown)
4051                         inven_item_describe(item);
4052                 inven_item_optimize(item);
4053         }
4054
4055         /* Reduce and describe floor item */
4056         else
4057         {
4058                 floor_item_increase(0 - item, -1);
4059                 floor_item_optimize(0 - item);
4060         }
4061         if (item >= INVEN_RARM)
4062         {
4063                 equiped_item = TRUE;
4064                 p_ptr->redraw |= (PR_EQUIPPY);
4065         }
4066
4067         /* Take a turn */
4068         energy_use = 100;
4069
4070         /* Rogue and Ninja gets bonus */
4071         if ((p_ptr->pclass == CLASS_ROGUE) || (p_ptr->pclass == CLASS_NINJA))
4072                 energy_use -= p_ptr->lev;
4073
4074         /* Start at the player */
4075         y = py;
4076         x = px;
4077
4078
4079         /* Hack -- Handle stuff */
4080         handle_stuff();
4081
4082         if ((p_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
4083         else shuriken = FALSE;
4084
4085         /* Chance of hitting */
4086         if (have_flag(flgs, TR_THROW)) chance = ((p_ptr->skill_tht) +
4087                 ((p_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
4088         else chance = (p_ptr->skill_tht + (p_ptr->to_h_b * BTH_PLUS_ADJ));
4089
4090         if (shuriken) chance *= 2;
4091
4092         /* Save the old location */
4093         prev_y = y;
4094         prev_x = x;
4095
4096         /* Travel until stopped */
4097         for (cur_dis = 0; cur_dis <= tdis; )
4098         {
4099                 /* Hack -- Stop at the target */
4100                 if ((y == ty) && (x == tx)) break;
4101
4102                 /* Calculate the new location (see "project()") */
4103                 ny[cur_dis] = y;
4104                 nx[cur_dis] = x;
4105                 mmove2(&ny[cur_dis], &nx[cur_dis], py, px, ty, tx);
4106
4107                 /* Stopped by walls/doors */
4108                 if (!cave_have_flag_bold(ny[cur_dis], nx[cur_dis], FF_PROJECT))
4109                 {
4110                         hit_wall = TRUE;
4111                         if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !cave[ny[cur_dis]][nx[cur_dis]].m_idx) break;
4112                 }
4113
4114                 /* The player can see the (on screen) missile */
4115                 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(ny[cur_dis], nx[cur_dis]))
4116                 {
4117                         char c = object_char(q_ptr);
4118                         byte a = object_attr(q_ptr);
4119
4120                         /* Draw, Hilite, Fresh, Pause, Erase */
4121                         print_rel(c, a, ny[cur_dis], nx[cur_dis]);
4122                         move_cursor_relative(ny[cur_dis], nx[cur_dis]);
4123                         Term_fresh();
4124                         Term_xtra(TERM_XTRA_DELAY, msec);
4125                         lite_spot(ny[cur_dis], nx[cur_dis]);
4126                         Term_fresh();
4127                 }
4128
4129                 /* The player cannot see the missile */
4130                 else
4131                 {
4132                         /* Pause anyway, for consistancy */
4133                         Term_xtra(TERM_XTRA_DELAY, msec);
4134                 }
4135
4136                 /* Save the old location */
4137                 prev_y = y;
4138                 prev_x = x;
4139
4140                 /* Save the new location */
4141                 x = nx[cur_dis];
4142                 y = ny[cur_dis];
4143
4144                 /* Advance the distance */
4145                 cur_dis++;
4146
4147                 /* Monster here, Try to hit it */
4148                 if (cave[y][x].m_idx)
4149                 {
4150                         cave_type *c_ptr = &cave[y][x];
4151
4152                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
4153                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4154
4155                         /* Check the visibility */
4156                         visible = m_ptr->ml;
4157
4158                         /* Note the collision */
4159                         hit_body = TRUE;
4160
4161                         /* Did we hit it (penalize range) */
4162                         if (test_hit_fire(chance - cur_dis, r_ptr->ac, m_ptr->ml))
4163                         {
4164                                 bool fear = FALSE;
4165
4166                                 /* Handle unseen monster */
4167                                 if (!visible)
4168                                 {
4169                                         /* Invisible monster */
4170 #ifdef JP
4171                                         msg_format("%s¤¬Å¨¤òÊ᪤·¤¿¡£", o_name);
4172 #else
4173                                         msg_format("The %s finds a mark.", o_name);
4174 #endif
4175
4176                                 }
4177
4178                                 /* Handle visible monster */
4179                                 else
4180                                 {
4181                                         char m_name[80];
4182
4183                                         /* Get "the monster" or "it" */
4184                                         monster_desc(m_name, m_ptr, 0);
4185
4186                                         /* Message */
4187 #ifdef JP
4188                                         msg_format("%s¤¬%s¤ËÌ¿Ã椷¤¿¡£", o_name, m_name);
4189 #else
4190                                         msg_format("The %s hits %s.", o_name, m_name);
4191 #endif
4192
4193
4194                                         /* Hack -- Track this monster race */
4195                                         if (m_ptr->ml) monster_race_track(m_ptr->ap_r_idx);
4196
4197                                         /* Hack -- Track this monster */
4198                                         if (m_ptr->ml) health_track(c_ptr->m_idx);
4199                                 }
4200
4201                                 /* Hack -- Base damage from thrown object */
4202                                 tdam = damroll(q_ptr->dd, q_ptr->ds);
4203                                 /* Apply special damage XXX XXX XXX */
4204                                 tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0, TRUE);
4205                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, tdam);
4206                                 if (q_ptr->to_d > 0)
4207                                         tdam += q_ptr->to_d;
4208                                 else
4209                                         tdam += -q_ptr->to_d;
4210
4211                                 if (boomerang)
4212                                 {
4213                                         tdam *= (mult+p_ptr->num_blow[item - INVEN_RARM]);
4214                                         tdam += p_ptr->to_d_m;
4215                                 }
4216                                 else if (have_flag(flgs, TR_THROW))
4217                                 {
4218                                         tdam *= (3+mult);
4219                                         tdam += p_ptr->to_d_m;
4220                                 }
4221                                 else
4222                                 {
4223                                         tdam *= mult;
4224                                 }
4225                                 if (shuriken)
4226                                 {
4227                                         tdam += ((p_ptr->lev+30)*(p_ptr->lev+30)-900)/55;
4228                                 }
4229
4230                                 /* No negative damage */
4231                                 if (tdam < 0) tdam = 0;
4232
4233                                 /* Modify the damage */
4234                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
4235
4236                                 /* Complex message */
4237                                 if (p_ptr->wizard)
4238                                 {
4239 #ifdef JP
4240                                         msg_format("%d/%d¤Î¥À¥á¡¼¥¸¤òÍ¿¤¨¤¿¡£",
4241                                                    tdam, m_ptr->hp);
4242 #else
4243                                         msg_format("You do %d (out of %d) damage.",
4244                                                    tdam, m_ptr->hp);
4245 #endif
4246
4247                                 }
4248
4249                                 /* Hit the monster, check for death */
4250                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
4251                                 {
4252                                         /* Dead monster */
4253                                 }
4254
4255                                 /* No death */
4256                                 else
4257                                 {
4258                                         /* Message */
4259                                         message_pain(c_ptr->m_idx, tdam);
4260
4261                                         /* Anger the monster */
4262                                         if ((tdam > 0) && !object_is_potion(q_ptr))
4263                                                 anger_monster(m_ptr);
4264
4265                                         /* Take note */
4266                                         if (fear && m_ptr->ml)
4267                                         {
4268                                                 char m_name[80];
4269
4270                                                 /* Sound */
4271                                                 sound(SOUND_FLEE);
4272
4273                                                 /* Get the monster name (or "it") */
4274                                                 monster_desc(m_name, m_ptr, 0);
4275
4276                                                 /* Message */
4277 #ifdef JP
4278                                                 msg_format("%^s¤Ï¶²Éݤ·¤Æƨ¤²½Ð¤·¤¿¡ª", m_name);
4279 #else
4280                                                 msg_format("%^s flees in terror!", m_name);
4281 #endif
4282
4283                                         }
4284                                 }
4285                         }
4286
4287                         /* Stop looking */
4288                         break;
4289                 }
4290         }
4291
4292         /* Chance of breakage (during attacks) */
4293         j = (hit_body ? breakage_chance(q_ptr) : 0);
4294
4295         /* Figurines transform */
4296         if ((q_ptr->tval == TV_FIGURINE) && !(p_ptr->inside_arena))
4297         {
4298                 j = 100;
4299
4300                 if (!(summon_named_creature(0, y, x, q_ptr->pval,
4301                                             !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
4302 #ifdef JP
4303 msg_print("¿Í·Á¤ÏDZ¤¸¶Ê¤¬¤êºÕ¤±»¶¤Ã¤Æ¤·¤Þ¤Ã¤¿¡ª");
4304 #else
4305                         msg_print("The Figurine writhes and then shatters.");
4306 #endif
4307
4308                 else if (object_is_cursed(q_ptr))
4309 #ifdef JP
4310 msg_print("¤³¤ì¤Ï¤¢¤Þ¤êÎɤ¯¤Ê¤¤µ¤¤¬¤¹¤ë¡£");
4311 #else
4312                         msg_print("You have a bad feeling about this.");
4313 #endif
4314
4315         }
4316
4317
4318         /* Potions smash open */
4319         if (object_is_potion(q_ptr))
4320         {
4321                 if (hit_body || hit_wall || (randint1(100) < j))
4322                 {
4323                         /* Message */
4324 #ifdef JP
4325                         msg_format("%s¤ÏºÕ¤±»¶¤Ã¤¿¡ª", o_name);
4326 #else
4327                         msg_format("The %s shatters!", o_name);
4328 #endif
4329
4330
4331                         if (potion_smash_effect(0, y, x, q_ptr->k_idx))
4332                         {
4333                                 monster_type *m_ptr = &m_list[cave[y][x].m_idx];
4334
4335                                 /* ToDo (Robert): fix the invulnerability */
4336                                 if (cave[y][x].m_idx &&
4337                                     is_friendly(&m_list[cave[y][x].m_idx]) &&
4338                                     !(m_ptr->invulner))
4339                                 {
4340                                         char m_name[80];
4341                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
4342 #ifdef JP
4343                                         msg_format("%s¤ÏÅܤä¿¡ª", m_name);
4344 #else
4345                                         msg_format("%^s gets angry!", m_name);
4346 #endif
4347
4348                                         set_hostile(&m_list[cave[y][x].m_idx]);
4349                                 }
4350                         }
4351                         do_drop = FALSE;
4352                 }
4353                 else
4354                 {
4355                         j = 0;
4356                 }
4357         }
4358
4359         if (return_when_thrown)
4360         {
4361                 int back_chance = randint1(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4362                 char o2_name[MAX_NLEN];
4363                 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
4364
4365                 j = -1;
4366                 if (boomerang) back_chance += 4+randint1(5);
4367                 if (super_boomerang) back_chance += 100;
4368                 object_desc(o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4369
4370                 if((back_chance > 30) && (!one_in_(100) || super_boomerang))
4371                 {
4372                         for (i = cur_dis - 1; i > 0; i--)
4373                         {
4374                                 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(ny[i], nx[i]))
4375                                 {
4376                                         char c = object_char(q_ptr);
4377                                         byte a = object_attr(q_ptr);
4378
4379                                         /* Draw, Hilite, Fresh, Pause, Erase */
4380                                         print_rel(c, a, ny[i], nx[i]);
4381                                         move_cursor_relative(ny[i], nx[i]);
4382                                         Term_fresh();
4383                                         Term_xtra(TERM_XTRA_DELAY, msec);
4384                                         lite_spot(ny[i], nx[i]);
4385                                         Term_fresh();
4386                                 }
4387                                 else
4388                                 {
4389                                         /* Pause anyway, for consistancy */
4390                                         Term_xtra(TERM_XTRA_DELAY, msec);
4391                                 }
4392                         }
4393                         if((back_chance > 37) && !p_ptr->blind && (item >= 0))
4394                         {
4395 #ifdef JP
4396                                 msg_format("%s¤¬¼ê¸µ¤ËÊ֤äƤ­¤¿¡£", o2_name);
4397 #else
4398                                 msg_format("%s comes back to you.", o2_name);
4399 #endif
4400                                 come_back = TRUE;
4401                         }
4402                         else
4403                         {
4404                                 if (item >= 0)
4405                                 {
4406 #ifdef JP
4407                                         msg_format("%s¤ò¼õ¤±Â»¤Í¤¿¡ª", o2_name);
4408 #else
4409                                         msg_format("%s backs, but you can't catch!", o2_name);
4410 #endif
4411                                 }
4412                                 else
4413                                 {
4414 #ifdef JP
4415                                         msg_format("%s¤¬Ê֤äƤ­¤¿¡£", o2_name);
4416 #else
4417                                         msg_format("%s comes back.", o2_name);
4418 #endif
4419                                 }
4420                                 y = py;
4421                                 x = px;
4422                         }
4423                 }
4424                 else
4425                 {
4426 #ifdef JP
4427                         msg_format("%s¤¬Ê֤äƤ³¤Ê¤«¤Ã¤¿¡ª", o2_name);
4428 #else
4429                         msg_format("%s doesn't back!", o2_name);
4430 #endif
4431                 }
4432         }
4433
4434         if (come_back)
4435         {
4436                 if (item == INVEN_RARM || item == INVEN_LARM)
4437                 {
4438                         /* Access the wield slot */
4439                         o_ptr = &inventory[item];
4440
4441                         /* Wear the new stuff */
4442                         object_copy(o_ptr, q_ptr);
4443
4444                         /* Increase the weight */
4445                         p_ptr->total_weight += q_ptr->weight;
4446
4447                         /* Increment the equip counter by hand */
4448                         equip_cnt++;
4449
4450                         /* Recalculate bonuses */
4451                         p_ptr->update |= (PU_BONUS);
4452
4453                         /* Recalculate torch */
4454                         p_ptr->update |= (PU_TORCH);
4455
4456                         /* Recalculate mana XXX */
4457                         p_ptr->update |= (PU_MANA);
4458
4459                         /* Window stuff */
4460                         p_ptr->window |= (PW_EQUIP);
4461                 }
4462                 else
4463                 {
4464                         inven_carry(q_ptr);
4465                 }
4466                 do_drop = FALSE;
4467         }
4468         else if (equiped_item)
4469         {
4470                 kamaenaoshi(item);
4471                 calc_android_exp();
4472         }
4473
4474         /* Drop (or break) near that location */
4475         if (do_drop)
4476         {
4477                 if (cave_have_flag_bold(y, x, FF_PROJECT))
4478                 {
4479                         /* Drop (or break) near that location */
4480                         (void)drop_near(q_ptr, j, y, x);
4481                 }
4482                 else
4483                 {
4484                         /* Drop (or break) near that location */
4485                         (void)drop_near(q_ptr, j, prev_y, prev_x);
4486                 }
4487         }
4488
4489         return TRUE;
4490 }
4491
4492
4493 /*
4494  * Throw an object from the pack or floor.
4495  */
4496 void do_cmd_throw(void)
4497 {
4498         do_cmd_throw_aux(1, FALSE, 0);
4499 }