OSDN Git Service

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