OSDN Git Service

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