OSDN Git Service

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