OSDN Git Service

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