OSDN Git Service

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