OSDN Git Service

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