OSDN Git Service

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