OSDN Git Service

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