OSDN Git Service

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