OSDN Git Service

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