OSDN Git Service

[Refactor] #37287 #37353 型の置換。 / Type replacement.
[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                         BIT_FLAGS 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                                 BIT_FLAGS flgs[TR_FLAG_SIZE];
2495                                 o_ptr = &inventory[i];
2496
2497                                 /* Skip non-objects */
2498                                 if (!o_ptr->k_idx) continue;
2499
2500                                 /* Extract the item flags */
2501                                 object_flags(o_ptr, flgs);
2502
2503                                 if (have_flag(flgs, TR_TELEPORT))
2504                                 {
2505                                         /* {.} will stop random teleportation. */
2506                                         if (!o_ptr->inscription || !my_strchr(quark_str(o_ptr->inscription), '.'))
2507                                         {
2508                                                 count++;
2509                                                 if (one_in_(count)) i_keep = i;
2510                                         }
2511                                 }
2512                         }
2513
2514                         o_ptr = &inventory[i_keep];
2515                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2516                         msg_format(_("%sがテレポートの能力を発動させようとしている。", "Your %s is activating teleportation."), o_name);
2517                         if (get_check_strict(_("テレポートしますか?", "Teleport? "), CHECK_OKAY_CANCEL))
2518                         {
2519                                 disturb(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(SOUND_TPLEVEL);
2956                 }
2957         }
2958
2959
2960         /* Delayed Alter reality */
2961         if (p_ptr->alter_reality)
2962         {
2963                 if (autosave_l && (p_ptr->alter_reality == 1) && !p_ptr->inside_battle)
2964                         do_cmd_save_game(TRUE);
2965
2966                 /* Count down towards alter */
2967                 p_ptr->alter_reality--;
2968
2969                 p_ptr->redraw |= (PR_STATUS);
2970
2971                 /* Activate the alter reality */
2972                 if (!p_ptr->alter_reality)
2973                 {
2974                         /* Disturbing! */
2975                         disturb(0, 1);
2976
2977                         /* Determine the level */
2978                         if (!quest_number(dun_level) && dun_level)
2979                         {
2980                                 msg_print(_("世界が変わった!", "The world changes!"));
2981
2982                                 /*
2983                                  * Clear all saved floors
2984                                  * and create a first saved floor
2985                                  */
2986                                 prepare_change_floor_mode(CFM_FIRST_FLOOR);
2987
2988                                 /* Leaving */
2989                                 p_ptr->leaving = TRUE;
2990                         }
2991                         else
2992                         {
2993                                 msg_print(_("世界が少しの間変化したようだ。", "The world seems to change for a moment!"));
2994                         }
2995
2996                         sound(SOUND_TPLEVEL);
2997                 }
2998         }
2999 }
3000
3001
3002 /*!
3003  * @brief 指定したモンスターに隣接しているモンスターの数を返す。
3004  * / Count number of adjacent monsters
3005  * @param m_idx 隣接数を調べたいモンスターのID
3006  * @return 隣接しているモンスターの数
3007  */
3008 static int get_monster_crowd_number(MONSTER_IDX m_idx)
3009 {
3010         monster_type *m_ptr = &m_list[m_idx];
3011         int my = m_ptr->fy;
3012         int mx = m_ptr->fx;
3013         int i;
3014         int count = 0;
3015
3016         for (i = 0; i < 7; i++)
3017         {
3018                 int ay = my + ddy_ddd[i];
3019                 int ax = mx + ddx_ddd[i];
3020
3021                 if (!in_bounds(ay, ax)) continue;
3022
3023                 /* Count number of monsters */
3024                 if (cave[ay][ax].m_idx > 0) count++;
3025         }
3026
3027         return count;
3028 }
3029
3030
3031
3032 /*!
3033  * ダンジョンの雰囲気を計算するための非線形基準値 / Dungeon rating is no longer linear
3034  */
3035 #define RATING_BOOST(delta) (delta * delta + 50 * delta)
3036
3037 /*!
3038  * @brief ダンジョンの雰囲気を算出する。
3039  * / Examine all monsters and unidentified objects, and get the feeling of current dungeon floor
3040  * @return 算出されたダンジョンの雰囲気ランク
3041  */
3042 static byte get_dungeon_feeling(void)
3043 {
3044         const int base = 10;
3045         int rating = 0;
3046         IDX i;
3047
3048         /* Hack -- no feeling in the town */
3049         if (!dun_level) return 0;
3050
3051         /* Examine each monster */
3052         for (i = 1; i < m_max; i++)
3053         {
3054                 monster_type *m_ptr = &m_list[i];
3055                 monster_race *r_ptr;
3056                 int delta = 0;
3057
3058                 /* Skip dead monsters */
3059                 if (!m_ptr->r_idx) continue;
3060
3061                 /* Ignore pet */
3062                 if (is_pet(m_ptr)) continue;
3063
3064                 r_ptr = &r_info[m_ptr->r_idx];
3065
3066                 /* Unique monsters */
3067                 if (r_ptr->flags1 & (RF1_UNIQUE))
3068                 {
3069                         /* Nearly out-of-depth unique monsters */
3070                         if (r_ptr->level + 10 > dun_level)
3071                         {
3072                                 /* Boost rating by twice delta-depth */
3073                                 delta += (r_ptr->level + 10 - dun_level) * 2 * base;
3074                         }
3075                 }
3076                 else
3077                 {
3078                         /* Out-of-depth monsters */
3079                         if (r_ptr->level > dun_level)
3080                         {
3081                                 /* Boost rating by delta-depth */
3082                                 delta += (r_ptr->level - dun_level) * base;
3083                         }
3084                 }
3085
3086                 /* Unusually crowded monsters get a little bit of rating boost */
3087                 if (r_ptr->flags1 & RF1_FRIENDS)
3088                 {
3089                         if (5 <= get_monster_crowd_number(i)) delta += 1;
3090                 }
3091                 else
3092                 {
3093                         if (2 <= get_monster_crowd_number(i)) delta += 1;
3094                 }
3095
3096
3097                 rating += RATING_BOOST(delta);
3098         }
3099
3100         /* Examine each unidentified object */
3101         for (i = 1; i < o_max; i++)
3102         {
3103                 object_type *o_ptr = &o_list[i];
3104                 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3105                 int delta = 0;
3106
3107                 /* Skip dead objects */
3108                 if (!o_ptr->k_idx) continue;
3109
3110                 /* Skip known objects */
3111                 if (object_is_known(o_ptr))
3112                 {
3113                         /* Touched? */
3114                         if (o_ptr->marked & OM_TOUCHED) continue;
3115                 }
3116
3117                 /* Skip pseudo-known objects */
3118                 if (o_ptr->ident & IDENT_SENSE) continue;
3119
3120                 /* Ego objects */
3121                 if (object_is_ego(o_ptr))
3122                 {
3123                         ego_item_type *e_ptr = &e_info[o_ptr->name2];
3124
3125                         delta += e_ptr->rating * base;
3126                 }
3127
3128                 /* Artifacts */
3129                 if (object_is_artifact(o_ptr))
3130                 {
3131                         s32b cost = object_value_real(o_ptr);
3132
3133                         delta += 10 * base;
3134                         if (cost > 10000L) delta += 10 * base;
3135                         if (cost > 50000L) delta += 10 * base;
3136                         if (cost > 100000L) delta += 10 * base;
3137
3138                         /* Special feeling */
3139                         if (!preserve_mode) return 1;
3140                 }
3141
3142                 if (o_ptr->tval == TV_DRAG_ARMOR) delta += 30 * base;
3143                 if (o_ptr->tval == TV_SHIELD &&
3144                     o_ptr->sval == SV_DRAGON_SHIELD) delta += 5 * base;
3145                 if (o_ptr->tval == TV_GLOVES &&
3146                     o_ptr->sval == SV_SET_OF_DRAGON_GLOVES) delta += 5 * base;
3147                 if (o_ptr->tval == TV_BOOTS &&
3148                     o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE) delta += 5 * base;
3149                 if (o_ptr->tval == TV_HELM &&
3150                     o_ptr->sval == SV_DRAGON_HELM) delta += 5 * base;
3151                 if (o_ptr->tval == TV_RING &&
3152                     o_ptr->sval == SV_RING_SPEED &&
3153                     !object_is_cursed(o_ptr)) delta += 25 * base;
3154                 if (o_ptr->tval == TV_RING &&
3155                     o_ptr->sval == SV_RING_LORDLY &&
3156                     !object_is_cursed(o_ptr)) delta += 15 * base;
3157                 if (o_ptr->tval == TV_AMULET &&
3158                     o_ptr->sval == SV_AMULET_THE_MAGI &&
3159                     !object_is_cursed(o_ptr)) delta += 15 * base;
3160
3161                 /* Out-of-depth objects */
3162                 if (!object_is_cursed(o_ptr) && !object_is_broken(o_ptr) &&
3163                     k_ptr->level > dun_level)
3164                 {
3165                         /* Rating increase */
3166                         delta += (k_ptr->level - dun_level) * base;
3167                 }
3168
3169                 rating += RATING_BOOST(delta);
3170         }
3171
3172
3173         if (rating > RATING_BOOST(1000)) return 2;
3174         if (rating > RATING_BOOST(800)) return 3;
3175         if (rating > RATING_BOOST(600)) return 4;
3176         if (rating > RATING_BOOST(400)) return 5;
3177         if (rating > RATING_BOOST(300)) return 6;
3178         if (rating > RATING_BOOST(200)) return 7;
3179         if (rating > RATING_BOOST(100)) return 8;
3180         if (rating > RATING_BOOST(0)) return 9;
3181
3182         return 10;
3183 }
3184
3185 /*!
3186  * @brief ダンジョンの雰囲気を更新し、変化があった場合メッセージを表示する
3187  * / Update dungeon feeling, and announce it if changed
3188  * @return なし
3189  */
3190 static void update_dungeon_feeling(void)
3191 {
3192         byte new_feeling;
3193         int quest_num;
3194         int delay;
3195
3196         /* No feeling on the surface */
3197         if (!dun_level) return;
3198
3199         /* No feeling in the arena */
3200         if (p_ptr->inside_battle) return;
3201
3202         /* Extract delay time */
3203         delay = MAX(10, 150 - p_ptr->skill_fos) * (150 - dun_level) * TURNS_PER_TICK / 100;
3204
3205         /* Not yet felt anything */
3206         if (turn < p_ptr->feeling_turn + delay && !cheat_xtra) return;
3207
3208         /* Extract quest number (if any) */
3209         quest_num = quest_number(dun_level);
3210
3211         /* No feeling in a quest */
3212         if (quest_num &&
3213             (is_fixed_quest_idx(quest_num) &&
3214              !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) ||
3215                !(quest[quest_num].flags & QUEST_FLAG_PRESET)))) return;
3216
3217
3218         /* Get new dungeon feeling */
3219         new_feeling = get_dungeon_feeling();
3220
3221         /* Remember last time updated */
3222         p_ptr->feeling_turn = turn;
3223
3224         /* No change */
3225         if (p_ptr->feeling == new_feeling) return;
3226
3227         /* Dungeon feeling is changed */
3228         p_ptr->feeling = new_feeling;
3229
3230         /* Announce feeling */
3231         do_cmd_feeling();
3232
3233         select_floor_music();
3234
3235         /* Update the level indicator */
3236         p_ptr->redraw |= (PR_DEPTH);
3237
3238         /* Disturb */
3239         if (disturb_minor) disturb(0, 0);
3240 }
3241
3242 /*!
3243  * @brief 10ゲームターンが進行する毎にゲーム世界全体の処理を行う。
3244  * / Handle certain things once every 10 game turns
3245  * @return なし
3246  */
3247 static void process_world(void)
3248 {
3249         int day, hour, min;
3250
3251         const s32b A_DAY = TURNS_PER_TICK * TOWN_DAWN;
3252         s32b prev_turn_in_today = ((turn - TURNS_PER_TICK) % A_DAY + A_DAY / 4) % A_DAY;
3253         int prev_min = (1440 * prev_turn_in_today / A_DAY) % 60;
3254         
3255         extract_day_hour_min(&day, &hour, &min);
3256
3257         /* Update dungeon feeling, and announce it if changed */
3258         update_dungeon_feeling();
3259
3260         /* 帰還無しモード時のレベルテレポバグ対策 / Fix for level teleport bugs on ironman_downward.*/
3261         if (ironman_downward && (dungeon_type != DUNGEON_ANGBAND && dungeon_type != 0))
3262         {
3263                 dun_level = 0;
3264                 dungeon_type = 0;
3265                 prepare_change_floor_mode(CFM_FIRST_FLOOR | CFM_RAND_PLACE);
3266                 p_ptr->inside_arena = FALSE;
3267                 p_ptr->wild_mode = FALSE;
3268                 p_ptr->leaving = TRUE;
3269         }
3270
3271         /*** Check monster arena ***/
3272         if (p_ptr->inside_battle && !p_ptr->leaving)
3273         {
3274                 int i2, j2;
3275                 int win_m_idx = 0;
3276                 int number_mon = 0;
3277
3278                 /* Count all hostile monsters */
3279                 for (i2 = 0; i2 < cur_wid; ++i2)
3280                         for (j2 = 0; j2 < cur_hgt; j2++)
3281                         {
3282                                 cave_type *c_ptr = &cave[j2][i2];
3283
3284                                 if ((c_ptr->m_idx > 0) && (c_ptr->m_idx != p_ptr->riding))
3285                                 {
3286                                         number_mon++;
3287                                         win_m_idx = c_ptr->m_idx;
3288                                 }
3289                         }
3290
3291                 if (number_mon == 0)
3292                 {
3293                         msg_print(_("相打ちに終わりました。", "They have kill each other at the same time."));
3294                         msg_print(NULL);
3295                         p_ptr->energy_need = 0;
3296                         battle_monsters();
3297                 }
3298                 else if ((number_mon-1) == 0)
3299                 {
3300                         char m_name[80];
3301                         monster_type *wm_ptr;
3302
3303                         wm_ptr = &m_list[win_m_idx];
3304
3305                         monster_desc(m_name, wm_ptr, 0);
3306                         msg_format(_("%sが勝利した!", "%s is winner!"), m_name);
3307                         msg_print(NULL);
3308
3309                         if (win_m_idx == (sel_monster+1))
3310                         {
3311                                 msg_print(_("おめでとうございます。", "Congratulations."));
3312                                 msg_format(_("%d$を受け取った。", "You received %d gold."), battle_odds);
3313                                 p_ptr->au += battle_odds;
3314                         }
3315                         else
3316                         {
3317                                 msg_print(_("残念でした。", "You lost gold."));
3318                         }
3319                         msg_print(NULL);
3320                         p_ptr->energy_need = 0;
3321                         battle_monsters();
3322                 }
3323                 else if (turn - old_turn == 150 * TURNS_PER_TICK)
3324                 {
3325                         msg_print(_("申し分けありませんが、この勝負は引き分けとさせていただきます。", "This battle have ended in a draw."));
3326                         p_ptr->au += kakekin;
3327                         msg_print(NULL);
3328                         p_ptr->energy_need = 0;
3329                         battle_monsters();
3330                 }
3331         }
3332
3333         /* Every 10 game turns */
3334         if (turn % TURNS_PER_TICK) return;
3335
3336         /*** Check the Time and Load ***/
3337
3338         if (!(turn % (50*TURNS_PER_TICK)))
3339         {
3340                 /* Check time and load */
3341                 if ((0 != check_time()) || (0 != check_load()))
3342                 {
3343                         /* Warning */
3344                         if (closing_flag <= 2)
3345                         {
3346                                 /* Disturb */
3347                                 disturb(0, 1);
3348
3349                                 /* Count warnings */
3350                                 closing_flag++;
3351
3352                                 /* Message */
3353                                 msg_print(_("アングバンドへの門が閉じかかっています...", "The gates to ANGBAND are closing..."));
3354                                 msg_print(_("ゲームを終了するかセーブするかして下さい。", "Please finish up and/or save your game."));
3355
3356                         }
3357
3358                         /* Slam the gate */
3359                         else
3360                         {
3361                                 /* Message */
3362                                 msg_print(_("今、アングバンドへの門が閉ざされました。", "The gates to ANGBAND are now closed."));
3363
3364                                 /* Stop playing */
3365                                 p_ptr->playing = FALSE;
3366
3367                                 /* Leaving */
3368                                 p_ptr->leaving = TRUE;
3369                         }
3370                 }
3371         }
3372
3373         /*** Attempt timed autosave ***/
3374         if (autosave_t && autosave_freq && !p_ptr->inside_battle)
3375         {
3376                 if (!(turn % ((s32b)autosave_freq * TURNS_PER_TICK)))
3377                         do_cmd_save_game(TRUE);
3378         }
3379
3380         if (mon_fight && !ignore_unview)
3381         {
3382                 msg_print(_("何かが聞こえた。", "You hear noise."));
3383         }
3384
3385         /*** Handle the wilderness/town (sunshine) ***/
3386
3387         /* While in town/wilderness */
3388         if (!dun_level && !p_ptr->inside_quest && !p_ptr->inside_battle && !p_ptr->inside_arena)
3389         {
3390                 /* Hack -- Daybreak/Nighfall in town */
3391                 if (!(turn % ((TURNS_PER_TICK * TOWN_DAWN) / 2)))
3392                 {
3393                         bool dawn;
3394
3395                         /* Check for dawn */
3396                         dawn = (!(turn % (TURNS_PER_TICK * TOWN_DAWN)));
3397
3398                         /* Day breaks */
3399                         if (dawn)
3400                         {
3401                                 int y, x;
3402
3403                                 /* Message */
3404                                 msg_print(_("夜が明けた。", "The sun has risen."));
3405
3406                                 if (!p_ptr->wild_mode)
3407                                 {
3408                                         /* Hack -- Scan the town */
3409                                         for (y = 0; y < cur_hgt; y++)
3410                                         {
3411                                                 for (x = 0; x < cur_wid; x++)
3412                                                 {
3413                                                         /* Get the cave grid */
3414                                                         cave_type *c_ptr = &cave[y][x];
3415
3416                                                         /* Assume lit */
3417                                                         c_ptr->info |= (CAVE_GLOW);
3418
3419                                                         /* Hack -- Memorize lit grids if allowed */
3420                                                         if (view_perma_grids) c_ptr->info |= (CAVE_MARK);
3421
3422                                                         /* Hack -- Notice spot */
3423                                                         note_spot(y, x);
3424                                                 }
3425                                         }
3426                                 }
3427                         }
3428
3429                         /* Night falls */
3430                         else
3431                         {
3432                                 int y, x;
3433
3434                                 /* Message */
3435                                 msg_print(_("日が沈んだ。", "The sun has fallen."));
3436
3437                                 if (!p_ptr->wild_mode)
3438                                 {
3439                                         /* Hack -- Scan the town */
3440                                         for (y = 0; y < cur_hgt; y++)
3441                                         {
3442                                                 for (x = 0; x < cur_wid; x++)
3443                                                 {
3444                                                         /* Get the cave grid */
3445                                                         cave_type *c_ptr = &cave[y][x];
3446
3447                                                         /* Feature code (applying "mimic" field) */
3448                                                         feature_type *f_ptr = &f_info[get_feat_mimic(c_ptr)];
3449
3450                                                         if (!is_mirror_grid(c_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
3451                                                             !have_flag(f_ptr->flags, FF_ENTRANCE))
3452                                                         {
3453                                                                 /* Assume dark */
3454                                                                 c_ptr->info &= ~(CAVE_GLOW);
3455
3456                                                                 if (!have_flag(f_ptr->flags, FF_REMEMBER))
3457                                                                 {
3458                                                                         /* Forget the normal floor grid */
3459                                                                         c_ptr->info &= ~(CAVE_MARK);
3460
3461                                                                         /* Hack -- Notice spot */
3462                                                                         note_spot(y, x);
3463                                                                 }
3464                                                         }
3465                                                 }
3466
3467                                                 /* Glow deep lava and building entrances */
3468                                                 glow_deep_lava_and_bldg();
3469                                         }
3470                                 }
3471                         }
3472
3473                         /* Update the monsters */
3474                         p_ptr->update |= (PU_MONSTERS | PU_MON_LITE);
3475
3476                         /* Redraw map */
3477                         p_ptr->redraw |= (PR_MAP);
3478
3479                         /* Window stuff */
3480                         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3481
3482                         if (p_ptr->special_defense & NINJA_S_STEALTH)
3483                         {
3484                                 if (cave[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
3485                         }
3486                 }
3487         }
3488
3489         /* While in the dungeon (vanilla_town or lite_town mode only) */
3490         else if ((vanilla_town || (lite_town && !p_ptr->inside_quest && !p_ptr->inside_battle && !p_ptr->inside_arena)) && dun_level)
3491         {
3492                 /*** Shuffle the Storekeepers ***/
3493
3494                 /* Chance is only once a day (while in dungeon) */
3495                 if (!(turn % (TURNS_PER_TICK * STORE_TICKS)))
3496                 {
3497                         /* Sometimes, shuffle the shop-keepers */
3498                         if (one_in_(STORE_SHUFFLE))
3499                         {
3500                                 int n, i;
3501
3502                                 /* Pick a random shop (except home and museum) */
3503                                 do
3504                                 {
3505                                         n = randint0(MAX_STORES);
3506                                 }
3507                                 while ((n == STORE_HOME) || (n == STORE_MUSEUM));
3508
3509                                 /* Check every feature */
3510                                 for (i = 1; i < max_f_idx; i++)
3511                                 {
3512                                         /* Access the index */
3513                                         feature_type *f_ptr = &f_info[i];
3514
3515                                         /* Skip empty index */
3516                                         if (!f_ptr->name) continue;
3517
3518                                         /* Skip non-store features */
3519                                         if (!have_flag(f_ptr->flags, FF_STORE)) continue;
3520
3521                                         /* Verify store type */
3522                                         if (f_ptr->subtype == n)
3523                                         {
3524                                                 /* Message */
3525                                                 if (cheat_xtra) msg_format(_("%sの店主をシャッフルします。", "Shuffle a Shopkeeper of %s."), f_name + f_ptr->name);
3526
3527                                                 /* Shuffle it */
3528                                                 store_shuffle(n);
3529
3530                                                 break;
3531                                         }
3532                                 }
3533                         }
3534                 }
3535         }
3536
3537
3538         /*** Process the monsters ***/
3539
3540         /* Check for creature generation. */
3541         if (one_in_(d_info[dungeon_type].max_m_alloc_chance) &&
3542             !p_ptr->inside_arena && !p_ptr->inside_quest && !p_ptr->inside_battle)
3543         {
3544                 /* Make a new monster */
3545                 (void)alloc_monster(MAX_SIGHT + 5, 0);
3546         }
3547
3548         /* Hack -- Check for creature regeneration */
3549         if (!(turn % (TURNS_PER_TICK*10)) && !p_ptr->inside_battle) regen_monsters();
3550         if (!(turn % (TURNS_PER_TICK*3))) regen_captured_monsters();
3551
3552         if (!p_ptr->leaving)
3553         {
3554                 int i;
3555
3556                 /* Hack -- Process the counters of monsters if needed */
3557                 for (i = 0; i < MAX_MTIMED; i++)
3558                 {
3559                         if (mproc_max[i] > 0) process_monsters_mtimed(i);
3560                 }
3561         }
3562
3563
3564         /* Date changes */
3565         if (!hour && !min)
3566         {
3567                 if (min != prev_min)
3568                 {
3569                         do_cmd_write_nikki(NIKKI_HIGAWARI, 0, NULL);
3570                         determine_today_mon(FALSE);
3571                 }
3572         }
3573
3574         /*
3575          * Nightmare mode activates the TY_CURSE at midnight
3576          * Require exact minute -- Don't activate multiple times in a minute
3577          */
3578
3579         if (ironman_nightmare && (min != prev_min))
3580         {
3581
3582                 /* Every 15 minutes after 11:00 pm */
3583                 if ((hour == 23) && !(min % 15))
3584                 {
3585                         /* Disturbing */
3586                         disturb(0, 1);
3587
3588                         switch (min / 15)
3589                         {
3590                         case 0:
3591                                 msg_print(_("遠くで不気味な鐘の音が鳴った。", "You hear a distant bell toll ominously."));
3592                                 break;
3593
3594                         case 1:
3595                                 msg_print(_("遠くで鐘が二回鳴った。", "A distant bell sounds twice."));
3596                                 break;
3597
3598                         case 2:
3599                                 msg_print(_("遠くで鐘が三回鳴った。", "A distant bell sounds three times."));
3600                                 break;
3601
3602                         case 3:
3603                                 msg_print(_("遠くで鐘が四回鳴った。", "A distant bell tolls four times."));
3604                                 break;
3605                         }
3606                 }
3607
3608                 /* TY_CURSE activates at midnight! */
3609                 if (!hour && !min)
3610                 {
3611
3612                         disturb(1, 1);
3613                         msg_print(_("遠くで鐘が何回も鳴り、死んだような静けさの中へ消えていった。", "A distant bell tolls many times, fading into an deathly silence."));
3614
3615                         if (p_ptr->wild_mode)
3616                         {
3617                                 /* Go into large wilderness view */
3618                                 p_ptr->oldpy = randint1(MAX_HGT - 2);
3619                                 p_ptr->oldpx = randint1(MAX_WID - 2);
3620                                 change_wild_mode();
3621
3622                                 /* Give first move to monsters */
3623                                 p_ptr->energy_use = 100;
3624
3625                                 /* HACk -- set the encouter flag for the wilderness generation */
3626                                 generate_encounter = TRUE;
3627                         }
3628
3629                         invoking_midnight_curse = TRUE;
3630                 }
3631         }
3632
3633
3634         /*** Check the Food, and Regenerate ***/
3635
3636         if (!p_ptr->inside_battle)
3637         {
3638                 /* Digest quickly when gorged */
3639                 if (p_ptr->food >= PY_FOOD_MAX)
3640                 {
3641                         /* Digest a lot of food */
3642                         (void)set_food(p_ptr->food - 100);
3643                 }
3644
3645                 /* Digest normally -- Every 50 game turns */
3646                 else if (!(turn % (TURNS_PER_TICK*5)))
3647                 {
3648                         /* Basic digestion rate based on speed */
3649                         int digestion = SPEED_TO_ENERGY(p_ptr->pspeed);
3650
3651                         /* Regeneration takes more food */
3652                         if (p_ptr->regenerate)
3653                                 digestion += 20;
3654                         if (p_ptr->special_defense & (KAMAE_MASK | KATA_MASK))
3655                                 digestion += 20;
3656                         if (p_ptr->cursed & TRC_FAST_DIGEST)
3657                                 digestion += 30;
3658
3659                         /* Slow digestion takes less food */
3660                         if (p_ptr->slow_digest)
3661                                 digestion -= 5;
3662
3663                         /* Minimal digestion */
3664                         if (digestion < 1) digestion = 1;
3665                         /* Maximal digestion */
3666                         if (digestion > 100) digestion = 100;
3667
3668                         /* Digest some food */
3669                         (void)set_food(p_ptr->food - digestion);
3670                 }
3671
3672
3673                 /* Getting Faint */
3674                 if ((p_ptr->food < PY_FOOD_FAINT))
3675                 {
3676                         /* Faint occasionally */
3677                         if (!p_ptr->paralyzed && (randint0(100) < 10))
3678                         {
3679                                 /* Message */
3680                                 msg_print(_("あまりにも空腹で気絶してしまった。", "You faint from the lack of food."));
3681                                 disturb(1, 1);
3682
3683                                 /* Hack -- faint (bypass free action) */
3684                                 (void)set_paralyzed(p_ptr->paralyzed + 1 + randint0(5));
3685                         }
3686
3687                         /* Starve to death (slowly) */
3688                         if (p_ptr->food < PY_FOOD_STARVE)
3689                         {
3690                                 /* Calculate damage */
3691                                 HIT_POINT dam = (PY_FOOD_STARVE - p_ptr->food) / 10;
3692
3693                                 /* Take damage */
3694                                 if (!IS_INVULN()) take_hit(DAMAGE_LOSELIFE, dam, _("空腹", "starvation"), -1);
3695                         }
3696                 }
3697         }
3698
3699
3700
3701         /* Process timed damage and regeneration */
3702         process_world_aux_hp_and_sp();
3703
3704         /* Process timeout */
3705         process_world_aux_timeout();
3706
3707         /* Process light */
3708         process_world_aux_light();
3709
3710         /* Process mutation effects */
3711         process_world_aux_mutation();
3712
3713         /* Process curse effects */
3714         process_world_aux_curse();
3715
3716         /* Process recharging */
3717         process_world_aux_recharge();
3718
3719         /* Feel the inventory */
3720         sense_inventory1();
3721         sense_inventory2();
3722
3723         /* Involuntary Movement */
3724         process_world_aux_movement();
3725 }
3726
3727 /*!
3728  * @brief ウィザードモードへの導入処理
3729  * / Verify use of "wizard" mode
3730  * @return 実際にウィザードモードへ移行したらTRUEを返す。
3731  */
3732 static bool enter_wizard_mode(void)
3733 {
3734         /* Ask first time */
3735         if (!p_ptr->noscore)
3736         {
3737                 /* Wizard mode is not permitted */
3738                 if (!allow_debug_opts || arg_wizard)
3739                 {
3740                         msg_print(_("ウィザードモードは許可されていません。 ", "Wizard mode is not permitted."));
3741                         return FALSE;
3742                 }
3743
3744                 /* Mention effects */
3745                 msg_print(_("ウィザードモードはデバッグと実験のためのモードです。 ", "Wizard mode is for debugging and experimenting."));
3746                 msg_print(_("一度ウィザードモードに入るとスコアは記録されません。", "The game will not be scored if you enter wizard mode."));
3747                 msg_print(NULL);
3748
3749                 /* Verify request */
3750                 if (!get_check(_("本当にウィザードモードに入りたいのですか? ", "Are you sure you want to enter wizard mode? ")))
3751                 {
3752                         return (FALSE);
3753                 }
3754
3755                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("ウィザードモードに突入してスコアを残せなくなった。", "give up recording score to enter wizard mode."));
3756                 /* Mark savefile */
3757                 p_ptr->noscore |= 0x0002;
3758         }
3759
3760         /* Success */
3761         return (TRUE);
3762 }
3763
3764
3765 #ifdef ALLOW_WIZARD
3766
3767 /*!
3768  * @brief デバッグコマンドへの導入処理
3769  * / Verify use of "debug" commands
3770  * @return 実際にデバッグコマンドへ移行したらTRUEを返す。
3771  */
3772 static bool enter_debug_mode(void)
3773 {
3774         /* Ask first time */
3775         if (!p_ptr->noscore)
3776         {
3777                 /* Debug mode is not permitted */
3778                 if (!allow_debug_opts)
3779                 {
3780                         msg_print(_("デバッグコマンドは許可されていません。 ", "Use of debug command is not permitted."));
3781                         return FALSE;
3782                 }
3783
3784                 /* Mention effects */
3785                 msg_print(_("デバッグ・コマンドはデバッグと実験のためのコマンドです。 ", "The debug commands are for debugging and experimenting."));
3786                 msg_print(_("デバッグ・コマンドを使うとスコアは記録されません。", "The game will not be scored if you use debug commands."));
3787
3788                 msg_print(NULL);
3789
3790                 /* Verify request */
3791                 if (!get_check(_("本当にデバッグ・コマンドを使いますか? ", "Are you sure you want to use debug commands? ")))
3792                 {
3793                         return (FALSE);
3794                 }
3795
3796                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("デバッグモードに突入してスコアを残せなくなった。", "give up sending score to use debug commands."));
3797                 /* Mark savefile */
3798                 p_ptr->noscore |= 0x0008;
3799         }
3800
3801         /* Success */
3802         return (TRUE);
3803 }
3804
3805 /*
3806  * Hack -- Declare the Debug Routines
3807  */
3808 extern void do_cmd_debug(void);
3809
3810 #endif /* ALLOW_WIZARD */
3811
3812
3813 #ifdef ALLOW_BORG
3814
3815 /*!
3816  * @brief ボーグコマンドへの導入処理
3817  * / Verify use of "borg" commands
3818  * @return 実際にボーグコマンドへ移行したらTRUEを返す。
3819  */
3820 static bool enter_borg_mode(void)
3821 {
3822         /* Ask first time */
3823         if (!(p_ptr->noscore & 0x0010))
3824         {
3825                 /* Mention effects */
3826                 msg_print(_("ボーグ・コマンドはデバッグと実験のためのコマンドです。 ", "The borg commands are for debugging and experimenting."));
3827                 msg_print(_("ボーグ・コマンドを使うとスコアは記録されません。", "The game will not be scored if you use borg commands."));
3828
3829                 msg_print(NULL);
3830
3831                 /* Verify request */
3832                 if (!get_check(_("本当にボーグ・コマンドを使いますか? ", "Are you sure you want to use borg commands? ")))
3833                 {
3834                         return (FALSE);
3835                 }
3836
3837                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("ボーグ・コマンドを使用してスコアを残せなくなった。", "give up recording score to use borg commands."));
3838                 /* Mark savefile */
3839                 p_ptr->noscore |= 0x0010;
3840         }
3841
3842         /* Success */
3843         return (TRUE);
3844 }
3845
3846 /*
3847  * Hack -- Declare the Ben Borg
3848  */
3849 extern void do_cmd_borg(void);
3850
3851 #endif /* ALLOW_BORG */
3852
3853
3854 /*!
3855  * @brief プレイヤーから受けた入力コマンドの分岐処理。
3856  * / Parse and execute the current command Give "Warning" on illegal commands.
3857  * @todo XXX XXX XXX Make some "blocks"
3858  * @return なし
3859  */
3860 static void process_command(void)
3861 {
3862         COMMAND_CODE old_now_message = now_message;
3863
3864 #ifdef ALLOW_REPEAT /* TNB */
3865
3866         /* Handle repeating the last command */
3867         repeat_check();
3868
3869 #endif /* ALLOW_REPEAT -- TNB */
3870
3871         now_message = 0;
3872
3873         /* Sniper */
3874         if ((p_ptr->pclass == CLASS_SNIPER) && (p_ptr->concent))
3875                 reset_concent = TRUE;
3876
3877         /* Parse the command */
3878         switch (command_cmd)
3879         {
3880                 /* Ignore */
3881                 case ESCAPE:
3882                 case ' ':
3883                 {
3884                         break;
3885                 }
3886
3887                 /* Ignore return */
3888                 case '\r':
3889                 case '\n':
3890                 {
3891                         break;
3892                 }
3893
3894                 /*** Wizard Commands ***/
3895
3896                 /* Toggle Wizard Mode */
3897                 case KTRL('W'):
3898                 {
3899                         if (p_ptr->wizard)
3900                         {
3901                                 p_ptr->wizard = FALSE;
3902                                 msg_print(_("ウィザードモード解除。", "Wizard mode off."));
3903                         }
3904                         else if (enter_wizard_mode())
3905                         {
3906                                 p_ptr->wizard = TRUE;
3907                                 msg_print(_("ウィザードモード突入。", "Wizard mode on."));
3908                         }
3909
3910                         /* Update monsters */
3911                         p_ptr->update |= (PU_MONSTERS);
3912
3913                         /* Redraw "title" */
3914                         p_ptr->redraw |= (PR_TITLE);
3915
3916                         break;
3917                 }
3918
3919
3920 #ifdef ALLOW_WIZARD
3921
3922                 /* Special "debug" commands */
3923                 case KTRL('A'):
3924                 {
3925                         /* Enter debug mode */
3926                         if (enter_debug_mode())
3927                         {
3928                                 do_cmd_debug();
3929                         }
3930                         break;
3931                 }
3932
3933 #endif /* ALLOW_WIZARD */
3934
3935
3936 #ifdef ALLOW_BORG
3937
3938                 /* Special "borg" commands */
3939                 case KTRL('Z'):
3940                 {
3941                         /* Enter borg mode */
3942                         if (enter_borg_mode())
3943                         {
3944                                 if (!p_ptr->wild_mode) do_cmd_borg();
3945                         }
3946
3947                         break;
3948                 }
3949
3950 #endif /* ALLOW_BORG */
3951
3952
3953
3954                 /*** Inventory Commands ***/
3955
3956                 /* Wear/wield equipment */
3957                 case 'w':
3958                 {
3959                         if (!p_ptr->wild_mode) do_cmd_wield();
3960                         break;
3961                 }
3962
3963                 /* Take off equipment */
3964                 case 't':
3965                 {
3966                         if (!p_ptr->wild_mode) do_cmd_takeoff();
3967                         break;
3968                 }
3969
3970                 /* Drop an item */
3971                 case 'd':
3972                 {
3973                         if (!p_ptr->wild_mode) do_cmd_drop();
3974                         break;
3975                 }
3976
3977                 /* Destroy an item */
3978                 case 'k':
3979                 {
3980                         do_cmd_destroy();
3981                         break;
3982                 }
3983
3984                 /* Equipment list */
3985                 case 'e':
3986                 {
3987                         do_cmd_equip();
3988                         break;
3989                 }
3990
3991                 /* Inventory list */
3992                 case 'i':
3993                 {
3994                         do_cmd_inven();
3995                         break;
3996                 }
3997
3998
3999                 /*** Various commands ***/
4000
4001                 /* Identify an object */
4002                 case 'I':
4003                 {
4004                         do_cmd_observe();
4005                         break;
4006                 }
4007
4008                 /* Hack -- toggle windows */
4009                 case KTRL('I'):
4010                 {
4011                         toggle_inven_equip();
4012                         break;
4013                 }
4014
4015
4016                 /*** Standard "Movement" Commands ***/
4017
4018                 /* Alter a grid */
4019                 case '+':
4020                 {
4021                         if (!p_ptr->wild_mode) do_cmd_alter();
4022                         break;
4023                 }
4024
4025                 /* Dig a tunnel */
4026                 case 'T':
4027                 {
4028                         if (!p_ptr->wild_mode) do_cmd_tunnel();
4029                         break;
4030                 }
4031
4032                 /* Move (usually pick up things) */
4033                 case ';':
4034                 {
4035 #ifdef ALLOW_EASY_DISARM /* TNB */
4036
4037                         do_cmd_walk(FALSE);
4038
4039 #else /* ALLOW_EASY_DISARM -- TNB */
4040
4041                         do_cmd_walk(always_pickup);
4042
4043 #endif /* ALLOW_EASY_DISARM -- TNB */
4044
4045                         break;
4046                 }
4047
4048                 /* Move (usually do not pick up) */
4049                 case '-':
4050                 {
4051 #ifdef ALLOW_EASY_DISARM /* TNB */
4052
4053                         do_cmd_walk(TRUE);
4054
4055 #else /* ALLOW_EASY_DISARM -- TNB */
4056
4057                         do_cmd_walk(!always_pickup);
4058
4059 #endif /* ALLOW_EASY_DISARM -- TNB */
4060
4061                         break;
4062                 }
4063
4064
4065                 /*** Running, Resting, Searching, Staying */
4066
4067                 /* Begin Running -- Arg is Max Distance */
4068                 case '.':
4069                 {
4070                         if (!p_ptr->wild_mode) do_cmd_run();
4071                         break;
4072                 }
4073
4074                 /* Stay still (usually pick things up) */
4075                 case ',':
4076                 {
4077                         do_cmd_stay(always_pickup);
4078                         break;
4079                 }
4080
4081                 /* Stay still (usually do not pick up) */
4082                 case 'g':
4083                 {
4084                         do_cmd_stay(!always_pickup);
4085                         break;
4086                 }
4087
4088                 /* Rest -- Arg is time */
4089                 case 'R':
4090                 {
4091                         do_cmd_rest();
4092                         break;
4093                 }
4094
4095                 /* Search for traps/doors */
4096                 case 's':
4097                 {
4098                         do_cmd_search();
4099                         break;
4100                 }
4101
4102                 /* Toggle search mode */
4103                 case 'S':
4104                 {
4105                         if (p_ptr->action == ACTION_SEARCH) set_action(ACTION_NONE);
4106                         else set_action(ACTION_SEARCH);
4107                         break;
4108                 }
4109
4110
4111                 /*** Stairs and Doors and Chests and Traps ***/
4112
4113                 /* Enter store */
4114                 case SPECIAL_KEY_STORE:
4115                 {
4116                         if (!p_ptr->wild_mode) do_cmd_store();
4117                         break;
4118                 }
4119
4120                 /* Enter building -KMW- */
4121                 case SPECIAL_KEY_BUILDING:
4122                 {
4123                         if (!p_ptr->wild_mode) do_cmd_bldg();
4124                         break;
4125                 }
4126
4127                 /* Enter quest level -KMW- */
4128                 case SPECIAL_KEY_QUEST:
4129                 {
4130                         if (!p_ptr->wild_mode) do_cmd_quest();
4131                         break;
4132                 }
4133
4134                 /* Go up staircase */
4135                 case '<':
4136                 {
4137                         if (!p_ptr->wild_mode && !dun_level && !p_ptr->inside_arena && !p_ptr->inside_quest)
4138                         {
4139                                 if (vanilla_town) break;
4140
4141                                 if (ambush_flag)
4142                                 {
4143                                         msg_print(_("襲撃から逃げるにはマップの端まで移動しなければならない。", "To flee the ambush you have to reach the edge of the map."));
4144                                         break;
4145                                 }
4146
4147                                 if (p_ptr->food < PY_FOOD_WEAK)
4148                                 {
4149                                         msg_print(_("その前に食事をとらないと。", "You must eat something here."));
4150                                         break;
4151                                 }
4152
4153                                 change_wild_mode();
4154                         }
4155                         else
4156                                 do_cmd_go_up();
4157                         break;
4158                 }
4159
4160                 /* Go down staircase */
4161                 case '>':
4162                 {
4163                         if (p_ptr->wild_mode)
4164                                 change_wild_mode();
4165                         else
4166                                 do_cmd_go_down();
4167
4168                         break;
4169                 }
4170
4171                 /* Open a door or chest */
4172                 case 'o':
4173                 {
4174                         if (!p_ptr->wild_mode) do_cmd_open();
4175                         break;
4176                 }
4177
4178                 /* Close a door */
4179                 case 'c':
4180                 {
4181                         if (!p_ptr->wild_mode) do_cmd_close();
4182                         break;
4183                 }
4184
4185                 /* Jam a door with spikes */
4186                 case 'j':
4187                 {
4188                         if (!p_ptr->wild_mode) do_cmd_spike();
4189                         break;
4190                 }
4191
4192                 /* Bash a door */
4193                 case 'B':
4194                 {
4195                         if (!p_ptr->wild_mode) do_cmd_bash();
4196                         break;
4197                 }
4198
4199                 /* Disarm a trap or chest */
4200                 case 'D':
4201                 {
4202                         if (!p_ptr->wild_mode) do_cmd_disarm();
4203                         break;
4204                 }
4205
4206
4207                 /*** Magic and Prayers ***/
4208
4209                 /* Gain new spells/prayers */
4210                 case 'G':
4211                 {
4212                         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
4213                                 msg_print(_("呪文を学習する必要はない!", "You don't have to learn spells!"));
4214                         else if (p_ptr->pclass == CLASS_SAMURAI)
4215                                 do_cmd_gain_hissatsu();
4216                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4217                                 gain_magic();
4218                         else
4219                                 do_cmd_study();
4220                         break;
4221                 }
4222
4223                 /* Browse a book */
4224                 case 'b':
4225                 {
4226                         if ( (p_ptr->pclass == CLASS_MINDCRAFTER) ||
4227                              (p_ptr->pclass == CLASS_BERSERKER) ||
4228                              (p_ptr->pclass == CLASS_NINJA) ||
4229                              (p_ptr->pclass == CLASS_MIRROR_MASTER) 
4230                              ) do_cmd_mind_browse();
4231                         else if (p_ptr->pclass == CLASS_SMITH)
4232                                 do_cmd_kaji(TRUE);
4233                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4234                                 do_cmd_magic_eater(TRUE, FALSE);
4235                         else if (p_ptr->pclass == CLASS_SNIPER)
4236                                 do_cmd_snipe_browse();
4237                         else do_cmd_browse();
4238                         break;
4239                 }
4240
4241                 /* Cast a spell */
4242                 case 'm':
4243                 {
4244                         /* -KMW- */
4245                         if (!p_ptr->wild_mode)
4246                         {
4247                                 if ((p_ptr->pclass == CLASS_WARRIOR) || (p_ptr->pclass == CLASS_ARCHER) || (p_ptr->pclass == CLASS_CAVALRY))
4248                                 {
4249                                         msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
4250                                 }
4251                                 else if (dun_level && (d_info[dungeon_type].flags1 & DF1_NO_MAGIC) && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
4252                                 {
4253                                         msg_print(_("ダンジョンが魔法を吸収した!", "The dungeon absorbs all attempted magic!"));
4254                                         msg_print(NULL);
4255                                 }
4256                                 else if (p_ptr->anti_magic && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
4257                                 {
4258                                         cptr which_power = _("魔法", "magic");
4259                                         if (p_ptr->pclass == CLASS_MINDCRAFTER)
4260                                                 which_power = _("超能力", "psionic powers");
4261                                         else if (p_ptr->pclass == CLASS_IMITATOR)
4262                                                 which_power = _("ものまね", "imitation");
4263                                         else if (p_ptr->pclass == CLASS_SAMURAI)
4264                                                 which_power = _("必殺剣", "hissatsu");
4265                                         else if (p_ptr->pclass == CLASS_MIRROR_MASTER)
4266                                                 which_power = _("鏡魔法", "mirror magic");
4267                                         else if (p_ptr->pclass == CLASS_NINJA)
4268                                                 which_power = _("忍術", "ninjutsu");
4269                                         else if (mp_ptr->spell_book == TV_LIFE_BOOK)
4270                                                 which_power = _("祈り", "prayer");
4271
4272                                         msg_format(_("反魔法バリアが%sを邪魔した!", "An anti-magic shell disrupts your %s!"), which_power);
4273                                         p_ptr->energy_use = 0;
4274                                 }
4275                                 else if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER))
4276                                 {
4277                                         msg_format(_("狂戦士化していて頭が回らない!", "You cannot think directly!"));
4278                                         p_ptr->energy_use = 0;
4279                                 }
4280                                 else
4281                                 {
4282                                         if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
4283                                             (p_ptr->pclass == CLASS_BERSERKER) ||
4284                                             (p_ptr->pclass == CLASS_NINJA) ||
4285                                             (p_ptr->pclass == CLASS_MIRROR_MASTER)
4286                                             )
4287                                                 do_cmd_mind();
4288                                         else if (p_ptr->pclass == CLASS_IMITATOR)
4289                                                 do_cmd_mane(FALSE);
4290                                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4291                                                 do_cmd_magic_eater(FALSE, FALSE);
4292                                         else if (p_ptr->pclass == CLASS_SAMURAI)
4293                                                 do_cmd_hissatsu();
4294                                         else if (p_ptr->pclass == CLASS_BLUE_MAGE)
4295                                                 do_cmd_cast_learned();
4296                                         else if (p_ptr->pclass == CLASS_SMITH)
4297                                                 do_cmd_kaji(FALSE);
4298                                         else if (p_ptr->pclass == CLASS_SNIPER)
4299                                                 do_cmd_snipe();
4300                                         else
4301                                                 do_cmd_cast();
4302                                 }
4303                         }
4304                         break;
4305                 }
4306
4307                 /* Issue a pet command */
4308                 case 'p':
4309                 {
4310                         if (!p_ptr->wild_mode) do_cmd_pet();
4311                         break;
4312                 }
4313
4314                 /*** Use various objects ***/
4315
4316                 /* Inscribe an object */
4317                 case '{':
4318                 {
4319                         do_cmd_inscribe();
4320                         break;
4321                 }
4322
4323                 /* Uninscribe an object */
4324                 case '}':
4325                 {
4326                         do_cmd_uninscribe();
4327                         break;
4328                 }
4329
4330                 /* Activate an artifact */
4331                 case 'A':
4332                 {
4333                         if (!p_ptr->wild_mode)
4334                         {
4335                         if (!p_ptr->inside_arena)
4336                                 do_cmd_activate();
4337                         else
4338                         {
4339                                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
4340                                 msg_print(NULL);
4341                         }
4342                         }
4343                         break;
4344                 }
4345
4346                 /* Eat some food */
4347                 case 'E':
4348                 {
4349                         do_cmd_eat_food();
4350                         break;
4351                 }
4352
4353                 /* Fuel your lantern/torch */
4354                 case 'F':
4355                 {
4356                         do_cmd_refill();
4357                         break;
4358                 }
4359
4360                 /* Fire an item */
4361                 case 'f':
4362                 {
4363                         if (!p_ptr->wild_mode) do_cmd_fire();
4364                         break;
4365                 }
4366
4367                 /* Throw an item */
4368                 case 'v':
4369                 {
4370                         if (!p_ptr->wild_mode) do_cmd_throw(1, FALSE, -1);
4371                         break;
4372                 }
4373
4374                 /* Aim a wand */
4375                 case 'a':
4376                 {
4377                         if (!p_ptr->wild_mode)
4378                         {
4379                         if (!p_ptr->inside_arena)
4380                                 do_cmd_aim_wand();
4381                         else
4382                         {
4383                                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
4384                                 msg_print(NULL);
4385                         }
4386                         }
4387                         break;
4388                 }
4389
4390                 /* Zap a rod */
4391                 case 'z':
4392                 {
4393                         if (!p_ptr->wild_mode)
4394                         {
4395                         if (p_ptr->inside_arena)
4396                         {
4397                                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
4398                                 msg_print(NULL);
4399                         }
4400                         else if (use_command && rogue_like_commands)
4401                         {
4402                                 do_cmd_use();
4403                         }
4404                         else
4405                         {
4406                                 do_cmd_zap_rod();
4407                         }
4408                         }
4409                         break;
4410                 }
4411
4412                 /* Quaff a potion */
4413                 case 'q':
4414                 {
4415                         if (!p_ptr->wild_mode)
4416                         {
4417                         if (!p_ptr->inside_arena)
4418                                 do_cmd_quaff_potion();
4419                         else
4420                         {
4421                                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
4422                                 msg_print(NULL);
4423                         }
4424                         }
4425                         break;
4426                 }
4427
4428                 /* Read a scroll */
4429                 case 'r':
4430                 {
4431                         if (!p_ptr->wild_mode)
4432                         {
4433                         if (!p_ptr->inside_arena)
4434                                 do_cmd_read_scroll();
4435                         else
4436                         {
4437                                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
4438                                 msg_print(NULL);
4439                         }
4440                         }
4441                         break;
4442                 }
4443
4444                 /* Use a staff */
4445                 case 'u':
4446                 {
4447                         if (!p_ptr->wild_mode)
4448                         {
4449                         if (p_ptr->inside_arena)
4450                         {
4451                                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
4452                                 msg_print(NULL);
4453                         }
4454                         else if (use_command && !rogue_like_commands)
4455                         {
4456                                 do_cmd_use();
4457                         }
4458                         else
4459                                 do_cmd_use_staff();
4460                         }
4461                         break;
4462                 }
4463
4464                 /* Use racial power */
4465                 case 'U':
4466                 {
4467                         if (!p_ptr->wild_mode) do_cmd_racial_power();
4468                         break;
4469                 }
4470
4471
4472                 /*** Looking at Things (nearby or on map) ***/
4473
4474                 /* Full dungeon map */
4475                 case 'M':
4476                 {
4477                         do_cmd_view_map();
4478                         break;
4479                 }
4480
4481                 /* Locate player on map */
4482                 case 'L':
4483                 {
4484                         do_cmd_locate();
4485                         break;
4486                 }
4487
4488                 /* Look around */
4489                 case 'l':
4490                 {
4491                         do_cmd_look();
4492                         break;
4493                 }
4494
4495                 /* Target monster or location */
4496                 case '*':
4497                 {
4498                         if (!p_ptr->wild_mode) do_cmd_target();
4499                         break;
4500                 }
4501
4502
4503
4504                 /*** Help and Such ***/
4505
4506                 /* Help */
4507                 case '?':
4508                 {
4509                         do_cmd_help();
4510                         break;
4511                 }
4512
4513                 /* Identify symbol */
4514                 case '/':
4515                 {
4516                         do_cmd_query_symbol();
4517                         break;
4518                 }
4519
4520                 /* Character description */
4521                 case 'C':
4522                 {
4523                         do_cmd_change_name();
4524                         break;
4525                 }
4526
4527
4528                 /*** System Commands ***/
4529
4530                 /* Hack -- User interface */
4531                 case '!':
4532                 {
4533                         (void)Term_user(0);
4534                         break;
4535                 }
4536
4537                 /* Single line from a pref file */
4538                 case '"':
4539                 {
4540                         do_cmd_pref();
4541                         break;
4542                 }
4543
4544                 case '$':
4545                 {
4546                         do_cmd_reload_autopick();
4547                         break;
4548                 }
4549
4550                 case '_':
4551                 {
4552                         do_cmd_edit_autopick();
4553                         break;
4554                 }
4555
4556                 /* Interact with macros */
4557                 case '@':
4558                 {
4559                         do_cmd_macros();
4560                         break;
4561                 }
4562
4563                 /* Interact with visuals */
4564                 case '%':
4565                 {
4566                         do_cmd_visuals();
4567                         do_cmd_redraw();
4568                         break;
4569                 }
4570
4571                 /* Interact with colors */
4572                 case '&':
4573                 {
4574                         do_cmd_colors();
4575                         do_cmd_redraw();
4576                         break;
4577                 }
4578
4579                 /* Interact with options */
4580                 case '=':
4581                 {
4582                         do_cmd_options();
4583                         (void)combine_and_reorder_home(STORE_HOME);
4584                         do_cmd_redraw();
4585                         break;
4586                 }
4587
4588                 /*** Misc Commands ***/
4589
4590                 /* Take notes */
4591                 case ':':
4592                 {
4593                         do_cmd_note();
4594                         break;
4595                 }
4596
4597                 /* Version info */
4598                 case 'V':
4599                 {
4600                         do_cmd_version();
4601                         break;
4602                 }
4603
4604                 /* Repeat level feeling */
4605                 case KTRL('F'):
4606                 {
4607                         if (!p_ptr->wild_mode) do_cmd_feeling();
4608                         break;
4609                 }
4610
4611                 /* Show previous message */
4612                 case KTRL('O'):
4613                 {
4614                         do_cmd_message_one();
4615                         break;
4616                 }
4617
4618                 /* Show previous messages */
4619                 case KTRL('P'):
4620                 {
4621                         do_cmd_messages(old_now_message);
4622                         break;
4623                 }
4624
4625                 /* Show quest status -KMW- */
4626                 case KTRL('Q'):
4627                 {
4628                         do_cmd_checkquest();
4629                         break;
4630                 }
4631
4632                 /* Redraw the screen */
4633                 case KTRL('R'):
4634                 {
4635                         now_message = old_now_message;
4636                         do_cmd_redraw();
4637                         break;
4638                 }
4639
4640 #ifndef VERIFY_SAVEFILE
4641
4642                 /* Hack -- Save and don't quit */
4643                 case KTRL('S'):
4644                 {
4645                         do_cmd_save_game(FALSE);
4646                         break;
4647                 }
4648
4649 #endif /* VERIFY_SAVEFILE */
4650
4651                 case KTRL('T'):
4652                 {
4653                         do_cmd_time();
4654                         break;
4655                 }
4656
4657                 /* Save and quit */
4658                 case KTRL('X'):
4659                 case SPECIAL_KEY_QUIT:
4660                 {
4661                         do_cmd_save_and_exit();
4662                         break;
4663                 }
4664
4665                 /* Quit (commit suicide) */
4666                 case 'Q':
4667                 {
4668                         do_cmd_suicide();
4669                         break;
4670                 }
4671
4672                 case '|':
4673                 {
4674                         do_cmd_nikki();
4675                         break;
4676                 }
4677
4678                 /* Check artifacts, uniques, objects */
4679                 case '~':
4680                 {
4681                         do_cmd_knowledge();
4682                         break;
4683                 }
4684
4685                 /* Load "screen dump" */
4686                 case '(':
4687                 {
4688                         do_cmd_load_screen();
4689                         break;
4690                 }
4691
4692                 /* Save "screen dump" */
4693                 case ')':
4694                 {
4695                         do_cmd_save_screen();
4696                         break;
4697                 }
4698
4699                 /* Record/stop "Movie" */
4700                 case ']':
4701                 {
4702                         prepare_movie_hooks();
4703                         break;
4704                 }
4705
4706                 /* Make random artifact list */
4707                 case KTRL('V'):
4708                 {
4709                         spoil_random_artifact("randifact.txt");
4710                         break;
4711                 }
4712
4713 #ifdef TRAVEL
4714                 case '`':
4715                 {
4716                         if (!p_ptr->wild_mode) do_cmd_travel();
4717                         if (p_ptr->special_defense & KATA_MUSOU)
4718                         {
4719                                 set_action(ACTION_NONE);
4720                         }
4721                         break;
4722                 }
4723 #endif
4724
4725                 /* Hack -- Unknown command */
4726                 default:
4727                 {
4728                         if (flush_failure) flush();
4729                         if (one_in_(2))
4730                         {
4731                                 char error_m[1024];
4732                                 sound(SOUND_ILLEGAL);
4733                                 if (!get_rnd_line(_("error_j.txt", "error.txt"), 0, error_m))
4734                                         msg_print(error_m);
4735                         }
4736                         else
4737                         {
4738                                 prt(_(" '?' でヘルプが表示されます。", "Type '?' for help."), 0, 0);
4739                         }
4740
4741                         break;
4742                 }
4743         }
4744         if (!p_ptr->energy_use && !now_message)
4745                 now_message = old_now_message;
4746 }
4747
4748 /*!
4749  * @brief モンスター種族が釣れる種族かどうかを判定する。
4750  * @param r_idx 判定したいモンスター種族のID
4751  * @return 釣れる対象ならばTRUEを返す
4752  */
4753 static bool monster_tsuri(MONRACE_IDX r_idx)
4754 {
4755         monster_race *r_ptr = &r_info[r_idx];
4756
4757         if ((r_ptr->flags7 & RF7_AQUATIC) && !(r_ptr->flags1 & RF1_UNIQUE) && my_strchr("Jjlw", r_ptr->d_char))
4758                 return TRUE;
4759         else
4760                 return FALSE;
4761 }
4762
4763
4764 /*!
4765  * @brief アイテムの所持種類数が超えた場合にアイテムを床に落とす処理 / Hack -- Pack Overflow
4766  * @return なし
4767  */
4768 static void pack_overflow(void)
4769 {
4770         if (inventory[INVEN_PACK].k_idx)
4771         {
4772                 char o_name[MAX_NLEN];
4773                 object_type *o_ptr;
4774
4775                 /* Is auto-destroy done? */
4776                 notice_stuff();
4777                 if (!inventory[INVEN_PACK].k_idx) return;
4778
4779                 /* Access the slot to be dropped */
4780                 o_ptr = &inventory[INVEN_PACK];
4781
4782                 /* Disturbing */
4783                 disturb(0, 1);
4784
4785                 /* Warning */
4786                 msg_print(_("ザックからアイテムがあふれた!", "Your pack overflows!"));
4787
4788                 /* Describe */
4789                 object_desc(o_name, o_ptr, 0);
4790
4791                 /* Message */
4792                 msg_format(_("%s(%c)を落とした。", "You drop %s (%c)."), o_name, index_to_label(INVEN_PACK));
4793
4794                 /* Drop it (carefully) near the player */
4795                 (void)drop_near(o_ptr, 0, p_ptr->y, p_ptr->x);
4796
4797                 /* Modify, Describe, Optimize */
4798                 inven_item_increase(INVEN_PACK, -255);
4799                 inven_item_describe(INVEN_PACK);
4800                 inven_item_optimize(INVEN_PACK);
4801
4802                 /* Handle "p_ptr->notice" */
4803                 notice_stuff();
4804
4805                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
4806                 handle_stuff();
4807         }
4808 }
4809
4810 /*!
4811  * @brief プレイヤーの行動エネルギーが充填される(=プレイヤーのターンが回る)毎に行われる処理  / process the effects per 100 energy at player speed.
4812  * @return なし
4813  */
4814 static void process_upkeep_with_speed(void)
4815 {
4816         /* Give the player some energy */
4817         if (!load && p_ptr->enchant_energy_need > 0 && !p_ptr->leaving)
4818         {
4819                 p_ptr->enchant_energy_need -= SPEED_TO_ENERGY(p_ptr->pspeed);
4820         }
4821         
4822         /* No turn yet */
4823         if (p_ptr->enchant_energy_need > 0) return;
4824         
4825         while (p_ptr->enchant_energy_need <= 0)
4826         {
4827                 /* Handle the player song */
4828                 if (!load) check_music();
4829
4830                 /* Hex - Handle the hex spells */
4831                 if (!load) check_hex();
4832                 if (!load) revenge_spell();
4833                 
4834                 /* There is some randomness of needed energy */
4835                 p_ptr->enchant_energy_need += ENERGY_NEED();
4836         }
4837 }
4838
4839 /*!
4840  * @brief プレイヤーの行動処理 / Process the player
4841  * @return なし
4842  * @note
4843  * Notice the annoying code to handle "pack overflow", which\n
4844  * must come first just in case somebody manages to corrupt\n
4845  * the savefiles by clever use of menu commands or something.\n
4846  */
4847 static void process_player(void)
4848 {
4849         IDX i;
4850
4851         /*** Apply energy ***/
4852
4853         if (hack_mutation)
4854         {
4855                 msg_print(_("何か変わった気がする!", "You feel different!"));
4856
4857                 (void)gain_random_mutation(0);
4858                 hack_mutation = FALSE;
4859         }
4860
4861         if (invoking_midnight_curse)
4862         {
4863                 int count = 0;
4864                 activate_ty_curse(FALSE, &count);
4865                 invoking_midnight_curse = FALSE;
4866         }
4867
4868         if (p_ptr->inside_battle)
4869         {
4870                 for(i = 1; i < m_max; i++)
4871                 {
4872                         monster_type *m_ptr = &m_list[i];
4873
4874                         if (!m_ptr->r_idx) continue;
4875
4876                         /* Hack -- Detect monster */
4877                         m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
4878
4879                         /* Update the monster */
4880                         update_mon(i, FALSE);
4881                 }
4882                 prt_time();
4883         }
4884
4885         /* Give the player some energy */
4886         else if (!(load && p_ptr->energy_need <= 0))
4887         {
4888                 p_ptr->energy_need -= SPEED_TO_ENERGY(p_ptr->pspeed);
4889         }
4890
4891         /* No turn yet */
4892         if (p_ptr->energy_need > 0) return;
4893         if (!command_rep) prt_time();
4894
4895         /*** Check for interupts ***/
4896
4897         /* Complete resting */
4898         if (resting < 0)
4899         {
4900                 /* Basic resting */
4901                 if (resting == COMMAND_ARG_REST_FULL_HEALING)
4902                 {
4903                         /* Stop resting */
4904                         if ((p_ptr->chp == p_ptr->mhp) &&
4905                             (p_ptr->csp >= p_ptr->msp))
4906                         {
4907                                 set_action(ACTION_NONE);
4908                         }
4909                 }
4910
4911                 /* Complete resting */
4912                 else if (resting == COMMAND_ARG_REST_UNTIL_DONE)
4913                 {
4914                         /* Stop resting */
4915                         if ((p_ptr->chp == p_ptr->mhp) &&
4916                             (p_ptr->csp >= p_ptr->msp) &&
4917                             !p_ptr->blind && !p_ptr->confused &&
4918                             !p_ptr->poisoned && !p_ptr->afraid &&
4919                             !p_ptr->stun && !p_ptr->cut &&
4920                             !p_ptr->slow && !p_ptr->paralyzed &&
4921                             !p_ptr->image && !p_ptr->word_recall &&
4922                             !p_ptr->alter_reality)
4923                         {
4924                                 set_action(ACTION_NONE);
4925                         }
4926                 }
4927         }
4928
4929         if (p_ptr->action == ACTION_FISH)
4930         {
4931                 /* Delay */
4932                 Term_xtra(TERM_XTRA_DELAY, 10);
4933                 if (one_in_(1000))
4934                 {
4935                         MONRACE_IDX r_idx;
4936                         bool success = FALSE;
4937                         get_mon_num_prep(monster_tsuri,NULL);
4938                         r_idx = get_mon_num(dun_level ? dun_level : wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level);
4939                         msg_print(NULL);
4940                         if (r_idx && one_in_(2))
4941                         {
4942                                 int y, x;
4943                                 y = p_ptr->y+ddy[tsuri_dir];
4944                                 x = p_ptr->x+ddx[tsuri_dir];
4945                                 if (place_monster_aux(0, y, x, r_idx, PM_NO_KAGE))
4946                                 {
4947                                         char m_name[80];
4948                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
4949                                         msg_format(_("%sが釣れた!", "You have a good catch!"), m_name);
4950                                         success = TRUE;
4951                                 }
4952                         }
4953                         if (!success)
4954                         {
4955                                 msg_print(_("餌だけ食われてしまった!くっそ~!", "Damn!  The fish stole your bait!"));
4956                         }
4957                         disturb(0, 1);
4958                 }
4959         }
4960
4961         /* Handle "abort" */
4962         if (check_abort)
4963         {
4964                 /* Check for "player abort" (semi-efficiently for resting) */
4965                 if (running || travel.run || command_rep || (p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH))
4966                 {
4967                         /* Do not wait */
4968                         inkey_scan = TRUE;
4969
4970                         /* Check for a key */
4971                         if (inkey())
4972                         {
4973                                 /* Flush input */
4974                                 flush();
4975
4976                                 /* Disturb */
4977                                 disturb(0, 1);
4978
4979                                 /* Hack -- Show a Message */
4980                                 msg_print(_("中断しました。", "Canceled."));
4981                         }
4982                 }
4983         }
4984
4985         if (p_ptr->riding && !p_ptr->confused && !p_ptr->blind)
4986         {
4987                 monster_type *m_ptr = &m_list[p_ptr->riding];
4988                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4989
4990                 if (MON_CSLEEP(m_ptr))
4991                 {
4992                         char m_name[80];
4993
4994                         /* Recover fully */
4995                         (void)set_monster_csleep(p_ptr->riding, 0);
4996
4997                         /* Acquire the monster name */
4998                         monster_desc(m_name, m_ptr, 0);
4999                         msg_format(_("%^sを起こした。", "You have waked %s up."), m_name);
5000                 }
5001
5002                 if (MON_STUNNED(m_ptr))
5003                 {
5004                         /* Hack -- Recover from stun */
5005                         if (set_monster_stunned(p_ptr->riding,
5006                                 (randint0(r_ptr->level) < p_ptr->skill_exp[GINOU_RIDING]) ? 0 : (MON_STUNNED(m_ptr) - 1)))
5007                         {
5008                                 char m_name[80];
5009
5010                                 /* Acquire the monster name */
5011                                 monster_desc(m_name, m_ptr, 0);
5012
5013                                 /* Dump a message */
5014                                 msg_format(_("%^sを朦朧状態から立ち直らせた。", "%^s is no longer stunned."), m_name);
5015                         }
5016                 }
5017
5018                 if (MON_CONFUSED(m_ptr))
5019                 {
5020                         /* Hack -- Recover from confusion */
5021                         if (set_monster_confused(p_ptr->riding,
5022                                 (randint0(r_ptr->level) < p_ptr->skill_exp[GINOU_RIDING]) ? 0 : (MON_CONFUSED(m_ptr) - 1)))
5023                         {
5024                                 char m_name[80];
5025
5026                                 /* Acquire the monster name */
5027                                 monster_desc(m_name, m_ptr, 0);
5028
5029                                 /* Dump a message */
5030                                 msg_format(_("%^sを混乱状態から立ち直らせた。", "%^s is no longer confused."), m_name);
5031                         }
5032                 }
5033
5034                 if (MON_MONFEAR(m_ptr))
5035                 {
5036                         /* Hack -- Recover from fear */
5037                         if (set_monster_monfear(p_ptr->riding,
5038                                 (randint0(r_ptr->level) < p_ptr->skill_exp[GINOU_RIDING]) ? 0 : (MON_MONFEAR(m_ptr) - 1)))
5039                         {
5040                                 char m_name[80];
5041
5042                                 /* Acquire the monster name */
5043                                 monster_desc(m_name, m_ptr, 0);
5044
5045                                 /* Dump a message */
5046                                 msg_format(_("%^sを恐怖から立ち直らせた。", "%^s is no longer fear."), m_name);
5047                         }
5048                 }
5049
5050                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5051                 handle_stuff();
5052         }
5053         
5054         load = FALSE;
5055
5056         /* Fast */
5057         if (p_ptr->lightspeed)
5058         {
5059                 (void)set_lightspeed(p_ptr->lightspeed - 1, TRUE);
5060         }
5061         if ((p_ptr->pclass == CLASS_FORCETRAINER) && P_PTR_KI)
5062         {
5063                 if (P_PTR_KI < 40)
5064                 {
5065                         P_PTR_KI = 0;
5066                 }
5067                 else P_PTR_KI -= 40;
5068                 p_ptr->update |= (PU_BONUS);
5069         }
5070         if (p_ptr->action == ACTION_LEARN)
5071         {
5072                 s32b cost = 0L;
5073                 u32b cost_frac = (p_ptr->msp + 30L) * 256L;
5074
5075                 /* Convert the unit (1/2^16) to (1/2^32) */
5076                 s64b_LSHIFT(cost, cost_frac, 16);
5077
5078  
5079                 if (s64b_cmp(p_ptr->csp, p_ptr->csp_frac, cost, cost_frac) < 0)
5080                 {
5081                         /* Mana run out */
5082                         p_ptr->csp = 0;
5083                         p_ptr->csp_frac = 0;
5084                         set_action(ACTION_NONE);
5085                 }
5086                 else
5087                 {
5088                         /* Reduce mana */
5089                         s64b_sub(&(p_ptr->csp), &(p_ptr->csp_frac), cost, cost_frac);
5090                 }
5091                 p_ptr->redraw |= PR_MANA;
5092         }
5093
5094         if (p_ptr->special_defense & KATA_MASK)
5095         {
5096                 if (p_ptr->special_defense & KATA_MUSOU)
5097                 {
5098                         if (p_ptr->csp < 3)
5099                         {
5100                                 set_action(ACTION_NONE);
5101                         }
5102                         else
5103                         {
5104                                 p_ptr->csp -= 2;
5105                                 p_ptr->redraw |= (PR_MANA);
5106                         }
5107                 }
5108         }
5109
5110         /*** Handle actual user input ***/
5111
5112         /* Repeat until out of energy */
5113         while (p_ptr->energy_need <= 0)
5114         {
5115                 p_ptr->window |= PW_PLAYER;
5116                 p_ptr->sutemi = FALSE;
5117                 p_ptr->counter = FALSE;
5118                 now_damaged = FALSE;
5119
5120                 /* Handle "p_ptr->notice" */
5121                 notice_stuff();
5122
5123                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5124                 handle_stuff();
5125
5126                 /* Place the cursor on the player */
5127                 move_cursor_relative(p_ptr->y, p_ptr->x);
5128
5129                 /* Refresh (optional) */
5130                 if (fresh_before) Term_fresh();
5131
5132
5133                 /* Hack -- Pack Overflow */
5134                 pack_overflow();
5135
5136
5137                 /* Hack -- cancel "lurking browse mode" */
5138                 if (!command_new) command_see = FALSE;
5139
5140
5141                 /* Assume free turn */
5142                 p_ptr->energy_use = 0;
5143
5144
5145                 if (p_ptr->inside_battle)
5146                 {
5147                         /* Place the cursor on the player */
5148                         move_cursor_relative(p_ptr->y, p_ptr->x);
5149
5150                         command_cmd = SPECIAL_KEY_BUILDING;
5151
5152                         /* Process the command */
5153                         process_command();
5154                 }
5155
5156                 /* Paralyzed or Knocked Out */
5157                 else if (p_ptr->paralyzed || (p_ptr->stun >= 100))
5158                 {
5159                         /* Take a turn */
5160                         p_ptr->energy_use = 100;
5161                 }
5162
5163                 /* Resting */
5164                 else if (p_ptr->action == ACTION_REST)
5165                 {
5166                         /* Timed rest */
5167                         if (resting > 0)
5168                         {
5169                                 /* Reduce rest count */
5170                                 resting--;
5171
5172                                 if (!resting) set_action(ACTION_NONE);
5173
5174                                 /* Redraw the state */
5175                                 p_ptr->redraw |= (PR_STATE);
5176                         }
5177
5178                         /* Take a turn */
5179                         p_ptr->energy_use = 100;
5180                 }
5181
5182                 /* Fishing */
5183                 else if (p_ptr->action == ACTION_FISH)
5184                 {
5185                         /* Take a turn */
5186                         p_ptr->energy_use = 100;
5187                 }
5188
5189                 /* Running */
5190                 else if (running)
5191                 {
5192                         /* Take a step */
5193                         run_step(0);
5194                 }
5195
5196 #ifdef TRAVEL
5197                 /* Traveling */
5198                 else if (travel.run)
5199                 {
5200                         /* Take a step */
5201                         travel_step();
5202                 }
5203 #endif
5204
5205                 /* Repeated command */
5206                 else if (command_rep)
5207                 {
5208                         /* Count this execution */
5209                         command_rep--;
5210
5211                         /* Redraw the state */
5212                         p_ptr->redraw |= (PR_STATE);
5213
5214                         /* Redraw stuff */
5215                         redraw_stuff();
5216
5217                         /* Hack -- Assume messages were seen */
5218                         msg_flag = FALSE;
5219
5220                         /* Clear the top line */
5221                         prt("", 0, 0);
5222
5223                         /* Process the command */
5224                         process_command();
5225                 }
5226
5227                 /* Normal command */
5228                 else
5229                 {
5230                         /* Place the cursor on the player */
5231                         move_cursor_relative(p_ptr->y, p_ptr->x);
5232
5233                         can_save = TRUE;
5234                         /* Get a command (normal) */
5235                         request_command(FALSE);
5236                         can_save = FALSE;
5237
5238                         /* Process the command */
5239                         process_command();
5240                 }
5241
5242
5243                 /* Hack -- Pack Overflow */
5244                 pack_overflow();
5245
5246
5247                 /*** Clean up ***/
5248
5249                 /* Significant */
5250                 if (p_ptr->energy_use)
5251                 {
5252                         /* Use some energy */
5253                         if (world_player || p_ptr->energy_use > 400)
5254                         {
5255                                 /* The Randomness is irrelevant */
5256                                 p_ptr->energy_need += p_ptr->energy_use * TURNS_PER_TICK / 10;
5257                         }
5258                         else
5259                         {
5260                                 /* There is some randomness of needed energy */
5261                                 p_ptr->energy_need += (s16b)((s32b)p_ptr->energy_use * ENERGY_NEED() / 100L);
5262                         }
5263
5264                         /* Hack -- constant hallucination */
5265                         if (p_ptr->image) p_ptr->redraw |= (PR_MAP);
5266
5267
5268                         /* Shimmer monsters if needed */
5269                         if (shimmer_monsters)
5270                         {
5271                                 /* Clear the flag */
5272                                 shimmer_monsters = FALSE;
5273
5274                                 /* Shimmer multi-hued monsters */
5275                                 for (i = 1; i < m_max; i++)
5276                                 {
5277                                         monster_type *m_ptr;
5278                                         monster_race *r_ptr;
5279
5280                                         /* Access monster */
5281                                         m_ptr = &m_list[i];
5282
5283                                         /* Skip dead monsters */
5284                                         if (!m_ptr->r_idx) continue;
5285
5286                                         /* Skip unseen monsters */
5287                                         if (!m_ptr->ml) continue;
5288
5289                                         /* Access the monster race */
5290                                         r_ptr = &r_info[m_ptr->ap_r_idx];
5291
5292                                         /* Skip non-multi-hued monsters */
5293                                         if (!(r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER)))
5294                                                 continue;
5295
5296                                         /* Reset the flag */
5297                                         shimmer_monsters = TRUE;
5298
5299                                         /* Redraw regardless */
5300                                         lite_spot(m_ptr->fy, m_ptr->fx);
5301                                 }
5302                         }
5303
5304
5305                         /* Handle monster detection */
5306                         if (repair_monsters)
5307                         {
5308                                 /* Reset the flag */
5309                                 repair_monsters = FALSE;
5310
5311                                 /* Rotate detection flags */
5312                                 for (i = 1; i < m_max; i++)
5313                                 {
5314                                         monster_type *m_ptr;
5315
5316                                         /* Access monster */
5317                                         m_ptr = &m_list[i];
5318
5319                                         /* Skip dead monsters */
5320                                         if (!m_ptr->r_idx) continue;
5321
5322                                         /* Nice monsters get mean */
5323                                         if (m_ptr->mflag & MFLAG_NICE)
5324                                         {
5325                                                 /* Nice monsters get mean */
5326                                                 m_ptr->mflag &= ~(MFLAG_NICE);
5327                                         }
5328
5329                                         /* Handle memorized monsters */
5330                                         if (m_ptr->mflag2 & MFLAG2_MARK)
5331                                         {
5332                                                 /* Maintain detection */
5333                                                 if (m_ptr->mflag2 & MFLAG2_SHOW)
5334                                                 {
5335                                                         /* Forget flag */
5336                                                         m_ptr->mflag2 &= ~(MFLAG2_SHOW);
5337
5338                                                         /* Still need repairs */
5339                                                         repair_monsters = TRUE;
5340                                                 }
5341
5342                                                 /* Remove detection */
5343                                                 else
5344                                                 {
5345                                                         /* Forget flag */
5346                                                         m_ptr->mflag2 &= ~(MFLAG2_MARK);
5347
5348                                                         /* Assume invisible */
5349                                                         m_ptr->ml = FALSE;
5350
5351                                                         /* Update the monster */
5352                                                         update_mon(i, FALSE);
5353
5354                                                         if (p_ptr->health_who == i) p_ptr->redraw |= (PR_HEALTH);
5355                                                         if (p_ptr->riding == i) p_ptr->redraw |= (PR_UHEALTH);
5356
5357                                                         /* Redraw regardless */
5358                                                         lite_spot(m_ptr->fy, m_ptr->fx);
5359                                                 }
5360                                         }
5361                                 }
5362                         }
5363                         if (p_ptr->pclass == CLASS_IMITATOR)
5364                         {
5365                                 if (p_ptr->mane_num > (p_ptr->lev > 44 ? 3 : p_ptr->lev > 29 ? 2 : 1))
5366                                 {
5367                                         p_ptr->mane_num--;
5368                                         for (i = 0; i < p_ptr->mane_num; i++)
5369                                         {
5370                                                 p_ptr->mane_spell[i] = p_ptr->mane_spell[i+1];
5371                                                 p_ptr->mane_dam[i] = p_ptr->mane_dam[i+1];
5372                                         }
5373                                 }
5374                                 new_mane = FALSE;
5375                                 p_ptr->redraw |= (PR_IMITATION);
5376                         }
5377                         if (p_ptr->action == ACTION_LEARN)
5378                         {
5379                                 new_mane = FALSE;
5380                                 p_ptr->redraw |= (PR_STATE);
5381                         }
5382
5383                         if (world_player && (p_ptr->energy_need > - 1000))
5384                         {
5385                                 /* Redraw map */
5386                                 p_ptr->redraw |= (PR_MAP);
5387
5388                                 /* Update monsters */
5389                                 p_ptr->update |= (PU_MONSTERS);
5390
5391                                 /* Window stuff */
5392                                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
5393
5394                                 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
5395                                 msg_print(NULL);
5396                                 world_player = FALSE;
5397                                 p_ptr->energy_need = ENERGY_NEED();
5398
5399                                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5400                                 handle_stuff();
5401                         }
5402                 }
5403
5404                 /* Hack -- notice death */
5405                 if (!p_ptr->playing || p_ptr->is_dead)
5406                 {
5407                         world_player = FALSE;
5408                         break;
5409                 }
5410
5411                 /* Sniper */
5412                 if (p_ptr->energy_use && reset_concent) reset_concentration(TRUE);
5413
5414                 /* Handle "leaving" */
5415                 if (p_ptr->leaving) break;
5416         }
5417
5418         /* Update scent trail */
5419         update_smell();
5420 }
5421
5422 /*!
5423  * @brief 現在プレイヤーがいるダンジョンの全体処理 / Interact with the current dungeon level.
5424  * @return なし
5425  * @details
5426  * <p>
5427  * この関数から現在の階層を出る、プレイヤーがキャラが死ぬ、
5428  * ゲームを終了するかのいずれかまでループする。
5429  * </p>
5430  * <p>
5431  * This function will not exit until the level is completed,\n
5432  * the user dies, or the game is terminated.\n
5433  * </p>
5434  */
5435 static void dungeon(bool load_game)
5436 {
5437         int quest_num = 0;
5438
5439         /* Set the base level */
5440         base_level = dun_level;
5441
5442         /* Reset various flags */
5443         is_loading_now = FALSE;
5444
5445         /* Not leaving */
5446         p_ptr->leaving = FALSE;
5447
5448         /* Reset the "command" vars */
5449         command_cmd = 0;
5450
5451 #if 0 /* Don't reset here --- It's used for Arena */
5452         command_new = 0;
5453 #endif
5454
5455         command_rep = 0;
5456         command_arg = 0;
5457         command_dir = 0;
5458
5459
5460         /* Cancel the target */
5461         target_who = 0;
5462         pet_t_m_idx = 0;
5463         riding_t_m_idx = 0;
5464         ambush_flag = FALSE;
5465
5466         /* Cancel the health bar */
5467         health_track(0);
5468
5469         /* Check visual effects */
5470         shimmer_monsters = TRUE;
5471         shimmer_objects = TRUE;
5472         repair_monsters = TRUE;
5473         repair_objects = TRUE;
5474
5475
5476         /* Disturb */
5477         disturb(1, 1);
5478
5479         /* Get index of current quest (if any) */
5480         quest_num = quest_number(dun_level);
5481
5482         /* Inside a quest? */
5483         if (quest_num)
5484         {
5485                 /* Mark the quest monster */
5486                 r_info[quest[quest_num].r_idx].flags1 |= RF1_QUESTOR;
5487         }
5488
5489         /* Track maximum player level */
5490         if (p_ptr->max_plv < p_ptr->lev)
5491         {
5492                 p_ptr->max_plv = p_ptr->lev;
5493         }
5494
5495
5496         /* Track maximum dungeon level (if not in quest -KMW-) */
5497         if ((max_dlv[dungeon_type] < dun_level) && !p_ptr->inside_quest)
5498         {
5499                 max_dlv[dungeon_type] = dun_level;
5500                 if (record_maxdepth) do_cmd_write_nikki(NIKKI_MAXDEAPTH, dun_level, NULL);
5501         }
5502
5503         (void)calculate_upkeep();
5504
5505         /* Validate the panel */
5506         panel_bounds_center();
5507
5508         /* Verify the panel */
5509         verify_panel();
5510
5511         /* Flush messages */
5512         msg_print(NULL);
5513
5514
5515         /* Enter "xtra" mode */
5516         character_xtra = TRUE;
5517
5518         /* Window stuff */
5519         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_MONSTER | PW_OVERHEAD | PW_DUNGEON);
5520
5521         /* Redraw dungeon */
5522         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_EQUIPPY);
5523
5524         /* Redraw map */
5525         p_ptr->redraw |= (PR_MAP);
5526
5527         /* Update stuff */
5528         p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
5529
5530         /* Update lite/view */
5531         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_TORCH);
5532
5533         /* Update monsters */
5534         p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
5535
5536         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5537         handle_stuff();
5538
5539         /* Leave "xtra" mode */
5540         character_xtra = FALSE;
5541
5542         /* Update stuff */
5543         p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
5544
5545         /* Combine / Reorder the pack */
5546         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
5547
5548         /* Handle "p_ptr->notice" */
5549         notice_stuff();
5550
5551         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5552         handle_stuff();
5553
5554         /* Refresh */
5555         Term_fresh();
5556
5557         if (quest_num && (is_fixed_quest_idx(quest_num) &&
5558             !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) ||
5559             !(quest[quest_num].flags & QUEST_FLAG_PRESET)))) do_cmd_feeling();
5560
5561         if (p_ptr->inside_battle)
5562         {
5563                 if (load_game)
5564                 {
5565                         p_ptr->energy_need = 0;
5566                         battle_monsters();
5567                 }
5568                 else
5569                 {
5570                         msg_print(_("試合開始!", "Ready..Fight!"));
5571                         msg_print(NULL);
5572                 }
5573         }
5574
5575         if ((p_ptr->pclass == CLASS_BARD) && (SINGING_SONG_EFFECT(p_ptr) > MUSIC_DETECT))
5576                 SINGING_SONG_EFFECT(p_ptr) = MUSIC_DETECT;
5577
5578         /* Hack -- notice death or departure */
5579         if (!p_ptr->playing || p_ptr->is_dead) return;
5580
5581         /* Print quest message if appropriate */
5582         if (!p_ptr->inside_quest && (dungeon_type == DUNGEON_ANGBAND))
5583         {
5584                 quest_discovery(random_quest_number(dun_level));
5585                 p_ptr->inside_quest = random_quest_number(dun_level);
5586         }
5587         if ((dun_level == d_info[dungeon_type].maxdepth) && d_info[dungeon_type].final_guardian)
5588         {
5589                 if (r_info[d_info[dungeon_type].final_guardian].max_num)
5590 #ifdef JP
5591                         msg_format("この階には%sの主である%sが棲んでいる。",
5592                                    d_name+d_info[dungeon_type].name, 
5593                                    r_name+r_info[d_info[dungeon_type].final_guardian].name);
5594 #else
5595                         msg_format("%^s lives in this level as the keeper of %s.",
5596                                            r_name+r_info[d_info[dungeon_type].final_guardian].name, 
5597                                            d_name+d_info[dungeon_type].name);
5598 #endif
5599         }
5600
5601         if (!load_game && (p_ptr->special_defense & NINJA_S_STEALTH)) set_superstealth(FALSE);
5602
5603         /*** Process this dungeon level ***/
5604
5605         /* Reset the monster generation level */
5606         monster_level = base_level;
5607
5608         /* Reset the object generation level */
5609         object_level = base_level;
5610
5611         is_loading_now = TRUE;
5612
5613         if (p_ptr->energy_need > 0 && !p_ptr->inside_battle &&
5614             (dun_level || p_ptr->leaving_dungeon || p_ptr->inside_arena))
5615                 p_ptr->energy_need = 0;
5616
5617         /* Not leaving dungeon */
5618         p_ptr->leaving_dungeon = FALSE;
5619
5620         /* Initialize monster process */
5621         mproc_init();
5622
5623         /* Main loop */
5624         while (TRUE)
5625         {
5626                 /* Hack -- Compact the monster list occasionally */
5627                 if ((m_cnt + 32 > max_m_idx) && !p_ptr->inside_battle) compact_monsters(64);
5628
5629                 /* Hack -- Compress the monster list occasionally */
5630                 if ((m_cnt + 32 < m_max) && !p_ptr->inside_battle) compact_monsters(0);
5631
5632
5633                 /* Hack -- Compact the object list occasionally */
5634                 if (o_cnt + 32 > max_o_idx) compact_objects(64);
5635
5636                 /* Hack -- Compress the object list occasionally */
5637                 if (o_cnt + 32 < o_max) compact_objects(0);
5638
5639                 
5640                 /* Process the player */
5641                 process_player();
5642                 
5643                 process_upkeep_with_speed();
5644
5645                 /* Handle "p_ptr->notice" */
5646                 notice_stuff();
5647
5648                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5649                 handle_stuff();
5650
5651                 /* Hack -- Hilite the player */
5652                 move_cursor_relative(p_ptr->y, p_ptr->x);
5653
5654                 /* Optional fresh */
5655                 if (fresh_after) Term_fresh();
5656
5657                 /* Hack -- Notice death or departure */
5658                 if (!p_ptr->playing || p_ptr->is_dead) break;
5659
5660                 /* Process all of the monsters */
5661                 process_monsters();
5662
5663                 /* Handle "p_ptr->notice" */
5664                 notice_stuff();
5665
5666                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5667                 handle_stuff();
5668
5669                 /* Hack -- Hilite the player */
5670                 move_cursor_relative(p_ptr->y, p_ptr->x);
5671
5672                 /* Optional fresh */
5673                 if (fresh_after) Term_fresh();
5674
5675                 /* Hack -- Notice death or departure */
5676                 if (!p_ptr->playing || p_ptr->is_dead) break;
5677
5678
5679                 /* Process the world */
5680                 process_world();
5681
5682                 /* Handle "p_ptr->notice" */
5683                 notice_stuff();
5684
5685                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5686                 handle_stuff();
5687
5688                 /* Hack -- Hilite the player */
5689                 move_cursor_relative(p_ptr->y, p_ptr->x);
5690
5691                 /* Optional fresh */
5692                 if (fresh_after) Term_fresh();
5693
5694                 /* Hack -- Notice death or departure */
5695                 if (!p_ptr->playing || p_ptr->is_dead) break;
5696
5697                 /* Count game turns */
5698                 turn++;
5699
5700                 if (dungeon_turn < dungeon_turn_limit)
5701                 {
5702                         if (!p_ptr->wild_mode || wild_regen) dungeon_turn++;
5703                         else if (p_ptr->wild_mode && !(turn % ((MAX_HGT + MAX_WID) / 2))) dungeon_turn++;
5704                 }
5705
5706                 prevent_turn_overflow();
5707
5708                 /* Handle "leaving" */
5709                 if (p_ptr->leaving) break;
5710
5711                 if (wild_regen) wild_regen--;
5712         }
5713
5714         /* Inside a quest and non-unique questor? */
5715         if (quest_num && !(r_info[quest[quest_num].r_idx].flags1 & RF1_UNIQUE))
5716         {
5717                 /* Un-mark the quest monster */
5718                 r_info[quest[quest_num].r_idx].flags1 &= ~RF1_QUESTOR;
5719         }
5720
5721         /* Not save-and-quit and not dead? */
5722         if (p_ptr->playing && !p_ptr->is_dead)
5723         {
5724                 /*
5725                  * Maintain Unique monsters and artifact, save current
5726                  * floor, then prepare next floor
5727                  */
5728                 leave_floor();
5729
5730                 /* Forget the flag */
5731                 reinit_wilderness = FALSE;
5732         }
5733
5734         /* Write about current level on the play record once per level */
5735         write_level = TRUE;
5736 }
5737
5738
5739 /*!
5740  * @brief 全ユーザプロファイルをロードする / Load some "user pref files"
5741  * @return なし
5742  * @note
5743  * Modified by Arcum Dagsson to support
5744  * separate macro files for different realms.
5745  */
5746 static void load_all_pref_files(void)
5747 {
5748         char buf[1024];
5749
5750         /* Access the "user" pref file */
5751         sprintf(buf, "user.prf");
5752
5753         /* Process that file */
5754         process_pref_file(buf);
5755
5756         /* Access the "user" system pref file */
5757         sprintf(buf, "user-%s.prf", ANGBAND_SYS);
5758
5759         /* Process that file */
5760         process_pref_file(buf);
5761
5762         /* Access the "race" pref file */
5763         sprintf(buf, "%s.prf", rp_ptr->title);
5764
5765         /* Process that file */
5766         process_pref_file(buf);
5767
5768         /* Access the "class" pref file */
5769         sprintf(buf, "%s.prf", cp_ptr->title);
5770
5771         /* Process that file */
5772         process_pref_file(buf);
5773
5774         /* Access the "character" pref file */
5775         sprintf(buf, "%s.prf", player_base);
5776
5777         /* Process that file */
5778         process_pref_file(buf);
5779
5780         /* Access the "realm 1" pref file */
5781         if (p_ptr->realm1 != REALM_NONE)
5782         {
5783                 sprintf(buf, "%s.prf", realm_names[p_ptr->realm1]);
5784
5785                 /* Process that file */
5786                 process_pref_file(buf);
5787         }
5788
5789         /* Access the "realm 2" pref file */
5790         if (p_ptr->realm2 != REALM_NONE)
5791         {
5792                 sprintf(buf, "%s.prf", realm_names[p_ptr->realm2]);
5793
5794                 /* Process that file */
5795                 process_pref_file(buf);
5796         }
5797
5798
5799         /* Load an autopick preference file */
5800         autopick_load_pref(FALSE);
5801 }
5802
5803
5804 /*!
5805  * @brief ビットセットからゲームオプションを展開する / Extract option variables from bit sets
5806  * @return なし
5807  */
5808 void extract_option_vars(void)
5809 {
5810         int i;
5811
5812         for (i = 0; option_info[i].o_desc; i++)
5813         {
5814                 int os = option_info[i].o_set;
5815                 int ob = option_info[i].o_bit;
5816
5817                 /* Set the "default" options */
5818                 if (option_info[i].o_var)
5819                 {
5820                         /* Set */
5821                         if (option_flag[os] & (1L << ob))
5822                         {
5823                                 /* Set */
5824                                 (*option_info[i].o_var) = TRUE;
5825                         }
5826
5827                         /* Clear */
5828                         else
5829                         {
5830                                 /* Clear */
5831                                 (*option_info[i].o_var) = FALSE;
5832                         }
5833                 }
5834         }
5835 }
5836
5837
5838 /*!
5839  * @brief 賞金首となるユニークを確定する / Determine bounty uniques
5840  * @return なし
5841  */
5842 void determine_bounty_uniques(void)
5843 {
5844         int i, j;
5845         MONRACE_IDX tmp;
5846         monster_race *r_ptr;
5847
5848         get_mon_num_prep(NULL, NULL);
5849         for (i = 0; i < MAX_KUBI; i++)
5850         {
5851                 while (1)
5852                 {
5853                         kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
5854                         r_ptr = &r_info[kubi_r_idx[i]];
5855
5856                         if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
5857
5858                         if (!(r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON))) continue;
5859
5860                         if (r_ptr->rarity > 100) continue;
5861
5862                         if (no_questor_or_bounty_uniques(kubi_r_idx[i])) continue;
5863
5864                         for (j = 0; j < i; j++)
5865                                 if (kubi_r_idx[i] == kubi_r_idx[j]) break;
5866
5867                         if (j == i) break;
5868                 }
5869         }
5870
5871         /* Sort them */
5872         for (i = 0; i < MAX_KUBI - 1; i++)
5873         {
5874                 for (j = i; j < MAX_KUBI; j++)
5875                 {
5876                         if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
5877                         {
5878                                 tmp = kubi_r_idx[i];
5879                                 kubi_r_idx[i] = kubi_r_idx[j];
5880                                 kubi_r_idx[j] = tmp;
5881                         }
5882                 }
5883         }
5884 }
5885
5886
5887 /*!
5888  * @brief 今日の賞金首を確定する / Determine today's bounty monster
5889  * @return なし
5890  * @note conv_old is used if loaded 0.0.3 or older save file
5891  */
5892 void determine_today_mon(bool conv_old)
5893 {
5894         int max_dl = 3, i;
5895         bool old_inside_battle = p_ptr->inside_battle;
5896         monster_race *r_ptr;
5897
5898         if (!conv_old)
5899         {
5900                 for (i = 0; i < max_d_idx; i++)
5901                 {
5902                         if (max_dlv[i] < d_info[i].mindepth) continue;
5903                         if (max_dl < max_dlv[i]) max_dl = max_dlv[i];
5904                 }
5905         }
5906         else max_dl = MAX(max_dlv[DUNGEON_ANGBAND], 3);
5907
5908         p_ptr->inside_battle = TRUE;
5909         get_mon_num_prep(NULL, NULL);
5910
5911         while (1)
5912         {
5913                 today_mon = get_mon_num(max_dl);
5914                 r_ptr = &r_info[today_mon];
5915
5916                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
5917                 if (r_ptr->flags7 & (RF7_NAZGUL | RF7_UNIQUE2)) continue;
5918                 if (r_ptr->flags2 & RF2_MULTIPLY) continue;
5919                 if ((r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) != (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) continue;
5920                 if (r_ptr->level < MIN(max_dl / 2, 40)) continue;
5921                 if (r_ptr->rarity > 10) continue;
5922                 break;
5923         }
5924
5925         p_ptr->today_mon = 0;
5926         p_ptr->inside_battle = old_inside_battle;
5927 }
5928
5929 /*!
5930  * @brief 1ゲームプレイの主要ルーチン / Actually play a game
5931  * @return なし
5932  * @note
5933  * If the "new_game" parameter is true, then, after loading the
5934  * savefile, we will commit suicide, if necessary, to allow the
5935  * player to start a new game.
5936  */
5937 void play_game(bool new_game)
5938 {
5939         MONSTER_IDX i;
5940         bool load_game = TRUE;
5941         bool init_random_seed = FALSE;
5942
5943 #ifdef CHUUKEI
5944         if (chuukei_client)
5945         {
5946                 reset_visuals();
5947                 browse_chuukei();
5948                 return;
5949         }
5950
5951         else if (chuukei_server)
5952         {
5953                 prepare_chuukei_hooks();
5954         }
5955 #endif
5956
5957         if (browsing_movie)
5958         {
5959                 reset_visuals();
5960                 browse_movie();
5961                 return;
5962         }
5963
5964         hack_mutation = FALSE;
5965
5966         /* Hack -- Character is "icky" */
5967         character_icky = TRUE;
5968
5969         /* Make sure main term is active */
5970         Term_activate(angband_term[0]);
5971
5972         /* Initialise the resize hooks */
5973         angband_term[0]->resize_hook = resize_map;
5974
5975         for (i = 1; i < 8; i++)
5976         {
5977                 /* Does the term exist? */
5978                 if (angband_term[i])
5979                 {
5980                         /* Add the redraw on resize hook */
5981                         angband_term[i]->resize_hook = redraw_window;
5982                 }
5983         }
5984
5985         /* Hack -- turn off the cursor */
5986         (void)Term_set_cursor(0);
5987
5988
5989         /* Attempt to load */
5990         if (!load_player())
5991         {
5992                 /* Oops */
5993                 quit(_("セーブファイルが壊れています", "broken savefile"));
5994         }
5995
5996         /* Extract the options */
5997         extract_option_vars();
5998
5999         /* Report waited score */
6000         if (p_ptr->wait_report_score)
6001         {
6002                 char buf[1024];
6003                 bool success;
6004
6005                 if (!get_check_strict(_("待機していたスコア登録を今行ないますか?", "Do you register score now? "), CHECK_NO_HISTORY))
6006                         quit(0);
6007
6008                 /* Update stuff */
6009                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
6010
6011                 /* Update stuff */
6012                 update_stuff();
6013
6014                 p_ptr->is_dead = TRUE;
6015
6016                 start_time = (u32b)time(NULL);
6017
6018                 /* No suspending now */
6019                 signals_ignore_tstp();
6020                 
6021                 /* Hack -- Character is now "icky" */
6022                 character_icky = TRUE;
6023
6024                 /* Build the filename */
6025                 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
6026
6027                 /* Open the high score file, for reading/writing */
6028                 highscore_fd = fd_open(buf, O_RDWR);
6029
6030                 /* 町名消失バグ対策(#38205) Init the wilderness */
6031                 process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
6032
6033                 /* Handle score, show Top scores */
6034                 success = send_world_score(TRUE);
6035
6036                 if (!success && !get_check_strict(_("スコア登録を諦めますか?", "Do you give up score registration? "), CHECK_NO_HISTORY))
6037                 {
6038                         prt(_("引き続き待機します。", "standing by for future registration..."), 0, 0);
6039                         (void)inkey();
6040                 }
6041                 else
6042                 {
6043                         p_ptr->wait_report_score = FALSE;
6044                         top_twenty();
6045                         if (!save_player()) msg_print(_("セーブ失敗!", "death save failed!"));
6046                 }
6047                 /* Shut the high score file */
6048                 (void)fd_close(highscore_fd);
6049
6050                 /* Forget the high score fd */
6051                 highscore_fd = -1;
6052                 
6053                 /* Allow suspending now */
6054                 signals_handle_tstp();
6055
6056                 quit(0);
6057         }
6058
6059         creating_savefile = new_game;
6060
6061         /* Nothing loaded */
6062         if (!character_loaded)
6063         {
6064                 /* Make new player */
6065                 new_game = TRUE;
6066
6067                 /* The dungeon is not ready */
6068                 character_dungeon = FALSE;
6069
6070                 /* Prepare to init the RNG */
6071                 init_random_seed = TRUE;
6072
6073                 /* Initialize the saved floors data */
6074                 init_saved_floors(FALSE);
6075         }
6076
6077         /* Old game is loaded.  But new game is requested. */
6078         else if (new_game)
6079         {
6080                 /* Initialize the saved floors data */
6081                 init_saved_floors(TRUE);
6082         }
6083
6084         /* Process old character */
6085         if (!new_game)
6086         {
6087                 /* Process the player name */
6088                 process_player_name(FALSE);
6089         }
6090
6091         /* Init the RNG */
6092         if (init_random_seed)
6093         {
6094                 Rand_state_init();
6095         }
6096
6097         /* Roll new character */
6098         if (new_game)
6099         {
6100                 /* The dungeon is not ready */
6101                 character_dungeon = FALSE;
6102
6103                 /* Start in town */
6104                 dun_level = 0;
6105                 p_ptr->inside_quest = 0;
6106                 p_ptr->inside_arena = FALSE;
6107                 p_ptr->inside_battle = FALSE;
6108
6109                 write_level = TRUE;
6110
6111                 /* Hack -- seed for flavors */
6112                 seed_flavor = randint0(0x10000000);
6113
6114                 /* Hack -- seed for town layout */
6115                 seed_town = randint0(0x10000000);
6116
6117                 /* Roll up a new character */
6118                 player_birth();
6119
6120                 counts_write(2,0);
6121                 p_ptr->count = 0;
6122
6123                 load = FALSE;
6124
6125                 determine_bounty_uniques();
6126                 determine_today_mon(FALSE);
6127
6128                 /* Initialize object array */
6129                 wipe_o_list();
6130         }
6131         else
6132         {
6133                 write_level = FALSE;
6134
6135                 do_cmd_write_nikki(NIKKI_GAMESTART, 1, 
6136                                           _("                            ----ゲーム再開----",
6137                                                 "                            ---- Restart Game ----"));
6138
6139 /*
6140  * 1.0.9 以前はセーブ前に p_ptr->riding = -1 としていたので、再設定が必要だった。
6141  * もう不要だが、以前のセーブファイルとの互換のために残しておく。
6142  */
6143                 if (p_ptr->riding == -1)
6144                 {
6145                         p_ptr->riding = 0;
6146                         for (i = m_max; i > 0; i--)
6147                         {
6148                                 if (player_bold(m_list[i].fy, m_list[i].fx))
6149                                 {
6150                                         p_ptr->riding = i;
6151                                         break;
6152                                 }
6153                         }
6154                 }
6155         }
6156
6157         creating_savefile = FALSE;
6158
6159         p_ptr->teleport_town = FALSE;
6160         p_ptr->sutemi = FALSE;
6161         world_monster = FALSE;
6162         now_damaged = FALSE;
6163         now_message = 0;
6164         start_time = time(NULL) - 1;
6165         record_o_name[0] = '\0';
6166
6167         /* Reset map panel */
6168         panel_row_min = cur_hgt;
6169         panel_col_min = cur_wid;
6170
6171         /* Sexy gal gets bonus to maximum weapon skill of whip */
6172         if (p_ptr->pseikaku == SEIKAKU_SEXY)
6173                 s_info[p_ptr->pclass].w_max[TV_HAFTED-TV_WEAPON_BEGIN][SV_WHIP] = WEAPON_EXP_MASTER;
6174
6175         /* Fill the arrays of floors and walls in the good proportions */
6176         set_floor_and_wall(dungeon_type);
6177
6178         /* Flavor the objects */
6179         flavor_init();
6180
6181         /* Flash a message */
6182         prt(_("お待ち下さい...", "Please wait..."), 0, 0);
6183
6184         /* Flush the message */
6185         Term_fresh();
6186
6187
6188         /* Hack -- Enter wizard mode */
6189         if (arg_wizard)
6190         {
6191                 if (enter_wizard_mode())
6192                 {
6193                         p_ptr->wizard = TRUE;
6194
6195                         if (p_ptr->is_dead || !p_ptr->y || !p_ptr->x)
6196                         {
6197                                 /* Initialize the saved floors data */
6198                                 init_saved_floors(TRUE);
6199
6200                                 /* Avoid crash */
6201                                 p_ptr->inside_quest = 0;
6202
6203                                 /* Avoid crash in update_view() */
6204                                 p_ptr->y = p_ptr->x = 10;
6205                         }
6206                 }
6207                 else if (p_ptr->is_dead)
6208                 {
6209                         quit("Already dead.");
6210                 }
6211         }
6212
6213         /* Initialize the town-buildings if necessary */
6214         if (!dun_level && !p_ptr->inside_quest)
6215         {
6216                 /* Init the wilderness */
6217
6218                 process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
6219
6220                 /* Init the town */
6221                 init_flags = INIT_ONLY_BUILDINGS;
6222
6223                 process_dungeon_file("t_info.txt", 0, 0, MAX_HGT, MAX_WID);
6224
6225                 select_floor_music();
6226         }
6227
6228
6229         /* Generate a dungeon level if needed */
6230         if (!character_dungeon)
6231         {
6232                 change_floor();
6233         }
6234
6235         else
6236         {
6237                 /* HACK -- Restore from panic-save */
6238                 if (p_ptr->panic_save)
6239                 {
6240                         /* No player?  -- Try to regenerate floor */
6241                         if (!p_ptr->y || !p_ptr->x)
6242                         {
6243                                 msg_print(_("プレイヤーの位置がおかしい。フロアを再生成します。", "What a strange player location.  Regenerate the dungeon floor."));
6244                                 change_floor();
6245                         }
6246
6247                         /* Still no player?  -- Try to locate random place */
6248                         if (!p_ptr->y || !p_ptr->x) p_ptr->y = p_ptr->x = 10;
6249
6250                         /* No longer in panic */
6251                         p_ptr->panic_save = 0;
6252                 }
6253         }
6254
6255         /* Character is now "complete" */
6256         character_generated = TRUE;
6257
6258
6259         /* Hack -- Character is no longer "icky" */
6260         character_icky = FALSE;
6261
6262
6263         if (new_game)
6264         {
6265                 char buf[80];
6266                 sprintf(buf, _("%sに降り立った。", "You are standing in the %s."), map_name());
6267                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, buf);
6268         }
6269
6270
6271         /* Start game */
6272         p_ptr->playing = TRUE;
6273
6274         /* Reset the visual mappings */
6275         reset_visuals();
6276
6277         /* Load the "pref" files */
6278         load_all_pref_files();
6279
6280         /* Give startup outfit (after loading pref files) */
6281         if (new_game)
6282         {
6283                 player_outfit();
6284         }
6285
6286         /* React to changes */
6287         Term_xtra(TERM_XTRA_REACT, 0);
6288
6289         /* Window stuff */
6290         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
6291
6292         /* Window stuff */
6293         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
6294
6295         /* Window stuff */
6296         window_stuff();
6297
6298
6299         /* Set or clear "rogue_like_commands" if requested */
6300         if (arg_force_original) rogue_like_commands = FALSE;
6301         if (arg_force_roguelike) rogue_like_commands = TRUE;
6302
6303         /* Hack -- Enforce "delayed death" */
6304         if (p_ptr->chp < 0) p_ptr->is_dead = TRUE;
6305
6306         if (p_ptr->prace == RACE_ANDROID) calc_android_exp();
6307
6308         if (new_game && ((p_ptr->pclass == CLASS_CAVALRY) || (p_ptr->pclass == CLASS_BEASTMASTER)))
6309         {
6310                 monster_type *m_ptr;
6311                 IDX pet_r_idx = ((p_ptr->pclass == CLASS_CAVALRY) ? MON_HORSE : MON_YASE_HORSE);
6312                 monster_race *r_ptr = &r_info[pet_r_idx];
6313                 place_monster_aux(0, p_ptr->y, p_ptr->x - 1, pet_r_idx,
6314                                   (PM_FORCE_PET | PM_NO_KAGE));
6315                 m_ptr = &m_list[hack_m_idx_ii];
6316                 m_ptr->mspeed = r_ptr->speed;
6317                 m_ptr->maxhp = r_ptr->hdice*(r_ptr->hside+1)/2;
6318                 m_ptr->max_maxhp = m_ptr->maxhp;
6319                 m_ptr->hp = r_ptr->hdice*(r_ptr->hside+1)/2;
6320                 m_ptr->dealt_damage = 0;
6321                 m_ptr->energy_need = ENERGY_NEED() + ENERGY_NEED();
6322         }
6323
6324         (void)combine_and_reorder_home(STORE_HOME);
6325         (void)combine_and_reorder_home(STORE_MUSEUM);
6326
6327         select_floor_music();
6328
6329         /* Process */
6330         while (TRUE)
6331         {
6332                 /* Process the level */
6333                 dungeon(load_game);
6334
6335                 /* Handle "p_ptr->notice" */
6336                 notice_stuff();
6337
6338                 /* Hack -- prevent "icky" message */
6339                 character_xtra = TRUE;
6340
6341                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6342                 handle_stuff();
6343
6344                 character_xtra = FALSE;
6345
6346                 /* Cancel the target */
6347                 target_who = 0;
6348
6349                 /* Cancel the health bar */
6350                 health_track(0);
6351
6352
6353                 /* Forget the lite */
6354                 forget_lite();
6355
6356                 /* Forget the view */
6357                 forget_view();
6358
6359                 /* Forget the view */
6360                 clear_mon_lite();
6361
6362                 /* Handle "quit and save" */
6363                 if (!p_ptr->playing && !p_ptr->is_dead) break;
6364
6365                 /* Erase the old cave */
6366                 wipe_o_list();
6367                 if (!p_ptr->is_dead) wipe_m_list();
6368
6369
6370                 /* XXX XXX XXX */
6371                 msg_print(NULL);
6372
6373                 load_game = FALSE;
6374
6375                 /* Accidental Death */
6376                 if (p_ptr->playing && p_ptr->is_dead)
6377                 {
6378                         if (p_ptr->inside_arena)
6379                         {
6380                                 p_ptr->inside_arena = FALSE;
6381                                 if (p_ptr->arena_number > MAX_ARENA_MONS)
6382                                         p_ptr->arena_number++;
6383                                 else
6384                                         p_ptr->arena_number = -1 - p_ptr->arena_number;
6385                                 p_ptr->is_dead = FALSE;
6386                                 p_ptr->chp = 0;
6387                                 p_ptr->chp_frac = 0;
6388                                 p_ptr->exit_bldg = TRUE;
6389                                 reset_tim_flags();
6390
6391                                 /* Leave through the exit */
6392                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_RAND_CONNECT);
6393
6394                                 /* prepare next floor */
6395                                 leave_floor();
6396                         }
6397                         else
6398                         {
6399                                 /* Mega-Hack -- Allow player to cheat death */
6400                                 if ((p_ptr->wizard || cheat_live) && !get_check(_("死にますか? ", "Die? ")))
6401                                 {
6402                                         /* Mark social class, reset age, if needed */
6403                                         if (p_ptr->sc) p_ptr->sc = p_ptr->age = 0;
6404
6405                                         /* Increase age */
6406                                         p_ptr->age++;
6407
6408                                         /* Mark savefile */
6409                                         p_ptr->noscore |= 0x0001;
6410
6411                                         /* Message */
6412                                         msg_print(_("ウィザードモードに念を送り、死を欺いた。", "You invoke wizard mode and cheat death."));
6413                                         msg_print(NULL);
6414
6415                                         (void)life_stream(FALSE, FALSE);
6416
6417                                         if (p_ptr->pclass == CLASS_MAGIC_EATER)
6418                                         {
6419                                                 int magic_idx;
6420                                                 for (magic_idx = 0; magic_idx < EATER_EXT*2; magic_idx++)
6421                                                 {
6422                                                         p_ptr->magic_num1[magic_idx] = p_ptr->magic_num2[magic_idx]*EATER_CHARGE;
6423                                                 }
6424                                                 for (; magic_idx < EATER_EXT*3; magic_idx++)
6425                                                 {
6426                                                         p_ptr->magic_num1[magic_idx] = 0;
6427                                                 }
6428                                         }
6429
6430                                         /* Restore spell points */
6431                                         p_ptr->csp = p_ptr->msp;
6432                                         p_ptr->csp_frac = 0;
6433
6434                                         /* Hack -- cancel recall */
6435                                         if (p_ptr->word_recall)
6436                                         {
6437                                                 /* Message */
6438                                                 msg_print(_("張りつめた大気が流れ去った...", "A tension leaves the air around you..."));
6439                                                 msg_print(NULL);
6440
6441                                                 /* Hack -- Prevent recall */
6442                                                 p_ptr->word_recall = 0;
6443                                                 p_ptr->redraw |= (PR_STATUS);
6444                                         }
6445
6446                                         /* Hack -- cancel alter */
6447                                         if (p_ptr->alter_reality)
6448                                         {
6449                                                 /* Hack -- Prevent alter */
6450                                                 p_ptr->alter_reality = 0;
6451                                                 p_ptr->redraw |= (PR_STATUS);
6452                                         }
6453
6454                                         /* Note cause of death XXX XXX XXX */
6455                                         (void)strcpy(p_ptr->died_from, _("死の欺き", "Cheating death"));
6456
6457                                         /* Do not die */
6458                                         p_ptr->is_dead = FALSE;
6459
6460                                         /* Hack -- Prevent starvation */
6461                                         (void)set_food(PY_FOOD_MAX - 1);
6462
6463                                         dun_level = 0;
6464                                         p_ptr->inside_arena = FALSE;
6465                                         p_ptr->inside_battle = FALSE;
6466                                         leaving_quest = 0;
6467                                         p_ptr->inside_quest = 0;
6468                                         if (dungeon_type) p_ptr->recall_dungeon = dungeon_type;
6469                                         dungeon_type = 0;
6470                                         if (lite_town || vanilla_town)
6471                                         {
6472                                                 p_ptr->wilderness_y = 1;
6473                                                 p_ptr->wilderness_x = 1;
6474                                                 if (vanilla_town)
6475                                                 {
6476                                                         p_ptr->oldpy = 10;
6477                                                         p_ptr->oldpx = 34;
6478                                                 }
6479                                                 else
6480                                                 {
6481                                                         p_ptr->oldpy = 33;
6482                                                         p_ptr->oldpx = 131;
6483                                                 }
6484                                         }
6485                                         else
6486                                         {
6487                                                 p_ptr->wilderness_y = 48;
6488                                                 p_ptr->wilderness_x = 5;
6489                                                 p_ptr->oldpy = 33;
6490                                                 p_ptr->oldpx = 131;
6491                                         }
6492
6493                                         /* Leaving */
6494                                         p_ptr->wild_mode = FALSE;
6495                                         p_ptr->leaving = TRUE;
6496
6497                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 1, 
6498                                                                 _("                            しかし、生き返った。", 
6499                                                                   "                            but revived."));
6500
6501                                         /* Prepare next floor */
6502                                         leave_floor();
6503                                         wipe_m_list();
6504                                 }
6505                         }
6506                 }
6507
6508                 /* Handle "death" */
6509                 if (p_ptr->is_dead) break;
6510
6511                 /* Make a new level */
6512                 change_floor();
6513         }
6514
6515         /* Close stuff */
6516         close_game();
6517
6518         /* Quit */
6519         quit(NULL);
6520 }
6521
6522 /*!
6523  * @brief ゲームターンからの実時間換算を行うための補正をかける
6524  * @param hoge ゲームターン
6525  * @details アンデッド種族は18:00からゲームを開始するので、この修正を予め行う。
6526  * @return 修正をかけた後のゲームターン
6527  */
6528 s32b turn_real(s32b hoge)
6529 {
6530         switch (p_ptr->start_race)
6531         {
6532         case RACE_VAMPIRE:
6533         case RACE_SKELETON:
6534         case RACE_ZOMBIE:
6535         case RACE_SPECTRE:
6536                 return hoge - (TURNS_PER_TICK * TOWN_DAWN * 3 / 4);
6537         default:
6538                 return hoge;
6539         }
6540 }
6541
6542 /*!
6543  * @brief ターンのオーバーフローに対する対処
6544  * @details ターン及びターンを記録する変数をターンの限界の1日前まで巻き戻す.
6545  * @return 修正をかけた後のゲームターン
6546  */
6547 void prevent_turn_overflow(void)
6548 {
6549         int rollback_days, i, j;
6550         s32b rollback_turns;
6551
6552         if (turn < turn_limit) return;
6553
6554         rollback_days = 1 + (turn - turn_limit) / (TURNS_PER_TICK * TOWN_DAWN);
6555         rollback_turns = TURNS_PER_TICK * TOWN_DAWN * rollback_days;
6556
6557         if (turn > rollback_turns) turn -= rollback_turns;
6558         else turn = 1; /* Paranoia */
6559         if (old_turn > rollback_turns) old_turn -= rollback_turns;
6560         else old_turn = 1;
6561         if (old_battle > rollback_turns) old_battle -= rollback_turns;
6562         else old_battle = 1;
6563         if (p_ptr->feeling_turn > rollback_turns) p_ptr->feeling_turn -= rollback_turns;
6564         else p_ptr->feeling_turn = 1;
6565
6566         for (i = 1; i < max_towns; i++)
6567         {
6568                 for (j = 0; j < MAX_STORES; j++)
6569                 {
6570                         store_type *st_ptr = &town[i].store[j];
6571
6572                         if (st_ptr->last_visit > -10L * TURNS_PER_TICK * STORE_TICKS)
6573                         {
6574                                 st_ptr->last_visit -= rollback_turns;
6575                                 if (st_ptr->last_visit < -10L * TURNS_PER_TICK * STORE_TICKS) st_ptr->last_visit = -10L * TURNS_PER_TICK * STORE_TICKS;
6576                         }
6577
6578                         if (st_ptr->store_open)
6579                         {
6580                                 st_ptr->store_open -= rollback_turns;
6581                                 if (st_ptr->store_open < 1) st_ptr->store_open = 1;
6582                         }
6583                 }
6584         }
6585 }