OSDN Git Service

Merge remote-tracking branch 'remotes/origin/feature/Refactoring-Hourier' into For2...
[hengband/hengband.git] / src / cmd / cmd-basic.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 "util.h"
15 #include "core.h"
16 #include "term.h"
17
18 #include "cmd-dump.h"
19 #include "chest.h"
20 #include "trap.h"
21 #include "dungeon.h"
22 #include "feature.h"
23 #include "floor.h"
24 #include "melee.h"
25 #include "object-hook.h"
26 #include "spells.h"
27 #include "spells-summon.h"
28 #include "spells-status.h"
29 #include "monster.h"
30 #include "monster-status.h"
31 #include "quest.h"
32 #include "artifact.h"
33 #include "avatar.h"
34 #include "player-status.h"
35 #include "realm-hex.h"
36 #include "realm-song.h"
37 #include "geometry.h"
38 #include "wild.h"
39 #include "grid.h"
40 #include "feature.h"
41 #include "player-move.h"
42 #include "player-effects.h"
43 #include "player-class.h"
44 #include "player-personality.h"
45 #include "player-inventory.h"
46 #include "objectkind.h"
47 #include "object-broken.h"
48 #include "object-flavor.h"
49 #include "shoot.h"
50 #include "snipe.h"
51
52 #include "cmd-basic.h"
53 #include "cmd-item.h"
54 #include "floor-save.h"
55 #include "dungeon-file.h"
56 #include "files.h"
57
58 #include "view-mainwindow.h"
59 #include "targeting.h"
60 #include "world.h"
61
62 /*!
63  * @brief フロア脱出時に出戻りが不可能だった場合に警告を加える処理
64  * @param down_stair TRUEならば階段を降りる処理、FALSEなら階段を昇る処理による内容
65  * @return フロア移動を実際に行うならTRUE、キャンセルする場合はFALSE
66  */
67 static bool confirm_leave_level(player_type *creature_ptr, bool down_stair)
68 {
69         quest_type *q_ptr = &quest[creature_ptr->current_floor_ptr->inside_quest];
70
71         /* Confirm leaving from once only quest */
72         if (confirm_quest && creature_ptr->current_floor_ptr->inside_quest &&
73             (q_ptr->type == QUEST_TYPE_RANDOM ||
74              (q_ptr->flags & QUEST_FLAG_ONCE &&
75                                                 q_ptr->status != QUEST_STATUS_COMPLETED) ||
76                  (q_ptr->flags & QUEST_FLAG_TOWER &&
77                                                 ((q_ptr->status != QUEST_STATUS_STAGE_COMPLETED) ||
78                                                  (down_stair && (quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED))))))
79         {
80                 msg_print(_("この階を一度去ると二度と戻って来られません。", "You can't come back here once you leave this floor."));
81                 if (get_check(_("本当にこの階を去りますか?", "Really leave this floor? "))) return TRUE;
82         }
83         else
84         {
85                 return TRUE;
86         }
87         return FALSE;
88 }
89
90 /*!
91  * @brief 魔法系コマンドが制限されているかを返す。
92  * @return 魔法系コマンドを使用可能ならFALSE、不可能ならば理由をメッセージ表示してTRUEを返す。
93  */
94 bool cmd_limit_cast(player_type *creature_ptr)
95 {
96         if (creature_ptr->current_floor_ptr->dun_level && (d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC))
97         {
98                 msg_print(_("ダンジョンが魔法を吸収した!", "The dungeon absorbs all attempted magic!"));
99                 msg_print(NULL);
100                 return TRUE;
101         }
102         else if (creature_ptr->anti_magic)
103         {
104                 msg_print(_("反魔法バリアが魔法を邪魔した!", "An anti-magic shell disrupts your magic!"));
105                 return TRUE;
106         }
107         else if (creature_ptr->shero)
108         {
109                 msg_format(_("狂戦士化していて頭が回らない!", "You cannot think directly!"));
110                 return TRUE;
111         }
112         else
113                 return FALSE;
114 }
115
116 bool cmd_limit_confused(player_type *creature_ptr)
117 {
118         if (creature_ptr->confused)
119         {
120                 msg_print(_("混乱していてできない!", "You are too confused!"));
121                 return TRUE;
122         }
123         return FALSE;
124 }
125
126 bool cmd_limit_image(player_type *creature_ptr)
127 {
128         if (creature_ptr->image)
129         {
130                 msg_print(_("幻覚が見えて集中できない!", "You are too hallucinated!"));
131                 return TRUE;
132         }
133         return FALSE;
134 }
135
136 bool cmd_limit_stun(player_type *creature_ptr)
137 {
138         if (creature_ptr->stun)
139         {
140                 msg_print(_("頭が朦朧としていて集中できない!", "You are too stuned!"));
141                 return TRUE;
142         }
143         return FALSE;
144 }
145
146 bool cmd_limit_arena(player_type *creature_ptr)
147 {
148         if (creature_ptr->current_floor_ptr->inside_arena)
149         {
150                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
151                 msg_print(NULL);
152                 return TRUE;
153         }
154         return FALSE;
155 }
156
157 bool cmd_limit_blind(player_type *creature_ptr)
158 {
159         if (creature_ptr->blind)
160         {
161                 msg_print(_("目が見えない。", "You can't see anything."));
162                 return TRUE;
163         }
164         if (no_lite(creature_ptr))
165         {
166                 msg_print(_("明かりがないので見えない。", "You have no light."));
167                 return TRUE;
168         }
169         return FALSE;
170 }
171
172 bool cmd_limit_time_walk(player_type *creature_ptr)
173 {
174         if (creature_ptr->timewalk)
175         {
176                 if (flush_failure) flush();
177                 msg_print(_("止まった時の中ではうまく働かないようだ。", "It shows no reaction."));
178                 sound(SOUND_FAIL);
179                 return TRUE;
180         }
181         return FALSE;
182 }
183
184 /*!
185  * @brief 階段を使って階層を昇る処理 / Go up one level
186  * @return なし
187  */
188 void do_cmd_go_up(player_type *creature_ptr)
189 {
190         bool go_up = FALSE;
191
192         /* Player grid */
193         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
194         feature_type *f_ptr = &f_info[g_ptr->feat];
195
196         int up_num = 0;
197
198         if (creature_ptr->special_defense & KATA_MUSOU)
199         {
200                 set_action(creature_ptr, ACTION_NONE);
201         }
202
203         /* Verify stairs */
204         if (!have_flag(f_ptr->flags, FF_LESS))
205         {
206                 msg_print(_("ここには上り階段が見当たらない。", "I see no up staircase here."));
207                 return;
208         }
209
210         /* Quest up stairs */
211         if (have_flag(f_ptr->flags, FF_QUEST))
212         {
213                 if (!confirm_leave_level(creature_ptr, FALSE)) return;
214         
215                 /* Success */
216                 if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
217                         msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
218                 else
219                         msg_print(_("上の階に登った。", "You enter the up staircase."));
220
221                 leave_quest_check(creature_ptr);
222
223                 creature_ptr->current_floor_ptr->inside_quest = g_ptr->special;
224
225                 /* Activate the quest */
226                 if (!quest[creature_ptr->current_floor_ptr->inside_quest].status)
227                 {
228                         if (quest[creature_ptr->current_floor_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
229                         {
230                                 init_flags = INIT_ASSIGN;
231                                 process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
232                         }
233                         quest[creature_ptr->current_floor_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
234                 }
235
236                 /* Leaving a quest */
237                 if (!creature_ptr->current_floor_ptr->inside_quest)
238                 {
239                         creature_ptr->current_floor_ptr->dun_level = 0;
240                 }
241                 creature_ptr->leaving = TRUE;
242
243                 creature_ptr->oldpx = 0;
244                 creature_ptr->oldpy = 0;
245                 
246                 take_turn(creature_ptr, 100);
247
248                 /* End the command */
249                 return;
250         }
251
252         if (!creature_ptr->current_floor_ptr->dun_level)
253         {
254                 go_up = TRUE;
255         }
256         else
257         {
258                 go_up = confirm_leave_level(creature_ptr, FALSE);
259         }
260
261         if (!go_up) return;
262
263         take_turn(creature_ptr, 100);
264
265         if (autosave_l) do_cmd_save_game(creature_ptr, TRUE);
266
267         /* For a random quest */
268         if (creature_ptr->current_floor_ptr->inside_quest &&
269             quest[creature_ptr->current_floor_ptr->inside_quest].type == QUEST_TYPE_RANDOM)
270         {
271                 leave_quest_check(creature_ptr);
272
273                 creature_ptr->current_floor_ptr->inside_quest = 0;
274         }
275
276         /* For a fixed quest */
277         if (creature_ptr->current_floor_ptr->inside_quest &&
278             quest[creature_ptr->current_floor_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
279         {
280                 leave_quest_check(creature_ptr);
281
282                 creature_ptr->current_floor_ptr->inside_quest = g_ptr->special;
283                 creature_ptr->current_floor_ptr->dun_level = 0;
284                 up_num = 0;
285         }
286
287         /* For normal dungeon and random quest */
288         else
289         {
290                 /* New depth */
291                 if (have_flag(f_ptr->flags, FF_SHAFT))
292                 {
293                         /* Create a way back */
294                         prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_UP | CFM_SHAFT);
295
296                         up_num = 2;
297                 }
298                 else
299                 {
300                         /* Create a way back */
301                         prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_UP);
302
303                         up_num = 1;
304                 }
305
306                 /* Get out from current dungeon */
307                 if (creature_ptr->current_floor_ptr->dun_level - up_num < d_info[creature_ptr->dungeon_idx].mindepth)
308                         up_num = creature_ptr->current_floor_ptr->dun_level;
309         }
310         if (record_stair) exe_write_diary(creature_ptr, NIKKI_STAIR, 0-up_num, _("階段を上った", "climbed up the stairs to"));
311
312         /* Success */
313         if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
314                 msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
315         else if (up_num == creature_ptr->current_floor_ptr->dun_level)
316                 msg_print(_("地上に戻った。", "You go back to the surface."));
317         else
318                 msg_print(_("階段を上って新たなる迷宮へと足を踏み入れた。", "You enter a maze of up staircases."));
319         creature_ptr->leaving = TRUE;
320 }
321
322
323 /*!
324  * @brief 階段を使って階層を降りる処理 / Go down one level
325  * @param creature_ptr プレーヤーへの参照ポインタ
326  * @return なし
327  */
328 void do_cmd_go_down(player_type *creature_ptr)
329 {
330         bool fall_trap = FALSE;
331         int down_num = 0;
332
333         if (creature_ptr->special_defense & KATA_MUSOU)
334         {
335                 set_action(creature_ptr, ACTION_NONE);
336         }
337
338         /* Verify stairs */
339         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
340         feature_type *f_ptr = &f_info[g_ptr->feat];
341         if (!have_flag(f_ptr->flags, FF_MORE))
342         {
343                 msg_print(_("ここには下り階段が見当たらない。", "I see no down staircase here."));
344                 return;
345         }
346
347         if (have_flag(f_ptr->flags, FF_TRAP)) fall_trap = TRUE;
348
349         /* Quest entrance */
350         if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
351         {
352                 do_cmd_quest(creature_ptr);
353                 return;
354         }
355
356         /* Quest down stairs */
357         if (have_flag(f_ptr->flags, FF_QUEST))
358         {
359                 /* Confirm Leaving */
360                 if(!confirm_leave_level(creature_ptr, TRUE)) return;
361                 
362                 if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
363                         msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
364                 else
365                         msg_print(_("下の階に降りた。", "You enter the down staircase."));
366
367                 leave_quest_check(creature_ptr);
368                 leave_tower_check(creature_ptr);
369
370                 creature_ptr->current_floor_ptr->inside_quest = g_ptr->special;
371
372                 /* Activate the quest */
373                 if (!quest[creature_ptr->current_floor_ptr->inside_quest].status)
374                 {
375                         if (quest[creature_ptr->current_floor_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
376                         {
377                                 init_flags = INIT_ASSIGN;
378                                 process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
379                         }
380                         quest[creature_ptr->current_floor_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
381                 }
382
383                 /* Leaving a quest */
384                 if (!creature_ptr->current_floor_ptr->inside_quest)
385                 {
386                         creature_ptr->current_floor_ptr->dun_level = 0;
387                 }
388                 creature_ptr->leaving = TRUE;
389                 creature_ptr->oldpx = 0;
390                 creature_ptr->oldpy = 0;
391                 
392                 take_turn(creature_ptr, 100);
393                 return;
394         }
395
396         DUNGEON_IDX target_dungeon = 0;
397
398         if (!creature_ptr->current_floor_ptr->dun_level)
399         {
400                 target_dungeon = have_flag(f_ptr->flags, FF_ENTRANCE) ? g_ptr->special : DUNGEON_ANGBAND;
401
402                 if (ironman_downward && (target_dungeon != DUNGEON_ANGBAND))
403                 {
404                         msg_print(_("ダンジョンの入口は塞がれている!", "The entrance of this dungeon is closed!"));
405                         return;
406                 }
407                 if (!max_dlv[target_dungeon])
408                 {
409                         msg_format(_("ここには%sの入り口(%d階相当)があります", "There is the entrance of %s (Danger level: %d)"),
410                                 d_name + d_info[target_dungeon].name, d_info[target_dungeon].mindepth);
411                         if (!get_check(_("本当にこのダンジョンに入りますか?", "Do you really get in this dungeon? "))) return;
412                 }
413
414                 /* Save old player position */
415                 creature_ptr->oldpx = creature_ptr->x;
416                 creature_ptr->oldpy = creature_ptr->y;
417                 creature_ptr->dungeon_idx = target_dungeon;
418
419                 /*
420                  * Clear all saved floors
421                  * and create a first saved floor
422                  */
423                 prepare_change_floor_mode(creature_ptr, CFM_FIRST_FLOOR);
424         }
425
426         take_turn(creature_ptr, 100);
427
428         if (autosave_l) do_cmd_save_game(creature_ptr, TRUE);
429
430         /* Go down */
431         if (have_flag(f_ptr->flags, FF_SHAFT)) down_num += 2;
432         else down_num += 1;
433
434         if (!creature_ptr->current_floor_ptr->dun_level)
435         {
436                 /* Enter the dungeon just now */
437                 creature_ptr->enter_dungeon = TRUE;
438                 down_num = d_info[creature_ptr->dungeon_idx].mindepth;
439         }
440
441         if (record_stair)
442         {
443                 if (fall_trap) exe_write_diary(creature_ptr, NIKKI_STAIR, down_num, _("落とし戸に落ちた", "fell through a trap door"));
444                 else exe_write_diary(creature_ptr, NIKKI_STAIR, down_num, _("階段を下りた", "climbed down the stairs to"));
445         }
446
447         if (fall_trap)
448         {
449                 msg_print(_("わざと落とし戸に落ちた。", "You deliberately jump through the trap door."));
450         }
451         else
452         {
453                 /* Success */
454                 if (target_dungeon)
455                 {
456                         msg_format(_("%sへ入った。", "You entered %s."), d_text + d_info[creature_ptr->dungeon_idx].text);
457                 }
458                 else
459                 {
460                         if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
461                                 msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
462                         else
463                                 msg_print(_("階段を下りて新たなる迷宮へと足を踏み入れた。", "You enter a maze of down staircases."));
464                 }
465         }
466
467         creature_ptr->leaving = TRUE;
468
469         if (fall_trap)
470         {
471                 prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
472                 return;
473         }
474         
475         /* Create a way back */
476         if (have_flag(f_ptr->flags, FF_SHAFT))
477         {
478                 prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_DOWN | CFM_SHAFT);
479         }
480         else
481         {
482                 prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_DOWN);
483         }
484 }
485
486
487 /*!
488  * @brief 探索コマンドのメインルーチン / Simple command to "search" for one turn
489  * @return なし
490  */
491 void do_cmd_search(player_type * creature_ptr)
492 {
493         /* Allow repeated command */
494         if (command_arg)
495         {
496                 /* Set repeat count */
497                 command_rep = command_arg - 1;
498                 creature_ptr->redraw |= (PR_STATE);
499
500                 /* Cancel the arg */
501                 command_arg = 0;
502         }
503
504         take_turn(creature_ptr, 100);
505         search(creature_ptr);
506 }
507
508
509 /*!
510  * @brief 該当のマスに存在している箱のオブジェクトIDを返す。
511  * @param y 走査対象にしたいマスのY座標
512  * @param x 走査対象にしたいマスのX座標
513  * @param trapped TRUEならばトラップが存在する箱のみ、FALSEならば空でない箱全てを対象にする
514  * @return 箱が存在する場合そのオブジェクトID、存在しない場合0を返す。
515  */
516 static OBJECT_IDX chest_check(floor_type *floor_ptr, POSITION y, POSITION x, bool trapped)
517 {
518         grid_type *g_ptr = &floor_ptr->grid_array[y][x];
519         OBJECT_IDX this_o_idx, next_o_idx = 0;
520
521         /* Scan all objects in the grid */
522         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
523         {
524                 object_type *o_ptr;
525
526                 o_ptr = &floor_ptr->o_list[this_o_idx];
527                 next_o_idx = o_ptr->next_o_idx;
528
529                 /* Skip unknown chests XXX XXX */
530                 /* if (!(o_ptr->marked & OM_FOUND)) continue; */
531
532                 /* Check for non empty chest */
533                 if ((o_ptr->tval == TV_CHEST) &&
534                         (((!trapped) && (o_ptr->pval)) || /* non empty */
535                         ((trapped) && (o_ptr->pval > 0)))) /* trapped only */
536                 {
537                         return (this_o_idx);
538                 }
539         }
540
541         return 0;
542 }
543
544 /*!
545  * @brief 箱を開ける実行処理 /
546  * Attempt to open the given chest at the given location
547  * @param y 箱の存在するマスのY座標
548  * @param x 箱の存在するマスのX座標
549  * @param o_idx 箱のオブジェクトID
550  * @return 箱が開かなかった場合TRUE / Returns TRUE if repeated commands may continue
551  * @details
552  * Assume there is no monster blocking the destination
553  */
554 static bool exe_open_chest(player_type *creature_ptr, POSITION y, POSITION x, OBJECT_IDX o_idx)
555 {
556         bool flag = TRUE;
557         bool more = FALSE;
558         object_type *o_ptr = &creature_ptr->current_floor_ptr->o_list[o_idx];
559
560         take_turn(creature_ptr, 100);
561
562         /* Attempt to unlock it */
563         if (o_ptr->pval > 0)
564         {
565                 /* Assume locked, and thus not open */
566                 flag = FALSE;
567
568                 /* Get the "disarm" factor */
569                 int i = creature_ptr->skill_dis;
570
571                 /* Penalize some conditions */
572                 if (creature_ptr->blind || no_lite(creature_ptr)) i = i / 10;
573                 if (creature_ptr->confused || creature_ptr->image) i = i / 10;
574
575                 /* Extract the difficulty */
576                 int j = i - o_ptr->pval;
577
578                 /* Always have a small chance of success */
579                 if (j < 2) j = 2;
580
581                 /* Success -- May still have traps */
582                 if (randint0(100) < j)
583                 {
584                         msg_print(_("鍵をはずした。", "You have picked the lock."));
585                         gain_exp(creature_ptr, 1);
586                         flag = TRUE;
587                 }
588
589                 /* Failure -- Keep trying */
590                 else
591                 {
592                         /* We may continue repeating */
593                         more = TRUE;
594                         if (flush_failure) flush();
595                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
596
597                 }
598         }
599
600         /* Allowed to open */
601         if (flag)
602         {
603                 /* Apply chest traps, if any */
604                 chest_trap(creature_ptr, y, x, o_idx);
605
606                 /* Let the Chest drop items */
607                 chest_death(creature_ptr, FALSE, y, x, o_idx);
608         }
609
610         return more;
611 }
612
613 /*!
614  * @brief プレイヤーの周辺9マスに該当する地形がいくつあるかを返す /
615  * Attempt to open the given chest at the given location
616  * @param y 該当する地形の中から1つのY座標を返す参照ポインタ
617  * @param x 該当する地形の中から1つのX座標を返す参照ポインタ
618  * @param test 地形条件を判定するための関数ポインタ
619  * @param under TRUEならばプレイヤーの直下の座標も走査対象にする
620  * @return 該当する地形の数
621  * @details Return the number of features around (or under) the character.
622  * Usually look for doors and floor traps.
623  */
624 static int count_dt(player_type *creature_ptr, POSITION *y, POSITION *x, bool (*test)(FEAT_IDX feat), bool under)
625 {
626         /* Check around (and under) the character */
627         int count = 0;
628         for (DIRECTION d = 0; d < 9; d++)
629         {
630                 grid_type *g_ptr;
631                 FEAT_IDX feat;
632
633                 /* if not searching under player continue */
634                 if ((d == 8) && !under) continue;
635
636                 /* Extract adjacent (legal) location */
637                 POSITION yy = creature_ptr->y + ddy_ddd[d];
638                 POSITION xx = creature_ptr->x + ddx_ddd[d];
639
640                 /* Get the creature_ptr->current_floor_ptr->grid_array */
641                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[yy][xx];
642
643                 /* Must have knowledge */
644                 if (!(g_ptr->info & (CAVE_MARK))) continue;
645
646                 /* Feature code (applying "mimic" field) */
647                 feat = get_feat_mimic(g_ptr);
648
649                 /* Not looking for this feature */
650                 if (!((*test)(feat))) continue;
651
652                 /* OK */
653                 ++count;
654
655                 /* Remember the location. Only useful if only one match */
656                 *y = yy;
657                 *x = xx;
658         }
659
660         /* All done */
661         return count;
662 }
663
664
665 /*!
666  * @brief プレイヤーの周辺9マスに箱のあるマスがいくつあるかを返す /
667  * Return the number of chests around (or under) the character.
668  * @param y 該当するマスの中から1つのY座標を返す参照ポインタ
669  * @param x 該当するマスの中から1つのX座標を返す参照ポインタ
670  * @param trapped TRUEならばトラップの存在が判明している箱のみ対象にする
671  * @return 該当する地形の数
672  * @details
673  * If requested, count only trapped chests.
674  */
675 static int count_chests(player_type *creature_ptr, POSITION *y, POSITION *x, bool trapped)
676 {
677         /* Check around (and under) the character */
678         int count = 0;
679         for (DIRECTION d = 0; d < 9; d++)
680         {
681                 /* Extract adjacent (legal) location */
682                 POSITION yy = creature_ptr->y + ddy_ddd[d];
683                 POSITION xx = creature_ptr->x + ddx_ddd[d];
684
685                 /* No (visible) chest is there */
686                 OBJECT_IDX o_idx = chest_check(creature_ptr->current_floor_ptr, yy, xx, FALSE);
687                 if (!o_idx) continue;
688
689                 /* Grab the object */
690                 object_type *o_ptr;
691                 o_ptr = &creature_ptr->current_floor_ptr->o_list[o_idx];
692
693                 /* Already open */
694                 if (o_ptr->pval == 0) continue;
695
696                 /* No (known) traps here */
697                 if (trapped && (!object_is_known(o_ptr) ||
698                         !chest_traps[o_ptr->pval])) continue;
699
700                 /* OK */
701                 ++count;
702
703                 /* Remember the location. Only useful if only one match */
704                 *y = yy;
705                 *x = xx;
706         }
707
708         /* All done */
709         return count;
710 }
711
712
713
714 /*!
715  * @brief 「開ける」動作コマンドのサブルーチン /
716  * Perform the basic "open" command on doors
717  * @param y 対象を行うマスのY座標
718  * @param x 対象を行うマスのX座標
719  * @return 実際に処理が行われた場合TRUEを返す。
720  * @details
721  * Assume destination is a closed/locked/jammed door
722  * Assume there is no monster blocking the destination
723  * Returns TRUE if repeated commands may continue
724  */
725 static bool exe_open(player_type *creature_ptr, POSITION y, POSITION x)
726 {
727         /* Get requested grid */
728         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
729         feature_type *f_ptr = &f_info[g_ptr->feat];
730         bool more = FALSE;
731
732         take_turn(creature_ptr, 100);
733
734         /* Seeing true feature code (ignore mimic) */
735
736         /* Jammed door */
737         if (!have_flag(f_ptr->flags, FF_OPEN))
738         {
739                 /* Stuck */
740                 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(g_ptr)].name);
741                 return more;
742         }
743
744         if (!f_ptr->power)
745         {
746                 cave_alter_feat(creature_ptr, y, x, FF_OPEN);
747                 sound(SOUND_OPENDOOR);
748                 return more;
749         }
750         
751         /* Disarm factor */
752         int i = creature_ptr->skill_dis;
753
754         /* Penalize some conditions */
755         if (creature_ptr->blind || no_lite(creature_ptr)) i = i / 10;
756         if (creature_ptr->confused || creature_ptr->image) i = i / 10;
757
758         /* Extract the difficulty */
759         int j = f_ptr->power;
760         j = i - (j * 4);
761
762         /* Always have a small chance of success */
763         if (j < 2) j = 2;
764
765         if (randint0(100) >= j)
766         {
767                 if (flush_failure) flush();
768                 msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
769                 more = TRUE;
770         }
771
772         msg_print(_("鍵をはずした。", "You have picked the lock."));
773
774         /* Open the door */
775         cave_alter_feat(creature_ptr, y, x, FF_OPEN);
776
777         sound(SOUND_OPENDOOR);
778
779         /* Experience */
780         gain_exp(creature_ptr, 1);
781         return more;
782 }
783
784 /*!
785  * @brief 「開ける」コマンドのメインルーチン /
786  * Open a closed/locked/jammed door or a closed/locked chest.
787  * @return なし
788  * @details
789  * Unlocking a locked door/chest is worth one experience point.
790  */
791 void do_cmd_open(player_type *creature_ptr)
792 {
793         POSITION y, x;
794         DIRECTION dir;
795         OBJECT_IDX o_idx;
796
797         bool more = FALSE;
798
799         if (creature_ptr->wild_mode) return;
800
801         if (creature_ptr->special_defense & KATA_MUSOU)
802         {
803                 set_action(creature_ptr, ACTION_NONE);
804         }
805
806         /* Option: Pick a direction */
807         if (easy_open)
808         {
809                 int num_doors, num_chests;
810
811                 num_doors = count_dt(creature_ptr, &y, &x, is_closed_door, FALSE);
812                 num_chests = count_chests(creature_ptr, &y, &x, FALSE);
813                 if (num_doors || num_chests)
814                 {
815                         bool too_many = (num_doors && num_chests) || (num_doors > 1) ||
816                             (num_chests > 1);
817                         if (!too_many) command_dir = coords_to_dir(creature_ptr, y, x);
818                 }
819         }
820
821         /* Allow repeated command */
822         if (command_arg)
823         {
824                 /* Set repeat count */
825                 command_rep = command_arg - 1;
826                 creature_ptr->redraw |= (PR_STATE);
827
828                 /* Cancel the arg */
829                 command_arg = 0;
830         }
831
832         /* Get a "repeated" direction */
833         if (get_rep_dir(&dir, TRUE))
834         {
835                 FEAT_IDX feat;
836                 grid_type *g_ptr;
837
838                 /* Get requested location */
839                 y = creature_ptr->y + ddy[dir];
840                 x = creature_ptr->x + ddx[dir];
841
842                 /* Get requested grid */
843                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
844
845                 /* Feature code (applying "mimic" field) */
846                 feat = get_feat_mimic(g_ptr);
847
848                 /* Check for chest */
849                 o_idx = chest_check(creature_ptr->current_floor_ptr, y, x, FALSE);
850
851                 if (!have_flag(f_info[feat].flags, FF_OPEN) && !o_idx)
852                 {
853                         msg_print(_("そこには開けるものが見当たらない。", "You see nothing there to open."));
854                 }
855                 else if (g_ptr->m_idx && creature_ptr->riding != g_ptr->m_idx)
856                 {
857                         take_turn(creature_ptr, 100);
858                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
859                         py_attack(creature_ptr, y, x, 0);
860                 }
861                 else if (o_idx)
862                 {
863                         more = exe_open_chest(creature_ptr, y, x, o_idx);
864                 }
865                 else
866                 {
867                         more = exe_open(creature_ptr, y, x);
868                 }
869         }
870
871         /* Cancel repeat unless we may continue */
872         if (!more) disturb(creature_ptr, FALSE, FALSE);
873 }
874
875
876
877 /*
878  * todo 常にFALSEを返している
879  * @brief 「閉じる」動作コマンドのサブルーチン /
880  * Perform the basic "close" command
881  * @param y 対象を行うマスのY座標
882  * @param x 対象を行うマスのX座標
883  * @return 実際に処理が行われた場合TRUEを返す。
884  * @details
885  * Assume destination is an open/broken door
886  * Assume there is no monster blocking the destination
887  * Returns TRUE if repeated commands may continue
888  */
889 static bool exe_close(player_type *creature_ptr, POSITION y, POSITION x)
890 {
891         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
892         FEAT_IDX old_feat = g_ptr->feat;
893         bool more = FALSE;
894
895         take_turn(creature_ptr, 100);
896
897         /* Seeing true feature code (ignore mimic) */
898
899         /* Open door */
900         if (!have_flag(f_info[old_feat].flags, FF_CLOSE))
901         {
902                 return more;
903         }
904         
905         s16b closed_feat = feat_state(old_feat, FF_CLOSE);
906
907         /* Hack -- object in the way */
908         if ((g_ptr->o_idx || (g_ptr->info & CAVE_OBJECT)) &&
909                 (closed_feat != old_feat) && !have_flag(f_info[closed_feat].flags, FF_DROP))
910         {
911                 msg_print(_("何かがつっかえて閉まらない。", "There seems stuck."));
912         }
913         else
914         {
915                 /* Close the door */
916                 cave_alter_feat(creature_ptr, y, x, FF_CLOSE);
917
918                 /* Broken door */
919                 if (old_feat == g_ptr->feat)
920                 {
921                         msg_print(_("ドアは壊れてしまっている。", "The door appears to be broken."));
922                 }
923                 else
924                 {
925                         sound(SOUND_SHUTDOOR);
926                 }
927         }
928
929         return more;
930 }
931
932
933 /*!
934  * @brief 「閉じる」コマンドのメインルーチン /
935  * Close an open door.
936  * @return なし
937  * @details
938  * Unlocking a locked door/chest is worth one experience point.
939  */
940 void do_cmd_close(player_type *creature_ptr)
941 {
942         POSITION y, x;
943         DIRECTION dir;
944
945         bool more = FALSE;
946
947         if (creature_ptr->wild_mode) return;
948
949         if (creature_ptr->special_defense & KATA_MUSOU)
950         {
951                 set_action(creature_ptr, ACTION_NONE);
952         }
953
954         /* Option: Pick a direction */
955         if (easy_open)
956         {
957                 /* Count open doors */
958                 if (count_dt(creature_ptr, &y, &x, is_open, FALSE) == 1)
959                 {
960                         command_dir = coords_to_dir(creature_ptr, y, x);
961                 }
962         }
963
964         /* Allow repeated command */
965         if (command_arg)
966         {
967                 /* Set repeat count */
968                 command_rep = command_arg - 1;
969                 creature_ptr->redraw |= (PR_STATE);
970
971                 /* Cancel the arg */
972                 command_arg = 0;
973         }
974
975         /* Get a "repeated" direction */
976         if (get_rep_dir(&dir, FALSE))
977         {
978                 grid_type *g_ptr;
979                 FEAT_IDX feat;
980
981                 y = creature_ptr->y + ddy[dir];
982                 x = creature_ptr->x + ddx[dir];
983                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
984
985                 /* Feature code (applying "mimic" field) */
986                 feat = get_feat_mimic(g_ptr);
987
988                 /* Require open/broken door */
989                 if (!have_flag(f_info[feat].flags, FF_CLOSE))
990                 {
991                         msg_print(_("そこには閉じるものが見当たらない。", "You see nothing there to close."));
992                 }
993
994                 /* Monster in the way */
995                 else if (g_ptr->m_idx)
996                 {
997                         take_turn(creature_ptr, 100);
998
999                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1000
1001                         /* Attack */
1002                         py_attack(creature_ptr, y, x, 0);
1003                 }
1004
1005                 /* Close the door */
1006                 else
1007                 {
1008                         /* Close the door */
1009                         more = exe_close(creature_ptr, y, x);
1010                 }
1011         }
1012
1013         /* Cancel repeat unless we may continue */
1014         if (!more) disturb(creature_ptr, FALSE, FALSE);
1015 }
1016
1017
1018 /*!
1019  * @brief 「掘る」コマンドを該当のマスに行えるかの判定と結果メッセージの表示 /
1020  * Determine if a given grid may be "tunneled"
1021  * @param y 対象を行うマスのY座標
1022  * @param x 対象を行うマスのX座標
1023  * @return 
1024  */
1025 static bool do_cmd_tunnel_test(floor_type *floor_ptr, POSITION y, POSITION x)
1026 {
1027         grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1028
1029         /* Must have knowledge */
1030         if (!(g_ptr->info & CAVE_MARK))
1031         {
1032                 msg_print(_("そこには何も見当たらない。", "You see nothing there."));
1033
1034                 return FALSE;
1035         }
1036
1037         /* Must be a wall/door/etc */
1038         if (!cave_have_flag_grid(g_ptr, FF_TUNNEL))
1039         {
1040                 msg_print(_("そこには掘るものが見当たらない。", "You see nothing there to tunnel."));
1041
1042                 return FALSE;
1043         }
1044
1045         return TRUE;
1046 }
1047
1048
1049 /*!
1050  * @brief 「掘る」動作コマンドのサブルーチン /
1051  * Perform the basic "tunnel" command
1052  * @param y 対象を行うマスのY座標
1053  * @param x 対象を行うマスのX座標
1054  * @return 実際に処理が行われた場合TRUEを返す。
1055  * @details
1056  * Assumes that no monster is blocking the destination
1057  * Do not use twall anymore
1058  * Returns TRUE if repeated commands may continue
1059  */
1060 static bool exe_tunnel(player_type *creature_ptr, POSITION y, POSITION x)
1061 {
1062         grid_type *g_ptr;
1063         feature_type *f_ptr, *mimic_f_ptr;
1064         int power;
1065         concptr name;
1066         bool more = FALSE;
1067
1068         /* Verify legality */
1069         if (!do_cmd_tunnel_test(creature_ptr->current_floor_ptr, y, x)) return FALSE;
1070
1071         take_turn(creature_ptr, 100);
1072
1073         g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1074         f_ptr = &f_info[g_ptr->feat];
1075         power = f_ptr->power;
1076
1077         /* Feature code (applying "mimic" field) */
1078         mimic_f_ptr = &f_info[get_feat_mimic(g_ptr)];
1079
1080         name = f_name + mimic_f_ptr->name;
1081
1082         sound(SOUND_DIG);
1083
1084         if (have_flag(f_ptr->flags, FF_PERMANENT))
1085         {
1086                 /* Titanium */
1087                 if (have_flag(mimic_f_ptr->flags, FF_PERMANENT))
1088                 {
1089                         msg_print(_("この岩は硬すぎて掘れないようだ。", "This seems to be permanent rock."));
1090                 }
1091
1092                 /* Map border (mimiccing Permanent wall) */
1093                 else
1094                 {
1095                         msg_print(_("そこは掘れない!", "You can't tunnel through that!"));
1096                 }
1097         }
1098
1099         /* Dig or tunnel */
1100         else if (have_flag(f_ptr->flags, FF_CAN_DIG))
1101         {
1102                 /* Dig */
1103                 if (creature_ptr->skill_dig > randint0(20 * power))
1104                 {
1105                         msg_format(_("%sをくずした。", "You have removed the %s."), name);
1106
1107                         /* Remove the feature */
1108                         cave_alter_feat(creature_ptr, y, x, FF_TUNNEL);
1109                         creature_ptr->update |= (PU_FLOW);
1110                 }
1111                 else
1112                 {
1113                         /* Message, keep digging */
1114                         msg_format(_("%sをくずしている。", "You dig into the %s."), name);
1115                         
1116                         more = TRUE;
1117                 }
1118         }
1119
1120         else
1121         {
1122                 bool tree = have_flag(mimic_f_ptr->flags, FF_TREE);
1123
1124                 /* Tunnel */
1125                 if (creature_ptr->skill_dig > power + randint0(40 * power))
1126                 {
1127                         if (tree) msg_format(_("%sを切り払った。", "You have cleared away the %s."), name);
1128                         else
1129                         {
1130                                 msg_print(_("穴を掘り終えた。", "You have finished the tunnel."));
1131                                 creature_ptr->update |= (PU_FLOW);
1132                         }
1133                         
1134                         if (have_flag(f_ptr->flags, FF_GLASS)) sound(SOUND_GLASS);
1135
1136                         /* Remove the feature */
1137                         cave_alter_feat(creature_ptr, y, x, FF_TUNNEL);
1138
1139                         chg_virtue(creature_ptr, V_DILIGENCE, 1);
1140                         chg_virtue(creature_ptr, V_NATURE, -1);
1141                 }
1142
1143                 /* Keep trying */
1144                 else
1145                 {
1146                         if (tree)
1147                         {
1148                                 /* We may continue chopping */
1149                                 msg_format(_("%sを切っている。", "You chop away at the %s."), name);
1150                                 /* Occasional Search XXX XXX */
1151                                 if (randint0(100) < 25) search(creature_ptr);
1152                         }
1153                         else
1154                         {
1155                                 /* We may continue tunelling */
1156                                 msg_format(_("%sに穴を掘っている。", "You tunnel into the %s."), name);
1157                         }
1158
1159                         more = TRUE;
1160                 }
1161         }
1162
1163         if (is_hidden_door(g_ptr))
1164         {
1165                 /* Occasional Search XXX XXX */
1166                 if (randint0(100) < 25) search(creature_ptr);
1167         }
1168
1169         return more;
1170 }
1171
1172
1173 /*!
1174  * @brief 「掘る」動作コマンドのメインルーチン /
1175  * Tunnels through "walls" (including rubble and closed doors)
1176  * @return なし
1177  * @details
1178  * <pre>
1179  * Note that you must tunnel in order to hit invisible monsters
1180  * in walls, though moving into walls still takes a turn anyway.
1181  *
1182  * Digging is very difficult without a "digger" weapon, but can be
1183  * accomplished by strong players using heavy weapons.
1184  * </pre>
1185  */
1186 void do_cmd_tunnel(player_type *creature_ptr)
1187 {
1188         POSITION y, x;
1189         DIRECTION dir;
1190         grid_type *g_ptr;
1191         FEAT_IDX feat;
1192
1193         bool more = FALSE;
1194
1195         if (creature_ptr->special_defense & KATA_MUSOU)
1196         {
1197                 set_action(creature_ptr, ACTION_NONE);
1198         }
1199
1200         /* Allow repeated command */
1201         if (command_arg)
1202         {
1203                 /* Set repeat count */
1204                 command_rep = command_arg - 1;
1205                 creature_ptr->redraw |= (PR_STATE);
1206
1207                 /* Cancel the arg */
1208                 command_arg = 0;
1209         }
1210
1211         /* Get a direction to tunnel, or Abort */
1212         if (get_rep_dir(&dir,FALSE))
1213         {
1214                 /* Get location */
1215                 y = creature_ptr->y + ddy[dir];
1216                 x = creature_ptr->x + ddx[dir];
1217
1218                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1219
1220                 /* Feature code (applying "mimic" field) */
1221                 feat = get_feat_mimic(g_ptr);
1222
1223                 /* No tunnelling through doors */
1224                 if (have_flag(f_info[feat].flags, FF_DOOR))
1225                 {
1226                         msg_print(_("ドアは掘れない。", "You cannot tunnel through doors."));
1227                 }
1228
1229                 /* No tunnelling through most features */
1230                 else if (!have_flag(f_info[feat].flags, FF_TUNNEL))
1231                 {
1232                         msg_print(_("そこは掘れない。", "You can't tunnel through that."));
1233                 }
1234
1235                 /* A monster is in the way */
1236                 else if (g_ptr->m_idx)
1237                 {
1238                         take_turn(creature_ptr, 100);
1239                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1240
1241                         /* Attack */
1242                         py_attack(creature_ptr, y, x, 0);
1243                 }
1244
1245                 /* Try digging */
1246                 else
1247                 {
1248                         /* Tunnel through walls */
1249                         more = exe_tunnel(creature_ptr, y, x);
1250                 }
1251         }
1252
1253         /* Cancel repetition unless we can continue */
1254         if (!more) disturb(creature_ptr, FALSE, FALSE);
1255 }
1256
1257 /*!
1258  * @brief 移動処理による簡易な「開く」処理 /
1259  * easy_open_door --
1260  * @return 開く処理が実際に試みられた場合TRUEを返す
1261  * @details
1262  * <pre>
1263  *      If there is a jammed/closed/locked door at the given location,
1264  *      then attempt to unlock/open it. Return TRUE if an attempt was
1265  *      made (successful or not), otherwise return FALSE.
1266  *
1267  *      The code here should be nearly identical to that in
1268  *      do_cmd_open_test() and exe_open().
1269  * </pre>
1270  */
1271 bool easy_open_door(player_type *creature_ptr, POSITION y, POSITION x)
1272 {
1273         int i, j;
1274
1275         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1276         feature_type *f_ptr = &f_info[g_ptr->feat];
1277
1278         /* Must be a closed door */
1279         if (!is_closed_door(g_ptr->feat))
1280         {
1281                 return FALSE;
1282         }
1283
1284         /* Jammed door */
1285         if (!have_flag(f_ptr->flags, FF_OPEN))
1286         {
1287                 /* Stuck */
1288                 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(g_ptr)].name);
1289
1290         }
1291
1292         /* Locked door */
1293         else if (f_ptr->power)
1294         {
1295                 /* Disarm factor */
1296                 i = creature_ptr->skill_dis;
1297
1298                 /* Penalize some conditions */
1299                 if (creature_ptr->blind || no_lite(creature_ptr)) i = i / 10;
1300                 if (creature_ptr->confused || creature_ptr->image) i = i / 10;
1301
1302                 /* Extract the lock power */
1303                 j = f_ptr->power;
1304
1305                 /* Extract the difficulty */
1306                 j = i - (j * 4);
1307
1308                 /* Always have a small chance of success */
1309                 if (j < 2) j = 2;
1310
1311                 /* Success */
1312                 if (randint0(100) < j)
1313                 {
1314                         msg_print(_("鍵をはずした。", "You have picked the lock."));
1315
1316                         /* Open the door */
1317                         cave_alter_feat(creature_ptr, y, x, FF_OPEN);
1318
1319                         sound(SOUND_OPENDOOR);
1320
1321                         /* Experience */
1322                         gain_exp(creature_ptr, 1);
1323                 }
1324
1325                 /* Failure */
1326                 else
1327                 {
1328                         /* Failure */
1329                         if (flush_failure) flush();
1330
1331                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
1332
1333                 }
1334         }
1335
1336         /* Closed door */
1337         else
1338         {
1339                 /* Open the door */
1340                 cave_alter_feat(creature_ptr, y, x, FF_OPEN);
1341
1342                 sound(SOUND_OPENDOOR);
1343         }
1344
1345         return TRUE;
1346 }
1347
1348 /*!
1349  * @brief 箱のトラップを解除する実行処理 /
1350  * Perform the basic "disarm" command
1351  * @param y 解除を行うマスのY座標
1352  * @param x 解除を行うマスのX座標
1353  * @param o_idx 箱のオブジェクトID
1354  * @return ターンを消費する処理が行われた場合TRUEを返す
1355  * @details
1356  * <pre>
1357  * Assume destination is a visible trap
1358  * Assume there is no monster blocking the destination
1359  * Returns TRUE if repeated commands may continue
1360  * </pre>
1361  */
1362 static bool exe_disarm_chest(player_type *creature_ptr, POSITION y, POSITION x, OBJECT_IDX o_idx)
1363 {
1364         int i, j;
1365         bool more = FALSE;
1366         object_type *o_ptr = &creature_ptr->current_floor_ptr->o_list[o_idx];
1367
1368         take_turn(creature_ptr, 100);
1369
1370         /* Get the "disarm" factor */
1371         i = creature_ptr->skill_dis;
1372
1373         /* Penalize some conditions */
1374         if (creature_ptr->blind || no_lite(creature_ptr)) i = i / 10;
1375         if (creature_ptr->confused || creature_ptr->image) i = i / 10;
1376
1377         /* Extract the difficulty */
1378         j = i - o_ptr->pval;
1379
1380         /* Always have a small chance of success */
1381         if (j < 2) j = 2;
1382
1383         /* Must find the trap first. */
1384         if (!object_is_known(o_ptr))
1385         {
1386                 msg_print(_("トラップが見あたらない。", "I don't see any traps."));
1387
1388         }
1389
1390         /* Already disarmed/unlocked */
1391         else if (o_ptr->pval <= 0)
1392         {
1393                 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1394         }
1395
1396         /* No traps to find. */
1397         else if (!chest_traps[o_ptr->pval])
1398         {
1399                 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1400         }
1401
1402         /* Success (get a lot of experience) */
1403         else if (randint0(100) < j)
1404         {
1405                 msg_print(_("箱に仕掛けられていたトラップを解除した。", "You have disarmed the chest."));
1406                 gain_exp(creature_ptr, o_ptr->pval);
1407                 o_ptr->pval = (0 - o_ptr->pval);
1408         }
1409
1410         /* Failure -- Keep trying */
1411         else if ((i > 5) && (randint1(i) > 5))
1412         {
1413                 /* We may keep trying */
1414                 more = TRUE;
1415                 if (flush_failure) flush();
1416                 msg_print(_("箱のトラップ解除に失敗した。", "You failed to disarm the chest."));
1417         }
1418
1419         /* Failure -- Set off the trap */
1420         else
1421         {
1422                 msg_print(_("トラップを作動させてしまった!", "You set off a trap!"));
1423                 sound(SOUND_FAIL);
1424                 chest_trap(creature_ptr, y, x, o_idx);
1425         }
1426
1427         return (more);
1428 }
1429
1430
1431 /*!
1432  * @brief 箱のトラップを解除するコマンドのサブルーチン /
1433  * Perform the basic "disarm" command
1434  * @param y 解除を行うマスのY座標
1435  * @param x 解除を行うマスのX座標
1436  * @param dir プレイヤーからみた方向ID
1437  * @return ターンを消費する処理が行われた場合TRUEを返す
1438  * @details
1439  * <pre>
1440  * Assume destination is a visible trap
1441  * Assume there is no monster blocking the destination
1442  * Returns TRUE if repeated commands may continue
1443  * </pre>
1444  */
1445
1446 bool exe_disarm(player_type *creature_ptr, POSITION y, POSITION x, DIRECTION dir)
1447 {
1448         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1449
1450         /* Get feature */
1451         feature_type *f_ptr = &f_info[g_ptr->feat];
1452
1453         /* Access trap name */
1454         concptr name = (f_name + f_ptr->name);
1455
1456         /* Extract trap "power" */
1457         int power = f_ptr->power;
1458         bool more = FALSE;
1459
1460         /* Get the "disarm" factor */
1461         int i = creature_ptr->skill_dis;
1462         int j;
1463
1464         take_turn(creature_ptr, 100);
1465
1466         /* Penalize some conditions */
1467         if (creature_ptr->blind || no_lite(creature_ptr)) i = i / 10;
1468         if (creature_ptr->confused || creature_ptr->image) i = i / 10;
1469
1470         /* Extract the difficulty */
1471         j = i - power;
1472
1473         /* Always have a small chance of success */
1474         if (j < 2) j = 2;
1475
1476         /* Success */
1477         if (randint0(100) < j)
1478         {
1479                 msg_format(_("%sを解除した。", "You have disarmed the %s."), name);
1480                 
1481                 /* Reward */
1482                 gain_exp(creature_ptr, power);
1483
1484                 /* Remove the trap */
1485                 cave_alter_feat(creature_ptr, y, x, FF_DISARM);
1486
1487                 /* Move the player onto the trap */
1488                 move_player(creature_ptr, dir, easy_disarm, FALSE);
1489         }
1490
1491         /* Failure -- Keep trying */
1492         else if ((i > 5) && (randint1(i) > 5))
1493         {
1494                 /* Failure */
1495                 if (flush_failure) flush();
1496
1497                 msg_format(_("%sの解除に失敗した。", "You failed to disarm the %s."), name);
1498
1499                 /* We may keep trying */
1500                 more = TRUE;
1501         }
1502
1503         /* Failure -- Set off the trap */
1504         else
1505         {
1506                 msg_format(_("%sを作動させてしまった!", "You set off the %s!"), name);
1507                 /* Move the player onto the trap */
1508                 move_player(creature_ptr, dir, easy_disarm, FALSE);
1509         }
1510
1511         return (more);
1512 }
1513
1514
1515 /*!
1516  * @brief 箱、床のトラップ解除処理双方の統合メインルーチン /
1517  * Disarms a trap, or chest
1518  * @return なし
1519  */
1520 void do_cmd_disarm(player_type *creature_ptr)
1521 {
1522         POSITION y, x;
1523         DIRECTION dir;
1524         OBJECT_IDX o_idx;
1525
1526         bool more = FALSE;
1527
1528         if (creature_ptr->wild_mode) return;
1529
1530         if (creature_ptr->special_defense & KATA_MUSOU)
1531         {
1532                 set_action(creature_ptr, ACTION_NONE);
1533         }
1534
1535         /* Option: Pick a direction */
1536         if (easy_disarm)
1537         {
1538                 int num_traps, num_chests;
1539
1540                 /* Count visible traps */
1541                 num_traps = count_dt(creature_ptr, &y, &x, is_trap, TRUE);
1542
1543                 /* Count chests (trapped) */
1544                 num_chests = count_chests(creature_ptr, &y, &x, TRUE);
1545
1546                 /* See if only one target */
1547                 if (num_traps || num_chests)
1548                 {
1549                         bool too_many = (num_traps && num_chests) || (num_traps > 1) || (num_chests > 1);
1550                         if (!too_many) command_dir = coords_to_dir(creature_ptr, y, x);
1551                 }
1552         }
1553         
1554         /* Allow repeated command */
1555         if (command_arg)
1556         {
1557                 /* Set repeat count */
1558                 command_rep = command_arg - 1;
1559                 creature_ptr->redraw |= (PR_STATE);
1560
1561                 /* Cancel the arg */
1562                 command_arg = 0;
1563         }
1564
1565         /* Get a direction (or abort) */
1566         if (get_rep_dir(&dir,TRUE))
1567         {
1568                 grid_type *g_ptr;
1569                 FEAT_IDX feat;
1570
1571                 y = creature_ptr->y + ddy[dir];
1572                 x = creature_ptr->x + ddx[dir];
1573                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1574
1575                 /* Feature code (applying "mimic" field) */
1576                 feat = get_feat_mimic(g_ptr);
1577
1578                 /* Check for chests */
1579                 o_idx = chest_check(creature_ptr->current_floor_ptr, y, x, TRUE);
1580
1581                 /* Disarm a trap */
1582                 if (!is_trap(feat) && !o_idx)
1583                 {
1584                         msg_print(_("そこには解除するものが見当たらない。", "You see nothing there to disarm."));
1585                 }
1586
1587                 /* Monster in the way */
1588                 else if (g_ptr->m_idx && creature_ptr->riding != g_ptr->m_idx)
1589                 {
1590                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1591
1592                         /* Attack */
1593                         py_attack(creature_ptr, y, x, 0);
1594                 }
1595
1596                 /* Disarm chest */
1597                 else if (o_idx)
1598                 {
1599                         more = exe_disarm_chest(creature_ptr, y, x, o_idx);
1600                 }
1601
1602                 /* Disarm trap */
1603                 else
1604                 {
1605                         more = exe_disarm(creature_ptr, y, x, dir);
1606                 }
1607         }
1608
1609         /* Cancel repeat unless told not to */
1610         if (!more) disturb(creature_ptr, FALSE, FALSE);
1611 }
1612
1613
1614 /*!
1615  * @brief 「打ち破る」動作コマンドのサブルーチン /
1616  * Perform the basic "bash" command
1617  * @param y 対象を行うマスのY座標
1618  * @param x 対象を行うマスのX座標
1619  * @param dir プレイヤーから見たターゲットの方角ID
1620  * @return 実際に処理が行われた場合TRUEを返す。
1621  * @details
1622  * <pre>
1623  * Assume destination is a closed/locked/jammed door
1624  * Assume there is no monster blocking the destination
1625  * Returns TRUE if repeated commands may continue
1626  * </pre>
1627  */
1628 static bool do_cmd_bash_aux(player_type *creature_ptr, POSITION y, POSITION x, DIRECTION dir)
1629 {
1630         grid_type       *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1631
1632         /* Get feature */
1633         feature_type *f_ptr = &f_info[g_ptr->feat];
1634
1635         /* Hack -- Bash power based on strength */
1636         /* (Ranges from 3 to 20 to 100 to 200) */
1637         int bash = adj_str_blow[creature_ptr->stat_ind[A_STR]];
1638
1639         /* Extract door power */
1640         int temp = f_ptr->power;
1641
1642         bool            more = FALSE;
1643
1644         concptr name = f_name + f_info[get_feat_mimic(g_ptr)].name;
1645
1646         take_turn(creature_ptr, 100);
1647
1648         msg_format(_("%sに体当たりをした!", "You smash into the %s!"), name);
1649
1650         /* Compare bash power to door power */
1651         temp = (bash - (temp * 10));
1652
1653         if (creature_ptr->pclass == CLASS_BERSERKER) temp *= 2;
1654
1655         /* Hack -- always have a chance */
1656         if (temp < 1) temp = 1;
1657
1658         /* Hack -- attempt to bash down the door */
1659         if (randint0(100) < temp)
1660         {
1661                 msg_format(_("%sを壊した!", "The %s crashes open!"), name);
1662
1663                 sound(have_flag(f_ptr->flags, FF_GLASS) ? SOUND_GLASS : SOUND_OPENDOOR);
1664
1665                 /* Break down the door */
1666                 if ((randint0(100) < 50) || (feat_state(g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS))
1667                 {
1668                         cave_alter_feat(creature_ptr, y, x, FF_BASH);
1669                 }
1670
1671                 /* Open the door */
1672                 else
1673                 {
1674                         cave_alter_feat(creature_ptr, y, x, FF_OPEN);
1675                 }
1676
1677                 /* Hack -- Fall through the door */
1678                 move_player(creature_ptr, dir, FALSE, FALSE);
1679         }
1680
1681         /* Saving throw against stun */
1682         else if (randint0(100) < adj_dex_safe[creature_ptr->stat_ind[A_DEX]] +
1683                  creature_ptr->lev)
1684         {
1685                 msg_format(_("この%sは頑丈だ。", "The %s holds firm."), name);
1686
1687                 /* Allow repeated bashing */
1688                 more = TRUE;
1689         }
1690
1691         /* High dexterity yields coolness */
1692         else
1693         {
1694                 msg_print(_("体のバランスをくずしてしまった。", "You are off-balance."));
1695
1696                 /* Hack -- Lose balance ala paralysis */
1697                 (void)set_paralyzed(creature_ptr, creature_ptr->paralyzed + 2 + randint0(2));
1698         }
1699
1700         return (more);
1701 }
1702
1703
1704 /*!
1705  * @brief 「打ち破る」動作コマンドのメインルーチン /
1706  * Bash open a door, success based on character strength
1707  * @return なし
1708  * @details
1709  * <pre>
1710  * For a closed door, pval is positive if locked; negative if stuck.
1711  *
1712  * For an open door, pval is positive for a broken door.
1713  *
1714  * A closed door can be opened - harder if locked. Any door might be
1715  * bashed open (and thereby broken). Bashing a door is (potentially)
1716  * faster! You move into the door way. To open a stuck door, it must
1717  * be bashed. A closed door can be jammed (see do_cmd_spike()).
1718  *
1719  * Creatures can also open or bash doors, see elsewhere.
1720  * </pre>
1721  */
1722 void do_cmd_bash(player_type *creature_ptr)
1723 {
1724         POSITION y, x;
1725         DIRECTION dir;
1726         grid_type *g_ptr;
1727         bool more = FALSE;
1728
1729         if (creature_ptr->wild_mode) return;
1730
1731         if (creature_ptr->special_defense & KATA_MUSOU)
1732         {
1733                 set_action(creature_ptr, ACTION_NONE);
1734         }
1735
1736         /* Allow repeated command */
1737         if (command_arg)
1738         {
1739                 /* Set repeat count */
1740                 command_rep = command_arg - 1;
1741                 creature_ptr->redraw |= (PR_STATE);
1742
1743                 /* Cancel the arg */
1744                 command_arg = 0;
1745         }
1746
1747         /* Get a "repeated" direction */
1748         if (get_rep_dir(&dir,FALSE))
1749         {
1750                 FEAT_IDX feat;
1751
1752                 /* Bash location */
1753                 y = creature_ptr->y + ddy[dir];
1754                 x = creature_ptr->x + ddx[dir];
1755
1756                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1757
1758                 /* Feature code (applying "mimic" field) */
1759                 feat = get_feat_mimic(g_ptr);
1760
1761                 /* Nothing useful */
1762                 if (!have_flag(f_info[feat].flags, FF_BASH))
1763                 {
1764                         msg_print(_("そこには体当たりするものが見当たらない。", "You see nothing there to bash."));
1765                 }
1766
1767                 /* Monster in the way */
1768                 else if (g_ptr->m_idx)
1769                 {
1770                         take_turn(creature_ptr, 100);
1771
1772                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1773
1774                         /* Attack */
1775                         py_attack(creature_ptr, y, x, 0);
1776                 }
1777
1778                 /* Bash a closed door */
1779                 else
1780                 {
1781                         /* Bash the door */
1782                         more = do_cmd_bash_aux(creature_ptr, y, x, dir);
1783                 }
1784         }
1785
1786         /* Unless valid action taken, cancel bash */
1787         if (!more) disturb(creature_ptr, FALSE, FALSE);
1788 }
1789
1790
1791 /*!
1792  * @brief 特定のマスに影響を及ぼすための汎用的コマンド
1793  * @return なし
1794  * @details
1795  * <pre>
1796  * Manipulate an adjacent grid in some way
1797  *
1798  * Attack monsters, tunnel through walls, disarm traps, open doors.
1799  *
1800  * Consider confusion 
1801  *
1802  * This command must always take a turn, to prevent free detection
1803  * of invisible monsters.
1804  * </pre>
1805  */
1806 void do_cmd_alter(player_type *creature_ptr)
1807 {
1808         POSITION y, x;
1809         DIRECTION dir;
1810         grid_type *g_ptr;
1811         bool more = FALSE;
1812
1813         if (creature_ptr->special_defense & KATA_MUSOU)
1814         {
1815                 set_action(creature_ptr, ACTION_NONE);
1816         }
1817
1818         /* Allow repeated command */
1819         if (command_arg)
1820         {
1821                 /* Set repeat count */
1822                 command_rep = command_arg - 1;
1823                 creature_ptr->redraw |= (PR_STATE);
1824
1825                 /* Cancel the arg */
1826                 command_arg = 0;
1827         }
1828
1829         /* Get a direction */
1830         if (get_rep_dir(&dir,TRUE))
1831         {
1832                 FEAT_IDX feat;
1833                 feature_type *f_ptr;
1834
1835                 y = creature_ptr->y + ddy[dir];
1836                 x = creature_ptr->x + ddx[dir];
1837
1838                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1839
1840                 /* Feature code (applying "mimic" field) */
1841                 feat = get_feat_mimic(g_ptr);
1842                 f_ptr = &f_info[feat];
1843
1844                 take_turn(creature_ptr, 100);
1845
1846                 if (g_ptr->m_idx)
1847                 {
1848                         py_attack(creature_ptr, y, x, 0);
1849                 }
1850
1851                 /* Locked doors */
1852                 else if (have_flag(f_ptr->flags, FF_OPEN))
1853                 {
1854                         more = exe_open(creature_ptr, y, x);
1855                 }
1856
1857                 /* Bash jammed doors */
1858                 else if (have_flag(f_ptr->flags, FF_BASH))
1859                 {
1860                         more = do_cmd_bash_aux(creature_ptr, y, x, dir);
1861                 }
1862
1863                 /* Tunnel through walls */
1864                 else if (have_flag(f_ptr->flags, FF_TUNNEL))
1865                 {
1866                         more = exe_tunnel(creature_ptr, y, x);
1867                 }
1868
1869                 /* Close open doors */
1870                 else if (have_flag(f_ptr->flags, FF_CLOSE))
1871                 {
1872                         more = exe_close(creature_ptr, y, x);
1873                 }
1874
1875                 /* Disarm traps */
1876                 else if (have_flag(f_ptr->flags, FF_DISARM))
1877                 {
1878                         more = exe_disarm(creature_ptr, y, x, dir);
1879                 }
1880
1881                 else
1882                 {
1883                         msg_print(_("何もない空中を攻撃した。", "You attack the empty air."));
1884                 }
1885         }
1886
1887         /* Cancel repetition unless we can continue */
1888         if (!more) disturb(creature_ptr, FALSE, FALSE);
1889 }
1890
1891
1892
1893 /*!
1894  * @brief 「くさびを打つ」ために必要なオブジェクトを所持しているかどうかの判定を返す /
1895  * Find the index of some "spikes", if possible.
1896  * @param ip くさびとして打てるオブジェクトのID
1897  * @return オブジェクトがある場合TRUEを返す
1898  * @details
1899  * <pre>
1900  * Let user choose a pile of spikes, perhaps?
1901  * </pre>
1902  */
1903 static bool get_spike(player_type *creature_ptr, INVENTORY_IDX *ip)
1904 {
1905         INVENTORY_IDX i;
1906
1907         /* Check every item in the pack */
1908         for (i = 0; i < INVEN_PACK; i++)
1909         {
1910                 object_type *o_ptr = &creature_ptr->inventory_list[i];
1911                 if (!o_ptr->k_idx) continue;
1912
1913                 /* Check the "tval" code */
1914                 if (o_ptr->tval == TV_SPIKE)
1915                 {
1916                         /* Save the spike index */
1917                         (*ip) = i;
1918
1919                         /* Success */
1920                         return TRUE;
1921                 }
1922         }
1923
1924         return FALSE;
1925 }
1926
1927
1928 /*!
1929  * @brief 「くさびを打つ」動作コマンドのメインルーチン /
1930  * Jam a closed door with a spike
1931  * @param creature_ptr プレーヤーへの参照ポインタ
1932  * @return なし
1933  * @details
1934  * <pre>
1935  * This command may NOT be repeated
1936  * </pre>
1937  */
1938 void do_cmd_spike(player_type *creature_ptr)
1939 {
1940         DIRECTION dir;
1941
1942         if (creature_ptr->wild_mode) return;
1943         if (creature_ptr->special_defense & KATA_MUSOU)
1944         {
1945                 set_action(creature_ptr, ACTION_NONE);
1946         }
1947
1948         /* Get a "repeated" direction */
1949         if (!get_rep_dir(&dir, FALSE)) return;
1950
1951         POSITION y = creature_ptr->y + ddy[dir];
1952         POSITION x = creature_ptr->x + ddx[dir];
1953         grid_type *g_ptr;
1954         g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1955
1956         /* Feature code (applying "mimic" field) */
1957         FEAT_IDX feat = get_feat_mimic(g_ptr);
1958
1959         /* Require closed door */
1960         INVENTORY_IDX item;
1961         if (!have_flag(f_info[feat].flags, FF_SPIKE))
1962         {
1963                 msg_print(_("そこにはくさびを打てるものが見当たらない。", "You see nothing there to spike."));
1964         }
1965
1966         /* Get a spike */
1967         else if (!get_spike(creature_ptr, &item))
1968         {
1969                 msg_print(_("くさびを持っていない!", "You have no spikes!"));
1970         }
1971
1972         /* Is a monster in the way? */
1973         else if (g_ptr->m_idx)
1974         {
1975                 take_turn(creature_ptr, 100);
1976
1977                 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1978
1979                 /* Attack */
1980                 py_attack(creature_ptr, y, x, 0);
1981         }
1982
1983         /* Go for it */
1984         else
1985         {
1986                 take_turn(creature_ptr, 100);
1987
1988                 /* Successful jamming */
1989                 msg_format(_("%sにくさびを打ち込んだ。", "You jam the %s with a spike."), f_name + f_info[feat].name);
1990                 cave_alter_feat(creature_ptr, y, x, FF_SPIKE);
1991
1992                 vary_item(creature_ptr, item, -1);
1993         }
1994 }
1995
1996
1997 /*!
1998  * @brief 「歩く」動作コマンドのメインルーチン /
1999  * Support code for the "Walk" and "Jump" commands
2000  * @param creature_ptr プレーヤーへの参照ポインタ
2001  * @param pickup アイテムの自動拾いを行うならTRUE
2002  * @return なし
2003  */
2004 void do_cmd_walk(player_type *creature_ptr, bool pickup)
2005 {
2006         /* Allow repeated command */
2007         if (command_arg)
2008         {
2009                 /* Set repeat count */
2010                 command_rep = command_arg - 1;
2011                 creature_ptr->redraw |= (PR_STATE);
2012
2013                 /* Cancel the arg */
2014                 command_arg = 0;
2015         }
2016
2017         /* Get a "repeated" direction */
2018         bool more = FALSE;
2019         DIRECTION dir;
2020         if (get_rep_dir(&dir, FALSE))
2021         {
2022                 take_turn(creature_ptr, 100);
2023
2024                 if ((dir != 5) && (creature_ptr->special_defense & KATA_MUSOU))
2025                 {
2026                         set_action(creature_ptr, ACTION_NONE);
2027                 }
2028
2029                 /* Hack -- In small scale wilderness it takes MUCH more time to move */
2030                 if (creature_ptr->wild_mode) creature_ptr->energy_use *= ((MAX_HGT + MAX_WID) / 2);
2031                 if (creature_ptr->action == ACTION_HAYAGAKE) creature_ptr->energy_use = creature_ptr->energy_use * (45-(creature_ptr->lev/2)) / 100;
2032
2033                 /* Actually move the character */
2034                 move_player(creature_ptr, dir, pickup, FALSE);
2035
2036                 /* Allow more walking */
2037                 more = TRUE;
2038         }
2039
2040         /* Hack again -- Is there a special encounter ??? */
2041         if (creature_ptr->wild_mode && !cave_have_flag_bold(creature_ptr->current_floor_ptr, creature_ptr->y, creature_ptr->x, FF_TOWN))
2042         {
2043                 int tmp = 120 + creature_ptr->lev*10 - wilderness[creature_ptr->y][creature_ptr->x].level + 5;
2044                 if (tmp < 1) 
2045                         tmp = 1;
2046                 if (((wilderness[creature_ptr->y][creature_ptr->x].level + 5) > (creature_ptr->lev / 2)) && randint0(tmp) < (21-creature_ptr->skill_stl))
2047                 {
2048                         /* Inform the player of his horrible fate :=) */
2049                         msg_print(_("襲撃だ!", "You are ambushed !"));
2050
2051                         /* Go into large wilderness view */
2052                         creature_ptr->oldpy = randint1(MAX_HGT-2);
2053                         creature_ptr->oldpx = randint1(MAX_WID-2);
2054                         change_wild_mode(creature_ptr, TRUE);
2055
2056                         /* Give first move to monsters */
2057                         take_turn(creature_ptr, 100);
2058
2059                 }
2060         }
2061
2062         /* Cancel repeat unless we may continue */
2063         if (!more) disturb(creature_ptr, FALSE, FALSE);
2064 }
2065
2066
2067 /*!
2068  * @brief 「走る」動作コマンドのメインルーチン /
2069  * Start running.
2070  * @param creature_ptr プレーヤーへの参照ポインタ
2071  * @return なし
2072  */
2073 void do_cmd_run(player_type *creature_ptr)
2074 {
2075         DIRECTION dir;
2076         if (cmd_limit_confused(creature_ptr)) return;
2077
2078         if (creature_ptr->special_defense & KATA_MUSOU)
2079         {
2080                 set_action(creature_ptr, ACTION_NONE);
2081         }
2082
2083         /* Get a "repeated" direction */
2084         if (get_rep_dir(&dir,FALSE))
2085         {
2086                 /* Hack -- Set the run counter */
2087                 creature_ptr->running = (command_arg ? command_arg : 1000);
2088
2089                 /* First step */
2090                 run_step(dir);
2091         }
2092 }
2093
2094
2095 /*!
2096  * @brief 「留まる」動作コマンドのメインルーチン /
2097  * Stay still.  Search.  Enter stores.
2098  * Pick up treasure if "pickup" is true.
2099  * @param creature_ptr プレーヤーへの参照ポインタ
2100  * @param pickup アイテムの自動拾いを行うならTRUE
2101  * @return なし
2102  */
2103 void do_cmd_stay(player_type *creature_ptr, bool pickup)
2104 {
2105         u32b mpe_mode = MPE_STAYING | MPE_ENERGY_USE;
2106
2107         /* Allow repeated command */
2108         if (command_arg)
2109         {
2110                 /* Set repeat count */
2111                 command_rep = command_arg - 1;
2112                 creature_ptr->redraw |= (PR_STATE);
2113
2114                 /* Cancel the arg */
2115                 command_arg = 0;
2116         }
2117
2118         take_turn(creature_ptr, 100);
2119
2120         if (pickup) mpe_mode |= MPE_DO_PICKUP;
2121         (void)move_player_effect(creature_ptr, creature_ptr->y, creature_ptr->x, mpe_mode);
2122 }
2123
2124
2125 /*!
2126  * @brief 「休む」動作コマンドのメインルーチン /
2127  * Resting allows a player to safely restore his hp     -RAK-
2128  * @param creature_ptr プレーヤーへの参照ポインタ
2129  * @return なし
2130  */
2131 void do_cmd_rest(player_type *creature_ptr)
2132 {
2133         set_action(creature_ptr, ACTION_NONE);
2134
2135         if ((creature_ptr->pclass == CLASS_BARD) && (SINGING_SONG_EFFECT(creature_ptr) || INTERUPTING_SONG_EFFECT(creature_ptr)))
2136         {
2137                 stop_singing(creature_ptr);
2138         }
2139
2140         if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
2141
2142         /* Prompt for time if needed */
2143         if (command_arg <= 0)
2144         {
2145                 concptr p = _("休憩 (0-9999, '*' で HP/MP全快, '&' で必要なだけ): ", 
2146                                    "Rest (0-9999, '*' for HP/SP, '&' as needed): ");
2147
2148 char out_val[80];
2149
2150                 /* Default */
2151                 strcpy(out_val, "&");
2152
2153                 /* Ask for duration */
2154                 if (!get_string(p, out_val, 4)) return;
2155
2156                 /* Rest until done */
2157                 if (out_val[0] == '&')
2158                 {
2159                         command_arg = COMMAND_ARG_REST_UNTIL_DONE;
2160                 }
2161
2162                 /* Rest a lot */
2163                 else if (out_val[0] == '*')
2164                 {
2165                         command_arg = COMMAND_ARG_REST_FULL_HEALING;
2166                 }
2167
2168                 /* Rest some */
2169                 else
2170                 {
2171                         command_arg = (COMMAND_ARG)atoi(out_val);
2172                         if (command_arg <= 0) return;
2173                 }
2174         }
2175
2176         if (command_arg > 9999) command_arg = 9999;
2177
2178         if (creature_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(creature_ptr, FALSE);
2179
2180         /* Take a turn (?) */
2181         take_turn(creature_ptr, 100);
2182
2183         /* The sin of sloth */
2184         if (command_arg > 100) chg_virtue(creature_ptr, V_DILIGENCE, -1);
2185         
2186         /* Why are you sleeping when there's no need?  WAKE UP!*/
2187         if ((creature_ptr->chp == creature_ptr->mhp) &&
2188             (creature_ptr->csp == creature_ptr->msp) &&
2189             !creature_ptr->blind && !creature_ptr->confused &&
2190             !creature_ptr->poisoned && !creature_ptr->afraid &&
2191             !creature_ptr->stun && !creature_ptr->cut &&
2192             !creature_ptr->slow && !creature_ptr->paralyzed &&
2193             !creature_ptr->image && !creature_ptr->word_recall &&
2194             !creature_ptr->alter_reality)
2195                         chg_virtue(creature_ptr, V_DILIGENCE, -1);
2196
2197         /* Save the rest code */
2198         creature_ptr->resting = command_arg;
2199         creature_ptr->action = ACTION_REST;
2200         creature_ptr->update |= (PU_BONUS);
2201         update_creature(creature_ptr);
2202
2203         creature_ptr->redraw |= (PR_STATE);
2204         update_output(creature_ptr);
2205
2206         Term_fresh();
2207 }
2208
2209
2210
2211 /*
2212  * todo Doxygenの加筆求む
2213  * @brief 射撃処理のメインルーチン
2214  * @param creature_ptr プレーヤーへの参照ポインタ
2215  * @param snipe_type ???
2216  * @return なし
2217  */
2218 void do_cmd_fire(player_type *creature_ptr, SPELL_IDX snipe_type)
2219 {
2220         OBJECT_IDX item;
2221         object_type *j_ptr, *ammo_ptr;
2222         concptr q, s;
2223
2224         if(creature_ptr->wild_mode) return;
2225
2226         creature_ptr->is_fired = FALSE; /* not fired yet */
2227
2228         /* Get the "bow" (if any) */
2229         j_ptr = &creature_ptr->inventory_list[INVEN_BOW];
2230
2231         /* Require a launcher */
2232         if (!j_ptr->tval)
2233         {
2234                 msg_print(_("射撃用の武器を持っていない。", "You have nothing to fire with."));
2235                 flush();
2236                 return;
2237         }
2238
2239         if (j_ptr->sval == SV_CRIMSON)
2240         {
2241                 msg_print(_("この武器は発動して使うもののようだ。", "Do activate."));
2242                 flush();
2243                 return;
2244         }
2245
2246         if (j_ptr->sval == SV_HARP)
2247         {
2248                 msg_print(_("この武器で射撃はできない。", "It's not for firing."));
2249                 flush();
2250                 return;
2251         }
2252
2253
2254         if (creature_ptr->special_defense & KATA_MUSOU)
2255         {
2256                 set_action(creature_ptr, ACTION_NONE);
2257         }
2258
2259         q = _("どれを撃ちますか? ", "Fire which item? ");
2260         s = _("発射されるアイテムがありません。", "You have nothing to fire.");
2261
2262         ammo_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), creature_ptr->tval_ammo);
2263         if (!ammo_ptr)
2264         {
2265                 flush();
2266                 return;
2267         }
2268
2269         /* Fire the item */
2270         exe_fire(creature_ptr, item, j_ptr, snipe_type);
2271
2272         if (!creature_ptr->is_fired || creature_ptr->pclass != CLASS_SNIPER) return;
2273
2274         /* Sniper actions after some shootings */
2275         if (snipe_type == SP_AWAY)
2276         {
2277                 teleport_player(creature_ptr, 10 + (creature_ptr->concent * 2), 0L);
2278         }
2279
2280         if (snipe_type == SP_FINAL)
2281         {
2282                 msg_print(_("射撃の反動が体を襲った。", "A reactionary of shooting attacked you. "));
2283                 (void)set_slow(creature_ptr, creature_ptr->slow + randint0(7) + 7, FALSE);
2284                 (void)set_stun(creature_ptr, creature_ptr->stun + randint1(25));
2285         }
2286 }
2287
2288
2289 /*!
2290  * @brief 投射処理メインルーチン /
2291  * Throw an object from the pack or floor.
2292  * @param mult 威力の倍率
2293  * @param creature_ptr プレーヤーへの参照ポインタ
2294  * @param boomerang ブーメラン処理ならばTRUE
2295  * @param shuriken 忍者の手裏剣処理ならばTRUE
2296  * @return ターンを消費した場合TRUEを返す
2297  * @details
2298  * <pre>
2299  * Note: "unseen" monsters are very hard to hit.
2300  *
2301  * Should throwing a weapon do full damage?  Should it allow the magic
2302  * to hit bonus of the weapon to have an effect?  Should it ever cause
2303  * the item to be destroyed?  Should it do any damage at all?
2304  * </pre>
2305  */
2306 bool do_cmd_throw(player_type *creature_ptr, int mult, bool boomerang, OBJECT_IDX shuriken)
2307 {
2308         DIRECTION dir;
2309         OBJECT_IDX item;
2310         int i;
2311         POSITION y, x, ty, tx, prev_y, prev_x;
2312         POSITION ny[19], nx[19];
2313         int chance, tdam, tdis;
2314         int mul, div, dd, ds;
2315         int cur_dis, visible;
2316         PERCENTAGE j;
2317
2318         object_type forge;
2319         object_type *q_ptr;
2320         object_type *o_ptr;
2321
2322         bool hit_body = FALSE;
2323         bool hit_wall = FALSE;
2324         bool equiped_item = FALSE;
2325         bool return_when_thrown = FALSE;
2326
2327         GAME_TEXT o_name[MAX_NLEN];
2328
2329         int msec = delay_factor * delay_factor * delay_factor;
2330
2331         BIT_FLAGS flgs[TR_FLAG_SIZE];
2332         concptr q, s;
2333         bool come_back = FALSE;
2334         bool do_drop = TRUE;
2335
2336         if (creature_ptr->wild_mode) return FALSE;
2337
2338         if (creature_ptr->special_defense & KATA_MUSOU)
2339         {
2340                 set_action(creature_ptr, ACTION_NONE);
2341         }
2342
2343         if (shuriken >= 0)
2344         {
2345                 item = shuriken;
2346                 o_ptr = &creature_ptr->inventory_list[item];
2347         }
2348         else if (boomerang)
2349         {
2350                 if (has_melee_weapon(creature_ptr, INVEN_RARM) && has_melee_weapon(creature_ptr, INVEN_LARM))
2351                 {
2352                         item_tester_hook = item_tester_hook_boomerang;
2353                         q = _("どの武器を投げますか? ", "Throw which item? ");
2354                         s = _("投げる武器がない。", "You have nothing to throw.");
2355                         o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP), 0);
2356                         if (!o_ptr)
2357                         {
2358                                 flush();
2359                                 return FALSE;
2360                         }
2361                 }
2362                 else if (has_melee_weapon(creature_ptr, INVEN_LARM))
2363                 {
2364                         item = INVEN_LARM;
2365                         o_ptr = &creature_ptr->inventory_list[item];
2366                 }
2367                 else
2368                 {
2369                         item = INVEN_RARM;
2370                         o_ptr = &creature_ptr->inventory_list[item];
2371                 }
2372         }
2373         else
2374         {
2375                 q = _("どのアイテムを投げますか? ", "Throw which item? ");
2376                 s = _("投げるアイテムがない。", "You have nothing to throw.");
2377                 o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP), 0);
2378                 if (!o_ptr)
2379                 {
2380                         flush();
2381                         return FALSE;
2382                 }
2383         }
2384
2385         /* Item is cursed */
2386         if (object_is_cursed(o_ptr) && (item >= INVEN_RARM))
2387         {
2388                 msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
2389                 return FALSE;
2390         }
2391
2392         if (creature_ptr->current_floor_ptr->inside_arena && !boomerang)
2393         {
2394                 if (o_ptr->tval != TV_SPIKE)
2395                 {
2396                         msg_print(_("アリーナではアイテムを使えない!", "You're in the arena now. This is hand-to-hand!"));
2397                         msg_print(NULL);
2398
2399                         return FALSE;
2400                 }
2401         }
2402
2403         q_ptr = &forge;
2404         object_copy(q_ptr, o_ptr);
2405
2406         /* Extract the thrown object's flags. */
2407         object_flags(q_ptr, flgs);
2408         torch_flags(q_ptr, flgs);
2409
2410         /* Distribute the charges of rods/wands between the stacks */
2411         distribute_charges(o_ptr, q_ptr, 1);
2412
2413         /* Single object */
2414         q_ptr->number = 1;
2415
2416         object_desc(o_name, q_ptr, OD_OMIT_PREFIX);
2417
2418         if (creature_ptr->mighty_throw) mult += 3;
2419
2420         /* Extract a "distance multiplier" */
2421         /* Changed for 'launcher' mutation */
2422         mul = 10 + 2 * (mult - 1);
2423
2424         /* Enforce a minimum "weight" of one pound */
2425         div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
2426         if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
2427
2428         /* Hack -- Distance -- Reward strength, penalize weight */
2429         tdis = (adj_str_blow[creature_ptr->stat_ind[A_STR]] + 20) * mul / div;
2430
2431         /* Max distance of 10-18 */
2432         if (tdis > mul) tdis = mul;
2433
2434         if (shuriken >= 0)
2435         {
2436                 ty = randint0(101) - 50 + creature_ptr->y;
2437                 tx = randint0(101) - 50 + creature_ptr->x;
2438         }
2439         else
2440         {
2441                 project_length = tdis + 1;
2442
2443                 /* Get a direction (or cancel) */
2444                 if (!get_aim_dir(&dir)) return FALSE;
2445
2446                 /* Predict the "target" location */
2447                 tx = creature_ptr->x + 99 * ddx[dir];
2448                 ty = creature_ptr->y + 99 * ddy[dir];
2449
2450                 /* Check for "target request" */
2451                 if ((dir == 5) && target_okay())
2452                 {
2453                         tx = target_col;
2454                         ty = target_row;
2455                 }
2456
2457                 project_length = 0;  /* reset to default */
2458         }
2459
2460         if ((q_ptr->name1 == ART_MJOLLNIR) ||
2461             (q_ptr->name1 == ART_AEGISFANG) || boomerang)
2462                 return_when_thrown = TRUE;
2463
2464         if (item >= 0)
2465         {
2466                 inven_item_increase(creature_ptr, item, -1);
2467                 if (!return_when_thrown)
2468                         inven_item_describe(creature_ptr, item);
2469                 inven_item_optimize(creature_ptr, item);
2470         }
2471         else
2472         {
2473                 floor_item_increase(creature_ptr->current_floor_ptr, 0 - item, -1);
2474                 floor_item_optimize(creature_ptr->current_floor_ptr, 0 - item);
2475         }
2476
2477         if (item >= INVEN_RARM)
2478         {
2479                 equiped_item = TRUE;
2480                 creature_ptr->redraw |= (PR_EQUIPPY);
2481         }
2482
2483         take_turn(creature_ptr, 100);
2484
2485         /* Rogue and Ninja gets bonus */
2486         if ((creature_ptr->pclass == CLASS_ROGUE) || (creature_ptr->pclass == CLASS_NINJA))
2487                 creature_ptr->energy_use -= creature_ptr->lev;
2488
2489         /* Start at the player */
2490         y = creature_ptr->y;
2491         x = creature_ptr->x;
2492
2493         handle_stuff(creature_ptr);
2494
2495         if ((creature_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
2496         else shuriken = FALSE;
2497
2498         /* Chance of hitting */
2499         if (have_flag(flgs, TR_THROW)) chance = ((creature_ptr->skill_tht) +
2500                 ((creature_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
2501         else chance = (creature_ptr->skill_tht + (creature_ptr->to_h_b * BTH_PLUS_ADJ));
2502
2503         if (shuriken) chance *= 2;
2504
2505         prev_y = y;
2506         prev_x = x;
2507
2508         /* Travel until stopped */
2509         for (cur_dis = 0; cur_dis <= tdis; )
2510         {
2511                 /* Hack -- Stop at the target */
2512                 if ((y == ty) && (x == tx)) break;
2513
2514                 /* Calculate the new location (see "project()") */
2515                 ny[cur_dis] = y;
2516                 nx[cur_dis] = x;
2517                 mmove2(&ny[cur_dis], &nx[cur_dis], creature_ptr->y, creature_ptr->x, ty, tx);
2518
2519                 /* Stopped by walls/doors */
2520                 if (!cave_have_flag_bold(creature_ptr->current_floor_ptr, ny[cur_dis], nx[cur_dis], FF_PROJECT))
2521                 {
2522                         hit_wall = TRUE;
2523                         if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !creature_ptr->current_floor_ptr->grid_array[ny[cur_dis]][nx[cur_dis]].m_idx) break;
2524                 }
2525
2526                 /* The player can see the (on screen) missile */
2527                 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(creature_ptr, ny[cur_dis], nx[cur_dis]))
2528                 {
2529                         SYMBOL_CODE c = object_char(q_ptr);
2530                         TERM_COLOR a = object_attr(q_ptr);
2531
2532                         /* Draw, Hilite, Fresh, Pause, Erase */
2533                         print_rel(creature_ptr, c, a, ny[cur_dis], nx[cur_dis]);
2534                         move_cursor_relative(ny[cur_dis], nx[cur_dis]);
2535                         Term_fresh();
2536                         Term_xtra(TERM_XTRA_DELAY, msec);
2537                         lite_spot(ny[cur_dis], nx[cur_dis]);
2538                         Term_fresh();
2539                 }
2540
2541                 /* The player cannot see the missile */
2542                 else
2543                 {
2544                         /* Pause anyway, for consistancy */
2545                         Term_xtra(TERM_XTRA_DELAY, msec);
2546                 }
2547
2548                 prev_y = y;
2549                 prev_x = x;
2550
2551                 /* Save the new location */
2552                 x = nx[cur_dis];
2553                 y = ny[cur_dis];
2554
2555                 /* Advance the distance */
2556                 cur_dis++;
2557
2558                 /* Monster here, Try to hit it */
2559                 if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx)
2560                 {
2561                         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
2562                         monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2563                         GAME_TEXT m_name[MAX_NLEN];
2564                         monster_name(g_ptr->m_idx, m_name);
2565
2566                         /* Check the visibility */
2567                         visible = m_ptr->ml;
2568
2569                         /* Note the collision */
2570                         hit_body = TRUE;
2571
2572                         /* Did we hit it (penalize range) */
2573                         if (test_hit_fire(creature_ptr, chance - cur_dis, m_ptr, m_ptr->ml, o_name))
2574                         {
2575                                 bool fear = FALSE;
2576
2577                                 /* Handle unseen monster */
2578                                 if (!visible)
2579                                 {
2580                                         /* Invisible monster */
2581                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
2582                                 }
2583
2584                                 /* Handle visible monster */
2585                                 else
2586                                 {
2587                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
2588
2589                                         if (m_ptr->ml)
2590                                         {
2591                                                 if (!creature_ptr->image) monster_race_track(m_ptr->ap_r_idx);
2592                                                 health_track(g_ptr->m_idx);
2593                                         }
2594                                 }
2595
2596                                 /* Hack -- Base damage from thrown object */
2597                                 dd = q_ptr->dd;
2598                                 ds = q_ptr->ds;
2599                                 torch_dice(q_ptr, &dd, &ds); /* throwing a torch */
2600                                 tdam = damroll(dd, ds);
2601                                 /* Apply special damage */
2602                                 tdam = tot_dam_aux(creature_ptr, q_ptr, tdam, m_ptr, 0, TRUE);
2603                                 tdam = critical_shot(creature_ptr, q_ptr->weight, q_ptr->to_h, 0, tdam);
2604                                 if (q_ptr->to_d > 0)
2605                                         tdam += q_ptr->to_d;
2606                                 else
2607                                         tdam += -q_ptr->to_d;
2608
2609                                 if (boomerang)
2610                                 {
2611                                         tdam *= (mult+creature_ptr->num_blow[item - INVEN_RARM]);
2612                                         tdam += creature_ptr->to_d_m;
2613                                 }
2614                                 else if (have_flag(flgs, TR_THROW))
2615                                 {
2616                                         tdam *= (3+mult);
2617                                         tdam += creature_ptr->to_d_m;
2618                                 }
2619                                 else
2620                                 {
2621                                         tdam *= mult;
2622                                 }
2623                                 if (shuriken)
2624                                 {
2625                                         tdam += ((creature_ptr->lev+30)*(creature_ptr->lev+30)-900)/55;
2626                                 }
2627
2628                                 /* No negative damage */
2629                                 if (tdam < 0) tdam = 0;
2630
2631                                 /* Modify the damage */
2632                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
2633
2634                                 msg_format_wizard(CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
2635                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
2636
2637                                 /* Hit the monster, check for death */
2638                                 if (mon_take_hit(g_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_idx(m_ptr))))
2639                                 {
2640                                         /* Dead monster */
2641                                 }
2642
2643                                 /* No death */
2644                                 else
2645                                 {
2646                                         message_pain(g_ptr->m_idx, tdam);
2647
2648                                         /* Anger the monster */
2649                                         if ((tdam > 0) && !object_is_potion(q_ptr))
2650                                                 anger_monster(m_ptr);
2651
2652                                         if (fear && m_ptr->ml)
2653                                         {
2654                                                 sound(SOUND_FLEE);
2655                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
2656                                         }
2657                                 }
2658                         }
2659
2660                         /* Stop looking */
2661                         break;
2662                 }
2663         }
2664
2665         /* decrease toach's fuel */
2666         if (hit_body) torch_lost_fuel(q_ptr);
2667
2668         /* Chance of breakage (during attacks) */
2669         j = (hit_body ? breakage_chance(q_ptr, creature_ptr->pclass == CLASS_ARCHER, 0) : 0);
2670
2671         /* Figurines transform */
2672         if ((q_ptr->tval == TV_FIGURINE) && !(creature_ptr->current_floor_ptr->inside_arena))
2673         {
2674                 j = 100;
2675
2676                 if (!(summon_named_creature(0, y, x, q_ptr->pval, !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
2677                         msg_print(_("人形は捻じ曲がり砕け散ってしまった!", "The Figurine writhes and then shatters."));
2678                 else if (object_is_cursed(q_ptr))
2679                         msg_print(_("これはあまり良くない気がする。", "You have a bad feeling about this."));
2680
2681         }
2682
2683         /* Potions smash open */
2684         if (object_is_potion(q_ptr))
2685         {
2686                 if (hit_body || hit_wall || (randint1(100) < j))
2687                 {
2688                         msg_format(_("%sは砕け散った!", "The %s shatters!"), o_name);
2689
2690                         if (potion_smash_effect(0, y, x, q_ptr->k_idx))
2691                         {
2692                                 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[y][x].m_idx];
2693                                 if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx && is_friendly(m_ptr) && !MON_INVULNER(m_ptr))
2694                                 {
2695                                         GAME_TEXT m_name[MAX_NLEN];
2696                                         monster_desc(m_name, m_ptr, 0);
2697                                         msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
2698                                         set_hostile(&creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[y][x].m_idx]);
2699                                 }
2700                         }
2701                         do_drop = FALSE;
2702                 }
2703                 else
2704                 {
2705                         j = 0;
2706                 }
2707         }
2708
2709         if (return_when_thrown)
2710         {
2711                 int back_chance = randint1(30)+20+((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
2712                 char o2_name[MAX_NLEN];
2713                 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
2714
2715                 j = -1;
2716                 if (boomerang) back_chance += 4+randint1(5);
2717                 if (super_boomerang) back_chance += 100;
2718                 object_desc(o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2719
2720                 if((back_chance > 30) && (!one_in_(100) || super_boomerang))
2721                 {
2722                         for (i = cur_dis - 1; i > 0; i--)
2723                         {
2724                                 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(creature_ptr, ny[i], nx[i]))
2725                                 {
2726                                         char c = object_char(q_ptr);
2727                                         byte a = object_attr(q_ptr);
2728
2729                                         /* Draw, Hilite, Fresh, Pause, Erase */
2730                                         print_rel(creature_ptr, c, a, ny[i], nx[i]);
2731                                         move_cursor_relative(ny[i], nx[i]);
2732                                         Term_fresh();
2733                                         Term_xtra(TERM_XTRA_DELAY, msec);
2734                                         lite_spot(ny[i], nx[i]);
2735                                         Term_fresh();
2736                                 }
2737                                 else
2738                                 {
2739                                         /* Pause anyway, for consistancy */
2740                                         Term_xtra(TERM_XTRA_DELAY, msec);
2741                                 }
2742                         }
2743                         if((back_chance > 37) && !creature_ptr->blind && (item >= 0))
2744                         {
2745                                 msg_format(_("%sが手元に返ってきた。", "%s comes back to you."), o2_name);
2746                                 come_back = TRUE;
2747                         }
2748                         else
2749                         {
2750                                 if (item >= 0)
2751                                 {
2752                                         msg_format(_("%sを受け損ねた!", "%s comes backs, but you can't catch!"), o2_name);
2753                                 }
2754                                 else
2755                                 {
2756                                         msg_format(_("%sが返ってきた。", "%s comes back."), o2_name);
2757                                 }
2758                                 y = creature_ptr->y;
2759                                 x = creature_ptr->x;
2760                         }
2761                 }
2762                 else
2763                 {
2764                         msg_format(_("%sが返ってこなかった!", "%s doesn't come back!"), o2_name);
2765                 }
2766         }
2767
2768         if (come_back)
2769         {
2770                 if (item == INVEN_RARM || item == INVEN_LARM)
2771                 {
2772                         /* Access the wield slot */
2773                         o_ptr = &creature_ptr->inventory_list[item];
2774
2775                         /* Wear the new stuff */
2776                         object_copy(o_ptr, q_ptr);
2777
2778                         creature_ptr->total_weight += q_ptr->weight;
2779
2780                         /* Increment the equip counter by hand */
2781                         creature_ptr->equip_cnt++;
2782
2783                         creature_ptr->update |= (PU_BONUS | PU_TORCH | PU_MANA);
2784                         creature_ptr->window |= (PW_EQUIP);
2785                 }
2786                 else
2787                 {
2788                         inven_carry(creature_ptr, q_ptr);
2789                 }
2790                 do_drop = FALSE;
2791         }
2792         else if (equiped_item)
2793         {
2794                 verify_equip_slot(creature_ptr, item);
2795                 calc_android_exp(creature_ptr);
2796         }
2797
2798         if (do_drop)
2799         {
2800                 if (cave_have_flag_bold(creature_ptr->current_floor_ptr, y, x, FF_PROJECT))
2801                 {
2802                         (void)drop_near(creature_ptr, q_ptr, j, y, x);
2803                 }
2804                 else
2805                 {
2806                         (void)drop_near(creature_ptr, q_ptr, j, prev_y, prev_x);
2807                 }
2808         }
2809
2810         return TRUE;
2811 }
2812
2813 /*!
2814  * @brief 自殺するコマンドのメインルーチン
2815  * Hack -- commit suicide
2816  * @return なし
2817  * @details
2818  */
2819 void do_cmd_suicide(player_type *creature_ptr)
2820 {
2821         int i;
2822
2823         /* Flush input */
2824         flush();
2825
2826         /* Verify Retirement */
2827         if (current_world_ptr->total_winner)
2828         {
2829                 /* Verify */
2830                 if (!get_check_strict(_("引退しますか? ", "Do you want to retire? "), CHECK_NO_HISTORY)) return;
2831         }
2832
2833         /* Verify Suicide */
2834         else
2835         {
2836                 /* Verify */
2837                 if (!get_check(_("本当に自殺しますか?", "Do you really want to commit suicide? "))) return;
2838         }
2839
2840         if (!current_world_ptr->noscore)
2841         {
2842                 /* Special Verification for suicide */
2843                 prt(_("確認のため '@' を押して下さい。", "Please verify SUICIDE by typing the '@' sign: "), 0, 0);
2844
2845                 flush();
2846                 i = inkey();
2847                 prt("", 0, 0);
2848                 if (i != '@') return;
2849
2850                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
2851         }
2852
2853         /* Initialize "last message" buffer */
2854         if (creature_ptr->last_message) string_free(creature_ptr->last_message);
2855         creature_ptr->last_message = NULL;
2856
2857         /* Hack -- Note *winning* message */
2858         if (current_world_ptr->total_winner && last_words)
2859         {
2860                 char buf[1024] = "";
2861                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_WINNER);
2862                 do
2863                 {
2864                         while (!get_string(_("*勝利*メッセージ: ", "*Winning* message: "), buf, sizeof buf));
2865                 } while (!get_check_strict(_("よろしいですか?", "Are you sure? "), CHECK_NO_HISTORY));
2866
2867                 if (buf[0])
2868                 {
2869                         creature_ptr->last_message = string_make(buf);
2870                         msg_print(creature_ptr->last_message);
2871                 }
2872         }
2873
2874         /* Stop playing */
2875         creature_ptr->playing = FALSE;
2876
2877         /* Kill the player */
2878         creature_ptr->is_dead = TRUE;
2879         creature_ptr->leaving = TRUE;
2880
2881         if (!current_world_ptr->total_winner)
2882         {
2883                 exe_write_diary(creature_ptr, NIKKI_BUNSHOU, 0, _("ダンジョンの探索に絶望して自殺した。", "give up all hope to commit suicide."));
2884                 exe_write_diary(creature_ptr, NIKKI_GAMESTART, 1, _("-------- ゲームオーバー --------", "--------   Game  Over   --------"));
2885                 exe_write_diary(creature_ptr, NIKKI_BUNSHOU, 1, "\n\n\n\n");
2886         }
2887
2888         /* Cause of death */
2889         (void)strcpy(creature_ptr->died_from, _("途中終了", "Quitting"));
2890 }