OSDN Git Service

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