OSDN Git Service

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