OSDN Git Service

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