OSDN Git Service

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