OSDN Git Service

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