OSDN Git Service

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