OSDN Git Service

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