OSDN Git Service

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