OSDN Git Service

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