OSDN Git Service

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