OSDN Git Service

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