OSDN Git Service

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