OSDN Git Service

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