OSDN Git Service

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