OSDN Git Service

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