OSDN Git Service

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