OSDN Git Service

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