OSDN Git Service

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