OSDN Git Service

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