OSDN Git Service

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