OSDN Git Service

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