OSDN Git Service

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