OSDN Git Service

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