OSDN Git Service

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