OSDN Git Service

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