OSDN Git Service

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