OSDN Git Service

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