OSDN Git Service

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