OSDN Git Service

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