OSDN Git Service

hengband 1.0.8 fix2
[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 = 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 = 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 = 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 = 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                 if (((wilderness[py][px].level + 5) > (p_ptr->lev / 2)) && rand_int(120+p_ptr->lev*10 - wilderness[py][px].level+5) < (21-p_ptr->skill_stl))
3013                 {
3014                         /* Inform the player of his horrible fate :=) */
3015 #ifdef JP
3016                         msg_print("½±·â¤À¡ª");
3017 #else
3018                         msg_print("You are ambushed !");
3019 #endif
3020
3021                         /* Go into large wilderness view */
3022                         p_ptr->wilderness_x = px;
3023                         p_ptr->wilderness_y = py;
3024                         p_ptr->oldpy = randint(MAX_HGT-2);
3025                         p_ptr->oldpx = randint(MAX_WID-2);
3026                         energy_use = 100;
3027                         change_wild_mode();
3028
3029                         /* HACk -- set the encouter flag for the wilderness generation */
3030                         generate_encounter = TRUE;
3031                 }
3032         }
3033
3034         /* Cancel repeat unless we may continue */
3035         if (!more) disturb(0, 0);
3036 }
3037
3038
3039
3040 /*
3041  * Start running.
3042  */
3043 void do_cmd_run(void)
3044 {
3045         int dir;
3046
3047         /* Hack -- no running when confused */
3048         if (p_ptr->confused)
3049         {
3050 #ifdef JP
3051                 msg_print("º®Í𤷤Ƥ¤¤ÆÁö¤ì¤Ê¤¤¡ª");
3052 #else
3053                 msg_print("You are too confused!");
3054 #endif
3055
3056                 return;
3057         }
3058
3059         if (p_ptr->special_defense & KATA_MUSOU)
3060         {
3061                 set_action(ACTION_NONE);
3062         }
3063
3064         /* Get a "repeated" direction */
3065         if (get_rep_dir(&dir,FALSE))
3066         {
3067                 /* Hack -- Set the run counter */
3068                 running = (command_arg ? command_arg : 1000);
3069
3070                 /* First step */
3071                 run_step(dir);
3072         }
3073 }
3074
3075
3076
3077 /*
3078  * Stay still.  Search.  Enter stores.
3079  * Pick up treasure if "pickup" is true.
3080  */
3081 void do_cmd_stay(int pickup)
3082 {
3083         cave_type *c_ptr = &cave[py][px];
3084
3085
3086         /* Allow repeated command */
3087         if (command_arg)
3088         {
3089                 /* Set repeat count */
3090                 command_rep = command_arg - 1;
3091
3092                 /* Redraw the state */
3093                 p_ptr->redraw |= (PR_STATE);
3094
3095                 /* Cancel the arg */
3096                 command_arg = 0;
3097         }
3098
3099
3100         /* Take a turn */
3101         energy_use = 100;
3102
3103
3104         /* Spontaneous Searching */
3105         if ((p_ptr->skill_fos >= 50) || (0 == rand_int(50 - p_ptr->skill_fos)))
3106         {
3107                 search();
3108         }
3109
3110         /* Continuous Searching */
3111         if (p_ptr->action == ACTION_SEARCH)
3112         {
3113                 search();
3114         }
3115
3116
3117         /* Handle "objects" */
3118         carry(pickup);
3119
3120
3121         /* Hack -- enter a store if we are on one */
3122         if (((c_ptr->feat >= FEAT_SHOP_HEAD) &&
3123             (c_ptr->feat <= FEAT_SHOP_TAIL)) ||
3124             (c_ptr->feat == FEAT_MUSEUM))
3125         {
3126                 /* Disturb */
3127                 disturb(0, 0);
3128
3129                 energy_use = 0;
3130                 /* Hack -- enter store */
3131                 command_new = '_';
3132         }
3133
3134         /* Hack -- enter a building if we are on one -KMW- */
3135         else if ((c_ptr->feat >= FEAT_BLDG_HEAD) &&
3136             (c_ptr->feat <= FEAT_BLDG_TAIL))
3137         {
3138                 /* Disturb */
3139                 disturb(0, 0);
3140
3141                 energy_use = 0;
3142                 /* Hack -- enter building */
3143                 command_new = 254;
3144         }
3145
3146         /* Exit a quest if reach the quest exit */
3147         else if (c_ptr->feat == FEAT_QUEST_EXIT)
3148         {
3149                 int q_index = p_ptr->inside_quest;
3150
3151                 /* Was quest completed? */
3152                 if (quest[q_index].type == QUEST_TYPE_FIND_EXIT)
3153                 {
3154                         quest[q_index].status = QUEST_STATUS_COMPLETED;
3155                         quest[q_index].complev = p_ptr->lev;
3156 #ifdef JP
3157                         msg_print("¥¯¥¨¥¹¥È¤ò´°Î»¤·¤¿¡ª");
3158 #else
3159                         msg_print("You accomplished your quest!");
3160 #endif
3161
3162                         msg_print(NULL);
3163                 }
3164
3165                 leaving_quest = p_ptr->inside_quest;
3166
3167                 /* Leaving an 'only once' quest marks it as failed */
3168                 if (leaving_quest &&
3169                         ((quest[leaving_quest].flags & QUEST_FLAG_ONCE) || (quest[leaving_quest].type == QUEST_TYPE_RANDOM)) &&
3170                         (quest[leaving_quest].status == QUEST_STATUS_TAKEN))
3171                 {
3172                         quest[leaving_quest].status = QUEST_STATUS_FAILED;
3173                         quest[leaving_quest].complev = p_ptr->lev;
3174                         if (quest[leaving_quest].type == QUEST_TYPE_RANDOM)
3175                         {
3176                                 r_info[quest[leaving_quest].r_idx].flags1 &= ~(RF1_QUESTOR);
3177                                 if (record_rand_quest)
3178                                         do_cmd_write_nikki(NIKKI_RAND_QUEST_F, leaving_quest, NULL);
3179                         }
3180                         else if (record_fix_quest)
3181                                 do_cmd_write_nikki(NIKKI_FIX_QUEST_F, leaving_quest, NULL);
3182                 }
3183
3184                 p_ptr->inside_quest = cave[py][px].special;
3185                 dun_level = 0;
3186                 p_ptr->oldpx = 0;
3187                 p_ptr->oldpy = 0;
3188                 p_ptr->leaving = TRUE;
3189         }
3190 }
3191
3192
3193
3194 /*
3195  * Resting allows a player to safely restore his hp     -RAK-
3196  */
3197 void do_cmd_rest(void)
3198 {
3199
3200         set_action(ACTION_NONE);
3201
3202         if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] || p_ptr->magic_num1[1]))
3203         {
3204                 stop_singing();
3205         }
3206
3207         /* Prompt for time if needed */
3208         if (command_arg <= 0)
3209         {
3210 #ifdef JP
3211                 cptr p = "µÙ·Æ (0-9999, '*' ¤Ç HP/MPÁ´²÷, '&' ¤ÇɬÍפʤÀ¤±): ";
3212 #else
3213                 cptr p = "Rest (0-9999, '*' for HP/SP, '&' as needed): ";
3214 #endif
3215
3216
3217                 char out_val[80];
3218
3219                 /* Default */
3220                 strcpy(out_val, "&");
3221
3222                 /* Ask for duration */
3223                 if (!get_string(p, out_val, 4)) return;
3224
3225                 /* Rest until done */
3226                 if (out_val[0] == '&')
3227                 {
3228                         command_arg = (-2);
3229                 }
3230
3231                 /* Rest a lot */
3232                 else if (out_val[0] == '*')
3233                 {
3234                         command_arg = (-1);
3235                 }
3236
3237                 /* Rest some */
3238                 else
3239                 {
3240                         command_arg = atoi(out_val);
3241                         if (command_arg <= 0) return;
3242                 }
3243         }
3244
3245
3246         /* Paranoia */
3247         if (command_arg > 9999) command_arg = 9999;
3248
3249         if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
3250
3251         /* Take a turn XXX XXX XXX (?) */
3252         energy_use = 100;
3253
3254         /* The sin of sloth */
3255         if (command_arg > 100)
3256                 chg_virtue(V_DILIGENCE, -1);
3257         
3258         /* Why are you sleeping when there's no need?  WAKE UP!*/
3259         if ((p_ptr->chp == p_ptr->mhp) &&
3260                 (p_ptr->csp == p_ptr->msp) &&
3261                 !p_ptr->blind && !p_ptr->confused &&
3262                 !p_ptr->poisoned && !p_ptr->afraid &&
3263                 !p_ptr->stun && !p_ptr->cut &&
3264                 !p_ptr->slow && !p_ptr->paralyzed &&
3265                 !p_ptr->image && !p_ptr->word_recall)
3266                         chg_virtue(V_DILIGENCE, -1);
3267
3268         /* Save the rest code */
3269         resting = command_arg;
3270         p_ptr->action = ACTION_REST;
3271
3272         /* Recalculate bonuses */
3273         p_ptr->update |= (PU_BONUS);
3274
3275         /* Redraw the state */
3276         p_ptr->redraw |= (PR_STATE);
3277
3278         /* Handle stuff */
3279         handle_stuff();
3280
3281         /* Refresh */
3282         Term_fresh();
3283 }
3284
3285
3286 /*
3287  * Determines the odds of an object breaking when thrown at a monster
3288  *
3289  * Note that artifacts never break, see the "drop_near()" function.
3290  */
3291 static int breakage_chance(object_type *o_ptr)
3292 {
3293         int archer_bonus = (p_ptr->pclass == CLASS_ARCHER ? (p_ptr->lev-1)/7 + 4: 0);
3294
3295         /* Examine the item type */
3296         switch (o_ptr->tval)
3297         {
3298                 /* Always break */
3299                 case TV_FLASK:
3300                 case TV_POTION:
3301                 case TV_BOTTLE:
3302                 case TV_FOOD:
3303                 case TV_JUNK:
3304                         return (100);
3305
3306                 /* Often break */
3307                 case TV_LITE:
3308                 case TV_SCROLL:
3309                 case TV_SKELETON:
3310                         return (50);
3311
3312                 /* Sometimes break */
3313                 case TV_WAND:
3314                 case TV_SPIKE:
3315                         return (25);
3316                 case TV_ARROW:
3317                         return (20 - archer_bonus * 2);
3318
3319                 /* Rarely break */
3320                 case TV_SHOT:
3321                 case TV_BOLT:
3322                         return (10 - archer_bonus);
3323                 default:
3324                         return (10);
3325         }
3326 }
3327
3328
3329 s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
3330 {
3331         int mult = 10;
3332
3333         monster_race *r_ptr = &r_info[m_ptr->r_idx];
3334
3335         u32b f1, f2, f3;
3336
3337         /* Extract the flags */
3338         object_flags(o_ptr, &f1, &f2, &f3);
3339
3340         /* Some "weapons" and "ammo" do extra damage */
3341         switch (o_ptr->tval)
3342         {
3343                 case TV_SHOT:
3344                 case TV_ARROW:
3345                 case TV_BOLT:
3346                 {
3347                         /* Slay Animal */
3348                         if ((f1 & TR1_SLAY_ANIMAL) &&
3349                             (r_ptr->flags3 & RF3_ANIMAL))
3350                         {
3351                                 if (m_ptr->ml)
3352                                 {
3353                                         r_ptr->r_flags3 |= RF3_ANIMAL;
3354                                 }
3355
3356                                 if (mult < 17) mult = 17;
3357                         }
3358
3359                         /* Slay Evil */
3360                         if ((f1 & TR1_SLAY_EVIL) &&
3361                             (r_ptr->flags3 & RF3_EVIL))
3362                         {
3363                                 if (m_ptr->ml)
3364                                 {
3365                                         r_ptr->r_flags3 |= RF3_EVIL;
3366                                 }
3367
3368                                 if (mult < 15) mult = 15;
3369                         }
3370
3371                         /* Slay Undead */
3372                         if ((f1 & TR1_SLAY_UNDEAD) &&
3373                             (r_ptr->flags3 & RF3_UNDEAD))
3374                         {
3375                                 if (m_ptr->ml)
3376                                 {
3377                                         r_ptr->r_flags3 |= RF3_UNDEAD;
3378                                 }
3379
3380                                 if (mult < 20) mult = 20;
3381                         }
3382
3383                         /* Slay Demon */
3384                         if ((f1 & TR1_SLAY_DEMON) &&
3385                             (r_ptr->flags3 & RF3_DEMON))
3386                         {
3387                                 if (m_ptr->ml)
3388                                 {
3389                                         r_ptr->r_flags3 |= RF3_DEMON;
3390                                 }
3391
3392                                 if (mult < 20) mult = 20;
3393                         }
3394
3395                         /* Slay Orc */
3396                         if ((f1 & TR1_SLAY_ORC) &&
3397                             (r_ptr->flags3 & RF3_ORC))
3398                         {
3399                                 if (m_ptr->ml)
3400                                 {
3401                                         r_ptr->r_flags3 |= RF3_ORC;
3402                                 }
3403
3404                                 if (mult < 20) mult = 20;
3405                         }
3406
3407                         /* Slay Troll */
3408                         if ((f1 & TR1_SLAY_TROLL) &&
3409                             (r_ptr->flags3 & RF3_TROLL))
3410                         {
3411                                 if (m_ptr->ml)
3412                                 {
3413                                         r_ptr->r_flags3 |= RF3_TROLL;
3414                                 }
3415
3416                                 if (mult < 20) mult = 20;
3417                         }
3418
3419                         /* Slay Giant */
3420                         if ((f1 & TR1_SLAY_GIANT) &&
3421                             (r_ptr->flags3 & RF3_GIANT))
3422                         {
3423                                 if (m_ptr->ml)
3424                                 {
3425                                         r_ptr->r_flags3 |= RF3_GIANT;
3426                                 }
3427
3428                                 if (mult < 20) mult = 20;
3429                         }
3430
3431                         /* Slay Dragon  */
3432                         if ((f1 & TR1_SLAY_DRAGON) &&
3433                             (r_ptr->flags3 & RF3_DRAGON))
3434                         {
3435                                 if (m_ptr->ml)
3436                                 {
3437                                         r_ptr->r_flags3 |= RF3_DRAGON;
3438                                 }
3439
3440                                 if (mult < 20) mult = 20;
3441                         }
3442
3443                         /* Execute Dragon */
3444                         if ((f1 & TR1_KILL_DRAGON) &&
3445                             (r_ptr->flags3 & RF3_DRAGON))
3446                         {
3447                                 if (m_ptr->ml)
3448                                 {
3449                                         r_ptr->r_flags3 |= RF3_DRAGON;
3450                                 }
3451
3452                                 if (mult < 30) mult = 30;
3453
3454                                 if ((o_ptr->name1 == ART_BARD_ARROW) &&
3455                                     (m_ptr->r_idx == MON_SMAUG) &&
3456                                     (inventory[INVEN_BOW].name1 == ART_BARD))
3457                                         mult *= 5;
3458                         }
3459
3460                         /* Brand (Acid) */
3461                         if ((f1 & TR1_BRAND_ACID) || (p_ptr->special_attack & (ATTACK_ACID)))
3462                         {
3463                                 /* Notice immunity */
3464                                 if (r_ptr->flags3 & RF3_IM_ACID)
3465                                 {
3466                                         if (m_ptr->ml)
3467                                         {
3468                                                 r_ptr->r_flags3 |= RF3_IM_ACID;
3469                                         }
3470                                 }
3471
3472                                 /* Otherwise, take the damage */
3473                                 else
3474                                 {
3475                                         if (mult < 17) mult = 17;
3476                                 }
3477                         }
3478
3479                         /* Brand (Elec) */
3480                         if ((f1 & TR1_BRAND_ELEC) || (p_ptr->special_attack & (ATTACK_ELEC)))
3481                         {
3482                                 /* Notice immunity */
3483                                 if (r_ptr->flags3 & RF3_IM_ELEC)
3484                                 {
3485                                         if (m_ptr->ml)
3486                                         {
3487                                                 r_ptr->r_flags3 |= RF3_IM_ELEC;
3488                                         }
3489                                 }
3490
3491                                 /* Otherwise, take the damage */
3492                                 else
3493                                 {
3494                                         if (mult < 17) mult = 17;
3495                                 }
3496                         }
3497
3498                         /* Brand (Fire) */
3499                         if ((f1 & TR1_BRAND_FIRE) || (p_ptr->special_attack & (ATTACK_FIRE)))
3500                         {
3501                                 /* Notice immunity */
3502                                 if (r_ptr->flags3 & RF3_IM_FIRE)
3503                                 {
3504                                         if (m_ptr->ml)
3505                                         {
3506                                                 r_ptr->r_flags3 |= RF3_IM_FIRE;
3507                                         }
3508                                 }
3509
3510                                 /* Otherwise, take the damage */
3511                                 else
3512                                 {
3513                                         if (mult < 17) mult = 17;
3514                                 }
3515                         }
3516
3517                         /* Brand (Cold) */
3518                         if ((f1 & TR1_BRAND_COLD) || (p_ptr->special_attack & (ATTACK_COLD)))
3519                         {
3520                                 /* Notice immunity */
3521                                 if (r_ptr->flags3 & RF3_IM_COLD)
3522                                 {
3523                                         if (m_ptr->ml)
3524                                         {
3525                                                 r_ptr->r_flags3 |= RF3_IM_COLD;
3526                                         }
3527                                 }
3528                                 /* Otherwise, take the damage */
3529                                 else
3530                                 {
3531                                         if (mult < 17) mult = 17;
3532                                 }
3533                         }
3534
3535                         /* Brand (Poison) */
3536                         if ((f1 & TR1_BRAND_POIS) || (p_ptr->special_attack & (ATTACK_POIS)))
3537                         {
3538                                 /* Notice immunity */
3539                                 if (r_ptr->flags3 & RF3_IM_POIS)
3540                                 {
3541                                         if (m_ptr->ml)
3542                                         {
3543                                                 r_ptr->r_flags3 |= RF3_IM_POIS;
3544                                         }
3545                                 }
3546
3547                                 /* Otherwise, take the damage */
3548                                 else
3549                                 {
3550                                         if (mult < 17) mult = 17;
3551                                 }
3552                         }
3553
3554                         if ((f1 & TR1_FORCE_WEPON) && (p_ptr->csp > (p_ptr->msp / 30)))
3555                         {
3556                                 p_ptr->csp -= (1+(p_ptr->msp / 30));
3557                                 p_ptr->redraw |= (PR_MANA);
3558                                 mult = mult * 5 / 2;
3559                         }
3560                         break;
3561                 }
3562         }
3563
3564         /* Return the total damage */
3565         return (tdam * mult / 10);
3566 }
3567
3568
3569 /*
3570  * Fire an object from the pack or floor.
3571  *
3572  * You may only fire items that "match" your missile launcher.
3573  *
3574  * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
3575  *
3576  * See "calc_bonuses()" for more calculations and such.
3577  *
3578  * Note that "firing" a missile is MUCH better than "throwing" it.
3579  *
3580  * Note: "unseen" monsters are very hard to hit.
3581  *
3582  * Objects are more likely to break if they "attempt" to hit a monster.
3583  *
3584  * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
3585  *
3586  * The "extra shot" code works by decreasing the amount of energy
3587  * required to make each shot, spreading the shots out over time.
3588  *
3589  * Note that when firing missiles, the launcher multiplier is applied
3590  * after all the bonuses are added in, making multipliers very useful.
3591  *
3592  * Note that Bows of "Extra Might" get extra range and an extra bonus
3593  * for the damage multiplier.
3594  *
3595  * Note that Bows of "Extra Shots" give an extra shot.
3596  */
3597 void do_cmd_fire_aux(int item, object_type *j_ptr)
3598 {
3599         int dir;
3600         int j, y, x, ny, nx, ty, tx;
3601         int tdam, tdis, thits, tmul;
3602         int bonus, chance;
3603         int cur_dis, visible;
3604
3605         object_type forge;
3606         object_type *q_ptr;
3607
3608         object_type *o_ptr;
3609
3610         bool hit_body = FALSE;
3611
3612         char o_name[MAX_NLEN];
3613
3614         int msec = delay_factor * delay_factor * delay_factor;
3615
3616         /* STICK TO */
3617         bool stick_to = FALSE;
3618
3619         /* Access the item (if in the pack) */
3620         if (item >= 0)
3621         {
3622                 o_ptr = &inventory[item];
3623         }
3624         else
3625         {
3626                 o_ptr = &o_list[0 - item];
3627         }
3628
3629         /* Describe the object */
3630         object_desc(o_name, o_ptr, FALSE, 3);
3631
3632
3633         /* Use the proper number of shots */
3634         thits = p_ptr->num_fire;
3635
3636         /* Use a base distance */
3637         tdis = 10;
3638
3639         /* Base damage from thrown object plus launcher bonus */
3640         tdam = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
3641
3642         /* Actually "fire" the object */
3643         bonus = (p_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
3644         chance = (p_ptr->skill_thb + ((weapon_exp[0][j_ptr->sval]-4000)/200 + bonus) * BTH_PLUS_ADJ);
3645
3646         /* Assume a base multiplier */
3647         tmul = 1;
3648
3649         /* Analyze the launcher */
3650         switch (j_ptr->sval)
3651         {
3652                 /* Sling and ammo */
3653                 case SV_SLING:
3654                 {
3655                         tmul = 2;
3656                         energy_use = 8000;
3657                         break;
3658                 }
3659
3660                 /* Short Bow and Arrow */
3661                 case SV_SHORT_BOW:
3662                 {
3663                         tmul = 2;
3664                         energy_use = 10000;
3665                         break;
3666                 }
3667
3668                 /* Long Bow and Arrow */
3669                 case SV_LONG_BOW:
3670                 {
3671                         tmul = 3;
3672                         energy_use = 10000;
3673                         break;
3674                 }
3675
3676                 case SV_NAMAKE_BOW:
3677                 {
3678                         tmul = 3;
3679                         energy_use = 7777;
3680                         break;
3681                 }
3682
3683                 /* Light Crossbow and Bolt */
3684                 case SV_LIGHT_XBOW:
3685                 {
3686                         tmul = 3;
3687                         energy_use = 12000;
3688                         break;
3689                 }
3690
3691                 /* Heavy Crossbow and Bolt */
3692                 case SV_HEAVY_XBOW:
3693                 {
3694                         tmul = 4;
3695                         energy_use = 13333;
3696                         break;
3697                 }
3698         }
3699
3700         /* Get extra "power" from "extra might" */
3701         if (p_ptr->xtra_might) tmul++;
3702
3703         tmul = tmul * (100 + (int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
3704
3705         /* Boost the damage */
3706         tdam *= tmul;
3707         tdam /= 100;
3708
3709         /* Base range */
3710         tdis = 10 + tmul/40;
3711         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
3712                 tdis += 5;
3713
3714         project_length = tdis + 1;
3715
3716         /* Get a direction (or cancel) */
3717         if (!get_aim_dir(&dir))
3718         {
3719                 energy_use = 0;
3720
3721                 /* need not to reset project_length (already did)*/
3722
3723                 return;
3724         }
3725         project_length = 0; /* reset to default */
3726
3727         /* Get local object */
3728         q_ptr = &forge;
3729
3730         /* Obtain a local object */
3731         object_copy(q_ptr, o_ptr);
3732
3733         /* Single object */
3734         q_ptr->number = 1;
3735
3736         /* Reduce and describe inventory */
3737         if (item >= 0)
3738         {
3739                 inven_item_increase(item, -1);
3740                 inven_item_describe(item);
3741                 inven_item_optimize(item);
3742         }
3743
3744         /* Reduce and describe floor item */
3745         else
3746         {
3747                 floor_item_increase(0 - item, -1);
3748                 floor_item_optimize(0 - item);
3749         }
3750
3751
3752         /* Sound */
3753         sound(SOUND_SHOOT);
3754
3755
3756         /* Take a (partial) turn */
3757         energy_use = (energy_use / thits);
3758
3759
3760         /* Start at the player */
3761         y = py;
3762         x = px;
3763
3764         /* Predict the "target" location */
3765         tx = px + 99 * ddx[dir];
3766         ty = py + 99 * ddy[dir];
3767
3768         /* Check for "target request" */
3769         if ((dir == 5) && target_okay())
3770         {
3771                 tx = target_col;
3772                 ty = target_row;
3773         }
3774
3775
3776         /* Hack -- Handle stuff */
3777         handle_stuff();
3778
3779
3780         /* Travel until stopped */
3781         for (cur_dis = 0; cur_dis <= tdis; )
3782         {
3783                 /* Hack -- Stop at the target */
3784                 if ((y == ty) && (x == tx)) break;
3785
3786                 /* Calculate the new location (see "project()") */
3787                 ny = y;
3788                 nx = x;
3789                 mmove2(&ny, &nx, py, px, ty, tx);
3790
3791                 /* Stopped by walls/doors */
3792                 if (!cave_floor_bold(ny, nx) && !cave[ny][nx].m_idx) break;
3793
3794                 /* Advance the distance */
3795                 cur_dis++;
3796
3797
3798                 /* The player can see the (on screen) missile */
3799                 if (panel_contains(ny, nx) && player_can_see_bold(ny, nx))
3800                 {
3801                         char c = object_char(q_ptr);
3802                         byte a = object_attr(q_ptr);
3803
3804                         /* Draw, Hilite, Fresh, Pause, Erase */
3805                         print_rel(c, a, ny, nx);
3806                         move_cursor_relative(ny, nx);
3807                         Term_fresh();
3808                         Term_xtra(TERM_XTRA_DELAY, msec);
3809                         lite_spot(ny, nx);
3810                         Term_fresh();
3811                 }
3812
3813                 /* The player cannot see the missile */
3814                 else
3815                 {
3816                         /* Pause anyway, for consistancy */
3817                         Term_xtra(TERM_XTRA_DELAY, msec);
3818                 }
3819
3820                 /* Save the new location */
3821                 x = nx;
3822                 y = ny;
3823
3824
3825                 /* Monster here, Try to hit it */
3826                 if (cave[y][x].m_idx)
3827                 {
3828                         cave_type *c_ptr = &cave[y][x];
3829
3830                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
3831                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
3832
3833                         /* Check the visibility */
3834                         visible = m_ptr->ml;
3835
3836                         /* Note the collision */
3837                         hit_body = TRUE;
3838
3839                         if (m_ptr->csleep)
3840                         {
3841                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_COMPASSION, -1);
3842                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_HONOUR, -1);
3843                         }
3844
3845                         if ((r_ptr->level + 10) > p_ptr->lev)
3846                         {
3847                                 if (weapon_exp[0][j_ptr->sval] < weapon_exp_settei[p_ptr->pclass][0][j_ptr->sval][1])
3848                                 {
3849                                         if (weapon_exp[0][j_ptr->sval] < 4000)
3850                                                 weapon_exp[0][j_ptr->sval]+=80;
3851                                         else if ((weapon_exp[0][j_ptr->sval] < 6000))
3852                                                 weapon_exp[0][j_ptr->sval]+=25;
3853                                         else if ((weapon_exp[0][j_ptr->sval] < 7000) && (p_ptr->lev > 19))
3854                                                 weapon_exp[0][j_ptr->sval]+=10;
3855                                         else if ((weapon_exp[0][j_ptr->sval] < 8000) && (p_ptr->lev > 34))
3856                                                 weapon_exp[0][j_ptr->sval]+=2;
3857                                 }
3858                         }
3859
3860                         if (p_ptr->riding)
3861                         {
3862                                 if (skill_exp[GINOU_RIDING] < skill_exp_settei[p_ptr->pclass][GINOU_RIDING][1] && ((skill_exp[GINOU_RIDING] - 1000) / 200 < r_info[m_list[p_ptr->riding].r_idx].level) && one_in_(2))
3863                                 {
3864                                         skill_exp[GINOU_RIDING]+=1;
3865                                         p_ptr->update |= (PU_BONUS);
3866                                 }
3867                         }
3868
3869                         /* Did we hit it (penalize range) */
3870                         if (test_hit_fire(chance - cur_dis, r_ptr->ac, m_ptr->ml))
3871                         {
3872                                 bool fear = FALSE;
3873
3874                                 /* Assume a default death */
3875 #ifdef JP
3876                                 cptr note_dies = "¤Ï»à¤ó¤À¡£";
3877 #else
3878                                 cptr note_dies = " dies.";
3879 #endif
3880
3881                                 /* Some monsters get "destroyed" */
3882                                 if (!monster_living(r_ptr))
3883                                 {
3884                                         int i;
3885                                         bool explode = FALSE;
3886
3887                                         for (i = 0; i < 4; i++)
3888                                         {
3889                                                 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
3890                                         }
3891
3892                                         /* Special note at death */
3893                                         if (explode)
3894 #ifdef JP
3895 note_dies = "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£";
3896 #else
3897                                                 note_dies = " explodes into tiny shreds.";
3898 #endif
3899                                         else
3900 #ifdef JP
3901                                                 note_dies = "¤òÅݤ·¤¿¡£";
3902 #else
3903                                                 note_dies = " is destroyed.";
3904 #endif
3905
3906                                 }
3907
3908                                 /* Handle unseen monster */
3909                                 if (!visible)
3910                                 {
3911                                         /* Invisible monster */
3912 #ifdef JP
3913                                         msg_format("%s¤¬Å¨¤òÊ᪤·¤¿¡£", o_name);
3914 #else
3915                                         msg_format("The %s finds a mark.", o_name);
3916 #endif
3917
3918                                 }
3919
3920                                 /* Handle visible monster */
3921                                 else
3922                                 {
3923                                         char m_name[80];
3924
3925                                         /* Get "the monster" or "it" */
3926                                         monster_desc(m_name, m_ptr, 0);
3927
3928                                         /* Message */
3929 #ifdef JP
3930                                         msg_format("%s¤¬%s¤ËÌ¿Ã椷¤¿¡£", o_name, m_name);
3931 #else
3932                                         msg_format("The %s hits %s.", o_name, m_name);
3933 #endif
3934
3935
3936                                         /* Hack -- Track this monster race */
3937                                         if (m_ptr->ml) monster_race_track((m_ptr->mflag2 & MFLAG_KAGE), m_ptr->r_idx);
3938
3939                                         /* Hack -- Track this monster */
3940                                         if (m_ptr->ml) health_track(c_ptr->m_idx);
3941                                 }
3942
3943                                 /* Apply special damage XXX XXX XXX */
3944                                 tdam = tot_dam_aux_shot(q_ptr, tdam, m_ptr);
3945                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, tdam);
3946
3947                                 /* No negative damage */
3948                                 if (tdam < 0) tdam = 0;
3949
3950                                 /* Modify the damage */
3951                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
3952
3953                                 /* Complex message */
3954                                 if (wizard || cheat_xtra)
3955                                 {
3956 #ifdef JP
3957                                         msg_format("%d/%d ¤Î¥À¥á¡¼¥¸¤òÍ¿¤¨¤¿¡£",
3958                                                    tdam, m_ptr->hp);
3959 #else
3960                                         msg_format("You do %d (out of %d) damage.",
3961                                                    tdam, m_ptr->hp);
3962 #endif
3963
3964                                 }
3965
3966                                 /* Hit the monster, check for death */
3967                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, note_dies))
3968                                 {
3969                                         /* Dead monster */
3970                                 }
3971
3972                                 /* No death */
3973                                 else
3974                                 {
3975                                         /* STICK TO */
3976                                         if (q_ptr->name1)
3977                                         {
3978                                                 char m_name[80];
3979
3980                                                 monster_desc(m_name, m_ptr, 0);
3981
3982                                                 stick_to = TRUE;
3983 #ifdef JP
3984                                                 msg_format("%s¤Ï%s¤ËÆͤ­»É¤µ¤Ã¤¿¡ª",o_name, m_name);
3985 #else
3986                                                 msg_format("%^s have stuck into %s!",o_name, m_name);
3987 #endif
3988                                         }
3989
3990                                         /* Message */
3991                                         message_pain(c_ptr->m_idx, tdam);
3992
3993                                         /* Anger the monster */
3994                                         if (tdam > 0) anger_monster(m_ptr);
3995
3996                                         /* Take note */
3997                                         if (fear && m_ptr->ml)
3998                                         {
3999                                                 char m_name[80];
4000
4001                                                 /* Sound */
4002                                                 sound(SOUND_FLEE);
4003
4004                                                 /* Get the monster name (or "it") */
4005                                                 monster_desc(m_name, m_ptr, 0);
4006
4007                                                 /* Message */
4008 #ifdef JP
4009                                                 msg_format("%^s¤Ï¶²Éݤ·¤Æƨ¤²½Ð¤·¤¿¡ª", m_name);
4010 #else
4011                                                 msg_format("%^s flees in terror!", m_name);
4012 #endif
4013
4014                                         }
4015                                         if (!projectable(m_ptr->fy, m_ptr->fx, py, px))
4016                                         {
4017                                                 m_ptr->target_y = py;
4018                                                 m_ptr->target_x = px;
4019                                         }
4020                                 }
4021                         }
4022
4023                         /* Stop looking */
4024                         break;
4025                 }
4026         }
4027
4028         /* Chance of breakage (during attacks) */
4029         j = (hit_body ? breakage_chance(q_ptr) : 0);
4030
4031         if(stick_to)
4032         {
4033                 int m_idx = cave[y][x].m_idx;
4034                 monster_type *m_ptr = &m_list[m_idx];
4035                 int o_idx = o_pop();
4036
4037                 if (!o_idx)
4038                   {
4039                     msg_format("%s¤Ï¤É¤³¤«¤Ø¹Ô¤Ã¤¿¡£", o_name);
4040                     if (q_ptr->name1)
4041                       {
4042                         a_info[j_ptr->name1].cur_num = 0;
4043                       }
4044                     return;
4045                   }
4046
4047                 o_ptr = &o_list[ o_idx ];
4048                 object_copy(o_ptr, q_ptr);
4049
4050                 /* Forget mark */
4051                 o_ptr->marked = FALSE;
4052
4053                 /* Forget location */
4054                 o_ptr->iy = o_ptr->ix = 0;
4055
4056                 /* Memorize monster */
4057                 o_ptr->held_m_idx = m_idx;
4058
4059                 /* Build a stack */
4060                 o_ptr->next_o_idx = m_ptr->hold_o_idx;
4061
4062                 /* Carry object */
4063                 m_ptr->hold_o_idx = o_idx;
4064
4065         }
4066         else
4067                 /* Drop (or break) near that location */
4068                 (void)drop_near(q_ptr, j, y, x);
4069 }
4070
4071
4072 void do_cmd_fire(void)
4073 {
4074         int item;
4075         object_type *j_ptr;
4076         cptr q, s;
4077
4078         /* Get the "bow" (if any) */
4079         j_ptr = &inventory[INVEN_BOW];
4080
4081         /* Require a launcher */
4082         if (!j_ptr->tval)
4083         {
4084 #ifdef JP
4085                 msg_print("¼Í·âÍѤÎÉð´ï¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£");
4086 #else
4087                 msg_print("You have nothing to fire with.");
4088 #endif
4089                 flush();
4090                 return;
4091         }
4092
4093         if (j_ptr->sval == SV_CRIMSON)
4094         {
4095 #ifdef JP
4096                 msg_print("¤³¤ÎÉð´ï¤Ïȯư¤·¤Æ»È¤¦¤â¤Î¤Î¤è¤¦¤À¡£");
4097 #else
4098                 msg_print("Do activate.");
4099 #endif
4100                 flush();
4101                 return;
4102         }
4103
4104
4105         if (p_ptr->special_defense & KATA_MUSOU)
4106         {
4107                 set_action(ACTION_NONE);
4108         }
4109
4110         /* Require proper missile */
4111         item_tester_tval = p_ptr->tval_ammo;
4112
4113         /* Get an item */
4114 #ifdef JP
4115         q = "¤É¤ì¤ò·â¤Á¤Þ¤¹¤«? ";
4116         s = "ȯ¼Í¤µ¤ì¤ë¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
4117 #else
4118         q = "Fire which item? ";
4119         s = "You have nothing to fire.";
4120 #endif
4121
4122         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
4123         {
4124                 flush();
4125                 return;
4126         }
4127
4128         /* Fire the item */
4129         do_cmd_fire_aux(item, j_ptr);
4130 }
4131
4132
4133 static bool item_tester_hook_boomerang(object_type *o_ptr)
4134 {
4135         if ((o_ptr->tval==TV_DIGGING) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM) || (o_ptr->tval == TV_HAFTED)) return (TRUE);
4136
4137         /* Assume not */
4138         return (FALSE);
4139 }
4140
4141
4142 /*
4143  * Throw an object from the pack or floor.
4144  *
4145  * Note: "unseen" monsters are very hard to hit.
4146  *
4147  * Should throwing a weapon do full damage?  Should it allow the magic
4148  * to hit bonus of the weapon to have an effect?  Should it ever cause
4149  * the item to be destroyed?  Should it do any damage at all?
4150  */
4151 bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
4152 {
4153         int dir, item;
4154         int i, j, y, x, ty, tx;
4155         int ny[19], nx[19];
4156         int chance, tdam, tdis;
4157         int mul, div;
4158         int cur_dis, visible;
4159
4160         object_type forge;
4161         object_type *q_ptr;
4162
4163         object_type *o_ptr;
4164
4165         bool hit_body = FALSE;
4166         bool hit_wall = FALSE;
4167         bool equiped_item = FALSE;
4168         bool return_when_thrown = FALSE;
4169
4170         char o_name[MAX_NLEN];
4171
4172         int msec = delay_factor * delay_factor * delay_factor;
4173
4174         u32b f1, f2, f3;
4175         cptr q, s;
4176         bool come_back = FALSE;
4177         bool do_drop = TRUE;
4178
4179
4180         if (p_ptr->special_defense & KATA_MUSOU)
4181         {
4182                 set_action(ACTION_NONE);
4183         }
4184
4185         if (shuriken)
4186         {
4187                 item = shuriken;
4188         }
4189         else if (boomerang)
4190         {
4191                 if (buki_motteruka(INVEN_LARM))
4192                 {
4193                         item_tester_hook = item_tester_hook_boomerang;
4194 #ifdef JP
4195                         q = "¤É¤ÎÉð´ï¤òÅꤲ¤Þ¤¹¤«? ";
4196                         s = "Åꤲ¤ëÉð´ï¤¬¤Ê¤¤¡£";
4197 #else
4198                         q = "Throw which item? ";
4199                         s = "You have nothing to throw.";
4200 #endif
4201
4202                         if (!get_item(&item, q, s, (USE_EQUIP)))
4203                         {
4204                                 flush();
4205                                 return FALSE;
4206                         }
4207                 }
4208                 else
4209                 {
4210                         item = INVEN_RARM;
4211                 }
4212         }
4213         else
4214         {
4215                 /* Get an item */
4216 #ifdef JP
4217                 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅꤲ¤Þ¤¹¤«? ";
4218                 s = "Åꤲ¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
4219 #else
4220                 q = "Throw which item? ";
4221                 s = "You have nothing to throw.";
4222 #endif
4223
4224                 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP)))
4225                 {
4226                         flush();
4227                         return FALSE;
4228                 }
4229         }
4230
4231         /* Access the item (if in the pack) */
4232         if (item >= 0)
4233         {
4234                 o_ptr = &inventory[item];
4235         }
4236         else
4237         {
4238                 o_ptr = &o_list[0 - item];
4239         }
4240
4241
4242         /* Item is cursed */
4243         if (cursed_p(o_ptr) && (item >= INVEN_RARM))
4244         {
4245                 /* Oops */
4246 #ifdef JP
4247                 msg_print("¤Õ¡¼¤à¡¢¤É¤¦¤ä¤é¼ö¤ï¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£");
4248 #else
4249                 msg_print("Hmmm, it seems to be cursed.");
4250 #endif
4251
4252
4253                 /* Nope */
4254                 return FALSE;
4255         }
4256
4257
4258         /* Get local object */
4259         q_ptr = &forge;
4260
4261         /* Obtain a local object */
4262         object_copy(q_ptr, o_ptr);
4263
4264         /* Extract the thrown object's flags. */
4265         object_flags(q_ptr, &f1, &f2, &f3);
4266
4267         /* Distribute the charges of rods/wands between the stacks */
4268         distribute_charges(o_ptr, q_ptr, 1);
4269
4270         /* Single object */
4271         q_ptr->number = 1;
4272
4273         /* Description */
4274         object_desc(o_name, q_ptr, FALSE, 3);
4275
4276         if (p_ptr->mighty_throw) mult += 3;
4277
4278         /* Extract a "distance multiplier" */
4279         /* Changed for 'launcher' mutation */
4280         mul = 10 + 2 * (mult - 1);
4281
4282         /* Enforce a minimum "weight" of one pound */
4283         div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
4284         if ((f2 & (TR2_THROW)) || boomerang) div /= 2;
4285
4286         /* Hack -- Distance -- Reward strength, penalize weight */
4287         tdis = (adj_str_blow[p_ptr->stat_ind[A_STR]] + 20) * mul / div;
4288
4289         /* Max distance of 10-18 */
4290         if (tdis > mul) tdis = mul;
4291
4292         if (shuriken)
4293         {
4294                 ty = rand_int(101)-50+py;
4295                 tx = rand_int(101)-50+px;
4296         }
4297         else
4298         {
4299                 project_length = tdis + 1;
4300
4301                 /* Get a direction (or cancel) */
4302                 if (!get_aim_dir(&dir)) return FALSE;
4303
4304                 project_length = 0;  /* reset to default */
4305
4306                 /* Predict the "target" location */
4307                 tx = px + 99 * ddx[dir];
4308                 ty = py + 99 * ddy[dir];
4309
4310                 /* Check for "target request" */
4311                 if ((dir == 5) && target_okay())
4312                 {
4313                         tx = target_col;
4314                         ty = target_row;
4315                 }
4316         }
4317
4318         if ((q_ptr->name1 == ART_MJOLLNIR) ||
4319             (q_ptr->name1 == ART_AEGISFANG) || boomerang)
4320                 return_when_thrown = TRUE;
4321
4322         /* Reduce and describe inventory */
4323         if (item >= 0)
4324         {
4325                 inven_item_increase(item, -1);
4326                 if (!return_when_thrown)
4327                         inven_item_describe(item);
4328                 inven_item_optimize(item);
4329         }
4330         
4331         /* Reduce and describe floor item */
4332         else
4333         {
4334                 floor_item_increase(0 - item, -1);
4335                 floor_item_optimize(0 - item);
4336         }
4337         if (item >= INVEN_RARM)
4338         {
4339                 equiped_item = TRUE;
4340                 p_ptr->redraw |= (PR_EQUIPPY);
4341         }
4342         
4343         /* Take a turn */
4344         if ((p_ptr->pclass == CLASS_ROGUE) || (p_ptr->pclass == CLASS_NINJA))
4345                 energy_use = 100-p_ptr->lev;
4346         else
4347                 energy_use = 100;
4348
4349         /* Start at the player */
4350         y = py;
4351         x = px;
4352
4353
4354         /* Hack -- Handle stuff */
4355         handle_stuff();
4356
4357         if ((p_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((f2 & TR2_THROW) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
4358         else shuriken = FALSE;
4359
4360         /* Chance of hitting */
4361         if (f2 & (TR2_THROW)) chance = ((p_ptr->skill_tht) +
4362                 ((p_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
4363         else chance = (p_ptr->skill_tht + (p_ptr->to_h_b * BTH_PLUS_ADJ));
4364
4365         if (shuriken) chance *= 2;
4366
4367         /* Travel until stopped */
4368         for (cur_dis = 0; cur_dis <= tdis; )
4369         {
4370                 /* Hack -- Stop at the target */
4371                 if ((y == ty) && (x == tx)) break;
4372
4373                 /* Calculate the new location (see "project()") */
4374                 ny[cur_dis] = y;
4375                 nx[cur_dis] = x;
4376                 mmove2(&ny[cur_dis], &nx[cur_dis], py, px, ty, tx);
4377
4378                 /* Stopped by walls/doors */
4379                 if (!cave_floor_bold(ny[cur_dis], nx[cur_dis]))
4380                 {
4381                         hit_wall = TRUE;
4382                         break;
4383                 }
4384
4385                 /* Advance the distance */
4386                 cur_dis++;
4387
4388                 /* The player can see the (on screen) missile */
4389                 if (panel_contains(ny[cur_dis-1], nx[cur_dis-1]) && player_can_see_bold(ny[cur_dis-1], nx[cur_dis-1]))
4390                 {
4391                         char c = object_char(q_ptr);
4392                         byte a = object_attr(q_ptr);
4393
4394                         /* Draw, Hilite, Fresh, Pause, Erase */
4395                         print_rel(c, a, ny[cur_dis-1], nx[cur_dis-1]);
4396                         move_cursor_relative(ny[cur_dis-1], nx[cur_dis-1]);
4397                         Term_fresh();
4398                         Term_xtra(TERM_XTRA_DELAY, msec);
4399                         lite_spot(ny[cur_dis-1], nx[cur_dis-1]);
4400                         Term_fresh();
4401                 }
4402
4403                 /* The player cannot see the missile */
4404                 else
4405                 {
4406                         /* Pause anyway, for consistancy */
4407                         Term_xtra(TERM_XTRA_DELAY, msec);
4408                 }
4409
4410                 /* Save the new location */
4411                 x = nx[cur_dis-1];
4412                 y = ny[cur_dis-1];
4413
4414
4415                 /* Monster here, Try to hit it */
4416                 if (cave[y][x].m_idx)
4417                 {
4418                         cave_type *c_ptr = &cave[y][x];
4419
4420                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
4421                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4422
4423                         /* Check the visibility */
4424                         visible = m_ptr->ml;
4425
4426                         /* Note the collision */
4427                         hit_body = TRUE;
4428
4429                         /* Did we hit it (penalize range) */
4430                         if (test_hit_fire(chance - cur_dis, r_ptr->ac, m_ptr->ml))
4431                         {
4432                                 bool fear = FALSE;
4433
4434                                 /* Assume a default death */
4435 #ifdef JP
4436                                 cptr note_dies = "¤Ï»à¤ó¤À¡£";
4437 #else
4438                                 cptr note_dies = " dies.";
4439 #endif
4440
4441
4442                                 /* Some monsters get "destroyed" */
4443                                 if (!monster_living(r_ptr))
4444                                 {
4445                                         int i;
4446                                         bool explode = FALSE;
4447
4448                                         for (i = 0; i < 4; i++)
4449                                         {
4450                                                 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
4451                                         }
4452
4453                                         /* Special note at death */
4454                                         if (explode)
4455 #ifdef JP
4456 note_dies = "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£";
4457 #else
4458                                                 note_dies = " explodes into tiny shreds.";
4459 #endif
4460                                         else
4461 #ifdef JP
4462                                                 note_dies = "¤òÅݤ·¤¿¡£";
4463 #else
4464                                                 note_dies = " is destroyed.";
4465 #endif
4466
4467                                 }
4468
4469
4470                                 /* Handle unseen monster */
4471                                 if (!visible)
4472                                 {
4473                                         /* Invisible monster */
4474 #ifdef JP
4475                                         msg_format("%s¤¬Å¨¤òÊ᪤·¤¿¡£", o_name);
4476 #else
4477                                         msg_format("The %s finds a mark.", o_name);
4478 #endif
4479
4480                                 }
4481
4482                                 /* Handle visible monster */
4483                                 else
4484                                 {
4485                                         char m_name[80];
4486
4487                                         /* Get "the monster" or "it" */
4488                                         monster_desc(m_name, m_ptr, 0);
4489
4490                                         /* Message */
4491 #ifdef JP
4492                                         msg_format("%s¤¬%s¤ËÌ¿Ã椷¤¿¡£", o_name, m_name);
4493 #else
4494                                         msg_format("The %s hits %s.", o_name, m_name);
4495 #endif
4496
4497
4498                                         /* Hack -- Track this monster race */
4499                                         if (m_ptr->ml) monster_race_track((m_ptr->mflag2 & MFLAG_KAGE), m_ptr->r_idx);
4500
4501                                         /* Hack -- Track this monster */
4502                                         if (m_ptr->ml) health_track(c_ptr->m_idx);
4503                                 }
4504
4505                                 /* Hack -- Base damage from thrown object */
4506                                 tdam = damroll(q_ptr->dd, q_ptr->ds);
4507                                 /* Apply special damage XXX XXX XXX */
4508                                 tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0);
4509                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, tdam);
4510                                 tdam += q_ptr->to_d;
4511
4512                                 if (boomerang)
4513                                 {
4514                                         tdam *= (mult+p_ptr->num_blow[item - INVEN_RARM]);
4515                                         tdam += p_ptr->to_d_m;
4516                                 }
4517                                 else if (f2 & (TR2_THROW))
4518                                 {
4519                                         tdam *= (3+mult);
4520                                         tdam += p_ptr->to_d_m;
4521                                 }
4522                                 else
4523                                 {
4524                                         tdam *= mult;
4525                                 }
4526                                 if (shuriken)
4527                                 {
4528                                         tdam += ((p_ptr->lev+30)*(p_ptr->lev+30)-900)/55;
4529                                 }
4530
4531                                 /* No negative damage */
4532                                 if (tdam < 0) tdam = 0;
4533
4534                                 /* Modify the damage */
4535                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
4536
4537                                 /* Complex message */
4538                                 if (wizard)
4539                                 {
4540 #ifdef JP
4541                                         msg_format("%d/%d¤Î¥À¥á¡¼¥¸¤òÍ¿¤¨¤¿¡£",
4542                                                    tdam, m_ptr->hp);
4543 #else
4544                                         msg_format("You do %d (out of %d) damage.",
4545                                                    tdam, m_ptr->hp);
4546 #endif
4547
4548                                 }
4549
4550                                 /* Hit the monster, check for death */
4551                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, note_dies))
4552                                 {
4553                                         /* Dead monster */
4554                                 }
4555
4556                                 /* No death */
4557                                 else
4558                                 {
4559                                         /* Message */
4560                                         message_pain(c_ptr->m_idx, tdam);
4561
4562                                         /* Anger the monster */
4563                                         if ((tdam > 0) && !object_is_potion(q_ptr))
4564                                                 anger_monster(m_ptr);
4565
4566                                         /* Take note */
4567                                         if (fear && m_ptr->ml)
4568                                         {
4569                                                 char m_name[80];
4570
4571                                                 /* Sound */
4572                                                 sound(SOUND_FLEE);
4573
4574                                                 /* Get the monster name (or "it") */
4575                                                 monster_desc(m_name, m_ptr, 0);
4576
4577                                                 /* Message */
4578 #ifdef JP
4579                                                 msg_format("%^s¤Ï¶²Éݤ·¤Æƨ¤²½Ð¤·¤¿¡ª", m_name);
4580 #else
4581                                                 msg_format("%^s flees in terror!", m_name);
4582 #endif
4583
4584                                         }
4585                                 }
4586                         }
4587
4588                         /* Stop looking */
4589                         break;
4590                 }
4591         }
4592
4593         /* Chance of breakage (during attacks) */
4594         j = (hit_body ? breakage_chance(q_ptr) : 0);
4595
4596         /* Figurines transform */
4597         if ((q_ptr->tval == TV_FIGURINE) && !(p_ptr->inside_arena))
4598         {
4599                 j = 100;
4600
4601                 if (!(summon_named_creature(y, x, q_ptr->pval, FALSE, FALSE, FALSE,
4602                       (bool)!(q_ptr->ident & IDENT_CURSED))))
4603 #ifdef JP
4604 msg_print("¿Í·Á¤ÏDZ¤¸¶Ê¤¬¤êºÕ¤±»¶¤Ã¤Æ¤·¤Þ¤Ã¤¿¡ª");
4605 #else
4606                         msg_print("The Figurine writhes and then shatters.");
4607 #endif
4608
4609                 else if (q_ptr->ident & IDENT_CURSED)
4610 #ifdef JP
4611 msg_print("¤³¤ì¤Ï¤¢¤Þ¤êÎɤ¯¤Ê¤¤µ¤¤¬¤¹¤ë¡£");
4612 #else
4613                         msg_print("You have a bad feeling about this.");
4614 #endif
4615
4616         }
4617
4618
4619         /* Potions smash open */
4620         if (object_is_potion(q_ptr))
4621         {
4622                 if (hit_body || hit_wall || (randint(100) < j))
4623                 {
4624                         /* Message */
4625 #ifdef JP
4626                         msg_format("%s¤ÏºÕ¤±»¶¤Ã¤¿¡ª", o_name);
4627 #else
4628                         msg_format("The %s shatters!", o_name);
4629 #endif
4630
4631
4632                         if (potion_smash_effect(0, y, x, q_ptr->k_idx))
4633                         {
4634                                 monster_type *m_ptr = &m_list[cave[y][x].m_idx];
4635
4636                                 /* ToDo (Robert): fix the invulnerability */
4637                                 if (cave[y][x].m_idx &&
4638                                     is_friendly(&m_list[cave[y][x].m_idx]) &&
4639                                     !(m_ptr->invulner))
4640                                 {
4641                                         char m_name[80];
4642                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
4643 #ifdef JP
4644                                         msg_format("%s¤ÏÅܤä¿¡ª", m_name);
4645 #else
4646                                         msg_format("%^s gets angry!", m_name);
4647 #endif
4648
4649                                         set_hostile(&m_list[cave[y][x].m_idx]);
4650                                 }
4651                         }
4652                         do_drop = FALSE;
4653                 }
4654                 else
4655                 {
4656                         j = 0;
4657                 }
4658         }
4659
4660         if (return_when_thrown)
4661         {
4662                 int back_chance = randint(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4663                 char o2_name[MAX_NLEN];
4664                 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
4665
4666                 j = -1;
4667                 if (boomerang) back_chance += 4+randint(5);
4668                 if (super_boomerang) back_chance += 100;
4669                 object_desc(o2_name, q_ptr, FALSE, 0);
4670
4671                 if((back_chance > 30) && ((randint(100) != 1) || super_boomerang))
4672                 {
4673                         for (i = cur_dis-1;i>0;i--)
4674                         {
4675                                 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(ny[i], nx[i]))
4676                                 {
4677                                         char c = object_char(q_ptr);
4678                                         byte a = object_attr(q_ptr);
4679
4680                                         /* Draw, Hilite, Fresh, Pause, Erase */
4681                                         print_rel(c, a, ny[i], nx[i]);
4682                                         move_cursor_relative(ny[i], nx[i]);
4683                                         Term_fresh();
4684                                         Term_xtra(TERM_XTRA_DELAY, msec);
4685                                         lite_spot(ny[i], nx[i]);
4686                                         Term_fresh();
4687                                 }
4688                                 else
4689                                 {
4690                                         /* Pause anyway, for consistancy */
4691                                         Term_xtra(TERM_XTRA_DELAY, msec);
4692                                 }
4693                         }
4694                         if((back_chance > 37) && !p_ptr->blind && (item >= 0))
4695                         {
4696 #ifdef JP
4697                                 msg_format("%s¤¬¼ê¸µ¤ËÊ֤äƤ­¤¿¡£", o2_name);
4698 #else
4699                                 msg_format("%s comes back to you.", o2_name);
4700 #endif
4701                                 come_back = TRUE;
4702                         }
4703                         else
4704                         {
4705                                 if (item >= 0)
4706                                 {
4707 #ifdef JP
4708                                         msg_format("%s¤ò¼õ¤±Â»¤Í¤¿¡ª", o2_name);
4709 #else
4710                                         msg_format("%s backs, but you can't catch!", o2_name);
4711 #endif
4712                                 }
4713                                 else
4714                                 {
4715 #ifdef JP
4716                                         msg_format("%s¤¬Ê֤äƤ­¤¿¡£", o2_name);
4717 #else
4718                                         msg_format("%s comes back.", o2_name);
4719 #endif
4720                                 }
4721                                 y = py;
4722                                 x = px;
4723                         }
4724                 }
4725                 else
4726                 {
4727 #ifdef JP
4728                         msg_format("%s¤¬Ê֤äƤ³¤Ê¤«¤Ã¤¿¡ª", o2_name);
4729 #else
4730                         msg_format("%s doesn't back!", o2_name);
4731 #endif
4732                 }
4733         }
4734
4735         if (come_back)
4736         {
4737                 if (item == INVEN_RARM || item == INVEN_LARM)
4738                 {
4739                         /* Access the wield slot */
4740                         o_ptr = &inventory[item];
4741
4742                         /* Wear the new stuff */
4743                         object_copy(o_ptr, q_ptr);
4744
4745                         /* Increase the weight */
4746                         p_ptr->total_weight += q_ptr->weight;
4747
4748                         /* Increment the equip counter by hand */
4749                         equip_cnt++;
4750
4751                         /* Recalculate bonuses */
4752                         p_ptr->update |= (PU_BONUS);
4753
4754                         /* Recalculate torch */
4755                         p_ptr->update |= (PU_TORCH);
4756
4757                         /* Recalculate mana XXX */
4758                         p_ptr->update |= (PU_MANA);
4759
4760                         /* Window stuff */
4761                         p_ptr->window |= (PW_EQUIP);
4762                 }
4763                 else
4764                 {
4765                         inven_carry(q_ptr);
4766                 }
4767                 do_drop = FALSE;
4768         }
4769         else if (equiped_item)
4770         {
4771                 kamaenaoshi(item);
4772                 calc_android_exp();
4773         }
4774
4775         /* Drop (or break) near that location */
4776         if (do_drop) (void)drop_near(q_ptr, j, y, x);
4777
4778         return TRUE;
4779 }
4780
4781
4782 /*
4783  * Throw an object from the pack or floor.
4784  */
4785 void do_cmd_throw(void)
4786 {
4787         do_cmd_throw_aux(1, FALSE, 0);
4788 }