OSDN Git Service

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