OSDN Git Service

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