OSDN Git Service

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