OSDN Git Service

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