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