OSDN Git Service

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