OSDN Git Service

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