OSDN Git Service

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