OSDN Git Service

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