OSDN Git Service

deb3cc2f5ab695b28a5233e2804b3ccf71239ecd
[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 test 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  * @param y Âоݤò¹Ô¤¦¥Þ¥¹¤ÎYºÂɸ
1454  * @param x Âоݤò¹Ô¤¦¥Þ¥¹¤ÎXºÂɸ
1455  * @return ¤Ê¤·
1456  * @details
1457  * Unlocking a locked door/chest is worth one experience point.
1458  */
1459 void do_cmd_close(void)
1460 {
1461         int y, x, dir;
1462
1463         bool more = FALSE;
1464
1465         if (p_ptr->special_defense & KATA_MUSOU)
1466         {
1467                 set_action(ACTION_NONE);
1468         }
1469
1470 #ifdef ALLOW_EASY_OPEN /* TNB */
1471
1472         /* Option: Pick a direction */
1473         if (easy_open)
1474         {
1475                 /* Count open doors */
1476                 if (count_dt(&y, &x, is_open, FALSE) == 1)
1477                 {
1478                         command_dir = coords_to_dir(y, x);
1479                 }
1480         }
1481
1482 #endif /* ALLOW_EASY_OPEN -- TNB */
1483
1484         /* Allow repeated command */
1485         if (command_arg)
1486         {
1487                 /* Set repeat count */
1488                 command_rep = command_arg - 1;
1489
1490                 /* Redraw the state */
1491                 p_ptr->redraw |= (PR_STATE);
1492
1493                 /* Cancel the arg */
1494                 command_arg = 0;
1495         }
1496
1497         /* Get a "repeated" direction */
1498         if (get_rep_dir(&dir,FALSE))
1499         {
1500                 cave_type *c_ptr;
1501                 s16b feat;
1502
1503                 /* Get requested location */
1504                 y = py + ddy[dir];
1505                 x = px + ddx[dir];
1506
1507                 /* Get grid and contents */
1508                 c_ptr = &cave[y][x];
1509
1510                 /* Feature code (applying "mimic" field) */
1511                 feat = get_feat_mimic(c_ptr);
1512
1513                 /* Require open/broken door */
1514                 if (!have_flag(f_info[feat].flags, FF_CLOSE))
1515                 {
1516                         /* Message */
1517 #ifdef JP
1518                         msg_print("¤½¤³¤Ë¤ÏÊĤ¸¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
1519 #else
1520                         msg_print("You see nothing there to close.");
1521 #endif
1522                 }
1523
1524                 /* Monster in the way */
1525                 else if (c_ptr->m_idx)
1526                 {
1527                         /* Take a turn */
1528                         energy_use = 100;
1529
1530                         /* Message */
1531 #ifdef JP
1532                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
1533 #else
1534                         msg_print("There is a monster in the way!");
1535 #endif
1536
1537                         /* Attack */
1538                         py_attack(y, x, 0);
1539                 }
1540
1541                 /* Close the door */
1542                 else
1543                 {
1544                         /* Close the door */
1545                         more = do_cmd_close_aux(y, x);
1546                 }
1547         }
1548
1549         /* Cancel repeat unless we may continue */
1550         if (!more) disturb(0, 0);
1551 }
1552
1553
1554 /*!
1555  * @brief ¡Ö·¡¤ë¡×¥³¥Þ¥ó¥É¤ò³ºÅö¤Î¥Þ¥¹¤Ë¹Ô¤¨¤ë¤«¤ÎȽÄê¤È·ë²Ì¥á¥Ã¥»¡¼¥¸¤Îɽ¼¨ /
1556  * Determine if a given grid may be "tunneled"
1557  * @param y Âоݤò¹Ô¤¦¥Þ¥¹¤ÎYºÂɸ
1558  * @param x Âоݤò¹Ô¤¦¥Þ¥¹¤ÎXºÂɸ
1559  * @return 
1560  */
1561 static bool do_cmd_tunnel_test(int y, int x)
1562 {
1563         cave_type *c_ptr = &cave[y][x];
1564
1565         /* Must have knowledge */
1566         if (!(c_ptr->info & CAVE_MARK))
1567         {
1568                 /* Message */
1569 #ifdef JP
1570                 msg_print("¤½¤³¤Ë¤Ï²¿¤â¸«Åö¤¿¤é¤Ê¤¤¡£");
1571 #else
1572                 msg_print("You see nothing there.");
1573 #endif
1574
1575                 /* Nope */
1576                 return (FALSE);
1577         }
1578
1579         /* Must be a wall/door/etc */
1580         if (!cave_have_flag_grid(c_ptr, FF_TUNNEL))
1581         {
1582                 /* Message */
1583 #ifdef JP
1584                 msg_print("¤½¤³¤Ë¤Ï·¡¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
1585 #else
1586                 msg_print("You see nothing there to tunnel.");
1587 #endif
1588
1589                 /* Nope */
1590                 return (FALSE);
1591         }
1592
1593         /* Okay */
1594         return (TRUE);
1595 }
1596
1597
1598 /*!
1599  * @brief ¡Ö·¡¤ë¡×Æ°ºî¥³¥Þ¥ó¥É¤Î¥µ¥Ö¥ë¡¼¥Á¥ó /
1600  * Perform the basic "tunnel" command
1601  * @param y Âоݤò¹Ô¤¦¥Þ¥¹¤ÎYºÂɸ
1602  * @param x Âоݤò¹Ô¤¦¥Þ¥¹¤ÎXºÂɸ
1603  * @return ¼ÂºÝ¤Ë½èÍý¤¬¹Ô¤ï¤ì¤¿¾ì¹çTRUE¤òÊÖ¤¹¡£
1604  * @details
1605  * Assumes that no monster is blocking the destination
1606  * Do not use twall anymore
1607  * Returns TRUE if repeated commands may continue
1608  */
1609 static bool do_cmd_tunnel_aux(int y, int x)
1610 {
1611         cave_type *c_ptr;
1612         feature_type *f_ptr, *mimic_f_ptr;
1613         int power;
1614         cptr name;
1615         bool more = FALSE;
1616
1617         /* Verify legality */
1618         if (!do_cmd_tunnel_test(y, x)) return (FALSE);
1619
1620         /* Take a turn */
1621         energy_use = 100;
1622
1623         /* Get grid */
1624         c_ptr = &cave[y][x];
1625         f_ptr = &f_info[c_ptr->feat];
1626         power = f_ptr->power;
1627
1628         /* Feature code (applying "mimic" field) */
1629         mimic_f_ptr = &f_info[get_feat_mimic(c_ptr)];
1630
1631         name = f_name + mimic_f_ptr->name;
1632
1633         /* Sound */
1634         sound(SOUND_DIG);
1635
1636         if (have_flag(f_ptr->flags, FF_PERMANENT))
1637         {
1638                 /* Titanium */
1639                 if (have_flag(mimic_f_ptr->flags, FF_PERMANENT))
1640                 {
1641 #ifdef JP
1642                         msg_print("¤³¤Î´ä¤Ï¹Å¤¹¤®¤Æ·¡¤ì¤Ê¤¤¤è¤¦¤À¡£");
1643 #else
1644                         msg_print("This seems to be permanent rock.");
1645 #endif
1646                 }
1647
1648                 /* Map border (mimiccing Permanent wall) */
1649                 else
1650                 {
1651 #ifdef JP
1652                         msg_print("¤½¤³¤Ï·¡¤ì¤Ê¤¤!");
1653 #else
1654                         msg_print("You can't tunnel through that!");
1655 #endif
1656                 }
1657         }
1658
1659         /* Dig or tunnel */
1660         else if (have_flag(f_ptr->flags, FF_CAN_DIG))
1661         {
1662                 /* Dig */
1663                 if (p_ptr->skill_dig > randint0(20 * power))
1664                 {
1665                         /* Message */
1666 #ifdef JP
1667                         msg_format("%s¤ò¤¯¤º¤·¤¿¡£", name);
1668 #else
1669                         msg_format("You have removed the %s.", name);
1670 #endif
1671
1672                         /* Remove the feature */
1673                         cave_alter_feat(y, x, FF_TUNNEL);
1674
1675                         /* Update some things */
1676                         p_ptr->update |= (PU_FLOW);
1677                 }
1678                 else
1679                 {
1680                         /* Message, keep digging */
1681 #ifdef JP
1682                         msg_format("%s¤ò¤¯¤º¤·¤Æ¤¤¤ë¡£", name);
1683 #else
1684                         msg_format("You dig into the %s.", name);
1685 #endif
1686
1687                         more = TRUE;
1688                 }
1689         }
1690
1691         else
1692         {
1693                 bool tree = have_flag(mimic_f_ptr->flags, FF_TREE);
1694
1695                 /* Tunnel */
1696                 if (p_ptr->skill_dig > power + randint0(40 * power))
1697                 {
1698 #ifdef JP
1699                         if (tree) msg_format("%s¤òÀÚ¤êʧ¤Ã¤¿¡£", name);
1700                         else
1701                         {
1702                                 msg_print("·ê¤ò·¡¤ê½ª¤¨¤¿¡£");
1703                                 p_ptr->update |= (PU_FLOW);
1704                         }
1705 #else
1706                         if (tree) msg_format("You have cleared away the %s.", name);
1707                         else
1708                         {
1709                                 msg_print("You have finished the tunnel.");
1710                                 p_ptr->update |= (PU_FLOW);
1711                         }
1712 #endif
1713
1714                         /* Sound */
1715                         if (have_flag(f_ptr->flags, FF_GLASS)) sound(SOUND_GLASS);
1716
1717                         /* Remove the feature */
1718                         cave_alter_feat(y, x, FF_TUNNEL);
1719
1720                         chg_virtue(V_DILIGENCE, 1);
1721                         chg_virtue(V_NATURE, -1);
1722                 }
1723
1724                 /* Keep trying */
1725                 else
1726                 {
1727                         if (tree)
1728                         {
1729                                 /* We may continue chopping */
1730 #ifdef JP
1731                                 msg_format("%s¤òÀڤäƤ¤¤ë¡£", name);
1732 #else
1733                                 msg_format("You chop away at the %s.", name);
1734 #endif
1735                                 /* Occasional Search XXX XXX */
1736                                 if (randint0(100) < 25) search();
1737                         }
1738                         else
1739                         {
1740                                 /* We may continue tunelling */
1741 #ifdef JP
1742                                 msg_format("%s¤Ë·ê¤ò·¡¤Ã¤Æ¤¤¤ë¡£", name);
1743 #else
1744                                 msg_format("You tunnel into the %s.", name);
1745 #endif
1746                         }
1747
1748                         more = TRUE;
1749                 }
1750         }
1751
1752         if (is_hidden_door(c_ptr))
1753         {
1754                 /* Occasional Search XXX XXX */
1755                 if (randint0(100) < 25) search();
1756         }
1757
1758         /* Result */
1759         return more;
1760 }
1761
1762
1763 /*!
1764  * @brief ¡Ö·¡¤ë¡×Æ°ºî¥³¥Þ¥ó¥É¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
1765  * Tunnels through "walls" (including rubble and closed doors)
1766  * @return ¤Ê¤·
1767  * @details
1768  * <pre>
1769  * Note that you must tunnel in order to hit invisible monsters
1770  * in walls, though moving into walls still takes a turn anyway.
1771  *
1772  * Digging is very difficult without a "digger" weapon, but can be
1773  * accomplished by strong players using heavy weapons.
1774  * </pre>
1775  */
1776 void do_cmd_tunnel(void)
1777 {
1778         int                     y, x, dir;
1779
1780         cave_type       *c_ptr;
1781         s16b feat;
1782
1783         bool            more = FALSE;
1784
1785
1786         if (p_ptr->special_defense & KATA_MUSOU)
1787         {
1788                 set_action(ACTION_NONE);
1789         }
1790
1791         /* Allow repeated command */
1792         if (command_arg)
1793         {
1794                 /* Set repeat count */
1795                 command_rep = command_arg - 1;
1796
1797                 /* Redraw the state */
1798                 p_ptr->redraw |= (PR_STATE);
1799
1800                 /* Cancel the arg */
1801                 command_arg = 0;
1802         }
1803
1804         /* Get a direction to tunnel, or Abort */
1805         if (get_rep_dir(&dir,FALSE))
1806         {
1807                 /* Get location */
1808                 y = py + ddy[dir];
1809                 x = px + ddx[dir];
1810
1811                 /* Get grid */
1812                 c_ptr = &cave[y][x];
1813
1814                 /* Feature code (applying "mimic" field) */
1815                 feat = get_feat_mimic(c_ptr);
1816
1817                 /* No tunnelling through doors */
1818                 if (have_flag(f_info[feat].flags, FF_DOOR))
1819                 {
1820                         /* Message */
1821 #ifdef JP
1822                         msg_print("¥É¥¢¤Ï·¡¤ì¤Ê¤¤¡£");
1823 #else
1824                         msg_print("You cannot tunnel through doors.");
1825 #endif
1826                 }
1827
1828                 /* No tunnelling through most features */
1829                 else if (!have_flag(f_info[feat].flags, FF_TUNNEL))
1830                 {
1831 #ifdef JP
1832                         msg_print("¤½¤³¤Ï·¡¤ì¤Ê¤¤¡£");
1833 #else
1834                         msg_print("You can't tunnel through that.");
1835 #endif
1836                 }
1837
1838                 /* A monster is in the way */
1839                 else if (c_ptr->m_idx)
1840                 {
1841                         /* Take a turn */
1842                         energy_use = 100;
1843
1844                         /* Message */
1845 #ifdef JP
1846                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
1847 #else
1848                         msg_print("There is a monster in the way!");
1849 #endif
1850
1851                         /* Attack */
1852                         py_attack(y, x, 0);
1853                 }
1854
1855                 /* Try digging */
1856                 else
1857                 {
1858                         /* Tunnel through walls */
1859                         more = do_cmd_tunnel_aux(y, x);
1860                 }
1861         }
1862
1863         /* Cancel repetition unless we can continue */
1864         if (!more) disturb(0, 0);
1865 }
1866
1867
1868 #ifdef ALLOW_EASY_OPEN /* TNB */
1869
1870 /*!
1871  * @brief °ÜÆ°½èÍý¤Ë¤è¤ë´Ê°×¤Ê¡Ö³«¤¯¡×½èÍý /
1872  * easy_open_door --
1873  * @return ³«¤¯½èÍý¤¬¼ÂºÝ¤Ë»î¤ß¤é¤ì¤¿¾ì¹çTRUE¤òÊÖ¤¹
1874  * @details
1875  * <pre>
1876  *      If there is a jammed/closed/locked door at the given location,
1877  *      then attempt to unlock/open it. Return TRUE if an attempt was
1878  *      made (successful or not), otherwise return FALSE.
1879  *
1880  *      The code here should be nearly identical to that in
1881  *      do_cmd_open_test() and do_cmd_open_aux().
1882  * </pre>
1883  */
1884 bool easy_open_door(int y, int x)
1885 {
1886         int i, j;
1887
1888         cave_type *c_ptr = &cave[y][x];
1889         feature_type *f_ptr = &f_info[c_ptr->feat];
1890
1891         /* Must be a closed door */
1892         if (!is_closed_door(c_ptr->feat))
1893         {
1894                 /* Nope */
1895                 return (FALSE);
1896         }
1897
1898         /* Jammed door */
1899         if (!have_flag(f_ptr->flags, FF_OPEN))
1900         {
1901                 /* Stuck */
1902 #ifdef JP
1903                 msg_format("%s¤Ï¤¬¤Ã¤Á¤ê¤ÈÊĤ¸¤é¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£", f_name + f_info[get_feat_mimic(c_ptr)].name);
1904 #else
1905                 msg_format("The %s appears to be stuck.", f_name + f_info[get_feat_mimic(c_ptr)].name);
1906 #endif
1907
1908         }
1909
1910         /* Locked door */
1911         else if (f_ptr->power)
1912         {
1913                 /* Disarm factor */
1914                 i = p_ptr->skill_dis;
1915
1916                 /* Penalize some conditions */
1917                 if (p_ptr->blind || no_lite()) i = i / 10;
1918                 if (p_ptr->confused || p_ptr->image) i = i / 10;
1919
1920                 /* Extract the lock power */
1921                 j = f_ptr->power;
1922
1923                 /* Extract the difficulty XXX XXX XXX */
1924                 j = i - (j * 4);
1925
1926                 /* Always have a small chance of success */
1927                 if (j < 2) j = 2;
1928
1929                 /* Success */
1930                 if (randint0(100) < j)
1931                 {
1932                         /* Message */
1933 #ifdef JP
1934                         msg_print("¸°¤ò¤Ï¤º¤·¤¿¡£");
1935 #else
1936                         msg_print("You have picked the lock.");
1937 #endif
1938
1939                         /* Open the door */
1940                         cave_alter_feat(y, x, FF_OPEN);
1941
1942                         /* Sound */
1943                         sound(SOUND_OPENDOOR);
1944
1945                         /* Experience */
1946                         gain_exp(1);
1947                 }
1948
1949                 /* Failure */
1950                 else
1951                 {
1952                         /* Failure */
1953                         if (flush_failure) flush();
1954
1955                         /* Message */
1956 #ifdef JP
1957                         msg_print("¸°¤ò¤Ï¤º¤»¤Ê¤«¤Ã¤¿¡£");
1958 #else
1959                         msg_print("You failed to pick the lock.");
1960 #endif
1961
1962                 }
1963         }
1964
1965         /* Closed door */
1966         else
1967         {
1968                 /* Open the door */
1969                 cave_alter_feat(y, x, FF_OPEN);
1970
1971                 /* Sound */
1972                 sound(SOUND_OPENDOOR);
1973         }
1974
1975         /* Result */
1976         return (TRUE);
1977 }
1978
1979 #endif /* ALLOW_EASY_OPEN -- TNB */
1980
1981
1982 /*!
1983  * @brief È¢¤Î¥È¥é¥Ã¥×¤ò²ò½ü¤¹¤ë¥³¥Þ¥ó¥É¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
1984  * Perform the basic "disarm" command
1985  * @param y ²ò½ü¤ò¹Ô¤¦¥Þ¥¹¤ÎYºÂɸ
1986  * @param x ²ò½ü¤ò¹Ô¤¦¥Þ¥¹¤ÎXºÂɸ
1987  * @param o_idx È¢¤Î¥ª¥Ö¥¸¥§¥¯¥ÈID
1988  * @return ¥¿¡¼¥ó¤ò¾ÃÈñ¤¹¤ë½èÍý¤¬¹Ô¤ï¤ì¤¿¾ì¹çTRUE¤òÊÖ¤¹
1989  * @details
1990  * <pre>
1991  * Assume destination is a visible trap
1992  * Assume there is no monster blocking the destination
1993  * Returns TRUE if repeated commands may continue
1994  * </pre>
1995  */
1996 static bool do_cmd_disarm_chest(int y, int x, s16b o_idx)
1997 {
1998         int i, j;
1999
2000         bool more = FALSE;
2001
2002         object_type *o_ptr = &o_list[o_idx];
2003
2004
2005         /* Take a turn */
2006         energy_use = 100;
2007
2008         /* Get the "disarm" factor */
2009         i = p_ptr->skill_dis;
2010
2011         /* Penalize some conditions */
2012         if (p_ptr->blind || no_lite()) i = i / 10;
2013         if (p_ptr->confused || p_ptr->image) i = i / 10;
2014
2015         /* Extract the difficulty */
2016         j = i - o_ptr->pval;
2017
2018         /* Always have a small chance of success */
2019         if (j < 2) j = 2;
2020
2021         /* Must find the trap first. */
2022         if (!object_is_known(o_ptr))
2023         {
2024 #ifdef JP
2025                 msg_print("¥È¥é¥Ã¥×¤¬¸«¤¢¤¿¤é¤Ê¤¤¡£");
2026 #else
2027                 msg_print("I don't see any traps.");
2028 #endif
2029
2030         }
2031
2032         /* Already disarmed/unlocked */
2033         else if (o_ptr->pval <= 0)
2034         {
2035 #ifdef JP
2036                 msg_print("È¢¤Ë¤Ï¥È¥é¥Ã¥×¤¬»Å³Ý¤±¤é¤ì¤Æ¤¤¤Ê¤¤¡£");
2037 #else
2038                 msg_print("The chest is not trapped.");
2039 #endif
2040
2041         }
2042
2043         /* No traps to find. */
2044         else if (!chest_traps[o_ptr->pval])
2045         {
2046 #ifdef JP
2047                 msg_print("È¢¤Ë¤Ï¥È¥é¥Ã¥×¤¬»Å³Ý¤±¤é¤ì¤Æ¤¤¤Ê¤¤¡£");
2048 #else
2049                 msg_print("The chest is not trapped.");
2050 #endif
2051
2052         }
2053
2054         /* Success (get a lot of experience) */
2055         else if (randint0(100) < j)
2056         {
2057 #ifdef JP
2058                 msg_print("È¢¤Ë»Å³Ý¤±¤é¤ì¤Æ¤¤¤¿¥È¥é¥Ã¥×¤ò²ò½ü¤·¤¿¡£");
2059 #else
2060                 msg_print("You have disarmed the chest.");
2061 #endif
2062
2063                 gain_exp(o_ptr->pval);
2064                 o_ptr->pval = (0 - o_ptr->pval);
2065         }
2066
2067         /* Failure -- Keep trying */
2068         else if ((i > 5) && (randint1(i) > 5))
2069         {
2070                 /* We may keep trying */
2071                 more = TRUE;
2072                 if (flush_failure) flush();
2073 #ifdef JP
2074                 msg_print("È¢¤Î¥È¥é¥Ã¥×²ò½ü¤Ë¼ºÇÔ¤·¤¿¡£");
2075 #else
2076                 msg_print("You failed to disarm the chest.");
2077 #endif
2078
2079         }
2080
2081         /* Failure -- Set off the trap */
2082         else
2083         {
2084 #ifdef JP
2085                 msg_print("¥È¥é¥Ã¥×¤òºîÆ°¤µ¤»¤Æ¤·¤Þ¤Ã¤¿¡ª");
2086 #else
2087                 msg_print("You set off a trap!");
2088 #endif
2089
2090                 sound(SOUND_FAIL);
2091                 chest_trap(y, x, o_idx);
2092         }
2093
2094         /* Result */
2095         return (more);
2096 }
2097
2098
2099 /*!
2100  * @brief È¢¤Î¥È¥é¥Ã¥×¤ò²ò½ü¤¹¤ë¥³¥Þ¥ó¥É¤Î¥µ¥Ö¥ë¡¼¥Á¥ó /
2101  * Perform the basic "disarm" command
2102  * @param y ²ò½ü¤ò¹Ô¤¦¥Þ¥¹¤ÎYºÂɸ
2103  * @param x ²ò½ü¤ò¹Ô¤¦¥Þ¥¹¤ÎXºÂɸ
2104  * @param dir ¥×¥ì¥¤¥ä¡¼¤«¤é¤ß¤¿Êý¸þID
2105  * @return ¥¿¡¼¥ó¤ò¾ÃÈñ¤¹¤ë½èÍý¤¬¹Ô¤ï¤ì¤¿¾ì¹çTRUE¤òÊÖ¤¹
2106  * @details
2107  * <pre>
2108  * Assume destination is a visible trap
2109  * Assume there is no monster blocking the destination
2110  * Returns TRUE if repeated commands may continue
2111  * </pre>
2112  */
2113 #ifdef ALLOW_EASY_DISARM /* TNB */
2114
2115 bool do_cmd_disarm_aux(int y, int x, int dir)
2116
2117 #else /* ALLOW_EASY_DISARM -- TNB */
2118
2119 static bool do_cmd_disarm_aux(int y, int x, int dir)
2120
2121 #endif /* ALLOW_EASY_DISARM -- TNB */
2122 {
2123         /* Get grid and contents */
2124         cave_type *c_ptr = &cave[y][x];
2125
2126         /* Get feature */
2127         feature_type *f_ptr = &f_info[c_ptr->feat];
2128
2129         /* Access trap name */
2130         cptr name = (f_name + f_ptr->name);
2131
2132         /* Extract trap "power" */
2133         int power = f_ptr->power;
2134
2135         bool more = FALSE;
2136
2137         /* Get the "disarm" factor */
2138         int i = p_ptr->skill_dis;
2139
2140         int j;
2141
2142         /* Take a turn */
2143         energy_use = 100;
2144
2145         /* Penalize some conditions */
2146         if (p_ptr->blind || no_lite()) i = i / 10;
2147         if (p_ptr->confused || p_ptr->image) i = i / 10;
2148
2149         /* Extract the difficulty */
2150         j = i - power;
2151
2152         /* Always have a small chance of success */
2153         if (j < 2) j = 2;
2154
2155         /* Success */
2156         if (randint0(100) < j)
2157         {
2158                 /* Message */
2159 #ifdef JP
2160                 msg_format("%s¤ò²ò½ü¤·¤¿¡£", name);
2161 #else
2162                 msg_format("You have disarmed the %s.", name);
2163 #endif
2164
2165                 /* Reward */
2166                 gain_exp(power);
2167
2168                 /* Remove the trap */
2169                 cave_alter_feat(y, x, FF_DISARM);
2170
2171 #ifdef ALLOW_EASY_DISARM /* TNB */
2172
2173                 /* Move the player onto the trap */
2174                 move_player(dir, easy_disarm, FALSE);
2175
2176 #else /* ALLOW_EASY_DISARM -- TNB */
2177
2178                 /* move the player onto the trap grid */
2179                 move_player(dir, FALSE, FALSE);
2180
2181 #endif /* ALLOW_EASY_DISARM -- TNB */
2182         }
2183
2184         /* Failure -- Keep trying */
2185         else if ((i > 5) && (randint1(i) > 5))
2186         {
2187                 /* Failure */
2188                 if (flush_failure) flush();
2189
2190                 /* Message */
2191 #ifdef JP
2192                 msg_format("%s¤Î²ò½ü¤Ë¼ºÇÔ¤·¤¿¡£", name);
2193 #else
2194                 msg_format("You failed to disarm the %s.", name);
2195 #endif
2196
2197                 /* We may keep trying */
2198                 more = TRUE;
2199         }
2200
2201         /* Failure -- Set off the trap */
2202         else
2203         {
2204                 /* Message */
2205 #ifdef JP
2206                 msg_format("%s¤òºîÆ°¤µ¤»¤Æ¤·¤Þ¤Ã¤¿¡ª", name);
2207 #else
2208                 msg_format("You set off the %s!", name);
2209 #endif
2210
2211 #ifdef ALLOW_EASY_DISARM /* TNB */
2212
2213                 /* Move the player onto the trap */
2214                 move_player(dir, easy_disarm, FALSE);
2215
2216 #else /* ALLOW_EASY_DISARM -- TNB */
2217
2218                 /* Move the player onto the trap */
2219                 move_player(dir, FALSE, FALSE);
2220
2221 #endif /* ALLOW_EASY_DISARM -- TNB */
2222         }
2223
2224         /* Result */
2225         return (more);
2226 }
2227
2228
2229 /*!
2230  * @brief È¢¡¢¾²¤Î¥È¥é¥Ã¥×²ò½ü½èÍýÁÐÊý¤ÎÅý¹ç¥á¥¤¥ó¥ë¡¼¥Á¥ó /
2231  * Disarms a trap, or chest
2232  * @return ¤Ê¤·
2233  */
2234 void do_cmd_disarm(void)
2235 {
2236         int y, x, dir;
2237
2238         s16b o_idx;
2239
2240         bool more = FALSE;
2241
2242         if (p_ptr->special_defense & KATA_MUSOU)
2243         {
2244                 set_action(ACTION_NONE);
2245         }
2246
2247 #ifdef ALLOW_EASY_DISARM /* TNB */
2248
2249         /* Option: Pick a direction */
2250         if (easy_disarm)
2251         {
2252                 int num_traps, num_chests;
2253
2254                 /* Count visible traps */
2255                 num_traps = count_dt(&y, &x, is_trap, TRUE);
2256
2257                 /* Count chests (trapped) */
2258                 num_chests = count_chests(&y, &x, TRUE);
2259
2260                 /* See if only one target */
2261                 if (num_traps || num_chests)
2262                 {
2263                         bool too_many = (num_traps && num_chests) || (num_traps > 1) ||
2264                             (num_chests > 1);
2265                         if (!too_many) command_dir = coords_to_dir(y, x);
2266                 }
2267         }
2268
2269 #endif /* ALLOW_EASY_DISARM -- TNB */
2270
2271         /* Allow repeated command */
2272         if (command_arg)
2273         {
2274                 /* Set repeat count */
2275                 command_rep = command_arg - 1;
2276
2277                 /* Redraw the state */
2278                 p_ptr->redraw |= (PR_STATE);
2279
2280                 /* Cancel the arg */
2281                 command_arg = 0;
2282         }
2283
2284         /* Get a direction (or abort) */
2285         if (get_rep_dir(&dir,TRUE))
2286         {
2287                 cave_type *c_ptr;
2288                 s16b feat;
2289
2290                 /* Get location */
2291                 y = py + ddy[dir];
2292                 x = px + ddx[dir];
2293
2294                 /* Get grid and contents */
2295                 c_ptr = &cave[y][x];
2296
2297                 /* Feature code (applying "mimic" field) */
2298                 feat = get_feat_mimic(c_ptr);
2299
2300                 /* Check for chests */
2301                 o_idx = chest_check(y, x, TRUE);
2302
2303                 /* Disarm a trap */
2304                 if (!is_trap(feat) && !o_idx)
2305                 {
2306                         /* Message */
2307 #ifdef JP
2308                         msg_print("¤½¤³¤Ë¤Ï²ò½ü¤¹¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
2309 #else
2310                         msg_print("You see nothing there to disarm.");
2311 #endif
2312
2313                 }
2314
2315                 /* Monster in the way */
2316                 else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
2317                 {
2318                         /* Message */
2319 #ifdef JP
2320                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
2321 #else
2322                         msg_print("There is a monster in the way!");
2323 #endif
2324
2325
2326                         /* Attack */
2327                         py_attack(y, x, 0);
2328                 }
2329
2330                 /* Disarm chest */
2331                 else if (o_idx)
2332                 {
2333                         /* Disarm the chest */
2334                         more = do_cmd_disarm_chest(y, x, o_idx);
2335                 }
2336
2337                 /* Disarm trap */
2338                 else
2339                 {
2340                         /* Disarm the trap */
2341                         more = do_cmd_disarm_aux(y, x, dir);
2342                 }
2343         }
2344
2345         /* Cancel repeat unless told not to */
2346         if (!more) disturb(0, 0);
2347 }
2348
2349
2350 /*!
2351  * @brief ¡ÖÂǤÁÇˤë¡×Æ°ºî¥³¥Þ¥ó¥É¤Î¥µ¥Ö¥ë¡¼¥Á¥ó /
2352  * Perform the basic "bash" command
2353  * @param y Âоݤò¹Ô¤¦¥Þ¥¹¤ÎYºÂɸ
2354  * @param x Âоݤò¹Ô¤¦¥Þ¥¹¤ÎXºÂɸ
2355  * @param dir ¥×¥ì¥¤¥ä¡¼¤«¤é¸«¤¿¥¿¡¼¥²¥Ã¥È¤ÎÊý³ÑID
2356  * @return ¼ÂºÝ¤Ë½èÍý¤¬¹Ô¤ï¤ì¤¿¾ì¹çTRUE¤òÊÖ¤¹¡£
2357  * @details
2358  * <pre>
2359  * Assume destination is a closed/locked/jammed door
2360  * Assume there is no monster blocking the destination
2361  * Returns TRUE if repeated commands may continue
2362  * </pre>
2363  */
2364 static bool do_cmd_bash_aux(int y, int x, int dir)
2365 {
2366         /* Get grid */
2367         cave_type       *c_ptr = &cave[y][x];
2368
2369         /* Get feature */
2370         feature_type *f_ptr = &f_info[c_ptr->feat];
2371
2372         /* Hack -- Bash power based on strength */
2373         /* (Ranges from 3 to 20 to 100 to 200) */
2374         int bash = adj_str_blow[p_ptr->stat_ind[A_STR]];
2375
2376         /* Extract door power */
2377         int temp = f_ptr->power;
2378
2379         bool            more = FALSE;
2380
2381         cptr name = f_name + f_info[get_feat_mimic(c_ptr)].name;
2382
2383         /* Take a turn */
2384         energy_use = 100;
2385
2386         /* Message */
2387 #ifdef JP
2388         msg_format("%s¤ËÂÎÅö¤¿¤ê¤ò¤·¤¿¡ª", name);
2389 #else
2390         msg_format("You smash into the %s!", name);
2391 #endif
2392
2393         /* Compare bash power to door power XXX XXX XXX */
2394         temp = (bash - (temp * 10));
2395
2396         if (p_ptr->pclass == CLASS_BERSERKER) temp *= 2;
2397
2398         /* Hack -- always have a chance */
2399         if (temp < 1) temp = 1;
2400
2401         /* Hack -- attempt to bash down the door */
2402         if (randint0(100) < temp)
2403         {
2404                 /* Message */
2405 #ifdef JP
2406                 msg_format("%s¤ò²õ¤·¤¿¡ª", name);
2407 #else
2408                 msg_format("The %s crashes open!", name);
2409 #endif
2410
2411                 /* Sound */
2412                 sound(have_flag(f_ptr->flags, FF_GLASS) ? SOUND_GLASS : SOUND_OPENDOOR);
2413
2414                 /* Break down the door */
2415                 if ((randint0(100) < 50) || (feat_state(c_ptr->feat, FF_OPEN) == c_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS))
2416                 {
2417                         cave_alter_feat(y, x, FF_BASH);
2418                 }
2419
2420                 /* Open the door */
2421                 else
2422                 {
2423                         cave_alter_feat(y, x, FF_OPEN);
2424                 }
2425
2426                 /* Hack -- Fall through the door */
2427                 move_player(dir, FALSE, FALSE);
2428         }
2429
2430         /* Saving throw against stun */
2431         else if (randint0(100) < adj_dex_safe[p_ptr->stat_ind[A_DEX]] +
2432                  p_ptr->lev)
2433         {
2434                 /* Message */
2435 #ifdef JP
2436                 msg_format("¤³¤Î%s¤Ï´è¾æ¤À¡£", name);
2437 #else
2438                 msg_format("The %s holds firm.", name);
2439 #endif
2440
2441
2442                 /* Allow repeated bashing */
2443                 more = TRUE;
2444         }
2445
2446         /* High dexterity yields coolness */
2447         else
2448         {
2449                 /* Message */
2450 #ifdef JP
2451                 msg_print("ÂΤΥХé¥ó¥¹¤ò¤¯¤º¤·¤Æ¤·¤Þ¤Ã¤¿¡£");
2452 #else
2453                 msg_print("You are off-balance.");
2454 #endif
2455
2456
2457                 /* Hack -- Lose balance ala paralysis */
2458                 (void)set_paralyzed(p_ptr->paralyzed + 2 + randint0(2));
2459         }
2460
2461         /* Result */
2462         return (more);
2463 }
2464
2465
2466 /*!
2467  * @brief ¡ÖÂǤÁÇˤë¡×Æ°ºî¥³¥Þ¥ó¥É¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
2468  * Bash open a door, success based on character strength
2469  * @return ¤Ê¤·
2470  * @details
2471  * <pre>
2472  * For a closed door, pval is positive if locked; negative if stuck.
2473  *
2474  * For an open door, pval is positive for a broken door.
2475  *
2476  * A closed door can be opened - harder if locked. Any door might be
2477  * bashed open (and thereby broken). Bashing a door is (potentially)
2478  * faster! You move into the door way. To open a stuck door, it must
2479  * be bashed. A closed door can be jammed (see do_cmd_spike()).
2480  *
2481  * Creatures can also open or bash doors, see elsewhere.
2482  * </pre>
2483  */
2484 void do_cmd_bash(void)
2485 {
2486         int                     y, x, dir;
2487
2488         cave_type       *c_ptr;
2489
2490         bool            more = FALSE;
2491
2492
2493         if (p_ptr->special_defense & KATA_MUSOU)
2494         {
2495                 set_action(ACTION_NONE);
2496         }
2497
2498         /* Allow repeated command */
2499         if (command_arg)
2500         {
2501                 /* Set repeat count */
2502                 command_rep = command_arg - 1;
2503
2504                 /* Redraw the state */
2505                 p_ptr->redraw |= (PR_STATE);
2506
2507                 /* Cancel the arg */
2508                 command_arg = 0;
2509         }
2510
2511         /* Get a "repeated" direction */
2512         if (get_rep_dir(&dir,FALSE))
2513         {
2514                 s16b feat;
2515
2516                 /* Bash location */
2517                 y = py + ddy[dir];
2518                 x = px + ddx[dir];
2519
2520                 /* Get grid */
2521                 c_ptr = &cave[y][x];
2522
2523                 /* Feature code (applying "mimic" field) */
2524                 feat = get_feat_mimic(c_ptr);
2525
2526                 /* Nothing useful */
2527                 if (!have_flag(f_info[feat].flags, FF_BASH))
2528                 {
2529                         /* Message */
2530 #ifdef JP
2531                         msg_print("¤½¤³¤Ë¤ÏÂÎÅö¤¿¤ê¤¹¤ë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
2532 #else
2533                         msg_print("You see nothing there to bash.");
2534 #endif
2535
2536                 }
2537
2538                 /* Monster in the way */
2539                 else if (c_ptr->m_idx)
2540                 {
2541                         /* Take a turn */
2542                         energy_use = 100;
2543
2544                         /* Message */
2545 #ifdef JP
2546                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
2547 #else
2548                         msg_print("There is a monster in the way!");
2549 #endif
2550
2551
2552                         /* Attack */
2553                         py_attack(y, x, 0);
2554                 }
2555
2556                 /* Bash a closed door */
2557                 else
2558                 {
2559                         /* Bash the door */
2560                         more = do_cmd_bash_aux(y, x, dir);
2561                 }
2562         }
2563
2564         /* Unless valid action taken, cancel bash */
2565         if (!more) disturb(0, 0);
2566 }
2567
2568
2569 /*!
2570  * @brief ÆÃÄê¤Î¥Þ¥¹¤Ë±Æ¶Á¤òµÚ¤Ü¤¹¤¿¤á¤ÎÈÆÍÑŪ¥³¥Þ¥ó¥É
2571  * @return ¤Ê¤·
2572  * @details
2573  * <pre>
2574  * Manipulate an adjacent grid in some way
2575  *
2576  * Attack monsters, tunnel through walls, disarm traps, open doors.
2577  *
2578  * Consider confusion XXX XXX XXX
2579  *
2580  * This command must always take a turn, to prevent free detection
2581  * of invisible monsters.
2582  * </pre>
2583  */
2584 void do_cmd_alter(void)
2585 {
2586         int                     y, x, dir;
2587
2588         cave_type       *c_ptr;
2589
2590         bool            more = FALSE;
2591
2592
2593         if (p_ptr->special_defense & KATA_MUSOU)
2594         {
2595                 set_action(ACTION_NONE);
2596         }
2597
2598         /* Allow repeated command */
2599         if (command_arg)
2600         {
2601                 /* Set repeat count */
2602                 command_rep = command_arg - 1;
2603
2604                 /* Redraw the state */
2605                 p_ptr->redraw |= (PR_STATE);
2606
2607                 /* Cancel the arg */
2608                 command_arg = 0;
2609         }
2610
2611         /* Get a direction */
2612         if (get_rep_dir(&dir,TRUE))
2613         {
2614                 s16b feat;
2615                 feature_type *f_ptr;
2616
2617                 /* Get location */
2618                 y = py + ddy[dir];
2619                 x = px + ddx[dir];
2620
2621                 /* Get grid */
2622                 c_ptr = &cave[y][x];
2623
2624                 /* Feature code (applying "mimic" field) */
2625                 feat = get_feat_mimic(c_ptr);
2626                 f_ptr = &f_info[feat];
2627
2628                 /* Take a turn */
2629                 energy_use = 100;
2630
2631                 /* Attack monsters */
2632                 if (c_ptr->m_idx)
2633                 {
2634                         /* Attack */
2635                         py_attack(y, x, 0);
2636                 }
2637
2638                 /* Locked doors */
2639                 else if (have_flag(f_ptr->flags, FF_OPEN))
2640                 {
2641                         more = do_cmd_open_aux(y, x);
2642                 }
2643
2644                 /* Bash jammed doors */
2645                 else if (have_flag(f_ptr->flags, FF_BASH))
2646                 {
2647                         more = do_cmd_bash_aux(y, x, dir);
2648                 }
2649
2650                 /* Tunnel through walls */
2651                 else if (have_flag(f_ptr->flags, FF_TUNNEL))
2652                 {
2653                         more = do_cmd_tunnel_aux(y, x);
2654                 }
2655
2656                 /* Close open doors */
2657                 else if (have_flag(f_ptr->flags, FF_CLOSE))
2658                 {
2659                         more = do_cmd_close_aux(y, x);
2660                 }
2661
2662                 /* Disarm traps */
2663                 else if (have_flag(f_ptr->flags, FF_DISARM))
2664                 {
2665                         more = do_cmd_disarm_aux(y, x, dir);
2666                 }
2667
2668                 /* Oops */
2669                 else
2670                 {
2671                         /* Oops */
2672 #ifdef JP
2673                         msg_print("²¿¤â¤Ê¤¤¶õÃæ¤ò¹¶·â¤·¤¿¡£");
2674 #else
2675                         msg_print("You attack the empty air.");
2676 #endif
2677
2678                 }
2679         }
2680
2681         /* Cancel repetition unless we can continue */
2682         if (!more) disturb(0, 0);
2683 }
2684
2685
2686
2687 /*!
2688  * @brief ¡Ö¤¯¤µ¤Ó¤òÂǤġפ¿¤á¤ËɬÍפʥª¥Ö¥¸¥§¥¯¥È¤¬¤¢¤ë¤«¤É¤¦¤«¤ÎȽÄê¤òÊÖ¤¹ /
2689  * Find the index of some "spikes", if possible.
2690  * @param ip ¤¯¤µ¤Ó¤È¤·¤ÆÂǤƤ륪¥Ö¥¸¥§¥¯¥È¤ÎID
2691  * @return ¥ª¥Ö¥¸¥§¥¯¥È¤¬¤¢¤ë¾ì¹çTRUE¤òÊÖ¤¹
2692  * @details
2693  * <pre>
2694  * XXX XXX XXX Let user choose a pile of spikes, perhaps?
2695  * </pre>
2696  */
2697 static bool get_spike(int *ip)
2698 {
2699         int i;
2700
2701         /* Check every item in the pack */
2702         for (i = 0; i < INVEN_PACK; i++)
2703         {
2704                 object_type *o_ptr = &inventory[i];
2705
2706                 /* Skip non-objects */
2707                 if (!o_ptr->k_idx) continue;
2708
2709                 /* Check the "tval" code */
2710                 if (o_ptr->tval == TV_SPIKE)
2711                 {
2712                         /* Save the spike index */
2713                         (*ip) = i;
2714
2715                         /* Success */
2716                         return (TRUE);
2717                 }
2718         }
2719
2720         /* Oops */
2721         return (FALSE);
2722 }
2723
2724
2725 /*!
2726  * @brief ¡Ö¤¯¤µ¤Ó¤òÂǤġ×Æ°ºî¥³¥Þ¥ó¥É¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
2727  * Jam a closed door with a spike
2728  * @return ¤Ê¤·
2729  * @details
2730  * <pre>
2731  * This command may NOT be repeated
2732  * </pre>
2733  */
2734 void do_cmd_spike(void)
2735 {
2736         int dir;
2737
2738         if (p_ptr->special_defense & KATA_MUSOU)
2739         {
2740                 set_action(ACTION_NONE);
2741         }
2742
2743         /* Get a "repeated" direction */
2744         if (get_rep_dir(&dir,FALSE))
2745         {
2746                 int y, x, item;
2747                 cave_type *c_ptr;
2748                 s16b feat;
2749
2750                 /* Get location */
2751                 y = py + ddy[dir];
2752                 x = px + ddx[dir];
2753
2754                 /* Get grid and contents */
2755                 c_ptr = &cave[y][x];
2756
2757                 /* Feature code (applying "mimic" field) */
2758                 feat = get_feat_mimic(c_ptr);
2759
2760                 /* Require closed door */
2761                 if (!have_flag(f_info[feat].flags, FF_SPIKE))
2762                 {
2763                         /* Message */
2764 #ifdef JP
2765                         msg_print("¤½¤³¤Ë¤Ï¤¯¤µ¤Ó¤òÂǤƤë¤â¤Î¤¬¸«Åö¤¿¤é¤Ê¤¤¡£");
2766 #else
2767                         msg_print("You see nothing there to spike.");
2768 #endif
2769
2770                 }
2771
2772                 /* Get a spike */
2773                 else if (!get_spike(&item))
2774                 {
2775                         /* Message */
2776 #ifdef JP
2777                         msg_print("¤¯¤µ¤Ó¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡ª");
2778 #else
2779                         msg_print("You have no spikes!");
2780 #endif
2781                 }
2782
2783                 /* Is a monster in the way? */
2784                 else if (c_ptr->m_idx)
2785                 {
2786                         /* Take a turn */
2787                         energy_use = 100;
2788
2789                         /* Message */
2790 #ifdef JP
2791                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
2792 #else
2793                         msg_print("There is a monster in the way!");
2794 #endif
2795
2796                         /* Attack */
2797                         py_attack(y, x, 0);
2798                 }
2799
2800                 /* Go for it */
2801                 else
2802                 {
2803                         /* Take a turn */
2804                         energy_use = 100;
2805
2806                         /* Successful jamming */
2807 #ifdef JP
2808                         msg_format("%s¤Ë¤¯¤µ¤Ó¤òÂǤÁ¹þ¤ó¤À¡£", f_name + f_info[feat].name);
2809 #else
2810                         msg_format("You jam the %s with a spike.", f_name + f_info[feat].name);
2811 #endif
2812
2813                         cave_alter_feat(y, x, FF_SPIKE);
2814
2815                         /* Use up, and describe, a single spike, from the bottom */
2816                         inven_item_increase(item, -1);
2817                         inven_item_describe(item);
2818                         inven_item_optimize(item);
2819                 }
2820         }
2821 }
2822
2823
2824
2825 /*!
2826  * @brief ¡ÖÊ⤯¡×Æ°ºî¥³¥Þ¥ó¥É¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
2827  * Support code for the "Walk" and "Jump" commands
2828  * @param pickup ¥¢¥¤¥Æ¥à¤Î¼«Æ°½¦¤¤¤ò¹Ô¤¦¤Ê¤éTRUE
2829  * @return ¤Ê¤·
2830  */
2831 void do_cmd_walk(bool pickup)
2832 {
2833         int dir;
2834
2835         bool more = FALSE;
2836
2837
2838         /* Allow repeated command */
2839         if (command_arg)
2840         {
2841                 /* Set repeat count */
2842                 command_rep = command_arg - 1;
2843
2844                 /* Redraw the state */
2845                 p_ptr->redraw |= (PR_STATE);
2846
2847                 /* Cancel the arg */
2848                 command_arg = 0;
2849         }
2850
2851         /* Get a "repeated" direction */
2852         if (get_rep_dir(&dir,FALSE))
2853         {
2854                 /* Take a turn */
2855                 energy_use = 100;
2856
2857                 if ((dir != 5) && (p_ptr->special_defense & KATA_MUSOU))
2858                 {
2859                         set_action(ACTION_NONE);
2860                 }
2861
2862                 /* Hack -- In small scale wilderness it takes MUCH more time to move */
2863                 if (p_ptr->wild_mode) energy_use *= ((MAX_HGT + MAX_WID) / 2);
2864                 if (p_ptr->action == ACTION_HAYAGAKE) energy_use = energy_use * (45-(p_ptr->lev/2)) / 100;
2865
2866                 /* Actually move the character */
2867                 move_player(dir, pickup, FALSE);
2868
2869                 /* Allow more walking */
2870                 more = TRUE;
2871         }
2872
2873         /* Hack again -- Is there a special encounter ??? */
2874         if (p_ptr->wild_mode && !cave_have_flag_bold(py, px, FF_TOWN))
2875         {
2876                 int tmp = 120 + p_ptr->lev*10 - wilderness[py][px].level + 5;
2877                 if (tmp < 1) 
2878                         tmp = 1;
2879                 if (((wilderness[py][px].level + 5) > (p_ptr->lev / 2)) && randint0(tmp) < (21-p_ptr->skill_stl))
2880                 {
2881                         /* Inform the player of his horrible fate :=) */
2882 #ifdef JP
2883                         msg_print("½±·â¤À¡ª");
2884 #else
2885                         msg_print("You are ambushed !");
2886 #endif
2887
2888                         /* Go into large wilderness view */
2889                         p_ptr->oldpy = randint1(MAX_HGT-2);
2890                         p_ptr->oldpx = randint1(MAX_WID-2);
2891                         change_wild_mode();
2892
2893                         /* Give first move to monsters */
2894                         energy_use = 100;
2895
2896                         /* HACk -- set the encouter flag for the wilderness generation */
2897                         generate_encounter = TRUE;
2898                 }
2899         }
2900
2901         /* Cancel repeat unless we may continue */
2902         if (!more) disturb(0, 0);
2903 }
2904
2905
2906 /*!
2907  * @brief ¡ÖÁö¤ë¡×Æ°ºî¥³¥Þ¥ó¥É¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
2908  * Start running.
2909  * @return ¤Ê¤·
2910  */
2911 void do_cmd_run(void)
2912 {
2913         int dir;
2914
2915         /* Hack -- no running when confused */
2916         if (p_ptr->confused)
2917         {
2918 #ifdef JP
2919                 msg_print("º®Í𤷤Ƥ¤¤ÆÁö¤ì¤Ê¤¤¡ª");
2920 #else
2921                 msg_print("You are too confused!");
2922 #endif
2923
2924                 return;
2925         }
2926
2927         if (p_ptr->special_defense & KATA_MUSOU)
2928         {
2929                 set_action(ACTION_NONE);
2930         }
2931
2932         /* Get a "repeated" direction */
2933         if (get_rep_dir(&dir,FALSE))
2934         {
2935                 /* Hack -- Set the run counter */
2936                 running = (command_arg ? command_arg : 1000);
2937
2938                 /* First step */
2939                 run_step(dir);
2940         }
2941 }
2942
2943
2944 /*!
2945  * @brief ¡Öα¤Þ¤ë¡×Æ°ºî¥³¥Þ¥ó¥É¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
2946  * Stay still.  Search.  Enter stores.
2947  * Pick up treasure if "pickup" is true.
2948  * @param pickup ¥¢¥¤¥Æ¥à¤Î¼«Æ°½¦¤¤¤ò¹Ô¤¦¤Ê¤éTRUE
2949  * @return ¤Ê¤·
2950  */
2951 void do_cmd_stay(bool pickup)
2952 {
2953         u32b mpe_mode = MPE_STAYING | MPE_ENERGY_USE;
2954
2955         /* Allow repeated command */
2956         if (command_arg)
2957         {
2958                 /* Set repeat count */
2959                 command_rep = command_arg - 1;
2960
2961                 /* Redraw the state */
2962                 p_ptr->redraw |= (PR_STATE);
2963
2964                 /* Cancel the arg */
2965                 command_arg = 0;
2966         }
2967
2968         /* Take a turn */
2969         energy_use = 100;
2970
2971         if (pickup) mpe_mode |= MPE_DO_PICKUP;
2972         (void)move_player_effect(py, px, mpe_mode);
2973 }
2974
2975
2976 /*!
2977  * @brief ¡ÖµÙ¤à¡×Æ°ºî¥³¥Þ¥ó¥É¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
2978  * Resting allows a player to safely restore his hp     -RAK-
2979  * @return ¤Ê¤·
2980  */
2981 void do_cmd_rest(void)
2982 {
2983
2984         set_action(ACTION_NONE);
2985
2986         if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] || p_ptr->magic_num1[1]))
2987         {
2988                 stop_singing();
2989         }
2990
2991         /* Hex */
2992         if (hex_spelling_any()) stop_hex_spell_all();
2993
2994         /* Prompt for time if needed */
2995         if (command_arg <= 0)
2996         {
2997 #ifdef JP
2998                 cptr p = "µÙ·Æ (0-9999, '*' ¤Ç HP/MPÁ´²÷, '&' ¤ÇɬÍפʤÀ¤±): ";
2999 #else
3000                 cptr p = "Rest (0-9999, '*' for HP/SP, '&' as needed): ";
3001 #endif
3002
3003
3004                 char out_val[80];
3005
3006                 /* Default */
3007                 strcpy(out_val, "&");
3008
3009                 /* Ask for duration */
3010                 if (!get_string(p, out_val, 4)) return;
3011
3012                 /* Rest until done */
3013                 if (out_val[0] == '&')
3014                 {
3015                         command_arg = (-2);
3016                 }
3017
3018                 /* Rest a lot */
3019                 else if (out_val[0] == '*')
3020                 {
3021                         command_arg = (-1);
3022                 }
3023
3024                 /* Rest some */
3025                 else
3026                 {
3027                         command_arg = atoi(out_val);
3028                         if (command_arg <= 0) return;
3029                 }
3030         }
3031
3032
3033         /* Paranoia */
3034         if (command_arg > 9999) command_arg = 9999;
3035
3036         if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
3037
3038         /* Take a turn XXX XXX XXX (?) */
3039         energy_use = 100;
3040
3041         /* The sin of sloth */
3042         if (command_arg > 100)
3043                 chg_virtue(V_DILIGENCE, -1);
3044         
3045         /* Why are you sleeping when there's no need?  WAKE UP!*/
3046         if ((p_ptr->chp == p_ptr->mhp) &&
3047             (p_ptr->csp == p_ptr->msp) &&
3048             !p_ptr->blind && !p_ptr->confused &&
3049             !p_ptr->poisoned && !p_ptr->afraid &&
3050             !p_ptr->stun && !p_ptr->cut &&
3051             !p_ptr->slow && !p_ptr->paralyzed &&
3052             !p_ptr->image && !p_ptr->word_recall &&
3053             !p_ptr->alter_reality)
3054                         chg_virtue(V_DILIGENCE, -1);
3055
3056         /* Save the rest code */
3057         resting = command_arg;
3058         p_ptr->action = ACTION_REST;
3059
3060         /* Recalculate bonuses */
3061         p_ptr->update |= (PU_BONUS);
3062
3063         /* Redraw the state */
3064         p_ptr->redraw |= (PR_STATE);
3065
3066         /* Handle stuff */
3067         handle_stuff();
3068
3069         /* Refresh */
3070         Term_fresh();
3071 }
3072
3073
3074 /*!
3075  * @brief ÌðÃƤò¼Í·â¤·¤¿¾ì¹ç¤ÎÇË»³ÎΨ¤òÊÖ¤¹ /
3076  * Determines the odds of an object breaking when thrown at a monster
3077  * @param o_ptr ÌðÃƤΥª¥Ö¥¸¥§¥¯¥È¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
3078  * @return ÇË»³ÎΨ(%)
3079  * @details
3080  * Note that artifacts never break, see the "drop_near()" function.
3081  */
3082 static int breakage_chance(object_type *o_ptr)
3083 {
3084         int archer_bonus = (p_ptr->pclass == CLASS_ARCHER ? (p_ptr->lev-1)/7 + 4: 0);
3085
3086         /* Examine the snipe type */
3087         if (snipe_type)
3088         {
3089                 if (snipe_type == SP_KILL_WALL) return (100);
3090                 if (snipe_type == SP_EXPLODE) return (100);
3091                 if (snipe_type == SP_PIERCE) return (100);
3092                 if (snipe_type == SP_FINAL) return (100);
3093                 if (snipe_type == SP_NEEDLE) return (100);
3094                 if (snipe_type == SP_EVILNESS) return (40);
3095                 if (snipe_type == SP_HOLYNESS) return (40);
3096         }
3097
3098         /* Examine the item type */
3099         switch (o_ptr->tval)
3100         {
3101                 /* Always break */
3102                 case TV_FLASK:
3103                 case TV_POTION:
3104                 case TV_BOTTLE:
3105                 case TV_FOOD:
3106                 case TV_JUNK:
3107                         return (100);
3108
3109                 /* Often break */
3110                 case TV_LITE:
3111                 case TV_SCROLL:
3112                 case TV_SKELETON:
3113                         return (50);
3114
3115                 /* Sometimes break */
3116                 case TV_WAND:
3117                 case TV_SPIKE:
3118                         return (25);
3119                 case TV_ARROW:
3120                         return (20 - archer_bonus * 2);
3121
3122                 /* Rarely break */
3123                 case TV_SHOT:
3124                 case TV_BOLT:
3125                         return (10 - archer_bonus);
3126                 default:
3127                         return (10);
3128         }
3129 }
3130
3131
3132 /*!
3133  * @brief ÌðÃƤò¼Í·â¤·¤¿ºÝ¤Î¥¹¥ì¥¤ÇÜΨ¤ò¤«¤±¤¿·ë²Ì¤òÊÖ¤¹ /
3134  * Determines the odds of an object breaking when thrown at a monster
3135  * @param o_ptr ÌðÃƤΥª¥Ö¥¸¥§¥¯¥È¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
3136  * @param tdam ·×»»ÅÓÃæ¤Î¥À¥á¡¼¥¸ÎÌ
3137  * @param m_ptr ÌÜɸ¥â¥ó¥¹¥¿¡¼¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
3138  * @return ¥¹¥ì¥¤ÇÜΨ¤ò¤«¤±¤¿¥À¥á¡¼¥¸ÎÌ
3139  */
3140 static s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
3141 {
3142         int mult = 10;
3143
3144         monster_race *r_ptr = &r_info[m_ptr->r_idx];
3145
3146         u32b flgs[TR_FLAG_SIZE];
3147
3148         /* Extract the flags */
3149         object_flags(o_ptr, flgs);
3150
3151         /* Some "weapons" and "ammo" do extra damage */
3152         switch (o_ptr->tval)
3153         {
3154                 case TV_SHOT:
3155                 case TV_ARROW:
3156                 case TV_BOLT:
3157                 {
3158                         /* Slay Animal */
3159                         if ((have_flag(flgs, TR_SLAY_ANIMAL)) &&
3160                             (r_ptr->flags3 & RF3_ANIMAL))
3161                         {
3162                                 if (is_original_ap_and_seen(m_ptr))
3163                                 {
3164                                         r_ptr->r_flags3 |= RF3_ANIMAL;
3165                                 }
3166
3167                                 if (mult < 17) mult = 17;
3168                         }
3169
3170                         /* Kill Animal */
3171                         if ((have_flag(flgs, TR_KILL_ANIMAL)) &&
3172                             (r_ptr->flags3 & RF3_ANIMAL))
3173                         {
3174                                 if (is_original_ap_and_seen(m_ptr))
3175                                 {
3176                                         r_ptr->r_flags3 |= RF3_ANIMAL;
3177                                 }
3178
3179                                 if (mult < 27) mult = 27;
3180                         }
3181
3182                         /* Slay Evil */
3183                         if ((have_flag(flgs, TR_SLAY_EVIL)) &&
3184                             (r_ptr->flags3 & RF3_EVIL))
3185                         {
3186                                 if (is_original_ap_and_seen(m_ptr))
3187                                 {
3188                                         r_ptr->r_flags3 |= RF3_EVIL;
3189                                 }
3190
3191                                 if (mult < 15) mult = 15;
3192                         }
3193
3194                         /* Kill Evil */
3195                         if ((have_flag(flgs, TR_KILL_EVIL)) &&
3196                             (r_ptr->flags3 & RF3_EVIL))
3197                         {
3198                                 if (is_original_ap_and_seen(m_ptr))
3199                                 {
3200                                         r_ptr->r_flags3 |= RF3_EVIL;
3201                                 }
3202
3203                                 if (mult < 25) mult = 25;
3204                         }
3205
3206                         /* Slay Human */
3207                         if ((have_flag(flgs, TR_SLAY_HUMAN)) &&
3208                             (r_ptr->flags2 & RF2_HUMAN))
3209                         {
3210                                 if (is_original_ap_and_seen(m_ptr))
3211                                 {
3212                                         r_ptr->r_flags2 |= RF2_HUMAN;
3213                                 }
3214
3215                                 if (mult < 17) mult = 17;
3216                         }
3217
3218                         /* Kill Human */
3219                         if ((have_flag(flgs, TR_KILL_HUMAN)) &&
3220                             (r_ptr->flags2 & RF2_HUMAN))
3221                         {
3222                                 if (is_original_ap_and_seen(m_ptr))
3223                                 {
3224                                         r_ptr->r_flags2 |= RF2_HUMAN;
3225                                 }
3226
3227                                 if (mult < 27) mult = 27;
3228                         }
3229
3230                         /* Slay Undead */
3231                         if ((have_flag(flgs, TR_SLAY_UNDEAD)) &&
3232                             (r_ptr->flags3 & RF3_UNDEAD))
3233                         {
3234                                 if (is_original_ap_and_seen(m_ptr))
3235                                 {
3236                                         r_ptr->r_flags3 |= RF3_UNDEAD;
3237                                 }
3238
3239                                 if (mult < 20) mult = 20;
3240                         }
3241
3242                         /* Kill Undead */
3243                         if ((have_flag(flgs, TR_KILL_UNDEAD)) &&
3244                             (r_ptr->flags3 & RF3_UNDEAD))
3245                         {
3246                                 if (is_original_ap_and_seen(m_ptr))
3247                                 {
3248                                         r_ptr->r_flags3 |= RF3_UNDEAD;
3249                                 }
3250
3251                                 if (mult < 30) mult = 30;
3252                         }
3253
3254                         /* Slay Demon */
3255                         if ((have_flag(flgs, TR_SLAY_DEMON)) &&
3256                             (r_ptr->flags3 & RF3_DEMON))
3257                         {
3258                                 if (is_original_ap_and_seen(m_ptr))
3259                                 {
3260                                         r_ptr->r_flags3 |= RF3_DEMON;
3261                                 }
3262
3263                                 if (mult < 20) mult = 20;
3264                         }
3265
3266                         /* Kill Demon */
3267                         if ((have_flag(flgs, TR_KILL_DEMON)) &&
3268                             (r_ptr->flags3 & RF3_DEMON))
3269                         {
3270                                 if (is_original_ap_and_seen(m_ptr))
3271                                 {
3272                                         r_ptr->r_flags3 |= RF3_DEMON;
3273                                 }
3274
3275                                 if (mult < 30) mult = 30;
3276                         }
3277
3278                         /* Slay Orc */
3279                         if ((have_flag(flgs, TR_SLAY_ORC)) &&
3280                             (r_ptr->flags3 & RF3_ORC))
3281                         {
3282                                 if (is_original_ap_and_seen(m_ptr))
3283                                 {
3284                                         r_ptr->r_flags3 |= RF3_ORC;
3285                                 }
3286
3287                                 if (mult < 20) mult = 20;
3288                         }
3289
3290                         /* Kill Orc */
3291                         if ((have_flag(flgs, TR_KILL_ORC)) &&
3292                             (r_ptr->flags3 & RF3_ORC))
3293                         {
3294                                 if (is_original_ap_and_seen(m_ptr))
3295                                 {
3296                                         r_ptr->r_flags3 |= RF3_ORC;
3297                                 }
3298
3299                                 if (mult < 30) mult = 30;
3300                         }
3301
3302                         /* Slay Troll */
3303                         if ((have_flag(flgs, TR_SLAY_TROLL)) &&
3304                             (r_ptr->flags3 & RF3_TROLL))
3305                         {
3306                                 if (is_original_ap_and_seen(m_ptr))
3307                                 {
3308                                         r_ptr->r_flags3 |= RF3_TROLL;
3309                                 }
3310
3311                                 if (mult < 20) mult = 20;
3312                         }
3313
3314                         /* Kill Troll */
3315                         if ((have_flag(flgs, TR_KILL_TROLL)) &&
3316                             (r_ptr->flags3 & RF3_TROLL))
3317                         {
3318                                 if (is_original_ap_and_seen(m_ptr))
3319                                 {
3320                                         r_ptr->r_flags3 |= RF3_TROLL;
3321                                 }
3322
3323                                 if (mult < 30) mult = 30;
3324                         }
3325
3326                         /* Slay Giant */
3327                         if ((have_flag(flgs, TR_SLAY_GIANT)) &&
3328                             (r_ptr->flags3 & RF3_GIANT))
3329                         {
3330                                 if (is_original_ap_and_seen(m_ptr))
3331                                 {
3332                                         r_ptr->r_flags3 |= RF3_GIANT;
3333                                 }
3334
3335                                 if (mult < 20) mult = 20;
3336                         }
3337
3338                         /* Kill Giant */
3339                         if ((have_flag(flgs, TR_KILL_GIANT)) &&
3340                             (r_ptr->flags3 & RF3_GIANT))
3341                         {
3342                                 if (is_original_ap_and_seen(m_ptr))
3343                                 {
3344                                         r_ptr->r_flags3 |= RF3_GIANT;
3345                                 }
3346
3347                                 if (mult < 30) mult = 30;
3348                         }
3349
3350                         /* Slay Dragon  */
3351                         if ((have_flag(flgs, TR_SLAY_DRAGON)) &&
3352                             (r_ptr->flags3 & RF3_DRAGON))
3353                         {
3354                                 if (is_original_ap_and_seen(m_ptr))
3355                                 {
3356                                         r_ptr->r_flags3 |= RF3_DRAGON;
3357                                 }
3358
3359                                 if (mult < 20) mult = 20;
3360                         }
3361
3362                         /* Execute Dragon */
3363                         if ((have_flag(flgs, TR_KILL_DRAGON)) &&
3364                             (r_ptr->flags3 & RF3_DRAGON))
3365                         {
3366                                 if (is_original_ap_and_seen(m_ptr))
3367                                 {
3368                                         r_ptr->r_flags3 |= RF3_DRAGON;
3369                                 }
3370
3371                                 if (mult < 30) mult = 30;
3372
3373                                 if ((o_ptr->name1 == ART_BARD_ARROW) &&
3374                                     (m_ptr->r_idx == MON_SMAUG) &&
3375                                     (inventory[INVEN_BOW].name1 == ART_BARD))
3376                                         mult *= 5;
3377                         }
3378
3379                         /* Brand (Acid) */
3380                         if (have_flag(flgs, TR_BRAND_ACID))
3381                         {
3382                                 /* Notice immunity */
3383                                 if (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK)
3384                                 {
3385                                         if (is_original_ap_and_seen(m_ptr))
3386                                         {
3387                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK);
3388                                         }
3389                                 }
3390
3391                                 /* Otherwise, take the damage */
3392                                 else
3393                                 {
3394                                         if (mult < 17) mult = 17;
3395                                 }
3396                         }
3397
3398                         /* Brand (Elec) */
3399                         if (have_flag(flgs, TR_BRAND_ELEC))
3400                         {
3401                                 /* Notice immunity */
3402                                 if (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)
3403                                 {
3404                                         if (is_original_ap_and_seen(m_ptr))
3405                                         {
3406                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
3407                                         }
3408                                 }
3409
3410                                 /* Otherwise, take the damage */
3411                                 else
3412                                 {
3413                                         if (mult < 17) mult = 17;
3414                                 }
3415                         }
3416
3417                         /* Brand (Fire) */
3418                         if (have_flag(flgs, TR_BRAND_FIRE))
3419                         {
3420                                 /* Notice immunity */
3421                                 if (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)
3422                                 {
3423                                         if (is_original_ap_and_seen(m_ptr))
3424                                         {
3425                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
3426                                         }
3427                                 }
3428
3429                                 /* Otherwise, take the damage */
3430                                 else
3431                                 {
3432                                         if (r_ptr->flags3 & RF3_HURT_FIRE)
3433                                         {
3434                                                 if (mult < 25) mult = 25;
3435                                                 if (is_original_ap_and_seen(m_ptr))
3436                                                 {
3437                                                         r_ptr->r_flags3 |= RF3_HURT_FIRE;
3438                                                 }
3439                                         }
3440                                         else if (mult < 17) mult = 17;
3441                                 }
3442                         }
3443
3444                         /* Brand (Cold) */
3445                         if (have_flag(flgs, TR_BRAND_COLD))
3446                         {
3447                                 /* Notice immunity */
3448                                 if (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)
3449                                 {
3450                                         if (is_original_ap_and_seen(m_ptr))
3451                                         {
3452                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
3453                                         }
3454                                 }
3455                                 /* Otherwise, take the damage */
3456                                 else
3457                                 {
3458                                         if (r_ptr->flags3 & RF3_HURT_COLD)
3459                                         {
3460                                                 if (mult < 25) mult = 25;
3461                                                 if (is_original_ap_and_seen(m_ptr))
3462                                                 {
3463                                                         r_ptr->r_flags3 |= RF3_HURT_COLD;
3464                                                 }
3465                                         }
3466                                         else if (mult < 17) mult = 17;
3467                                 }
3468                         }
3469
3470                         /* Brand (Poison) */
3471                         if (have_flag(flgs, TR_BRAND_POIS))
3472                         {
3473                                 /* Notice immunity */
3474                                 if (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)
3475                                 {
3476                                         if (is_original_ap_and_seen(m_ptr))
3477                                         {
3478                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK);
3479                                         }
3480                                 }
3481
3482                                 /* Otherwise, take the damage */
3483                                 else
3484                                 {
3485                                         if (mult < 17) mult = 17;
3486                                 }
3487                         }
3488
3489                         if ((have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (p_ptr->msp / 30)))
3490                         {
3491                                 p_ptr->csp -= (1+(p_ptr->msp / 30));
3492                                 p_ptr->redraw |= (PR_MANA);
3493                                 mult = mult * 5 / 2;
3494                         }
3495                         break;
3496                 }
3497         }
3498
3499         /* Sniper */
3500         if (snipe_type) mult = tot_dam_aux_snipe(mult, m_ptr);
3501
3502         /* Return the total damage */
3503         return (tdam * mult / 10);
3504 }
3505
3506
3507 /*!
3508  * @brief ¼Í·â½èÍý¤Î¥µ¥Ö¥ë¡¼¥Á¥ó /
3509  * Fire an object from the pack or floor.
3510  * @param item ¼Í·â¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Î½ê»ýID
3511  * @param j_ptr ¼Í·âÉð´ï¤Î¥ª¥Ö¥¸¥§¥¯¥È»²¾È¥Ý¥¤¥ó¥¿
3512  * @return ¤Ê¤·
3513  * @details
3514  * <pre>
3515  * You may only fire items that "match" your missile launcher.
3516  *
3517  * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
3518  *
3519  * See "calc_bonuses()" for more calculations and such.
3520  *
3521  * Note that "firing" a missile is MUCH better than "throwing" it.
3522  *
3523  * Note: "unseen" monsters are very hard to hit.
3524  *
3525  * Objects are more likely to break if they "attempt" to hit a monster.
3526  *
3527  * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
3528  *
3529  * The "extra shot" code works by decreasing the amount of energy
3530  * required to make each shot, spreading the shots out over time.
3531  *
3532  * Note that when firing missiles, the launcher multiplier is applied
3533  * after all the bonuses are added in, making multipliers very useful.
3534  *
3535  * Note that Bows of "Extra Might" get extra range and an extra bonus
3536  * for the damage multiplier.
3537  *
3538  * Note that Bows of "Extra Shots" give an extra shot.
3539  * </pre>
3540  */
3541 void do_cmd_fire_aux(int item, object_type *j_ptr)
3542 {
3543         int dir;
3544         int i, j, y, x, ny, nx, ty, tx, prev_y, prev_x;
3545         int tdam_base, tdis, thits, tmul;
3546         int bonus, chance;
3547         int cur_dis, visible;
3548
3549         object_type forge;
3550         object_type *q_ptr;
3551
3552         object_type *o_ptr;
3553
3554         bool hit_body = FALSE;
3555
3556         char o_name[MAX_NLEN];
3557
3558         u16b path_g[512];       /* For calcuration of path length */
3559
3560         int msec = delay_factor * delay_factor * delay_factor;
3561
3562         /* STICK TO */
3563         bool stick_to = FALSE;
3564
3565         /* Access the item (if in the pack) */
3566         if (item >= 0)
3567         {
3568                 o_ptr = &inventory[item];
3569         }
3570         else
3571         {
3572                 o_ptr = &o_list[0 - item];
3573         }
3574
3575         /* Sniper - Cannot shot a single arrow twice */
3576         if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2)) snipe_type = SP_NONE;
3577
3578         /* Describe the object */
3579         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
3580
3581         /* Use the proper number of shots */
3582         thits = p_ptr->num_fire;
3583
3584         /* Use a base distance */
3585         tdis = 10;
3586
3587         /* Base damage from thrown object plus launcher bonus */
3588         tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
3589
3590         /* Actually "fire" the object */
3591         bonus = (p_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
3592         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
3593                 chance = (p_ptr->skill_thb + (p_ptr->weapon_exp[0][j_ptr->sval] / 400 + bonus) * BTH_PLUS_ADJ);
3594         else
3595                 chance = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
3596
3597         energy_use = bow_energy(j_ptr->sval);
3598         tmul = bow_tmul(j_ptr->sval);
3599
3600         /* Get extra "power" from "extra might" */
3601         if (p_ptr->xtra_might) tmul++;
3602
3603         tmul = tmul * (100 + (int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
3604
3605         /* Boost the damage */
3606         tdam_base *= tmul;
3607         tdam_base /= 100;
3608
3609         /* Base range */
3610         tdis = 13 + tmul/80;
3611         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
3612         {
3613                 if (p_ptr->concent)
3614                         tdis -= (5 - (p_ptr->concent + 1) / 2);
3615                 else
3616                         tdis -= 5;
3617         }
3618
3619         project_length = tdis + 1;
3620
3621         /* Get a direction (or cancel) */
3622         if (!get_aim_dir(&dir))
3623         {
3624                 energy_use = 0;
3625
3626                 if (snipe_type == SP_AWAY) snipe_type = SP_NONE;
3627
3628                 /* need not to reset project_length (already did)*/
3629
3630                 return;
3631         }
3632
3633         /* Predict the "target" location */
3634         tx = px + 99 * ddx[dir];
3635         ty = py + 99 * ddy[dir];
3636
3637         /* Check for "target request" */
3638         if ((dir == 5) && target_okay())
3639         {
3640                 tx = target_col;
3641                 ty = target_row;
3642         }
3643
3644         /* Get projection path length */
3645         tdis = project_path(path_g, project_length, py, px, ty, tx, PROJECT_PATH|PROJECT_THRU) - 1;
3646
3647         project_length = 0; /* reset to default */
3648
3649         /* Don't shoot at my feet */
3650         if (tx == px && ty == py)
3651         {
3652                 energy_use = 0;
3653
3654                 /* project_length is already reset to 0 */
3655
3656                 return;
3657         }
3658
3659
3660         /* Take a (partial) turn */
3661         energy_use = (energy_use / thits);
3662         is_fired = TRUE;
3663
3664         /* Sniper - Difficult to shot twice at 1 turn */
3665         if (snipe_type == SP_DOUBLE)  p_ptr->concent = (p_ptr->concent + 1) / 2;
3666
3667         /* Sniper - Repeat shooting when double shots */
3668         for (i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++)
3669         {
3670
3671         /* Start at the player */
3672         y = py;
3673         x = px;
3674
3675         /* Get local object */
3676         q_ptr = &forge;
3677
3678         /* Obtain a local object */
3679         object_copy(q_ptr, o_ptr);
3680
3681         /* Single object */
3682         q_ptr->number = 1;
3683
3684         /* Reduce and describe inventory */
3685         if (item >= 0)
3686         {
3687                 inven_item_increase(item, -1);
3688                 inven_item_describe(item);
3689                 inven_item_optimize(item);
3690         }
3691
3692         /* Reduce and describe floor item */
3693         else
3694         {
3695                 floor_item_increase(0 - item, -1);
3696                 floor_item_optimize(0 - item);
3697         }
3698
3699         /* Sound */
3700         sound(SOUND_SHOOT);
3701
3702         /* Hack -- Handle stuff */
3703         handle_stuff();
3704
3705         /* Save the old location */
3706         prev_y = y;
3707         prev_x = x;
3708
3709         /* The shot does not hit yet */
3710         hit_body = FALSE;
3711
3712         /* Travel until stopped */
3713         for (cur_dis = 0; cur_dis <= tdis; )
3714         {
3715                 cave_type *c_ptr;
3716
3717                 /* Hack -- Stop at the target */
3718                 if ((y == ty) && (x == tx)) break;
3719
3720                 /* Calculate the new location (see "project()") */
3721                 ny = y;
3722                 nx = x;
3723                 mmove2(&ny, &nx, py, px, ty, tx);
3724
3725                 /* Shatter Arrow */
3726                 if (snipe_type == SP_KILL_WALL)
3727                 {
3728                         c_ptr = &cave[ny][nx];
3729
3730                         if (cave_have_flag_grid(c_ptr, FF_HURT_ROCK) && !c_ptr->m_idx)
3731                         {
3732 #ifdef JP
3733                                 if (c_ptr->info & (CAVE_MARK)) msg_print("´ä¤¬ºÕ¤±»¶¤Ã¤¿¡£");
3734 #else
3735                                 if (c_ptr->info & (CAVE_MARK)) msg_print("Wall rocks were shattered.");
3736 #endif
3737                                 /* Forget the wall */
3738                                 c_ptr->info &= ~(CAVE_MARK);
3739
3740                                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
3741
3742                                 /* Destroy the wall */
3743                                 cave_alter_feat(ny, nx, FF_HURT_ROCK);
3744
3745                                 hit_body = TRUE;
3746                                 break;
3747                         }
3748                 }
3749
3750                 /* Stopped by walls/doors */
3751                 if (!cave_have_flag_bold(ny, nx, FF_PROJECT) && !cave[ny][nx].m_idx) break;
3752
3753                 /* Advance the distance */
3754                 cur_dis++;
3755
3756                 /* Sniper */
3757                 if (snipe_type == SP_LITE)
3758                 {
3759                         cave[ny][nx].info |= (CAVE_GLOW);
3760
3761                         /* Notice */
3762                         note_spot(ny, nx);
3763
3764                         /* Redraw */
3765                         lite_spot(ny, nx);
3766                 }
3767
3768                 /* The player can see the (on screen) missile */
3769                 if (panel_contains(ny, nx) && player_can_see_bold(ny, nx))
3770                 {
3771                         char c = object_char(q_ptr);
3772                         byte a = object_attr(q_ptr);
3773
3774                         /* Draw, Hilite, Fresh, Pause, Erase */
3775                         print_rel(c, a, ny, nx);
3776                         move_cursor_relative(ny, nx);
3777                         Term_fresh();
3778                         Term_xtra(TERM_XTRA_DELAY, msec);
3779                         lite_spot(ny, nx);
3780                         Term_fresh();
3781                 }
3782
3783                 /* The player cannot see the missile */
3784                 else
3785                 {
3786                         /* Pause anyway, for consistancy */
3787                         Term_xtra(TERM_XTRA_DELAY, msec);
3788                 }
3789
3790                 /* Sniper */
3791                 if (snipe_type == SP_KILL_TRAP)
3792                 {
3793                         project(0, 0, ny, nx, 0, GF_KILL_TRAP,
3794                                 (PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM), -1);
3795                 }
3796
3797                 /* Sniper */
3798                 if (snipe_type == SP_EVILNESS)
3799                 {
3800                         cave[ny][nx].info &= ~(CAVE_GLOW | CAVE_MARK);
3801
3802                         /* Notice */
3803                         note_spot(ny, nx);
3804
3805                         /* Redraw */
3806                         lite_spot(ny, nx);
3807                 }
3808
3809                 /* Save the old location */
3810                 prev_y = y;
3811                 prev_x = x;
3812
3813                 /* Save the new location */
3814                 x = nx;
3815                 y = ny;
3816
3817
3818                 /* Monster here, Try to hit it */
3819                 if (cave[y][x].m_idx)
3820                 {
3821                         int armour;
3822                         cave_type *c_ptr = &cave[y][x];
3823
3824                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
3825                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
3826
3827                         /* Check the visibility */
3828                         visible = m_ptr->ml;
3829
3830                         /* Note the collision */
3831                         hit_body = TRUE;
3832
3833                         if (MON_CSLEEP(m_ptr))
3834                         {
3835                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_COMPASSION, -1);
3836                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_HONOUR, -1);
3837                         }
3838
3839                         if ((r_ptr->level + 10) > p_ptr->lev)
3840                         {
3841                                 int now_exp = p_ptr->weapon_exp[0][j_ptr->sval];
3842                                 if (now_exp < s_info[p_ptr->pclass].w_max[0][j_ptr->sval])
3843                                 {
3844                                         int amount = 0;
3845                                         if (now_exp < WEAPON_EXP_BEGINNER) amount = 80;
3846                                         else if (now_exp < WEAPON_EXP_SKILLED) amount = 25;
3847                                         else if ((now_exp < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19)) amount = 10;
3848                                         else if (p_ptr->lev > 34) amount = 2;
3849                                         p_ptr->weapon_exp[0][j_ptr->sval] += amount;
3850                                         p_ptr->update |= (PU_BONUS);
3851                                 }
3852                         }
3853
3854                         if (p_ptr->riding)
3855                         {
3856                                 if ((p_ptr->skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING])
3857                                         && ((p_ptr->skill_exp[GINOU_RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 < r_info[m_list[p_ptr->riding].r_idx].level)
3858                                         && one_in_(2))
3859                                 {
3860                                         p_ptr->skill_exp[GINOU_RIDING] += 1;
3861                                         p_ptr->update |= (PU_BONUS);
3862                                 }
3863                         }
3864
3865                         /* Some shots have hit bonus */
3866                         armour = r_ptr->ac;
3867                         if (p_ptr->concent)
3868                         {
3869                                 armour *= (8 - p_ptr->concent);
3870                                 armour /= 8;
3871                         }
3872
3873                         /* Did we hit it (penalize range) */
3874                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
3875                         {
3876                                 bool fear = FALSE;
3877                                 int tdam = tdam_base;
3878
3879                                 /* Get extra damage from concentration */
3880                                 if (p_ptr->concent) tdam = boost_concentration_damage(tdam);
3881
3882                                 /* Handle unseen monster */
3883                                 if (!visible)
3884                                 {
3885                                         /* Invisible monster */
3886 #ifdef JP
3887                                         msg_format("%s¤¬Å¨¤òÊ᪤·¤¿¡£", o_name);
3888 #else
3889                                         msg_format("The %s finds a mark.", o_name);
3890 #endif
3891
3892                                 }
3893
3894                                 /* Handle visible monster */
3895                                 else
3896                                 {
3897                                         char m_name[80];
3898
3899                                         /* Get "the monster" or "it" */
3900                                         monster_desc(m_name, m_ptr, 0);
3901
3902                                         /* Message */
3903 #ifdef JP
3904                                         msg_format("%s¤¬%s¤ËÌ¿Ã椷¤¿¡£", o_name, m_name);
3905 #else
3906                                         msg_format("The %s hits %s.", o_name, m_name);
3907 #endif
3908
3909                                         if (m_ptr->ml)
3910                                         {
3911                                                 /* Hack -- Track this monster race */
3912                                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
3913
3914                                                 /* Hack -- Track this monster */
3915                                                 health_track(c_ptr->m_idx);
3916                                         }
3917                                 }
3918
3919                                 if (snipe_type == SP_NEEDLE)
3920                                 {
3921                                         if ((randint1(randint1(r_ptr->level / (3 + p_ptr->concent)) + (8 - p_ptr->concent)) == 1)
3922                                                 && !(r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_UNIQUE2))
3923                                         {
3924                                                 char m_name[80];
3925
3926                                                 /* Get "the monster" or "it" */
3927                                                 monster_desc(m_name, m_ptr, 0);
3928
3929                                                 tdam = m_ptr->hp + 1;
3930 #ifdef JP
3931                                                 msg_format("%s¤ÎµÞ½ê¤ËÆͤ­»É¤µ¤Ã¤¿¡ª", m_name);
3932 #else
3933                                                 msg_format("Your shot sticked on a fatal spot of %s!", m_name);
3934 #endif
3935                                         }
3936                                         else tdam = 1;
3937                                 }
3938                                 else
3939                                 {
3940                                         /* Apply special damage XXX XXX XXX */
3941                                         tdam = tot_dam_aux_shot(q_ptr, tdam, m_ptr);
3942                                         tdam = critical_shot(q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
3943
3944                                         /* No negative damage */
3945                                         if (tdam < 0) tdam = 0;
3946
3947                                         /* Modify the damage */
3948                                         tdam = mon_damage_mod(m_ptr, tdam, FALSE);
3949                                 }
3950
3951                                 /* Complex message */
3952                                 if (p_ptr->wizard || cheat_xtra)
3953                                 {
3954 #ifdef JP
3955                                         msg_format("%d/%d ¤Î¥À¥á¡¼¥¸¤òÍ¿¤¨¤¿¡£",
3956                                                    tdam, m_ptr->hp);
3957 #else
3958                                         msg_format("You do %d (out of %d) damage.",
3959                                                    tdam, m_ptr->hp);
3960 #endif
3961
3962                                 }
3963
3964                                 /* Sniper */
3965                                 if (snipe_type == SP_EXPLODE)
3966                                 {
3967                                         u16b flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
3968
3969                                         sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
3970                                         project(0, ((p_ptr->concent + 1) / 2 + 1), ny, nx, tdam, GF_MISSILE, flg, -1);
3971                                         break;
3972                                 }
3973
3974                                 /* Sniper */
3975                                 if (snipe_type == SP_HOLYNESS)
3976                                 {
3977                                         cave[ny][nx].info |= (CAVE_GLOW);
3978
3979                                         /* Notice */
3980                                         note_spot(ny, nx);
3981
3982                                         /* Redraw */
3983                                         lite_spot(ny, nx);
3984                                 }
3985
3986                                 /* Hit the monster, check for death */
3987                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
3988                                 {
3989                                         /* Dead monster */
3990                                 }
3991
3992                                 /* No death */
3993                                 else
3994                                 {
3995                                         /* STICK TO */
3996                                         if (object_is_fixed_artifact(q_ptr) &&
3997                                                 (p_ptr->pclass != CLASS_SNIPER || p_ptr->concent == 0))
3998                                         {
3999                                                 char m_name[80];
4000
4001                                                 monster_desc(m_name, m_ptr, 0);
4002
4003                                                 stick_to = TRUE;
4004 #ifdef JP
4005                                                 msg_format("%s¤Ï%s¤ËÆͤ­»É¤µ¤Ã¤¿¡ª",o_name, m_name);
4006 #else
4007                                                 msg_format("%^s have stuck into %s!",o_name, m_name);
4008 #endif
4009                                         }
4010
4011                                         /* Message */
4012                                         message_pain(c_ptr->m_idx, tdam);
4013
4014                                         /* Anger the monster */
4015                                         if (tdam > 0) anger_monster(m_ptr);
4016
4017                                         /* Take note */
4018                                         if (fear && m_ptr->ml)
4019                                         {
4020                                                 char m_name[80];
4021
4022                                                 /* Sound */
4023                                                 sound(SOUND_FLEE);
4024
4025                                                 /* Get the monster name (or "it") */
4026                                                 monster_desc(m_name, m_ptr, 0);
4027
4028                                                 /* Message */
4029 #ifdef JP
4030                                                 msg_format("%^s¤Ï¶²Éݤ·¤Æƨ¤²½Ð¤·¤¿¡ª", m_name);
4031 #else
4032                                                 msg_format("%^s flees in terror!", m_name);
4033 #endif
4034
4035                                         }
4036
4037                                         set_target(m_ptr, py, px);
4038
4039                                         /* Sniper */
4040                                         if (snipe_type == SP_RUSH)
4041                                         {
4042                                                 int n = randint1(5) + 3;
4043                                                 int m_idx = c_ptr->m_idx;
4044
4045                                                 for ( ; cur_dis <= tdis; )
4046                                                 {
4047                                                         int ox = nx;
4048                                                         int oy = ny;
4049
4050                                                         if (!n) break;
4051
4052                                                         /* Calculate the new location (see "project()") */
4053                                                         mmove2(&ny, &nx, py, px, ty, tx);
4054
4055                                                         /* Stopped by wilderness boundary */
4056                                                         if (!in_bounds2(ny, nx)) break;
4057
4058                                                         /* Stopped by walls/doors */
4059                                                         if (!player_can_enter(cave[ny][nx].feat, 0)) break;
4060
4061                                                         /* Stopped by monsters */
4062                                                         if (!cave_empty_bold(ny, nx)) break;
4063
4064                                                         cave[ny][nx].m_idx = m_idx;
4065                                                         cave[oy][ox].m_idx = 0;
4066
4067                                                         m_ptr->fx = nx;
4068                                                         m_ptr->fy = ny;
4069
4070                                                         /* Update the monster (new location) */
4071                                                         update_mon(c_ptr->m_idx, TRUE);
4072
4073                                                         lite_spot(ny, nx);
4074                                                         lite_spot(oy, ox);
4075
4076                                                         Term_fresh();
4077                                                         Term_xtra(TERM_XTRA_DELAY, msec);
4078
4079                                                         x = nx;
4080                                                         y = ny;
4081                                                         cur_dis++;
4082                                                         n--;
4083                                                 }
4084                                         }
4085                                 }
4086                         }
4087
4088                         /* Sniper */
4089                         if (snipe_type == SP_PIERCE)
4090                         {
4091                                 if(p_ptr->concent < 1) break;
4092                                 p_ptr->concent--;
4093                                 continue;
4094                         }
4095
4096                         /* Stop looking */
4097                         break;
4098                 }
4099         }
4100
4101         /* Chance of breakage (during attacks) */
4102         j = (hit_body ? breakage_chance(q_ptr) : 0);
4103
4104         if (stick_to)
4105         {
4106                 int m_idx = cave[y][x].m_idx;
4107                 monster_type *m_ptr = &m_list[m_idx];
4108                 int o_idx = o_pop();
4109
4110                 if (!o_idx)
4111                 {
4112 #ifdef JP
4113                         msg_format("%s¤Ï¤É¤³¤«¤Ø¹Ô¤Ã¤¿¡£", o_name);
4114 #else
4115                         msg_format("The %s have gone to somewhere.", o_name);
4116 #endif
4117                         if (object_is_fixed_artifact(q_ptr))
4118                         {
4119                                 a_info[j_ptr->name1].cur_num = 0;
4120                         }
4121                         return;
4122                 }
4123
4124                 o_ptr = &o_list[o_idx];
4125                 object_copy(o_ptr, q_ptr);
4126
4127                 /* Forget mark */
4128                 o_ptr->marked &= OM_TOUCHED;
4129
4130                 /* Forget location */
4131                 o_ptr->iy = o_ptr->ix = 0;
4132
4133                 /* Memorize monster */
4134                 o_ptr->held_m_idx = m_idx;
4135
4136                 /* Build a stack */
4137                 o_ptr->next_o_idx = m_ptr->hold_o_idx;
4138
4139                 /* Carry object */
4140                 m_ptr->hold_o_idx = o_idx;
4141         }
4142         else if (cave_have_flag_bold(y, x, FF_PROJECT))
4143         {
4144                 /* Drop (or break) near that location */
4145                 (void)drop_near(q_ptr, j, y, x);
4146         }
4147         else
4148         {
4149                 /* Drop (or break) near that location */
4150                 (void)drop_near(q_ptr, j, prev_y, prev_x);
4151         }
4152
4153         /* Sniper - Repeat shooting when double shots */
4154         }
4155
4156         /* Sniper - Loose his/her concentration after any shot */
4157         if (p_ptr->concent) reset_concentration(FALSE);
4158 }
4159
4160 /*!
4161  * @brief ¼Í·â½èÍý¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó
4162  * @return ¤Ê¤·
4163  */
4164 void do_cmd_fire(void)
4165 {
4166         int item;
4167         object_type *j_ptr;
4168         cptr q, s;
4169
4170         is_fired = FALSE;       /* not fired yet */
4171
4172         /* Get the "bow" (if any) */
4173         j_ptr = &inventory[INVEN_BOW];
4174
4175         /* Require a launcher */
4176         if (!j_ptr->tval)
4177         {
4178 #ifdef JP
4179                 msg_print("¼Í·âÍѤÎÉð´ï¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£");
4180 #else
4181                 msg_print("You have nothing to fire with.");
4182 #endif
4183                 flush();
4184                 return;
4185         }
4186
4187         if (j_ptr->sval == SV_CRIMSON)
4188         {
4189 #ifdef JP
4190                 msg_print("¤³¤ÎÉð´ï¤Ïȯư¤·¤Æ»È¤¦¤â¤Î¤Î¤è¤¦¤À¡£");
4191 #else
4192                 msg_print("Do activate.");
4193 #endif
4194                 flush();
4195                 return;
4196         }
4197
4198
4199         if (p_ptr->special_defense & KATA_MUSOU)
4200         {
4201                 set_action(ACTION_NONE);
4202         }
4203
4204         /* Require proper missile */
4205         item_tester_tval = p_ptr->tval_ammo;
4206
4207         /* Get an item */
4208 #ifdef JP
4209         q = "¤É¤ì¤ò·â¤Á¤Þ¤¹¤«? ";
4210         s = "ȯ¼Í¤µ¤ì¤ë¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
4211 #else
4212         q = "Fire which item? ";
4213         s = "You have nothing to fire.";
4214 #endif
4215
4216         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
4217         {
4218                 flush();
4219                 return;
4220         }
4221
4222         /* Fire the item */
4223         do_cmd_fire_aux(item, j_ptr);
4224
4225         if (!is_fired || p_ptr->pclass != CLASS_SNIPER) return;
4226
4227         /* Sniper actions after some shootings */
4228         if (snipe_type == SP_AWAY)
4229         {
4230                 teleport_player(10 + (p_ptr->concent * 2), 0L);
4231         }
4232         if (snipe_type == SP_FINAL)
4233         {
4234 #ifdef JP
4235                 msg_print("¼Í·â¤ÎÈ¿Æ°¤¬ÂΤò½±¤Ã¤¿¡£");
4236 #else
4237                 msg_print("A reactionary of shooting attacked you. ");
4238 #endif
4239                 (void)set_slow(p_ptr->slow + randint0(7) + 7, FALSE);
4240                 (void)set_stun(p_ptr->stun + randint1(25));
4241         }
4242 }
4243
4244 /*!
4245  * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤¬Åê¼Í²Äǽ¤ÊÉð´ï¤«¤É¤¦¤«¤òÊÖ¤¹¡£
4246  * @param o_ptr È½Äꤹ¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
4247  * @return Åê¼Í²Äǽ¤ÊÉð´ï¤Ê¤é¤ÐTRUE
4248  */
4249 static bool item_tester_hook_boomerang(object_type *o_ptr)
4250 {
4251         if ((o_ptr->tval==TV_DIGGING) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM) || (o_ptr->tval == TV_HAFTED)) return (TRUE);
4252
4253         /* Assume not */
4254         return (FALSE);
4255 }
4256
4257
4258 /*!
4259  * @brief Åê¼Í½èÍý¤Î¥µ¥Ö¥ë¡¼¥Á¥ó /
4260  * Throw an object from the pack or floor.
4261  * @param mult °ÒÎϤÎÇÜΨ
4262  * @param boomerang ¥Ö¡¼¥á¥é¥ó½èÍý¤Ê¤é¤ÐTRUE
4263  * @param shuriken Ç¦¼Ô¤Î¼ê΢·õ½èÍý¤Ê¤é¤ÐTRUE
4264  * @return ¥¿¡¼¥ó¤ò¾ÃÈñ¤·¤¿¾ì¹çTRUE¤òÊÖ¤¹
4265  * @details
4266  * <pre>
4267  * Note: "unseen" monsters are very hard to hit.
4268  *
4269  * Should throwing a weapon do full damage?  Should it allow the magic
4270  * to hit bonus of the weapon to have an effect?  Should it ever cause
4271  * the item to be destroyed?  Should it do any damage at all?
4272  * </pre>
4273  */
4274 bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
4275 {
4276         int dir, item;
4277         int i, j, y, x, ty, tx, prev_y, prev_x;
4278         int ny[19], nx[19];
4279         int chance, tdam, tdis;
4280         int mul, div, dd, ds;
4281         int cur_dis, visible;
4282
4283         object_type forge;
4284         object_type *q_ptr;
4285
4286         object_type *o_ptr;
4287
4288         bool hit_body = FALSE;
4289         bool hit_wall = FALSE;
4290         bool equiped_item = FALSE;
4291         bool return_when_thrown = FALSE;
4292
4293         char o_name[MAX_NLEN];
4294
4295         int msec = delay_factor * delay_factor * delay_factor;
4296
4297         u32b flgs[TR_FLAG_SIZE];
4298         cptr q, s;
4299         bool come_back = FALSE;
4300         bool do_drop = TRUE;
4301
4302
4303         if (p_ptr->special_defense & KATA_MUSOU)
4304         {
4305                 set_action(ACTION_NONE);
4306         }
4307
4308         if (shuriken >= 0)
4309         {
4310                 item = shuriken;
4311         }
4312         else if (boomerang)
4313         {
4314                 if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
4315                 {
4316                         item_tester_hook = item_tester_hook_boomerang;
4317 #ifdef JP
4318                         q = "¤É¤ÎÉð´ï¤òÅꤲ¤Þ¤¹¤«? ";
4319                         s = "Åꤲ¤ëÉð´ï¤¬¤Ê¤¤¡£";
4320 #else
4321                         q = "Throw which item? ";
4322                         s = "You have nothing to throw.";
4323 #endif
4324
4325                         if (!get_item(&item, q, s, (USE_EQUIP)))
4326                         {
4327                                 flush();
4328                                 return FALSE;
4329                         }
4330                 }
4331                 else if (buki_motteruka(INVEN_LARM)) item = INVEN_LARM;
4332                 else item = INVEN_RARM;
4333         }
4334         else
4335         {
4336                 /* Get an item */
4337 #ifdef JP
4338                 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅꤲ¤Þ¤¹¤«? ";
4339                 s = "Åꤲ¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
4340 #else
4341                 q = "Throw which item? ";
4342                 s = "You have nothing to throw.";
4343 #endif
4344
4345                 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP)))
4346                 {
4347                         flush();
4348                         return FALSE;
4349                 }
4350         }
4351
4352         /* Access the item (if in the pack) */
4353         if (item >= 0)
4354         {
4355                 o_ptr = &inventory[item];
4356         }
4357         else
4358         {
4359                 o_ptr = &o_list[0 - item];
4360         }
4361
4362
4363         /* Item is cursed */
4364         if (object_is_cursed(o_ptr) && (item >= INVEN_RARM))
4365         {
4366                 /* Oops */
4367 #ifdef JP
4368                 msg_print("¤Õ¡¼¤à¡¢¤É¤¦¤ä¤é¼ö¤ï¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£");
4369 #else
4370                 msg_print("Hmmm, it seems to be cursed.");
4371 #endif
4372
4373                 /* Nope */
4374                 return FALSE;
4375         }
4376
4377         if (p_ptr->inside_arena && !boomerang)
4378         {
4379                 if (o_ptr->tval != TV_SPIKE)
4380                 {
4381 #ifdef JP
4382                         msg_print("¥¢¥ê¡¼¥Ê¤Ç¤Ï¥¢¥¤¥Æ¥à¤ò»È¤¨¤Ê¤¤¡ª");
4383 #else
4384                         msg_print("You're in the arena now. This is hand-to-hand!");
4385 #endif
4386                         msg_print(NULL);
4387
4388                         /* Nope */
4389                         return FALSE;
4390                 }
4391         }
4392
4393         /* Get local object */
4394         q_ptr = &forge;
4395
4396         /* Obtain a local object */
4397         object_copy(q_ptr, o_ptr);
4398
4399         /* Extract the thrown object's flags. */
4400         object_flags(q_ptr, flgs);
4401         torch_flags(q_ptr, flgs);
4402
4403         /* Distribute the charges of rods/wands between the stacks */
4404         distribute_charges(o_ptr, q_ptr, 1);
4405
4406         /* Single object */
4407         q_ptr->number = 1;
4408
4409         /* Description */
4410         object_desc(o_name, q_ptr, OD_OMIT_PREFIX);
4411
4412         if (p_ptr->mighty_throw) mult += 3;
4413
4414         /* Extract a "distance multiplier" */
4415         /* Changed for 'launcher' mutation */
4416         mul = 10 + 2 * (mult - 1);
4417
4418         /* Enforce a minimum "weight" of one pound */
4419         div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
4420         if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
4421
4422         /* Hack -- Distance -- Reward strength, penalize weight */
4423         tdis = (adj_str_blow[p_ptr->stat_ind[A_STR]] + 20) * mul / div;
4424
4425         /* Max distance of 10-18 */
4426         if (tdis > mul) tdis = mul;
4427
4428         if (shuriken >= 0)
4429         {
4430                 ty = randint0(101)-50+py;
4431                 tx = randint0(101)-50+px;
4432         }
4433         else
4434         {
4435                 project_length = tdis + 1;
4436
4437                 /* Get a direction (or cancel) */
4438                 if (!get_aim_dir(&dir)) return FALSE;
4439
4440                 /* Predict the "target" location */
4441                 tx = px + 99 * ddx[dir];
4442                 ty = py + 99 * ddy[dir];
4443
4444                 /* Check for "target request" */
4445                 if ((dir == 5) && target_okay())
4446                 {
4447                         tx = target_col;
4448                         ty = target_row;
4449                 }
4450
4451                 project_length = 0;  /* reset to default */
4452         }
4453
4454         if ((q_ptr->name1 == ART_MJOLLNIR) ||
4455             (q_ptr->name1 == ART_AEGISFANG) || boomerang)
4456                 return_when_thrown = TRUE;
4457
4458         /* Reduce and describe inventory */
4459         if (item >= 0)
4460         {
4461                 inven_item_increase(item, -1);
4462                 if (!return_when_thrown)
4463                         inven_item_describe(item);
4464                 inven_item_optimize(item);
4465         }
4466
4467         /* Reduce and describe floor item */
4468         else
4469         {
4470                 floor_item_increase(0 - item, -1);
4471                 floor_item_optimize(0 - item);
4472         }
4473         if (item >= INVEN_RARM)
4474         {
4475                 equiped_item = TRUE;
4476                 p_ptr->redraw |= (PR_EQUIPPY);
4477         }
4478
4479         /* Take a turn */
4480         energy_use = 100;
4481
4482         /* Rogue and Ninja gets bonus */
4483         if ((p_ptr->pclass == CLASS_ROGUE) || (p_ptr->pclass == CLASS_NINJA))
4484                 energy_use -= p_ptr->lev;
4485
4486         /* Start at the player */
4487         y = py;
4488         x = px;
4489
4490
4491         /* Hack -- Handle stuff */
4492         handle_stuff();
4493
4494         if ((p_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
4495         else shuriken = FALSE;
4496
4497         /* Chance of hitting */
4498         if (have_flag(flgs, TR_THROW)) chance = ((p_ptr->skill_tht) +
4499                 ((p_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
4500         else chance = (p_ptr->skill_tht + (p_ptr->to_h_b * BTH_PLUS_ADJ));
4501
4502         if (shuriken) chance *= 2;
4503
4504         /* Save the old location */
4505         prev_y = y;
4506         prev_x = x;
4507
4508         /* Travel until stopped */
4509         for (cur_dis = 0; cur_dis <= tdis; )
4510         {
4511                 /* Hack -- Stop at the target */
4512                 if ((y == ty) && (x == tx)) break;
4513
4514                 /* Calculate the new location (see "project()") */
4515                 ny[cur_dis] = y;
4516                 nx[cur_dis] = x;
4517                 mmove2(&ny[cur_dis], &nx[cur_dis], py, px, ty, tx);
4518
4519                 /* Stopped by walls/doors */
4520                 if (!cave_have_flag_bold(ny[cur_dis], nx[cur_dis], FF_PROJECT))
4521                 {
4522                         hit_wall = TRUE;
4523                         if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !cave[ny[cur_dis]][nx[cur_dis]].m_idx) break;
4524                 }
4525
4526                 /* The player can see the (on screen) missile */
4527                 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(ny[cur_dis], nx[cur_dis]))
4528                 {
4529                         char c = object_char(q_ptr);
4530                         byte a = object_attr(q_ptr);
4531
4532                         /* Draw, Hilite, Fresh, Pause, Erase */
4533                         print_rel(c, a, ny[cur_dis], nx[cur_dis]);
4534                         move_cursor_relative(ny[cur_dis], nx[cur_dis]);
4535                         Term_fresh();
4536                         Term_xtra(TERM_XTRA_DELAY, msec);
4537                         lite_spot(ny[cur_dis], nx[cur_dis]);
4538                         Term_fresh();
4539                 }
4540
4541                 /* The player cannot see the missile */
4542                 else
4543                 {
4544                         /* Pause anyway, for consistancy */
4545                         Term_xtra(TERM_XTRA_DELAY, msec);
4546                 }
4547
4548                 /* Save the old location */
4549                 prev_y = y;
4550                 prev_x = x;
4551
4552                 /* Save the new location */
4553                 x = nx[cur_dis];
4554                 y = ny[cur_dis];
4555
4556                 /* Advance the distance */
4557                 cur_dis++;
4558
4559                 /* Monster here, Try to hit it */
4560                 if (cave[y][x].m_idx)
4561                 {
4562                         cave_type *c_ptr = &cave[y][x];
4563
4564                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
4565                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4566
4567                         /* Check the visibility */
4568                         visible = m_ptr->ml;
4569
4570                         /* Note the collision */
4571                         hit_body = TRUE;
4572
4573                         /* Did we hit it (penalize range) */
4574                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
4575                         {
4576                                 bool fear = FALSE;
4577
4578                                 /* Handle unseen monster */
4579                                 if (!visible)
4580                                 {
4581                                         /* Invisible monster */
4582 #ifdef JP
4583                                         msg_format("%s¤¬Å¨¤òÊ᪤·¤¿¡£", o_name);
4584 #else
4585                                         msg_format("The %s finds a mark.", o_name);
4586 #endif
4587
4588                                 }
4589
4590                                 /* Handle visible monster */
4591                                 else
4592                                 {
4593                                         char m_name[80];
4594
4595                                         /* Get "the monster" or "it" */
4596                                         monster_desc(m_name, m_ptr, 0);
4597
4598                                         /* Message */
4599 #ifdef JP
4600                                         msg_format("%s¤¬%s¤ËÌ¿Ã椷¤¿¡£", o_name, m_name);
4601 #else
4602                                         msg_format("The %s hits %s.", o_name, m_name);
4603 #endif
4604
4605                                         if (m_ptr->ml)
4606                                         {
4607                                                 /* Hack -- Track this monster race */
4608                                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
4609
4610                                                 /* Hack -- Track this monster */
4611                                                 health_track(c_ptr->m_idx);
4612                                         }
4613                                 }
4614
4615                                 /* Hack -- Base damage from thrown object */
4616                                 dd = q_ptr->dd;
4617                                 ds = q_ptr->ds;
4618                                 torch_dice(q_ptr, &dd, &ds); /* throwing a torch */
4619                                 tdam = damroll(dd, ds);
4620                                 /* Apply special damage XXX XXX XXX */
4621                                 tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0, TRUE);
4622                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, 0, tdam);
4623                                 if (q_ptr->to_d > 0)
4624                                         tdam += q_ptr->to_d;
4625                                 else
4626                                         tdam += -q_ptr->to_d;
4627
4628                                 if (boomerang)
4629                                 {
4630                                         tdam *= (mult+p_ptr->num_blow[item - INVEN_RARM]);
4631                                         tdam += p_ptr->to_d_m;
4632                                 }
4633                                 else if (have_flag(flgs, TR_THROW))
4634                                 {
4635                                         tdam *= (3+mult);
4636                                         tdam += p_ptr->to_d_m;
4637                                 }
4638                                 else
4639                                 {
4640                                         tdam *= mult;
4641                                 }
4642                                 if (shuriken)
4643                                 {
4644                                         tdam += ((p_ptr->lev+30)*(p_ptr->lev+30)-900)/55;
4645                                 }
4646
4647                                 /* No negative damage */
4648                                 if (tdam < 0) tdam = 0;
4649
4650                                 /* Modify the damage */
4651                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
4652
4653                                 /* Complex message */
4654                                 if (p_ptr->wizard)
4655                                 {
4656 #ifdef JP
4657                                         msg_format("%d/%d¤Î¥À¥á¡¼¥¸¤òÍ¿¤¨¤¿¡£",
4658                                                    tdam, m_ptr->hp);
4659 #else
4660                                         msg_format("You do %d (out of %d) damage.",
4661                                                    tdam, m_ptr->hp);
4662 #endif
4663
4664                                 }
4665
4666                                 /* Hit the monster, check for death */
4667                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
4668                                 {
4669                                         /* Dead monster */
4670                                 }
4671
4672                                 /* No death */
4673                                 else
4674                                 {
4675                                         /* Message */
4676                                         message_pain(c_ptr->m_idx, tdam);
4677
4678                                         /* Anger the monster */
4679                                         if ((tdam > 0) && !object_is_potion(q_ptr))
4680                                                 anger_monster(m_ptr);
4681
4682                                         /* Take note */
4683                                         if (fear && m_ptr->ml)
4684                                         {
4685                                                 char m_name[80];
4686
4687                                                 /* Sound */
4688                                                 sound(SOUND_FLEE);
4689
4690                                                 /* Get the monster name (or "it") */
4691                                                 monster_desc(m_name, m_ptr, 0);
4692
4693                                                 /* Message */
4694 #ifdef JP
4695                                                 msg_format("%^s¤Ï¶²Éݤ·¤Æƨ¤²½Ð¤·¤¿¡ª", m_name);
4696 #else
4697                                                 msg_format("%^s flees in terror!", m_name);
4698 #endif
4699
4700                                         }
4701                                 }
4702                         }
4703
4704                         /* Stop looking */
4705                         break;
4706                 }
4707         }
4708
4709         /* decrease toach's fuel */
4710         if (hit_body) torch_lost_fuel(q_ptr);
4711
4712         /* Chance of breakage (during attacks) */
4713         j = (hit_body ? breakage_chance(q_ptr) : 0);
4714
4715         /* Figurines transform */
4716         if ((q_ptr->tval == TV_FIGURINE) && !(p_ptr->inside_arena))
4717         {
4718                 j = 100;
4719
4720                 if (!(summon_named_creature(0, y, x, q_ptr->pval,
4721                                             !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
4722 #ifdef JP
4723 msg_print("¿Í·Á¤ÏDZ¤¸¶Ê¤¬¤êºÕ¤±»¶¤Ã¤Æ¤·¤Þ¤Ã¤¿¡ª");
4724 #else
4725                         msg_print("The Figurine writhes and then shatters.");
4726 #endif
4727
4728                 else if (object_is_cursed(q_ptr))
4729 #ifdef JP
4730 msg_print("¤³¤ì¤Ï¤¢¤Þ¤êÎɤ¯¤Ê¤¤µ¤¤¬¤¹¤ë¡£");
4731 #else
4732                         msg_print("You have a bad feeling about this.");
4733 #endif
4734
4735         }
4736
4737
4738         /* Potions smash open */
4739         if (object_is_potion(q_ptr))
4740         {
4741                 if (hit_body || hit_wall || (randint1(100) < j))
4742                 {
4743                         /* Message */
4744 #ifdef JP
4745                         msg_format("%s¤ÏºÕ¤±»¶¤Ã¤¿¡ª", o_name);
4746 #else
4747                         msg_format("The %s shatters!", o_name);
4748 #endif
4749
4750
4751                         if (potion_smash_effect(0, y, x, q_ptr->k_idx))
4752                         {
4753                                 monster_type *m_ptr = &m_list[cave[y][x].m_idx];
4754
4755                                 /* ToDo (Robert): fix the invulnerability */
4756                                 if (cave[y][x].m_idx &&
4757                                     is_friendly(&m_list[cave[y][x].m_idx]) &&
4758                                     !MON_INVULNER(m_ptr))
4759                                 {
4760                                         char m_name[80];
4761                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
4762 #ifdef JP
4763                                         msg_format("%s¤ÏÅܤä¿¡ª", m_name);
4764 #else
4765                                         msg_format("%^s gets angry!", m_name);
4766 #endif
4767
4768                                         set_hostile(&m_list[cave[y][x].m_idx]);
4769                                 }
4770                         }
4771                         do_drop = FALSE;
4772                 }
4773                 else
4774                 {
4775                         j = 0;
4776                 }
4777         }
4778
4779         if (return_when_thrown)
4780         {
4781                 int back_chance = randint1(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4782                 char o2_name[MAX_NLEN];
4783                 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
4784
4785                 j = -1;
4786                 if (boomerang) back_chance += 4+randint1(5);
4787                 if (super_boomerang) back_chance += 100;
4788                 object_desc(o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4789
4790                 if((back_chance > 30) && (!one_in_(100) || super_boomerang))
4791                 {
4792                         for (i = cur_dis - 1; i > 0; i--)
4793                         {
4794                                 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(ny[i], nx[i]))
4795                                 {
4796                                         char c = object_char(q_ptr);
4797                                         byte a = object_attr(q_ptr);
4798
4799                                         /* Draw, Hilite, Fresh, Pause, Erase */
4800                                         print_rel(c, a, ny[i], nx[i]);
4801                                         move_cursor_relative(ny[i], nx[i]);
4802                                         Term_fresh();
4803                                         Term_xtra(TERM_XTRA_DELAY, msec);
4804                                         lite_spot(ny[i], nx[i]);
4805                                         Term_fresh();
4806                                 }
4807                                 else
4808                                 {
4809                                         /* Pause anyway, for consistancy */
4810                                         Term_xtra(TERM_XTRA_DELAY, msec);
4811                                 }
4812                         }
4813                         if((back_chance > 37) && !p_ptr->blind && (item >= 0))
4814                         {
4815 #ifdef JP
4816                                 msg_format("%s¤¬¼ê¸µ¤ËÊ֤äƤ­¤¿¡£", o2_name);
4817 #else
4818                                 msg_format("%s comes back to you.", o2_name);
4819 #endif
4820                                 come_back = TRUE;
4821                         }
4822                         else
4823                         {
4824                                 if (item >= 0)
4825                                 {
4826 #ifdef JP
4827                                         msg_format("%s¤ò¼õ¤±Â»¤Í¤¿¡ª", o2_name);
4828 #else
4829                                         msg_format("%s backs, but you can't catch!", o2_name);
4830 #endif
4831                                 }
4832                                 else
4833                                 {
4834 #ifdef JP
4835                                         msg_format("%s¤¬Ê֤äƤ­¤¿¡£", o2_name);
4836 #else
4837                                         msg_format("%s comes back.", o2_name);
4838 #endif
4839                                 }
4840                                 y = py;
4841                                 x = px;
4842                         }
4843                 }
4844                 else
4845                 {
4846 #ifdef JP
4847                         msg_format("%s¤¬Ê֤äƤ³¤Ê¤«¤Ã¤¿¡ª", o2_name);
4848 #else
4849                         msg_format("%s doesn't back!", o2_name);
4850 #endif
4851                 }
4852         }
4853
4854         if (come_back)
4855         {
4856                 if (item == INVEN_RARM || item == INVEN_LARM)
4857                 {
4858                         /* Access the wield slot */
4859                         o_ptr = &inventory[item];
4860
4861                         /* Wear the new stuff */
4862                         object_copy(o_ptr, q_ptr);
4863
4864                         /* Increase the weight */
4865                         p_ptr->total_weight += q_ptr->weight;
4866
4867                         /* Increment the equip counter by hand */
4868                         equip_cnt++;
4869
4870                         /* Recalculate bonuses */
4871                         p_ptr->update |= (PU_BONUS);
4872
4873                         /* Recalculate torch */
4874                         p_ptr->update |= (PU_TORCH);
4875
4876                         /* Recalculate mana XXX */
4877                         p_ptr->update |= (PU_MANA);
4878
4879                         /* Window stuff */
4880                         p_ptr->window |= (PW_EQUIP);
4881                 }
4882                 else
4883                 {
4884                         inven_carry(q_ptr);
4885                 }
4886                 do_drop = FALSE;
4887         }
4888         else if (equiped_item)
4889         {
4890                 kamaenaoshi(item);
4891                 calc_android_exp();
4892         }
4893
4894         /* Drop (or break) near that location */
4895         if (do_drop)
4896         {
4897                 if (cave_have_flag_bold(y, x, FF_PROJECT))
4898                 {
4899                         /* Drop (or break) near that location */
4900                         (void)drop_near(q_ptr, j, y, x);
4901                 }
4902                 else
4903                 {
4904                         /* Drop (or break) near that location */
4905                         (void)drop_near(q_ptr, j, prev_y, prev_x);
4906                 }
4907         }
4908
4909         return TRUE;
4910 }
4911
4912
4913 /*!
4914  * @brief Åê¼Í½èÍý¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
4915  * Throw an object from the pack or floor.
4916  * @return ¤Ê¤·
4917  */
4918 void do_cmd_throw(void)
4919 {
4920         do_cmd_throw_aux(1, FALSE, -1);
4921 }
4922
4923
4924 #ifdef TRAVEL
4925 /*
4926  * Hack: travel command
4927  */
4928 #define TRAVEL_UNABLE 9999
4929
4930 static int flow_head = 0;
4931 static int flow_tail = 0;
4932 static s16b temp2_x[MAX_SHORT];
4933 static s16b temp2_y[MAX_SHORT];
4934
4935 /* Hack: forget the "flow" information */
4936 void forget_travel_flow(void)
4937 {
4938         int x, y;
4939
4940         /* Check the entire dungeon */
4941         for (y = 0; y < cur_hgt; y++)
4942         {
4943                 for (x = 0; x < cur_wid; x++)
4944                 {
4945                         /* Forget the old data */
4946                         travel.cost[y][x] = MAX_SHORT;
4947                 }
4948         }
4949
4950         travel.y = travel.x = 0;
4951 }
4952
4953 static int travel_flow_cost(int y, int x)
4954 {
4955         feature_type *f_ptr = &f_info[cave[y][x].feat];
4956         int cost = 1;
4957
4958         /* Avoid obstacles (ex. trees) */
4959         if (have_flag(f_ptr->flags, FF_AVOID_RUN)) cost += 1;
4960
4961         /* Water */
4962         if (have_flag(f_ptr->flags, FF_WATER))
4963         {
4964                 if (have_flag(f_ptr->flags, FF_DEEP) && !p_ptr->levitation) cost += 5;
4965         }
4966
4967         /* Lava */
4968         if (have_flag(f_ptr->flags, FF_LAVA))
4969         {
4970                 int lava = 2;
4971                 if (!p_ptr->resist_fire) lava *= 2;
4972                 if (!p_ptr->levitation) lava *= 2;
4973                 if (have_flag(f_ptr->flags, FF_DEEP)) lava *= 2;
4974
4975                 cost += lava;
4976         }
4977
4978         /* Detected traps and doors */
4979         if (cave[y][x].info & (CAVE_MARK))
4980         {
4981                 if (have_flag(f_ptr->flags, FF_DOOR)) cost += 1;
4982                 if (have_flag(f_ptr->flags, FF_TRAP)) cost += 10;
4983         }
4984
4985         return (cost);
4986 }
4987
4988 static void travel_flow_aux(int y, int x, int n, bool wall)
4989 {
4990         cave_type *c_ptr = &cave[y][x];
4991         feature_type *f_ptr = &f_info[c_ptr->feat];
4992         int old_head = flow_head;
4993         int add_cost = 1;
4994         int base_cost = (n % TRAVEL_UNABLE);
4995         int from_wall = (n / TRAVEL_UNABLE);
4996         int cost;
4997
4998         /* Ignore out of bounds */
4999         if (!in_bounds(y, x)) return;
5000
5001         /* Ignore unknown grid except in wilderness */
5002         if (dun_level > 0 && !(c_ptr->info & CAVE_KNOWN)) return;
5003
5004         /* Ignore "walls" and "rubble" (include "secret doors") */
5005         if (have_flag(f_ptr->flags, FF_WALL) ||
5006                 have_flag(f_ptr->flags, FF_CAN_DIG) ||
5007                 (have_flag(f_ptr->flags, FF_DOOR) && cave[y][x].mimic) ||
5008                 (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation))
5009         {
5010                 if (!wall || !from_wall) return;
5011                 add_cost += TRAVEL_UNABLE;
5012         }
5013         else
5014         {
5015                 add_cost = travel_flow_cost(y, x);
5016         }
5017
5018         cost = base_cost + add_cost;
5019
5020         /* Ignore lower cost entries */
5021         if (travel.cost[y][x] <= cost) return;
5022
5023         /* Save the flow cost */
5024         travel.cost[y][x] = cost;
5025
5026         /* Enqueue that entry */
5027         temp2_y[flow_head] = y;
5028         temp2_x[flow_head] = x;
5029
5030         /* Advance the queue */
5031         if (++flow_head == MAX_SHORT) flow_head = 0;
5032
5033         /* Hack -- notice overflow by forgetting new entry */
5034         if (flow_head == flow_tail) flow_head = old_head;
5035
5036         return;
5037 }
5038
5039
5040 static void travel_flow(int ty, int tx)
5041 {
5042         int x, y, d;
5043         bool wall = FALSE;
5044         feature_type *f_ptr = &f_info[cave[py][px].feat];
5045
5046         /* Reset the "queue" */
5047         flow_head = flow_tail = 0;
5048
5049         /* is player in the wall? */
5050         if (!have_flag(f_ptr->flags, FF_MOVE)) wall = TRUE;
5051
5052         /* Start at the target grid */
5053         travel_flow_aux(ty, tx, 0, wall);
5054
5055         /* Now process the queue */
5056         while (flow_head != flow_tail)
5057         {
5058                 /* Extract the next entry */
5059                 y = temp2_y[flow_tail];
5060                 x = temp2_x[flow_tail];
5061
5062                 /* Forget that entry */
5063                 if (++flow_tail == MAX_SHORT) flow_tail = 0;
5064
5065                 /* Ignore too far entries */
5066                 //if (distance(ty, tx, y, x) > 100) continue;
5067
5068                 /* Add the "children" */
5069                 for (d = 0; d < 8; d++)
5070                 {
5071                         /* Add that child if "legal" */
5072                         travel_flow_aux(y + ddy_ddd[d], x + ddx_ddd[d], travel.cost[y][x], wall);
5073                 }
5074         }
5075
5076         /* Forget the flow info */
5077         flow_head = flow_tail = 0;
5078 }
5079
5080 /*!
5081  * @brief ¥È¥é¥Ù¥ë½èÍý¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó
5082  * @return ¤Ê¤·
5083  */
5084 void do_cmd_travel(void)
5085 {
5086         int x, y, i;
5087         int dx, dy, sx, sy;
5088         feature_type *f_ptr;
5089
5090         if (travel.x != 0 && travel.y != 0 &&
5091             get_check(_("¥È¥é¥Ù¥ë¤ò·Ñ³¤·¤Þ¤¹¤«¡©", "Do you continue to travel?")))
5092         {
5093                 y = travel.y;
5094                 x = travel.x;
5095         }
5096         else if (!tgt_pt(&x, &y)) return;
5097
5098         if ((x == px) && (y == py))
5099         {
5100 #ifdef JP
5101                 msg_print("¤¹¤Ç¤Ë¤½¤³¤Ë¤¤¤Þ¤¹¡ª");
5102 #else
5103                 msg_print("You are already there!!");
5104 #endif
5105                 return;
5106         }
5107
5108         f_ptr = &f_info[cave[y][x].feat];
5109
5110         if ((cave[y][x].info & CAVE_MARK) &&
5111                 (have_flag(f_ptr->flags, FF_WALL) ||
5112                         have_flag(f_ptr->flags, FF_CAN_DIG) ||
5113                         (have_flag(f_ptr->flags, FF_DOOR) && cave[y][x].mimic)))
5114         {
5115 #ifdef JP
5116                 msg_print("¤½¤³¤Ë¤Ï¹Ô¤¯¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¡ª");
5117 #else
5118                 msg_print("You cannot travel there!");
5119 #endif
5120                 return;
5121         }
5122
5123         forget_travel_flow();
5124         travel_flow(y, x);
5125
5126         travel.x = x;
5127         travel.y = y;
5128
5129         /* Travel till 255 steps */
5130         travel.run = 255;
5131
5132         /* Paranoia */
5133         travel.dir = 0;
5134
5135         /* Decides first direction */
5136         dx = abs(px - x);
5137         dy = abs(py - y);
5138         sx = ((x == px) || (dx < dy)) ? 0 : ((x > px) ? 1 : -1);
5139         sy = ((y == py) || (dy < dx)) ? 0 : ((y > py) ? 1 : -1);
5140
5141         for (i = 1; i <= 9; i++)
5142         {
5143                 if ((sx == ddx[i]) && (sy == ddy[i])) travel.dir = i;
5144         }
5145 }
5146 #endif