OSDN Git Service

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