OSDN Git Service

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