OSDN Git Service

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