OSDN Git Service

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