OSDN Git Service

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