OSDN Git Service

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