OSDN Git Service

[Refactor] #37353 コメント整理 / Refactor comments.
[hengbandforosx/hengbandosx.git] / src / cmd2.c
1 /*!
2  *  @file cmd2.c
3  *  @brief プレイヤーのコマンド処理2 / Movement commands (part 2)
4  *  @date 2014/01/02
5  *  @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  *
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  */
12
13 #include "angband.h"
14 #include "chest.h"
15 #include "object-hook.h"
16
17 /*!
18  * @brief フロア脱出時に出戻りが不可能だった場合に警告を加える処理
19  * @param down_stair TRUEならば階段を降りる処理、FALSEなら階段を昇る処理による内容
20  * @return フロア移動を実際に行うならTRUE、キャンセルする場合はFALSE
21  */
22 bool confirm_leave_level(bool down_stair)
23 {
24         quest_type *q_ptr = &quest[p_ptr->inside_quest];
25
26         /* Confirm leaving from once only quest */
27         if (confirm_quest && p_ptr->inside_quest &&
28             (q_ptr->type == QUEST_TYPE_RANDOM ||
29              (q_ptr->flags & QUEST_FLAG_ONCE &&
30                                                 q_ptr->status != QUEST_STATUS_COMPLETED) ||
31                  (q_ptr->flags & QUEST_FLAG_TOWER &&
32                                                 ((q_ptr->status != QUEST_STATUS_STAGE_COMPLETED) ||
33                                                  (down_stair && (quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED))))))
34         {
35                 msg_print(_("この階を一度去ると二度と戻って来られません。", "You can't come back here once you leave this floor."));
36                 if (get_check(_("本当にこの階を去りますか?", "Really leave this floor? "))) return TRUE;
37         }
38         else
39         {
40                 return TRUE;
41         }
42         return FALSE;
43 }
44
45 /*!
46  * @brief 階段を使って階層を昇る処理 / Go up one level
47  * @return なし
48  */
49 void do_cmd_go_up(void)
50 {
51         bool go_up = FALSE;
52
53         /* Player grid */
54         cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
55         feature_type *f_ptr = &f_info[c_ptr->feat];
56
57         int up_num = 0;
58
59         if (p_ptr->special_defense & KATA_MUSOU)
60         {
61                 set_action(ACTION_NONE);
62         }
63
64         /* Verify stairs */
65         if (!have_flag(f_ptr->flags, FF_LESS))
66         {
67                 msg_print(_("ここには上り階段が見当たらない。", "I see no up staircase here."));
68                 return;
69         }
70
71         /* Quest up stairs */
72         if (have_flag(f_ptr->flags, FF_QUEST))
73         {
74                 /* Cancel the command */
75                 if (!confirm_leave_level(FALSE)) return;
76         
77                 
78                 /* Success */
79                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
80                         msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
81                 else
82                         msg_print(_("上の階に登った。", "You enter the up staircase."));
83
84                 leave_quest_check();
85
86                 p_ptr->inside_quest = c_ptr->special;
87
88                 /* Activate the quest */
89                 if (!quest[p_ptr->inside_quest].status)
90                 {
91                         if (quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
92                         {
93                                 init_flags = INIT_ASSIGN;
94                                 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
95                         }
96                         quest[p_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
97                 }
98
99                 /* Leaving a quest */
100                 if (!p_ptr->inside_quest)
101                 {
102                         dun_level = 0;
103                 }
104
105                 /* Leaving */
106                 p_ptr->leaving = TRUE;
107
108                 p_ptr->oldpx = 0;
109                 p_ptr->oldpy = 0;
110                 
111                 /* Hack -- take a turn */
112                 p_ptr->energy_use = 100;
113
114                 /* End the command */
115                 return;
116         }
117
118         if (!dun_level)
119         {
120                 go_up = TRUE;
121         }
122         else
123         {
124                 go_up = confirm_leave_level(FALSE);
125         }
126
127         /* Cancel the command */
128         if (!go_up) return;
129
130         /* Hack -- take a turn */
131         p_ptr->energy_use = 100;
132
133         if (autosave_l) do_cmd_save_game(TRUE);
134
135         /* For a random quest */
136         if (p_ptr->inside_quest &&
137             quest[p_ptr->inside_quest].type == QUEST_TYPE_RANDOM)
138         {
139                 leave_quest_check();
140
141                 p_ptr->inside_quest = 0;
142         }
143
144         /* For a fixed quest */
145         if (p_ptr->inside_quest &&
146             quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
147         {
148                 leave_quest_check();
149
150                 p_ptr->inside_quest = c_ptr->special;
151                 dun_level = 0;
152                 up_num = 0;
153         }
154
155         /* For normal dungeon and random quest */
156         else
157         {
158                 /* New depth */
159                 if (have_flag(f_ptr->flags, FF_SHAFT))
160                 {
161                         /* Create a way back */
162                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP | CFM_SHAFT);
163
164                         up_num = 2;
165                 }
166                 else
167                 {
168                         /* Create a way back */
169                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP);
170
171                         up_num = 1;
172                 }
173
174                 /* Get out from current dungeon */
175                 if (dun_level - up_num < d_info[dungeon_type].mindepth)
176                         up_num = dun_level;
177         }
178         if (record_stair) do_cmd_write_nikki(NIKKI_STAIR, 0-up_num, _("階段を上った", "climbed up the stairs to"));
179
180         /* Success */
181         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
182                 msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
183         else if (up_num == dun_level)
184                 msg_print(_("地上に戻った。", "You go back to the surface."));
185         else
186                 msg_print(_("階段を上って新たなる迷宮へと足を踏み入れた。", "You enter a maze of up staircases."));
187
188         /* Leaving */
189         p_ptr->leaving = TRUE;
190 }
191
192
193 /*!
194  * @brief 階段を使って階層を降りる処理 / Go down one level
195  * @return なし
196  */
197 void do_cmd_go_down(void)
198 {
199         /* Player grid */
200         cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
201         feature_type *f_ptr = &f_info[c_ptr->feat];
202
203         bool fall_trap = FALSE;
204         int down_num = 0;
205
206         if (p_ptr->special_defense & KATA_MUSOU)
207         {
208                 set_action(ACTION_NONE);
209         }
210
211         /* Verify stairs */
212         if (!have_flag(f_ptr->flags, FF_MORE))
213         {
214                 msg_print(_("ここには下り階段が見当たらない。", "I see no down staircase here."));
215                 return;
216         }
217
218         if (have_flag(f_ptr->flags, FF_TRAP)) fall_trap = TRUE;
219
220         /* Quest entrance */
221         if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
222         {
223                 do_cmd_quest();
224         }
225
226         /* Quest down stairs */
227         else if (have_flag(f_ptr->flags, FF_QUEST))
228         {
229                 /* Confirm Leaving */
230                 if(!confirm_leave_level(TRUE)) return;
231                 
232                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
233                         msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
234                 else
235                         msg_print(_("下の階に降りた。", "You enter the down staircase."));
236
237                 leave_quest_check();
238                 leave_tower_check();
239
240                 p_ptr->inside_quest = c_ptr->special;
241
242                 /* Activate the quest */
243                 if (!quest[p_ptr->inside_quest].status)
244                 {
245                         if (quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
246                         {
247                                 init_flags = INIT_ASSIGN;
248                                 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
249                         }
250                         quest[p_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
251                 }
252
253                 /* Leaving a quest */
254                 if (!p_ptr->inside_quest)
255                 {
256                         dun_level = 0;
257                 }
258
259                 /* Leaving */
260                 p_ptr->leaving = TRUE;
261
262                 p_ptr->oldpx = 0;
263                 p_ptr->oldpy = 0;
264                 
265                 
266         /* Hack -- take a turn */
267         p_ptr->energy_use = 100;
268         }
269
270         else
271         {
272                 int target_dungeon = 0;
273
274                 if (!dun_level)
275                 {
276                         target_dungeon = have_flag(f_ptr->flags, FF_ENTRANCE) ? c_ptr->special : DUNGEON_ANGBAND;
277
278                         if (ironman_downward && (target_dungeon != DUNGEON_ANGBAND))
279                         {
280                                 msg_print(_("ダンジョンの入口は塞がれている!", "The entrance of this dungeon is closed!"));
281                                 return;
282                         }
283                         if (!max_dlv[target_dungeon])
284                         {
285                                 msg_format(_("ここには%sの入り口(%d階相当)があります", "There is the entrance of %s (Danger level: %d)"),
286                                                         d_name+d_info[target_dungeon].name, d_info[target_dungeon].mindepth);
287                                 if (!get_check(_("本当にこのダンジョンに入りますか?", "Do you really get in this dungeon? "))) return;
288                         }
289
290                         /* Save old player position */
291                         p_ptr->oldpx = p_ptr->x;
292                         p_ptr->oldpy = p_ptr->y;
293                         dungeon_type = (byte)target_dungeon;
294
295                         /*
296                          * Clear all saved floors
297                          * and create a first saved floor
298                          */
299                         prepare_change_floor_mode(CFM_FIRST_FLOOR);
300                 }
301
302                 /* Hack -- take a turn */
303                 p_ptr->energy_use = 100;
304
305                 if (autosave_l) do_cmd_save_game(TRUE);
306
307                 /* Go down */
308                 if (have_flag(f_ptr->flags, FF_SHAFT)) down_num += 2;
309                 else down_num += 1;
310
311                 if (!dun_level)
312                 {
313                         /* Enter the dungeon just now */
314                         p_ptr->enter_dungeon = TRUE;
315                         down_num = d_info[dungeon_type].mindepth;
316                 }
317
318                 if (record_stair)
319                 {
320                         if (fall_trap) do_cmd_write_nikki(NIKKI_STAIR, down_num, _("落とし戸に落ちた", "fell through a trap door"));
321                         else do_cmd_write_nikki(NIKKI_STAIR, down_num, _("階段を下りた", "climbed down the stairs to"));
322                 }
323
324                 if (fall_trap)
325                 {
326                         msg_print(_("わざと落とし戸に落ちた。", "You deliberately jump through the trap door."));
327                 }
328                 else
329                 {
330                         /* Success */
331                         if (target_dungeon)
332                         {
333                                 msg_format(_("%sへ入った。", "You entered %s."), d_text + d_info[dungeon_type].text);
334                         }
335                         else
336                         {
337                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
338                                         msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
339                                 else
340                                         msg_print(_("階段を下りて新たなる迷宮へと足を踏み入れた。", "You enter a maze of down staircases."));
341                         }
342                 }
343
344
345                 /* Leaving */
346                 p_ptr->leaving = TRUE;
347
348                 if (fall_trap)
349                 {
350                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
351                 }
352                 else
353                 {
354                         if (have_flag(f_ptr->flags, FF_SHAFT))
355                         {
356                                 /* Create a way back */
357                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_SHAFT);
358                         }
359                         else
360                         {
361                                 /* Create a way back */
362                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN);
363                         }
364                 }
365         }
366 }
367
368
369 /*!
370  * @brief 探索コマンドのメインルーチン / Simple command to "search" for one turn
371  * @return なし
372  */
373 void do_cmd_search(void)
374 {
375         /* Allow repeated command */
376         if (command_arg)
377         {
378                 /* Set repeat count */
379                 command_rep = command_arg - 1;
380
381                 /* Redraw the state */
382                 p_ptr->redraw |= (PR_STATE);
383
384                 /* Cancel the arg */
385                 command_arg = 0;
386         }
387         p_ptr->energy_use = 100;
388
389         /* Search */
390         search();
391 }
392
393
394 /*!
395  * @brief 該当のマスに存在している箱のオブジェクトIDを返す。
396  * @param y 走査対象にしたいマスのY座標
397  * @param x 走査対象にしたいマスのX座標
398  * @param trapped TRUEならばトラップが存在する箱のみ、FALSEならば空でない箱全てを対象にする
399  * @return 箱が存在する場合そのオブジェクトID、存在しない場合0を返す。
400  */
401 static OBJECT_IDX chest_check(POSITION y, POSITION x, bool trapped)
402 {
403         cave_type *c_ptr = &cave[y][x];
404
405         OBJECT_IDX this_o_idx, next_o_idx = 0;
406
407
408         /* Scan all objects in the grid */
409         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
410         {
411                 object_type *o_ptr;
412
413                 /* Acquire object */
414                 o_ptr = &o_list[this_o_idx];
415
416                 /* Acquire next object */
417                 next_o_idx = o_ptr->next_o_idx;
418
419                 /* Skip unknown chests XXX XXX */
420                 /* if (!(o_ptr->marked & OM_FOUND)) continue; */
421
422                 /* Check for non empty chest */
423                 if ((o_ptr->tval == TV_CHEST) &&
424                         (((!trapped) && (o_ptr->pval)) || /* non empty */
425                         ((trapped) && (o_ptr->pval > 0)))) /* trapped only */
426                 {
427                         return (this_o_idx);
428                 }
429         }
430
431         /* No chest */
432         return (0);
433 }
434
435 /*!
436  * @brief 箱を開けるコマンドのメインルーチン /
437  * Attempt to open the given chest at the given location
438  * @param y 箱の存在するマスのY座標
439  * @param x 箱の存在するマスのX座標
440  * @param o_idx 箱のオブジェクトID
441  * @return 箱が開かなかった場合TRUE / Returns TRUE if repeated commands may continue
442  * @details
443  * Assume there is no monster blocking the destination
444  */
445 static bool do_cmd_open_chest(POSITION y, POSITION x, OBJECT_IDX o_idx)
446 {
447         int i, j;
448         bool flag = TRUE;
449         bool more = FALSE;
450         object_type *o_ptr = &o_list[o_idx];
451
452         p_ptr->energy_use = 100;
453
454         /* Attempt to unlock it */
455         if (o_ptr->pval > 0)
456         {
457                 /* Assume locked, and thus not open */
458                 flag = FALSE;
459
460                 /* Get the "disarm" factor */
461                 i = p_ptr->skill_dis;
462
463                 /* Penalize some conditions */
464                 if (p_ptr->blind || no_lite()) i = i / 10;
465                 if (p_ptr->confused || p_ptr->image) i = i / 10;
466
467                 /* Extract the difficulty */
468                 j = i - o_ptr->pval;
469
470                 /* Always have a small chance of success */
471                 if (j < 2) j = 2;
472
473                 /* Success -- May still have traps */
474                 if (randint0(100) < j)
475                 {
476                         msg_print(_("鍵をはずした。", "You have picked the lock."));
477                         gain_exp(1);
478                         flag = TRUE;
479                 }
480
481                 /* Failure -- Keep trying */
482                 else
483                 {
484                         /* We may continue repeating */
485                         more = TRUE;
486                         if (flush_failure) flush();
487                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
488
489                 }
490         }
491
492         /* Allowed to open */
493         if (flag)
494         {
495                 /* Apply chest traps, if any */
496                 chest_trap(y, x, o_idx);
497
498                 /* Let the Chest drop items */
499                 chest_death(FALSE, y, x, o_idx);
500         }
501
502         /* Result */
503         return (more);
504 }
505
506
507 #if defined(ALLOW_EASY_OPEN) || defined(ALLOW_EASY_DISARM) /* TNB */
508
509 /*!
510  * @brief 地形は開くものであって、かつ開かれているかを返す /
511  * Attempt to open the given chest at the given location
512  * @param feat 地形ID
513  * @return 開いた地形である場合TRUEを返す /  Return TRUE if the given feature is an open door
514  */
515 static bool is_open(IDX feat)
516 {
517         return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
518 }
519
520
521 /*!
522  * @brief プレイヤーの周辺9マスに該当する地形がいくつあるかを返す /
523  * Attempt to open the given chest at the given location
524  * @param y 該当する地形の中から1つのY座標を返す参照ポインタ
525  * @param x 該当する地形の中から1つのX座標を返す参照ポインタ
526  * @param test 地形条件を判定するための関数ポインタ
527  * @param under TRUEならばプレイヤーの直下の座標も走査対象にする
528  * @return 該当する地形の数
529  * @details Return the number of features around (or under) the character.
530  * Usually look for doors and floor traps.
531  */
532 static int count_dt(POSITION *y, POSITION *x, bool (*test)(IDX feat), bool under)
533 {
534         int d, count, xx, yy;
535
536         /* Count how many matches */
537         count = 0;
538
539         /* Check around (and under) the character */
540         for (d = 0; d < 9; d++)
541         {
542                 cave_type *c_ptr;
543                 FEAT_IDX feat;
544
545                 /* if not searching under player continue */
546                 if ((d == 8) && !under) continue;
547
548                 /* Extract adjacent (legal) location */
549                 yy = p_ptr->y + ddy_ddd[d];
550                 xx = p_ptr->x + ddx_ddd[d];
551
552                 /* Get the cave */
553                 c_ptr = &cave[yy][xx];
554
555                 /* Must have knowledge */
556                 if (!(c_ptr->info & (CAVE_MARK))) continue;
557
558                 /* Feature code (applying "mimic" field) */
559                 feat = get_feat_mimic(c_ptr);
560
561                 /* Not looking for this feature */
562                 if (!((*test)(feat))) continue;
563
564                 /* OK */
565                 ++count;
566
567                 /* Remember the location. Only useful if only one match */
568                 *y = yy;
569                 *x = xx;
570         }
571
572         /* All done */
573         return count;
574 }
575
576
577 /*!
578  * @brief プレイヤーの周辺9マスに箱のあるマスがいくつあるかを返す /
579  * Return the number of chests around (or under) the character.
580  * @param y 該当するマスの中から1つのY座標を返す参照ポインタ
581  * @param x 該当するマスの中から1つのX座標を返す参照ポインタ
582  * @param trapped TRUEならばトラップの存在が判明している箱のみ対象にする
583  * @return 該当する地形の数
584  * @details
585  * If requested, count only trapped chests.
586  */
587 static int count_chests(POSITION *y, POSITION *x, bool trapped)
588 {
589         int d, count;
590         OBJECT_IDX o_idx;
591
592         object_type *o_ptr;
593
594         /* Count how many matches */
595         count = 0;
596
597         /* Check around (and under) the character */
598         for (d = 0; d < 9; d++)
599         {
600                 /* Extract adjacent (legal) location */
601                 POSITION yy = p_ptr->y + ddy_ddd[d];
602                 POSITION xx = p_ptr->x + ddx_ddd[d];
603
604                 /* No (visible) chest is there */
605                 if ((o_idx = chest_check(yy, xx, FALSE)) == 0) continue;
606
607                 /* Grab the object */
608                 o_ptr = &o_list[o_idx];
609
610                 /* Already open */
611                 if (o_ptr->pval == 0) continue;
612
613                 /* No (known) traps here */
614                 if (trapped && (!object_is_known(o_ptr) ||
615                         !chest_traps[o_ptr->pval])) continue;
616
617                 /* OK */
618                 ++count;
619
620                 /* Remember the location. Only useful if only one match */
621                 *y = yy;
622                 *x = xx;
623         }
624
625         /* All done */
626         return count;
627 }
628
629
630 /*!
631  * @brief プレイヤーから指定の座標がどの方角にあるかを返す /
632  * Convert an adjacent location to a direction.
633  * @param y 方角を確認したY座標
634  * @param x 方角を確認したX座標
635  * @return 方向ID
636  */
637 static DIRECTION coords_to_dir(POSITION y, POSITION x)
638 {
639         int d[3][3] = { {7, 4, 1}, {8, 5, 2}, {9, 6, 3} };
640         int dy, dx;
641
642         dy = y - p_ptr->y;
643         dx = x - p_ptr->x;
644
645         /* Paranoia */
646         if (ABS(dx) > 1 || ABS(dy) > 1) return (0);
647
648         return d[dx + 1][dy + 1];
649 }
650
651 #endif /* defined(ALLOW_EASY_OPEN) || defined(ALLOW_EASY_DISARM) -- TNB */
652
653
654 /*!
655  * @brief 「開ける」動作コマンドのサブルーチン /
656  * Perform the basic "open" command on doors
657  * @param y 対象を行うマスのY座標
658  * @param x 対象を行うマスのX座標
659  * @return 実際に処理が行われた場合TRUEを返す。
660  * @details
661  * Assume destination is a closed/locked/jammed door
662  * Assume there is no monster blocking the destination
663  * Returns TRUE if repeated commands may continue
664  */
665 static bool do_cmd_open_aux(POSITION y, POSITION x)
666 {
667         int i, j;
668
669         /* Get requested grid */
670         cave_type *c_ptr = &cave[y][x];
671         feature_type *f_ptr = &f_info[c_ptr->feat];
672         bool more = FALSE;
673
674         p_ptr->energy_use = 100;
675
676         /* Seeing true feature code (ignore mimic) */
677
678         /* Jammed door */
679         if (!have_flag(f_ptr->flags, FF_OPEN))
680         {
681                 /* Stuck */
682                 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(c_ptr)].name);
683         }
684
685         /* Locked door */
686         else if (f_ptr->power)
687         {
688                 /* Disarm factor */
689                 i = p_ptr->skill_dis;
690
691                 /* Penalize some conditions */
692                 if (p_ptr->blind || no_lite()) i = i / 10;
693                 if (p_ptr->confused || p_ptr->image) i = i / 10;
694
695                 /* Extract the lock power */
696                 j = f_ptr->power;
697
698                 /* Extract the difficulty XXX XXX XXX */
699                 j = i - (j * 4);
700
701                 /* Always have a small chance of success */
702                 if (j < 2) j = 2;
703
704                 /* Success */
705                 if (randint0(100) < j)
706                 {
707                         /* Message */
708                         msg_print(_("鍵をはずした。", "You have picked the lock."));
709
710                         /* Open the door */
711                         cave_alter_feat(y, x, FF_OPEN);
712
713                         sound(SOUND_OPENDOOR);
714
715                         /* Experience */
716                         gain_exp(1);
717                 }
718
719                 /* Failure */
720                 else
721                 {
722                         /* Failure */
723                         if (flush_failure) flush();
724
725                         /* Message */
726                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
727
728                         /* We may keep trying */
729                         more = TRUE;
730                 }
731         }
732
733         /* Closed door */
734         else
735         {
736                 /* Open the door */
737                 cave_alter_feat(y, x, FF_OPEN);
738
739                 sound(SOUND_OPENDOOR);
740         }
741
742         /* Result */
743         return (more);
744 }
745
746 /*!
747  * @brief 「開ける」コマンドのメインルーチン /
748  * Open a closed/locked/jammed door or a closed/locked chest.
749  * @return なし
750  * @details
751  * Unlocking a locked door/chest is worth one experience point.
752  */
753 void do_cmd_open(void)
754 {
755         POSITION y, x;
756         DIRECTION dir;
757         OBJECT_IDX o_idx;
758
759         bool more = FALSE;
760
761         if (p_ptr->special_defense & KATA_MUSOU)
762         {
763                 set_action(ACTION_NONE);
764         }
765
766 #ifdef ALLOW_EASY_OPEN /* TNB */
767
768         /* Option: Pick a direction */
769         if (easy_open)
770         {
771                 int num_doors, num_chests;
772
773                 /* Count closed doors (locked or jammed) */
774                 num_doors = count_dt(&y, &x, is_closed_door, FALSE);
775
776                 /* Count chests (locked) */
777                 num_chests = count_chests(&y, &x, FALSE);
778
779                 /* See if only one target */
780                 if (num_doors || num_chests)
781                 {
782                         bool too_many = (num_doors && num_chests) || (num_doors > 1) ||
783                             (num_chests > 1);
784                         if (!too_many) command_dir = coords_to_dir(y, x);
785                 }
786         }
787
788 #endif /* ALLOW_EASY_OPEN -- TNB */
789
790         /* Allow repeated command */
791         if (command_arg)
792         {
793                 /* Set repeat count */
794                 command_rep = command_arg - 1;
795
796                 /* Redraw the state */
797                 p_ptr->redraw |= (PR_STATE);
798
799                 /* Cancel the arg */
800                 command_arg = 0;
801         }
802
803         /* Get a "repeated" direction */
804         if (get_rep_dir(&dir, TRUE))
805         {
806                 FEAT_IDX feat;
807                 cave_type *c_ptr;
808
809                 /* Get requested location */
810                 y = p_ptr->y + ddy[dir];
811                 x = p_ptr->x + ddx[dir];
812
813                 /* Get requested grid */
814                 c_ptr = &cave[y][x];
815
816                 /* Feature code (applying "mimic" field) */
817                 feat = get_feat_mimic(c_ptr);
818
819                 /* Check for chest */
820                 o_idx = chest_check(y, x, FALSE);
821
822                 /* Nothing useful */
823                 if (!have_flag(f_info[feat].flags, FF_OPEN) && !o_idx)
824                 {
825                         /* Message */
826                         msg_print(_("そこには開けるものが見当たらない。", "You see nothing there to open."));
827                 }
828
829                 /* Monster in the way */
830                 else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
831                 {
832                         p_ptr->energy_use = 100;
833
834                         /* Message */
835                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
836                         
837                         /* Attack */
838                         py_attack(y, x, 0);
839                 }
840
841                 /* Handle chests */
842                 else if (o_idx)
843                 {
844                         /* Open the chest */
845                         more = do_cmd_open_chest(y, x, o_idx);
846                 }
847
848                 /* Handle doors */
849                 else
850                 {
851                         /* Open the door */
852                         more = do_cmd_open_aux(y, x);
853                 }
854         }
855
856         /* Cancel repeat unless we may continue */
857         if (!more) disturb(0, 0);
858 }
859
860
861
862 /*!
863  * @brief 「閉じる」動作コマンドのサブルーチン /
864  * Perform the basic "close" command
865  * @param y 対象を行うマスのY座標
866  * @param x 対象を行うマスのX座標
867  * @return 実際に処理が行われた場合TRUEを返す。
868  * @details
869  * Assume destination is an open/broken door
870  * Assume there is no monster blocking the destination
871  * Returns TRUE if repeated commands may continue
872  */
873 static bool do_cmd_close_aux(POSITION y, POSITION x)
874 {
875         /* Get grid and contents */
876         cave_type *c_ptr = &cave[y][x];
877         FEAT_IDX old_feat = c_ptr->feat;
878         bool more = FALSE;
879
880         p_ptr->energy_use = 100;
881
882         /* Seeing true feature code (ignore mimic) */
883
884         /* Open door */
885         if (have_flag(f_info[old_feat].flags, FF_CLOSE))
886         {
887                 s16b closed_feat = feat_state(old_feat, FF_CLOSE);
888
889                 /* Hack -- object in the way */
890                 if ((c_ptr->o_idx || (c_ptr->info & CAVE_OBJECT)) &&
891                     (closed_feat != old_feat) && !have_flag(f_info[closed_feat].flags, FF_DROP))
892                 {
893                         /* Message */
894                         msg_print(_("何かがつっかえて閉まらない。", "There seems stuck."));
895                 }
896                 else
897                 {
898                         /* Close the door */
899                         cave_alter_feat(y, x, FF_CLOSE);
900
901                         /* Broken door */
902                         if (old_feat == c_ptr->feat)
903                         {
904                                 /* Message */
905                                 msg_print(_("ドアは壊れてしまっている。", "The door appears to be broken."));
906                         }
907                         else
908                         {
909                                 sound(SOUND_SHUTDOOR);
910                         }
911                 }
912         }
913
914         /* Result */
915         return (more);
916 }
917
918
919 /*!
920  * @brief 「閉じる」コマンドのメインルーチン /
921  * Close an open door.
922  * @return なし
923  * @details
924  * Unlocking a locked door/chest is worth one experience point.
925  */
926 void do_cmd_close(void)
927 {
928         POSITION y, x;
929         DIRECTION dir;
930
931         bool more = FALSE;
932
933         if (p_ptr->special_defense & KATA_MUSOU)
934         {
935                 set_action(ACTION_NONE);
936         }
937
938 #ifdef ALLOW_EASY_OPEN /* TNB */
939
940         /* Option: Pick a direction */
941         if (easy_open)
942         {
943                 /* Count open doors */
944                 if (count_dt(&y, &x, is_open, FALSE) == 1)
945                 {
946                         command_dir = coords_to_dir(y, x);
947                 }
948         }
949
950 #endif /* ALLOW_EASY_OPEN -- TNB */
951
952         /* Allow repeated command */
953         if (command_arg)
954         {
955                 /* Set repeat count */
956                 command_rep = command_arg - 1;
957
958                 /* Redraw the state */
959                 p_ptr->redraw |= (PR_STATE);
960
961                 /* Cancel the arg */
962                 command_arg = 0;
963         }
964
965         /* Get a "repeated" direction */
966         if (get_rep_dir(&dir,FALSE))
967         {
968                 cave_type *c_ptr;
969                 FEAT_IDX feat;
970
971                 /* Get requested location */
972                 y = p_ptr->y + ddy[dir];
973                 x = p_ptr->x + ddx[dir];
974
975                 /* Get grid and contents */
976                 c_ptr = &cave[y][x];
977
978                 /* Feature code (applying "mimic" field) */
979                 feat = get_feat_mimic(c_ptr);
980
981                 /* Require open/broken door */
982                 if (!have_flag(f_info[feat].flags, FF_CLOSE))
983                 {
984                         /* Message */
985                         msg_print(_("そこには閉じるものが見当たらない。", "You see nothing there to close."));
986                 }
987
988                 /* Monster in the way */
989                 else if (c_ptr->m_idx)
990                 {
991                         p_ptr->energy_use = 100;
992
993                         /* Message */
994                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
995
996                         /* Attack */
997                         py_attack(y, x, 0);
998                 }
999
1000                 /* Close the door */
1001                 else
1002                 {
1003                         /* Close the door */
1004                         more = do_cmd_close_aux(y, x);
1005                 }
1006         }
1007
1008         /* Cancel repeat unless we may continue */
1009         if (!more) disturb(0, 0);
1010 }
1011
1012
1013 /*!
1014  * @brief 「掘る」コマンドを該当のマスに行えるかの判定と結果メッセージの表示 /
1015  * Determine if a given grid may be "tunneled"
1016  * @param y 対象を行うマスのY座標
1017  * @param x 対象を行うマスのX座標
1018  * @return 
1019  */
1020 static bool do_cmd_tunnel_test(POSITION y, POSITION x)
1021 {
1022         cave_type *c_ptr = &cave[y][x];
1023
1024         /* Must have knowledge */
1025         if (!(c_ptr->info & CAVE_MARK))
1026         {
1027                 /* Message */
1028                 msg_print(_("そこには何も見当たらない。", "You see nothing there."));
1029
1030                 /* Nope */
1031                 return (FALSE);
1032         }
1033
1034         /* Must be a wall/door/etc */
1035         if (!cave_have_flag_grid(c_ptr, FF_TUNNEL))
1036         {
1037                 /* Message */
1038                 msg_print(_("そこには掘るものが見当たらない。", "You see nothing there to tunnel."));
1039
1040                 /* Nope */
1041                 return (FALSE);
1042         }
1043
1044         /* Okay */
1045         return (TRUE);
1046 }
1047
1048
1049 /*!
1050  * @brief 「掘る」動作コマンドのサブルーチン /
1051  * Perform the basic "tunnel" command
1052  * @param y 対象を行うマスのY座標
1053  * @param x 対象を行うマスのX座標
1054  * @return 実際に処理が行われた場合TRUEを返す。
1055  * @details
1056  * Assumes that no monster is blocking the destination
1057  * Do not use twall anymore
1058  * Returns TRUE if repeated commands may continue
1059  */
1060 static bool do_cmd_tunnel_aux(POSITION y, POSITION x)
1061 {
1062         cave_type *c_ptr;
1063         feature_type *f_ptr, *mimic_f_ptr;
1064         int power;
1065         cptr name;
1066         bool more = FALSE;
1067
1068         /* Verify legality */
1069         if (!do_cmd_tunnel_test(y, x)) return (FALSE);
1070
1071         p_ptr->energy_use = 100;
1072
1073         /* Get grid */
1074         c_ptr = &cave[y][x];
1075         f_ptr = &f_info[c_ptr->feat];
1076         power = f_ptr->power;
1077
1078         /* Feature code (applying "mimic" field) */
1079         mimic_f_ptr = &f_info[get_feat_mimic(c_ptr)];
1080
1081         name = f_name + mimic_f_ptr->name;
1082
1083         sound(SOUND_DIG);
1084
1085         if (have_flag(f_ptr->flags, FF_PERMANENT))
1086         {
1087                 /* Titanium */
1088                 if (have_flag(mimic_f_ptr->flags, FF_PERMANENT))
1089                 {
1090                         msg_print(_("この岩は硬すぎて掘れないようだ。", "This seems to be permanent rock."));
1091                 }
1092
1093                 /* Map border (mimiccing Permanent wall) */
1094                 else
1095                 {
1096                         msg_print(_("そこは掘れない!", "You can't tunnel through that!"));
1097                 }
1098         }
1099
1100         /* Dig or tunnel */
1101         else if (have_flag(f_ptr->flags, FF_CAN_DIG))
1102         {
1103                 /* Dig */
1104                 if (p_ptr->skill_dig > randint0(20 * power))
1105                 {
1106                         /* Message */
1107                         msg_format(_("%sをくずした。", "You have removed the %s."), name);
1108
1109                         /* Remove the feature */
1110                         cave_alter_feat(y, x, FF_TUNNEL);
1111
1112                         /* Update some things */
1113                         p_ptr->update |= (PU_FLOW);
1114                 }
1115                 else
1116                 {
1117                         /* Message, keep digging */
1118                         msg_format(_("%sをくずしている。", "You dig into the %s."), name);
1119                         
1120                         more = TRUE;
1121                 }
1122         }
1123
1124         else
1125         {
1126                 bool tree = have_flag(mimic_f_ptr->flags, FF_TREE);
1127
1128                 /* Tunnel */
1129                 if (p_ptr->skill_dig > power + randint0(40 * power))
1130                 {
1131                         if (tree) msg_format(_("%sを切り払った。", "You have cleared away the %s."), name);
1132                         else
1133                         {
1134                                 msg_print(_("穴を掘り終えた。", "You have finished the tunnel."));
1135                                 p_ptr->update |= (PU_FLOW);
1136                         }
1137                         
1138                         if (have_flag(f_ptr->flags, FF_GLASS)) sound(SOUND_GLASS);
1139
1140                         /* Remove the feature */
1141                         cave_alter_feat(y, x, FF_TUNNEL);
1142
1143                         chg_virtue(V_DILIGENCE, 1);
1144                         chg_virtue(V_NATURE, -1);
1145                 }
1146
1147                 /* Keep trying */
1148                 else
1149                 {
1150                         if (tree)
1151                         {
1152                                 /* We may continue chopping */
1153                                 msg_format(_("%sを切っている。", "You chop away at the %s."), name);
1154                                 /* Occasional Search XXX XXX */
1155                                 if (randint0(100) < 25) search();
1156                         }
1157                         else
1158                         {
1159                                 /* We may continue tunelling */
1160                                 msg_format(_("%sに穴を掘っている。", "You tunnel into the %s."), name);
1161                         }
1162
1163                         more = TRUE;
1164                 }
1165         }
1166
1167         if (is_hidden_door(c_ptr))
1168         {
1169                 /* Occasional Search XXX XXX */
1170                 if (randint0(100) < 25) search();
1171         }
1172
1173         /* Result */
1174         return more;
1175 }
1176
1177
1178 /*!
1179  * @brief 「掘る」動作コマンドのメインルーチン /
1180  * Tunnels through "walls" (including rubble and closed doors)
1181  * @return なし
1182  * @details
1183  * <pre>
1184  * Note that you must tunnel in order to hit invisible monsters
1185  * in walls, though moving into walls still takes a turn anyway.
1186  *
1187  * Digging is very difficult without a "digger" weapon, but can be
1188  * accomplished by strong players using heavy weapons.
1189  * </pre>
1190  */
1191 void do_cmd_tunnel(void)
1192 {
1193         int                     y, x, dir;
1194
1195         cave_type       *c_ptr;
1196         FEAT_IDX feat;
1197
1198         bool            more = FALSE;
1199
1200
1201         if (p_ptr->special_defense & KATA_MUSOU)
1202         {
1203                 set_action(ACTION_NONE);
1204         }
1205
1206         /* Allow repeated command */
1207         if (command_arg)
1208         {
1209                 /* Set repeat count */
1210                 command_rep = command_arg - 1;
1211
1212                 /* Redraw the state */
1213                 p_ptr->redraw |= (PR_STATE);
1214
1215                 /* Cancel the arg */
1216                 command_arg = 0;
1217         }
1218
1219         /* Get a direction to tunnel, or Abort */
1220         if (get_rep_dir(&dir,FALSE))
1221         {
1222                 /* Get location */
1223                 y = p_ptr->y + ddy[dir];
1224                 x = p_ptr->x + ddx[dir];
1225
1226                 /* Get grid */
1227                 c_ptr = &cave[y][x];
1228
1229                 /* Feature code (applying "mimic" field) */
1230                 feat = get_feat_mimic(c_ptr);
1231
1232                 /* No tunnelling through doors */
1233                 if (have_flag(f_info[feat].flags, FF_DOOR))
1234                 {
1235                         /* Message */
1236                         msg_print(_("ドアは掘れない。", "You cannot tunnel through doors."));
1237                 }
1238
1239                 /* No tunnelling through most features */
1240                 else if (!have_flag(f_info[feat].flags, FF_TUNNEL))
1241                 {
1242                         msg_print(_("そこは掘れない。", "You can't tunnel through that."));
1243                 }
1244
1245                 /* A monster is in the way */
1246                 else if (c_ptr->m_idx)
1247                 {
1248                         p_ptr->energy_use = 100;
1249
1250                         /* Message */
1251                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1252
1253                         /* Attack */
1254                         py_attack(y, x, 0);
1255                 }
1256
1257                 /* Try digging */
1258                 else
1259                 {
1260                         /* Tunnel through walls */
1261                         more = do_cmd_tunnel_aux(y, x);
1262                 }
1263         }
1264
1265         /* Cancel repetition unless we can continue */
1266         if (!more) disturb(0, 0);
1267 }
1268
1269
1270 #ifdef ALLOW_EASY_OPEN /* TNB */
1271
1272 /*!
1273  * @brief 移動処理による簡易な「開く」処理 /
1274  * easy_open_door --
1275  * @return 開く処理が実際に試みられた場合TRUEを返す
1276  * @details
1277  * <pre>
1278  *      If there is a jammed/closed/locked door at the given location,
1279  *      then attempt to unlock/open it. Return TRUE if an attempt was
1280  *      made (successful or not), otherwise return FALSE.
1281  *
1282  *      The code here should be nearly identical to that in
1283  *      do_cmd_open_test() and do_cmd_open_aux().
1284  * </pre>
1285  */
1286 bool easy_open_door(POSITION y, POSITION x)
1287 {
1288         int i, j;
1289
1290         cave_type *c_ptr = &cave[y][x];
1291         feature_type *f_ptr = &f_info[c_ptr->feat];
1292
1293         /* Must be a closed door */
1294         if (!is_closed_door(c_ptr->feat))
1295         {
1296                 /* Nope */
1297                 return (FALSE);
1298         }
1299
1300         /* Jammed door */
1301         if (!have_flag(f_ptr->flags, FF_OPEN))
1302         {
1303                 /* Stuck */
1304                 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(c_ptr)].name);
1305
1306         }
1307
1308         /* Locked door */
1309         else if (f_ptr->power)
1310         {
1311                 /* Disarm factor */
1312                 i = p_ptr->skill_dis;
1313
1314                 /* Penalize some conditions */
1315                 if (p_ptr->blind || no_lite()) i = i / 10;
1316                 if (p_ptr->confused || p_ptr->image) i = i / 10;
1317
1318                 /* Extract the lock power */
1319                 j = f_ptr->power;
1320
1321                 /* Extract the difficulty XXX XXX XXX */
1322                 j = i - (j * 4);
1323
1324                 /* Always have a small chance of success */
1325                 if (j < 2) j = 2;
1326
1327                 /* Success */
1328                 if (randint0(100) < j)
1329                 {
1330                         /* Message */
1331                         msg_print(_("鍵をはずした。", "You have picked the lock."));
1332
1333                         /* Open the door */
1334                         cave_alter_feat(y, x, FF_OPEN);
1335
1336                         sound(SOUND_OPENDOOR);
1337
1338                         /* Experience */
1339                         gain_exp(1);
1340                 }
1341
1342                 /* Failure */
1343                 else
1344                 {
1345                         /* Failure */
1346                         if (flush_failure) flush();
1347
1348                         /* Message */
1349                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
1350
1351                 }
1352         }
1353
1354         /* Closed door */
1355         else
1356         {
1357                 /* Open the door */
1358                 cave_alter_feat(y, x, FF_OPEN);
1359
1360                 sound(SOUND_OPENDOOR);
1361         }
1362
1363         /* Result */
1364         return (TRUE);
1365 }
1366
1367 #endif /* ALLOW_EASY_OPEN -- TNB */
1368
1369
1370 /*!
1371  * @brief 箱のトラップを解除するコマンドのメインルーチン /
1372  * Perform the basic "disarm" command
1373  * @param y 解除を行うマスのY座標
1374  * @param x 解除を行うマスのX座標
1375  * @param o_idx 箱のオブジェクトID
1376  * @return ターンを消費する処理が行われた場合TRUEを返す
1377  * @details
1378  * <pre>
1379  * Assume destination is a visible trap
1380  * Assume there is no monster blocking the destination
1381  * Returns TRUE if repeated commands may continue
1382  * </pre>
1383  */
1384 static bool do_cmd_disarm_chest(POSITION y, POSITION x, OBJECT_IDX o_idx)
1385 {
1386         int i, j;
1387         bool more = FALSE;
1388         object_type *o_ptr = &o_list[o_idx];
1389
1390         p_ptr->energy_use = 100;
1391
1392         /* Get the "disarm" factor */
1393         i = p_ptr->skill_dis;
1394
1395         /* Penalize some conditions */
1396         if (p_ptr->blind || no_lite()) i = i / 10;
1397         if (p_ptr->confused || p_ptr->image) i = i / 10;
1398
1399         /* Extract the difficulty */
1400         j = i - o_ptr->pval;
1401
1402         /* Always have a small chance of success */
1403         if (j < 2) j = 2;
1404
1405         /* Must find the trap first. */
1406         if (!object_is_known(o_ptr))
1407         {
1408                 msg_print(_("トラップが見あたらない。", "I don't see any traps."));
1409
1410         }
1411
1412         /* Already disarmed/unlocked */
1413         else if (o_ptr->pval <= 0)
1414         {
1415                 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1416         }
1417
1418         /* No traps to find. */
1419         else if (!chest_traps[o_ptr->pval])
1420         {
1421                 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1422         }
1423
1424         /* Success (get a lot of experience) */
1425         else if (randint0(100) < j)
1426         {
1427                 msg_print(_("箱に仕掛けられていたトラップを解除した。", "You have disarmed the chest."));
1428                 gain_exp(o_ptr->pval);
1429                 o_ptr->pval = (0 - o_ptr->pval);
1430         }
1431
1432         /* Failure -- Keep trying */
1433         else if ((i > 5) && (randint1(i) > 5))
1434         {
1435                 /* We may keep trying */
1436                 more = TRUE;
1437                 if (flush_failure) flush();
1438                 msg_print(_("箱のトラップ解除に失敗した。", "You failed to disarm the chest."));
1439         }
1440
1441         /* Failure -- Set off the trap */
1442         else
1443         {
1444                 msg_print(_("トラップを作動させてしまった!", "You set off a trap!"));
1445                 sound(SOUND_FAIL);
1446                 chest_trap(y, x, o_idx);
1447         }
1448
1449         /* Result */
1450         return (more);
1451 }
1452
1453
1454 /*!
1455  * @brief 箱のトラップを解除するコマンドのサブルーチン /
1456  * Perform the basic "disarm" command
1457  * @param y 解除を行うマスのY座標
1458  * @param x 解除を行うマスのX座標
1459  * @param dir プレイヤーからみた方向ID
1460  * @return ターンを消費する処理が行われた場合TRUEを返す
1461  * @details
1462  * <pre>
1463  * Assume destination is a visible trap
1464  * Assume there is no monster blocking the destination
1465  * Returns TRUE if repeated commands may continue
1466  * </pre>
1467  */
1468 #ifdef ALLOW_EASY_DISARM /* TNB */
1469
1470 bool do_cmd_disarm_aux(POSITION y, POSITION x, DIRECTION dir)
1471
1472 #else /* ALLOW_EASY_DISARM -- TNB */
1473
1474 static bool do_cmd_disarm_aux(POSITION y, POSITION x, DIRECTION dir)
1475
1476 #endif /* ALLOW_EASY_DISARM -- TNB */
1477 {
1478         /* Get grid and contents */
1479         cave_type *c_ptr = &cave[y][x];
1480
1481         /* Get feature */
1482         feature_type *f_ptr = &f_info[c_ptr->feat];
1483
1484         /* Access trap name */
1485         cptr name = (f_name + f_ptr->name);
1486
1487         /* Extract trap "power" */
1488         int power = f_ptr->power;
1489         bool more = FALSE;
1490
1491         /* Get the "disarm" factor */
1492         int i = p_ptr->skill_dis;
1493         int j;
1494
1495         p_ptr->energy_use = 100;
1496
1497         /* Penalize some conditions */
1498         if (p_ptr->blind || no_lite()) i = i / 10;
1499         if (p_ptr->confused || p_ptr->image) i = i / 10;
1500
1501         /* Extract the difficulty */
1502         j = i - power;
1503
1504         /* Always have a small chance of success */
1505         if (j < 2) j = 2;
1506
1507         /* Success */
1508         if (randint0(100) < j)
1509         {
1510                 /* Message */
1511                 msg_format(_("%sを解除した。", "You have disarmed the %s."), name);
1512                 
1513                 /* Reward */
1514                 gain_exp(power);
1515
1516                 /* Remove the trap */
1517                 cave_alter_feat(y, x, FF_DISARM);
1518
1519 #ifdef ALLOW_EASY_DISARM /* TNB */
1520
1521                 /* Move the player onto the trap */
1522                 move_player(dir, easy_disarm, FALSE);
1523
1524 #else /* ALLOW_EASY_DISARM -- TNB */
1525
1526                 /* move the player onto the trap grid */
1527                 move_player(dir, FALSE, FALSE);
1528
1529 #endif /* ALLOW_EASY_DISARM -- TNB */
1530         }
1531
1532         /* Failure -- Keep trying */
1533         else if ((i > 5) && (randint1(i) > 5))
1534         {
1535                 /* Failure */
1536                 if (flush_failure) flush();
1537
1538                 /* Message */
1539                 msg_format(_("%sの解除に失敗した。", "You failed to disarm the %s."), name);
1540
1541                 /* We may keep trying */
1542                 more = TRUE;
1543         }
1544
1545         /* Failure -- Set off the trap */
1546         else
1547         {
1548                 /* Message */
1549                 msg_format(_("%sを作動させてしまった!", "You set off the %s!"), name);
1550
1551 #ifdef ALLOW_EASY_DISARM /* TNB */
1552
1553                 /* Move the player onto the trap */
1554                 move_player(dir, easy_disarm, FALSE);
1555
1556 #else /* ALLOW_EASY_DISARM -- TNB */
1557
1558                 /* Move the player onto the trap */
1559                 move_player(dir, FALSE, FALSE);
1560
1561 #endif /* ALLOW_EASY_DISARM -- TNB */
1562         }
1563
1564         /* Result */
1565         return (more);
1566 }
1567
1568
1569 /*!
1570  * @brief 箱、床のトラップ解除処理双方の統合メインルーチン /
1571  * Disarms a trap, or chest
1572  * @return なし
1573  */
1574 void do_cmd_disarm(void)
1575 {
1576         POSITION y, x;
1577         DIRECTION dir;
1578         s16b o_idx;
1579
1580         bool more = FALSE;
1581
1582         if (p_ptr->special_defense & KATA_MUSOU)
1583         {
1584                 set_action(ACTION_NONE);
1585         }
1586
1587 #ifdef ALLOW_EASY_DISARM /* TNB */
1588
1589         /* Option: Pick a direction */
1590         if (easy_disarm)
1591         {
1592                 int num_traps, num_chests;
1593
1594                 /* Count visible traps */
1595                 num_traps = count_dt(&y, &x, is_trap, TRUE);
1596
1597                 /* Count chests (trapped) */
1598                 num_chests = count_chests(&y, &x, TRUE);
1599
1600                 /* See if only one target */
1601                 if (num_traps || num_chests)
1602                 {
1603                         bool too_many = (num_traps && num_chests) || (num_traps > 1) || (num_chests > 1);
1604                         if (!too_many) command_dir = coords_to_dir(y, x);
1605                 }
1606         }
1607
1608 #endif /* ALLOW_EASY_DISARM -- TNB */
1609
1610         /* Allow repeated command */
1611         if (command_arg)
1612         {
1613                 /* Set repeat count */
1614                 command_rep = command_arg - 1;
1615
1616                 /* Redraw the state */
1617                 p_ptr->redraw |= (PR_STATE);
1618
1619                 /* Cancel the arg */
1620                 command_arg = 0;
1621         }
1622
1623         /* Get a direction (or abort) */
1624         if (get_rep_dir(&dir,TRUE))
1625         {
1626                 cave_type *c_ptr;
1627                 FEAT_IDX feat;
1628
1629                 /* Get location */
1630                 y = p_ptr->y + ddy[dir];
1631                 x = p_ptr->x + ddx[dir];
1632
1633                 /* Get grid and contents */
1634                 c_ptr = &cave[y][x];
1635
1636                 /* Feature code (applying "mimic" field) */
1637                 feat = get_feat_mimic(c_ptr);
1638
1639                 /* Check for chests */
1640                 o_idx = chest_check(y, x, TRUE);
1641
1642                 /* Disarm a trap */
1643                 if (!is_trap(feat) && !o_idx)
1644                 {
1645                         /* Message */
1646                         msg_print(_("そこには解除するものが見当たらない。", "You see nothing there to disarm."));
1647                 }
1648
1649                 /* Monster in the way */
1650                 else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
1651                 {
1652                         /* Message */
1653                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1654
1655                         /* Attack */
1656                         py_attack(y, x, 0);
1657                 }
1658
1659                 /* Disarm chest */
1660                 else if (o_idx)
1661                 {
1662                         /* Disarm the chest */
1663                         more = do_cmd_disarm_chest(y, x, o_idx);
1664                 }
1665
1666                 /* Disarm trap */
1667                 else
1668                 {
1669                         /* Disarm the trap */
1670                         more = do_cmd_disarm_aux(y, x, dir);
1671                 }
1672         }
1673
1674         /* Cancel repeat unless told not to */
1675         if (!more) disturb(0, 0);
1676 }
1677
1678
1679 /*!
1680  * @brief 「打ち破る」動作コマンドのサブルーチン /
1681  * Perform the basic "bash" command
1682  * @param y 対象を行うマスのY座標
1683  * @param x 対象を行うマスのX座標
1684  * @param dir プレイヤーから見たターゲットの方角ID
1685  * @return 実際に処理が行われた場合TRUEを返す。
1686  * @details
1687  * <pre>
1688  * Assume destination is a closed/locked/jammed door
1689  * Assume there is no monster blocking the destination
1690  * Returns TRUE if repeated commands may continue
1691  * </pre>
1692  */
1693 static bool do_cmd_bash_aux(POSITION y, POSITION x, DIRECTION dir)
1694 {
1695         /* Get grid */
1696         cave_type       *c_ptr = &cave[y][x];
1697
1698         /* Get feature */
1699         feature_type *f_ptr = &f_info[c_ptr->feat];
1700
1701         /* Hack -- Bash power based on strength */
1702         /* (Ranges from 3 to 20 to 100 to 200) */
1703         int bash = adj_str_blow[p_ptr->stat_ind[A_STR]];
1704
1705         /* Extract door power */
1706         int temp = f_ptr->power;
1707
1708         bool            more = FALSE;
1709
1710         cptr name = f_name + f_info[get_feat_mimic(c_ptr)].name;
1711
1712         p_ptr->energy_use = 100;
1713
1714         /* Message */
1715         msg_format(_("%sに体当たりをした!", "You smash into the %s!"), name);
1716
1717         /* Compare bash power to door power XXX XXX XXX */
1718         temp = (bash - (temp * 10));
1719
1720         if (p_ptr->pclass == CLASS_BERSERKER) temp *= 2;
1721
1722         /* Hack -- always have a chance */
1723         if (temp < 1) temp = 1;
1724
1725         /* Hack -- attempt to bash down the door */
1726         if (randint0(100) < temp)
1727         {
1728                 /* Message */
1729                 msg_format(_("%sを壊した!", "The %s crashes open!"), name);
1730
1731                 sound(have_flag(f_ptr->flags, FF_GLASS) ? SOUND_GLASS : SOUND_OPENDOOR);
1732
1733                 /* Break down the door */
1734                 if ((randint0(100) < 50) || (feat_state(c_ptr->feat, FF_OPEN) == c_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS))
1735                 {
1736                         cave_alter_feat(y, x, FF_BASH);
1737                 }
1738
1739                 /* Open the door */
1740                 else
1741                 {
1742                         cave_alter_feat(y, x, FF_OPEN);
1743                 }
1744
1745                 /* Hack -- Fall through the door */
1746                 move_player(dir, FALSE, FALSE);
1747         }
1748
1749         /* Saving throw against stun */
1750         else if (randint0(100) < adj_dex_safe[p_ptr->stat_ind[A_DEX]] +
1751                  p_ptr->lev)
1752         {
1753                 /* Message */
1754                 msg_format(_("この%sは頑丈だ。", "The %s holds firm."), name);
1755
1756                 /* Allow repeated bashing */
1757                 more = TRUE;
1758         }
1759
1760         /* High dexterity yields coolness */
1761         else
1762         {
1763                 /* Message */
1764                 msg_print(_("体のバランスをくずしてしまった。", "You are off-balance."));
1765
1766                 /* Hack -- Lose balance ala paralysis */
1767                 (void)set_paralyzed(p_ptr->paralyzed + 2 + randint0(2));
1768         }
1769
1770         /* Result */
1771         return (more);
1772 }
1773
1774
1775 /*!
1776  * @brief 「打ち破る」動作コマンドのメインルーチン /
1777  * Bash open a door, success based on character strength
1778  * @return なし
1779  * @details
1780  * <pre>
1781  * For a closed door, pval is positive if locked; negative if stuck.
1782  *
1783  * For an open door, pval is positive for a broken door.
1784  *
1785  * A closed door can be opened - harder if locked. Any door might be
1786  * bashed open (and thereby broken). Bashing a door is (potentially)
1787  * faster! You move into the door way. To open a stuck door, it must
1788  * be bashed. A closed door can be jammed (see do_cmd_spike()).
1789  *
1790  * Creatures can also open or bash doors, see elsewhere.
1791  * </pre>
1792  */
1793 void do_cmd_bash(void)
1794 {
1795         int                     y, x, dir;
1796
1797         cave_type       *c_ptr;
1798
1799         bool            more = FALSE;
1800
1801
1802         if (p_ptr->special_defense & KATA_MUSOU)
1803         {
1804                 set_action(ACTION_NONE);
1805         }
1806
1807         /* Allow repeated command */
1808         if (command_arg)
1809         {
1810                 /* Set repeat count */
1811                 command_rep = command_arg - 1;
1812
1813                 /* Redraw the state */
1814                 p_ptr->redraw |= (PR_STATE);
1815
1816                 /* Cancel the arg */
1817                 command_arg = 0;
1818         }
1819
1820         /* Get a "repeated" direction */
1821         if (get_rep_dir(&dir,FALSE))
1822         {
1823                 FEAT_IDX feat;
1824
1825                 /* Bash location */
1826                 y = p_ptr->y + ddy[dir];
1827                 x = p_ptr->x + ddx[dir];
1828
1829                 /* Get grid */
1830                 c_ptr = &cave[y][x];
1831
1832                 /* Feature code (applying "mimic" field) */
1833                 feat = get_feat_mimic(c_ptr);
1834
1835                 /* Nothing useful */
1836                 if (!have_flag(f_info[feat].flags, FF_BASH))
1837                 {
1838                         /* Message */
1839                         msg_print(_("そこには体当たりするものが見当たらない。", "You see nothing there to bash."));
1840                 }
1841
1842                 /* Monster in the way */
1843                 else if (c_ptr->m_idx)
1844                 {
1845                         p_ptr->energy_use = 100;
1846
1847                         /* Message */
1848                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1849
1850                         /* Attack */
1851                         py_attack(y, x, 0);
1852                 }
1853
1854                 /* Bash a closed door */
1855                 else
1856                 {
1857                         /* Bash the door */
1858                         more = do_cmd_bash_aux(y, x, dir);
1859                 }
1860         }
1861
1862         /* Unless valid action taken, cancel bash */
1863         if (!more) disturb(0, 0);
1864 }
1865
1866
1867 /*!
1868  * @brief 特定のマスに影響を及ぼすための汎用的コマンド
1869  * @return なし
1870  * @details
1871  * <pre>
1872  * Manipulate an adjacent grid in some way
1873  *
1874  * Attack monsters, tunnel through walls, disarm traps, open doors.
1875  *
1876  * Consider confusion XXX XXX XXX
1877  *
1878  * This command must always take a turn, to prevent free detection
1879  * of invisible monsters.
1880  * </pre>
1881  */
1882 void do_cmd_alter(void)
1883 {
1884         int                     y, x, dir;
1885
1886         cave_type       *c_ptr;
1887
1888         bool            more = FALSE;
1889
1890
1891         if (p_ptr->special_defense & KATA_MUSOU)
1892         {
1893                 set_action(ACTION_NONE);
1894         }
1895
1896         /* Allow repeated command */
1897         if (command_arg)
1898         {
1899                 /* Set repeat count */
1900                 command_rep = command_arg - 1;
1901
1902                 /* Redraw the state */
1903                 p_ptr->redraw |= (PR_STATE);
1904
1905                 /* Cancel the arg */
1906                 command_arg = 0;
1907         }
1908
1909         /* Get a direction */
1910         if (get_rep_dir(&dir,TRUE))
1911         {
1912                 FEAT_IDX feat;
1913                 feature_type *f_ptr;
1914
1915                 /* Get location */
1916                 y = p_ptr->y + ddy[dir];
1917                 x = p_ptr->x + ddx[dir];
1918
1919                 /* Get grid */
1920                 c_ptr = &cave[y][x];
1921
1922                 /* Feature code (applying "mimic" field) */
1923                 feat = get_feat_mimic(c_ptr);
1924                 f_ptr = &f_info[feat];
1925
1926                 p_ptr->energy_use = 100;
1927
1928                 /* Attack monsters */
1929                 if (c_ptr->m_idx)
1930                 {
1931                         /* Attack */
1932                         py_attack(y, x, 0);
1933                 }
1934
1935                 /* Locked doors */
1936                 else if (have_flag(f_ptr->flags, FF_OPEN))
1937                 {
1938                         more = do_cmd_open_aux(y, x);
1939                 }
1940
1941                 /* Bash jammed doors */
1942                 else if (have_flag(f_ptr->flags, FF_BASH))
1943                 {
1944                         more = do_cmd_bash_aux(y, x, dir);
1945                 }
1946
1947                 /* Tunnel through walls */
1948                 else if (have_flag(f_ptr->flags, FF_TUNNEL))
1949                 {
1950                         more = do_cmd_tunnel_aux(y, x);
1951                 }
1952
1953                 /* Close open doors */
1954                 else if (have_flag(f_ptr->flags, FF_CLOSE))
1955                 {
1956                         more = do_cmd_close_aux(y, x);
1957                 }
1958
1959                 /* Disarm traps */
1960                 else if (have_flag(f_ptr->flags, FF_DISARM))
1961                 {
1962                         more = do_cmd_disarm_aux(y, x, dir);
1963                 }
1964
1965                 /* Oops */
1966                 else
1967                 {
1968                         /* Oops */
1969                         msg_print(_("何もない空中を攻撃した。", "You attack the empty air."));
1970                 }
1971         }
1972
1973         /* Cancel repetition unless we can continue */
1974         if (!more) disturb(0, 0);
1975 }
1976
1977
1978
1979 /*!
1980  * @brief 「くさびを打つ」ために必要なオブジェクトがあるかどうかの判定を返す /
1981  * Find the index of some "spikes", if possible.
1982  * @param ip くさびとして打てるオブジェクトのID
1983  * @return オブジェクトがある場合TRUEを返す
1984  * @details
1985  * <pre>
1986  * XXX XXX XXX Let user choose a pile of spikes, perhaps?
1987  * </pre>
1988  */
1989 static bool get_spike(INVENTORY_IDX *ip)
1990 {
1991         INVENTORY_IDX i;
1992
1993         /* Check every item in the pack */
1994         for (i = 0; i < INVEN_PACK; i++)
1995         {
1996                 object_type *o_ptr = &inventory[i];
1997
1998                 /* Skip non-objects */
1999                 if (!o_ptr->k_idx) continue;
2000
2001                 /* Check the "tval" code */
2002                 if (o_ptr->tval == TV_SPIKE)
2003                 {
2004                         /* Save the spike index */
2005                         (*ip) = i;
2006
2007                         /* Success */
2008                         return (TRUE);
2009                 }
2010         }
2011
2012         /* Oops */
2013         return (FALSE);
2014 }
2015
2016
2017 /*!
2018  * @brief 「くさびを打つ」動作コマンドのメインルーチン /
2019  * Jam a closed door with a spike
2020  * @return なし
2021  * @details
2022  * <pre>
2023  * This command may NOT be repeated
2024  * </pre>
2025  */
2026 void do_cmd_spike(void)
2027 {
2028         DIRECTION dir;
2029
2030         if (p_ptr->special_defense & KATA_MUSOU)
2031         {
2032                 set_action(ACTION_NONE);
2033         }
2034
2035         /* Get a "repeated" direction */
2036         if (get_rep_dir(&dir,FALSE))
2037         {
2038                 POSITION y, x;
2039                 INVENTORY_IDX item;
2040                 cave_type *c_ptr;
2041                 FEAT_IDX feat;
2042
2043                 /* Get location */
2044                 y = p_ptr->y + ddy[dir];
2045                 x = p_ptr->x + ddx[dir];
2046
2047                 /* Get grid and contents */
2048                 c_ptr = &cave[y][x];
2049
2050                 /* Feature code (applying "mimic" field) */
2051                 feat = get_feat_mimic(c_ptr);
2052
2053                 /* Require closed door */
2054                 if (!have_flag(f_info[feat].flags, FF_SPIKE))
2055                 {
2056                         /* Message */
2057                         msg_print(_("そこにはくさびを打てるものが見当たらない。", "You see nothing there to spike."));
2058                 }
2059
2060                 /* Get a spike */
2061                 else if (!get_spike(&item))
2062                 {
2063                         /* Message */
2064                         msg_print(_("くさびを持っていない!", "You have no spikes!"));
2065                 }
2066
2067                 /* Is a monster in the way? */
2068                 else if (c_ptr->m_idx)
2069                 {
2070                         p_ptr->energy_use = 100;
2071
2072                         /* Message */
2073                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
2074
2075                         /* Attack */
2076                         py_attack(y, x, 0);
2077                 }
2078
2079                 /* Go for it */
2080                 else
2081                 {
2082                         p_ptr->energy_use = 100;
2083
2084                         /* Successful jamming */
2085                         msg_format(_("%sにくさびを打ち込んだ。", "You jam the %s with a spike."), f_name + f_info[feat].name);
2086                         cave_alter_feat(y, x, FF_SPIKE);
2087
2088                         /* Use up, and describe, a single spike, from the bottom */
2089                         inven_item_increase(item, -1);
2090                         inven_item_describe(item);
2091                         inven_item_optimize(item);
2092                 }
2093         }
2094 }
2095
2096
2097
2098 /*!
2099  * @brief 「歩く」動作コマンドのメインルーチン /
2100  * Support code for the "Walk" and "Jump" commands
2101  * @param pickup アイテムの自動拾いを行うならTRUE
2102  * @return なし
2103  */
2104 void do_cmd_walk(bool pickup)
2105 {
2106         DIRECTION dir;
2107
2108         bool more = FALSE;
2109
2110
2111         /* Allow repeated command */
2112         if (command_arg)
2113         {
2114                 /* Set repeat count */
2115                 command_rep = command_arg - 1;
2116
2117                 /* Redraw the state */
2118                 p_ptr->redraw |= (PR_STATE);
2119
2120                 /* Cancel the arg */
2121                 command_arg = 0;
2122         }
2123
2124         /* Get a "repeated" direction */
2125         if (get_rep_dir(&dir, FALSE))
2126         {
2127                 p_ptr->energy_use = 100;
2128
2129                 if ((dir != 5) && (p_ptr->special_defense & KATA_MUSOU))
2130                 {
2131                         set_action(ACTION_NONE);
2132                 }
2133
2134                 /* Hack -- In small scale wilderness it takes MUCH more time to move */
2135                 if (p_ptr->wild_mode) p_ptr->energy_use *= ((MAX_HGT + MAX_WID) / 2);
2136                 if (p_ptr->action == ACTION_HAYAGAKE) p_ptr->energy_use = p_ptr->energy_use * (45-(p_ptr->lev/2)) / 100;
2137
2138                 /* Actually move the character */
2139                 move_player(dir, pickup, FALSE);
2140
2141                 /* Allow more walking */
2142                 more = TRUE;
2143         }
2144
2145         /* Hack again -- Is there a special encounter ??? */
2146         if (p_ptr->wild_mode && !cave_have_flag_bold(p_ptr->y, p_ptr->x, FF_TOWN))
2147         {
2148                 int tmp = 120 + p_ptr->lev*10 - wilderness[p_ptr->y][p_ptr->x].level + 5;
2149                 if (tmp < 1) 
2150                         tmp = 1;
2151                 if (((wilderness[p_ptr->y][p_ptr->x].level + 5) > (p_ptr->lev / 2)) && randint0(tmp) < (21-p_ptr->skill_stl))
2152                 {
2153                         /* Inform the player of his horrible fate :=) */
2154                         msg_print(_("襲撃だ!", "You are ambushed !"));
2155
2156                         /* Go into large wilderness view */
2157                         p_ptr->oldpy = randint1(MAX_HGT-2);
2158                         p_ptr->oldpx = randint1(MAX_WID-2);
2159                         change_wild_mode();
2160
2161                         /* Give first move to monsters */
2162                         p_ptr->energy_use = 100;
2163
2164                         /* HACk -- set the encouter flag for the wilderness generation */
2165                         generate_encounter = TRUE;
2166                 }
2167         }
2168
2169         /* Cancel repeat unless we may continue */
2170         if (!more) disturb(0, 0);
2171 }
2172
2173
2174 /*!
2175  * @brief 「走る」動作コマンドのメインルーチン /
2176  * Start running.
2177  * @return なし
2178  */
2179 void do_cmd_run(void)
2180 {
2181         DIRECTION dir;
2182
2183         /* Hack -- no running when confused */
2184         if (p_ptr->confused)
2185         {
2186                 msg_print(_("混乱していて走れない!", "You are too confused!"));
2187                 return;
2188         }
2189
2190         if (p_ptr->special_defense & KATA_MUSOU)
2191         {
2192                 set_action(ACTION_NONE);
2193         }
2194
2195         /* Get a "repeated" direction */
2196         if (get_rep_dir(&dir,FALSE))
2197         {
2198                 /* Hack -- Set the run counter */
2199                 running = (command_arg ? command_arg : 1000);
2200
2201                 /* First step */
2202                 run_step(dir);
2203         }
2204 }
2205
2206
2207 /*!
2208  * @brief 「留まる」動作コマンドのメインルーチン /
2209  * Stay still.  Search.  Enter stores.
2210  * Pick up treasure if "pickup" is true.
2211  * @param pickup アイテムの自動拾いを行うならTRUE
2212  * @return なし
2213  */
2214 void do_cmd_stay(bool pickup)
2215 {
2216         u32b mpe_mode = MPE_STAYING | MPE_ENERGY_USE;
2217
2218         /* Allow repeated command */
2219         if (command_arg)
2220         {
2221                 /* Set repeat count */
2222                 command_rep = command_arg - 1;
2223
2224                 /* Redraw the state */
2225                 p_ptr->redraw |= (PR_STATE);
2226
2227                 /* Cancel the arg */
2228                 command_arg = 0;
2229         }
2230
2231         p_ptr->energy_use = 100;
2232
2233         if (pickup) mpe_mode |= MPE_DO_PICKUP;
2234         (void)move_player_effect(p_ptr->y, p_ptr->x, mpe_mode);
2235 }
2236
2237
2238 /*!
2239  * @brief 「休む」動作コマンドのメインルーチン /
2240  * Resting allows a player to safely restore his hp     -RAK-
2241  * @return なし
2242  */
2243 void do_cmd_rest(void)
2244 {
2245
2246         set_action(ACTION_NONE);
2247
2248         if ((p_ptr->pclass == CLASS_BARD) && (SINGING_SONG_EFFECT(p_ptr) || INTERUPTING_SONG_EFFECT(p_ptr)))
2249         {
2250                 stop_singing();
2251         }
2252
2253         /* Hex */
2254         if (hex_spelling_any()) stop_hex_spell_all();
2255
2256         /* Prompt for time if needed */
2257         if (command_arg <= 0)
2258         {
2259                 cptr p = _("休憩 (0-9999, '*' で HP/MP全快, '&' で必要なだけ): ", 
2260                                    "Rest (0-9999, '*' for HP/SP, '&' as needed): ");
2261
2262
2263                 char out_val[80];
2264
2265                 /* Default */
2266                 strcpy(out_val, "&");
2267
2268                 /* Ask for duration */
2269                 if (!get_string(p, out_val, 4)) return;
2270
2271                 /* Rest until done */
2272                 if (out_val[0] == '&')
2273                 {
2274                         command_arg = COMMAND_ARG_REST_UNTIL_DONE;
2275                 }
2276
2277                 /* Rest a lot */
2278                 else if (out_val[0] == '*')
2279                 {
2280                         command_arg = COMMAND_ARG_REST_FULL_HEALING;
2281                 }
2282
2283                 /* Rest some */
2284                 else
2285                 {
2286                         command_arg = (COMMAND_ARG)atoi(out_val);
2287                         if (command_arg <= 0) return;
2288                 }
2289         }
2290
2291
2292         /* Paranoia */
2293         if (command_arg > 9999) command_arg = 9999;
2294
2295         if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
2296
2297         /* Take a turn XXX XXX XXX (?) */
2298         p_ptr->energy_use = 100;
2299
2300         /* The sin of sloth */
2301         if (command_arg > 100)
2302                 chg_virtue(V_DILIGENCE, -1);
2303         
2304         /* Why are you sleeping when there's no need?  WAKE UP!*/
2305         if ((p_ptr->chp == p_ptr->mhp) &&
2306             (p_ptr->csp == p_ptr->msp) &&
2307             !p_ptr->blind && !p_ptr->confused &&
2308             !p_ptr->poisoned && !p_ptr->afraid &&
2309             !p_ptr->stun && !p_ptr->cut &&
2310             !p_ptr->slow && !p_ptr->paralyzed &&
2311             !p_ptr->image && !p_ptr->word_recall &&
2312             !p_ptr->alter_reality)
2313                         chg_virtue(V_DILIGENCE, -1);
2314
2315         /* Save the rest code */
2316         resting = command_arg;
2317         p_ptr->action = ACTION_REST;
2318
2319         /* Recalculate bonuses */
2320         p_ptr->update |= (PU_BONUS);
2321
2322         /* Redraw the state */
2323         p_ptr->redraw |= (PR_STATE);
2324
2325         /* Handle stuff */
2326         handle_stuff();
2327
2328         /* Refresh */
2329         Term_fresh();
2330 }
2331
2332
2333 /*!
2334  * @brief 矢弾を射撃した場合の破損確率を返す /
2335  * Determines the odds of an object breaking when thrown at a monster
2336  * @param o_ptr 矢弾のオブジェクト構造体参照ポインタ
2337  * @return 破損確率(%)
2338  * @details
2339  * Note that artifacts never break, see the "drop_near()" function.
2340  */
2341 static PERCENTAGE breakage_chance(object_type *o_ptr)
2342 {
2343         PERCENTAGE archer_bonus = (p_ptr->pclass == CLASS_ARCHER ? (PERCENTAGE)(p_ptr->lev-1)/7 + 4: 0);
2344
2345         /* Examine the snipe type */
2346         if (snipe_type)
2347         {
2348                 if (snipe_type == SP_KILL_WALL) return (100);
2349                 if (snipe_type == SP_EXPLODE) return (100);
2350                 if (snipe_type == SP_PIERCE) return (100);
2351                 if (snipe_type == SP_FINAL) return (100);
2352                 if (snipe_type == SP_NEEDLE) return (100);
2353                 if (snipe_type == SP_EVILNESS) return (40);
2354                 if (snipe_type == SP_HOLYNESS) return (40);
2355         }
2356
2357         /* Examine the item type */
2358         switch (o_ptr->tval)
2359         {
2360                 /* Always break */
2361                 case TV_FLASK:
2362                 case TV_POTION:
2363                 case TV_BOTTLE:
2364                 case TV_FOOD:
2365                 case TV_JUNK:
2366                         return (100);
2367
2368                 /* Often break */
2369                 case TV_LITE:
2370                 case TV_SCROLL:
2371                 case TV_SKELETON:
2372                         return (50);
2373
2374                 /* Sometimes break */
2375                 case TV_WAND:
2376                 case TV_SPIKE:
2377                         return (25);
2378                 case TV_ARROW:
2379                         return (20 - archer_bonus * 2);
2380
2381                 /* Rarely break */
2382                 case TV_SHOT:
2383                 case TV_BOLT:
2384                         return (10 - archer_bonus);
2385                 default:
2386                         return (10);
2387         }
2388 }
2389
2390
2391 /*!
2392  * @brief 矢弾を射撃した際のスレイ倍率をかけた結果を返す /
2393  * Determines the odds of an object breaking when thrown at a monster
2394  * @param o_ptr 矢弾のオブジェクト構造体参照ポインタ
2395  * @param tdam 計算途中のダメージ量
2396  * @param m_ptr 目標モンスターの構造体参照ポインタ
2397  * @return スレイ倍率をかけたダメージ量
2398  */
2399 static s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
2400 {
2401         int mult = 10;
2402
2403         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2404
2405         BIT_FLAGS flgs[TR_FLAG_SIZE];
2406
2407         /* Extract the flags */
2408         object_flags(o_ptr, flgs);
2409
2410         /* Some "weapons" and "ammo" do extra damage */
2411         switch (o_ptr->tval)
2412         {
2413                 case TV_SHOT:
2414                 case TV_ARROW:
2415                 case TV_BOLT:
2416                 {
2417                         /* Slay Animal */
2418                         if ((have_flag(flgs, TR_SLAY_ANIMAL)) &&
2419                             (r_ptr->flags3 & RF3_ANIMAL))
2420                         {
2421                                 if (is_original_ap_and_seen(m_ptr))
2422                                 {
2423                                         r_ptr->r_flags3 |= RF3_ANIMAL;
2424                                 }
2425
2426                                 if (mult < 17) mult = 17;
2427                         }
2428
2429                         /* Kill Animal */
2430                         if ((have_flag(flgs, TR_KILL_ANIMAL)) &&
2431                             (r_ptr->flags3 & RF3_ANIMAL))
2432                         {
2433                                 if (is_original_ap_and_seen(m_ptr))
2434                                 {
2435                                         r_ptr->r_flags3 |= RF3_ANIMAL;
2436                                 }
2437
2438                                 if (mult < 27) mult = 27;
2439                         }
2440
2441                         /* Slay Evil */
2442                         if ((have_flag(flgs, TR_SLAY_EVIL)) &&
2443                             (r_ptr->flags3 & RF3_EVIL))
2444                         {
2445                                 if (is_original_ap_and_seen(m_ptr))
2446                                 {
2447                                         r_ptr->r_flags3 |= RF3_EVIL;
2448                                 }
2449
2450                                 if (mult < 15) mult = 15;
2451                         }
2452
2453                         /* Kill Evil */
2454                         if ((have_flag(flgs, TR_KILL_EVIL)) &&
2455                             (r_ptr->flags3 & RF3_EVIL))
2456                         {
2457                                 if (is_original_ap_and_seen(m_ptr))
2458                                 {
2459                                         r_ptr->r_flags3 |= RF3_EVIL;
2460                                 }
2461
2462                                 if (mult < 25) mult = 25;
2463                         }
2464
2465                         /* Slay Human */
2466                         if ((have_flag(flgs, TR_SLAY_HUMAN)) &&
2467                             (r_ptr->flags2 & RF2_HUMAN))
2468                         {
2469                                 if (is_original_ap_and_seen(m_ptr))
2470                                 {
2471                                         r_ptr->r_flags2 |= RF2_HUMAN;
2472                                 }
2473
2474                                 if (mult < 17) mult = 17;
2475                         }
2476
2477                         /* Kill Human */
2478                         if ((have_flag(flgs, TR_KILL_HUMAN)) &&
2479                             (r_ptr->flags2 & RF2_HUMAN))
2480                         {
2481                                 if (is_original_ap_and_seen(m_ptr))
2482                                 {
2483                                         r_ptr->r_flags2 |= RF2_HUMAN;
2484                                 }
2485
2486                                 if (mult < 27) mult = 27;
2487                         }
2488
2489                         /* Slay Undead */
2490                         if ((have_flag(flgs, TR_SLAY_UNDEAD)) &&
2491                             (r_ptr->flags3 & RF3_UNDEAD))
2492                         {
2493                                 if (is_original_ap_and_seen(m_ptr))
2494                                 {
2495                                         r_ptr->r_flags3 |= RF3_UNDEAD;
2496                                 }
2497
2498                                 if (mult < 20) mult = 20;
2499                         }
2500
2501                         /* Kill Undead */
2502                         if ((have_flag(flgs, TR_KILL_UNDEAD)) &&
2503                             (r_ptr->flags3 & RF3_UNDEAD))
2504                         {
2505                                 if (is_original_ap_and_seen(m_ptr))
2506                                 {
2507                                         r_ptr->r_flags3 |= RF3_UNDEAD;
2508                                 }
2509
2510                                 if (mult < 30) mult = 30;
2511                         }
2512
2513                         /* Slay Demon */
2514                         if ((have_flag(flgs, TR_SLAY_DEMON)) &&
2515                             (r_ptr->flags3 & RF3_DEMON))
2516                         {
2517                                 if (is_original_ap_and_seen(m_ptr))
2518                                 {
2519                                         r_ptr->r_flags3 |= RF3_DEMON;
2520                                 }
2521
2522                                 if (mult < 20) mult = 20;
2523                         }
2524
2525                         /* Kill Demon */
2526                         if ((have_flag(flgs, TR_KILL_DEMON)) &&
2527                             (r_ptr->flags3 & RF3_DEMON))
2528                         {
2529                                 if (is_original_ap_and_seen(m_ptr))
2530                                 {
2531                                         r_ptr->r_flags3 |= RF3_DEMON;
2532                                 }
2533
2534                                 if (mult < 30) mult = 30;
2535                         }
2536
2537                         /* Slay Orc */
2538                         if ((have_flag(flgs, TR_SLAY_ORC)) &&
2539                             (r_ptr->flags3 & RF3_ORC))
2540                         {
2541                                 if (is_original_ap_and_seen(m_ptr))
2542                                 {
2543                                         r_ptr->r_flags3 |= RF3_ORC;
2544                                 }
2545
2546                                 if (mult < 20) mult = 20;
2547                         }
2548
2549                         /* Kill Orc */
2550                         if ((have_flag(flgs, TR_KILL_ORC)) &&
2551                             (r_ptr->flags3 & RF3_ORC))
2552                         {
2553                                 if (is_original_ap_and_seen(m_ptr))
2554                                 {
2555                                         r_ptr->r_flags3 |= RF3_ORC;
2556                                 }
2557
2558                                 if (mult < 30) mult = 30;
2559                         }
2560
2561                         /* Slay Troll */
2562                         if ((have_flag(flgs, TR_SLAY_TROLL)) &&
2563                             (r_ptr->flags3 & RF3_TROLL))
2564                         {
2565                                 if (is_original_ap_and_seen(m_ptr))
2566                                 {
2567                                         r_ptr->r_flags3 |= RF3_TROLL;
2568                                 }
2569
2570                                 if (mult < 20) mult = 20;
2571                         }
2572
2573                         /* Kill Troll */
2574                         if ((have_flag(flgs, TR_KILL_TROLL)) &&
2575                             (r_ptr->flags3 & RF3_TROLL))
2576                         {
2577                                 if (is_original_ap_and_seen(m_ptr))
2578                                 {
2579                                         r_ptr->r_flags3 |= RF3_TROLL;
2580                                 }
2581
2582                                 if (mult < 30) mult = 30;
2583                         }
2584
2585                         /* Slay Giant */
2586                         if ((have_flag(flgs, TR_SLAY_GIANT)) &&
2587                             (r_ptr->flags3 & RF3_GIANT))
2588                         {
2589                                 if (is_original_ap_and_seen(m_ptr))
2590                                 {
2591                                         r_ptr->r_flags3 |= RF3_GIANT;
2592                                 }
2593
2594                                 if (mult < 20) mult = 20;
2595                         }
2596
2597                         /* Kill Giant */
2598                         if ((have_flag(flgs, TR_KILL_GIANT)) &&
2599                             (r_ptr->flags3 & RF3_GIANT))
2600                         {
2601                                 if (is_original_ap_and_seen(m_ptr))
2602                                 {
2603                                         r_ptr->r_flags3 |= RF3_GIANT;
2604                                 }
2605
2606                                 if (mult < 30) mult = 30;
2607                         }
2608
2609                         /* Slay Dragon  */
2610                         if ((have_flag(flgs, TR_SLAY_DRAGON)) &&
2611                             (r_ptr->flags3 & RF3_DRAGON))
2612                         {
2613                                 if (is_original_ap_and_seen(m_ptr))
2614                                 {
2615                                         r_ptr->r_flags3 |= RF3_DRAGON;
2616                                 }
2617
2618                                 if (mult < 20) mult = 20;
2619                         }
2620
2621                         /* Execute Dragon */
2622                         if ((have_flag(flgs, TR_KILL_DRAGON)) &&
2623                             (r_ptr->flags3 & RF3_DRAGON))
2624                         {
2625                                 if (is_original_ap_and_seen(m_ptr))
2626                                 {
2627                                         r_ptr->r_flags3 |= RF3_DRAGON;
2628                                 }
2629
2630                                 if (mult < 30) mult = 30;
2631
2632                                 if ((o_ptr->name1 == ART_BARD_ARROW) &&
2633                                     (m_ptr->r_idx == MON_SMAUG) &&
2634                                     (inventory[INVEN_BOW].name1 == ART_BARD))
2635                                         mult *= 5;
2636                         }
2637
2638                         /* Brand (Acid) */
2639                         if (have_flag(flgs, TR_BRAND_ACID))
2640                         {
2641                                 /* Notice immunity */
2642                                 if (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK)
2643                                 {
2644                                         if (is_original_ap_and_seen(m_ptr))
2645                                         {
2646                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK);
2647                                         }
2648                                 }
2649
2650                                 /* Otherwise, take the damage */
2651                                 else
2652                                 {
2653                                         if (mult < 17) mult = 17;
2654                                 }
2655                         }
2656
2657                         /* Brand (Elec) */
2658                         if (have_flag(flgs, TR_BRAND_ELEC))
2659                         {
2660                                 /* Notice immunity */
2661                                 if (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)
2662                                 {
2663                                         if (is_original_ap_and_seen(m_ptr))
2664                                         {
2665                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
2666                                         }
2667                                 }
2668
2669                                 /* Otherwise, take the damage */
2670                                 else
2671                                 {
2672                                         if (mult < 17) mult = 17;
2673                                 }
2674                         }
2675
2676                         /* Brand (Fire) */
2677                         if (have_flag(flgs, TR_BRAND_FIRE))
2678                         {
2679                                 /* Notice immunity */
2680                                 if (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)
2681                                 {
2682                                         if (is_original_ap_and_seen(m_ptr))
2683                                         {
2684                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
2685                                         }
2686                                 }
2687
2688                                 /* Otherwise, take the damage */
2689                                 else
2690                                 {
2691                                         if (r_ptr->flags3 & RF3_HURT_FIRE)
2692                                         {
2693                                                 if (mult < 25) mult = 25;
2694                                                 if (is_original_ap_and_seen(m_ptr))
2695                                                 {
2696                                                         r_ptr->r_flags3 |= RF3_HURT_FIRE;
2697                                                 }
2698                                         }
2699                                         else if (mult < 17) mult = 17;
2700                                 }
2701                         }
2702
2703                         /* Brand (Cold) */
2704                         if (have_flag(flgs, TR_BRAND_COLD))
2705                         {
2706                                 /* Notice immunity */
2707                                 if (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)
2708                                 {
2709                                         if (is_original_ap_and_seen(m_ptr))
2710                                         {
2711                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
2712                                         }
2713                                 }
2714                                 /* Otherwise, take the damage */
2715                                 else
2716                                 {
2717                                         if (r_ptr->flags3 & RF3_HURT_COLD)
2718                                         {
2719                                                 if (mult < 25) mult = 25;
2720                                                 if (is_original_ap_and_seen(m_ptr))
2721                                                 {
2722                                                         r_ptr->r_flags3 |= RF3_HURT_COLD;
2723                                                 }
2724                                         }
2725                                         else if (mult < 17) mult = 17;
2726                                 }
2727                         }
2728
2729                         /* Brand (Poison) */
2730                         if (have_flag(flgs, TR_BRAND_POIS))
2731                         {
2732                                 /* Notice immunity */
2733                                 if (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)
2734                                 {
2735                                         if (is_original_ap_and_seen(m_ptr))
2736                                         {
2737                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK);
2738                                         }
2739                                 }
2740
2741                                 /* Otherwise, take the damage */
2742                                 else
2743                                 {
2744                                         if (mult < 17) mult = 17;
2745                                 }
2746                         }
2747
2748                         if ((have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (p_ptr->msp / 30)))
2749                         {
2750                                 p_ptr->csp -= (1+(p_ptr->msp / 30));
2751                                 p_ptr->redraw |= (PR_MANA);
2752                                 mult = mult * 5 / 2;
2753                         }
2754                         break;
2755                 }
2756         }
2757
2758         /* Sniper */
2759         if (snipe_type) mult = tot_dam_aux_snipe(mult, m_ptr);
2760
2761         /* Return the total damage */
2762         return (tdam * mult / 10);
2763 }
2764
2765
2766 /*!
2767  * @brief 射撃処理のサブルーチン /
2768  * Fire an object from the pack or floor.
2769  * @param item 射撃するオブジェクトの所持ID
2770  * @param j_ptr 射撃武器のオブジェクト参照ポインタ
2771  * @return なし
2772  * @details
2773  * <pre>
2774  * You may only fire items that "match" your missile launcher.
2775  *
2776  * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
2777  *
2778  * See "calc_bonuses()" for more calculations and such.
2779  *
2780  * Note that "firing" a missile is MUCH better than "throwing" it.
2781  *
2782  * Note: "unseen" monsters are very hard to hit.
2783  *
2784  * Objects are more likely to break if they "attempt" to hit a monster.
2785  *
2786  * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
2787  *
2788  * The "extra shot" code works by decreasing the amount of energy
2789  * required to make each shot, spreading the shots out over time.
2790  *
2791  * Note that when firing missiles, the launcher multiplier is applied
2792  * after all the bonuses are added in, making multipliers very useful.
2793  *
2794  * Note that Bows of "Extra Might" get extra range and an extra bonus
2795  * for the damage multiplier.
2796  *
2797  * Note that Bows of "Extra Shots" give an extra shot.
2798  * </pre>
2799  */
2800 void do_cmd_fire_aux(INVENTORY_IDX item, object_type *j_ptr)
2801 {
2802         DIRECTION dir;
2803         int i;
2804         POSITION y, x, ny, nx, ty, tx, prev_y, prev_x;
2805         int tdam_base, tdis, thits, tmul;
2806         int bonus, chance;
2807         int cur_dis, visible;
2808         PERCENTAGE j;
2809
2810         object_type forge;
2811         object_type *q_ptr;
2812
2813         object_type *o_ptr;
2814
2815         bool hit_body = FALSE;
2816
2817         char o_name[MAX_NLEN];
2818
2819         u16b path_g[512];       /* For calcuration of path length */
2820
2821         int msec = delay_factor * delay_factor * delay_factor;
2822
2823         /* STICK TO */
2824         bool stick_to = FALSE;
2825
2826         /* Access the item (if in the pack) */
2827         if (item >= 0)
2828         {
2829                 o_ptr = &inventory[item];
2830         }
2831         else
2832         {
2833                 o_ptr = &o_list[0 - item];
2834         }
2835
2836         /* Sniper - Cannot shot a single arrow twice */
2837         if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2)) snipe_type = SP_NONE;
2838
2839         /* Describe the object */
2840         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
2841
2842         /* Use the proper number of shots */
2843         thits = p_ptr->num_fire;
2844
2845         /* Use a base distance */
2846         tdis = 10;
2847
2848         /* Base damage from thrown object plus launcher bonus */
2849         tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
2850
2851         /* Actually "fire" the object */
2852         bonus = (p_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
2853         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
2854                 chance = (p_ptr->skill_thb + (p_ptr->weapon_exp[0][j_ptr->sval] / 400 + bonus) * BTH_PLUS_ADJ);
2855         else
2856                 chance = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
2857
2858         p_ptr->energy_use = bow_energy(j_ptr->sval);
2859         tmul = bow_tmul(j_ptr->sval);
2860
2861         /* Get extra "power" from "extra might" */
2862         if (p_ptr->xtra_might) tmul++;
2863
2864         tmul = tmul * (100 + (int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
2865
2866         /* Boost the damage */
2867         tdam_base *= tmul;
2868         tdam_base /= 100;
2869
2870         /* Base range */
2871         tdis = 13 + tmul/80;
2872         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
2873         {
2874                 if (p_ptr->concent)
2875                         tdis -= (5 - (p_ptr->concent + 1) / 2);
2876                 else
2877                         tdis -= 5;
2878         }
2879
2880         project_length = tdis + 1;
2881
2882         /* Get a direction (or cancel) */
2883         if (!get_aim_dir(&dir))
2884         {
2885                 p_ptr->energy_use = 0;
2886
2887                 if (snipe_type == SP_AWAY) snipe_type = SP_NONE;
2888
2889                 /* need not to reset project_length (already did)*/
2890
2891                 return;
2892         }
2893
2894         /* Predict the "target" location */
2895         tx = p_ptr->x + 99 * ddx[dir];
2896         ty = p_ptr->y + 99 * ddy[dir];
2897
2898         /* Check for "target request" */
2899         if ((dir == 5) && target_okay())
2900         {
2901                 tx = target_col;
2902                 ty = target_row;
2903         }
2904
2905         /* Get projection path length */
2906         tdis = project_path(path_g, project_length, p_ptr->y, p_ptr->x, ty, tx, PROJECT_PATH|PROJECT_THRU) - 1;
2907
2908         project_length = 0; /* reset to default */
2909
2910         /* Don't shoot at my feet */
2911         if (tx == p_ptr->x && ty == p_ptr->y)
2912         {
2913                 p_ptr->energy_use = 0;
2914
2915                 /* project_length is already reset to 0 */
2916
2917                 return;
2918         }
2919
2920
2921         /* Take a (partial) turn */
2922         p_ptr->energy_use = (p_ptr->energy_use / thits);
2923         is_fired = TRUE;
2924
2925         /* Sniper - Difficult to shot twice at 1 turn */
2926         if (snipe_type == SP_DOUBLE)  p_ptr->concent = (p_ptr->concent + 1) / 2;
2927
2928         /* Sniper - Repeat shooting when double shots */
2929         for (i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++)
2930         {
2931
2932         /* Start at the player */
2933         y = p_ptr->y;
2934         x = p_ptr->x;
2935
2936         /* Get local object */
2937         q_ptr = &forge;
2938
2939         /* Obtain a local object */
2940         object_copy(q_ptr, o_ptr);
2941
2942         /* Single object */
2943         q_ptr->number = 1;
2944
2945         /* Reduce and describe inventory */
2946         if (item >= 0)
2947         {
2948                 inven_item_increase(item, -1);
2949                 inven_item_describe(item);
2950                 inven_item_optimize(item);
2951         }
2952
2953         /* Reduce and describe floor item */
2954         else
2955         {
2956                 floor_item_increase(0 - item, -1);
2957                 floor_item_optimize(0 - item);
2958         }
2959
2960         sound(SOUND_SHOOT);
2961
2962         /* Hack -- Handle stuff */
2963         handle_stuff();
2964
2965         /* Save the old location */
2966         prev_y = y;
2967         prev_x = x;
2968
2969         /* The shot does not hit yet */
2970         hit_body = FALSE;
2971
2972         /* Travel until stopped */
2973         for (cur_dis = 0; cur_dis <= tdis; )
2974         {
2975                 cave_type *c_ptr;
2976
2977                 /* Hack -- Stop at the target */
2978                 if ((y == ty) && (x == tx)) break;
2979
2980                 /* Calculate the new location (see "project()") */
2981                 ny = y;
2982                 nx = x;
2983                 mmove2(&ny, &nx, p_ptr->y, p_ptr->x, ty, tx);
2984
2985                 /* Shatter Arrow */
2986                 if (snipe_type == SP_KILL_WALL)
2987                 {
2988                         c_ptr = &cave[ny][nx];
2989
2990                         if (cave_have_flag_grid(c_ptr, FF_HURT_ROCK) && !c_ptr->m_idx)
2991                         {
2992                                 if (c_ptr->info & (CAVE_MARK)) msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
2993                                 /* Forget the wall */
2994                                 c_ptr->info &= ~(CAVE_MARK);
2995
2996                                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
2997
2998                                 /* Destroy the wall */
2999                                 cave_alter_feat(ny, nx, FF_HURT_ROCK);
3000
3001                                 hit_body = TRUE;
3002                                 break;
3003                         }
3004                 }
3005
3006                 /* Stopped by walls/doors */
3007                 if (!cave_have_flag_bold(ny, nx, FF_PROJECT) && !cave[ny][nx].m_idx) break;
3008
3009                 /* Advance the distance */
3010                 cur_dis++;
3011
3012                 /* Sniper */
3013                 if (snipe_type == SP_LITE)
3014                 {
3015                         cave[ny][nx].info |= (CAVE_GLOW);
3016
3017                         /* Notice */
3018                         note_spot(ny, nx);
3019
3020                         /* Redraw */
3021                         lite_spot(ny, nx);
3022                 }
3023
3024                 /* The player can see the (on screen) missile */
3025                 if (panel_contains(ny, nx) && player_can_see_bold(ny, nx))
3026                 {
3027                         char c = object_char(q_ptr);
3028                         byte a = object_attr(q_ptr);
3029
3030                         /* Draw, Hilite, Fresh, Pause, Erase */
3031                         print_rel(c, a, ny, nx);
3032                         move_cursor_relative(ny, nx);
3033                         Term_fresh();
3034                         Term_xtra(TERM_XTRA_DELAY, msec);
3035                         lite_spot(ny, nx);
3036                         Term_fresh();
3037                 }
3038
3039                 /* The player cannot see the missile */
3040                 else
3041                 {
3042                         /* Pause anyway, for consistancy */
3043                         Term_xtra(TERM_XTRA_DELAY, msec);
3044                 }
3045
3046                 /* Sniper */
3047                 if (snipe_type == SP_KILL_TRAP)
3048                 {
3049                         project(0, 0, ny, nx, 0, GF_KILL_TRAP,
3050                                 (PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM), -1);
3051                 }
3052
3053                 /* Sniper */
3054                 if (snipe_type == SP_EVILNESS)
3055                 {
3056                         cave[ny][nx].info &= ~(CAVE_GLOW | CAVE_MARK);
3057
3058                         /* Notice */
3059                         note_spot(ny, nx);
3060
3061                         /* Redraw */
3062                         lite_spot(ny, nx);
3063                 }
3064
3065                 /* Save the old location */
3066                 prev_y = y;
3067                 prev_x = x;
3068
3069                 /* Save the new location */
3070                 x = nx;
3071                 y = ny;
3072
3073
3074                 /* Monster here, Try to hit it */
3075                 if (cave[y][x].m_idx)
3076                 {
3077                         cave_type *c_mon_ptr = &cave[y][x];
3078
3079                         monster_type *m_ptr = &m_list[c_mon_ptr->m_idx];
3080                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
3081
3082                         /* Check the visibility */
3083                         visible = m_ptr->ml;
3084
3085                         /* Note the collision */
3086                         hit_body = TRUE;
3087
3088                         if (MON_CSLEEP(m_ptr))
3089                         {
3090                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_COMPASSION, -1);
3091                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_HONOUR, -1);
3092                         }
3093
3094                         if ((r_ptr->level + 10) > p_ptr->lev)
3095                         {
3096                                 int now_exp = p_ptr->weapon_exp[0][j_ptr->sval];
3097                                 if (now_exp < s_info[p_ptr->pclass].w_max[0][j_ptr->sval])
3098                                 {
3099                                         SUB_EXP amount = 0;
3100                                         if (now_exp < WEAPON_EXP_BEGINNER) amount = 80;
3101                                         else if (now_exp < WEAPON_EXP_SKILLED) amount = 25;
3102                                         else if ((now_exp < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19)) amount = 10;
3103                                         else if (p_ptr->lev > 34) amount = 2;
3104                                         p_ptr->weapon_exp[0][j_ptr->sval] += amount;
3105                                         p_ptr->update |= (PU_BONUS);
3106                                 }
3107                         }
3108
3109                         if (p_ptr->riding)
3110                         {
3111                                 if ((p_ptr->skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING])
3112                                         && ((p_ptr->skill_exp[GINOU_RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 < r_info[m_list[p_ptr->riding].r_idx].level)
3113                                         && one_in_(2))
3114                                 {
3115                                         p_ptr->skill_exp[GINOU_RIDING] += 1;
3116                                         p_ptr->update |= (PU_BONUS);
3117                                 }
3118                         }
3119
3120                         /* Did we hit it (penalize range) */
3121                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
3122                         {
3123                                 bool fear = FALSE;
3124                                 int tdam = tdam_base;
3125
3126                                 /* Get extra damage from concentration */
3127                                 if (p_ptr->concent) tdam = boost_concentration_damage(tdam);
3128
3129                                 /* Handle unseen monster */
3130                                 if (!visible)
3131                                 {
3132                                         /* Invisible monster */
3133                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
3134                                 }
3135
3136                                 /* Handle visible monster */
3137                                 else
3138                                 {
3139                                         char m_name[80];
3140
3141                                         /* Get "the monster" or "it" */
3142                                         monster_desc(m_name, m_ptr, 0);
3143
3144                                         /* Message */
3145                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
3146
3147                                         if (m_ptr->ml)
3148                                         {
3149                                                 /* Hack -- Track this monster race */
3150                                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
3151
3152                                                 /* Hack -- Track this monster */
3153                                                 health_track(c_mon_ptr->m_idx);
3154                                         }
3155                                 }
3156
3157                                 if (snipe_type == SP_NEEDLE)
3158                                 {
3159                                         if ((randint1(randint1(r_ptr->level / (3 + p_ptr->concent)) + (8 - p_ptr->concent)) == 1)
3160                                                 && !(r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_UNIQUE2))
3161                                         {
3162                                                 char m_name[80];
3163
3164                                                 /* Get "the monster" or "it" */
3165                                                 monster_desc(m_name, m_ptr, 0);
3166
3167                                                 tdam = m_ptr->hp + 1;
3168                                                 msg_format(_("%sの急所に突き刺さった!", "Your shot sticked on a fatal spot of %s!"), m_name);
3169                                         }
3170                                         else tdam = 1;
3171                                 }
3172                                 else
3173                                 {
3174                                         /* Apply special damage XXX XXX XXX */
3175                                         tdam = tot_dam_aux_shot(q_ptr, tdam, m_ptr);
3176                                         tdam = critical_shot(q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
3177
3178                                         /* No negative damage */
3179                                         if (tdam < 0) tdam = 0;
3180
3181                                         /* Modify the damage */
3182                                         tdam = mon_damage_mod(m_ptr, tdam, FALSE);
3183                                 }
3184
3185                                 msg_format_wizard(CHEAT_MONSTER,
3186                                         _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
3187                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
3188
3189                                 /* Sniper */
3190                                 if (snipe_type == SP_EXPLODE)
3191                                 {
3192                                         u16b flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
3193
3194                                         sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
3195                                         project(0, ((p_ptr->concent + 1) / 2 + 1), ny, nx, tdam, GF_MISSILE, flg, -1);
3196                                         break;
3197                                 }
3198
3199                                 /* Sniper */
3200                                 if (snipe_type == SP_HOLYNESS)
3201                                 {
3202                                         cave[ny][nx].info |= (CAVE_GLOW);
3203
3204                                         /* Notice */
3205                                         note_spot(ny, nx);
3206
3207                                         /* Redraw */
3208                                         lite_spot(ny, nx);
3209                                 }
3210
3211                                 /* Hit the monster, check for death */
3212                                 if (mon_take_hit(c_mon_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
3213                                 {
3214                                         /* Dead monster */
3215                                 }
3216
3217                                 /* No death */
3218                                 else
3219                                 {
3220                                         /* STICK TO */
3221                                         if (object_is_fixed_artifact(q_ptr) &&
3222                                                 (p_ptr->pclass != CLASS_SNIPER || p_ptr->concent == 0))
3223                                         {
3224                                                 char m_name[80];
3225
3226                                                 monster_desc(m_name, m_ptr, 0);
3227
3228                                                 stick_to = TRUE;
3229                                                 msg_format(_("%sは%sに突き刺さった!", "%^s have stuck into %s!"),o_name, m_name);
3230                                         }
3231
3232                                         /* Message */
3233                                         message_pain(c_mon_ptr->m_idx, tdam);
3234
3235                                         /* Anger the monster */
3236                                         if (tdam > 0) anger_monster(m_ptr);
3237
3238                                         /* Take note */
3239                                         if (fear && m_ptr->ml)
3240                                         {
3241                                                 char m_name[80];
3242
3243                                                 sound(SOUND_FLEE);
3244
3245                                                 /* Get the monster name (or "it") */
3246                                                 monster_desc(m_name, m_ptr, 0);
3247
3248                                                 /* Message */
3249                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
3250                                         }
3251
3252                                         set_target(m_ptr, p_ptr->y, p_ptr->x);
3253
3254                                         /* Sniper */
3255                                         if (snipe_type == SP_RUSH)
3256                                         {
3257                                                 int n = randint1(5) + 3;
3258                                                 MONSTER_IDX m_idx = c_mon_ptr->m_idx;
3259
3260                                                 for ( ; cur_dis <= tdis; )
3261                                                 {
3262                                                         POSITION ox = nx;
3263                                                         POSITION oy = ny;
3264
3265                                                         if (!n) break;
3266
3267                                                         /* Calculate the new location (see "project()") */
3268                                                         mmove2(&ny, &nx, p_ptr->y, p_ptr->x, ty, tx);
3269
3270                                                         /* Stopped by wilderness boundary */
3271                                                         if (!in_bounds2(ny, nx)) break;
3272
3273                                                         /* Stopped by walls/doors */
3274                                                         if (!player_can_enter(cave[ny][nx].feat, 0)) break;
3275
3276                                                         /* Stopped by monsters */
3277                                                         if (!cave_empty_bold(ny, nx)) break;
3278
3279                                                         cave[ny][nx].m_idx = m_idx;
3280                                                         cave[oy][ox].m_idx = 0;
3281
3282                                                         m_ptr->fx = nx;
3283                                                         m_ptr->fy = ny;
3284
3285                                                         /* Update the monster (new location) */
3286                                                         update_mon(c_mon_ptr->m_idx, TRUE);
3287
3288                                                         lite_spot(ny, nx);
3289                                                         lite_spot(oy, ox);
3290
3291                                                         Term_fresh();
3292                                                         Term_xtra(TERM_XTRA_DELAY, msec);
3293
3294                                                         x = nx;
3295                                                         y = ny;
3296                                                         cur_dis++;
3297                                                         n--;
3298                                                 }
3299                                         }
3300                                 }
3301                         }
3302
3303                         /* Sniper */
3304                         if (snipe_type == SP_PIERCE)
3305                         {
3306                                 if(p_ptr->concent < 1) break;
3307                                 p_ptr->concent--;
3308                                 continue;
3309                         }
3310
3311                         /* Stop looking */
3312                         break;
3313                 }
3314         }
3315
3316         /* Chance of breakage (during attacks) */
3317         j = (hit_body ? breakage_chance(q_ptr) : 0);
3318
3319         if (stick_to)
3320         {
3321                 MONSTER_IDX m_idx = cave[y][x].m_idx;
3322                 monster_type *m_ptr = &m_list[m_idx];
3323                 OBJECT_IDX o_idx = o_pop();
3324
3325                 if (!o_idx)
3326                 {
3327                         msg_format(_("%sはどこかへ行った。", "The %s have gone to somewhere."), o_name);
3328                         if (object_is_fixed_artifact(q_ptr))
3329                         {
3330                                 a_info[j_ptr->name1].cur_num = 0;
3331                         }
3332                         return;
3333                 }
3334
3335                 o_ptr = &o_list[o_idx];
3336                 object_copy(o_ptr, q_ptr);
3337
3338                 /* Forget mark */
3339                 o_ptr->marked &= OM_TOUCHED;
3340
3341                 /* Forget location */
3342                 o_ptr->iy = o_ptr->ix = 0;
3343
3344                 /* Memorize monster */
3345                 o_ptr->held_m_idx = m_idx;
3346
3347                 /* Build a stack */
3348                 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3349
3350                 /* Carry object */
3351                 m_ptr->hold_o_idx = o_idx;
3352         }
3353         else if (cave_have_flag_bold(y, x, FF_PROJECT))
3354         {
3355                 /* Drop (or break) near that location */
3356                 (void)drop_near(q_ptr, j, y, x);
3357         }
3358         else
3359         {
3360                 /* Drop (or break) near that location */
3361                 (void)drop_near(q_ptr, j, prev_y, prev_x);
3362         }
3363
3364         /* Sniper - Repeat shooting when double shots */
3365         }
3366
3367         /* Sniper - Loose his/her concentration after any shot */
3368         if (p_ptr->concent) reset_concentration(FALSE);
3369 }
3370
3371 /*!
3372  * @brief 射撃処理のメインルーチン
3373  * @return なし
3374  */
3375 void do_cmd_fire(void)
3376 {
3377         OBJECT_IDX item;
3378         object_type *j_ptr;
3379         cptr q, s;
3380
3381         is_fired = FALSE;       /* not fired yet */
3382
3383         /* Get the "bow" (if any) */
3384         j_ptr = &inventory[INVEN_BOW];
3385
3386         /* Require a launcher */
3387         if (!j_ptr->tval)
3388         {
3389                 msg_print(_("射撃用の武器を持っていない。", "You have nothing to fire with."));
3390                 flush();
3391                 return;
3392         }
3393
3394         if (j_ptr->sval == SV_CRIMSON)
3395         {
3396                 msg_print(_("この武器は発動して使うもののようだ。", "Do activate."));
3397                 flush();
3398                 return;
3399         }
3400
3401         if (j_ptr->sval == SV_HARP)
3402         {
3403                 msg_print(_("この武器で射撃はできない。", "It's not for firing."));
3404                 flush();
3405                 return;
3406         }
3407
3408
3409         if (p_ptr->special_defense & KATA_MUSOU)
3410         {
3411                 set_action(ACTION_NONE);
3412         }
3413
3414         /* Require proper missile */
3415         item_tester_tval = p_ptr->tval_ammo;
3416
3417         /* Get an item */
3418         q = _("どれを撃ちますか? ", "Fire which item? ");
3419         s = _("発射されるアイテムがありません。", "You have nothing to fire.");
3420         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
3421         {
3422                 flush();
3423                 return;
3424         }
3425
3426         /* Fire the item */
3427         do_cmd_fire_aux(item, j_ptr);
3428
3429         if (!is_fired || p_ptr->pclass != CLASS_SNIPER) return;
3430
3431         /* Sniper actions after some shootings */
3432         if (snipe_type == SP_AWAY)
3433         {
3434                 teleport_player(10 + (p_ptr->concent * 2), 0L);
3435         }
3436         if (snipe_type == SP_FINAL)
3437         {
3438                 msg_print(_("射撃の反動が体を襲った。", "A reactionary of shooting attacked you. "));
3439                 (void)set_slow(p_ptr->slow + randint0(7) + 7, FALSE);
3440                 (void)set_stun(p_ptr->stun + randint1(25));
3441         }
3442 }
3443
3444
3445 /*!
3446  * @brief 投射処理メインルーチン /
3447  * Throw an object from the pack or floor.
3448  * @param mult 威力の倍率
3449  * @param boomerang ブーメラン処理ならばTRUE
3450  * @param shuriken 忍者の手裏剣処理ならばTRUE
3451  * @return ターンを消費した場合TRUEを返す
3452  * @details
3453  * <pre>
3454  * Note: "unseen" monsters are very hard to hit.
3455  *
3456  * Should throwing a weapon do full damage?  Should it allow the magic
3457  * to hit bonus of the weapon to have an effect?  Should it ever cause
3458  * the item to be destroyed?  Should it do any damage at all?
3459  * </pre>
3460  */
3461 bool do_cmd_throw(int mult, bool boomerang, OBJECT_IDX shuriken)
3462 {
3463         DIRECTION dir;
3464         OBJECT_IDX item;
3465         int i;
3466         POSITION y, x, ty, tx, prev_y, prev_x;
3467         POSITION ny[19], nx[19];
3468         int chance, tdam, tdis;
3469         int mul, div, dd, ds;
3470         int cur_dis, visible;
3471         PERCENTAGE j;
3472
3473         object_type forge;
3474         object_type *q_ptr;
3475
3476         object_type *o_ptr;
3477
3478         bool hit_body = FALSE;
3479         bool hit_wall = FALSE;
3480         bool equiped_item = FALSE;
3481         bool return_when_thrown = FALSE;
3482
3483         char o_name[MAX_NLEN];
3484
3485         int msec = delay_factor * delay_factor * delay_factor;
3486
3487         BIT_FLAGS flgs[TR_FLAG_SIZE];
3488         cptr q, s;
3489         bool come_back = FALSE;
3490         bool do_drop = TRUE;
3491
3492
3493         if (p_ptr->special_defense & KATA_MUSOU)
3494         {
3495                 set_action(ACTION_NONE);
3496         }
3497
3498         if (shuriken >= 0)
3499         {
3500                 item = shuriken;
3501         }
3502         else if (boomerang)
3503         {
3504                 if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
3505                 {
3506                         item_tester_hook = item_tester_hook_boomerang;
3507                         q = _("どの武器を投げますか? ", "Throw which item? ");
3508                         s = _("投げる武器がない。", "You have nothing to throw.");
3509                         if (!get_item(&item, q, s, (USE_EQUIP)))
3510                         {
3511                                 flush();
3512                                 return FALSE;
3513                         }
3514                 }
3515                 else if (buki_motteruka(INVEN_LARM)) item = INVEN_LARM;
3516                 else item = INVEN_RARM;
3517         }
3518         else
3519         {
3520                 /* Get an item */
3521                 q = _("どのアイテムを投げますか? ", "Throw which item? ");
3522                 s = _("投げるアイテムがない。", "You have nothing to throw.");
3523                 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP)))
3524                 {
3525                         flush();
3526                         return FALSE;
3527                 }
3528         }
3529
3530         /* Access the item (if in the pack) */
3531         if (item >= 0)
3532         {
3533                 o_ptr = &inventory[item];
3534         }
3535         else
3536         {
3537                 o_ptr = &o_list[0 - item];
3538         }
3539
3540
3541         /* Item is cursed */
3542         if (object_is_cursed(o_ptr) && (item >= INVEN_RARM))
3543         {
3544                 /* Oops */
3545                 msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
3546
3547                 /* Nope */
3548                 return FALSE;
3549         }
3550
3551         if (p_ptr->inside_arena && !boomerang)
3552         {
3553                 if (o_ptr->tval != TV_SPIKE)
3554                 {
3555                         msg_print(_("アリーナではアイテムを使えない!", "You're in the arena now. This is hand-to-hand!"));
3556                         msg_print(NULL);
3557
3558                         /* Nope */
3559                         return FALSE;
3560                 }
3561
3562         }
3563
3564         /* Get local object */
3565         q_ptr = &forge;
3566
3567         /* Obtain a local object */
3568         object_copy(q_ptr, o_ptr);
3569
3570         /* Extract the thrown object's flags. */
3571         object_flags(q_ptr, flgs);
3572         torch_flags(q_ptr, flgs);
3573
3574         /* Distribute the charges of rods/wands between the stacks */
3575         distribute_charges(o_ptr, q_ptr, 1);
3576
3577         /* Single object */
3578         q_ptr->number = 1;
3579
3580         /* Description */
3581         object_desc(o_name, q_ptr, OD_OMIT_PREFIX);
3582
3583         if (p_ptr->mighty_throw) mult += 3;
3584
3585         /* Extract a "distance multiplier" */
3586         /* Changed for 'launcher' mutation */
3587         mul = 10 + 2 * (mult - 1);
3588
3589         /* Enforce a minimum "weight" of one pound */
3590         div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
3591         if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
3592
3593         /* Hack -- Distance -- Reward strength, penalize weight */
3594         tdis = (adj_str_blow[p_ptr->stat_ind[A_STR]] + 20) * mul / div;
3595
3596         /* Max distance of 10-18 */
3597         if (tdis > mul) tdis = mul;
3598
3599         if (shuriken >= 0)
3600         {
3601                 ty = randint0(101) - 50 + p_ptr->y;
3602                 tx = randint0(101) - 50 + p_ptr->x;
3603         }
3604         else
3605         {
3606                 project_length = tdis + 1;
3607
3608                 /* Get a direction (or cancel) */
3609                 if (!get_aim_dir(&dir)) return FALSE;
3610
3611                 /* Predict the "target" location */
3612                 tx = p_ptr->x + 99 * ddx[dir];
3613                 ty = p_ptr->y + 99 * ddy[dir];
3614
3615                 /* Check for "target request" */
3616                 if ((dir == 5) && target_okay())
3617                 {
3618                         tx = target_col;
3619                         ty = target_row;
3620                 }
3621
3622                 project_length = 0;  /* reset to default */
3623         }
3624
3625         if ((q_ptr->name1 == ART_MJOLLNIR) ||
3626             (q_ptr->name1 == ART_AEGISFANG) || boomerang)
3627                 return_when_thrown = TRUE;
3628
3629         /* Reduce and describe inventory */
3630         if (item >= 0)
3631         {
3632                 inven_item_increase(item, -1);
3633                 if (!return_when_thrown)
3634                         inven_item_describe(item);
3635                 inven_item_optimize(item);
3636         }
3637
3638         /* Reduce and describe floor item */
3639         else
3640         {
3641                 floor_item_increase(0 - item, -1);
3642                 floor_item_optimize(0 - item);
3643         }
3644         if (item >= INVEN_RARM)
3645         {
3646                 equiped_item = TRUE;
3647                 p_ptr->redraw |= (PR_EQUIPPY);
3648         }
3649
3650         p_ptr->energy_use = 100;
3651
3652         /* Rogue and Ninja gets bonus */
3653         if ((p_ptr->pclass == CLASS_ROGUE) || (p_ptr->pclass == CLASS_NINJA))
3654                 p_ptr->energy_use -= p_ptr->lev;
3655
3656         /* Start at the player */
3657         y = p_ptr->y;
3658         x = p_ptr->x;
3659
3660
3661         /* Hack -- Handle stuff */
3662         handle_stuff();
3663
3664         if ((p_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
3665         else shuriken = FALSE;
3666
3667         /* Chance of hitting */
3668         if (have_flag(flgs, TR_THROW)) chance = ((p_ptr->skill_tht) +
3669                 ((p_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
3670         else chance = (p_ptr->skill_tht + (p_ptr->to_h_b * BTH_PLUS_ADJ));
3671
3672         if (shuriken) chance *= 2;
3673
3674         /* Save the old location */
3675         prev_y = y;
3676         prev_x = x;
3677
3678         /* Travel until stopped */
3679         for (cur_dis = 0; cur_dis <= tdis; )
3680         {
3681                 /* Hack -- Stop at the target */
3682                 if ((y == ty) && (x == tx)) break;
3683
3684                 /* Calculate the new location (see "project()") */
3685                 ny[cur_dis] = y;
3686                 nx[cur_dis] = x;
3687                 mmove2(&ny[cur_dis], &nx[cur_dis], p_ptr->y, p_ptr->x, ty, tx);
3688
3689                 /* Stopped by walls/doors */
3690                 if (!cave_have_flag_bold(ny[cur_dis], nx[cur_dis], FF_PROJECT))
3691                 {
3692                         hit_wall = TRUE;
3693                         if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !cave[ny[cur_dis]][nx[cur_dis]].m_idx) break;
3694                 }
3695
3696                 /* The player can see the (on screen) missile */
3697                 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(ny[cur_dis], nx[cur_dis]))
3698                 {
3699                         char c = object_char(q_ptr);
3700                         byte a = object_attr(q_ptr);
3701
3702                         /* Draw, Hilite, Fresh, Pause, Erase */
3703                         print_rel(c, a, ny[cur_dis], nx[cur_dis]);
3704                         move_cursor_relative(ny[cur_dis], nx[cur_dis]);
3705                         Term_fresh();
3706                         Term_xtra(TERM_XTRA_DELAY, msec);
3707                         lite_spot(ny[cur_dis], nx[cur_dis]);
3708                         Term_fresh();
3709                 }
3710
3711                 /* The player cannot see the missile */
3712                 else
3713                 {
3714                         /* Pause anyway, for consistancy */
3715                         Term_xtra(TERM_XTRA_DELAY, msec);
3716                 }
3717
3718                 /* Save the old location */
3719                 prev_y = y;
3720                 prev_x = x;
3721
3722                 /* Save the new location */
3723                 x = nx[cur_dis];
3724                 y = ny[cur_dis];
3725
3726                 /* Advance the distance */
3727                 cur_dis++;
3728
3729                 /* Monster here, Try to hit it */
3730                 if (cave[y][x].m_idx)
3731                 {
3732                         cave_type *c_ptr = &cave[y][x];
3733                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
3734
3735                         /* Check the visibility */
3736                         visible = m_ptr->ml;
3737
3738                         /* Note the collision */
3739                         hit_body = TRUE;
3740
3741                         /* Did we hit it (penalize range) */
3742                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
3743                         {
3744                                 bool fear = FALSE;
3745
3746                                 /* Handle unseen monster */
3747                                 if (!visible)
3748                                 {
3749                                         /* Invisible monster */
3750                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
3751                                 }
3752
3753                                 /* Handle visible monster */
3754                                 else
3755                                 {
3756                                         char m_name[80];
3757
3758                                         /* Get "the monster" or "it" */
3759                                         monster_desc(m_name, m_ptr, 0);
3760
3761                                         /* Message */
3762                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
3763
3764                                         if (m_ptr->ml)
3765                                         {
3766                                                 /* Hack -- Track this monster race */
3767                                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
3768
3769                                                 /* Hack -- Track this monster */
3770                                                 health_track(c_ptr->m_idx);
3771                                         }
3772                                 }
3773
3774                                 /* Hack -- Base damage from thrown object */
3775                                 dd = q_ptr->dd;
3776                                 ds = q_ptr->ds;
3777                                 torch_dice(q_ptr, &dd, &ds); /* throwing a torch */
3778                                 tdam = damroll(dd, ds);
3779                                 /* Apply special damage XXX XXX XXX */
3780                                 tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0, TRUE);
3781                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, 0, tdam);
3782                                 if (q_ptr->to_d > 0)
3783                                         tdam += q_ptr->to_d;
3784                                 else
3785                                         tdam += -q_ptr->to_d;
3786
3787                                 if (boomerang)
3788                                 {
3789                                         tdam *= (mult+p_ptr->num_blow[item - INVEN_RARM]);
3790                                         tdam += p_ptr->to_d_m;
3791                                 }
3792                                 else if (have_flag(flgs, TR_THROW))
3793                                 {
3794                                         tdam *= (3+mult);
3795                                         tdam += p_ptr->to_d_m;
3796                                 }
3797                                 else
3798                                 {
3799                                         tdam *= mult;
3800                                 }
3801                                 if (shuriken)
3802                                 {
3803                                         tdam += ((p_ptr->lev+30)*(p_ptr->lev+30)-900)/55;
3804                                 }
3805
3806                                 /* No negative damage */
3807                                 if (tdam < 0) tdam = 0;
3808
3809                                 /* Modify the damage */
3810                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
3811
3812                                 msg_format_wizard(CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
3813                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
3814
3815                                 /* Hit the monster, check for death */
3816                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
3817                                 {
3818                                         /* Dead monster */
3819                                 }
3820
3821                                 /* No death */
3822                                 else
3823                                 {
3824                                         /* Message */
3825                                         message_pain(c_ptr->m_idx, tdam);
3826
3827                                         /* Anger the monster */
3828                                         if ((tdam > 0) && !object_is_potion(q_ptr))
3829                                                 anger_monster(m_ptr);
3830
3831                                         /* Take note */
3832                                         if (fear && m_ptr->ml)
3833                                         {
3834                                                 char m_name[80];
3835
3836                                                 sound(SOUND_FLEE);
3837
3838                                                 /* Get the monster name (or "it") */
3839                                                 monster_desc(m_name, m_ptr, 0);
3840
3841                                                 /* Message */
3842                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
3843                                         }
3844                                 }
3845                         }
3846
3847                         /* Stop looking */
3848                         break;
3849                 }
3850         }
3851
3852         /* decrease toach's fuel */
3853         if (hit_body) torch_lost_fuel(q_ptr);
3854
3855         /* Chance of breakage (during attacks) */
3856         j = (hit_body ? breakage_chance(q_ptr) : 0);
3857
3858         /* Figurines transform */
3859         if ((q_ptr->tval == TV_FIGURINE) && !(p_ptr->inside_arena))
3860         {
3861                 j = 100;
3862
3863                 if (!(summon_named_creature(0, y, x, q_ptr->pval,
3864                                             !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
3865                         msg_print(_("人形は捻じ曲がり砕け散ってしまった!", "The Figurine writhes and then shatters."));
3866                 else if (object_is_cursed(q_ptr))
3867                         msg_print(_("これはあまり良くない気がする。", "You have a bad feeling about this."));
3868
3869         }
3870
3871
3872         /* Potions smash open */
3873         if (object_is_potion(q_ptr))
3874         {
3875                 if (hit_body || hit_wall || (randint1(100) < j))
3876                 {
3877                         /* Message */
3878                         msg_format(_("%sは砕け散った!", "The %s shatters!"), o_name);
3879
3880                         if (potion_smash_effect(0, y, x, q_ptr->k_idx))
3881                         {
3882                                 monster_type *m_ptr = &m_list[cave[y][x].m_idx];
3883
3884                                 /* ToDo (Robert): fix the invulnerability */
3885                                 if (cave[y][x].m_idx &&
3886                                     is_friendly(&m_list[cave[y][x].m_idx]) &&
3887                                     !MON_INVULNER(m_ptr))
3888                                 {
3889                                         char m_name[80];
3890                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
3891                                         msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
3892                                         set_hostile(&m_list[cave[y][x].m_idx]);
3893                                 }
3894                         }
3895                         do_drop = FALSE;
3896                 }
3897                 else
3898                 {
3899                         j = 0;
3900                 }
3901         }
3902
3903         if (return_when_thrown)
3904         {
3905                 int back_chance = randint1(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
3906                 char o2_name[MAX_NLEN];
3907                 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
3908
3909                 j = -1;
3910                 if (boomerang) back_chance += 4+randint1(5);
3911                 if (super_boomerang) back_chance += 100;
3912                 object_desc(o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3913
3914                 if((back_chance > 30) && (!one_in_(100) || super_boomerang))
3915                 {
3916                         for (i = cur_dis - 1; i > 0; i--)
3917                         {
3918                                 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(ny[i], nx[i]))
3919                                 {
3920                                         char c = object_char(q_ptr);
3921                                         byte a = object_attr(q_ptr);
3922
3923                                         /* Draw, Hilite, Fresh, Pause, Erase */
3924                                         print_rel(c, a, ny[i], nx[i]);
3925                                         move_cursor_relative(ny[i], nx[i]);
3926                                         Term_fresh();
3927                                         Term_xtra(TERM_XTRA_DELAY, msec);
3928                                         lite_spot(ny[i], nx[i]);
3929                                         Term_fresh();
3930                                 }
3931                                 else
3932                                 {
3933                                         /* Pause anyway, for consistancy */
3934                                         Term_xtra(TERM_XTRA_DELAY, msec);
3935                                 }
3936                         }
3937                         if((back_chance > 37) && !p_ptr->blind && (item >= 0))
3938                         {
3939                                 msg_format(_("%sが手元に返ってきた。", "%s comes back to you."), o2_name);
3940                                 come_back = TRUE;
3941                         }
3942                         else
3943                         {
3944                                 if (item >= 0)
3945                                 {
3946                                         msg_format(_("%sを受け損ねた!", "%s backs, but you can't catch!"), o2_name);
3947                                 }
3948                                 else
3949                                 {
3950                                         msg_format(_("%sが返ってきた。", "%s comes back."), o2_name);
3951                                 }
3952                                 y = p_ptr->y;
3953                                 x = p_ptr->x;
3954                         }
3955                 }
3956                 else
3957                 {
3958                         msg_format(_("%sが返ってこなかった!", "%s doesn't back!"), o2_name);
3959                 }
3960         }
3961
3962         if (come_back)
3963         {
3964                 if (item == INVEN_RARM || item == INVEN_LARM)
3965                 {
3966                         /* Access the wield slot */
3967                         o_ptr = &inventory[item];
3968
3969                         /* Wear the new stuff */
3970                         object_copy(o_ptr, q_ptr);
3971
3972                         /* Increase the weight */
3973                         p_ptr->total_weight += q_ptr->weight;
3974
3975                         /* Increment the equip counter by hand */
3976                         equip_cnt++;
3977
3978                         /* Recalculate bonuses */
3979                         p_ptr->update |= (PU_BONUS);
3980
3981                         /* Recalculate torch */
3982                         p_ptr->update |= (PU_TORCH);
3983
3984                         /* Recalculate mana XXX */
3985                         p_ptr->update |= (PU_MANA);
3986
3987                         /* Window stuff */
3988                         p_ptr->window |= (PW_EQUIP);
3989                 }
3990                 else
3991                 {
3992                         inven_carry(q_ptr);
3993                 }
3994                 do_drop = FALSE;
3995         }
3996         else if (equiped_item)
3997         {
3998                 kamaenaoshi(item);
3999                 calc_android_exp();
4000         }
4001
4002         /* Drop (or break) near that location */
4003         if (do_drop)
4004         {
4005                 if (cave_have_flag_bold(y, x, FF_PROJECT))
4006                 {
4007                         /* Drop (or break) near that location */
4008                         (void)drop_near(q_ptr, j, y, x);
4009                 }
4010                 else
4011                 {
4012                         /* Drop (or break) near that location */
4013                         (void)drop_near(q_ptr, j, prev_y, prev_x);
4014                 }
4015         }
4016
4017         return TRUE;
4018 }
4019
4020
4021 #ifdef TRAVEL
4022 /*
4023  * Hack: travel command
4024  */
4025 #define TRAVEL_UNABLE 9999
4026
4027 static int flow_head = 0;
4028 static int flow_tail = 0;
4029 static POSITION temp2_x[MAX_SHORT];
4030 static POSITION temp2_y[MAX_SHORT];
4031
4032 /*!
4033  * @brief トラベル処理の記憶配列を初期化する Hack: forget the "flow" information 
4034  * @return なし
4035  */
4036 void forget_travel_flow(void)
4037 {
4038         POSITION x, y;
4039
4040         /* Check the entire dungeon */
4041         for (y = 0; y < cur_hgt; y++)
4042         {
4043                 for (x = 0; x < cur_wid; x++)
4044                 {
4045                         /* Forget the old data */
4046                         travel.cost[y][x] = MAX_SHORT;
4047                 }
4048         }
4049
4050         travel.y = travel.x = 0;
4051 }
4052
4053 /*!
4054  * @brief トラベル処理中に地形に応じた移動コスト基準を返す
4055  * @param y 該当地点のY座標
4056  * @param x 該当地点のX座標
4057  * @return コスト値
4058  */
4059 static int travel_flow_cost(POSITION y, POSITION x)
4060 {
4061         feature_type *f_ptr = &f_info[cave[y][x].feat];
4062         int cost = 1;
4063
4064         /* Avoid obstacles (ex. trees) */
4065         if (have_flag(f_ptr->flags, FF_AVOID_RUN)) cost += 1;
4066
4067         /* Water */
4068         if (have_flag(f_ptr->flags, FF_WATER))
4069         {
4070                 if (have_flag(f_ptr->flags, FF_DEEP) && !p_ptr->levitation) cost += 5;
4071         }
4072
4073         /* Lava */
4074         if (have_flag(f_ptr->flags, FF_LAVA))
4075         {
4076                 int lava = 2;
4077                 if (!p_ptr->resist_fire) lava *= 2;
4078                 if (!p_ptr->levitation) lava *= 2;
4079                 if (have_flag(f_ptr->flags, FF_DEEP)) lava *= 2;
4080
4081                 cost += lava;
4082         }
4083
4084         /* Detected traps and doors */
4085         if (cave[y][x].info & (CAVE_MARK))
4086         {
4087                 if (have_flag(f_ptr->flags, FF_DOOR)) cost += 1;
4088                 if (have_flag(f_ptr->flags, FF_TRAP)) cost += 10;
4089         }
4090
4091         return (cost);
4092 }
4093
4094 /*!
4095  * @brief トラベル処理の到達地点までの行程を得る処理のサブルーチン
4096  * @param y 目標地点のY座標
4097  * @param x 目標地点のX座標
4098  * @param n 現在のコスト
4099  * @param wall プレイヤーが壁の中にいるならばTRUE
4100  * @return なし
4101  */
4102 static void travel_flow_aux(POSITION y, POSITION x, int n, bool wall)
4103 {
4104         cave_type *c_ptr = &cave[y][x];
4105         feature_type *f_ptr = &f_info[c_ptr->feat];
4106         int old_head = flow_head;
4107         int add_cost = 1;
4108         int base_cost = (n % TRAVEL_UNABLE);
4109         int from_wall = (n / TRAVEL_UNABLE);
4110         int cost;
4111
4112         /* Ignore out of bounds */
4113         if (!in_bounds(y, x)) return;
4114
4115         /* Ignore unknown grid except in wilderness */
4116         if (dun_level > 0 && !(c_ptr->info & CAVE_KNOWN)) return;
4117
4118         /* Ignore "walls" and "rubble" (include "secret doors") */
4119         if (have_flag(f_ptr->flags, FF_WALL) ||
4120                 have_flag(f_ptr->flags, FF_CAN_DIG) ||
4121                 (have_flag(f_ptr->flags, FF_DOOR) && cave[y][x].mimic) ||
4122                 (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation))
4123         {
4124                 if (!wall || !from_wall) return;
4125                 add_cost += TRAVEL_UNABLE;
4126         }
4127         else
4128         {
4129                 add_cost = travel_flow_cost(y, x);
4130         }
4131
4132         cost = base_cost + add_cost;
4133
4134         /* Ignore lower cost entries */
4135         if (travel.cost[y][x] <= cost) return;
4136
4137         /* Save the flow cost */
4138         travel.cost[y][x] = cost;
4139
4140         /* Enqueue that entry */
4141         temp2_y[flow_head] = y;
4142         temp2_x[flow_head] = x;
4143
4144         /* Advance the queue */
4145         if (++flow_head == MAX_SHORT) flow_head = 0;
4146
4147         /* Hack -- notice overflow by forgetting new entry */
4148         if (flow_head == flow_tail) flow_head = old_head;
4149
4150         return;
4151 }
4152
4153 /*!
4154  * @brief トラベル処理の到達地点までの行程を得る処理のメインルーチン
4155  * @param ty 目標地点のY座標
4156  * @param tx 目標地点のX座標
4157  * @return なし
4158  */
4159 static void travel_flow(POSITION ty, POSITION tx)
4160 {
4161         POSITION x, y, d;
4162         bool wall = FALSE;
4163         feature_type *f_ptr = &f_info[cave[p_ptr->y][p_ptr->x].feat];
4164
4165         /* Reset the "queue" */
4166         flow_head = flow_tail = 0;
4167
4168         /* is player in the wall? */
4169         if (!have_flag(f_ptr->flags, FF_MOVE)) wall = TRUE;
4170
4171         /* Start at the target grid */
4172         travel_flow_aux(ty, tx, 0, wall);
4173
4174         /* Now process the queue */
4175         while (flow_head != flow_tail)
4176         {
4177                 /* Extract the next entry */
4178                 y = temp2_y[flow_tail];
4179                 x = temp2_x[flow_tail];
4180
4181                 /* Forget that entry */
4182                 if (++flow_tail == MAX_SHORT) flow_tail = 0;
4183
4184                 /* Ignore too far entries */
4185                 //if (distance(ty, tx, y, x) > 100) continue;
4186
4187                 /* Add the "children" */
4188                 for (d = 0; d < 8; d++)
4189                 {
4190                         /* Add that child if "legal" */
4191                         travel_flow_aux(y + ddy_ddd[d], x + ddx_ddd[d], travel.cost[y][x], wall);
4192                 }
4193         }
4194
4195         /* Forget the flow info */
4196         flow_head = flow_tail = 0;
4197 }
4198
4199 /*!
4200  * @brief トラベル処理のメインルーチン
4201  * @return なし
4202  */
4203 void do_cmd_travel(void)
4204 {
4205         POSITION x, y;
4206         int i;
4207         int dx, dy, sx, sy;
4208         feature_type *f_ptr;
4209
4210         if (travel.x != 0 && travel.y != 0 &&
4211             get_check(_("トラベルを継続しますか?", "Do you continue to travel?")))
4212         {
4213                 y = travel.y;
4214                 x = travel.x;
4215         }
4216         else if (!tgt_pt(&x, &y)) return;
4217
4218         if ((x == p_ptr->x) && (y == p_ptr->y))
4219         {
4220                 msg_print(_("すでにそこにいます!", "You are already there!!"));
4221                 return;
4222         }
4223
4224         f_ptr = &f_info[cave[y][x].feat];
4225
4226         if ((cave[y][x].info & CAVE_MARK) &&
4227                 (have_flag(f_ptr->flags, FF_WALL) ||
4228                         have_flag(f_ptr->flags, FF_CAN_DIG) ||
4229                         (have_flag(f_ptr->flags, FF_DOOR) && cave[y][x].mimic)))
4230         {
4231                 msg_print(_("そこには行くことができません!", "You cannot travel there!"));
4232                 return;
4233         }
4234
4235         forget_travel_flow();
4236         travel_flow(y, x);
4237
4238         travel.x = x;
4239         travel.y = y;
4240
4241         /* Travel till 255 steps */
4242         travel.run = 255;
4243
4244         /* Paranoia */
4245         travel.dir = 0;
4246
4247         /* Decides first direction */
4248         dx = abs(p_ptr->x - x);
4249         dy = abs(p_ptr->y - y);
4250         sx = ((x == p_ptr->x) || (dx < dy)) ? 0 : ((x > p_ptr->x) ? 1 : -1);
4251         sy = ((y == p_ptr->y) || (dy < dx)) ? 0 : ((y > p_ptr->y) ? 1 : -1);
4252
4253         for (i = 1; i <= 9; i++)
4254         {
4255                 if ((sx == ddx[i]) && (sy == ddy[i])) travel.dir = i;
4256         }
4257 }
4258 #endif