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