OSDN Git Service

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