OSDN Git Service

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