OSDN Git Service

[Refactor] #37353 プレイヤーのアイテム発動処理を cmd-activate.c/h に分離。文字コードミス修正。 / Separate player...
[hengband/hengband.git] / src / dungeon.c
1 /*!
2     @file dungeon.c
3     @brief Angbandゲームエンジン / Angband game engine
4     @date 2013/12/31
5     @author
6     Copyright (c) 1989 James E. Wilson, Robert A. Koeneke\n
7     This software may be copied and distributed for educational, research, and\n
8     not for profit purposes provided that this copyright and statement are\n
9     included in all such copies.\n
10     2013 Deskull rearranged comment for Doxygen.
11  */
12
13 #include "angband.h"
14 #include "cmd-activate.h"
15 #include "cmd-eat.h"
16 #include "cmd-quaff.h"
17
18 #define TY_CURSE_CHANCE 200 /*!<太古の怨念の1ターン毎の発動確率(1/n)*/
19 #define CHAINSWORD_NOISE 100 /*!<チェンソーの1ターン毎の発動確率(1/n)*/
20
21 static bool load = TRUE; /*!<ロード処理中の分岐フラグ*/
22 static int wild_regen = 20; /*!<広域マップ移動時の自然回復処理カウンタ(広域マップ1マス毎に20回処理を基本とする)*/
23
24 /*!
25  * @brief 重度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item.  Method 1 (Heavy).
26  * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
27  * @return 擬似鑑定結果のIDを返す。
28  */
29 static byte value_check_aux1(object_type *o_ptr)
30 {
31         /* Artifacts */
32         if (object_is_artifact(o_ptr))
33         {
34                 /* Cursed/Broken */
35                 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_TERRIBLE;
36
37                 /* Normal */
38                 return FEEL_SPECIAL;
39         }
40
41         /* Ego-Items */
42         if (object_is_ego(o_ptr))
43         {
44                 /* Cursed/Broken */
45                 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_WORTHLESS;
46
47                 /* Normal */
48                 return FEEL_EXCELLENT;
49         }
50
51         /* Cursed items */
52         if (object_is_cursed(o_ptr)) return FEEL_CURSED;
53
54         /* Broken items */
55         if (object_is_broken(o_ptr)) return FEEL_BROKEN;
56
57         if ((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) return FEEL_AVERAGE;
58
59         /* Good "armor" bonus */
60         if (o_ptr->to_a > 0) return FEEL_GOOD;
61
62         /* Good "weapon" bonus */
63         if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_GOOD;
64
65         /* Default to "average" */
66         return FEEL_AVERAGE;
67 }
68
69 /*!
70  * @brief 軽度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item.  Method 2 (Light).
71  * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
72  * @return 擬似鑑定結果のIDを返す。
73  */
74 static byte value_check_aux2(object_type *o_ptr)
75 {
76         /* Cursed items (all of them) */
77         if (object_is_cursed(o_ptr)) return FEEL_CURSED;
78
79         /* Broken items (all of them) */
80         if (object_is_broken(o_ptr)) return FEEL_BROKEN;
81
82         /* Artifacts -- except cursed/broken ones */
83         if (object_is_artifact(o_ptr)) return FEEL_UNCURSED;
84
85         /* Ego-Items -- except cursed/broken ones */
86         if (object_is_ego(o_ptr)) return FEEL_UNCURSED;
87
88         /* Good armor bonus */
89         if (o_ptr->to_a > 0) return FEEL_UNCURSED;
90
91         /* Good weapon bonuses */
92         if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_UNCURSED;
93
94         /* No feeling */
95         return FEEL_NONE;
96 }
97
98
99 /*!
100  * @brief 擬似鑑定を実際に行い判定を反映する
101  * @param slot 擬似鑑定を行うプレイヤーの所持リストID
102  * @param heavy 重度の擬似鑑定を行うならばTRUE
103  * @return なし
104  */
105 static void sense_inventory_aux(int slot, bool heavy)
106 {
107         byte        feel;
108         object_type *o_ptr = &inventory[slot];
109         char        o_name[MAX_NLEN];
110
111         /* We know about it already, do not tell us again */
112         if (o_ptr->ident & (IDENT_SENSE))return;
113
114         /* It is fully known, no information needed */
115         if (object_is_known(o_ptr)) return;
116
117         /* Check for a feeling */
118         feel = (heavy ? value_check_aux1(o_ptr) : value_check_aux2(o_ptr));
119
120         /* Skip non-feelings */
121         if (!feel) return;
122
123         /* Bad luck */
124         if ((p_ptr->muta3 & MUT3_BAD_LUCK) && !randint0(13))
125         {
126                 switch (feel)
127                 {
128                         case FEEL_TERRIBLE:
129                         {
130                                 feel = FEEL_SPECIAL;
131                                 break;
132                         }
133                         case FEEL_WORTHLESS:
134                         {
135                                 feel = FEEL_EXCELLENT;
136                                 break;
137                         }
138                         case FEEL_CURSED:
139                         {
140                                 if (heavy)
141                                         feel = randint0(3) ? FEEL_GOOD : FEEL_AVERAGE;
142                                 else
143                                         feel = FEEL_UNCURSED;
144                                 break;
145                         }
146                         case FEEL_AVERAGE:
147                         {
148                                 feel = randint0(2) ? FEEL_CURSED : FEEL_GOOD;
149                                 break;
150                         }
151                         case FEEL_GOOD:
152                         {
153                                 if (heavy)
154                                         feel = randint0(3) ? FEEL_CURSED : FEEL_AVERAGE;
155                                 else
156                                         feel = FEEL_CURSED;
157                                 break;
158                         }
159                         case FEEL_EXCELLENT:
160                         {
161                                 feel = FEEL_WORTHLESS;
162                                 break;
163                         }
164                         case FEEL_SPECIAL:
165                         {
166                                 feel = FEEL_TERRIBLE;
167                                 break;
168                         }
169                 }
170         }
171
172         /* Stop everything */
173         if (disturb_minor) disturb(0, 0);
174
175         /* Get an object description */
176         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
177
178         /* Message (equipment) */
179         if (slot >= INVEN_RARM)
180         {
181 #ifdef JP
182 msg_format("%s%s(%c)は%sという感じがする...",
183 describe_use(slot),o_name, index_to_label(slot),game_inscriptions[feel]);
184 #else
185                 msg_format("You feel the %s (%c) you are %s %s %s...",
186                            o_name, index_to_label(slot), describe_use(slot),
187                            ((o_ptr->number == 1) ? "is" : "are"),
188                                    game_inscriptions[feel]);
189 #endif
190
191         }
192
193         /* Message (inventory) */
194         else
195         {
196 #ifdef JP
197 msg_format("ザックの中の%s(%c)は%sという感じがする...",
198 o_name, index_to_label(slot),game_inscriptions[feel]);
199 #else
200                 msg_format("You feel the %s (%c) in your pack %s %s...",
201                            o_name, index_to_label(slot),
202                            ((o_ptr->number == 1) ? "is" : "are"),
203                                    game_inscriptions[feel]);
204 #endif
205
206         }
207
208         /* We have "felt" it */
209         o_ptr->ident |= (IDENT_SENSE);
210
211         /* Set the "inscription" */
212         o_ptr->feeling = feel;
213
214         /* Auto-inscription/destroy */
215         autopick_alter_item(slot, destroy_feeling);
216
217         /* Combine / Reorder the pack (later) */
218         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
219
220         /* Window stuff */
221         p_ptr->window |= (PW_INVEN | PW_EQUIP);
222 }
223
224
225
226 /*!
227  * @brief 1プレイヤーターン毎に武器、防具の擬似鑑定が行われるかを判定する。
228  * @return なし
229  * @details
230  * Sense the inventory\n
231  *\n
232  *   Class 0 = Warrior --> fast and heavy\n
233  *   Class 1 = Mage    --> slow and light\n
234  *   Class 2 = Priest  --> fast but light\n
235  *   Class 3 = Rogue   --> okay and heavy\n
236  *   Class 4 = Ranger  --> slow but heavy  (changed!)\n
237  *   Class 5 = Paladin --> slow but heavy\n
238  */
239 static void sense_inventory1(void)
240 {
241         int         i;
242         int         plev = p_ptr->lev;
243         bool        heavy = FALSE;
244         object_type *o_ptr;
245
246
247         /*** Check for "sensing" ***/
248
249         /* No sensing when confused */
250         if (p_ptr->confused) return;
251
252         /* Analyze the class */
253         switch (p_ptr->pclass)
254         {
255                 case CLASS_WARRIOR:
256                 case CLASS_ARCHER:
257                 case CLASS_SAMURAI:
258                 case CLASS_CAVALRY:
259                 {
260                         /* Good sensing */
261                         if (0 != randint0(9000L / (plev * plev + 40))) return;
262
263                         /* Heavy sensing */
264                         heavy = TRUE;
265
266                         /* Done */
267                         break;
268                 }
269
270                 case CLASS_SMITH:
271                 {
272                         /* Good sensing */
273                         if (0 != randint0(6000L / (plev * plev + 50))) return;
274
275                         /* Heavy sensing */
276                         heavy = TRUE;
277
278                         /* Done */
279                         break;
280                 }
281
282                 case CLASS_MAGE:
283                 case CLASS_HIGH_MAGE:
284                 case CLASS_SORCERER:
285                 case CLASS_MAGIC_EATER:
286                 {
287                         /* Very bad (light) sensing */
288                         if (0 != randint0(240000L / (plev + 5))) return;
289
290                         /* Done */
291                         break;
292                 }
293
294                 case CLASS_PRIEST:
295                 case CLASS_BARD:
296                 {
297                         /* Good (light) sensing */
298                         if (0 != randint0(10000L / (plev * plev + 40))) return;
299
300                         /* Done */
301                         break;
302                 }
303
304                 case CLASS_ROGUE:
305                 case CLASS_NINJA:
306                 {
307                         /* Okay sensing */
308                         if (0 != randint0(20000L / (plev * plev + 40))) return;
309
310                         /* Heavy sensing */
311                         heavy = TRUE;
312
313                         /* Done */
314                         break;
315                 }
316
317                 case CLASS_RANGER:
318                 {
319                         /* Bad sensing */
320                         if (0 != randint0(95000L / (plev * plev + 40))) return;
321
322                         /* Changed! */
323                         heavy = TRUE;
324
325                         /* Done */
326                         break;
327                 }
328
329                 case CLASS_PALADIN:
330                 case CLASS_SNIPER:
331                 {
332                         /* Bad sensing */
333                         if (0 != randint0(77777L / (plev * plev + 40))) return;
334
335                         /* Heavy sensing */
336                         heavy = TRUE;
337
338                         /* Done */
339                         break;
340                 }
341
342                 case CLASS_WARRIOR_MAGE:
343                 case CLASS_RED_MAGE:
344                 {
345                         /* Bad sensing */
346                         if (0 != randint0(75000L / (plev * plev + 40))) return;
347
348                         /* Done */
349                         break;
350                 }
351
352                 case CLASS_MINDCRAFTER:
353                 case CLASS_IMITATOR:
354                 case CLASS_BLUE_MAGE:
355                 case CLASS_MIRROR_MASTER:
356                 {
357                         /* Bad sensing */
358                         if (0 != randint0(55000L / (plev * plev + 40))) return;
359
360                         /* Done */
361                         break;
362                 }
363
364                 case CLASS_CHAOS_WARRIOR:
365                 {
366                         /* Bad sensing */
367                         if (0 != randint0(80000L / (plev * plev + 40))) return;
368
369                         /* Changed! */
370                         heavy = TRUE;
371
372                         /* Done */
373                         break;
374                 }
375
376                 case CLASS_MONK:
377                 case CLASS_FORCETRAINER:
378                 {
379                         /* Okay sensing */
380                         if (0 != randint0(20000L / (plev * plev + 40))) return;
381
382                         /* Done */
383                         break;
384                 }
385
386                 case CLASS_TOURIST:
387                 {
388                         /* Good sensing */
389                         if (0 != randint0(20000L / ((plev+50)*(plev+50)))) return;
390
391                         /* Heavy sensing */
392                         heavy = TRUE;
393
394                         /* Done */
395                         break;
396                 }
397
398                 case CLASS_BEASTMASTER:
399                 {
400                         /* Bad sensing */
401                         if (0 != randint0(65000L / (plev * plev + 40))) return;
402
403                         /* Done */
404                         break;
405                 }
406                 case CLASS_BERSERKER:
407                 {
408                         /* Heavy sensing */
409                         heavy = TRUE;
410
411                         /* Done */
412                         break;
413                 }
414         }
415
416         if (compare_virtue(V_KNOWLEDGE, 100, VIRTUE_LARGE)) heavy = TRUE;
417
418         /*** Sense everything ***/
419
420         /* Check everything */
421         for (i = 0; i < INVEN_TOTAL; i++)
422         {
423                 bool okay = FALSE;
424
425                 o_ptr = &inventory[i];
426
427                 /* Skip empty slots */
428                 if (!o_ptr->k_idx) continue;
429
430                 /* Valid "tval" codes */
431                 switch (o_ptr->tval)
432                 {
433                         case TV_SHOT:
434                         case TV_ARROW:
435                         case TV_BOLT:
436                         case TV_BOW:
437                         case TV_DIGGING:
438                         case TV_HAFTED:
439                         case TV_POLEARM:
440                         case TV_SWORD:
441                         case TV_BOOTS:
442                         case TV_GLOVES:
443                         case TV_HELM:
444                         case TV_CROWN:
445                         case TV_SHIELD:
446                         case TV_CLOAK:
447                         case TV_SOFT_ARMOR:
448                         case TV_HARD_ARMOR:
449                         case TV_DRAG_ARMOR:
450                         case TV_CARD:
451                         {
452                                 okay = TRUE;
453                                 break;
454                         }
455                 }
456
457                 /* Skip non-sense machines */
458                 if (!okay) continue;
459
460                 /* Occasional failure on inventory items */
461                 if ((i < INVEN_RARM) && (0 != randint0(5))) continue;
462
463                 /* Good luck */
464                 if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && !randint0(13))
465                 {
466                         heavy = TRUE;
467                 }
468
469                 sense_inventory_aux(i, heavy);
470         }
471 }
472
473 /*!
474  * @brief 1プレイヤーターン毎に武器、防具以外の擬似鑑定が行われるかを判定する。
475  * @return なし
476  */
477 static void sense_inventory2(void)
478 {
479         int         i;
480         int         plev = p_ptr->lev;
481         object_type *o_ptr;
482
483
484         /*** Check for "sensing" ***/
485
486         /* No sensing when confused */
487         if (p_ptr->confused) return;
488
489         /* Analyze the class */
490         switch (p_ptr->pclass)
491         {
492                 case CLASS_WARRIOR:
493                 case CLASS_ARCHER:
494                 case CLASS_SAMURAI:
495                 case CLASS_CAVALRY:
496                 case CLASS_BERSERKER:
497                 case CLASS_SNIPER:
498                 {
499                         return;
500                 }
501
502                 case CLASS_SMITH:
503                 case CLASS_PALADIN:
504                 case CLASS_CHAOS_WARRIOR:
505                 case CLASS_IMITATOR:
506                 case CLASS_BEASTMASTER:
507                 case CLASS_NINJA:
508                 {
509                         /* Very bad (light) sensing */
510                         if (0 != randint0(240000L / (plev + 5))) return;
511
512                         /* Done */
513                         break;
514                 }
515
516                 case CLASS_RANGER:
517                 case CLASS_WARRIOR_MAGE:
518                 case CLASS_RED_MAGE:
519                 case CLASS_MONK:
520                 {
521                         /* Bad sensing */
522                         if (0 != randint0(95000L / (plev * plev + 40))) return;
523
524                         /* Done */
525                         break;
526                 }
527
528                 case CLASS_PRIEST:
529                 case CLASS_BARD:
530                 case CLASS_ROGUE:
531                 case CLASS_FORCETRAINER:
532                 case CLASS_MINDCRAFTER:
533                 {
534                         /* Good sensing */
535                         if (0 != randint0(20000L / (plev * plev + 40))) return;
536
537                         /* Done */
538                         break;
539                 }
540
541                 case CLASS_MAGE:
542                 case CLASS_HIGH_MAGE:
543                 case CLASS_SORCERER:
544                 case CLASS_MAGIC_EATER:
545                 case CLASS_MIRROR_MASTER:
546                 case CLASS_BLUE_MAGE:
547                 {
548                         /* Good sensing */
549                         if (0 != randint0(9000L / (plev * plev + 40))) return;
550
551                         /* Done */
552                         break;
553                 }
554
555                 case CLASS_TOURIST:
556                 {
557                         /* Good sensing */
558                         if (0 != randint0(20000L / ((plev+50)*(plev+50)))) return;
559
560                         /* Done */
561                         break;
562                 }
563         }
564
565         /*** Sense everything ***/
566
567         /* Check everything */
568         for (i = 0; i < INVEN_TOTAL; i++)
569         {
570                 bool okay = FALSE;
571
572                 o_ptr = &inventory[i];
573
574                 /* Skip empty slots */
575                 if (!o_ptr->k_idx) continue;
576
577                 /* Valid "tval" codes */
578                 switch (o_ptr->tval)
579                 {
580                         case TV_RING:
581                         case TV_AMULET:
582                         case TV_LITE:
583                         case TV_FIGURINE:
584                         {
585                                 okay = TRUE;
586                                 break;
587                         }
588                 }
589
590                 /* Skip non-sense machines */
591                 if (!okay) continue;
592
593                 /* Occasional failure on inventory items */
594                 if ((i < INVEN_RARM) && (0 != randint0(5))) continue;
595
596                 sense_inventory_aux(i, TRUE);
597         }
598 }
599
600 /*!
601  * @brief パターン終点到達時のテレポート処理を行う
602  * @return なし
603  */
604 static void pattern_teleport(void)
605 {
606         DEPTH min_level = 0;
607         DEPTH max_level = 99;
608
609         /* Ask for level */
610         if (get_check(_("他の階にテレポートしますか?", "Teleport level? ")))
611         {
612                 char    ppp[80];
613                 char    tmp_val[160];
614
615                 /* Only downward in ironman mode */
616                 if (ironman_downward)
617                         min_level = dun_level;
618
619                 /* Maximum level */
620                 if (dungeon_type == DUNGEON_ANGBAND)
621                 {
622                         if (dun_level > 100)
623                                 max_level = MAX_DEPTH - 1;
624                         else if (dun_level == 100)
625                                 max_level = 100;
626                 }
627                 else
628                 {
629                         max_level = d_info[dungeon_type].maxdepth;
630                         min_level = d_info[dungeon_type].mindepth;
631                 }
632
633                 /* Prompt */
634                 sprintf(ppp, _("テレポート先:(%d-%d)", "Teleport to level (%d-%d): "), (int)min_level, (int)max_level);
635
636                 /* Default */
637                 sprintf(tmp_val, "%d", (int)dun_level);
638
639                 /* Ask for a level */
640                 if (!get_string(ppp, tmp_val, 10)) return;
641
642                 /* Extract request */
643                 command_arg = (COMMAND_ARG)atoi(tmp_val);
644         }
645         else if (get_check(_("通常テレポート?", "Normal teleport? ")))
646         {
647                 teleport_player(200, 0L);
648                 return;
649         }
650         else
651         {
652                 return;
653         }
654
655         /* Paranoia */
656         if (command_arg < min_level) command_arg = (COMMAND_ARG)min_level;
657
658         /* Paranoia */
659         if (command_arg > max_level) command_arg = (COMMAND_ARG)max_level;
660
661         /* Accept request */
662         msg_format(_("%d 階にテレポートしました。", "You teleport to dungeon level %d."), command_arg);
663
664         if (autosave_l) do_cmd_save_game(TRUE);
665
666         /* Change level */
667         dun_level = command_arg;
668
669         leave_quest_check();
670
671         if (record_stair) do_cmd_write_nikki(NIKKI_PAT_TELE,0,NULL);
672
673         p_ptr->inside_quest = 0;
674         p_ptr->energy_use = 0;
675
676         /*
677          * Clear all saved floors
678          * and create a first saved floor
679          */
680         prepare_change_floor_mode(CFM_FIRST_FLOOR);
681
682         /* Leaving */
683         p_ptr->leaving = TRUE;
684 }
685
686 /*!
687  * @brief 種族アンバライトが出血時パターンの上に乗った際のペナルティ処理
688  * @return なし
689  */
690 static void wreck_the_pattern(void)
691 {
692         int to_ruin = 0;
693         POSITION r_y, r_x;
694         int pattern_type = f_info[cave[p_ptr->y][p_ptr->x].feat].subtype;
695
696         if (pattern_type == PATTERN_TILE_WRECKED)
697         {
698                 /* Ruined already */
699                 return;
700         }
701
702         msg_print(_("パターンを血で汚してしまった!", "You bleed on the Pattern!"));
703         msg_print(_("何か恐ろしい事が起こった!", "Something terrible happens!"));
704
705         if (!IS_INVULN())
706                 take_hit(DAMAGE_NOESCAPE, damroll(10, 8), _("パターン損壊", "corrupting the Pattern"), -1);
707
708         to_ruin = randint1(45) + 35;
709
710         while (to_ruin--)
711         {
712                 scatter(&r_y, &r_x, p_ptr->y, p_ptr->x, 4, 0);
713
714                 if (pattern_tile(r_y, r_x) &&
715                     (f_info[cave[r_y][r_x].feat].subtype != PATTERN_TILE_WRECKED))
716                 {
717                         cave_set_feat(r_y, r_x, feat_pattern_corrupted);
718                 }
719         }
720
721         cave_set_feat(p_ptr->y, p_ptr->x, feat_pattern_corrupted);
722 }
723
724 /*!
725  * @brief 各種パターン地形上の特別な処理 / Returns TRUE if we are on the Pattern...
726  * @return 実際にパターン地形上にプレイヤーが居た場合はTRUEを返す。
727  */
728 static bool pattern_effect(void)
729 {
730         int pattern_type;
731
732         if (!pattern_tile(p_ptr->y, p_ptr->x)) return FALSE;
733
734         if ((prace_is_(RACE_AMBERITE)) &&
735             (p_ptr->cut > 0) && one_in_(10))
736         {
737                 wreck_the_pattern();
738         }
739
740         pattern_type = f_info[cave[p_ptr->y][p_ptr->x].feat].subtype;
741
742         switch (pattern_type)
743         {
744         case PATTERN_TILE_END:
745                 (void)set_poisoned(0);
746                 (void)set_image(0);
747                 (void)set_stun(0);
748                 (void)set_cut(0);
749                 (void)set_blind(0);
750                 (void)set_afraid(0);
751                 (void)do_res_stat(A_STR);
752                 (void)do_res_stat(A_INT);
753                 (void)do_res_stat(A_WIS);
754                 (void)do_res_stat(A_DEX);
755                 (void)do_res_stat(A_CON);
756                 (void)do_res_stat(A_CHR);
757                 (void)restore_level();
758                 (void)hp_player(1000);
759
760                 cave_set_feat(p_ptr->y, p_ptr->x, feat_pattern_old);
761                 msg_print(_("「パターン」のこの部分は他の部分より強力でないようだ。", "This section of the Pattern looks less powerful."));
762
763                 /*
764                  * We could make the healing effect of the
765                  * Pattern center one-time only to avoid various kinds
766                  * of abuse, like luring the win monster into fighting you
767                  * in the middle of the pattern...
768                  */
769                 break;
770
771         case PATTERN_TILE_OLD:
772                 /* No effect */
773                 break;
774
775         case PATTERN_TILE_TELEPORT:
776                 pattern_teleport();
777                 break;
778
779         case PATTERN_TILE_WRECKED:
780                 if (!IS_INVULN())
781                         take_hit(DAMAGE_NOESCAPE, 200, _("壊れた「パターン」を歩いたダメージ", "walking the corrupted Pattern"), -1);
782                 break;
783
784         default:
785                 if (prace_is_(RACE_AMBERITE) && !one_in_(2))
786                         return TRUE;
787                 else if (!IS_INVULN())
788                         take_hit(DAMAGE_NOESCAPE, damroll(1, 3), _("「パターン」を歩いたダメージ", "walking the Pattern"), -1);
789                 break;
790         }
791
792         return TRUE;
793 }
794
795
796 /*!
797  * @brief プレイヤーのHP自然回復処理 / Regenerate hit points -RAK-
798  * @param percent 回復比率
799  * @return なし
800  */
801 static void regenhp(int percent)
802 {
803         s32b new_chp;
804         u32b new_chp_frac;
805         s32b old_chp;
806
807         if (p_ptr->special_defense & KATA_KOUKIJIN) return;
808         if (p_ptr->action == ACTION_HAYAGAKE) return;
809
810         /* Save the old hitpoints */
811         old_chp = p_ptr->chp;
812
813         /*
814          * Extract the new hitpoints
815          *
816          * 'percent' is the Regen factor in unit (1/2^16)
817          */
818         new_chp = 0;
819         new_chp_frac = (p_ptr->mhp * percent + PY_REGEN_HPBASE);
820
821         /* Convert the unit (1/2^16) to (1/2^32) */
822         s64b_LSHIFT(new_chp, new_chp_frac, 16);
823
824         /* Regenerating */
825         s64b_add(&(p_ptr->chp), &(p_ptr->chp_frac), new_chp, new_chp_frac);
826
827
828         /* Fully healed */
829         if (0 < s64b_cmp(p_ptr->chp, p_ptr->chp_frac, p_ptr->mhp, 0))
830         {
831                 p_ptr->chp = p_ptr->mhp;
832                 p_ptr->chp_frac = 0;
833         }
834
835         /* Notice changes */
836         if (old_chp != p_ptr->chp)
837         {
838                 /* Redraw */
839                 p_ptr->redraw |= (PR_HP);
840
841                 /* Window stuff */
842                 p_ptr->window |= (PW_PLAYER);
843
844                 wild_regen = 20;
845         }
846 }
847
848
849 /*!
850  * @brief プレイヤーのMP自然回復処理(regen_magic()のサブセット) / Regenerate mana points
851  * @param upkeep_factor ペット維持によるMPコスト量
852  * @param regen_amount 回復量
853  * @return なし
854  */
855 static void regenmana(int upkeep_factor, int regen_amount)
856 {
857         s32b old_csp = p_ptr->csp;
858         s32b regen_rate = regen_amount * 100 - upkeep_factor * PY_REGEN_NORMAL;
859
860         /*
861          * Excess mana will decay 32 times faster than normal
862          * regeneration rate.
863          */
864         if (p_ptr->csp > p_ptr->msp)
865         {
866                 /* PY_REGEN_NORMAL is the Regen factor in unit (1/2^16) */
867                 s32b decay = 0;
868                 u32b decay_frac = (p_ptr->msp * 32 * PY_REGEN_NORMAL + PY_REGEN_MNBASE);
869
870                 /* Convert the unit (1/2^16) to (1/2^32) */
871                 s64b_LSHIFT(decay, decay_frac, 16);
872
873                 /* Decay */
874                 s64b_sub(&(p_ptr->csp), &(p_ptr->csp_frac), decay, decay_frac);
875
876                 /* Stop decaying */
877                 if (p_ptr->csp < p_ptr->msp)
878                 {
879                         p_ptr->csp = p_ptr->msp;
880                         p_ptr->csp_frac = 0;
881                 }
882         }
883
884         /* Regenerating mana (unless the player has excess mana) */
885         else if (regen_rate > 0)
886         {
887                 /* (percent/100) is the Regen factor in unit (1/2^16) */
888                 s32b new_mana = 0;
889                 u32b new_mana_frac = (p_ptr->msp * regen_rate / 100 + PY_REGEN_MNBASE);
890
891                 /* Convert the unit (1/2^16) to (1/2^32) */
892                 s64b_LSHIFT(new_mana, new_mana_frac, 16);
893
894                 /* Regenerate */
895                 s64b_add(&(p_ptr->csp), &(p_ptr->csp_frac), new_mana, new_mana_frac);
896
897                 /* Must set frac to zero even if equal */
898                 if (p_ptr->csp >= p_ptr->msp)
899                 {
900                         p_ptr->csp = p_ptr->msp;
901                         p_ptr->csp_frac = 0;
902                 }
903         }
904
905
906         /* Reduce mana (even when the player has excess mana) */
907         if (regen_rate < 0)
908         {
909                 /* PY_REGEN_NORMAL is the Regen factor in unit (1/2^16) */
910                 s32b reduce_mana = 0;
911                 u32b reduce_mana_frac = (p_ptr->msp * (-1) * regen_rate / 100 + PY_REGEN_MNBASE);
912
913                 /* Convert the unit (1/2^16) to (1/2^32) */
914                 s64b_LSHIFT(reduce_mana, reduce_mana_frac, 16);
915
916                 /* Reduce mana */
917                 s64b_sub(&(p_ptr->csp), &(p_ptr->csp_frac), reduce_mana, reduce_mana_frac);
918
919                 /* Check overflow */
920                 if (p_ptr->csp < 0)
921                 {
922                         p_ptr->csp = 0;
923                         p_ptr->csp_frac = 0;
924                 }
925         }
926
927
928         /* Redraw mana */
929         if (old_csp != p_ptr->csp)
930         {
931                 /* Redraw */
932                 p_ptr->redraw |= (PR_MANA);
933
934                 /* Window stuff */
935                 p_ptr->window |= (PW_PLAYER);
936                 p_ptr->window |= (PW_SPELL);
937
938                 wild_regen = 20;
939         }
940 }
941
942 /*!
943  * @brief プレイヤーのMP自然回復処理 / Regenerate magic regen_amount: PY_REGEN_NORMAL * 2 (if resting) * 2 (if having regenarate)
944  * @param regen_amount 回復量
945  * @return なし
946  */
947 static void regenmagic(int regen_amount)
948 {
949         s32b new_mana;
950         int i;
951         int dev = 30;
952         int mult = (dev + adj_mag_mana[p_ptr->stat_ind[A_INT]]); /* x1 to x2 speed bonus for recharging */
953
954         for (i = 0; i < EATER_EXT*2; i++)
955         {
956                 if (!p_ptr->magic_num2[i]) continue;
957                 if (p_ptr->magic_num1[i] == ((long)p_ptr->magic_num2[i] << 16)) continue;
958
959                 /* Increase remaining charge number like float value */
960                 new_mana = (regen_amount * mult * ((long)p_ptr->magic_num2[i] + 13)) / (dev * 8);
961                 p_ptr->magic_num1[i] += new_mana;
962
963                 /* Check maximum charge */
964                 if (p_ptr->magic_num1[i] > (p_ptr->magic_num2[i] << 16))
965                 {
966                         p_ptr->magic_num1[i] = ((long)p_ptr->magic_num2[i] << 16);
967                 }
968                 wild_regen = 20;
969         }
970         for (i = EATER_EXT*2; i < EATER_EXT*3; i++)
971         {
972                 if (!p_ptr->magic_num1[i]) continue;
973                 if (!p_ptr->magic_num2[i]) continue;
974
975                 /* Decrease remaining period for charging */
976                 new_mana = (regen_amount * mult * ((long)p_ptr->magic_num2[i] + 10) * EATER_ROD_CHARGE) 
977                                         / (dev * 16 * PY_REGEN_NORMAL); 
978                 p_ptr->magic_num1[i] -= new_mana;
979
980                 /* Check minimum remaining period for charging */
981                 if (p_ptr->magic_num1[i] < 0) p_ptr->magic_num1[i] = 0;
982                 wild_regen = 20;
983         }
984 }
985
986
987 /*!
988  * @brief 100ゲームターン毎のモンスターのHP自然回復処理 / Regenerate the monsters (once per 100 game turns)
989  * @return なし
990  * @note XXX XXX XXX Should probably be done during monster turns.
991  */
992 static void regen_monsters(void)
993 {
994         int i, frac;
995
996
997         /* Regenerate everyone */
998         for (i = 1; i < m_max; i++)
999         {
1000                 /* Check the i'th monster */
1001                 monster_type *m_ptr = &m_list[i];
1002                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1003
1004
1005                 /* Skip dead monsters */
1006                 if (!m_ptr->r_idx) continue;
1007
1008                 /* Allow regeneration (if needed) */
1009                 if (m_ptr->hp < m_ptr->maxhp)
1010                 {
1011                         /* Hack -- Base regeneration */
1012                         frac = m_ptr->maxhp / 100;
1013
1014                         /* Hack -- Minimal regeneration rate */
1015                         if (!frac) if (one_in_(2)) frac = 1;
1016
1017                         /* Hack -- Some monsters regenerate quickly */
1018                         if (r_ptr->flags2 & RF2_REGENERATE) frac *= 2;
1019
1020                         /* Hack -- Regenerate */
1021                         m_ptr->hp += frac;
1022
1023                         /* Do not over-regenerate */
1024                         if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
1025
1026                         /* Redraw (later) if needed */
1027                         if (p_ptr->health_who == i) p_ptr->redraw |= (PR_HEALTH);
1028                         if (p_ptr->riding == i) p_ptr->redraw |= (PR_UHEALTH);
1029                 }
1030         }
1031 }
1032
1033
1034 /*!
1035  * @brief 30ゲームターン毎のボール中モンスターのHP自然回復処理 / Regenerate the captured monsters (once per 30 game turns)
1036  * @return なし
1037  * @note XXX XXX XXX Should probably be done during monster turns.
1038  */
1039 static void regen_captured_monsters(void)
1040 {
1041         int i, frac;
1042         bool heal = FALSE;
1043
1044         /* Regenerate everyone */
1045         for (i = 0; i < INVEN_TOTAL; i++)
1046         {
1047                 monster_race *r_ptr;
1048                 object_type *o_ptr = &inventory[i];
1049
1050                 if (!o_ptr->k_idx) continue;
1051                 if (o_ptr->tval != TV_CAPTURE) continue;
1052                 if (!o_ptr->pval) continue;
1053
1054                 heal = TRUE;
1055
1056                 r_ptr = &r_info[o_ptr->pval];
1057
1058                 /* Allow regeneration (if needed) */
1059                 if (o_ptr->xtra4 < o_ptr->xtra5)
1060                 {
1061                         /* Hack -- Base regeneration */
1062                         frac = o_ptr->xtra5 / 100;
1063
1064                         /* Hack -- Minimal regeneration rate */
1065                         if (!frac) if (one_in_(2)) frac = 1;
1066
1067                         /* Hack -- Some monsters regenerate quickly */
1068                         if (r_ptr->flags2 & RF2_REGENERATE) frac *= 2;
1069
1070                         /* Hack -- Regenerate */
1071                         o_ptr->xtra4 += (XTRA16)frac;
1072
1073                         /* Do not over-regenerate */
1074                         if (o_ptr->xtra4 > o_ptr->xtra5) o_ptr->xtra4 = o_ptr->xtra5;
1075                 }
1076         }
1077
1078         if (heal)
1079         {
1080                 /* Combine pack */
1081                 p_ptr->notice |= (PN_COMBINE);
1082
1083                 /* Window stuff */
1084                 p_ptr->window |= (PW_INVEN);
1085                 p_ptr->window |= (PW_EQUIP);
1086                 wild_regen = 20;
1087         }
1088 }
1089
1090 /*!
1091  * @brief 寿命つき光源の警告メッセージ処理
1092  * @param o_ptr 現在光源として使っているオブジェクトの構造体参照ポインタ
1093  * @return なし
1094  */
1095 static void notice_lite_change(object_type *o_ptr)
1096 {
1097         /* Hack -- notice interesting fuel steps */
1098         if ((o_ptr->xtra4 < 100) || (!(o_ptr->xtra4 % 100)))
1099         {
1100                 /* Window stuff */
1101                 p_ptr->window |= (PW_EQUIP);
1102         }
1103
1104         /* Hack -- Special treatment when blind */
1105         if (p_ptr->blind)
1106         {
1107                 /* Hack -- save some light for later */
1108                 if (o_ptr->xtra4 == 0) o_ptr->xtra4++;
1109         }
1110
1111         /* The light is now out */
1112         else if (o_ptr->xtra4 == 0)
1113         {
1114                 disturb(0, 1);
1115                 msg_print(_("明かりが消えてしまった!", "Your light has gone out!"));
1116
1117                 /* Recalculate torch radius */
1118                 p_ptr->update |= (PU_TORCH);
1119
1120                 /* Some ego light lose its effects without fuel */
1121                 p_ptr->update |= (PU_BONUS);
1122         }
1123
1124         /* The light is getting dim */
1125         else if (o_ptr->name2 == EGO_LITE_LONG)
1126         {
1127                 if ((o_ptr->xtra4 < 50) && (!(o_ptr->xtra4 % 5))
1128                     && (turn % (TURNS_PER_TICK*2)))
1129                 {
1130                         if (disturb_minor) disturb(0, 1);
1131                         msg_print(_("明かりが微かになってきている。", "Your light is growing faint."));
1132                 }
1133         }
1134
1135         /* The light is getting dim */
1136         else if ((o_ptr->xtra4 < 100) && (!(o_ptr->xtra4 % 10)))
1137         {
1138                 if (disturb_minor) disturb(0, 1);
1139                         msg_print(_("明かりが微かになってきている。", "Your light is growing faint."));
1140         }
1141 }
1142
1143 /*!
1144  * @brief クエスト階層から離脱する際の処理
1145  * @return なし
1146  */
1147 void leave_quest_check(void)
1148 {
1149         /* Save quest number for dungeon pref file ($LEAVING_QUEST) */
1150         leaving_quest = p_ptr->inside_quest;
1151
1152         /* Leaving an 'only once' quest marks it as failed */
1153         if (leaving_quest)
1154         {       
1155                 quest_type* const q_ptr = &quest[leaving_quest];
1156                 
1157             if(((q_ptr->flags & QUEST_FLAG_ONCE)  || (q_ptr->type == QUEST_TYPE_RANDOM)) &&
1158                (q_ptr->status == QUEST_STATUS_TAKEN))
1159                 {
1160                         q_ptr->status = QUEST_STATUS_FAILED;
1161                         q_ptr->complev = (byte)p_ptr->lev;
1162                         update_playtime();
1163                         q_ptr->comptime = playtime;
1164
1165                         /* Additional settings */
1166                         switch (q_ptr->type)
1167                         {
1168                           case QUEST_TYPE_TOWER:
1169                                 quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
1170                                 quest[QUEST_TOWER1].complev = (byte)p_ptr->lev;
1171                                 break;
1172                           case QUEST_TYPE_FIND_ARTIFACT:
1173                                 a_info[q_ptr->k_idx].gen_flags &= ~(TRG_QUESTITEM);
1174                                 break;
1175                           case QUEST_TYPE_RANDOM:
1176                                 r_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
1177
1178                                 /* Floor of random quest will be blocked */
1179                                 prepare_change_floor_mode(CFM_NO_RETURN);
1180                                 break;
1181                         }
1182
1183                         /* Record finishing a quest */
1184                         if (q_ptr->type == QUEST_TYPE_RANDOM)
1185                         {
1186                                 if (record_rand_quest) do_cmd_write_nikki(NIKKI_RAND_QUEST_F, leaving_quest, NULL);
1187                         }
1188                         else
1189                         {
1190                                 if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_F, leaving_quest, NULL);
1191                         }
1192                 }
1193         }
1194 }
1195
1196 /*!
1197  * @brief 「塔」クエストの各階層から離脱する際の処理
1198  * @return なし
1199  */
1200 void leave_tower_check(void)
1201 {
1202         leaving_quest = p_ptr->inside_quest;
1203         /* Check for Tower Quest */
1204         if (leaving_quest &&
1205                 (quest[leaving_quest].type == QUEST_TYPE_TOWER) &&
1206                 (quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED))
1207         {
1208                 if(quest[leaving_quest].type == QUEST_TYPE_TOWER)
1209                 {
1210                         quest[QUEST_TOWER1].status = QUEST_STATUS_FAILED;
1211                         quest[QUEST_TOWER1].complev = (byte)p_ptr->lev;
1212                         update_playtime();
1213                         quest[QUEST_TOWER1].comptime = playtime;
1214                 }
1215         }
1216 }
1217
1218 /*!
1219  * @brief 超能力者のサイコメトリー処理/ Forcibly pseudo-identify an object in the inventory (or on the floor)
1220  * @return なし
1221  * @todo mind.cにこの関数を移動させるべき。
1222  * @note
1223  * currently this function allows pseudo-id of any object,
1224  * including silly ones like potions & scrolls, which always
1225  * get '{average}'. This should be changed, either to stop such
1226  * items from being pseudo-id'd, or to allow psychometry to
1227  * detect whether the unidentified potion/scroll/etc is
1228  * good (Cure Light Wounds, Restore Strength, etc) or
1229  * bad (Poison, Weakness etc) or 'useless' (Slime Mold Juice, etc).
1230  */
1231 bool psychometry(void)
1232 {
1233         OBJECT_IDX      item;
1234         object_type     *o_ptr;
1235         char            o_name[MAX_NLEN];
1236         byte            feel;
1237         cptr            q, s;
1238         bool okay = FALSE;
1239
1240         item_tester_no_ryoute = TRUE;
1241         /* Get an item */
1242         q = _("どのアイテムを調べますか?", "Meditate on which item? ");
1243         s = _("調べるアイテムがありません。", "You have nothing appropriate.");
1244
1245         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
1246
1247         /* Get the item (in the pack) */
1248         if (item >= 0)
1249         {
1250                 o_ptr = &inventory[item];
1251         }
1252
1253         /* Get the item (on the floor) */
1254         else
1255         {
1256                 o_ptr = &o_list[0 - item];
1257         }
1258
1259         /* It is fully known, no information needed */
1260         if (object_is_known(o_ptr))
1261         {
1262                 msg_print(_("何も新しいことは判らなかった。", "You cannot find out anything more about that."));
1263                 return TRUE;
1264         }
1265
1266         /* Check for a feeling */
1267         feel = value_check_aux1(o_ptr);
1268
1269         /* Get an object description */
1270         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1271
1272         /* Skip non-feelings */
1273         if (!feel)
1274         {
1275                 msg_format(_("%sからは特に変わった事は感じとれなかった。", "You do not perceive anything unusual about the %s."), o_name);
1276                 return TRUE;
1277         }
1278
1279 #ifdef JP
1280 msg_format("%sは%sという感じがする...",
1281     o_name,  game_inscriptions[feel]);
1282 #else
1283         msg_format("You feel that the %s %s %s...",
1284                            o_name, ((o_ptr->number == 1) ? "is" : "are"),
1285                            game_inscriptions[feel]);
1286 #endif
1287
1288
1289         /* We have "felt" it */
1290         o_ptr->ident |= (IDENT_SENSE);
1291
1292         /* "Inscribe" it */
1293         o_ptr->feeling = feel;
1294
1295         /* Player touches it */
1296         o_ptr->marked |= OM_TOUCHED;
1297
1298         /* Combine / Reorder the pack (later) */
1299         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
1300
1301         /* Window stuff */
1302         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1303
1304         /* Valid "tval" codes */
1305         switch (o_ptr->tval)
1306         {
1307         case TV_SHOT:
1308         case TV_ARROW:
1309         case TV_BOLT:
1310         case TV_BOW:
1311         case TV_DIGGING:
1312         case TV_HAFTED:
1313         case TV_POLEARM:
1314         case TV_SWORD:
1315         case TV_BOOTS:
1316         case TV_GLOVES:
1317         case TV_HELM:
1318         case TV_CROWN:
1319         case TV_SHIELD:
1320         case TV_CLOAK:
1321         case TV_SOFT_ARMOR:
1322         case TV_HARD_ARMOR:
1323         case TV_DRAG_ARMOR:
1324         case TV_CARD:
1325         case TV_RING:
1326         case TV_AMULET:
1327         case TV_LITE:
1328         case TV_FIGURINE:
1329                 okay = TRUE;
1330                 break;
1331         }
1332
1333         /* Auto-inscription/destroy */
1334         autopick_alter_item(item, (bool)(okay && destroy_feeling));
1335
1336         /* Something happened */
1337         return (TRUE);
1338 }
1339
1340 /*!
1341  * @brief !!を刻んだ魔道具の時間経過による再充填を知らせる処理 / If player has inscribed the object with "!!", let him know when it's recharged. -LM-
1342  * @param o_ptr 対象オブジェクトの構造体参照ポインタ
1343  * @return なし
1344  */
1345 static void recharged_notice(object_type *o_ptr)
1346 {
1347         char o_name[MAX_NLEN];
1348
1349         cptr s;
1350
1351         /* No inscription */
1352         if (!o_ptr->inscription) return;
1353
1354         /* Find a '!' */
1355         s = my_strchr(quark_str(o_ptr->inscription), '!');
1356
1357         /* Process notification request. */
1358         while (s)
1359         {
1360                 /* Find another '!' */
1361                 if (s[1] == '!')
1362                 {
1363                         /* Describe (briefly) */
1364                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1365
1366                         /* Notify the player */
1367 #ifdef JP
1368                         msg_format("%sは再充填された。", o_name);
1369 #else
1370                         if (o_ptr->number > 1)
1371                                 msg_format("Your %s are recharged.", o_name);
1372                         else
1373                                 msg_format("Your %s is recharged.", o_name);
1374 #endif
1375
1376                         disturb(0, 0);
1377
1378                         /* Done. */
1379                         return;
1380                 }
1381
1382                 /* Keep looking for '!'s */
1383                 s = my_strchr(s + 1, '!');
1384         }
1385 }
1386
1387 /*!
1388  * @brief プレイヤーの歌に関する継続処理
1389  * @return なし
1390  */
1391 static void check_music(void)
1392 {
1393         const magic_type *s_ptr;
1394         int spell;
1395         s32b need_mana;
1396         u32b need_mana_frac;
1397
1398         /* Music singed by player */
1399         if (p_ptr->pclass != CLASS_BARD) return;
1400         if (!SINGING_SONG_EFFECT(p_ptr) && !INTERUPTING_SONG_EFFECT(p_ptr)) return;
1401
1402         if (p_ptr->anti_magic)
1403         {
1404                 stop_singing();
1405                 return;
1406         }
1407
1408         spell = SINGING_SONG_ID(p_ptr);
1409         s_ptr = &technic_info[REALM_MUSIC - MIN_TECHNIC][spell];
1410
1411         need_mana = mod_need_mana(s_ptr->smana, spell, REALM_MUSIC);
1412         need_mana_frac = 0;
1413
1414         /* Divide by 2 */
1415         s64b_RSHIFT(need_mana, need_mana_frac, 1);
1416
1417         if (s64b_cmp(p_ptr->csp, p_ptr->csp_frac, need_mana, need_mana_frac) < 0)
1418         {
1419                 stop_singing();
1420                 return;
1421         }
1422         else
1423         {
1424                 s64b_sub(&(p_ptr->csp), &(p_ptr->csp_frac), need_mana, need_mana_frac);
1425
1426                 p_ptr->redraw |= PR_MANA;
1427                 if (INTERUPTING_SONG_EFFECT(p_ptr))
1428                 {
1429                         SINGING_SONG_EFFECT(p_ptr) = INTERUPTING_SONG_EFFECT(p_ptr);
1430                         INTERUPTING_SONG_EFFECT(p_ptr) = MUSIC_NONE;
1431                         msg_print(_("歌を再開した。", "You restart singing."));
1432                         p_ptr->action = ACTION_SING;
1433
1434                         /* Recalculate bonuses */
1435                         p_ptr->update |= (PU_BONUS | PU_HP);
1436
1437                         /* Redraw map and status bar */
1438                         p_ptr->redraw |= (PR_MAP | PR_STATUS | PR_STATE);
1439
1440                         /* Update monsters */
1441                         p_ptr->update |= (PU_MONSTERS);
1442
1443                         /* Window stuff */
1444                         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1445                 }
1446         }
1447         if (p_ptr->spell_exp[spell] < SPELL_EXP_BEGINNER)
1448                 p_ptr->spell_exp[spell] += 5;
1449         else if(p_ptr->spell_exp[spell] < SPELL_EXP_SKILLED)
1450         { if (one_in_(2) && (dun_level > 4) && ((dun_level + 10) > p_ptr->lev)) p_ptr->spell_exp[spell] += 1; }
1451         else if(p_ptr->spell_exp[spell] < SPELL_EXP_EXPERT)
1452         { if (one_in_(5) && ((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel)) p_ptr->spell_exp[spell] += 1; }
1453         else if(p_ptr->spell_exp[spell] < SPELL_EXP_MASTER)
1454         { if (one_in_(5) && ((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel)) p_ptr->spell_exp[spell] += 1; }
1455
1456         /* Do any effects of continual song */
1457         do_spell(REALM_MUSIC, spell, SPELL_CONT);
1458 }
1459
1460 /*!
1461  * @brief 現在呪いを保持している装備品を一つランダムに探し出す / Choose one of items that have cursed flag
1462  * @param flag 探し出したい呪いフラグ配列
1463  * @return 該当の呪いが一つでもあった場合にランダムに選ばれた装備品のオブジェクト構造体参照ポインタを返す。\n
1464  * 呪いがない場合NULLを返す。
1465  */
1466 static object_type *choose_cursed_obj_name(u32b flag)
1467 {
1468         int i;
1469         int choices[INVEN_TOTAL-INVEN_RARM];
1470         int number = 0;
1471
1472         /* Paranoia -- Player has no warning-item */
1473         if (!(p_ptr->cursed & flag)) return NULL;
1474
1475         /* Search Inventry */
1476         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
1477         {
1478                 object_type *o_ptr = &inventory[i];
1479
1480                 if (o_ptr->curse_flags & flag)
1481                 {
1482                         choices[number] = i;
1483                         number++;
1484                 }
1485                 else if ((flag == TRC_ADD_L_CURSE) || 
1486                                         (flag == TRC_ADD_H_CURSE) || 
1487                                         (flag == TRC_DRAIN_HP) || 
1488                                         (flag == TRC_DRAIN_MANA) || 
1489                                         (flag == TRC_CALL_ANIMAL) || 
1490                                         (flag == TRC_CALL_DEMON) || 
1491                                         (flag == TRC_CALL_DRAGON) || 
1492                                         (flag == TRC_CALL_UNDEAD) || 
1493                                         (flag == TRC_COWARDICE) || 
1494                                         (flag == TRC_LOW_MELEE) || 
1495                                         (flag == TRC_LOW_AC) || 
1496                                         (flag == TRC_LOW_MAGIC) || 
1497                                         (flag == TRC_FAST_DIGEST) || 
1498                                         (flag == TRC_SLOW_REGEN) )
1499                 {
1500                         u32b cf;
1501                         u32b flgs[TR_FLAG_SIZE];
1502                         object_flags(o_ptr, flgs);
1503                         switch (flag)
1504                         {
1505                           case TRC_ADD_L_CURSE  : cf = TR_ADD_L_CURSE; break;
1506                           case TRC_ADD_H_CURSE  : cf = TR_ADD_H_CURSE; break;
1507                           case TRC_DRAIN_HP             : cf = TR_DRAIN_HP; break;
1508                           case TRC_DRAIN_MANA   : cf = TR_DRAIN_MANA; break;
1509                           case TRC_CALL_ANIMAL  : cf = TR_CALL_ANIMAL; break;
1510                           case TRC_CALL_DEMON   : cf = TR_CALL_DEMON; break;
1511                           case TRC_CALL_DRAGON  : cf = TR_CALL_DRAGON; break;
1512                           case TRC_CALL_UNDEAD  : cf = TR_CALL_UNDEAD; break;
1513                           case TRC_COWARDICE    : cf = TR_COWARDICE; break;
1514                           case TRC_LOW_MELEE    : cf = TR_LOW_MELEE; break;
1515                           case TRC_LOW_AC               : cf = TR_LOW_AC; break;
1516                           case TRC_LOW_MAGIC    : cf = TR_LOW_MAGIC; break;
1517                           case TRC_FAST_DIGEST  : cf = TR_FAST_DIGEST; break;
1518                           case TRC_SLOW_REGEN   : cf = TR_SLOW_REGEN; break;
1519                           default                               : break;
1520                         }
1521                         if (have_flag(flgs, cf))
1522                         {
1523                                 choices[number] = i;
1524                                 number++;
1525                         }
1526                 }
1527         }
1528
1529         /* Choice one of them */
1530         return (&inventory[choices[randint0(number)]]);
1531 }
1532
1533 /*!
1534  * @brief 10ゲームターンが進行するごとにプレイヤーのHPとMPの増減処理を行う。
1535  *  / Handle timed damage and regeneration every 10 game turns
1536  * @return なし
1537  */
1538 static void process_world_aux_hp_and_sp(void)
1539 {
1540         feature_type *f_ptr = &f_info[cave[p_ptr->y][p_ptr->x].feat];
1541         bool cave_no_regen = FALSE;
1542         int upkeep_factor = 0;
1543
1544         /* Default regeneration */
1545         int regen_amount = PY_REGEN_NORMAL;
1546
1547
1548         /*** Damage over Time ***/
1549
1550         /* Take damage from poison */
1551         if (p_ptr->poisoned && !IS_INVULN())
1552         {
1553                 /* Take damage */
1554                 take_hit(DAMAGE_NOESCAPE, 1, _("毒", "poison"), -1);
1555         }
1556
1557         /* Take damage from cuts */
1558         if (p_ptr->cut && !IS_INVULN())
1559         {
1560                 HIT_POINT dam;
1561
1562                 /* Mortal wound or Deep Gash */
1563                 if (p_ptr->cut > 1000)
1564                 {
1565                         dam = 200;
1566                 }
1567
1568                 else if (p_ptr->cut > 200)
1569                 {
1570                         dam = 80;
1571                 }
1572
1573                 /* Severe cut */
1574                 else if (p_ptr->cut > 100)
1575                 {
1576                         dam = 32;
1577                 }
1578
1579                 else if (p_ptr->cut > 50)
1580                 {
1581                         dam = 16;
1582                 }
1583
1584                 else if (p_ptr->cut > 25)
1585                 {
1586                         dam = 7;
1587                 }
1588
1589                 else if (p_ptr->cut > 10)
1590                 {
1591                         dam = 3;
1592                 }
1593
1594                 /* Other cuts */
1595                 else
1596                 {
1597                         dam = 1;
1598                 }
1599
1600                 /* Take damage */
1601                 take_hit(DAMAGE_NOESCAPE, dam, _("致命傷", "a fatal wound"), -1);
1602         }
1603
1604
1605         /* (Vampires) Take damage from sunlight */
1606         if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE))
1607         {
1608                 if (!dun_level && !p_ptr->resist_lite && !IS_INVULN() && is_daytime())
1609                 {
1610                         if ((cave[p_ptr->y][p_ptr->x].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
1611                         {
1612                                 /* Take damage */
1613                                 msg_print(_("日光があなたのアンデッドの肉体を焼き焦がした!", "The sun's rays scorch your undead flesh!"));
1614                                 take_hit(DAMAGE_NOESCAPE, 1, _("日光", "sunlight"), -1);
1615
1616                                 cave_no_regen = TRUE;
1617                         }
1618                 }
1619
1620                 if (inventory[INVEN_LITE].tval && (inventory[INVEN_LITE].name2 != EGO_LITE_DARKNESS) &&
1621                     !p_ptr->resist_lite)
1622                 {
1623                         object_type * o_ptr = &inventory[INVEN_LITE];
1624                         char o_name [MAX_NLEN];
1625                         char ouch [MAX_NLEN+40];
1626
1627                         /* Get an object description */
1628                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1629                         msg_format(_("%sがあなたのアンデッドの肉体を焼き焦がした!", "The %s scorches your undead flesh!"), o_name);
1630
1631                         cave_no_regen = TRUE;
1632
1633                         /* Get an object description */
1634                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
1635                         sprintf(ouch, _("%sを装備したダメージ", "wielding %s"), o_name);
1636
1637                         if (!IS_INVULN()) take_hit(DAMAGE_NOESCAPE, 1, ouch, -1);
1638                 }
1639         }
1640
1641         if (have_flag(f_ptr->flags, FF_LAVA) && !IS_INVULN() && !p_ptr->immune_fire)
1642         {
1643                 int damage = 0;
1644
1645                 if (have_flag(f_ptr->flags, FF_DEEP))
1646                 {
1647                         damage = 6000 + randint0(4000);
1648                 }
1649                 else if (!p_ptr->levitation)
1650                 {
1651                         damage = 3000 + randint0(2000);
1652                 }
1653
1654                 if (damage)
1655                 {
1656                         if (prace_is_(RACE_ENT)) damage += damage / 3;
1657                         if (p_ptr->resist_fire) damage = damage / 3;
1658                         if (IS_OPPOSE_FIRE()) damage = damage / 3;
1659
1660                         if (p_ptr->levitation) damage = damage / 5;
1661
1662                         damage = damage / 100 + (randint0(100) < (damage % 100));
1663
1664                         if (p_ptr->levitation)
1665                         {
1666                                 msg_print(_("熱で火傷した!", "The heat burns you!"));
1667                                 take_hit(DAMAGE_NOESCAPE, damage, format(_("%sの上に浮遊したダメージ", "flying over %s"), 
1668                                                                 f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name), -1);
1669                         }
1670                         else
1671                         {
1672                                 cptr name = f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name;
1673                                 msg_format(_("%sで火傷した!", "The %s burns you!"), name);
1674                                 take_hit(DAMAGE_NOESCAPE, damage, name, -1);
1675                         }
1676
1677                         cave_no_regen = TRUE;
1678                 }
1679         }
1680
1681         if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP) &&
1682             !p_ptr->levitation && !p_ptr->can_swim)
1683         {
1684                 if (p_ptr->total_weight > weight_limit())
1685                 {
1686                         /* Take damage */
1687                         msg_print(_("溺れている!", "You are drowning!"));
1688                         take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->lev), _("溺れ", "drowning"), -1);
1689                         cave_no_regen = TRUE;
1690                 }
1691         }
1692
1693         if (p_ptr->riding)
1694         {
1695                 int damage;
1696                 if ((r_info[m_list[p_ptr->riding].r_idx].flags2 & RF2_AURA_FIRE) && !p_ptr->immune_fire)
1697                 {
1698                         damage = r_info[m_list[p_ptr->riding].r_idx].level / 2;
1699                         if (prace_is_(RACE_ENT)) damage += damage / 3;
1700                         if (p_ptr->resist_fire) damage = damage / 3;
1701                         if (IS_OPPOSE_FIRE()) damage = damage / 3;
1702                         msg_print(_("熱い!", "It's hot!"));
1703                         take_hit(DAMAGE_NOESCAPE, damage, _("炎のオーラ", "Fire aura"), -1);
1704                 }
1705                 if ((r_info[m_list[p_ptr->riding].r_idx].flags2 & RF2_AURA_ELEC) && !p_ptr->immune_elec)
1706                 {
1707                         damage = r_info[m_list[p_ptr->riding].r_idx].level / 2;
1708                         if (prace_is_(RACE_ANDROID)) damage += damage / 3;
1709                         if (p_ptr->resist_elec) damage = damage / 3;
1710                         if (IS_OPPOSE_ELEC()) damage = damage / 3;
1711                         msg_print(_("痛い!", "It hurts!"));
1712                         take_hit(DAMAGE_NOESCAPE, damage, _("電気のオーラ", "Elec aura"), -1);
1713                 }
1714                 if ((r_info[m_list[p_ptr->riding].r_idx].flags3 & RF3_AURA_COLD) && !p_ptr->immune_cold)
1715                 {
1716                         damage = r_info[m_list[p_ptr->riding].r_idx].level / 2;
1717                         if (p_ptr->resist_cold) damage = damage / 3;
1718                         if (IS_OPPOSE_COLD()) damage = damage / 3;
1719                         msg_print(_("冷たい!", "It's cold!"));
1720                         take_hit(DAMAGE_NOESCAPE, damage, _("冷気のオーラ", "Cold aura"), -1);
1721                 }
1722         }
1723
1724         /* Spectres -- take damage when moving through walls */
1725         /*
1726          * Added: ANYBODY takes damage if inside through walls
1727          * without wraith form -- NOTE: Spectres will never be
1728          * reduced below 0 hp by being inside a stone wall; others
1729          * WILL BE!
1730          */
1731         if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY))
1732         {
1733                 if (!IS_INVULN() && !p_ptr->wraith_form && !p_ptr->kabenuke &&
1734                     ((p_ptr->chp > (p_ptr->lev / 5)) || !p_ptr->pass_wall))
1735                 {
1736                         cptr dam_desc;
1737
1738                         cave_no_regen = TRUE;
1739
1740                         if (p_ptr->pass_wall)
1741                         {
1742                                 msg_print(_("体の分子が分解した気がする!", "Your molecules feel disrupted!"));
1743                                 dam_desc = _("密度", "density");
1744                         }
1745                         else
1746                         {
1747                                 msg_print(_("崩れた岩に押し潰された!", "You are being crushed!"));
1748                                 dam_desc = _("硬い岩", "solid rock");
1749                         }
1750
1751                         take_hit(DAMAGE_NOESCAPE, 1 + (p_ptr->lev / 5), dam_desc, -1);
1752                 }
1753         }
1754
1755
1756         /*** handle regeneration ***/
1757
1758         /* Getting Weak */
1759         if (p_ptr->food < PY_FOOD_WEAK)
1760         {
1761                 /* Lower regeneration */
1762                 if (p_ptr->food < PY_FOOD_STARVE)
1763                 {
1764                         regen_amount = 0;
1765                 }
1766                 else if (p_ptr->food < PY_FOOD_FAINT)
1767                 {
1768                         regen_amount = PY_REGEN_FAINT;
1769                 }
1770                 else
1771                 {
1772                         regen_amount = PY_REGEN_WEAK;
1773                 }
1774         }
1775
1776         /* Are we walking the pattern? */
1777         if (pattern_effect())
1778         {
1779                 cave_no_regen = TRUE;
1780         }
1781         else
1782         {
1783                 /* Regeneration ability */
1784                 if (p_ptr->regenerate)
1785                 {
1786                         regen_amount = regen_amount * 2;
1787                 }
1788                 if (p_ptr->special_defense & (KAMAE_MASK | KATA_MASK))
1789                 {
1790                         regen_amount /= 2;
1791                 }
1792                 if (p_ptr->cursed & TRC_SLOW_REGEN)
1793                 {
1794                         regen_amount /= 5;
1795                 }
1796         }
1797
1798
1799         /* Searching or Resting */
1800         if ((p_ptr->action == ACTION_SEARCH) || (p_ptr->action == ACTION_REST))
1801         {
1802                 regen_amount = regen_amount * 2;
1803         }
1804
1805         upkeep_factor = calculate_upkeep();
1806
1807         /* No regeneration while special action */
1808         if ((p_ptr->action == ACTION_LEARN) ||
1809             (p_ptr->action == ACTION_HAYAGAKE) ||
1810             (p_ptr->special_defense & KATA_KOUKIJIN))
1811         {
1812                 upkeep_factor += 100;
1813         }
1814
1815         /* Regenerate the mana */
1816         regenmana(upkeep_factor, regen_amount);
1817
1818
1819         /* Recharge magic eater's power */
1820         if (p_ptr->pclass == CLASS_MAGIC_EATER)
1821         {
1822                 regenmagic(regen_amount);
1823         }
1824
1825         if ((p_ptr->csp == 0) && (p_ptr->csp_frac == 0))
1826         {
1827                 while (upkeep_factor > 100)
1828                 {
1829                         msg_print(_("こんなに多くのペットを制御できない!", "Too many pets to control at once!"));
1830                         msg_print(NULL);
1831                         do_cmd_pet_dismiss();
1832
1833                         upkeep_factor = calculate_upkeep();
1834
1835                         msg_format(_("維持MPは %d%%", "Upkeep: %d%% mana."), upkeep_factor);
1836                         msg_print(NULL);
1837                 }
1838         }
1839
1840         /* Poisoned or cut yields no healing */
1841         if (p_ptr->poisoned) regen_amount = 0;
1842         if (p_ptr->cut) regen_amount = 0;
1843
1844         /* Special floor -- Pattern, in a wall -- yields no healing */
1845         if (cave_no_regen) regen_amount = 0;
1846
1847         regen_amount = (regen_amount * mutant_regenerate_mod) / 100;
1848
1849         /* Regenerate Hit Points if needed */
1850         if ((p_ptr->chp < p_ptr->mhp) && !cave_no_regen)
1851         {
1852                 regenhp(regen_amount);
1853         }
1854 }
1855
1856 /*!
1857  * @brief 10ゲームターンが進行するごとに魔法効果の残りターンを減らしていく処理
1858  * / Handle timeout every 10 game turns
1859  * @return なし
1860  */
1861 static void process_world_aux_timeout(void)
1862 {
1863         const int dec_count = (easy_band ? 2 : 1);
1864
1865         /*** Timeout Various Things ***/
1866
1867         /* Mimic */
1868         if (p_ptr->tim_mimic)
1869         {
1870                 (void)set_mimic(p_ptr->tim_mimic - 1, p_ptr->mimic_form, TRUE);
1871         }
1872
1873         /* Hack -- Hallucinating */
1874         if (p_ptr->image)
1875         {
1876                 (void)set_image(p_ptr->image - dec_count);
1877         }
1878
1879         /* Blindness */
1880         if (p_ptr->blind)
1881         {
1882                 (void)set_blind(p_ptr->blind - dec_count);
1883         }
1884
1885         /* Times see-invisible */
1886         if (p_ptr->tim_invis)
1887         {
1888                 (void)set_tim_invis(p_ptr->tim_invis - 1, TRUE);
1889         }
1890
1891         if (multi_rew)
1892         {
1893                 multi_rew = FALSE;
1894         }
1895
1896         /* Timed esp */
1897         if (p_ptr->tim_esp)
1898         {
1899                 (void)set_tim_esp(p_ptr->tim_esp - 1, TRUE);
1900         }
1901
1902         /* Timed temporary elemental brands. -LM- */
1903         if (p_ptr->ele_attack)
1904         {
1905                 p_ptr->ele_attack--;
1906
1907                 /* Clear all temporary elemental brands. */
1908                 if (!p_ptr->ele_attack) set_ele_attack(0, 0);
1909         }
1910
1911         /* Timed temporary elemental immune. -LM- */
1912         if (p_ptr->ele_immune)
1913         {
1914                 p_ptr->ele_immune--;
1915
1916                 /* Clear all temporary elemental brands. */
1917                 if (!p_ptr->ele_immune) set_ele_immune(0, 0);
1918         }
1919
1920         /* Timed infra-vision */
1921         if (p_ptr->tim_infra)
1922         {
1923                 (void)set_tim_infra(p_ptr->tim_infra - 1, TRUE);
1924         }
1925
1926         /* Timed stealth */
1927         if (p_ptr->tim_stealth)
1928         {
1929                 (void)set_tim_stealth(p_ptr->tim_stealth - 1, TRUE);
1930         }
1931
1932         /* Timed levitation */
1933         if (p_ptr->tim_levitation)
1934         {
1935                 (void)set_tim_levitation(p_ptr->tim_levitation - 1, TRUE);
1936         }
1937
1938         /* Timed sh_touki */
1939         if (p_ptr->tim_sh_touki)
1940         {
1941                 (void)set_tim_sh_touki(p_ptr->tim_sh_touki - 1, TRUE);
1942         }
1943
1944         /* Timed sh_fire */
1945         if (p_ptr->tim_sh_fire)
1946         {
1947                 (void)set_tim_sh_fire(p_ptr->tim_sh_fire - 1, TRUE);
1948         }
1949
1950         /* Timed sh_holy */
1951         if (p_ptr->tim_sh_holy)
1952         {
1953                 (void)set_tim_sh_holy(p_ptr->tim_sh_holy - 1, TRUE);
1954         }
1955
1956         /* Timed eyeeye */
1957         if (p_ptr->tim_eyeeye)
1958         {
1959                 (void)set_tim_eyeeye(p_ptr->tim_eyeeye - 1, TRUE);
1960         }
1961
1962         /* Timed resist-magic */
1963         if (p_ptr->resist_magic)
1964         {
1965                 (void)set_resist_magic(p_ptr->resist_magic - 1, TRUE);
1966         }
1967
1968         /* Timed regeneration */
1969         if (p_ptr->tim_regen)
1970         {
1971                 (void)set_tim_regen(p_ptr->tim_regen - 1, TRUE);
1972         }
1973
1974         /* Timed resist nether */
1975         if (p_ptr->tim_res_nether)
1976         {
1977                 (void)set_tim_res_nether(p_ptr->tim_res_nether - 1, TRUE);
1978         }
1979
1980         /* Timed resist time */
1981         if (p_ptr->tim_res_time)
1982         {
1983                 (void)set_tim_res_time(p_ptr->tim_res_time - 1, TRUE);
1984         }
1985
1986         /* Timed reflect */
1987         if (p_ptr->tim_reflect)
1988         {
1989                 (void)set_tim_reflect(p_ptr->tim_reflect - 1, TRUE);
1990         }
1991
1992         /* Multi-shadow */
1993         if (p_ptr->multishadow)
1994         {
1995                 (void)set_multishadow(p_ptr->multishadow - 1, TRUE);
1996         }
1997
1998         /* Timed Robe of dust */
1999         if (p_ptr->dustrobe)
2000         {
2001                 (void)set_dustrobe(p_ptr->dustrobe - 1, TRUE);
2002         }
2003
2004         /* Timed infra-vision */
2005         if (p_ptr->kabenuke)
2006         {
2007                 (void)set_kabenuke(p_ptr->kabenuke - 1, TRUE);
2008         }
2009
2010         /* Paralysis */
2011         if (p_ptr->paralyzed)
2012         {
2013                 (void)set_paralyzed(p_ptr->paralyzed - dec_count);
2014         }
2015
2016         /* Confusion */
2017         if (p_ptr->confused)
2018         {
2019                 (void)set_confused(p_ptr->confused - dec_count);
2020         }
2021
2022         /* Afraid */
2023         if (p_ptr->afraid)
2024         {
2025                 (void)set_afraid(p_ptr->afraid - dec_count);
2026         }
2027
2028         /* Fast */
2029         if (p_ptr->fast)
2030         {
2031                 (void)set_fast(p_ptr->fast - 1, TRUE);
2032         }
2033
2034         /* Slow */
2035         if (p_ptr->slow)
2036         {
2037                 (void)set_slow(p_ptr->slow - dec_count, TRUE);
2038         }
2039
2040         /* Protection from evil */
2041         if (p_ptr->protevil)
2042         {
2043                 (void)set_protevil(p_ptr->protevil - 1, TRUE);
2044         }
2045
2046         /* Invulnerability */
2047         if (p_ptr->invuln)
2048         {
2049                 (void)set_invuln(p_ptr->invuln - 1, TRUE);
2050         }
2051
2052         /* Wraith form */
2053         if (p_ptr->wraith_form)
2054         {
2055                 (void)set_wraith_form(p_ptr->wraith_form - 1, TRUE);
2056         }
2057
2058         /* Heroism */
2059         if (p_ptr->hero)
2060         {
2061                 (void)set_hero(p_ptr->hero - 1, TRUE);
2062         }
2063
2064         /* Super Heroism */
2065         if (p_ptr->shero)
2066         {
2067                 (void)set_shero(p_ptr->shero - 1, TRUE);
2068         }
2069
2070         /* Blessed */
2071         if (p_ptr->blessed)
2072         {
2073                 (void)set_blessed(p_ptr->blessed - 1, TRUE);
2074         }
2075
2076         /* Shield */
2077         if (p_ptr->shield)
2078         {
2079                 (void)set_shield(p_ptr->shield - 1, TRUE);
2080         }
2081
2082         /* Tsubureru */
2083         if (p_ptr->tsubureru)
2084         {
2085                 (void)set_tsubureru(p_ptr->tsubureru - 1, TRUE);
2086         }
2087
2088         /* Magicdef */
2089         if (p_ptr->magicdef)
2090         {
2091                 (void)set_magicdef(p_ptr->magicdef - 1, TRUE);
2092         }
2093
2094         /* Tsuyoshi */
2095         if (p_ptr->tsuyoshi)
2096         {
2097                 (void)set_tsuyoshi(p_ptr->tsuyoshi - 1, TRUE);
2098         }
2099
2100         /* Oppose Acid */
2101         if (p_ptr->oppose_acid)
2102         {
2103                 (void)set_oppose_acid(p_ptr->oppose_acid - 1, TRUE);
2104         }
2105
2106         /* Oppose Lightning */
2107         if (p_ptr->oppose_elec)
2108         {
2109                 (void)set_oppose_elec(p_ptr->oppose_elec - 1, TRUE);
2110         }
2111
2112         /* Oppose Fire */
2113         if (p_ptr->oppose_fire)
2114         {
2115                 (void)set_oppose_fire(p_ptr->oppose_fire - 1, TRUE);
2116         }
2117
2118         /* Oppose Cold */
2119         if (p_ptr->oppose_cold)
2120         {
2121                 (void)set_oppose_cold(p_ptr->oppose_cold - 1, TRUE);
2122         }
2123
2124         /* Oppose Poison */
2125         if (p_ptr->oppose_pois)
2126         {
2127                 (void)set_oppose_pois(p_ptr->oppose_pois - 1, TRUE);
2128         }
2129
2130         if (p_ptr->ult_res)
2131         {
2132                 (void)set_ultimate_res(p_ptr->ult_res - 1, TRUE);
2133         }
2134
2135         /*** Poison and Stun and Cut ***/
2136
2137         /* Poison */
2138         if (p_ptr->poisoned)
2139         {
2140                 int adjust = adj_con_fix[p_ptr->stat_ind[A_CON]] + 1;
2141
2142                 /* Apply some healing */
2143                 (void)set_poisoned(p_ptr->poisoned - adjust);
2144         }
2145
2146         /* Stun */
2147         if (p_ptr->stun)
2148         {
2149                 int adjust = adj_con_fix[p_ptr->stat_ind[A_CON]] + 1;
2150
2151                 /* Apply some healing */
2152                 (void)set_stun(p_ptr->stun - adjust);
2153         }
2154
2155         /* Cut */
2156         if (p_ptr->cut)
2157         {
2158                 int adjust = adj_con_fix[p_ptr->stat_ind[A_CON]] + 1;
2159
2160                 /* Hack -- Truly "mortal" wound */
2161                 if (p_ptr->cut > 1000) adjust = 0;
2162
2163                 /* Apply some healing */
2164                 (void)set_cut(p_ptr->cut - adjust);
2165         }
2166 }
2167
2168
2169 /*!
2170  * @brief 10ゲームターンが進行する毎に光源の寿命を減らす処理
2171  * / Handle burning fuel every 10 game turns
2172  * @return なし
2173  */
2174 static void process_world_aux_light(void)
2175 {
2176         /* Check for light being wielded */
2177         object_type *o_ptr = &inventory[INVEN_LITE];
2178
2179         /* Burn some fuel in the current lite */
2180         if (o_ptr->tval == TV_LITE)
2181         {
2182                 /* Hack -- Use some fuel (except on artifacts) */
2183                 if (!(object_is_fixed_artifact(o_ptr) || o_ptr->sval == SV_LITE_FEANOR) && (o_ptr->xtra4 > 0))
2184                 {
2185                         /* Decrease life-span */
2186                         if (o_ptr->name2 == EGO_LITE_LONG)
2187                         {
2188                                 if (turn % (TURNS_PER_TICK*2)) o_ptr->xtra4--;
2189                         }
2190                         else o_ptr->xtra4--;
2191
2192                         /* Notice interesting fuel steps */
2193                         notice_lite_change(o_ptr);
2194                 }
2195         }
2196 }
2197
2198
2199 /*!
2200  * @brief 10ゲームターンが進行するごとに突然変異の発動判定を行う処理
2201  * / Handle mutation effects once every 10 game turns
2202  * @return なし
2203  */
2204 static void process_world_aux_mutation(void)
2205 {
2206         /* No mutation with effects */
2207         if (!p_ptr->muta2) return;
2208
2209         /* No effect on monster arena */
2210         if (p_ptr->inside_battle) return;
2211
2212         /* No effect on the global map */
2213         if (p_ptr->wild_mode) return;
2214
2215
2216         if ((p_ptr->muta2 & MUT2_BERS_RAGE) && one_in_(3000))
2217         {
2218                 disturb(0, 1);
2219                 msg_print(_("ウガァァア!", "RAAAAGHH!"));
2220                 msg_print(_("激怒の発作に襲われた!", "You feel a fit of rage coming over you!"));
2221
2222                 (void)set_shero(10 + randint1(p_ptr->lev), FALSE);
2223                 (void)set_afraid(0);
2224         }
2225
2226         if ((p_ptr->muta2 & MUT2_COWARDICE) && (randint1(3000) == 13))
2227         {
2228                 if (!p_ptr->resist_fear)
2229                 {
2230                         disturb(0, 1);
2231                         msg_print(_("とても暗い... とても恐い!", "It's so dark... so scary!"));
2232                         set_afraid(p_ptr->afraid + 13 + randint1(26));
2233                 }
2234         }
2235
2236         if ((p_ptr->muta2 & MUT2_RTELEPORT) && (randint1(5000) == 88))
2237         {
2238                 if (!p_ptr->resist_nexus && !(p_ptr->muta1 & MUT1_VTELEPORT) &&
2239                     !p_ptr->anti_tele)
2240                 {
2241                         disturb(0, 1);
2242
2243                         /* Teleport player */
2244                         msg_print(_("あなたの位置は突然ひじょうに不確定になった...", "Your position suddenly seems very uncertain..."));
2245                         msg_print(NULL);
2246                         teleport_player(40, TELEPORT_PASSIVE);
2247                 }
2248         }
2249
2250         if ((p_ptr->muta2 & MUT2_ALCOHOL) && (randint1(6400) == 321))
2251         {
2252                 if (!p_ptr->resist_conf && !p_ptr->resist_chaos)
2253                 {
2254                         disturb(0, 1);
2255                         p_ptr->redraw |= PR_EXTRA;
2256                         msg_print(_("いひきがもーろーとひてきたきがふる...ヒック!", "You feel a SSSCHtupor cOmINg over yOu... *HIC*!"));
2257                 }
2258
2259                 if (!p_ptr->resist_conf)
2260                 {
2261                         (void)set_confused(p_ptr->confused + randint0(20) + 15);
2262                 }
2263
2264                 if (!p_ptr->resist_chaos)
2265                 {
2266                         if (one_in_(20))
2267                         {
2268                                 msg_print(NULL);
2269                                 if (one_in_(3)) lose_all_info();
2270                                 else wiz_dark();
2271                                 (void)teleport_player_aux(100, TELEPORT_NONMAGICAL | TELEPORT_PASSIVE);
2272                                 wiz_dark();
2273                                 msg_print(_("あなたは見知らぬ場所で目が醒めた...頭が痛い。", "You wake up somewhere with a sore head..."));
2274                                 msg_print(_("何も覚えていない。どうやってここに来たかも分からない!", "You can't remember a thing, or how you got here!"));
2275                         }
2276                         else
2277                         {
2278                                 if (one_in_(3))
2279                                 {
2280                                         msg_print(_("き~れいなちょおちょらとんれいる~", "Thishcischs GooDSChtuff!"));
2281                                         (void)set_image(p_ptr->image + randint0(150) + 150);
2282                                 }
2283                         }
2284                 }
2285         }
2286
2287         if ((p_ptr->muta2 & MUT2_HALLU) && (randint1(6400) == 42))
2288         {
2289                 if (!p_ptr->resist_chaos)
2290                 {
2291                         disturb(0, 1);
2292                         p_ptr->redraw |= PR_EXTRA;
2293                         (void)set_image(p_ptr->image + randint0(50) + 20);
2294                 }
2295         }
2296
2297         if ((p_ptr->muta2 & MUT2_FLATULENT) && (randint1(3000) == 13))
2298         {
2299                 disturb(0, 1);
2300
2301                 msg_print(_("ブゥーーッ!おっと。", "BRRAAAP! Oops."));
2302
2303                 msg_print(NULL);
2304                 fire_ball(GF_POIS, 0, p_ptr->lev, 3);
2305         }
2306
2307         if ((p_ptr->muta2 & MUT2_PROD_MANA) &&
2308             !p_ptr->anti_magic && one_in_(9000))
2309         {
2310                 int dire = 0;
2311                 disturb(0, 1);
2312                 msg_print(_("魔法のエネルギーが突然あなたの中に流れ込んできた!エネルギーを解放しなければならない!", 
2313                                                 "Magical energy flows through you! You must release it!"));
2314
2315                 flush();
2316                 msg_print(NULL);
2317                 (void)get_hack_dir(&dire);
2318                 fire_ball(GF_MANA, dire, p_ptr->lev * 2, 3);
2319         }
2320
2321         if ((p_ptr->muta2 & MUT2_ATT_DEMON) &&
2322             !p_ptr->anti_magic && (randint1(6666) == 666))
2323         {
2324                 bool pet = one_in_(6);
2325                 BIT_FLAGS mode = PM_ALLOW_GROUP;
2326
2327                 if (pet) mode |= PM_FORCE_PET;
2328                 else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
2329
2330                 if (summon_specific((pet ? -1 : 0), p_ptr->y, p_ptr->x,
2331                                     dun_level, SUMMON_DEMON, mode))
2332                 {
2333                         msg_print(_("あなたはデーモンを引き寄せた!", "You have attracted a demon!"));
2334                         disturb(0, 1);
2335                 }
2336         }
2337
2338         if ((p_ptr->muta2 & MUT2_SPEED_FLUX) && one_in_(6000))
2339         {
2340                 disturb(0, 1);
2341                 if (one_in_(2))
2342                 {
2343                         msg_print(_("精力的でなくなった気がする。", "You feel less energetic."));
2344
2345                         if (p_ptr->fast > 0)
2346                         {
2347                                 set_fast(0, TRUE);
2348                         }
2349                         else
2350                         {
2351                                 set_slow(randint1(30) + 10, FALSE);
2352                         }
2353                 }
2354                 else
2355                 {
2356                         msg_print(_("精力的になった気がする。", "You feel more energetic."));
2357
2358                         if (p_ptr->slow > 0)
2359                         {
2360                                 set_slow(0, TRUE);
2361                         }
2362                         else
2363                         {
2364                                 set_fast(randint1(30) + 10, FALSE);
2365                         }
2366                 }
2367                 msg_print(NULL);
2368         }
2369         if ((p_ptr->muta2 & MUT2_BANISH_ALL) && one_in_(9000))
2370         {
2371                 disturb(0, 1);
2372                 msg_print(_("突然ほとんど孤独になった気がする。", "You suddenly feel almost lonely."));
2373
2374                 banish_monsters(100);
2375                 if (!dun_level && p_ptr->town_num)
2376                 {
2377                         int n;
2378
2379                         /* Pick a random shop (except home) */
2380                         do
2381                         {
2382                                 n = randint0(MAX_STORES);
2383                         }
2384                         while ((n == STORE_HOME) || (n == STORE_MUSEUM));
2385
2386                         msg_print(_("店の主人が丘に向かって走っている!", "You see one of the shopkeepers running for the hills!"));
2387                         store_shuffle(n);
2388                 }
2389                 msg_print(NULL);
2390         }
2391
2392         if ((p_ptr->muta2 & MUT2_EAT_LIGHT) && one_in_(3000))
2393         {
2394                 object_type *o_ptr;
2395
2396                 msg_print(_("影につつまれた。", "A shadow passes over you."));
2397                 msg_print(NULL);
2398
2399                 /* Absorb light from the current possition */
2400                 if ((cave[p_ptr->y][p_ptr->x].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
2401                 {
2402                         hp_player(10);
2403                 }
2404
2405                 o_ptr = &inventory[INVEN_LITE];
2406
2407                 /* Absorb some fuel in the current lite */
2408                 if (o_ptr->tval == TV_LITE)
2409                 {
2410                         /* Use some fuel (except on artifacts) */
2411                         if (!object_is_fixed_artifact(o_ptr) && (o_ptr->xtra4 > 0))
2412                         {
2413                                 /* Heal the player a bit */
2414                                 hp_player(o_ptr->xtra4 / 20);
2415
2416                                 /* Decrease life-span of lite */
2417                                 o_ptr->xtra4 /= 2;
2418                                 msg_print(_("光源からエネルギーを吸収した!", "You absorb energy from your light!"));
2419
2420                                 /* Notice interesting fuel steps */
2421                                 notice_lite_change(o_ptr);
2422                         }
2423                 }
2424
2425                 /*
2426                  * Unlite the area (radius 10) around player and
2427                  * do 50 points damage to every affected monster
2428                  */
2429                 unlite_area(50, 10);
2430         }
2431
2432         if ((p_ptr->muta2 & MUT2_ATT_ANIMAL) &&
2433             !p_ptr->anti_magic && one_in_(7000))
2434         {
2435                 bool pet = one_in_(3);
2436                 BIT_FLAGS mode = PM_ALLOW_GROUP;
2437
2438                 if (pet) mode |= PM_FORCE_PET;
2439                 else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
2440
2441                 if (summon_specific((pet ? -1 : 0), p_ptr->y, p_ptr->x, dun_level, SUMMON_ANIMAL, mode))
2442                 {
2443                         msg_print(_("動物を引き寄せた!", "You have attracted an animal!"));
2444                         disturb(0, 1);
2445                 }
2446         }
2447
2448         if ((p_ptr->muta2 & MUT2_RAW_CHAOS) &&
2449             !p_ptr->anti_magic && one_in_(8000))
2450         {
2451                 disturb(0, 1);
2452                 msg_print(_("周りの空間が歪んでいる気がする!", "You feel the world warping around you!"));
2453
2454                 msg_print(NULL);
2455                 fire_ball(GF_CHAOS, 0, p_ptr->lev, 8);
2456         }
2457         if ((p_ptr->muta2 & MUT2_NORMALITY) && one_in_(5000))
2458         {
2459                 if (!lose_mutation(0))
2460                         msg_print(_("奇妙なくらい普通になった気がする。", "You feel oddly normal."));
2461         }
2462         if ((p_ptr->muta2 & MUT2_WRAITH) && !p_ptr->anti_magic && one_in_(3000))
2463         {
2464                 disturb(0, 1);
2465                 msg_print(_("非物質化した!", "You feel insubstantial!"));
2466
2467                 msg_print(NULL);
2468                 set_wraith_form(randint1(p_ptr->lev / 2) + (p_ptr->lev / 2), FALSE);
2469         }
2470         if ((p_ptr->muta2 & MUT2_POLY_WOUND) && one_in_(3000))
2471         {
2472                 do_poly_wounds();
2473         }
2474         if ((p_ptr->muta2 & MUT2_WASTING) && one_in_(3000))
2475         {
2476                 int which_stat = randint0(6);
2477                 int sustained = FALSE;
2478
2479                 switch (which_stat)
2480                 {
2481                 case A_STR:
2482                         if (p_ptr->sustain_str) sustained = TRUE;
2483                         break;
2484                 case A_INT:
2485                         if (p_ptr->sustain_int) sustained = TRUE;
2486                         break;
2487                 case A_WIS:
2488                         if (p_ptr->sustain_wis) sustained = TRUE;
2489                         break;
2490                 case A_DEX:
2491                         if (p_ptr->sustain_dex) sustained = TRUE;
2492                         break;
2493                 case A_CON:
2494                         if (p_ptr->sustain_con) sustained = TRUE;
2495                         break;
2496                 case A_CHR:
2497                         if (p_ptr->sustain_chr) sustained = TRUE;
2498                         break;
2499                 default:
2500                         msg_print(_("不正な状態!", "Invalid stat chosen!"));
2501                         sustained = TRUE;
2502                 }
2503
2504                 if (!sustained)
2505                 {
2506                         disturb(0, 1);
2507                         msg_print(_("自分が衰弱していくのが分かる!", "You can feel yourself wasting away!"));
2508                         msg_print(NULL);
2509                         (void)dec_stat(which_stat, randint1(6) + 6, one_in_(3));
2510                 }
2511         }
2512         if ((p_ptr->muta2 & MUT2_ATT_DRAGON) &&
2513             !p_ptr->anti_magic && one_in_(3000))
2514         {
2515                 bool pet = one_in_(5);
2516                 BIT_FLAGS mode = PM_ALLOW_GROUP;
2517
2518                 if (pet) mode |= PM_FORCE_PET;
2519                 else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
2520
2521                 if (summon_specific((pet ? -1 : 0), p_ptr->y, p_ptr->x, dun_level, SUMMON_DRAGON, mode))
2522                 {
2523                         msg_print(_("ドラゴンを引き寄せた!", "You have attracted a dragon!"));
2524                         disturb(0, 1);
2525                 }
2526         }
2527         if ((p_ptr->muta2 & MUT2_WEIRD_MIND) && !p_ptr->anti_magic &&
2528             one_in_(3000))
2529         {
2530                 if (p_ptr->tim_esp > 0)
2531                 {
2532                         msg_print(_("精神にもやがかかった!", "Your mind feels cloudy!"));
2533                         set_tim_esp(0, TRUE);
2534                 }
2535                 else
2536                 {
2537                         msg_print(_("精神が広がった!", "Your mind expands!"));
2538                         set_tim_esp(p_ptr->lev, FALSE);
2539                 }
2540         }
2541         if ((p_ptr->muta2 & MUT2_NAUSEA) && !p_ptr->slow_digest &&
2542             one_in_(9000))
2543         {
2544                 disturb(0, 1);
2545                 msg_print(_("胃が痙攣し、食事を失った!", "Your stomach roils, and you lose your lunch!"));
2546                 msg_print(NULL);
2547                 set_food(PY_FOOD_WEAK);
2548                 if (music_singing_any()) stop_singing();
2549                 if (hex_spelling_any()) stop_hex_spell_all();
2550         }
2551
2552         if ((p_ptr->muta2 & MUT2_WALK_SHAD) &&
2553             !p_ptr->anti_magic && one_in_(12000) && !p_ptr->inside_arena)
2554         {
2555                 alter_reality();
2556         }
2557
2558         if ((p_ptr->muta2 & MUT2_WARNING) && one_in_(1000))
2559         {
2560                 int danger_amount = 0;
2561                 int monster;
2562
2563                 for (monster = 0; monster < m_max; monster++)
2564                 {
2565                         monster_type    *m_ptr = &m_list[monster];
2566                         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
2567
2568                         /* Paranoia -- Skip dead monsters */
2569                         if (!m_ptr->r_idx) continue;
2570
2571                         if (r_ptr->level >= p_ptr->lev)
2572                         {
2573                                 danger_amount += r_ptr->level - p_ptr->lev + 1;
2574                         }
2575                 }
2576
2577                 if (danger_amount > 100)
2578                         msg_print(_("非常に恐ろしい気がする!", "You feel utterly terrified!"));
2579                 else if (danger_amount > 50)
2580                         msg_print(_("恐ろしい気がする!", "You feel terrified!"));
2581                 else if (danger_amount > 20)
2582                         msg_print(_("非常に心配な気がする!", "You feel very worried!"));
2583                 else if (danger_amount > 10)
2584                         msg_print(_("心配な気がする!", "You feel paranoid!"));
2585                 else if (danger_amount > 5)
2586                         msg_print(_("ほとんど安全な気がする。", "You feel almost safe."));
2587                 else
2588                         msg_print(_("寂しい気がする。", "You feel lonely."));
2589         }
2590         if ((p_ptr->muta2 & MUT2_INVULN) && !p_ptr->anti_magic &&
2591             one_in_(5000))
2592         {
2593                 disturb(0, 1);
2594                 msg_print(_("無敵な気がする!", "You feel invincible!"));
2595                 msg_print(NULL);
2596                 (void)set_invuln(randint1(8) + 8, FALSE);
2597         }
2598         if ((p_ptr->muta2 & MUT2_SP_TO_HP) && one_in_(2000))
2599         {
2600                 int wounds = p_ptr->mhp - p_ptr->chp;
2601
2602                 if (wounds > 0)
2603                 {
2604                         int healing = p_ptr->csp;
2605
2606                         if (healing > wounds)
2607                         {
2608                                 healing = wounds;
2609                         }
2610
2611                         hp_player(healing);
2612                         p_ptr->csp -= healing;
2613
2614                         /* Redraw mana */
2615                         p_ptr->redraw |= (PR_MANA);
2616                 }
2617         }
2618         if ((p_ptr->muta2 & MUT2_HP_TO_SP) && !p_ptr->anti_magic &&
2619             one_in_(4000))
2620         {
2621                 int wounds = p_ptr->msp - p_ptr->csp;
2622
2623                 if (wounds > 0)
2624                 {
2625                         int healing = p_ptr->chp;
2626
2627                         if (healing > wounds)
2628                         {
2629                                 healing = wounds;
2630                         }
2631
2632                         p_ptr->csp += healing;
2633
2634                         /* Redraw mana */
2635                         p_ptr->redraw |= (PR_MANA);
2636                         take_hit(DAMAGE_LOSELIFE, healing, _("頭に昇った血", "blood rushing to the head"), -1);
2637                 }
2638         }
2639         if ((p_ptr->muta2 & MUT2_DISARM) && one_in_(10000))
2640         {
2641                 INVENTORY_IDX slot = 0;
2642                 object_type *o_ptr = NULL;
2643
2644                 disturb(0, 1);
2645                 msg_print(_("足がもつれて転んだ!", "You trip over your own feet!"));
2646                 take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->wt / 6), _("転倒", "tripping"), -1);
2647
2648                 msg_print(NULL);
2649                 if (buki_motteruka(INVEN_RARM))
2650                 {
2651                         slot = INVEN_RARM;
2652                         o_ptr = &inventory[INVEN_RARM];
2653
2654                         if (buki_motteruka(INVEN_LARM) && one_in_(2))
2655                         {
2656                                 o_ptr = &inventory[INVEN_LARM];
2657                                 slot = INVEN_LARM;
2658                         }
2659                 }
2660                 else if (buki_motteruka(INVEN_LARM))
2661                 {
2662                         o_ptr = &inventory[INVEN_LARM];
2663                         slot = INVEN_LARM;
2664                 }
2665
2666                 if (slot && !object_is_cursed(o_ptr))
2667                 {
2668                         msg_print(_("武器を落としてしまった!", "You drop your weapon!"));
2669                         inven_drop(slot, 1);
2670                 }
2671         }
2672 }
2673
2674 /*!
2675  * @brief 10ゲームターンが進行するごとに装備効果の発動判定を行う処理
2676  * / Handle curse effects once every 10 game turns
2677  * @return なし
2678  */
2679 static void process_world_aux_curse(void)
2680 {
2681         if ((p_ptr->cursed & TRC_P_FLAG_MASK) && !p_ptr->inside_battle && !p_ptr->wild_mode)
2682         {
2683                 /*
2684                  * Hack: Uncursed teleporting items (e.g. Trump Weapons)
2685                  * can actually be useful!
2686                  */
2687                 if ((p_ptr->cursed & TRC_TELEPORT_SELF) && one_in_(200))
2688                 {
2689                         char o_name[MAX_NLEN];
2690                         object_type *o_ptr;
2691                         int i, i_keep = 0, count = 0;
2692
2693                         /* Scan the equipment with random teleport ability */
2694                         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
2695                         {
2696                                 u32b flgs[TR_FLAG_SIZE];
2697                                 o_ptr = &inventory[i];
2698
2699                                 /* Skip non-objects */
2700                                 if (!o_ptr->k_idx) continue;
2701
2702                                 /* Extract the item flags */
2703                                 object_flags(o_ptr, flgs);
2704
2705                                 if (have_flag(flgs, TR_TELEPORT))
2706                                 {
2707                                         /* {.} will stop random teleportation. */
2708                                         if (!o_ptr->inscription || !my_strchr(quark_str(o_ptr->inscription), '.'))
2709                                         {
2710                                                 count++;
2711                                                 if (one_in_(count)) i_keep = i;
2712                                         }
2713                                 }
2714                         }
2715
2716                         o_ptr = &inventory[i_keep];
2717                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2718                         msg_format(_("%sがテレポートの能力を発動させようとしている。", "Your %s is activating teleportation."), o_name);
2719                         if (get_check_strict(_("テレポートしますか?", "Teleport? "), CHECK_OKAY_CANCEL))
2720                         {
2721                                 disturb(0, 1);
2722                                 teleport_player(50, 0L);
2723                         }
2724                         else
2725                         {
2726                                 msg_format(_("%sに{.}(ピリオド)と銘を刻むと発動を抑制できます。", 
2727                                                          "You can inscribe {.} on your %s to disable random teleportation. "), o_name);
2728                                 disturb(1, 1);
2729                         }
2730                 }
2731                 /* Make a chainsword noise */
2732                 if ((p_ptr->cursed & TRC_CHAINSWORD) && one_in_(CHAINSWORD_NOISE))
2733                 {
2734                         char noise[1024];
2735                         if (!get_rnd_line(_("chainswd_j.txt", "chainswd.txt"), 0, noise))
2736                                 msg_print(noise);
2737                         disturb(FALSE, FALSE);
2738                 }
2739                 /* TY Curse */
2740                 if ((p_ptr->cursed & TRC_TY_CURSE) && one_in_(TY_CURSE_CHANCE))
2741                 {
2742                         int count = 0;
2743                         (void)activate_ty_curse(FALSE, &count);
2744                 }
2745                 /* Handle experience draining */
2746                 if (p_ptr->prace != RACE_ANDROID && 
2747                         ((p_ptr->cursed & TRC_DRAIN_EXP) && one_in_(4)))
2748                 {
2749                         p_ptr->exp -= (p_ptr->lev+1)/2;
2750                         if (p_ptr->exp < 0) p_ptr->exp = 0;
2751                         p_ptr->max_exp -= (p_ptr->lev+1)/2;
2752                         if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
2753                         check_experience();
2754                 }
2755                 /* Add light curse (Later) */
2756                 if ((p_ptr->cursed & TRC_ADD_L_CURSE) && one_in_(2000))
2757                 {
2758                         u32b new_curse;
2759                         object_type *o_ptr;
2760
2761                         o_ptr = choose_cursed_obj_name(TRC_ADD_L_CURSE);
2762
2763                         new_curse = get_curse(0, o_ptr);
2764                         if (!(o_ptr->curse_flags & new_curse))
2765                         {
2766                                 char o_name[MAX_NLEN];
2767
2768                                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2769
2770                                 o_ptr->curse_flags |= new_curse;
2771                                 msg_format(_("悪意に満ちた黒いオーラが%sをとりまいた...", "There is a malignant black aura surrounding your %s..."), o_name);
2772
2773                                 o_ptr->feeling = FEEL_NONE;
2774
2775                                 p_ptr->update |= (PU_BONUS);
2776                         }
2777                 }
2778                 /* Add heavy curse (Later) */
2779                 if ((p_ptr->cursed & TRC_ADD_H_CURSE) && one_in_(2000))
2780                 {
2781                         u32b new_curse;
2782                         object_type *o_ptr;
2783
2784                         o_ptr = choose_cursed_obj_name(TRC_ADD_H_CURSE);
2785
2786                         new_curse = get_curse(1, o_ptr);
2787                         if (!(o_ptr->curse_flags & new_curse))
2788                         {
2789                                 char o_name[MAX_NLEN];
2790
2791                                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2792
2793                                 o_ptr->curse_flags |= new_curse;
2794                                 msg_format(_("悪意に満ちた黒いオーラが%sをとりまいた...", "There is a malignant black aura surrounding your %s..."), o_name);
2795                                 o_ptr->feeling = FEEL_NONE;
2796
2797                                 p_ptr->update |= (PU_BONUS);
2798                         }
2799                 }
2800                 /* Call animal */
2801                 if ((p_ptr->cursed & TRC_CALL_ANIMAL) && one_in_(2500))
2802                 {
2803                         if (summon_specific(0, p_ptr->y, p_ptr->x, dun_level, SUMMON_ANIMAL,
2804                             (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
2805                         {
2806                                 char o_name[MAX_NLEN];
2807
2808                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_ANIMAL), (OD_OMIT_PREFIX | OD_NAME_ONLY));
2809                                 msg_format(_("%sが動物を引き寄せた!", "Your %s have attracted an animal!"), o_name);
2810                                 disturb(0, 1);
2811                         }
2812                 }
2813                 /* Call demon */
2814                 if ((p_ptr->cursed & TRC_CALL_DEMON) && one_in_(1111))
2815                 {
2816                         if (summon_specific(0, p_ptr->y, p_ptr->x, dun_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
2817                         {
2818                                 char o_name[MAX_NLEN];
2819
2820                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_DEMON), (OD_OMIT_PREFIX | OD_NAME_ONLY));
2821                                 msg_format(_("%sが悪魔を引き寄せた!", "Your %s have attracted a demon!"), o_name);
2822                                 disturb(0, 1);
2823                         }
2824                 }
2825                 /* Call dragon */
2826                 if ((p_ptr->cursed & TRC_CALL_DRAGON) && one_in_(800))
2827                 {
2828                         if (summon_specific(0, p_ptr->y, p_ptr->x, dun_level, SUMMON_DRAGON,
2829                             (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
2830                         {
2831                                 char o_name[MAX_NLEN];
2832
2833                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_DRAGON), (OD_OMIT_PREFIX | OD_NAME_ONLY));
2834                                 msg_format(_("%sがドラゴンを引き寄せた!", "Your %s have attracted an dragon!"), o_name);
2835                                 disturb(0, 1);
2836                         }
2837                 }
2838                 /* Call undead */
2839                 if ((p_ptr->cursed & TRC_CALL_UNDEAD) && one_in_(1111))
2840                 {
2841                         if (summon_specific(0, p_ptr->y, p_ptr->x, dun_level, SUMMON_UNDEAD,
2842                             (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
2843                         {
2844                                 char o_name[MAX_NLEN];
2845
2846                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_UNDEAD), (OD_OMIT_PREFIX | OD_NAME_ONLY));
2847                                 msg_format(_("%sが死霊を引き寄せた!", "Your %s have attracted an undead!"), o_name);
2848                                 disturb(0, 1);
2849                         }
2850                 }
2851                 if ((p_ptr->cursed & TRC_COWARDICE) && one_in_(1500))
2852                 {
2853                         if (!p_ptr->resist_fear)
2854                         {
2855                                 disturb(0, 1);
2856                                 msg_print(_("とても暗い... とても恐い!", "It's so dark... so scary!"));
2857                                 set_afraid(p_ptr->afraid + 13 + randint1(26));
2858                         }
2859                 }
2860                 /* Teleport player */
2861                 if ((p_ptr->cursed & TRC_TELEPORT) && one_in_(200) && !p_ptr->anti_tele)
2862                 {
2863                         disturb(0, 1);
2864
2865                         /* Teleport player */
2866                         teleport_player(40, TELEPORT_PASSIVE);
2867                 }
2868                 /* Handle HP draining */
2869                 if ((p_ptr->cursed & TRC_DRAIN_HP) && one_in_(666))
2870                 {
2871                         char o_name[MAX_NLEN];
2872
2873                         object_desc(o_name, choose_cursed_obj_name(TRC_DRAIN_HP), (OD_OMIT_PREFIX | OD_NAME_ONLY));
2874                         msg_format(_("%sはあなたの体力を吸収した!", "Your %s drains HP from you!"), o_name);
2875                         take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev*2, 100), o_name, -1);
2876                 }
2877                 /* Handle mana draining */
2878                 if ((p_ptr->cursed & TRC_DRAIN_MANA) && p_ptr->csp && one_in_(666))
2879                 {
2880                         char o_name[MAX_NLEN];
2881
2882                         object_desc(o_name, choose_cursed_obj_name(TRC_DRAIN_MANA), (OD_OMIT_PREFIX | OD_NAME_ONLY));
2883                         msg_format(_("%sはあなたの魔力を吸収した!", "Your %s drains mana from you!"), o_name);
2884                         p_ptr->csp -= MIN(p_ptr->lev, 50);
2885                         if (p_ptr->csp < 0)
2886                         {
2887                                 p_ptr->csp = 0;
2888                                 p_ptr->csp_frac = 0;
2889                         }
2890                         p_ptr->redraw |= PR_MANA;
2891                 }
2892         }
2893
2894         /* Rarely, take damage from the Jewel of Judgement */
2895         if (one_in_(999) && !p_ptr->anti_magic)
2896         {
2897                 object_type *o_ptr = &inventory[INVEN_LITE];
2898
2899                 if (o_ptr->name1 == ART_JUDGE)
2900                 {
2901 #ifdef JP
2902                         if (object_is_known(o_ptr))
2903                                 msg_print("『審判の宝石』はあなたの体力を吸収した!");
2904                         else
2905                                 msg_print("なにかがあなたの体力を吸収した!");
2906                         take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "審判の宝石", -1);
2907 #else
2908                         if (object_is_known(o_ptr))
2909                                 msg_print("The Jewel of Judgement drains life from you!");
2910                         else
2911                                 msg_print("Something drains life from you!");
2912                         take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "the Jewel of Judgement", -1);
2913 #endif
2914                 }
2915         }
2916 }
2917
2918
2919 /*!
2920  * @brief 10ゲームターンが進行するごとに魔道具の自然充填を行う処理
2921  * / Handle recharging objects once every 10 game turns
2922  * @return なし
2923  */
2924 static void process_world_aux_recharge(void)
2925 {
2926         int i;
2927         bool changed;
2928
2929         /* Process equipment */
2930         for (changed = FALSE, i = INVEN_RARM; i < INVEN_TOTAL; i++)
2931         {
2932                 /* Get the object */
2933                 object_type *o_ptr = &inventory[i];
2934
2935                 /* Skip non-objects */
2936                 if (!o_ptr->k_idx) continue;
2937
2938                 /* Recharge activatable objects */
2939                 if (o_ptr->timeout > 0)
2940                 {
2941                         /* Recharge */
2942                         o_ptr->timeout--;
2943
2944                         /* Notice changes */
2945                         if (!o_ptr->timeout)
2946                         {
2947                                 recharged_notice(o_ptr);
2948                                 changed = TRUE;
2949                         }
2950                 }
2951         }
2952
2953         /* Notice changes */
2954         if (changed)
2955         {
2956                 /* Window stuff */
2957                 p_ptr->window |= (PW_EQUIP);
2958                 wild_regen = 20;
2959         }
2960
2961         /*
2962          * Recharge rods.  Rods now use timeout to control charging status,
2963          * and each charging rod in a stack decreases the stack's timeout by
2964          * one per turn. -LM-
2965          */
2966         for (changed = FALSE, i = 0; i < INVEN_PACK; i++)
2967         {
2968                 object_type *o_ptr = &inventory[i];
2969                 object_kind *k_ptr = &k_info[o_ptr->k_idx];
2970
2971                 /* Skip non-objects */
2972                 if (!o_ptr->k_idx) continue;
2973
2974                 /* Examine all charging rods or stacks of charging rods. */
2975                 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
2976                 {
2977                         /* Determine how many rods are charging. */
2978                         TIME_EFFECT temp = (o_ptr->timeout + (k_ptr->pval - 1)) / k_ptr->pval;
2979                         if (temp > o_ptr->number) temp = (TIME_EFFECT)o_ptr->number;
2980
2981                         /* Decrease timeout by that number. */
2982                         o_ptr->timeout -= temp;
2983
2984                         /* Boundary control. */
2985                         if (o_ptr->timeout < 0) o_ptr->timeout = 0;
2986
2987                         /* Notice changes, provide message if object is inscribed. */
2988                         if (!(o_ptr->timeout))
2989                         {
2990                                 recharged_notice(o_ptr);
2991                                 changed = TRUE;
2992                         }
2993
2994                         /* One of the stack of rod is charged */
2995                         else if (o_ptr->timeout % k_ptr->pval)
2996                         {
2997                                 changed = TRUE;
2998                         }
2999                 }
3000         }
3001
3002         /* Notice changes */
3003         if (changed)
3004         {
3005                 /* Window stuff */
3006                 p_ptr->window |= (PW_INVEN);
3007                 wild_regen = 20;
3008         }
3009
3010         /* Process objects on floor */
3011         for (i = 1; i < o_max; i++)
3012         {
3013                 /* Access object */
3014                 object_type *o_ptr = &o_list[i];
3015
3016                 /* Skip dead objects */
3017                 if (!o_ptr->k_idx) continue;
3018
3019                 /* Recharge rods on the ground.  No messages. */
3020                 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
3021                 {
3022                         /* Charge it */
3023                         o_ptr->timeout -= (TIME_EFFECT)o_ptr->number;
3024
3025                         /* Boundary control. */
3026                         if (o_ptr->timeout < 0) o_ptr->timeout = 0;
3027                 }
3028         }
3029 }
3030
3031
3032 /*!
3033  * @brief 10ゲームターンが進行するごとに帰還や現実変容などの残り時間カウントダウンと発動を処理する。
3034  * / Handle involuntary movement once every 10 game turns
3035  * @return なし
3036  */
3037 static void process_world_aux_movement(void)
3038 {
3039         /* Delayed Word-of-Recall */
3040         if (p_ptr->word_recall)
3041         {
3042                 /*
3043                  * HACK: Autosave BEFORE resetting the recall counter (rr9)
3044                  * The player is yanked up/down as soon as
3045                  * he loads the autosaved game.
3046                  */
3047                 if (autosave_l && (p_ptr->word_recall == 1) && !p_ptr->inside_battle)
3048                         do_cmd_save_game(TRUE);
3049
3050                 /* Count down towards recall */
3051                 p_ptr->word_recall--;
3052
3053                 p_ptr->redraw |= (PR_STATUS);
3054
3055                 /* Activate the recall */
3056                 if (!p_ptr->word_recall)
3057                 {
3058                         /* Disturbing! */
3059                         disturb(0, 1);
3060
3061                         /* Determine the level */
3062                         if (dun_level || p_ptr->inside_quest || p_ptr->enter_dungeon)
3063                         {
3064                                 msg_print(_("上に引っ張りあげられる感じがする!",
3065                                                         "You feel yourself yanked upwards!"));
3066
3067                                 if (dungeon_type) p_ptr->recall_dungeon = dungeon_type;
3068                                 if (record_stair)
3069                                         do_cmd_write_nikki(NIKKI_RECALL, dun_level, NULL);
3070
3071                                 dun_level = 0;
3072                                 dungeon_type = 0;
3073
3074                                 leave_quest_check();
3075                                 leave_tower_check();
3076
3077                                 p_ptr->inside_quest = 0;
3078
3079                                 p_ptr->leaving = TRUE;
3080                         }
3081                         else
3082                         {
3083                                 msg_print(_("下に引きずり降ろされる感じがする!",
3084                                                         "You feel yourself yanked downwards!"));
3085
3086                                 dungeon_type = p_ptr->recall_dungeon;
3087
3088                                 if (record_stair)
3089                                         do_cmd_write_nikki(NIKKI_RECALL, dun_level, NULL);
3090
3091                                 /* New depth */
3092                                 dun_level = max_dlv[dungeon_type];
3093                                 if (dun_level < 1) dun_level = 1;
3094
3095                                 /* Nightmare mode makes recall more dangerous */
3096                                 if (ironman_nightmare && !randint0(666) && (dungeon_type == DUNGEON_ANGBAND))
3097                                 {
3098                                         if (dun_level < 50)
3099                                         {
3100                                                 dun_level *= 2;
3101                                         }
3102                                         else if (dun_level < 99)
3103                                         {
3104                                                 dun_level = (dun_level + 99) / 2;
3105                                         }
3106                                         else if (dun_level > 100)
3107                                         {
3108                                                 dun_level = d_info[dungeon_type].maxdepth - 1;
3109                                         }
3110                                 }
3111
3112                                 if (p_ptr->wild_mode)
3113                                 {
3114                                         p_ptr->wilderness_y = p_ptr->y;
3115                                         p_ptr->wilderness_x = p_ptr->x;
3116                                 }
3117                                 else
3118                                 {
3119                                         /* Save player position */
3120                                         p_ptr->oldpx = p_ptr->x;
3121                                         p_ptr->oldpy = p_ptr->y;
3122                                 }
3123                                 p_ptr->wild_mode = FALSE;
3124
3125                                 /*
3126                                  * Clear all saved floors
3127                                  * and create a first saved floor
3128                                  */
3129                                 prepare_change_floor_mode(CFM_FIRST_FLOOR);
3130
3131                                 /* Leaving */
3132                                 p_ptr->leaving = TRUE;
3133
3134                                 if (dungeon_type == DUNGEON_ANGBAND)
3135                                 {
3136                                         int i;
3137
3138                                         for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3139                                         {
3140                                                 quest_type* const q_ptr = &quest[i];
3141
3142                                                 
3143                                                 if ((q_ptr->type == QUEST_TYPE_RANDOM) &&
3144                                                     (q_ptr->status == QUEST_STATUS_TAKEN) &&
3145                                                     (q_ptr->level < dun_level))
3146                                                 {
3147                                                         q_ptr->status = QUEST_STATUS_FAILED;
3148                                                         q_ptr->complev = (byte)p_ptr->lev;
3149                                                         update_playtime();
3150                                                         q_ptr->comptime = playtime;
3151                                                         r_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
3152                                                 }
3153                                         }
3154                                 }
3155                         }
3156
3157                         /* Sound */
3158                         sound(SOUND_TPLEVEL);
3159                 }
3160         }
3161
3162
3163         /* Delayed Alter reality */
3164         if (p_ptr->alter_reality)
3165         {
3166                 if (autosave_l && (p_ptr->alter_reality == 1) && !p_ptr->inside_battle)
3167                         do_cmd_save_game(TRUE);
3168
3169                 /* Count down towards alter */
3170                 p_ptr->alter_reality--;
3171
3172                 p_ptr->redraw |= (PR_STATUS);
3173
3174                 /* Activate the alter reality */
3175                 if (!p_ptr->alter_reality)
3176                 {
3177                         /* Disturbing! */
3178                         disturb(0, 1);
3179
3180                         /* Determine the level */
3181                         if (!quest_number(dun_level) && dun_level)
3182                         {
3183                                 msg_print(_("世界が変わった!", "The world changes!"));
3184
3185                                 /*
3186                                  * Clear all saved floors
3187                                  * and create a first saved floor
3188                                  */
3189                                 prepare_change_floor_mode(CFM_FIRST_FLOOR);
3190
3191                                 /* Leaving */
3192                                 p_ptr->leaving = TRUE;
3193                         }
3194                         else
3195                         {
3196                                 msg_print(_("世界が少しの間変化したようだ。", "The world seems to change for a moment!"));
3197                         }
3198
3199                         /* Sound */
3200                         sound(SOUND_TPLEVEL);
3201                 }
3202         }
3203 }
3204
3205
3206 /*!
3207  * @brief 指定したモンスターに隣接しているモンスターの数を返す。
3208  * / Count number of adjacent monsters
3209  * @param m_idx 隣接数を調べたいモンスターのID
3210  * @return 隣接しているモンスターの数
3211  */
3212 static int get_monster_crowd_number(MONSTER_IDX m_idx)
3213 {
3214         monster_type *m_ptr = &m_list[m_idx];
3215         int my = m_ptr->fy;
3216         int mx = m_ptr->fx;
3217         int i;
3218         int count = 0;
3219
3220         for (i = 0; i < 7; i++)
3221         {
3222                 int ay = my + ddy_ddd[i];
3223                 int ax = mx + ddx_ddd[i];
3224
3225                 if (!in_bounds(ay, ax)) continue;
3226
3227                 /* Count number of monsters */
3228                 if (cave[ay][ax].m_idx > 0) count++;
3229         }
3230
3231         return count;
3232 }
3233
3234
3235
3236 /*!
3237  * ダンジョンの雰囲気を計算するための非線形基準値 / Dungeon rating is no longer linear
3238  */
3239 #define RATING_BOOST(delta) (delta * delta + 50 * delta)
3240
3241 /*!
3242  * @brief ダンジョンの雰囲気を算出する。
3243  * / Examine all monsters and unidentified objects, and get the feeling of current dungeon floor
3244  * @return 算出されたダンジョンの雰囲気ランク
3245  */
3246 static byte get_dungeon_feeling(void)
3247 {
3248         const int base = 10;
3249         int rating = 0;
3250         IDX i;
3251
3252         /* Hack -- no feeling in the town */
3253         if (!dun_level) return 0;
3254
3255         /* Examine each monster */
3256         for (i = 1; i < m_max; i++)
3257         {
3258                 monster_type *m_ptr = &m_list[i];
3259                 monster_race *r_ptr;
3260                 int delta = 0;
3261
3262                 /* Skip dead monsters */
3263                 if (!m_ptr->r_idx) continue;
3264
3265                 /* Ignore pet */
3266                 if (is_pet(m_ptr)) continue;
3267
3268                 r_ptr = &r_info[m_ptr->r_idx];
3269
3270                 /* Unique monsters */
3271                 if (r_ptr->flags1 & (RF1_UNIQUE))
3272                 {
3273                         /* Nearly out-of-depth unique monsters */
3274                         if (r_ptr->level + 10 > dun_level)
3275                         {
3276                                 /* Boost rating by twice delta-depth */
3277                                 delta += (r_ptr->level + 10 - dun_level) * 2 * base;
3278                         }
3279                 }
3280                 else
3281                 {
3282                         /* Out-of-depth monsters */
3283                         if (r_ptr->level > dun_level)
3284                         {
3285                                 /* Boost rating by delta-depth */
3286                                 delta += (r_ptr->level - dun_level) * base;
3287                         }
3288                 }
3289
3290                 /* Unusually crowded monsters get a little bit of rating boost */
3291                 if (r_ptr->flags1 & RF1_FRIENDS)
3292                 {
3293                         if (5 <= get_monster_crowd_number(i)) delta += 1;
3294                 }
3295                 else
3296                 {
3297                         if (2 <= get_monster_crowd_number(i)) delta += 1;
3298                 }
3299
3300
3301                 rating += RATING_BOOST(delta);
3302         }
3303
3304         /* Examine each unidentified object */
3305         for (i = 1; i < o_max; i++)
3306         {
3307                 object_type *o_ptr = &o_list[i];
3308                 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3309                 int delta = 0;
3310
3311                 /* Skip dead objects */
3312                 if (!o_ptr->k_idx) continue;
3313
3314                 /* Skip known objects */
3315                 if (object_is_known(o_ptr))
3316                 {
3317                         /* Touched? */
3318                         if (o_ptr->marked & OM_TOUCHED) continue;
3319                 }
3320
3321                 /* Skip pseudo-known objects */
3322                 if (o_ptr->ident & IDENT_SENSE) continue;
3323
3324                 /* Ego objects */
3325                 if (object_is_ego(o_ptr))
3326                 {
3327                         ego_item_type *e_ptr = &e_info[o_ptr->name2];
3328
3329                         delta += e_ptr->rating * base;
3330                 }
3331
3332                 /* Artifacts */
3333                 if (object_is_artifact(o_ptr))
3334                 {
3335                         s32b cost = object_value_real(o_ptr);
3336
3337                         delta += 10 * base;
3338                         if (cost > 10000L) delta += 10 * base;
3339                         if (cost > 50000L) delta += 10 * base;
3340                         if (cost > 100000L) delta += 10 * base;
3341
3342                         /* Special feeling */
3343                         if (!preserve_mode) return 1;
3344                 }
3345
3346                 if (o_ptr->tval == TV_DRAG_ARMOR) delta += 30 * base;
3347                 if (o_ptr->tval == TV_SHIELD &&
3348                     o_ptr->sval == SV_DRAGON_SHIELD) delta += 5 * base;
3349                 if (o_ptr->tval == TV_GLOVES &&
3350                     o_ptr->sval == SV_SET_OF_DRAGON_GLOVES) delta += 5 * base;
3351                 if (o_ptr->tval == TV_BOOTS &&
3352                     o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE) delta += 5 * base;
3353                 if (o_ptr->tval == TV_HELM &&
3354                     o_ptr->sval == SV_DRAGON_HELM) delta += 5 * base;
3355                 if (o_ptr->tval == TV_RING &&
3356                     o_ptr->sval == SV_RING_SPEED &&
3357                     !object_is_cursed(o_ptr)) delta += 25 * base;
3358                 if (o_ptr->tval == TV_RING &&
3359                     o_ptr->sval == SV_RING_LORDLY &&
3360                     !object_is_cursed(o_ptr)) delta += 15 * base;
3361                 if (o_ptr->tval == TV_AMULET &&
3362                     o_ptr->sval == SV_AMULET_THE_MAGI &&
3363                     !object_is_cursed(o_ptr)) delta += 15 * base;
3364
3365                 /* Out-of-depth objects */
3366                 if (!object_is_cursed(o_ptr) && !object_is_broken(o_ptr) &&
3367                     k_ptr->level > dun_level)
3368                 {
3369                         /* Rating increase */
3370                         delta += (k_ptr->level - dun_level) * base;
3371                 }
3372
3373                 rating += RATING_BOOST(delta);
3374         }
3375
3376
3377         if (rating > RATING_BOOST(1000)) return 2;
3378         if (rating > RATING_BOOST(800)) return 3;
3379         if (rating > RATING_BOOST(600)) return 4;
3380         if (rating > RATING_BOOST(400)) return 5;
3381         if (rating > RATING_BOOST(300)) return 6;
3382         if (rating > RATING_BOOST(200)) return 7;
3383         if (rating > RATING_BOOST(100)) return 8;
3384         if (rating > RATING_BOOST(0)) return 9;
3385
3386         return 10;
3387 }
3388
3389 /*!
3390  * @brief ダンジョンの雰囲気を更新し、変化があった場合メッセージを表示する
3391  * / Update dungeon feeling, and announce it if changed
3392  * @return なし
3393  */
3394 static void update_dungeon_feeling(void)
3395 {
3396         byte new_feeling;
3397         int quest_num;
3398         int delay;
3399
3400         /* No feeling on the surface */
3401         if (!dun_level) return;
3402
3403         /* No feeling in the arena */
3404         if (p_ptr->inside_battle) return;
3405
3406         /* Extract delay time */
3407         delay = MAX(10, 150 - p_ptr->skill_fos) * (150 - dun_level) * TURNS_PER_TICK / 100;
3408
3409         /* Not yet felt anything */
3410         if (turn < p_ptr->feeling_turn + delay && !cheat_xtra) return;
3411
3412         /* Extract quest number (if any) */
3413         quest_num = quest_number(dun_level);
3414
3415         /* No feeling in a quest */
3416         if (quest_num &&
3417             (is_fixed_quest_idx(quest_num) &&
3418              !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) ||
3419                !(quest[quest_num].flags & QUEST_FLAG_PRESET)))) return;
3420
3421
3422         /* Get new dungeon feeling */
3423         new_feeling = get_dungeon_feeling();
3424
3425         /* Remember last time updated */
3426         p_ptr->feeling_turn = turn;
3427
3428         /* No change */
3429         if (p_ptr->feeling == new_feeling) return;
3430
3431         /* Dungeon feeling is changed */
3432         p_ptr->feeling = new_feeling;
3433
3434         /* Announce feeling */
3435         do_cmd_feeling();
3436
3437         select_floor_music();
3438
3439         /* Update the level indicator */
3440         p_ptr->redraw |= (PR_DEPTH);
3441
3442         /* Disturb */
3443         if (disturb_minor) disturb(0, 0);
3444 }
3445
3446 /*!
3447  * @brief 10ゲームターンが進行する毎にゲーム世界全体の処理を行う。
3448  * / Handle certain things once every 10 game turns
3449  * @return なし
3450  */
3451 static void process_world(void)
3452 {
3453         int day, hour, min;
3454
3455         const s32b A_DAY = TURNS_PER_TICK * TOWN_DAWN;
3456         s32b prev_turn_in_today = ((turn - TURNS_PER_TICK) % A_DAY + A_DAY / 4) % A_DAY;
3457         int prev_min = (1440 * prev_turn_in_today / A_DAY) % 60;
3458         
3459         extract_day_hour_min(&day, &hour, &min);
3460
3461         /* Update dungeon feeling, and announce it if changed */
3462         update_dungeon_feeling();
3463
3464         /* 帰還無しモード時のレベルテレポバグ対策 / Fix for level teleport bugs on ironman_downward.*/
3465         if (ironman_downward && (dungeon_type != DUNGEON_ANGBAND && dungeon_type != 0))
3466         {
3467                 dun_level = 0;
3468                 dungeon_type = 0;
3469                 prepare_change_floor_mode(CFM_FIRST_FLOOR | CFM_RAND_PLACE);
3470                 p_ptr->inside_arena = FALSE;
3471                 p_ptr->wild_mode = FALSE;
3472                 p_ptr->leaving = TRUE;
3473         }
3474
3475         /*** Check monster arena ***/
3476         if (p_ptr->inside_battle && !p_ptr->leaving)
3477         {
3478                 int i2, j2;
3479                 int win_m_idx = 0;
3480                 int number_mon = 0;
3481
3482                 /* Count all hostile monsters */
3483                 for (i2 = 0; i2 < cur_wid; ++i2)
3484                         for (j2 = 0; j2 < cur_hgt; j2++)
3485                         {
3486                                 cave_type *c_ptr = &cave[j2][i2];
3487
3488                                 if ((c_ptr->m_idx > 0) && (c_ptr->m_idx != p_ptr->riding))
3489                                 {
3490                                         number_mon++;
3491                                         win_m_idx = c_ptr->m_idx;
3492                                 }
3493                         }
3494
3495                 if (number_mon == 0)
3496                 {
3497                         msg_print(_("相打ちに終わりました。", "They have kill each other at the same time."));
3498                         msg_print(NULL);
3499                         p_ptr->energy_need = 0;
3500                         battle_monsters();
3501                 }
3502                 else if ((number_mon-1) == 0)
3503                 {
3504                         char m_name[80];
3505                         monster_type *wm_ptr;
3506
3507                         wm_ptr = &m_list[win_m_idx];
3508
3509                         monster_desc(m_name, wm_ptr, 0);
3510                         msg_format(_("%sが勝利した!", "%s is winner!"), m_name);
3511                         msg_print(NULL);
3512
3513                         if (win_m_idx == (sel_monster+1))
3514                         {
3515                                 msg_print(_("おめでとうございます。", "Congratulations."));
3516                                 msg_format(_("%d$を受け取った。", "You received %d gold."), battle_odds);
3517                                 p_ptr->au += battle_odds;
3518                         }
3519                         else
3520                         {
3521                                 msg_print(_("残念でした。", "You lost gold."));
3522                         }
3523                         msg_print(NULL);
3524                         p_ptr->energy_need = 0;
3525                         battle_monsters();
3526                 }
3527                 else if (turn - old_turn == 150 * TURNS_PER_TICK)
3528                 {
3529                         msg_print(_("申し分けありませんが、この勝負は引き分けとさせていただきます。", "This battle have ended in a draw."));
3530                         p_ptr->au += kakekin;
3531                         msg_print(NULL);
3532                         p_ptr->energy_need = 0;
3533                         battle_monsters();
3534                 }
3535         }
3536
3537         /* Every 10 game turns */
3538         if (turn % TURNS_PER_TICK) return;
3539
3540         /*** Check the Time and Load ***/
3541
3542         if (!(turn % (50*TURNS_PER_TICK)))
3543         {
3544                 /* Check time and load */
3545                 if ((0 != check_time()) || (0 != check_load()))
3546                 {
3547                         /* Warning */
3548                         if (closing_flag <= 2)
3549                         {
3550                                 /* Disturb */
3551                                 disturb(0, 1);
3552
3553                                 /* Count warnings */
3554                                 closing_flag++;
3555
3556                                 /* Message */
3557                                 msg_print(_("アングバンドへの門が閉じかかっています...", "The gates to ANGBAND are closing..."));
3558                                 msg_print(_("ゲームを終了するかセーブするかして下さい。", "Please finish up and/or save your game."));
3559
3560                         }
3561
3562                         /* Slam the gate */
3563                         else
3564                         {
3565                                 /* Message */
3566                                 msg_print(_("今、アングバンドへの門が閉ざされました。", "The gates to ANGBAND are now closed."));
3567
3568                                 /* Stop playing */
3569                                 p_ptr->playing = FALSE;
3570
3571                                 /* Leaving */
3572                                 p_ptr->leaving = TRUE;
3573                         }
3574                 }
3575         }
3576
3577         /*** Attempt timed autosave ***/
3578         if (autosave_t && autosave_freq && !p_ptr->inside_battle)
3579         {
3580                 if (!(turn % ((s32b)autosave_freq * TURNS_PER_TICK)))
3581                         do_cmd_save_game(TRUE);
3582         }
3583
3584         if (mon_fight && !ignore_unview)
3585         {
3586                 msg_print(_("何かが聞こえた。", "You hear noise."));
3587         }
3588
3589         /*** Handle the wilderness/town (sunshine) ***/
3590
3591         /* While in town/wilderness */
3592         if (!dun_level && !p_ptr->inside_quest && !p_ptr->inside_battle && !p_ptr->inside_arena)
3593         {
3594                 /* Hack -- Daybreak/Nighfall in town */
3595                 if (!(turn % ((TURNS_PER_TICK * TOWN_DAWN) / 2)))
3596                 {
3597                         bool dawn;
3598
3599                         /* Check for dawn */
3600                         dawn = (!(turn % (TURNS_PER_TICK * TOWN_DAWN)));
3601
3602                         /* Day breaks */
3603                         if (dawn)
3604                         {
3605                                 int y, x;
3606
3607                                 /* Message */
3608                                 msg_print(_("夜が明けた。", "The sun has risen."));
3609
3610                                 if (!p_ptr->wild_mode)
3611                                 {
3612                                         /* Hack -- Scan the town */
3613                                         for (y = 0; y < cur_hgt; y++)
3614                                         {
3615                                                 for (x = 0; x < cur_wid; x++)
3616                                                 {
3617                                                         /* Get the cave grid */
3618                                                         cave_type *c_ptr = &cave[y][x];
3619
3620                                                         /* Assume lit */
3621                                                         c_ptr->info |= (CAVE_GLOW);
3622
3623                                                         /* Hack -- Memorize lit grids if allowed */
3624                                                         if (view_perma_grids) c_ptr->info |= (CAVE_MARK);
3625
3626                                                         /* Hack -- Notice spot */
3627                                                         note_spot(y, x);
3628                                                 }
3629                                         }
3630                                 }
3631                         }
3632
3633                         /* Night falls */
3634                         else
3635                         {
3636                                 int y, x;
3637
3638                                 /* Message */
3639                                 msg_print(_("日が沈んだ。", "The sun has fallen."));
3640
3641                                 if (!p_ptr->wild_mode)
3642                                 {
3643                                         /* Hack -- Scan the town */
3644                                         for (y = 0; y < cur_hgt; y++)
3645                                         {
3646                                                 for (x = 0; x < cur_wid; x++)
3647                                                 {
3648                                                         /* Get the cave grid */
3649                                                         cave_type *c_ptr = &cave[y][x];
3650
3651                                                         /* Feature code (applying "mimic" field) */
3652                                                         feature_type *f_ptr = &f_info[get_feat_mimic(c_ptr)];
3653
3654                                                         if (!is_mirror_grid(c_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
3655                                                             !have_flag(f_ptr->flags, FF_ENTRANCE))
3656                                                         {
3657                                                                 /* Assume dark */
3658                                                                 c_ptr->info &= ~(CAVE_GLOW);
3659
3660                                                                 if (!have_flag(f_ptr->flags, FF_REMEMBER))
3661                                                                 {
3662                                                                         /* Forget the normal floor grid */
3663                                                                         c_ptr->info &= ~(CAVE_MARK);
3664
3665                                                                         /* Hack -- Notice spot */
3666                                                                         note_spot(y, x);
3667                                                                 }
3668                                                         }
3669                                                 }
3670
3671                                                 /* Glow deep lava and building entrances */
3672                                                 glow_deep_lava_and_bldg();
3673                                         }
3674                                 }
3675                         }
3676
3677                         /* Update the monsters */
3678                         p_ptr->update |= (PU_MONSTERS | PU_MON_LITE);
3679
3680                         /* Redraw map */
3681                         p_ptr->redraw |= (PR_MAP);
3682
3683                         /* Window stuff */
3684                         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3685
3686                         if (p_ptr->special_defense & NINJA_S_STEALTH)
3687                         {
3688                                 if (cave[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
3689                         }
3690                 }
3691         }
3692
3693         /* While in the dungeon (vanilla_town or lite_town mode only) */
3694         else if ((vanilla_town || (lite_town && !p_ptr->inside_quest && !p_ptr->inside_battle && !p_ptr->inside_arena)) && dun_level)
3695         {
3696                 /*** Shuffle the Storekeepers ***/
3697
3698                 /* Chance is only once a day (while in dungeon) */
3699                 if (!(turn % (TURNS_PER_TICK * STORE_TICKS)))
3700                 {
3701                         /* Sometimes, shuffle the shop-keepers */
3702                         if (one_in_(STORE_SHUFFLE))
3703                         {
3704                                 int n, i;
3705
3706                                 /* Pick a random shop (except home and museum) */
3707                                 do
3708                                 {
3709                                         n = randint0(MAX_STORES);
3710                                 }
3711                                 while ((n == STORE_HOME) || (n == STORE_MUSEUM));
3712
3713                                 /* Check every feature */
3714                                 for (i = 1; i < max_f_idx; i++)
3715                                 {
3716                                         /* Access the index */
3717                                         feature_type *f_ptr = &f_info[i];
3718
3719                                         /* Skip empty index */
3720                                         if (!f_ptr->name) continue;
3721
3722                                         /* Skip non-store features */
3723                                         if (!have_flag(f_ptr->flags, FF_STORE)) continue;
3724
3725                                         /* Verify store type */
3726                                         if (f_ptr->subtype == n)
3727                                         {
3728                                                 /* Message */
3729                                                 if (cheat_xtra) msg_format(_("%sの店主をシャッフルします。", "Shuffle a Shopkeeper of %s."), f_name + f_ptr->name);
3730
3731                                                 /* Shuffle it */
3732                                                 store_shuffle(n);
3733
3734                                                 break;
3735                                         }
3736                                 }
3737                         }
3738                 }
3739         }
3740
3741
3742         /*** Process the monsters ***/
3743
3744         /* Check for creature generation. */
3745         if (one_in_(d_info[dungeon_type].max_m_alloc_chance) &&
3746             !p_ptr->inside_arena && !p_ptr->inside_quest && !p_ptr->inside_battle)
3747         {
3748                 /* Make a new monster */
3749                 (void)alloc_monster(MAX_SIGHT + 5, 0);
3750         }
3751
3752         /* Hack -- Check for creature regeneration */
3753         if (!(turn % (TURNS_PER_TICK*10)) && !p_ptr->inside_battle) regen_monsters();
3754         if (!(turn % (TURNS_PER_TICK*3))) regen_captured_monsters();
3755
3756         if (!p_ptr->leaving)
3757         {
3758                 int i;
3759
3760                 /* Hack -- Process the counters of monsters if needed */
3761                 for (i = 0; i < MAX_MTIMED; i++)
3762                 {
3763                         if (mproc_max[i] > 0) process_monsters_mtimed(i);
3764                 }
3765         }
3766
3767
3768         /* Date changes */
3769         if (!hour && !min)
3770         {
3771                 if (min != prev_min)
3772                 {
3773                         do_cmd_write_nikki(NIKKI_HIGAWARI, 0, NULL);
3774                         determine_today_mon(FALSE);
3775                 }
3776         }
3777
3778         /*
3779          * Nightmare mode activates the TY_CURSE at midnight
3780          * Require exact minute -- Don't activate multiple times in a minute
3781          */
3782
3783         if (ironman_nightmare && (min != prev_min))
3784         {
3785
3786                 /* Every 15 minutes after 11:00 pm */
3787                 if ((hour == 23) && !(min % 15))
3788                 {
3789                         /* Disturbing */
3790                         disturb(0, 1);
3791
3792                         switch (min / 15)
3793                         {
3794                         case 0:
3795                                 msg_print(_("遠くで不気味な鐘の音が鳴った。", "You hear a distant bell toll ominously."));
3796                                 break;
3797
3798                         case 1:
3799                                 msg_print(_("遠くで鐘が二回鳴った。", "A distant bell sounds twice."));
3800                                 break;
3801
3802                         case 2:
3803                                 msg_print(_("遠くで鐘が三回鳴った。", "A distant bell sounds three times."));
3804                                 break;
3805
3806                         case 3:
3807                                 msg_print(_("遠くで鐘が四回鳴った。", "A distant bell tolls four times."));
3808                                 break;
3809                         }
3810                 }
3811
3812                 /* TY_CURSE activates at midnight! */
3813                 if (!hour && !min)
3814                 {
3815
3816                         disturb(1, 1);
3817                         msg_print(_("遠くで鐘が何回も鳴り、死んだような静けさの中へ消えていった。", "A distant bell tolls many times, fading into an deathly silence."));
3818
3819                         if (p_ptr->wild_mode)
3820                         {
3821                                 /* Go into large wilderness view */
3822                                 p_ptr->oldpy = randint1(MAX_HGT - 2);
3823                                 p_ptr->oldpx = randint1(MAX_WID - 2);
3824                                 change_wild_mode();
3825
3826                                 /* Give first move to monsters */
3827                                 p_ptr->energy_use = 100;
3828
3829                                 /* HACk -- set the encouter flag for the wilderness generation */
3830                                 generate_encounter = TRUE;
3831                         }
3832
3833                         invoking_midnight_curse = TRUE;
3834                 }
3835         }
3836
3837
3838         /*** Check the Food, and Regenerate ***/
3839
3840         if (!p_ptr->inside_battle)
3841         {
3842                 /* Digest quickly when gorged */
3843                 if (p_ptr->food >= PY_FOOD_MAX)
3844                 {
3845                         /* Digest a lot of food */
3846                         (void)set_food(p_ptr->food - 100);
3847                 }
3848
3849                 /* Digest normally -- Every 50 game turns */
3850                 else if (!(turn % (TURNS_PER_TICK*5)))
3851                 {
3852                         /* Basic digestion rate based on speed */
3853                         int digestion = SPEED_TO_ENERGY(p_ptr->pspeed);
3854
3855                         /* Regeneration takes more food */
3856                         if (p_ptr->regenerate)
3857                                 digestion += 20;
3858                         if (p_ptr->special_defense & (KAMAE_MASK | KATA_MASK))
3859                                 digestion += 20;
3860                         if (p_ptr->cursed & TRC_FAST_DIGEST)
3861                                 digestion += 30;
3862
3863                         /* Slow digestion takes less food */
3864                         if (p_ptr->slow_digest)
3865                                 digestion -= 5;
3866
3867                         /* Minimal digestion */
3868                         if (digestion < 1) digestion = 1;
3869                         /* Maximal digestion */
3870                         if (digestion > 100) digestion = 100;
3871
3872                         /* Digest some food */
3873                         (void)set_food(p_ptr->food - digestion);
3874                 }
3875
3876
3877                 /* Getting Faint */
3878                 if ((p_ptr->food < PY_FOOD_FAINT))
3879                 {
3880                         /* Faint occasionally */
3881                         if (!p_ptr->paralyzed && (randint0(100) < 10))
3882                         {
3883                                 /* Message */
3884                                 msg_print(_("あまりにも空腹で気絶してしまった。", "You faint from the lack of food."));
3885                                 disturb(1, 1);
3886
3887                                 /* Hack -- faint (bypass free action) */
3888                                 (void)set_paralyzed(p_ptr->paralyzed + 1 + randint0(5));
3889                         }
3890
3891                         /* Starve to death (slowly) */
3892                         if (p_ptr->food < PY_FOOD_STARVE)
3893                         {
3894                                 /* Calculate damage */
3895                                 HIT_POINT dam = (PY_FOOD_STARVE - p_ptr->food) / 10;
3896
3897                                 /* Take damage */
3898                                 if (!IS_INVULN()) take_hit(DAMAGE_LOSELIFE, dam, _("空腹", "starvation"), -1);
3899                         }
3900                 }
3901         }
3902
3903
3904
3905         /* Process timed damage and regeneration */
3906         process_world_aux_hp_and_sp();
3907
3908         /* Process timeout */
3909         process_world_aux_timeout();
3910
3911         /* Process light */
3912         process_world_aux_light();
3913
3914         /* Process mutation effects */
3915         process_world_aux_mutation();
3916
3917         /* Process curse effects */
3918         process_world_aux_curse();
3919
3920         /* Process recharging */
3921         process_world_aux_recharge();
3922
3923         /* Feel the inventory */
3924         sense_inventory1();
3925         sense_inventory2();
3926
3927         /* Involuntary Movement */
3928         process_world_aux_movement();
3929 }
3930
3931 /*!
3932  * @brief ウィザードモードへの導入処理
3933  * / Verify use of "wizard" mode
3934  * @return 実際にウィザードモードへ移行したらTRUEを返す。
3935  */
3936 static bool enter_wizard_mode(void)
3937 {
3938         /* Ask first time */
3939         if (!p_ptr->noscore)
3940         {
3941                 /* Wizard mode is not permitted */
3942                 if (!allow_debug_opts || arg_wizard)
3943                 {
3944                         msg_print(_("ウィザードモードは許可されていません。 ", "Wizard mode is not permitted."));
3945                         return FALSE;
3946                 }
3947
3948                 /* Mention effects */
3949                 msg_print(_("ウィザードモードはデバッグと実験のためのモードです。 ", "Wizard mode is for debugging and experimenting."));
3950                 msg_print(_("一度ウィザードモードに入るとスコアは記録されません。", "The game will not be scored if you enter wizard mode."));
3951                 msg_print(NULL);
3952
3953                 /* Verify request */
3954                 if (!get_check(_("本当にウィザードモードに入りたいのですか? ", "Are you sure you want to enter wizard mode? ")))
3955                 {
3956                         return (FALSE);
3957                 }
3958
3959                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("ウィザードモードに突入してスコアを残せなくなった。", "give up recording score to enter wizard mode."));
3960                 /* Mark savefile */
3961                 p_ptr->noscore |= 0x0002;
3962         }
3963
3964         /* Success */
3965         return (TRUE);
3966 }
3967
3968
3969 #ifdef ALLOW_WIZARD
3970
3971 /*!
3972  * @brief デバッグコマンドへの導入処理
3973  * / Verify use of "debug" commands
3974  * @return 実際にデバッグコマンドへ移行したらTRUEを返す。
3975  */
3976 static bool enter_debug_mode(void)
3977 {
3978         /* Ask first time */
3979         if (!p_ptr->noscore)
3980         {
3981                 /* Debug mode is not permitted */
3982                 if (!allow_debug_opts)
3983                 {
3984                         msg_print(_("デバッグコマンドは許可されていません。 ", "Use of debug command is not permitted."));
3985                         return FALSE;
3986                 }
3987
3988                 /* Mention effects */
3989                 msg_print(_("デバッグ・コマンドはデバッグと実験のためのコマンドです。 ", "The debug commands are for debugging and experimenting."));
3990                 msg_print(_("デバッグ・コマンドを使うとスコアは記録されません。", "The game will not be scored if you use debug commands."));
3991
3992                 msg_print(NULL);
3993
3994                 /* Verify request */
3995                 if (!get_check(_("本当にデバッグ・コマンドを使いますか? ", "Are you sure you want to use debug commands? ")))
3996                 {
3997                         return (FALSE);
3998                 }
3999
4000                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("デバッグモードに突入してスコアを残せなくなった。", "give up sending score to use debug commands."));
4001                 /* Mark savefile */
4002                 p_ptr->noscore |= 0x0008;
4003         }
4004
4005         /* Success */
4006         return (TRUE);
4007 }
4008
4009 /*
4010  * Hack -- Declare the Debug Routines
4011  */
4012 extern void do_cmd_debug(void);
4013
4014 #endif /* ALLOW_WIZARD */
4015
4016
4017 #ifdef ALLOW_BORG
4018
4019 /*!
4020  * @brief ボーグコマンドへの導入処理
4021  * / Verify use of "borg" commands
4022  * @return 実際にボーグコマンドへ移行したらTRUEを返す。
4023  */
4024 static bool enter_borg_mode(void)
4025 {
4026         /* Ask first time */
4027         if (!(p_ptr->noscore & 0x0010))
4028         {
4029                 /* Mention effects */
4030                 msg_print(_("ボーグ・コマンドはデバッグと実験のためのコマンドです。 ", "The borg commands are for debugging and experimenting."));
4031                 msg_print(_("ボーグ・コマンドを使うとスコアは記録されません。", "The game will not be scored if you use borg commands."));
4032
4033                 msg_print(NULL);
4034
4035                 /* Verify request */
4036                 if (!get_check(_("本当にボーグ・コマンドを使いますか? ", "Are you sure you want to use borg commands? ")))
4037                 {
4038                         return (FALSE);
4039                 }
4040
4041                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("ボーグ・コマンドを使用してスコアを残せなくなった。", "give up recording score to use borg commands."));
4042                 /* Mark savefile */
4043                 p_ptr->noscore |= 0x0010;
4044         }
4045
4046         /* Success */
4047         return (TRUE);
4048 }
4049
4050 /*
4051  * Hack -- Declare the Ben Borg
4052  */
4053 extern void do_cmd_borg(void);
4054
4055 #endif /* ALLOW_BORG */
4056
4057
4058 /*!
4059  * @brief プレイヤーから受けた入力コマンドの分岐処理。
4060  * / Parse and execute the current command Give "Warning" on illegal commands.
4061  * @todo XXX XXX XXX Make some "blocks"
4062  * @return なし
4063  */
4064 static void process_command(void)
4065 {
4066         COMMAND_CODE old_now_message = now_message;
4067
4068 #ifdef ALLOW_REPEAT /* TNB */
4069
4070         /* Handle repeating the last command */
4071         repeat_check();
4072
4073 #endif /* ALLOW_REPEAT -- TNB */
4074
4075         now_message = 0;
4076
4077         /* Sniper */
4078         if ((p_ptr->pclass == CLASS_SNIPER) && (p_ptr->concent))
4079                 reset_concent = TRUE;
4080
4081         /* Parse the command */
4082         switch (command_cmd)
4083         {
4084                 /* Ignore */
4085                 case ESCAPE:
4086                 case ' ':
4087                 {
4088                         break;
4089                 }
4090
4091                 /* Ignore return */
4092                 case '\r':
4093                 case '\n':
4094                 {
4095                         break;
4096                 }
4097
4098                 /*** Wizard Commands ***/
4099
4100                 /* Toggle Wizard Mode */
4101                 case KTRL('W'):
4102                 {
4103                         if (p_ptr->wizard)
4104                         {
4105                                 p_ptr->wizard = FALSE;
4106                                 msg_print(_("ウィザードモード解除。", "Wizard mode off."));
4107                         }
4108                         else if (enter_wizard_mode())
4109                         {
4110                                 p_ptr->wizard = TRUE;
4111                                 msg_print(_("ウィザードモード突入。", "Wizard mode on."));
4112                         }
4113
4114                         /* Update monsters */
4115                         p_ptr->update |= (PU_MONSTERS);
4116
4117                         /* Redraw "title" */
4118                         p_ptr->redraw |= (PR_TITLE);
4119
4120                         break;
4121                 }
4122
4123
4124 #ifdef ALLOW_WIZARD
4125
4126                 /* Special "debug" commands */
4127                 case KTRL('A'):
4128                 {
4129                         /* Enter debug mode */
4130                         if (enter_debug_mode())
4131                         {
4132                                 do_cmd_debug();
4133                         }
4134                         break;
4135                 }
4136
4137 #endif /* ALLOW_WIZARD */
4138
4139
4140 #ifdef ALLOW_BORG
4141
4142                 /* Special "borg" commands */
4143                 case KTRL('Z'):
4144                 {
4145                         /* Enter borg mode */
4146                         if (enter_borg_mode())
4147                         {
4148                                 if (!p_ptr->wild_mode) do_cmd_borg();
4149                         }
4150
4151                         break;
4152                 }
4153
4154 #endif /* ALLOW_BORG */
4155
4156
4157
4158                 /*** Inventory Commands ***/
4159
4160                 /* Wear/wield equipment */
4161                 case 'w':
4162                 {
4163                         if (!p_ptr->wild_mode) do_cmd_wield();
4164                         break;
4165                 }
4166
4167                 /* Take off equipment */
4168                 case 't':
4169                 {
4170                         if (!p_ptr->wild_mode) do_cmd_takeoff();
4171                         break;
4172                 }
4173
4174                 /* Drop an item */
4175                 case 'd':
4176                 {
4177                         if (!p_ptr->wild_mode) do_cmd_drop();
4178                         break;
4179                 }
4180
4181                 /* Destroy an item */
4182                 case 'k':
4183                 {
4184                         do_cmd_destroy();
4185                         break;
4186                 }
4187
4188                 /* Equipment list */
4189                 case 'e':
4190                 {
4191                         do_cmd_equip();
4192                         break;
4193                 }
4194
4195                 /* Inventory list */
4196                 case 'i':
4197                 {
4198                         do_cmd_inven();
4199                         break;
4200                 }
4201
4202
4203                 /*** Various commands ***/
4204
4205                 /* Identify an object */
4206                 case 'I':
4207                 {
4208                         do_cmd_observe();
4209                         break;
4210                 }
4211
4212                 /* Hack -- toggle windows */
4213                 case KTRL('I'):
4214                 {
4215                         toggle_inven_equip();
4216                         break;
4217                 }
4218
4219
4220                 /*** Standard "Movement" Commands ***/
4221
4222                 /* Alter a grid */
4223                 case '+':
4224                 {
4225                         if (!p_ptr->wild_mode) do_cmd_alter();
4226                         break;
4227                 }
4228
4229                 /* Dig a tunnel */
4230                 case 'T':
4231                 {
4232                         if (!p_ptr->wild_mode) do_cmd_tunnel();
4233                         break;
4234                 }
4235
4236                 /* Move (usually pick up things) */
4237                 case ';':
4238                 {
4239 #ifdef ALLOW_EASY_DISARM /* TNB */
4240
4241                         do_cmd_walk(FALSE);
4242
4243 #else /* ALLOW_EASY_DISARM -- TNB */
4244
4245                         do_cmd_walk(always_pickup);
4246
4247 #endif /* ALLOW_EASY_DISARM -- TNB */
4248
4249                         break;
4250                 }
4251
4252                 /* Move (usually do not pick up) */
4253                 case '-':
4254                 {
4255 #ifdef ALLOW_EASY_DISARM /* TNB */
4256
4257                         do_cmd_walk(TRUE);
4258
4259 #else /* ALLOW_EASY_DISARM -- TNB */
4260
4261                         do_cmd_walk(!always_pickup);
4262
4263 #endif /* ALLOW_EASY_DISARM -- TNB */
4264
4265                         break;
4266                 }
4267
4268
4269                 /*** Running, Resting, Searching, Staying */
4270
4271                 /* Begin Running -- Arg is Max Distance */
4272                 case '.':
4273                 {
4274                         if (!p_ptr->wild_mode) do_cmd_run();
4275                         break;
4276                 }
4277
4278                 /* Stay still (usually pick things up) */
4279                 case ',':
4280                 {
4281                         do_cmd_stay(always_pickup);
4282                         break;
4283                 }
4284
4285                 /* Stay still (usually do not pick up) */
4286                 case 'g':
4287                 {
4288                         do_cmd_stay(!always_pickup);
4289                         break;
4290                 }
4291
4292                 /* Rest -- Arg is time */
4293                 case 'R':
4294                 {
4295                         do_cmd_rest();
4296                         break;
4297                 }
4298
4299                 /* Search for traps/doors */
4300                 case 's':
4301                 {
4302                         do_cmd_search();
4303                         break;
4304                 }
4305
4306                 /* Toggle search mode */
4307                 case 'S':
4308                 {
4309                         if (p_ptr->action == ACTION_SEARCH) set_action(ACTION_NONE);
4310                         else set_action(ACTION_SEARCH);
4311                         break;
4312                 }
4313
4314
4315                 /*** Stairs and Doors and Chests and Traps ***/
4316
4317                 /* Enter store */
4318                 case SPECIAL_KEY_STORE:
4319                 {
4320                         if (!p_ptr->wild_mode) do_cmd_store();
4321                         break;
4322                 }
4323
4324                 /* Enter building -KMW- */
4325                 case SPECIAL_KEY_BUILDING:
4326                 {
4327                         if (!p_ptr->wild_mode) do_cmd_bldg();
4328                         break;
4329                 }
4330
4331                 /* Enter quest level -KMW- */
4332                 case SPECIAL_KEY_QUEST:
4333                 {
4334                         if (!p_ptr->wild_mode) do_cmd_quest();
4335                         break;
4336                 }
4337
4338                 /* Go up staircase */
4339                 case '<':
4340                 {
4341                         if (!p_ptr->wild_mode && !dun_level && !p_ptr->inside_arena && !p_ptr->inside_quest)
4342                         {
4343                                 if (vanilla_town) break;
4344
4345                                 if (ambush_flag)
4346                                 {
4347                                         msg_print(_("襲撃から逃げるにはマップの端まで移動しなければならない。", "To flee the ambush you have to reach the edge of the map."));
4348                                         break;
4349                                 }
4350
4351                                 if (p_ptr->food < PY_FOOD_WEAK)
4352                                 {
4353                                         msg_print(_("その前に食事をとらないと。", "You must eat something here."));
4354                                         break;
4355                                 }
4356
4357                                 change_wild_mode();
4358                         }
4359                         else
4360                                 do_cmd_go_up();
4361                         break;
4362                 }
4363
4364                 /* Go down staircase */
4365                 case '>':
4366                 {
4367                         if (p_ptr->wild_mode)
4368                                 change_wild_mode();
4369                         else
4370                                 do_cmd_go_down();
4371
4372                         break;
4373                 }
4374
4375                 /* Open a door or chest */
4376                 case 'o':
4377                 {
4378                         if (!p_ptr->wild_mode) do_cmd_open();
4379                         break;
4380                 }
4381
4382                 /* Close a door */
4383                 case 'c':
4384                 {
4385                         if (!p_ptr->wild_mode) do_cmd_close();
4386                         break;
4387                 }
4388
4389                 /* Jam a door with spikes */
4390                 case 'j':
4391                 {
4392                         if (!p_ptr->wild_mode) do_cmd_spike();
4393                         break;
4394                 }
4395
4396                 /* Bash a door */
4397                 case 'B':
4398                 {
4399                         if (!p_ptr->wild_mode) do_cmd_bash();
4400                         break;
4401                 }
4402
4403                 /* Disarm a trap or chest */
4404                 case 'D':
4405                 {
4406                         if (!p_ptr->wild_mode) do_cmd_disarm();
4407                         break;
4408                 }
4409
4410
4411                 /*** Magic and Prayers ***/
4412
4413                 /* Gain new spells/prayers */
4414                 case 'G':
4415                 {
4416                         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
4417                                 msg_print(_("呪文を学習する必要はない!", "You don't have to learn spells!"));
4418                         else if (p_ptr->pclass == CLASS_SAMURAI)
4419                                 do_cmd_gain_hissatsu();
4420                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4421                                 gain_magic();
4422                         else
4423                                 do_cmd_study();
4424                         break;
4425                 }
4426
4427                 /* Browse a book */
4428                 case 'b':
4429                 {
4430                         if ( (p_ptr->pclass == CLASS_MINDCRAFTER) ||
4431                              (p_ptr->pclass == CLASS_BERSERKER) ||
4432                              (p_ptr->pclass == CLASS_NINJA) ||
4433                              (p_ptr->pclass == CLASS_MIRROR_MASTER) 
4434                              ) do_cmd_mind_browse();
4435                         else if (p_ptr->pclass == CLASS_SMITH)
4436                                 do_cmd_kaji(TRUE);
4437                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4438                                 do_cmd_magic_eater(TRUE, FALSE);
4439                         else if (p_ptr->pclass == CLASS_SNIPER)
4440                                 do_cmd_snipe_browse();
4441                         else do_cmd_browse();
4442                         break;
4443                 }
4444
4445                 /* Cast a spell */
4446                 case 'm':
4447                 {
4448                         /* -KMW- */
4449                         if (!p_ptr->wild_mode)
4450                         {
4451                                 if ((p_ptr->pclass == CLASS_WARRIOR) || (p_ptr->pclass == CLASS_ARCHER) || (p_ptr->pclass == CLASS_CAVALRY))
4452                                 {
4453                                         msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
4454                                 }
4455                                 else if (dun_level && (d_info[dungeon_type].flags1 & DF1_NO_MAGIC) && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
4456                                 {
4457                                         msg_print(_("ダンジョンが魔法を吸収した!", "The dungeon absorbs all attempted magic!"));
4458                                         msg_print(NULL);
4459                                 }
4460                                 else if (p_ptr->anti_magic && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
4461                                 {
4462                                         cptr which_power = _("魔法", "magic");
4463                                         if (p_ptr->pclass == CLASS_MINDCRAFTER)
4464                                                 which_power = _("超能力", "psionic powers");
4465                                         else if (p_ptr->pclass == CLASS_IMITATOR)
4466                                                 which_power = _("ものまね", "imitation");
4467                                         else if (p_ptr->pclass == CLASS_SAMURAI)
4468                                                 which_power = _("必殺剣", "hissatsu");
4469                                         else if (p_ptr->pclass == CLASS_MIRROR_MASTER)
4470                                                 which_power = _("鏡魔法", "mirror magic");
4471                                         else if (p_ptr->pclass == CLASS_NINJA)
4472                                                 which_power = _("忍術", "ninjutsu");
4473                                         else if (mp_ptr->spell_book == TV_LIFE_BOOK)
4474                                                 which_power = _("祈り", "prayer");
4475
4476                                         msg_format(_("反魔法バリアが%sを邪魔した!", "An anti-magic shell disrupts your %s!"), which_power);
4477                                         p_ptr->energy_use = 0;
4478                                 }
4479                                 else if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER))
4480                                 {
4481                                         msg_format(_("狂戦士化していて頭が回らない!", "You cannot think directly!"));
4482                                         p_ptr->energy_use = 0;
4483                                 }
4484                                 else
4485                                 {
4486                                         if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
4487                                             (p_ptr->pclass == CLASS_BERSERKER) ||
4488                                             (p_ptr->pclass == CLASS_NINJA) ||
4489                                             (p_ptr->pclass == CLASS_MIRROR_MASTER)
4490                                             )
4491                                                 do_cmd_mind();
4492                                         else if (p_ptr->pclass == CLASS_IMITATOR)
4493                                                 do_cmd_mane(FALSE);
4494                                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4495                                                 do_cmd_magic_eater(FALSE, FALSE);
4496                                         else if (p_ptr->pclass == CLASS_SAMURAI)
4497                                                 do_cmd_hissatsu();
4498                                         else if (p_ptr->pclass == CLASS_BLUE_MAGE)
4499                                                 do_cmd_cast_learned();
4500                                         else if (p_ptr->pclass == CLASS_SMITH)
4501                                                 do_cmd_kaji(FALSE);
4502                                         else if (p_ptr->pclass == CLASS_SNIPER)
4503                                                 do_cmd_snipe();
4504                                         else
4505                                                 do_cmd_cast();
4506                                 }
4507                         }
4508                         break;
4509                 }
4510
4511                 /* Issue a pet command */
4512                 case 'p':
4513                 {
4514                         if (!p_ptr->wild_mode) do_cmd_pet();
4515                         break;
4516                 }
4517
4518                 /*** Use various objects ***/
4519
4520                 /* Inscribe an object */
4521                 case '{':
4522                 {
4523                         do_cmd_inscribe();
4524                         break;
4525                 }
4526
4527                 /* Uninscribe an object */
4528                 case '}':
4529                 {
4530                         do_cmd_uninscribe();
4531                         break;
4532                 }
4533
4534                 /* Activate an artifact */
4535                 case 'A':
4536                 {
4537                         if (!p_ptr->wild_mode)
4538                         {
4539                         if (!p_ptr->inside_arena)
4540                                 do_cmd_activate();
4541                         else
4542                         {
4543                                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
4544                                 msg_print(NULL);
4545                         }
4546                         }
4547                         break;
4548                 }
4549
4550                 /* Eat some food */
4551                 case 'E':
4552                 {
4553                         do_cmd_eat_food();
4554                         break;
4555                 }
4556
4557                 /* Fuel your lantern/torch */
4558                 case 'F':
4559                 {
4560                         do_cmd_refill();
4561                         break;
4562                 }
4563
4564                 /* Fire an item */
4565                 case 'f':
4566                 {
4567                         if (!p_ptr->wild_mode) do_cmd_fire();
4568                         break;
4569                 }
4570
4571                 /* Throw an item */
4572                 case 'v':
4573                 {
4574                         if (!p_ptr->wild_mode)
4575                         {
4576                                 do_cmd_throw();
4577                         }
4578                         break;
4579                 }
4580
4581                 /* Aim a wand */
4582                 case 'a':
4583                 {
4584                         if (!p_ptr->wild_mode)
4585                         {
4586                         if (!p_ptr->inside_arena)
4587                                 do_cmd_aim_wand();
4588                         else
4589                         {
4590                                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
4591                                 msg_print(NULL);
4592                         }
4593                         }
4594                         break;
4595                 }
4596
4597                 /* Zap a rod */
4598                 case 'z':
4599                 {
4600                         if (!p_ptr->wild_mode)
4601                         {
4602                         if (p_ptr->inside_arena)
4603                         {
4604                                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
4605                                 msg_print(NULL);
4606                         }
4607                         else if (use_command && rogue_like_commands)
4608                         {
4609                                 do_cmd_use();
4610                         }
4611                         else
4612                         {
4613                                 do_cmd_zap_rod();
4614                         }
4615                         }
4616                         break;
4617                 }
4618
4619                 /* Quaff a potion */
4620                 case 'q':
4621                 {
4622                         if (!p_ptr->wild_mode)
4623                         {
4624                         if (!p_ptr->inside_arena)
4625                                 do_cmd_quaff_potion();
4626                         else
4627                         {
4628                                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
4629                                 msg_print(NULL);
4630                         }
4631                         }
4632                         break;
4633                 }
4634
4635                 /* Read a scroll */
4636                 case 'r':
4637                 {
4638                         if (!p_ptr->wild_mode)
4639                         {
4640                         if (!p_ptr->inside_arena)
4641                                 do_cmd_read_scroll();
4642                         else
4643                         {
4644                                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
4645                                 msg_print(NULL);
4646                         }
4647                         }
4648                         break;
4649                 }
4650
4651                 /* Use a staff */
4652                 case 'u':
4653                 {
4654                         if (!p_ptr->wild_mode)
4655                         {
4656                         if (p_ptr->inside_arena)
4657                         {
4658                                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
4659                                 msg_print(NULL);
4660                         }
4661                         else if (use_command && !rogue_like_commands)
4662                         {
4663                                 do_cmd_use();
4664                         }
4665                         else
4666                                 do_cmd_use_staff();
4667                         }
4668                         break;
4669                 }
4670
4671                 /* Use racial power */
4672                 case 'U':
4673                 {
4674                         if (!p_ptr->wild_mode) do_cmd_racial_power();
4675                         break;
4676                 }
4677
4678
4679                 /*** Looking at Things (nearby or on map) ***/
4680
4681                 /* Full dungeon map */
4682                 case 'M':
4683                 {
4684                         do_cmd_view_map();
4685                         break;
4686                 }
4687
4688                 /* Locate player on map */
4689                 case 'L':
4690                 {
4691                         do_cmd_locate();
4692                         break;
4693                 }
4694
4695                 /* Look around */
4696                 case 'l':
4697                 {
4698                         do_cmd_look();
4699                         break;
4700                 }
4701
4702                 /* Target monster or location */
4703                 case '*':
4704                 {
4705                         if (!p_ptr->wild_mode) do_cmd_target();
4706                         break;
4707                 }
4708
4709
4710
4711                 /*** Help and Such ***/
4712
4713                 /* Help */
4714                 case '?':
4715                 {
4716                         do_cmd_help();
4717                         break;
4718                 }
4719
4720                 /* Identify symbol */
4721                 case '/':
4722                 {
4723                         do_cmd_query_symbol();
4724                         break;
4725                 }
4726
4727                 /* Character description */
4728                 case 'C':
4729                 {
4730                         do_cmd_change_name();
4731                         break;
4732                 }
4733
4734
4735                 /*** System Commands ***/
4736
4737                 /* Hack -- User interface */
4738                 case '!':
4739                 {
4740                         (void)Term_user(0);
4741                         break;
4742                 }
4743
4744                 /* Single line from a pref file */
4745                 case '"':
4746                 {
4747                         do_cmd_pref();
4748                         break;
4749                 }
4750
4751                 case '$':
4752                 {
4753                         do_cmd_reload_autopick();
4754                         break;
4755                 }
4756
4757                 case '_':
4758                 {
4759                         do_cmd_edit_autopick();
4760                         break;
4761                 }
4762
4763                 /* Interact with macros */
4764                 case '@':
4765                 {
4766                         do_cmd_macros();
4767                         break;
4768                 }
4769
4770                 /* Interact with visuals */
4771                 case '%':
4772                 {
4773                         do_cmd_visuals();
4774                         do_cmd_redraw();
4775                         break;
4776                 }
4777
4778                 /* Interact with colors */
4779                 case '&':
4780                 {
4781                         do_cmd_colors();
4782                         do_cmd_redraw();
4783                         break;
4784                 }
4785
4786                 /* Interact with options */
4787                 case '=':
4788                 {
4789                         do_cmd_options();
4790                         (void)combine_and_reorder_home(STORE_HOME);
4791                         do_cmd_redraw();
4792                         break;
4793                 }
4794
4795                 /*** Misc Commands ***/
4796
4797                 /* Take notes */
4798                 case ':':
4799                 {
4800                         do_cmd_note();
4801                         break;
4802                 }
4803
4804                 /* Version info */
4805                 case 'V':
4806                 {
4807                         do_cmd_version();
4808                         break;
4809                 }
4810
4811                 /* Repeat level feeling */
4812                 case KTRL('F'):
4813                 {
4814                         if (!p_ptr->wild_mode) do_cmd_feeling();
4815                         break;
4816                 }
4817
4818                 /* Show previous message */
4819                 case KTRL('O'):
4820                 {
4821                         do_cmd_message_one();
4822                         break;
4823                 }
4824
4825                 /* Show previous messages */
4826                 case KTRL('P'):
4827                 {
4828                         do_cmd_messages(old_now_message);
4829                         break;
4830                 }
4831
4832                 /* Show quest status -KMW- */
4833                 case KTRL('Q'):
4834                 {
4835                         do_cmd_checkquest();
4836                         break;
4837                 }
4838
4839                 /* Redraw the screen */
4840                 case KTRL('R'):
4841                 {
4842                         now_message = old_now_message;
4843                         do_cmd_redraw();
4844                         break;
4845                 }
4846
4847 #ifndef VERIFY_SAVEFILE
4848
4849                 /* Hack -- Save and don't quit */
4850                 case KTRL('S'):
4851                 {
4852                         do_cmd_save_game(FALSE);
4853                         break;
4854                 }
4855
4856 #endif /* VERIFY_SAVEFILE */
4857
4858                 case KTRL('T'):
4859                 {
4860                         do_cmd_time();
4861                         break;
4862                 }
4863
4864                 /* Save and quit */
4865                 case KTRL('X'):
4866                 case SPECIAL_KEY_QUIT:
4867                 {
4868                         do_cmd_save_and_exit();
4869                         break;
4870                 }
4871
4872                 /* Quit (commit suicide) */
4873                 case 'Q':
4874                 {
4875                         do_cmd_suicide();
4876                         break;
4877                 }
4878
4879                 case '|':
4880                 {
4881                         do_cmd_nikki();
4882                         break;
4883                 }
4884
4885                 /* Check artifacts, uniques, objects */
4886                 case '~':
4887                 {
4888                         do_cmd_knowledge();
4889                         break;
4890                 }
4891
4892                 /* Load "screen dump" */
4893                 case '(':
4894                 {
4895                         do_cmd_load_screen();
4896                         break;
4897                 }
4898
4899                 /* Save "screen dump" */
4900                 case ')':
4901                 {
4902                         do_cmd_save_screen();
4903                         break;
4904                 }
4905
4906                 /* Record/stop "Movie" */
4907                 case ']':
4908                 {
4909                         prepare_movie_hooks();
4910                         break;
4911                 }
4912
4913                 /* Make random artifact list */
4914                 case KTRL('V'):
4915                 {
4916                         spoil_random_artifact("randifact.txt");
4917                         break;
4918                 }
4919
4920 #ifdef TRAVEL
4921                 case '`':
4922                 {
4923                         if (!p_ptr->wild_mode) do_cmd_travel();
4924                         if (p_ptr->special_defense & KATA_MUSOU)
4925                         {
4926                                 set_action(ACTION_NONE);
4927                         }
4928                         break;
4929                 }
4930 #endif
4931
4932                 /* Hack -- Unknown command */
4933                 default:
4934                 {
4935                         if (flush_failure) flush();
4936                         if (one_in_(2))
4937                         {
4938                                 char error_m[1024];
4939                                 sound(SOUND_ILLEGAL);
4940                                 if (!get_rnd_line(_("error_j.txt", "error.txt"), 0, error_m))
4941                                         msg_print(error_m);
4942                         }
4943                         else
4944                         {
4945                                 prt(_(" '?' でヘルプが表示されます。", "Type '?' for help."), 0, 0);
4946                         }
4947
4948                         break;
4949                 }
4950         }
4951         if (!p_ptr->energy_use && !now_message)
4952                 now_message = old_now_message;
4953 }
4954
4955 /*!
4956  * @brief モンスター種族が釣れる種族かどうかを判定する。
4957  * @param r_idx 判定したいモンスター種族のID
4958  * @return 釣れる対象ならばTRUEを返す
4959  */
4960 static bool monster_tsuri(MONRACE_IDX r_idx)
4961 {
4962         monster_race *r_ptr = &r_info[r_idx];
4963
4964         if ((r_ptr->flags7 & RF7_AQUATIC) && !(r_ptr->flags1 & RF1_UNIQUE) && my_strchr("Jjlw", r_ptr->d_char))
4965                 return TRUE;
4966         else
4967                 return FALSE;
4968 }
4969
4970
4971 /*!
4972  * @brief アイテムの所持種類数が超えた場合にアイテムを床に落とす処理 / Hack -- Pack Overflow
4973  * @return なし
4974  */
4975 static void pack_overflow(void)
4976 {
4977         if (inventory[INVEN_PACK].k_idx)
4978         {
4979                 char o_name[MAX_NLEN];
4980                 object_type *o_ptr;
4981
4982                 /* Is auto-destroy done? */
4983                 notice_stuff();
4984                 if (!inventory[INVEN_PACK].k_idx) return;
4985
4986                 /* Access the slot to be dropped */
4987                 o_ptr = &inventory[INVEN_PACK];
4988
4989                 /* Disturbing */
4990                 disturb(0, 1);
4991
4992                 /* Warning */
4993                 msg_print(_("ザックからアイテムがあふれた!", "Your pack overflows!"));
4994
4995                 /* Describe */
4996                 object_desc(o_name, o_ptr, 0);
4997
4998                 /* Message */
4999                 msg_format(_("%s(%c)を落とした。", "You drop %s (%c)."), o_name, index_to_label(INVEN_PACK));
5000
5001                 /* Drop it (carefully) near the player */
5002                 (void)drop_near(o_ptr, 0, p_ptr->y, p_ptr->x);
5003
5004                 /* Modify, Describe, Optimize */
5005                 inven_item_increase(INVEN_PACK, -255);
5006                 inven_item_describe(INVEN_PACK);
5007                 inven_item_optimize(INVEN_PACK);
5008
5009                 /* Handle "p_ptr->notice" */
5010                 notice_stuff();
5011
5012                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5013                 handle_stuff();
5014         }
5015 }
5016
5017 /*!
5018  * @brief プレイヤーの行動エネルギーが充填される(=プレイヤーのターンが回る)毎に行われる処理  / process the effects per 100 energy at player speed.
5019  * @return なし
5020  */
5021 static void process_upkeep_with_speed(void)
5022 {
5023         /* Give the player some energy */
5024         if (!load && p_ptr->enchant_energy_need > 0 && !p_ptr->leaving)
5025         {
5026                 p_ptr->enchant_energy_need -= SPEED_TO_ENERGY(p_ptr->pspeed);
5027         }
5028         
5029         /* No turn yet */
5030         if (p_ptr->enchant_energy_need > 0) return;
5031         
5032         while (p_ptr->enchant_energy_need <= 0)
5033         {
5034                 /* Handle the player song */
5035                 if (!load) check_music();
5036
5037                 /* Hex - Handle the hex spells */
5038                 if (!load) check_hex();
5039                 if (!load) revenge_spell();
5040                 
5041                 /* There is some randomness of needed energy */
5042                 p_ptr->enchant_energy_need += ENERGY_NEED();
5043         }
5044 }
5045
5046 /*!
5047  * @brief プレイヤーの行動処理 / Process the player
5048  * @return なし
5049  * @note
5050  * Notice the annoying code to handle "pack overflow", which\n
5051  * must come first just in case somebody manages to corrupt\n
5052  * the savefiles by clever use of menu commands or something.\n
5053  */
5054 static void process_player(void)
5055 {
5056         IDX i;
5057
5058         /*** Apply energy ***/
5059
5060         if (hack_mutation)
5061         {
5062                 msg_print(_("何か変わった気がする!", "You feel different!"));
5063
5064                 (void)gain_random_mutation(0);
5065                 hack_mutation = FALSE;
5066         }
5067
5068         if (invoking_midnight_curse)
5069         {
5070                 int count = 0;
5071                 activate_ty_curse(FALSE, &count);
5072                 invoking_midnight_curse = FALSE;
5073         }
5074
5075         if (p_ptr->inside_battle)
5076         {
5077                 for(i = 1; i < m_max; i++)
5078                 {
5079                         monster_type *m_ptr = &m_list[i];
5080
5081                         if (!m_ptr->r_idx) continue;
5082
5083                         /* Hack -- Detect monster */
5084                         m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
5085
5086                         /* Update the monster */
5087                         update_mon(i, FALSE);
5088                 }
5089                 prt_time();
5090         }
5091
5092         /* Give the player some energy */
5093         else if (!(load && p_ptr->energy_need <= 0))
5094         {
5095                 p_ptr->energy_need -= SPEED_TO_ENERGY(p_ptr->pspeed);
5096         }
5097
5098         /* No turn yet */
5099         if (p_ptr->energy_need > 0) return;
5100         if (!command_rep) prt_time();
5101
5102         /*** Check for interupts ***/
5103
5104         /* Complete resting */
5105         if (resting < 0)
5106         {
5107                 /* Basic resting */
5108                 if (resting == COMMAND_ARG_REST_FULL_HEALING)
5109                 {
5110                         /* Stop resting */
5111                         if ((p_ptr->chp == p_ptr->mhp) &&
5112                             (p_ptr->csp >= p_ptr->msp))
5113                         {
5114                                 set_action(ACTION_NONE);
5115                         }
5116                 }
5117
5118                 /* Complete resting */
5119                 else if (resting == COMMAND_ARG_REST_UNTIL_DONE)
5120                 {
5121                         /* Stop resting */
5122                         if ((p_ptr->chp == p_ptr->mhp) &&
5123                             (p_ptr->csp >= p_ptr->msp) &&
5124                             !p_ptr->blind && !p_ptr->confused &&
5125                             !p_ptr->poisoned && !p_ptr->afraid &&
5126                             !p_ptr->stun && !p_ptr->cut &&
5127                             !p_ptr->slow && !p_ptr->paralyzed &&
5128                             !p_ptr->image && !p_ptr->word_recall &&
5129                             !p_ptr->alter_reality)
5130                         {
5131                                 set_action(ACTION_NONE);
5132                         }
5133                 }
5134         }
5135
5136         if (p_ptr->action == ACTION_FISH)
5137         {
5138                 /* Delay */
5139                 Term_xtra(TERM_XTRA_DELAY, 10);
5140                 if (one_in_(1000))
5141                 {
5142                         MONRACE_IDX r_idx;
5143                         bool success = FALSE;
5144                         get_mon_num_prep(monster_tsuri,NULL);
5145                         r_idx = get_mon_num(dun_level ? dun_level : wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level);
5146                         msg_print(NULL);
5147                         if (r_idx && one_in_(2))
5148                         {
5149                                 int y, x;
5150                                 y = p_ptr->y+ddy[tsuri_dir];
5151                                 x = p_ptr->x+ddx[tsuri_dir];
5152                                 if (place_monster_aux(0, y, x, r_idx, PM_NO_KAGE))
5153                                 {
5154                                         char m_name[80];
5155                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
5156                                         msg_format(_("%sが釣れた!", "You have a good catch!"), m_name);
5157                                         success = TRUE;
5158                                 }
5159                         }
5160                         if (!success)
5161                         {
5162                                 msg_print(_("餌だけ食われてしまった!くっそ~!", "Damn!  The fish stole your bait!"));
5163                         }
5164                         disturb(0, 1);
5165                 }
5166         }
5167
5168         /* Handle "abort" */
5169         if (check_abort)
5170         {
5171                 /* Check for "player abort" (semi-efficiently for resting) */
5172                 if (running || travel.run || command_rep || (p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH))
5173                 {
5174                         /* Do not wait */
5175                         inkey_scan = TRUE;
5176
5177                         /* Check for a key */
5178                         if (inkey())
5179                         {
5180                                 /* Flush input */
5181                                 flush();
5182
5183                                 /* Disturb */
5184                                 disturb(0, 1);
5185
5186                                 /* Hack -- Show a Message */
5187                                 msg_print(_("中断しました。", "Canceled."));
5188                         }
5189                 }
5190         }
5191
5192         if (p_ptr->riding && !p_ptr->confused && !p_ptr->blind)
5193         {
5194                 monster_type *m_ptr = &m_list[p_ptr->riding];
5195                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
5196
5197                 if (MON_CSLEEP(m_ptr))
5198                 {
5199                         char m_name[80];
5200
5201                         /* Recover fully */
5202                         (void)set_monster_csleep(p_ptr->riding, 0);
5203
5204                         /* Acquire the monster name */
5205                         monster_desc(m_name, m_ptr, 0);
5206                         msg_format(_("%^sを起こした。", "You have waked %s up."), m_name);
5207                 }
5208
5209                 if (MON_STUNNED(m_ptr))
5210                 {
5211                         /* Hack -- Recover from stun */
5212                         if (set_monster_stunned(p_ptr->riding,
5213                                 (randint0(r_ptr->level) < p_ptr->skill_exp[GINOU_RIDING]) ? 0 : (MON_STUNNED(m_ptr) - 1)))
5214                         {
5215                                 char m_name[80];
5216
5217                                 /* Acquire the monster name */
5218                                 monster_desc(m_name, m_ptr, 0);
5219
5220                                 /* Dump a message */
5221                                 msg_format(_("%^sを朦朧状態から立ち直らせた。", "%^s is no longer stunned."), m_name);
5222                         }
5223                 }
5224
5225                 if (MON_CONFUSED(m_ptr))
5226                 {
5227                         /* Hack -- Recover from confusion */
5228                         if (set_monster_confused(p_ptr->riding,
5229                                 (randint0(r_ptr->level) < p_ptr->skill_exp[GINOU_RIDING]) ? 0 : (MON_CONFUSED(m_ptr) - 1)))
5230                         {
5231                                 char m_name[80];
5232
5233                                 /* Acquire the monster name */
5234                                 monster_desc(m_name, m_ptr, 0);
5235
5236                                 /* Dump a message */
5237                                 msg_format(_("%^sを混乱状態から立ち直らせた。", "%^s is no longer confused."), m_name);
5238                         }
5239                 }
5240
5241                 if (MON_MONFEAR(m_ptr))
5242                 {
5243                         /* Hack -- Recover from fear */
5244                         if (set_monster_monfear(p_ptr->riding,
5245                                 (randint0(r_ptr->level) < p_ptr->skill_exp[GINOU_RIDING]) ? 0 : (MON_MONFEAR(m_ptr) - 1)))
5246                         {
5247                                 char m_name[80];
5248
5249                                 /* Acquire the monster name */
5250                                 monster_desc(m_name, m_ptr, 0);
5251
5252                                 /* Dump a message */
5253                                 msg_format(_("%^sを恐怖から立ち直らせた。", "%^s is no longer fear."), m_name);
5254                         }
5255                 }
5256
5257                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5258                 handle_stuff();
5259         }
5260         
5261         load = FALSE;
5262
5263         /* Fast */
5264         if (p_ptr->lightspeed)
5265         {
5266                 (void)set_lightspeed(p_ptr->lightspeed - 1, TRUE);
5267         }
5268         if ((p_ptr->pclass == CLASS_FORCETRAINER) && P_PTR_KI)
5269         {
5270                 if (P_PTR_KI < 40)
5271                 {
5272                         P_PTR_KI = 0;
5273                 }
5274                 else P_PTR_KI -= 40;
5275                 p_ptr->update |= (PU_BONUS);
5276         }
5277         if (p_ptr->action == ACTION_LEARN)
5278         {
5279                 s32b cost = 0L;
5280                 u32b cost_frac = (p_ptr->msp + 30L) * 256L;
5281
5282                 /* Convert the unit (1/2^16) to (1/2^32) */
5283                 s64b_LSHIFT(cost, cost_frac, 16);
5284
5285  
5286                 if (s64b_cmp(p_ptr->csp, p_ptr->csp_frac, cost, cost_frac) < 0)
5287                 {
5288                         /* Mana run out */
5289                         p_ptr->csp = 0;
5290                         p_ptr->csp_frac = 0;
5291                         set_action(ACTION_NONE);
5292                 }
5293                 else
5294                 {
5295                         /* Reduce mana */
5296                         s64b_sub(&(p_ptr->csp), &(p_ptr->csp_frac), cost, cost_frac);
5297                 }
5298                 p_ptr->redraw |= PR_MANA;
5299         }
5300
5301         if (p_ptr->special_defense & KATA_MASK)
5302         {
5303                 if (p_ptr->special_defense & KATA_MUSOU)
5304                 {
5305                         if (p_ptr->csp < 3)
5306                         {
5307                                 set_action(ACTION_NONE);
5308                         }
5309                         else
5310                         {
5311                                 p_ptr->csp -= 2;
5312                                 p_ptr->redraw |= (PR_MANA);
5313                         }
5314                 }
5315         }
5316
5317         /*** Handle actual user input ***/
5318
5319         /* Repeat until out of energy */
5320         while (p_ptr->energy_need <= 0)
5321         {
5322                 p_ptr->window |= PW_PLAYER;
5323                 p_ptr->sutemi = FALSE;
5324                 p_ptr->counter = FALSE;
5325                 now_damaged = FALSE;
5326
5327                 /* Handle "p_ptr->notice" */
5328                 notice_stuff();
5329
5330                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5331                 handle_stuff();
5332
5333                 /* Place the cursor on the player */
5334                 move_cursor_relative(p_ptr->y, p_ptr->x);
5335
5336                 /* Refresh (optional) */
5337                 if (fresh_before) Term_fresh();
5338
5339
5340                 /* Hack -- Pack Overflow */
5341                 pack_overflow();
5342
5343
5344                 /* Hack -- cancel "lurking browse mode" */
5345                 if (!command_new) command_see = FALSE;
5346
5347
5348                 /* Assume free turn */
5349                 p_ptr->energy_use = 0;
5350
5351
5352                 if (p_ptr->inside_battle)
5353                 {
5354                         /* Place the cursor on the player */
5355                         move_cursor_relative(p_ptr->y, p_ptr->x);
5356
5357                         command_cmd = SPECIAL_KEY_BUILDING;
5358
5359                         /* Process the command */
5360                         process_command();
5361                 }
5362
5363                 /* Paralyzed or Knocked Out */
5364                 else if (p_ptr->paralyzed || (p_ptr->stun >= 100))
5365                 {
5366                         /* Take a turn */
5367                         p_ptr->energy_use = 100;
5368                 }
5369
5370                 /* Resting */
5371                 else if (p_ptr->action == ACTION_REST)
5372                 {
5373                         /* Timed rest */
5374                         if (resting > 0)
5375                         {
5376                                 /* Reduce rest count */
5377                                 resting--;
5378
5379                                 if (!resting) set_action(ACTION_NONE);
5380
5381                                 /* Redraw the state */
5382                                 p_ptr->redraw |= (PR_STATE);
5383                         }
5384
5385                         /* Take a turn */
5386                         p_ptr->energy_use = 100;
5387                 }
5388
5389                 /* Fishing */
5390                 else if (p_ptr->action == ACTION_FISH)
5391                 {
5392                         /* Take a turn */
5393                         p_ptr->energy_use = 100;
5394                 }
5395
5396                 /* Running */
5397                 else if (running)
5398                 {
5399                         /* Take a step */
5400                         run_step(0);
5401                 }
5402
5403 #ifdef TRAVEL
5404                 /* Traveling */
5405                 else if (travel.run)
5406                 {
5407                         /* Take a step */
5408                         travel_step();
5409                 }
5410 #endif
5411
5412                 /* Repeated command */
5413                 else if (command_rep)
5414                 {
5415                         /* Count this execution */
5416                         command_rep--;
5417
5418                         /* Redraw the state */
5419                         p_ptr->redraw |= (PR_STATE);
5420
5421                         /* Redraw stuff */
5422                         redraw_stuff();
5423
5424                         /* Hack -- Assume messages were seen */
5425                         msg_flag = FALSE;
5426
5427                         /* Clear the top line */
5428                         prt("", 0, 0);
5429
5430                         /* Process the command */
5431                         process_command();
5432                 }
5433
5434                 /* Normal command */
5435                 else
5436                 {
5437                         /* Place the cursor on the player */
5438                         move_cursor_relative(p_ptr->y, p_ptr->x);
5439
5440                         can_save = TRUE;
5441                         /* Get a command (normal) */
5442                         request_command(FALSE);
5443                         can_save = FALSE;
5444
5445                         /* Process the command */
5446                         process_command();
5447                 }
5448
5449
5450                 /* Hack -- Pack Overflow */
5451                 pack_overflow();
5452
5453
5454                 /*** Clean up ***/
5455
5456                 /* Significant */
5457                 if (p_ptr->energy_use)
5458                 {
5459                         /* Use some energy */
5460                         if (world_player || p_ptr->energy_use > 400)
5461                         {
5462                                 /* The Randomness is irrelevant */
5463                                 p_ptr->energy_need += p_ptr->energy_use * TURNS_PER_TICK / 10;
5464                         }
5465                         else
5466                         {
5467                                 /* There is some randomness of needed energy */
5468                                 p_ptr->energy_need += (s16b)((s32b)p_ptr->energy_use * ENERGY_NEED() / 100L);
5469                         }
5470
5471                         /* Hack -- constant hallucination */
5472                         if (p_ptr->image) p_ptr->redraw |= (PR_MAP);
5473
5474
5475                         /* Shimmer monsters if needed */
5476                         if (shimmer_monsters)
5477                         {
5478                                 /* Clear the flag */
5479                                 shimmer_monsters = FALSE;
5480
5481                                 /* Shimmer multi-hued monsters */
5482                                 for (i = 1; i < m_max; i++)
5483                                 {
5484                                         monster_type *m_ptr;
5485                                         monster_race *r_ptr;
5486
5487                                         /* Access monster */
5488                                         m_ptr = &m_list[i];
5489
5490                                         /* Skip dead monsters */
5491                                         if (!m_ptr->r_idx) continue;
5492
5493                                         /* Skip unseen monsters */
5494                                         if (!m_ptr->ml) continue;
5495
5496                                         /* Access the monster race */
5497                                         r_ptr = &r_info[m_ptr->ap_r_idx];
5498
5499                                         /* Skip non-multi-hued monsters */
5500                                         if (!(r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER)))
5501                                                 continue;
5502
5503                                         /* Reset the flag */
5504                                         shimmer_monsters = TRUE;
5505
5506                                         /* Redraw regardless */
5507                                         lite_spot(m_ptr->fy, m_ptr->fx);
5508                                 }
5509                         }
5510
5511
5512                         /* Handle monster detection */
5513                         if (repair_monsters)
5514                         {
5515                                 /* Reset the flag */
5516                                 repair_monsters = FALSE;
5517
5518                                 /* Rotate detection flags */
5519                                 for (i = 1; i < m_max; i++)
5520                                 {
5521                                         monster_type *m_ptr;
5522
5523                                         /* Access monster */
5524                                         m_ptr = &m_list[i];
5525
5526                                         /* Skip dead monsters */
5527                                         if (!m_ptr->r_idx) continue;
5528
5529                                         /* Nice monsters get mean */
5530                                         if (m_ptr->mflag & MFLAG_NICE)
5531                                         {
5532                                                 /* Nice monsters get mean */
5533                                                 m_ptr->mflag &= ~(MFLAG_NICE);
5534                                         }
5535
5536                                         /* Handle memorized monsters */
5537                                         if (m_ptr->mflag2 & MFLAG2_MARK)
5538                                         {
5539                                                 /* Maintain detection */
5540                                                 if (m_ptr->mflag2 & MFLAG2_SHOW)
5541                                                 {
5542                                                         /* Forget flag */
5543                                                         m_ptr->mflag2 &= ~(MFLAG2_SHOW);
5544
5545                                                         /* Still need repairs */
5546                                                         repair_monsters = TRUE;
5547                                                 }
5548
5549                                                 /* Remove detection */
5550                                                 else
5551                                                 {
5552                                                         /* Forget flag */
5553                                                         m_ptr->mflag2 &= ~(MFLAG2_MARK);
5554
5555                                                         /* Assume invisible */
5556                                                         m_ptr->ml = FALSE;
5557
5558                                                         /* Update the monster */
5559                                                         update_mon(i, FALSE);
5560
5561                                                         if (p_ptr->health_who == i) p_ptr->redraw |= (PR_HEALTH);
5562                                                         if (p_ptr->riding == i) p_ptr->redraw |= (PR_UHEALTH);
5563
5564                                                         /* Redraw regardless */
5565                                                         lite_spot(m_ptr->fy, m_ptr->fx);
5566                                                 }
5567                                         }
5568                                 }
5569                         }
5570                         if (p_ptr->pclass == CLASS_IMITATOR)
5571                         {
5572                                 if (p_ptr->mane_num > (p_ptr->lev > 44 ? 3 : p_ptr->lev > 29 ? 2 : 1))
5573                                 {
5574                                         p_ptr->mane_num--;
5575                                         for (i = 0; i < p_ptr->mane_num; i++)
5576                                         {
5577                                                 p_ptr->mane_spell[i] = p_ptr->mane_spell[i+1];
5578                                                 p_ptr->mane_dam[i] = p_ptr->mane_dam[i+1];
5579                                         }
5580                                 }
5581                                 new_mane = FALSE;
5582                                 p_ptr->redraw |= (PR_IMITATION);
5583                         }
5584                         if (p_ptr->action == ACTION_LEARN)
5585                         {
5586                                 new_mane = FALSE;
5587                                 p_ptr->redraw |= (PR_STATE);
5588                         }
5589
5590                         if (world_player && (p_ptr->energy_need > - 1000))
5591                         {
5592                                 /* Redraw map */
5593                                 p_ptr->redraw |= (PR_MAP);
5594
5595                                 /* Update monsters */
5596                                 p_ptr->update |= (PU_MONSTERS);
5597
5598                                 /* Window stuff */
5599                                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
5600
5601                                 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
5602                                 msg_print(NULL);
5603                                 world_player = FALSE;
5604                                 p_ptr->energy_need = ENERGY_NEED();
5605
5606                                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5607                                 handle_stuff();
5608                         }
5609                 }
5610
5611                 /* Hack -- notice death */
5612                 if (!p_ptr->playing || p_ptr->is_dead)
5613                 {
5614                         world_player = FALSE;
5615                         break;
5616                 }
5617
5618                 /* Sniper */
5619                 if (p_ptr->energy_use && reset_concent) reset_concentration(TRUE);
5620
5621                 /* Handle "leaving" */
5622                 if (p_ptr->leaving) break;
5623         }
5624
5625         /* Update scent trail */
5626         update_smell();
5627 }
5628
5629 /*!
5630  * @brief 現在プレイヤーがいるダンジョンの全体処理 / Interact with the current dungeon level.
5631  * @return なし
5632  * @details
5633  * <p>
5634  * この関数から現在の階層を出る、プレイヤーがキャラが死ぬ、
5635  * ゲームを終了するかのいずれかまでループする。
5636  * </p>
5637  * <p>
5638  * This function will not exit until the level is completed,\n
5639  * the user dies, or the game is terminated.\n
5640  * </p>
5641  */
5642 static void dungeon(bool load_game)
5643 {
5644         int quest_num = 0;
5645
5646         /* Set the base level */
5647         base_level = dun_level;
5648
5649         /* Reset various flags */
5650         is_loading_now = FALSE;
5651
5652         /* Not leaving */
5653         p_ptr->leaving = FALSE;
5654
5655         /* Reset the "command" vars */
5656         command_cmd = 0;
5657
5658 #if 0 /* Don't reset here --- It's used for Arena */
5659         command_new = 0;
5660 #endif
5661
5662         command_rep = 0;
5663         command_arg = 0;
5664         command_dir = 0;
5665
5666
5667         /* Cancel the target */
5668         target_who = 0;
5669         pet_t_m_idx = 0;
5670         riding_t_m_idx = 0;
5671         ambush_flag = FALSE;
5672
5673         /* Cancel the health bar */
5674         health_track(0);
5675
5676         /* Check visual effects */
5677         shimmer_monsters = TRUE;
5678         shimmer_objects = TRUE;
5679         repair_monsters = TRUE;
5680         repair_objects = TRUE;
5681
5682
5683         /* Disturb */
5684         disturb(1, 1);
5685
5686         /* Get index of current quest (if any) */
5687         quest_num = quest_number(dun_level);
5688
5689         /* Inside a quest? */
5690         if (quest_num)
5691         {
5692                 /* Mark the quest monster */
5693                 r_info[quest[quest_num].r_idx].flags1 |= RF1_QUESTOR;
5694         }
5695
5696         /* Track maximum player level */
5697         if (p_ptr->max_plv < p_ptr->lev)
5698         {
5699                 p_ptr->max_plv = p_ptr->lev;
5700         }
5701
5702
5703         /* Track maximum dungeon level (if not in quest -KMW-) */
5704         if ((max_dlv[dungeon_type] < dun_level) && !p_ptr->inside_quest)
5705         {
5706                 max_dlv[dungeon_type] = dun_level;
5707                 if (record_maxdepth) do_cmd_write_nikki(NIKKI_MAXDEAPTH, dun_level, NULL);
5708         }
5709
5710         (void)calculate_upkeep();
5711
5712         /* Validate the panel */
5713         panel_bounds_center();
5714
5715         /* Verify the panel */
5716         verify_panel();
5717
5718         /* Flush messages */
5719         msg_print(NULL);
5720
5721
5722         /* Enter "xtra" mode */
5723         character_xtra = TRUE;
5724
5725         /* Window stuff */
5726         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_MONSTER | PW_OVERHEAD | PW_DUNGEON);
5727
5728         /* Redraw dungeon */
5729         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_EQUIPPY);
5730
5731         /* Redraw map */
5732         p_ptr->redraw |= (PR_MAP);
5733
5734         /* Update stuff */
5735         p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
5736
5737         /* Update lite/view */
5738         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_TORCH);
5739
5740         /* Update monsters */
5741         p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
5742
5743         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5744         handle_stuff();
5745
5746         /* Leave "xtra" mode */
5747         character_xtra = FALSE;
5748
5749         /* Update stuff */
5750         p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
5751
5752         /* Combine / Reorder the pack */
5753         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
5754
5755         /* Handle "p_ptr->notice" */
5756         notice_stuff();
5757
5758         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5759         handle_stuff();
5760
5761         /* Refresh */
5762         Term_fresh();
5763
5764         if (quest_num && (is_fixed_quest_idx(quest_num) &&
5765             !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) ||
5766             !(quest[quest_num].flags & QUEST_FLAG_PRESET)))) do_cmd_feeling();
5767
5768         if (p_ptr->inside_battle)
5769         {
5770                 if (load_game)
5771                 {
5772                         p_ptr->energy_need = 0;
5773                         battle_monsters();
5774                 }
5775                 else
5776                 {
5777                         msg_print(_("試合開始!", "Ready..Fight!"));
5778                         msg_print(NULL);
5779                 }
5780         }
5781
5782         if ((p_ptr->pclass == CLASS_BARD) && (SINGING_SONG_EFFECT(p_ptr) > MUSIC_DETECT))
5783                 SINGING_SONG_EFFECT(p_ptr) = MUSIC_DETECT;
5784
5785         /* Hack -- notice death or departure */
5786         if (!p_ptr->playing || p_ptr->is_dead) return;
5787
5788         /* Print quest message if appropriate */
5789         if (!p_ptr->inside_quest && (dungeon_type == DUNGEON_ANGBAND))
5790         {
5791                 quest_discovery(random_quest_number(dun_level));
5792                 p_ptr->inside_quest = random_quest_number(dun_level);
5793         }
5794         if ((dun_level == d_info[dungeon_type].maxdepth) && d_info[dungeon_type].final_guardian)
5795         {
5796                 if (r_info[d_info[dungeon_type].final_guardian].max_num)
5797 #ifdef JP
5798                         msg_format("この階には%sの主である%sが棲んでいる。",
5799                                    d_name+d_info[dungeon_type].name, 
5800                                    r_name+r_info[d_info[dungeon_type].final_guardian].name);
5801 #else
5802                         msg_format("%^s lives in this level as the keeper of %s.",
5803                                            r_name+r_info[d_info[dungeon_type].final_guardian].name, 
5804                                            d_name+d_info[dungeon_type].name);
5805 #endif
5806         }
5807
5808         if (!load_game && (p_ptr->special_defense & NINJA_S_STEALTH)) set_superstealth(FALSE);
5809
5810         /*** Process this dungeon level ***/
5811
5812         /* Reset the monster generation level */
5813         monster_level = base_level;
5814
5815         /* Reset the object generation level */
5816         object_level = base_level;
5817
5818         is_loading_now = TRUE;
5819
5820         if (p_ptr->energy_need > 0 && !p_ptr->inside_battle &&
5821             (dun_level || p_ptr->leaving_dungeon || p_ptr->inside_arena))
5822                 p_ptr->energy_need = 0;
5823
5824         /* Not leaving dungeon */
5825         p_ptr->leaving_dungeon = FALSE;
5826
5827         /* Initialize monster process */
5828         mproc_init();
5829
5830         /* Main loop */
5831         while (TRUE)
5832         {
5833                 /* Hack -- Compact the monster list occasionally */
5834                 if ((m_cnt + 32 > max_m_idx) && !p_ptr->inside_battle) compact_monsters(64);
5835
5836                 /* Hack -- Compress the monster list occasionally */
5837                 if ((m_cnt + 32 < m_max) && !p_ptr->inside_battle) compact_monsters(0);
5838
5839
5840                 /* Hack -- Compact the object list occasionally */
5841                 if (o_cnt + 32 > max_o_idx) compact_objects(64);
5842
5843                 /* Hack -- Compress the object list occasionally */
5844                 if (o_cnt + 32 < o_max) compact_objects(0);
5845
5846                 
5847                 /* Process the player */
5848                 process_player();
5849                 
5850                 process_upkeep_with_speed();
5851
5852                 /* Handle "p_ptr->notice" */
5853                 notice_stuff();
5854
5855                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5856                 handle_stuff();
5857
5858                 /* Hack -- Hilite the player */
5859                 move_cursor_relative(p_ptr->y, p_ptr->x);
5860
5861                 /* Optional fresh */
5862                 if (fresh_after) Term_fresh();
5863
5864                 /* Hack -- Notice death or departure */
5865                 if (!p_ptr->playing || p_ptr->is_dead) break;
5866
5867                 /* Process all of the monsters */
5868                 process_monsters();
5869
5870                 /* Handle "p_ptr->notice" */
5871                 notice_stuff();
5872
5873                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5874                 handle_stuff();
5875
5876                 /* Hack -- Hilite the player */
5877                 move_cursor_relative(p_ptr->y, p_ptr->x);
5878
5879                 /* Optional fresh */
5880                 if (fresh_after) Term_fresh();
5881
5882                 /* Hack -- Notice death or departure */
5883                 if (!p_ptr->playing || p_ptr->is_dead) break;
5884
5885
5886                 /* Process the world */
5887                 process_world();
5888
5889                 /* Handle "p_ptr->notice" */
5890                 notice_stuff();
5891
5892                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5893                 handle_stuff();
5894
5895                 /* Hack -- Hilite the player */
5896                 move_cursor_relative(p_ptr->y, p_ptr->x);
5897
5898                 /* Optional fresh */
5899                 if (fresh_after) Term_fresh();
5900
5901                 /* Hack -- Notice death or departure */
5902                 if (!p_ptr->playing || p_ptr->is_dead) break;
5903
5904                 /* Count game turns */
5905                 turn++;
5906
5907                 if (dungeon_turn < dungeon_turn_limit)
5908                 {
5909                         if (!p_ptr->wild_mode || wild_regen) dungeon_turn++;
5910                         else if (p_ptr->wild_mode && !(turn % ((MAX_HGT + MAX_WID) / 2))) dungeon_turn++;
5911                 }
5912
5913                 prevent_turn_overflow();
5914
5915                 /* Handle "leaving" */
5916                 if (p_ptr->leaving) break;
5917
5918                 if (wild_regen) wild_regen--;
5919         }
5920
5921         /* Inside a quest and non-unique questor? */
5922         if (quest_num && !(r_info[quest[quest_num].r_idx].flags1 & RF1_UNIQUE))
5923         {
5924                 /* Un-mark the quest monster */
5925                 r_info[quest[quest_num].r_idx].flags1 &= ~RF1_QUESTOR;
5926         }
5927
5928         /* Not save-and-quit and not dead? */
5929         if (p_ptr->playing && !p_ptr->is_dead)
5930         {
5931                 /*
5932                  * Maintain Unique monsters and artifact, save current
5933                  * floor, then prepare next floor
5934                  */
5935                 leave_floor();
5936
5937                 /* Forget the flag */
5938                 reinit_wilderness = FALSE;
5939         }
5940
5941         /* Write about current level on the play record once per level */
5942         write_level = TRUE;
5943 }
5944
5945
5946 /*!
5947  * @brief 全ユーザプロファイルをロードする / Load some "user pref files"
5948  * @return なし
5949  * @note
5950  * Modified by Arcum Dagsson to support
5951  * separate macro files for different realms.
5952  */
5953 static void load_all_pref_files(void)
5954 {
5955         char buf[1024];
5956
5957         /* Access the "user" pref file */
5958         sprintf(buf, "user.prf");
5959
5960         /* Process that file */
5961         process_pref_file(buf);
5962
5963         /* Access the "user" system pref file */
5964         sprintf(buf, "user-%s.prf", ANGBAND_SYS);
5965
5966         /* Process that file */
5967         process_pref_file(buf);
5968
5969         /* Access the "race" pref file */
5970         sprintf(buf, "%s.prf", rp_ptr->title);
5971
5972         /* Process that file */
5973         process_pref_file(buf);
5974
5975         /* Access the "class" pref file */
5976         sprintf(buf, "%s.prf", cp_ptr->title);
5977
5978         /* Process that file */
5979         process_pref_file(buf);
5980
5981         /* Access the "character" pref file */
5982         sprintf(buf, "%s.prf", player_base);
5983
5984         /* Process that file */
5985         process_pref_file(buf);
5986
5987         /* Access the "realm 1" pref file */
5988         if (p_ptr->realm1 != REALM_NONE)
5989         {
5990                 sprintf(buf, "%s.prf", realm_names[p_ptr->realm1]);
5991
5992                 /* Process that file */
5993                 process_pref_file(buf);
5994         }
5995
5996         /* Access the "realm 2" pref file */
5997         if (p_ptr->realm2 != REALM_NONE)
5998         {
5999                 sprintf(buf, "%s.prf", realm_names[p_ptr->realm2]);
6000
6001                 /* Process that file */
6002                 process_pref_file(buf);
6003         }
6004
6005
6006         /* Load an autopick preference file */
6007         autopick_load_pref(FALSE);
6008 }
6009
6010
6011 /*!
6012  * @brief ビットセットからゲームオプションを展開する / Extract option variables from bit sets
6013  * @return なし
6014  */
6015 void extract_option_vars(void)
6016 {
6017         int i;
6018
6019         for (i = 0; option_info[i].o_desc; i++)
6020         {
6021                 int os = option_info[i].o_set;
6022                 int ob = option_info[i].o_bit;
6023
6024                 /* Set the "default" options */
6025                 if (option_info[i].o_var)
6026                 {
6027                         /* Set */
6028                         if (option_flag[os] & (1L << ob))
6029                         {
6030                                 /* Set */
6031                                 (*option_info[i].o_var) = TRUE;
6032                         }
6033
6034                         /* Clear */
6035                         else
6036                         {
6037                                 /* Clear */
6038                                 (*option_info[i].o_var) = FALSE;
6039                         }
6040                 }
6041         }
6042 }
6043
6044
6045 /*!
6046  * @brief 賞金首となるユニークを確定する / Determine bounty uniques
6047  * @return なし
6048  */
6049 void determine_bounty_uniques(void)
6050 {
6051         int i, j;
6052         MONRACE_IDX tmp;
6053         monster_race *r_ptr;
6054
6055         get_mon_num_prep(NULL, NULL);
6056         for (i = 0; i < MAX_KUBI; i++)
6057         {
6058                 while (1)
6059                 {
6060                         kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
6061                         r_ptr = &r_info[kubi_r_idx[i]];
6062
6063                         if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
6064
6065                         if (!(r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON))) continue;
6066
6067                         if (r_ptr->rarity > 100) continue;
6068
6069                         if (no_questor_or_bounty_uniques(kubi_r_idx[i])) continue;
6070
6071                         for (j = 0; j < i; j++)
6072                                 if (kubi_r_idx[i] == kubi_r_idx[j]) break;
6073
6074                         if (j == i) break;
6075                 }
6076         }
6077
6078         /* Sort them */
6079         for (i = 0; i < MAX_KUBI - 1; i++)
6080         {
6081                 for (j = i; j < MAX_KUBI; j++)
6082                 {
6083                         if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
6084                         {
6085                                 tmp = kubi_r_idx[i];
6086                                 kubi_r_idx[i] = kubi_r_idx[j];
6087                                 kubi_r_idx[j] = tmp;
6088                         }
6089                 }
6090         }
6091 }
6092
6093
6094 /*!
6095  * @brief 今日の賞金首を確定する / Determine today's bounty monster
6096  * @return なし
6097  * @note conv_old is used if loaded 0.0.3 or older save file
6098  */
6099 void determine_today_mon(bool conv_old)
6100 {
6101         int max_dl = 3, i;
6102         bool old_inside_battle = p_ptr->inside_battle;
6103         monster_race *r_ptr;
6104
6105         if (!conv_old)
6106         {
6107                 for (i = 0; i < max_d_idx; i++)
6108                 {
6109                         if (max_dlv[i] < d_info[i].mindepth) continue;
6110                         if (max_dl < max_dlv[i]) max_dl = max_dlv[i];
6111                 }
6112         }
6113         else max_dl = MAX(max_dlv[DUNGEON_ANGBAND], 3);
6114
6115         p_ptr->inside_battle = TRUE;
6116         get_mon_num_prep(NULL, NULL);
6117
6118         while (1)
6119         {
6120                 today_mon = get_mon_num(max_dl);
6121                 r_ptr = &r_info[today_mon];
6122
6123                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
6124                 if (r_ptr->flags7 & (RF7_NAZGUL | RF7_UNIQUE2)) continue;
6125                 if (r_ptr->flags2 & RF2_MULTIPLY) continue;
6126                 if ((r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) != (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) continue;
6127                 if (r_ptr->level < MIN(max_dl / 2, 40)) continue;
6128                 if (r_ptr->rarity > 10) continue;
6129                 break;
6130         }
6131
6132         p_ptr->today_mon = 0;
6133         p_ptr->inside_battle = old_inside_battle;
6134 }
6135
6136 /*!
6137  * @brief 1ゲームプレイの主要ルーチン / Actually play a game
6138  * @return なし
6139  * @note
6140  * If the "new_game" parameter is true, then, after loading the
6141  * savefile, we will commit suicide, if necessary, to allow the
6142  * player to start a new game.
6143  */
6144 void play_game(bool new_game)
6145 {
6146         MONSTER_IDX i;
6147         bool load_game = TRUE;
6148         bool init_random_seed = FALSE;
6149
6150 #ifdef CHUUKEI
6151         if (chuukei_client)
6152         {
6153                 reset_visuals();
6154                 browse_chuukei();
6155                 return;
6156         }
6157
6158         else if (chuukei_server)
6159         {
6160                 prepare_chuukei_hooks();
6161         }
6162 #endif
6163
6164         if (browsing_movie)
6165         {
6166                 reset_visuals();
6167                 browse_movie();
6168                 return;
6169         }
6170
6171         hack_mutation = FALSE;
6172
6173         /* Hack -- Character is "icky" */
6174         character_icky = TRUE;
6175
6176         /* Make sure main term is active */
6177         Term_activate(angband_term[0]);
6178
6179         /* Initialise the resize hooks */
6180         angband_term[0]->resize_hook = resize_map;
6181
6182         for (i = 1; i < 8; i++)
6183         {
6184                 /* Does the term exist? */
6185                 if (angband_term[i])
6186                 {
6187                         /* Add the redraw on resize hook */
6188                         angband_term[i]->resize_hook = redraw_window;
6189                 }
6190         }
6191
6192         /* Hack -- turn off the cursor */
6193         (void)Term_set_cursor(0);
6194
6195
6196         /* Attempt to load */
6197         if (!load_player())
6198         {
6199                 /* Oops */
6200                 quit(_("セーブファイルが壊れています", "broken savefile"));
6201         }
6202
6203         /* Extract the options */
6204         extract_option_vars();
6205
6206         /* Report waited score */
6207         if (p_ptr->wait_report_score)
6208         {
6209                 char buf[1024];
6210                 bool success;
6211
6212                 if (!get_check_strict(_("待機していたスコア登録を今行ないますか?", "Do you register score now? "), CHECK_NO_HISTORY))
6213                         quit(0);
6214
6215                 /* Update stuff */
6216                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
6217
6218                 /* Update stuff */
6219                 update_stuff();
6220
6221                 p_ptr->is_dead = TRUE;
6222
6223                 start_time = (u32b)time(NULL);
6224
6225                 /* No suspending now */
6226                 signals_ignore_tstp();
6227                 
6228                 /* Hack -- Character is now "icky" */
6229                 character_icky = TRUE;
6230
6231                 /* Build the filename */
6232                 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
6233
6234                 /* Open the high score file, for reading/writing */
6235                 highscore_fd = fd_open(buf, O_RDWR);
6236
6237                 /* Handle score, show Top scores */
6238                 success = send_world_score(TRUE);
6239
6240                 if (!success && !get_check_strict(_("スコア登録を諦めますか?", "Do you give up score registration? "), CHECK_NO_HISTORY))
6241                 {
6242                         prt(_("引き続き待機します。", "standing by for future registration..."), 0, 0);
6243                         (void)inkey();
6244                 }
6245                 else
6246                 {
6247                         p_ptr->wait_report_score = FALSE;
6248                         top_twenty();
6249                         if (!save_player()) msg_print(_("セーブ失敗!", "death save failed!"));
6250                 }
6251                 /* Shut the high score file */
6252                 (void)fd_close(highscore_fd);
6253
6254                 /* Forget the high score fd */
6255                 highscore_fd = -1;
6256                 
6257                 /* Allow suspending now */
6258                 signals_handle_tstp();
6259
6260                 quit(0);
6261         }
6262
6263         creating_savefile = new_game;
6264
6265         /* Nothing loaded */
6266         if (!character_loaded)
6267         {
6268                 /* Make new player */
6269                 new_game = TRUE;
6270
6271                 /* The dungeon is not ready */
6272                 character_dungeon = FALSE;
6273
6274                 /* Prepare to init the RNG */
6275                 init_random_seed = TRUE;
6276
6277                 /* Initialize the saved floors data */
6278                 init_saved_floors(FALSE);
6279         }
6280
6281         /* Old game is loaded.  But new game is requested. */
6282         else if (new_game)
6283         {
6284                 /* Initialize the saved floors data */
6285                 init_saved_floors(TRUE);
6286         }
6287
6288         /* Process old character */
6289         if (!new_game)
6290         {
6291                 /* Process the player name */
6292                 process_player_name(FALSE);
6293         }
6294
6295         /* Init the RNG */
6296         if (init_random_seed)
6297         {
6298                 Rand_state_init();
6299         }
6300
6301         /* Roll new character */
6302         if (new_game)
6303         {
6304                 /* The dungeon is not ready */
6305                 character_dungeon = FALSE;
6306
6307                 /* Start in town */
6308                 dun_level = 0;
6309                 p_ptr->inside_quest = 0;
6310                 p_ptr->inside_arena = FALSE;
6311                 p_ptr->inside_battle = FALSE;
6312
6313                 write_level = TRUE;
6314
6315                 /* Hack -- seed for flavors */
6316                 seed_flavor = randint0(0x10000000);
6317
6318                 /* Hack -- seed for town layout */
6319                 seed_town = randint0(0x10000000);
6320
6321                 /* Roll up a new character */
6322                 player_birth();
6323
6324                 counts_write(2,0);
6325                 p_ptr->count = 0;
6326
6327                 load = FALSE;
6328
6329                 determine_bounty_uniques();
6330                 determine_today_mon(FALSE);
6331
6332                 /* Initialize object array */
6333                 wipe_o_list();
6334         }
6335         else
6336         {
6337                 write_level = FALSE;
6338
6339                 do_cmd_write_nikki(NIKKI_GAMESTART, 1, 
6340                                           _("                            ----ゲーム再開----",
6341                                                 "                            ---- Restart Game ----"));
6342
6343 /*
6344  * 1.0.9 以前はセーブ前に p_ptr->riding = -1 としていたので、再設定が必要だった。
6345  * もう不要だが、以前のセーブファイルとの互換のために残しておく。
6346  */
6347                 if (p_ptr->riding == -1)
6348                 {
6349                         p_ptr->riding = 0;
6350                         for (i = m_max; i > 0; i--)
6351                         {
6352                                 if (player_bold(m_list[i].fy, m_list[i].fx))
6353                                 {
6354                                         p_ptr->riding = i;
6355                                         break;
6356                                 }
6357                         }
6358                 }
6359         }
6360
6361         creating_savefile = FALSE;
6362
6363         p_ptr->teleport_town = FALSE;
6364         p_ptr->sutemi = FALSE;
6365         world_monster = FALSE;
6366         now_damaged = FALSE;
6367         now_message = 0;
6368         start_time = time(NULL) - 1;
6369         record_o_name[0] = '\0';
6370
6371         /* Reset map panel */
6372         panel_row_min = cur_hgt;
6373         panel_col_min = cur_wid;
6374
6375         /* Sexy gal gets bonus to maximum weapon skill of whip */
6376         if (p_ptr->pseikaku == SEIKAKU_SEXY)
6377                 s_info[p_ptr->pclass].w_max[TV_HAFTED-TV_WEAPON_BEGIN][SV_WHIP] = WEAPON_EXP_MASTER;
6378
6379         /* Fill the arrays of floors and walls in the good proportions */
6380         set_floor_and_wall(dungeon_type);
6381
6382         /* Flavor the objects */
6383         flavor_init();
6384
6385         /* Flash a message */
6386         prt(_("お待ち下さい...", "Please wait..."), 0, 0);
6387
6388         /* Flush the message */
6389         Term_fresh();
6390
6391
6392         /* Hack -- Enter wizard mode */
6393         if (arg_wizard)
6394         {
6395                 if (enter_wizard_mode())
6396                 {
6397                         p_ptr->wizard = TRUE;
6398
6399                         if (p_ptr->is_dead || !p_ptr->y || !p_ptr->x)
6400                         {
6401                                 /* Initialize the saved floors data */
6402                                 init_saved_floors(TRUE);
6403
6404                                 /* Avoid crash */
6405                                 p_ptr->inside_quest = 0;
6406
6407                                 /* Avoid crash in update_view() */
6408                                 p_ptr->y = p_ptr->x = 10;
6409                         }
6410                 }
6411                 else if (p_ptr->is_dead)
6412                 {
6413                         quit("Already dead.");
6414                 }
6415         }
6416
6417         /* Initialize the town-buildings if necessary */
6418         if (!dun_level && !p_ptr->inside_quest)
6419         {
6420                 /* Init the wilderness */
6421
6422                 process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
6423
6424                 /* Init the town */
6425                 init_flags = INIT_ONLY_BUILDINGS;
6426
6427                 process_dungeon_file("t_info.txt", 0, 0, MAX_HGT, MAX_WID);
6428
6429                 select_floor_music();
6430         }
6431
6432
6433         /* Generate a dungeon level if needed */
6434         if (!character_dungeon)
6435         {
6436                 change_floor();
6437         }
6438
6439         else
6440         {
6441                 /* HACK -- Restore from panic-save */
6442                 if (p_ptr->panic_save)
6443                 {
6444                         /* No player?  -- Try to regenerate floor */
6445                         if (!p_ptr->y || !p_ptr->x)
6446                         {
6447                                 msg_print(_("プレイヤーの位置がおかしい。フロアを再生成します。", "What a strange player location.  Regenerate the dungeon floor."));
6448                                 change_floor();
6449                         }
6450
6451                         /* Still no player?  -- Try to locate random place */
6452                         if (!p_ptr->y || !p_ptr->x) p_ptr->y = p_ptr->x = 10;
6453
6454                         /* No longer in panic */
6455                         p_ptr->panic_save = 0;
6456                 }
6457         }
6458
6459         /* Character is now "complete" */
6460         character_generated = TRUE;
6461
6462
6463         /* Hack -- Character is no longer "icky" */
6464         character_icky = FALSE;
6465
6466
6467         if (new_game)
6468         {
6469                 char buf[80];
6470                 sprintf(buf, _("%sに降り立った。", "You are standing in the %s."), map_name());
6471                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, buf);
6472         }
6473
6474
6475         /* Start game */
6476         p_ptr->playing = TRUE;
6477
6478         /* Reset the visual mappings */
6479         reset_visuals();
6480
6481         /* Load the "pref" files */
6482         load_all_pref_files();
6483
6484         /* Give startup outfit (after loading pref files) */
6485         if (new_game)
6486         {
6487                 player_outfit();
6488         }
6489
6490         /* React to changes */
6491         Term_xtra(TERM_XTRA_REACT, 0);
6492
6493         /* Window stuff */
6494         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
6495
6496         /* Window stuff */
6497         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
6498
6499         /* Window stuff */
6500         window_stuff();
6501
6502
6503         /* Set or clear "rogue_like_commands" if requested */
6504         if (arg_force_original) rogue_like_commands = FALSE;
6505         if (arg_force_roguelike) rogue_like_commands = TRUE;
6506
6507         /* Hack -- Enforce "delayed death" */
6508         if (p_ptr->chp < 0) p_ptr->is_dead = TRUE;
6509
6510         if (p_ptr->prace == RACE_ANDROID) calc_android_exp();
6511
6512         if (new_game && ((p_ptr->pclass == CLASS_CAVALRY) || (p_ptr->pclass == CLASS_BEASTMASTER)))
6513         {
6514                 monster_type *m_ptr;
6515                 IDX pet_r_idx = ((p_ptr->pclass == CLASS_CAVALRY) ? MON_HORSE : MON_YASE_HORSE);
6516                 monster_race *r_ptr = &r_info[pet_r_idx];
6517                 place_monster_aux(0, p_ptr->y, p_ptr->x - 1, pet_r_idx,
6518                                   (PM_FORCE_PET | PM_NO_KAGE));
6519                 m_ptr = &m_list[hack_m_idx_ii];
6520                 m_ptr->mspeed = r_ptr->speed;
6521                 m_ptr->maxhp = r_ptr->hdice*(r_ptr->hside+1)/2;
6522                 m_ptr->max_maxhp = m_ptr->maxhp;
6523                 m_ptr->hp = r_ptr->hdice*(r_ptr->hside+1)/2;
6524                 m_ptr->dealt_damage = 0;
6525                 m_ptr->energy_need = ENERGY_NEED() + ENERGY_NEED();
6526         }
6527
6528         (void)combine_and_reorder_home(STORE_HOME);
6529         (void)combine_and_reorder_home(STORE_MUSEUM);
6530
6531         select_floor_music();
6532
6533         /* Process */
6534         while (TRUE)
6535         {
6536                 /* Process the level */
6537                 dungeon(load_game);
6538
6539                 /* Handle "p_ptr->notice" */
6540                 notice_stuff();
6541
6542                 /* Hack -- prevent "icky" message */
6543                 character_xtra = TRUE;
6544
6545                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6546                 handle_stuff();
6547
6548                 character_xtra = FALSE;
6549
6550                 /* Cancel the target */
6551                 target_who = 0;
6552
6553                 /* Cancel the health bar */
6554                 health_track(0);
6555
6556
6557                 /* Forget the lite */
6558                 forget_lite();
6559
6560                 /* Forget the view */
6561                 forget_view();
6562
6563                 /* Forget the view */
6564                 clear_mon_lite();
6565
6566                 /* Handle "quit and save" */
6567                 if (!p_ptr->playing && !p_ptr->is_dead) break;
6568
6569                 /* Erase the old cave */
6570                 wipe_o_list();
6571                 if (!p_ptr->is_dead) wipe_m_list();
6572
6573
6574                 /* XXX XXX XXX */
6575                 msg_print(NULL);
6576
6577                 load_game = FALSE;
6578
6579                 /* Accidental Death */
6580                 if (p_ptr->playing && p_ptr->is_dead)
6581                 {
6582                         if (p_ptr->inside_arena)
6583                         {
6584                                 p_ptr->inside_arena = FALSE;
6585                                 if (p_ptr->arena_number > MAX_ARENA_MONS)
6586                                         p_ptr->arena_number++;
6587                                 else
6588                                         p_ptr->arena_number = -1 - p_ptr->arena_number;
6589                                 p_ptr->is_dead = FALSE;
6590                                 p_ptr->chp = 0;
6591                                 p_ptr->chp_frac = 0;
6592                                 p_ptr->exit_bldg = TRUE;
6593                                 reset_tim_flags();
6594
6595                                 /* Leave through the exit */
6596                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_RAND_CONNECT);
6597
6598                                 /* prepare next floor */
6599                                 leave_floor();
6600                         }
6601                         else
6602                         {
6603                                 /* Mega-Hack -- Allow player to cheat death */
6604                                 if ((p_ptr->wizard || cheat_live) && !get_check(_("死にますか? ", "Die? ")))
6605                                 {
6606                                         /* Mark social class, reset age, if needed */
6607                                         if (p_ptr->sc) p_ptr->sc = p_ptr->age = 0;
6608
6609                                         /* Increase age */
6610                                         p_ptr->age++;
6611
6612                                         /* Mark savefile */
6613                                         p_ptr->noscore |= 0x0001;
6614
6615                                         /* Message */
6616                                         msg_print(_("ウィザードモードに念を送り、死を欺いた。", "You invoke wizard mode and cheat death."));
6617                                         msg_print(NULL);
6618
6619                                         /* Restore hit points */
6620                                         p_ptr->chp = p_ptr->mhp;
6621                                         p_ptr->chp_frac = 0;
6622
6623                                         if (p_ptr->pclass == CLASS_MAGIC_EATER)
6624                                         {
6625                                                 int magic_idx;
6626                                                 for (magic_idx = 0; magic_idx < EATER_EXT*2; magic_idx++)
6627                                                 {
6628                                                         p_ptr->magic_num1[magic_idx] = p_ptr->magic_num2[magic_idx]*EATER_CHARGE;
6629                                                 }
6630                                                 for (; magic_idx < EATER_EXT*3; magic_idx++)
6631                                                 {
6632                                                         p_ptr->magic_num1[magic_idx] = 0;
6633                                                 }
6634                                         }
6635                                         /* Restore spell points */
6636                                         p_ptr->csp = p_ptr->msp;
6637                                         p_ptr->csp_frac = 0;
6638
6639                                         /* Hack -- cancel recall */
6640                                         if (p_ptr->word_recall)
6641                                         {
6642                                                 /* Message */
6643                                                 msg_print(_("張りつめた大気が流れ去った...", "A tension leaves the air around you..."));
6644                                                 msg_print(NULL);
6645
6646                                                 /* Hack -- Prevent recall */
6647                                                 p_ptr->word_recall = 0;
6648                                                 p_ptr->redraw |= (PR_STATUS);
6649                                         }
6650
6651                                         /* Hack -- cancel alter */
6652                                         if (p_ptr->alter_reality)
6653                                         {
6654                                                 /* Hack -- Prevent alter */
6655                                                 p_ptr->alter_reality = 0;
6656                                                 p_ptr->redraw |= (PR_STATUS);
6657                                         }
6658
6659                                         /* Note cause of death XXX XXX XXX */
6660                                         (void)strcpy(p_ptr->died_from, _("死の欺き", "Cheating death"));
6661
6662                                         /* Do not die */
6663                                         p_ptr->is_dead = FALSE;
6664
6665                                         /* Hack -- Healing */
6666                                         (void)set_blind(0);
6667                                         (void)set_confused(0);
6668                                         (void)set_poisoned(0);
6669                                         (void)set_afraid(0);
6670                                         (void)set_paralyzed(0);
6671                                         (void)set_image(0);
6672                                         (void)set_stun(0);
6673                                         (void)set_cut(0);
6674
6675                                         /* Hack -- Prevent starvation */
6676                                         (void)set_food(PY_FOOD_MAX - 1);
6677
6678                                         dun_level = 0;
6679                                         p_ptr->inside_arena = FALSE;
6680                                         p_ptr->inside_battle = FALSE;
6681                                         leaving_quest = 0;
6682                                         p_ptr->inside_quest = 0;
6683                                         if (dungeon_type) p_ptr->recall_dungeon = dungeon_type;
6684                                         dungeon_type = 0;
6685                                         if (lite_town || vanilla_town)
6686                                         {
6687                                                 p_ptr->wilderness_y = 1;
6688                                                 p_ptr->wilderness_x = 1;
6689                                                 if (vanilla_town)
6690                                                 {
6691                                                         p_ptr->oldpy = 10;
6692                                                         p_ptr->oldpx = 34;
6693                                                 }
6694                                                 else
6695                                                 {
6696                                                         p_ptr->oldpy = 33;
6697                                                         p_ptr->oldpx = 131;
6698                                                 }
6699                                         }
6700                                         else
6701                                         {
6702                                                 p_ptr->wilderness_y = 48;
6703                                                 p_ptr->wilderness_x = 5;
6704                                                 p_ptr->oldpy = 33;
6705                                                 p_ptr->oldpx = 131;
6706                                         }
6707
6708                                         /* Leaving */
6709                                         p_ptr->wild_mode = FALSE;
6710                                         p_ptr->leaving = TRUE;
6711
6712                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 1, 
6713                                                                 _("                            しかし、生き返った。", 
6714                                                                   "                            but revived."));
6715
6716                                         /* Prepare next floor */
6717                                         leave_floor();
6718                                         wipe_m_list();
6719                                 }
6720                         }
6721                 }
6722
6723                 /* Handle "death" */
6724                 if (p_ptr->is_dead) break;
6725
6726                 /* Make a new level */
6727                 change_floor();
6728         }
6729
6730         /* Close stuff */
6731         close_game();
6732
6733         /* Quit */
6734         quit(NULL);
6735 }
6736
6737 /*!
6738  * @brief ゲームターンからの実時間換算を行うための補正をかける
6739  * @param hoge ゲームターン
6740  * @details アンデッド種族は18:00からゲームを開始するので、この修正を予め行う。
6741  * @return 修正をかけた後のゲームターン
6742  */
6743 s32b turn_real(s32b hoge)
6744 {
6745         switch (p_ptr->start_race)
6746         {
6747         case RACE_VAMPIRE:
6748         case RACE_SKELETON:
6749         case RACE_ZOMBIE:
6750         case RACE_SPECTRE:
6751                 return hoge - (TURNS_PER_TICK * TOWN_DAWN * 3 / 4);
6752         default:
6753                 return hoge;
6754         }
6755 }
6756
6757 /*!
6758  * @brief ターンのオーバーフローに対する対処
6759  * @details ターン及びターンを記録する変数をターンの限界の1日前まで巻き戻す.
6760  * @return 修正をかけた後のゲームターン
6761  */
6762 void prevent_turn_overflow(void)
6763 {
6764         int rollback_days, i, j;
6765         s32b rollback_turns;
6766
6767         if (turn < turn_limit) return;
6768
6769         rollback_days = 1 + (turn - turn_limit) / (TURNS_PER_TICK * TOWN_DAWN);
6770         rollback_turns = TURNS_PER_TICK * TOWN_DAWN * rollback_days;
6771
6772         if (turn > rollback_turns) turn -= rollback_turns;
6773         else turn = 1; /* Paranoia */
6774         if (old_turn > rollback_turns) old_turn -= rollback_turns;
6775         else old_turn = 1;
6776         if (old_battle > rollback_turns) old_battle -= rollback_turns;
6777         else old_battle = 1;
6778         if (p_ptr->feeling_turn > rollback_turns) p_ptr->feeling_turn -= rollback_turns;
6779         else p_ptr->feeling_turn = 1;
6780
6781         for (i = 1; i < max_towns; i++)
6782         {
6783                 for (j = 0; j < MAX_STORES; j++)
6784                 {
6785                         store_type *st_ptr = &town[i].store[j];
6786
6787                         if (st_ptr->last_visit > -10L * TURNS_PER_TICK * STORE_TICKS)
6788                         {
6789                                 st_ptr->last_visit -= rollback_turns;
6790                                 if (st_ptr->last_visit < -10L * TURNS_PER_TICK * STORE_TICKS) st_ptr->last_visit = -10L * TURNS_PER_TICK * STORE_TICKS;
6791                         }
6792
6793                         if (st_ptr->store_open)
6794                         {
6795                                 st_ptr->store_open -= rollback_turns;
6796                                 if (st_ptr->store_open < 1) st_ptr->store_open = 1;
6797                         }
6798                 }
6799         }
6800 }