OSDN Git Service

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