OSDN Git Service

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