OSDN Git Service

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