OSDN Git Service

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