OSDN Git Service

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