OSDN Git Service

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