OSDN Git Service

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