OSDN Git Service

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