OSDN Git Service

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