OSDN Git Service

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