OSDN Git Service

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