OSDN Git Service

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