OSDN Git Service

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