OSDN Git Service

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