OSDN Git Service

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