OSDN Git Service

ランダムテレポート時に、{.}と刻む方法をメッセージ表示するようにした。
[hengband/hengband.git] / src / dungeon.c
1 /* File: dungeonc */
2
3 /*
4  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
5  *
6  * This software may be copied and distributed for educational, research,
7  * and not for profit purposes provided that this copyright and statement
8  * are included in all such copies.  Other copyrights may also apply.
9  */
10
11 /* Purpose: Angband game engine */
12
13 #include "angband.h"
14
15 #define TY_CURSE_CHANCE 200
16 #define CHAINSWORD_NOISE 100
17
18 static bool load = TRUE;
19 static int wild_regen = 20;
20
21 /*
22  * Return a "feeling" (or NULL) about an item.  Method 1 (Heavy).
23  */
24 static byte value_check_aux1(object_type *o_ptr)
25 {
26         /* Artifacts */
27         if (artifact_p(o_ptr) || o_ptr->art_name)
28         {
29                 /* Cursed/Broken */
30                 if (cursed_p(o_ptr) || broken_p(o_ptr)) return FEEL_TERRIBLE;
31
32                 /* Normal */
33                 return FEEL_SPECIAL;
34         }
35
36         /* Ego-Items */
37         if (ego_item_p(o_ptr))
38         {
39                 /* Cursed/Broken */
40                 if (cursed_p(o_ptr) || broken_p(o_ptr)) return FEEL_WORTHLESS;
41
42                 /* Normal */
43                 return FEEL_EXCELLENT;
44         }
45
46         /* Cursed items */
47         if (cursed_p(o_ptr)) return FEEL_CURSED;
48
49         /* Broken items */
50         if (broken_p(o_ptr)) return FEEL_BROKEN;
51
52         if ((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) return FEEL_AVERAGE;
53
54         /* Good "armor" bonus */
55         if (o_ptr->to_a > 0) return FEEL_GOOD;
56
57         /* Good "weapon" bonus */
58         if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_GOOD;
59
60         /* Default to "average" */
61         return FEEL_AVERAGE;
62 }
63
64
65 /*
66  * Return a "feeling" (or NULL) about an item.  Method 2 (Light).
67  */
68 static byte value_check_aux2(object_type *o_ptr)
69 {
70         /* Cursed items (all of them) */
71         if (cursed_p(o_ptr)) return FEEL_CURSED;
72
73         /* Broken items (all of them) */
74         if (broken_p(o_ptr)) return FEEL_BROKEN;
75
76         /* Artifacts -- except cursed/broken ones */
77         if (artifact_p(o_ptr) || o_ptr->art_name) return FEEL_UNCURSED;
78
79         /* Ego-Items -- except cursed/broken ones */
80         if (ego_item_p(o_ptr)) return FEEL_UNCURSED;
81
82         /* Good armor bonus */
83         if (o_ptr->to_a > 0) return FEEL_UNCURSED;
84
85         /* Good weapon bonuses */
86         if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_UNCURSED;
87
88         /* No feeling */
89         return FEEL_NONE;
90 }
91
92
93
94 static void sense_inventory_aux(int slot, bool heavy)
95 {
96         byte        feel;
97         object_type *o_ptr = &inventory[slot];
98         char        o_name[MAX_NLEN];
99
100         /* We know about it already, do not tell us again */
101         if (o_ptr->ident & (IDENT_SENSE))return;
102
103         /* It is fully known, no information needed */
104         if (object_known_p(o_ptr)) return;
105
106         /* Check for a feeling */
107         feel = (heavy ? value_check_aux1(o_ptr) : value_check_aux2(o_ptr));
108
109         /* Skip non-feelings */
110         if (!feel) return;
111
112         /* Bad luck */
113         if ((p_ptr->muta3 & MUT3_BAD_LUCK) && !randint0(13))
114         {
115                 switch (feel)
116                 {
117                         case FEEL_TERRIBLE:
118                         {
119                                 feel = FEEL_SPECIAL;
120                                 break;
121                         }
122                         case FEEL_WORTHLESS:
123                         {
124                                 feel = FEEL_EXCELLENT;
125                                 break;
126                         }
127                         case FEEL_CURSED:
128                         {
129                                 if (heavy)
130                                         feel = randint0(3) ? FEEL_GOOD : FEEL_AVERAGE;
131                                 else
132                                         feel = FEEL_UNCURSED;
133                                 break;
134                         }
135                         case FEEL_AVERAGE:
136                         {
137                                 feel = randint0(2) ? FEEL_CURSED : FEEL_GOOD;
138                                 break;
139                         }
140                         case FEEL_GOOD:
141                         {
142                                 if (heavy)
143                                         feel = randint0(3) ? FEEL_CURSED : FEEL_AVERAGE;
144                                 else
145                                         feel = FEEL_CURSED;
146                                 break;
147                         }
148                         case FEEL_EXCELLENT:
149                         {
150                                 feel = FEEL_WORTHLESS;
151                                 break;
152                         }
153                         case FEEL_SPECIAL:
154                         {
155                                 feel = FEEL_TERRIBLE;
156                                 break;
157                         }
158                 }
159         }
160
161         /* Stop everything */
162         if (disturb_minor) disturb(0, 0);
163
164         /* Get an object description */
165         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
166
167         /* Message (equipment) */
168         if (slot >= INVEN_RARM)
169         {
170 #ifdef JP
171 msg_format("%s%s(%c)¤Ï%s¤È¤¤¤¦´¶¤¸¤¬¤¹¤ë...",
172 describe_use(slot),o_name, index_to_label(slot),game_inscriptions[feel]);
173 #else
174                 msg_format("You feel the %s (%c) you are %s %s %s...",
175                            o_name, index_to_label(slot), describe_use(slot),
176                            ((o_ptr->number == 1) ? "is" : "are"),
177                                    game_inscriptions[feel]);
178 #endif
179
180         }
181
182         /* Message (inventory) */
183         else
184         {
185 #ifdef JP
186 msg_format("¥¶¥Ã¥¯¤ÎÃæ¤Î%s(%c)¤Ï%s¤È¤¤¤¦´¶¤¸¤¬¤¹¤ë...",
187 o_name, index_to_label(slot),game_inscriptions[feel]);
188 #else
189                 msg_format("You feel the %s (%c) in your pack %s %s...",
190                            o_name, index_to_label(slot),
191                            ((o_ptr->number == 1) ? "is" : "are"),
192                                    game_inscriptions[feel]);
193 #endif
194
195         }
196
197         /* We have "felt" it */
198         o_ptr->ident |= (IDENT_SENSE);
199
200         /* Set the "inscription" */
201         o_ptr->feeling = feel;
202
203         /* Auto-inscription/destroy */
204         autopick_alter_item(slot, destroy_feeling);
205
206         /* Combine / Reorder the pack (later) */
207         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
208
209         /* Window stuff */
210         p_ptr->window |= (PW_INVEN | PW_EQUIP);
211 }
212
213
214
215 /*
216  * Sense the inventory
217  *
218  *   Class 0 = Warrior --> fast and heavy
219  *   Class 1 = Mage    --> slow and light
220  *   Class 2 = Priest  --> fast but light
221  *   Class 3 = Rogue   --> okay and heavy
222  *   Class 4 = Ranger  --> slow but heavy  (changed!)
223  *   Class 5 = Paladin --> slow but heavy
224  */
225 static void sense_inventory1(void)
226 {
227         int         i;
228         int         plev = p_ptr->lev;
229         bool        heavy = FALSE;
230         object_type *o_ptr;
231
232
233         /*** Check for "sensing" ***/
234
235         /* No sensing when confused */
236         if (p_ptr->confused) return;
237
238         /* Analyze the class */
239         switch (p_ptr->pclass)
240         {
241                 case CLASS_WARRIOR:
242                 case CLASS_ARCHER:
243                 case CLASS_SAMURAI:
244                 case CLASS_CAVALRY:
245                 {
246                         /* Good sensing */
247                         if (0 != randint0(9000L / (plev * plev + 40))) return;
248
249                         /* Heavy sensing */
250                         heavy = TRUE;
251
252                         /* Done */
253                         break;
254                 }
255
256                 case CLASS_SMITH:
257                 {
258                         /* Good sensing */
259                         if (0 != randint0(6000L / (plev * plev + 50))) return;
260
261                         /* Heavy sensing */
262                         heavy = TRUE;
263
264                         /* Done */
265                         break;
266                 }
267
268                 case CLASS_MAGE:
269                 case CLASS_HIGH_MAGE:
270                 case CLASS_SORCERER:
271                 case CLASS_MAGIC_EATER:
272                 {
273                         /* Very bad (light) sensing */
274                         if (0 != randint0(240000L / (plev + 5))) return;
275
276                         /* Done */
277                         break;
278                 }
279
280                 case CLASS_PRIEST:
281                 case CLASS_BARD:
282                 {
283                         /* Good (light) sensing */
284                         if (0 != randint0(10000L / (plev * plev + 40))) return;
285
286                         /* Done */
287                         break;
288                 }
289
290                 case CLASS_ROGUE:
291                 case CLASS_NINJA:
292                 {
293                         /* Okay sensing */
294                         if (0 != randint0(20000L / (plev * plev + 40))) return;
295
296                         /* Heavy sensing */
297                         heavy = TRUE;
298
299                         /* Done */
300                         break;
301                 }
302
303                 case CLASS_RANGER:
304                 {
305                         /* Bad sensing */
306                         if (0 != randint0(95000L / (plev * plev + 40))) return;
307
308                         /* Changed! */
309                         heavy = TRUE;
310
311                         /* Done */
312                         break;
313                 }
314
315                 case CLASS_PALADIN:
316                 {
317                         /* Bad sensing */
318                         if (0 != randint0(77777L / (plev * plev + 40))) return;
319
320                         /* Heavy sensing */
321                         heavy = TRUE;
322
323                         /* Done */
324                         break;
325                 }
326
327                 case CLASS_WARRIOR_MAGE:
328                 case CLASS_RED_MAGE:
329                 {
330                         /* Bad sensing */
331                         if (0 != randint0(75000L / (plev * plev + 40))) return;
332
333                         /* Done */
334                         break;
335                 }
336
337                 case CLASS_MINDCRAFTER:
338                 case CLASS_IMITATOR:
339                 case CLASS_BLUE_MAGE:
340                 case CLASS_MIRROR_MASTER:
341                 {
342                         /* Bad sensing */
343                         if (0 != randint0(55000L / (plev * plev + 40))) return;
344
345                         /* Done */
346                         break;
347                 }
348
349                 case CLASS_CHAOS_WARRIOR:
350                 {
351                         /* Bad sensing */
352                         if (0 != randint0(80000L / (plev * plev + 40))) return;
353
354                         /* Changed! */
355                         heavy = TRUE;
356
357                         /* Done */
358                         break;
359                 }
360
361                 case CLASS_MONK:
362                 case CLASS_FORCETRAINER:
363                 {
364                         /* Okay sensing */
365                         if (0 != randint0(20000L / (plev * plev + 40))) return;
366
367                         /* Done */
368                         break;
369                 }
370
371                 case CLASS_TOURIST:
372                 {
373                         /* Good sensing */
374                         if (0 != randint0(20000L / ((plev+50)*(plev+50)))) return;
375
376                         /* Heavy sensing */
377                         heavy = TRUE;
378
379                         /* Done */
380                         break;
381                 }
382
383                 case CLASS_BEASTMASTER:
384                 {
385                         /* Bad sensing */
386                         if (0 != randint0(65000L / (plev * plev + 40))) return;
387
388                         /* Done */
389                         break;
390                 }
391                 case CLASS_BERSERKER:
392                 {
393                         /* Heavy sensing */
394                         heavy = TRUE;
395
396                         /* Done */
397                         break;
398                 }
399         }
400
401         if (compare_virtue(V_KNOWLEDGE, 100, VIRTUE_LARGE)) heavy = TRUE;
402
403         /*** Sense everything ***/
404
405         /* Check everything */
406         for (i = 0; i < INVEN_TOTAL; i++)
407         {
408                 bool okay = FALSE;
409
410                 o_ptr = &inventory[i];
411
412                 /* Skip empty slots */
413                 if (!o_ptr->k_idx) continue;
414
415                 /* Valid "tval" codes */
416                 switch (o_ptr->tval)
417                 {
418                         case TV_SHOT:
419                         case TV_ARROW:
420                         case TV_BOLT:
421                         case TV_BOW:
422                         case TV_DIGGING:
423                         case TV_HAFTED:
424                         case TV_POLEARM:
425                         case TV_SWORD:
426                         case TV_BOOTS:
427                         case TV_GLOVES:
428                         case TV_HELM:
429                         case TV_CROWN:
430                         case TV_SHIELD:
431                         case TV_CLOAK:
432                         case TV_SOFT_ARMOR:
433                         case TV_HARD_ARMOR:
434                         case TV_DRAG_ARMOR:
435                         case TV_CARD:
436                         {
437                                 okay = TRUE;
438                                 break;
439                         }
440                 }
441
442                 /* Skip non-sense machines */
443                 if (!okay) continue;
444
445                 /* Occasional failure on inventory items */
446                 if ((i < INVEN_RARM) && (0 != randint0(5))) continue;
447
448                 /* Good luck */
449                 if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && !randint0(13))
450                 {
451                         heavy = TRUE;
452                 }
453
454                 sense_inventory_aux(i, heavy);
455         }
456 }
457
458
459 static void sense_inventory2(void)
460 {
461         int         i;
462         int         plev = p_ptr->lev;
463         object_type *o_ptr;
464
465
466         /*** Check for "sensing" ***/
467
468         /* No sensing when confused */
469         if (p_ptr->confused) return;
470
471         /* Analyze the class */
472         switch (p_ptr->pclass)
473         {
474                 case CLASS_WARRIOR:
475                 case CLASS_ARCHER:
476                 case CLASS_SAMURAI:
477                 case CLASS_CAVALRY:
478                 case CLASS_BERSERKER:
479                 {
480                         return;
481                 }
482
483                 case CLASS_SMITH:
484                 case CLASS_PALADIN:
485                 case CLASS_CHAOS_WARRIOR:
486                 case CLASS_IMITATOR:
487                 case CLASS_BEASTMASTER:
488                 case CLASS_NINJA:
489                 {
490                         /* Very bad (light) sensing */
491                         if (0 != randint0(240000L / (plev + 5))) return;
492
493                         /* Done */
494                         break;
495                 }
496
497                 case CLASS_RANGER:
498                 case CLASS_WARRIOR_MAGE:
499                 case CLASS_RED_MAGE:
500                 case CLASS_MONK:
501                 {
502                         /* Bad sensing */
503                         if (0 != randint0(95000L / (plev * plev + 40))) return;
504
505                         /* Done */
506                         break;
507                 }
508
509                 case CLASS_PRIEST:
510                 case CLASS_BARD:
511                 case CLASS_ROGUE:
512                 case CLASS_FORCETRAINER:
513                 case CLASS_MINDCRAFTER:
514                 {
515                         /* Good sensing */
516                         if (0 != randint0(20000L / (plev * plev + 40))) return;
517
518                         /* Done */
519                         break;
520                 }
521
522                 case CLASS_MAGE:
523                 case CLASS_HIGH_MAGE:
524                 case CLASS_SORCERER:
525                 case CLASS_MAGIC_EATER:
526                 case CLASS_MIRROR_MASTER:
527                 case CLASS_BLUE_MAGE:
528                 {
529                         /* Good sensing */
530                         if (0 != randint0(9000L / (plev * plev + 40))) return;
531
532                         /* Done */
533                         break;
534                 }
535
536                 case CLASS_TOURIST:
537                 {
538                         /* Good sensing */
539                         if (0 != randint0(20000L / ((plev+50)*(plev+50)))) return;
540
541                         /* Done */
542                         break;
543                 }
544         }
545
546         /*** Sense everything ***/
547
548         /* Check everything */
549         for (i = 0; i < INVEN_TOTAL; i++)
550         {
551                 bool okay = FALSE;
552
553                 o_ptr = &inventory[i];
554
555                 /* Skip empty slots */
556                 if (!o_ptr->k_idx) continue;
557
558                 /* Valid "tval" codes */
559                 switch (o_ptr->tval)
560                 {
561                         case TV_RING:
562                         case TV_AMULET:
563                         case TV_LITE:
564                         case TV_FIGURINE:
565                         {
566                                 okay = TRUE;
567                                 break;
568                         }
569                 }
570
571                 /* Skip non-sense machines */
572                 if (!okay) continue;
573
574                 /* Occasional failure on inventory items */
575                 if ((i < INVEN_RARM) && (0 != randint0(5))) continue;
576
577                 sense_inventory_aux(i, TRUE);
578         }
579 }
580
581
582
583 /*
584  * Go to any level (ripped off from wiz_jump)
585  */
586 static void pattern_teleport(void)
587 {
588         int min_level = 0;
589         int max_level = 99;
590
591         /* Ask for level */
592 #ifdef JP
593 if (get_check("¾¤Î³¬¤Ë¥Æ¥ì¥Ý¡¼¥È¤·¤Þ¤¹¤«¡©"))
594 #else
595         if (get_check("Teleport level? "))
596 #endif
597
598         {
599                 char    ppp[80];
600                 char    tmp_val[160];
601
602                 /* Only downward in ironman mode */
603                 if (ironman_downward)
604                         min_level = dun_level;
605
606                 /* Maximum level */
607                 if (dungeon_type == DUNGEON_ANGBAND)
608                 {
609                         if (dun_level > 100)
610                                 max_level = MAX_DEPTH - 1;
611                         else if (dun_level == 100)
612                                 max_level = 100;
613                 }
614                 else
615                 {
616                         max_level = d_info[dungeon_type].maxdepth;
617                         min_level = d_info[dungeon_type].mindepth;
618                 }
619
620                 /* Prompt */
621 #ifdef JP
622 sprintf(ppp, "¥Æ¥ì¥Ý¡¼¥ÈÀè:(%d-%d)", min_level, max_level);
623 #else
624                 sprintf(ppp, "Teleport to level (%d-%d): ", min_level, max_level);
625 #endif
626
627
628                 /* Default */
629                 sprintf(tmp_val, "%d", dun_level);
630
631                 /* Ask for a level */
632                 if (!get_string(ppp, tmp_val, 10)) return;
633
634                 /* Extract request */
635                 command_arg = atoi(tmp_val);
636         }
637 #ifdef JP
638 else if (get_check("Ä̾ï¥Æ¥ì¥Ý¡¼¥È¡©"))
639 #else
640         else if (get_check("Normal teleport? "))
641 #endif
642
643         {
644                 teleport_player(200);
645                 return;
646         }
647         else
648         {
649                 return;
650         }
651
652         /* Paranoia */
653         if (command_arg < min_level) command_arg = min_level;
654
655         /* Paranoia */
656         if (command_arg > max_level) command_arg = max_level;
657
658         /* Accept request */
659 #ifdef JP
660 msg_format("%d ³¬¤Ë¥Æ¥ì¥Ý¡¼¥È¤·¤Þ¤·¤¿¡£", command_arg);
661 #else
662         msg_format("You teleport to dungeon level %d.", command_arg);
663 #endif
664
665
666         if (autosave_l) do_cmd_save_game(TRUE);
667
668         /* Change level */
669         dun_level = command_arg;
670
671         leave_quest_check();
672
673         if (record_stair) do_cmd_write_nikki(NIKKI_PAT_TELE,0,NULL);
674
675         p_ptr->inside_quest = 0;
676         energy_use = 0;
677
678         /* Leaving */
679         p_ptr->leaving = TRUE;
680 }
681
682
683 static void wreck_the_pattern(void)
684 {
685         int to_ruin = 0, r_y, r_x;
686
687         if (cave[py][px].feat == FEAT_PATTERN_XTRA2)
688         {
689                 /* Ruined already */
690                 return;
691         }
692
693 #ifdef JP
694 msg_print("¥Ñ¥¿¡¼¥ó¤ò·ì¤Ç±ø¤·¤Æ¤·¤Þ¤Ã¤¿¡ª");
695 msg_print("²¿¤«¶²¤í¤·¤¤»ö¤¬µ¯¤³¤Ã¤¿¡ª");
696 #else
697         msg_print("You bleed on the Pattern!");
698         msg_print("Something terrible happens!");
699 #endif
700
701
702         if (!IS_INVULN())
703 #ifdef JP
704                 take_hit(DAMAGE_NOESCAPE, damroll(10, 8), "¥Ñ¥¿¡¼¥ó»²õ", -1);
705 #else
706                 take_hit(DAMAGE_NOESCAPE, damroll(10, 8), "corrupting the Pattern", -1);
707 #endif
708
709
710         to_ruin = randint1(45) + 35;
711
712         while (to_ruin--)
713         {
714                 scatter(&r_y, &r_x, py, px, 4, 0);
715
716                 if ((cave[r_y][r_x].feat >= FEAT_PATTERN_START) &&
717                     (cave[r_y][r_x].feat < FEAT_PATTERN_XTRA2))
718                 {
719                         cave_set_feat(r_y, r_x, FEAT_PATTERN_XTRA2);
720                 }
721         }
722
723         cave_set_feat(py, px, FEAT_PATTERN_XTRA2);
724 }
725
726
727 /* Returns TRUE if we are on the Pattern... */
728 static bool pattern_effect(void)
729 {
730         if ((cave[py][px].feat < FEAT_PATTERN_START) ||
731             (cave[py][px].feat > FEAT_PATTERN_XTRA2))
732                 return FALSE;
733
734         if ((prace_is_(RACE_AMBERITE)) &&
735             (p_ptr->cut > 0) && one_in_(10))
736         {
737                 wreck_the_pattern();
738         }
739
740         if (cave[py][px].feat == FEAT_PATTERN_END)
741         {
742                 (void)set_poisoned(0);
743                 (void)set_image(0);
744                 (void)set_stun(0);
745                 (void)set_cut(0);
746                 (void)set_blind(0);
747                 (void)set_afraid(0);
748                 (void)do_res_stat(A_STR);
749                 (void)do_res_stat(A_INT);
750                 (void)do_res_stat(A_WIS);
751                 (void)do_res_stat(A_DEX);
752                 (void)do_res_stat(A_CON);
753                 (void)do_res_stat(A_CHR);
754                 (void)restore_level();
755                 (void)hp_player(1000);
756                 cave_set_feat(py, px, FEAT_PATTERN_OLD);
757 #ifdef JP
758 msg_print("¡Ö¥Ñ¥¿¡¼¥ó¡×¤Î¤³¤ÎÉôʬ¤Ï¾¤ÎÉôʬ¤è¤ê¶¯ÎϤǤʤ¤¤è¤¦¤À¡£");
759 #else
760                 msg_print("This section of the Pattern looks less powerful.");
761 #endif
762
763         }
764
765
766         /*
767          * We could make the healing effect of the
768          * Pattern center one-time only to avoid various kinds
769          * of abuse, like luring the win monster into fighting you
770          * in the middle of the pattern...
771          */
772
773         else if (cave[py][px].feat == FEAT_PATTERN_OLD)
774         {
775                 /* No effect */
776         }
777         else if (cave[py][px].feat == FEAT_PATTERN_XTRA1)
778         {
779                 pattern_teleport();
780         }
781         else if (cave[py][px].feat == FEAT_PATTERN_XTRA2)
782         {
783                 if (!IS_INVULN())
784 #ifdef JP
785                         take_hit(DAMAGE_NOESCAPE, 200, "²õ¤ì¤¿¡Ö¥Ñ¥¿¡¼¥ó¡×¤òÊ⤤¤¿¥À¥á¡¼¥¸", -1);
786 #else
787                         take_hit(DAMAGE_NOESCAPE, 200, "walking the corrupted Pattern", -1);
788 #endif
789
790         }
791         else
792         {
793                 if ((prace_is_(RACE_AMBERITE)) && !one_in_(2))
794                         return TRUE;
795                 else if (!IS_INVULN())
796 #ifdef JP
797                         take_hit(DAMAGE_NOESCAPE, damroll(1, 3), "¡Ö¥Ñ¥¿¡¼¥ó¡×¤òÊ⤤¤¿¥À¥á¡¼¥¸", -1);
798 #else
799                         take_hit(DAMAGE_NOESCAPE, damroll(1, 3), "walking the Pattern", -1);
800 #endif
801
802         }
803
804         return TRUE;
805 }
806
807
808
809
810
811 /*
812  * Regenerate hit points                                -RAK-
813  */
814 static void regenhp(int percent)
815 {
816         s32b    new_chp, new_chp_frac;
817         int     old_chp;
818
819         if (p_ptr->special_defense & KATA_KOUKIJIN) return;
820         if (p_ptr->action == ACTION_HAYAGAKE) return;
821         /* Save the old hitpoints */
822         old_chp = p_ptr->chp;
823
824         /* Extract the new hitpoints */
825         new_chp = ((long)p_ptr->mhp) * percent + PY_REGEN_HPBASE;
826         p_ptr->chp += (s16b)(new_chp >> 16);   /* div 65536 */
827
828         /* check for overflow */
829         if ((p_ptr->chp < 0) && (old_chp > 0)) p_ptr->chp = MAX_SHORT;
830         new_chp_frac = (new_chp & 0xFFFF) + p_ptr->chp_frac;    /* mod 65536 */
831         if (new_chp_frac >= 0x10000L)
832         {
833                 p_ptr->chp_frac = (u16b)(new_chp_frac - 0x10000L);
834                 p_ptr->chp++;
835         }
836         else
837         {
838                 p_ptr->chp_frac = (u16b)new_chp_frac;
839         }
840
841         /* Fully healed */
842         if (p_ptr->chp >= p_ptr->mhp)
843         {
844                 p_ptr->chp = p_ptr->mhp;
845                 p_ptr->chp_frac = 0;
846         }
847
848         /* Notice changes */
849         if (old_chp != p_ptr->chp)
850         {
851                 /* Redraw */
852                 p_ptr->redraw |= (PR_HP);
853
854                 /* Window stuff */
855                 p_ptr->window |= (PW_PLAYER);
856
857                 wild_regen = 20;
858         }
859 }
860
861
862 /*
863  * Regenerate mana points                               -RAK-
864  */
865 static void regenmana(int percent)
866 {
867         s32b        new_mana, new_mana_frac;
868         int                   old_csp;
869         bool    old_csp_msp = (p_ptr->csp > p_ptr->msp);
870
871         if (p_ptr->special_defense & KATA_KOUKIJIN) return;
872         if ((p_ptr->pclass == CLASS_SAMURAI) && (p_ptr->regenerate)) percent /= 2;
873         old_csp = p_ptr->csp;
874         new_mana = ((long)p_ptr->msp) * percent + PY_REGEN_MNBASE;
875         if (old_csp_msp && (new_mana > 0))
876         {
877                 new_mana *= 32;
878                 p_ptr->csp--;
879                 p_ptr->csp -= (s16b)(new_mana >> 16);   /* div 65536 */
880                 new_mana_frac = p_ptr->csp_frac + 0x10000L - (new_mana & 0xFFFF);
881         }
882         else
883         {
884                 if (old_csp_msp) new_mana += ((((long)p_ptr->msp) * percent + PY_REGEN_MNBASE) * 32);
885                 p_ptr->csp += (s16b)(new_mana >> 16);   /* div 65536 */
886
887                 new_mana_frac = (new_mana & 0xFFFF) + p_ptr->csp_frac;  /* mod 65536 */
888         }
889         if (new_mana_frac >= 0x10000L)
890         {
891                 p_ptr->csp_frac = (u16b)(new_mana_frac - 0x10000L);
892                 p_ptr->csp++;
893         }
894         else
895         {
896                 p_ptr->csp_frac = (u16b)(new_mana_frac);
897         }
898
899         /* check for overflow */
900         if (p_ptr->csp < 0)
901         {
902                 p_ptr->csp = 0;
903                 p_ptr->csp_frac = 0;
904         }
905
906         /* Must set frac to zero even if equal */
907         if ((old_csp_msp && p_ptr->csp < p_ptr->msp) || (!old_csp_msp && p_ptr->csp >= p_ptr->msp))
908         {
909                 p_ptr->csp = p_ptr->msp;
910                 p_ptr->csp_frac = 0;
911         }
912
913         /* Redraw mana */
914         if (old_csp != p_ptr->csp)
915         {
916                 /* Redraw */
917                 p_ptr->redraw |= (PR_MANA);
918
919                 /* Window stuff */
920                 p_ptr->window |= (PW_PLAYER);
921                 p_ptr->window |= (PW_SPELL);
922
923                 wild_regen = 20;
924         }
925 }
926
927
928
929 /*
930  * Regenerate magic
931  */
932 static void regenmagic(int percent)
933 {
934         s32b        new_mana;
935         int i;
936
937         for (i = 0; i < EATER_EXT*2; i++)
938         {
939                 if (!p_ptr->magic_num2[i]) continue;
940                 if (p_ptr->magic_num1[i] == ((long)p_ptr->magic_num2[i] << 16)) continue;
941                 new_mana = ((long)p_ptr->magic_num2[i]+adj_mag_mana[A_INT]+13) * percent / 8;
942                 p_ptr->magic_num1[i] += new_mana;
943
944                 /* Must set frac to zero even if equal */
945                 if (p_ptr->magic_num1[i] > (p_ptr->magic_num2[i] << 16))
946                 {
947                         p_ptr->magic_num1[i] = ((long)p_ptr->magic_num2[i] << 16);
948                 }
949                 wild_regen = 20;
950         }
951         for (i = EATER_EXT*2; i < EATER_EXT*3; i++)
952         {
953                 if (!p_ptr->magic_num1[i]) continue;
954                 if (!p_ptr->magic_num2[i]) continue;
955                 p_ptr->magic_num1[i] -= (long)(p_ptr->magic_num2[i] * (adj_mag_mana[A_INT] + 10)) * EATER_ROD_CHARGE/16;
956                 if (p_ptr->magic_num1[i] < 0) p_ptr->magic_num1[i] = 0;
957                 wild_regen = 20;
958         }
959 }
960
961
962
963
964
965
966 /*
967  * Regenerate the monsters (once per 100 game turns)
968  *
969  * XXX XXX XXX Should probably be done during monster turns.
970  */
971 static void regen_monsters(void)
972 {
973         int i, frac;
974
975
976         /* Regenerate everyone */
977         for (i = 1; i < m_max; i++)
978         {
979                 /* Check the i'th monster */
980                 monster_type *m_ptr = &m_list[i];
981                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
982
983
984                 /* Skip dead monsters */
985                 if (!m_ptr->r_idx) continue;
986
987                 /* Allow regeneration (if needed) */
988                 if (m_ptr->hp < m_ptr->maxhp)
989                 {
990                         /* Hack -- Base regeneration */
991                         frac = m_ptr->maxhp / 100;
992
993                         /* Hack -- Minimal regeneration rate */
994                         if (!frac) if (one_in_(2)) frac = 1;
995
996                         /* Hack -- Some monsters regenerate quickly */
997                         if (r_ptr->flags2 & RF2_REGENERATE) frac *= 2;
998
999                         /* Hack -- Regenerate */
1000                         m_ptr->hp += frac;
1001
1002                         /* Do not over-regenerate */
1003                         if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
1004
1005                         /* Redraw (later) if needed */
1006                         if (p_ptr->health_who == i) p_ptr->redraw |= (PR_HEALTH);
1007                         if (p_ptr->riding == i) p_ptr->redraw |= (PR_UHEALTH);
1008                 }
1009         }
1010 }
1011
1012
1013 /*
1014  * Regenerate the captured monsters (once per 30 game turns)
1015  *
1016  * XXX XXX XXX Should probably be done during monster turns.
1017  */
1018 static void regen_captured_monsters(void)
1019 {
1020         int i, frac;
1021         bool heal = FALSE;
1022
1023         /* Regenerate everyone */
1024         for (i = 0; i < INVEN_TOTAL; i++)
1025         {
1026                 monster_race *r_ptr;
1027                 object_type *o_ptr = &inventory[i];
1028
1029                 if (!o_ptr->k_idx) continue;
1030                 if (o_ptr->tval != TV_CAPTURE) continue;
1031                 if (!o_ptr->pval) continue;
1032
1033                 heal = TRUE;
1034
1035                 r_ptr = &r_info[o_ptr->pval];
1036
1037                 /* Allow regeneration (if needed) */
1038                 if (o_ptr->xtra4 < o_ptr->xtra5)
1039                 {
1040                         /* Hack -- Base regeneration */
1041                         frac = o_ptr->xtra5 / 100;
1042
1043                         /* Hack -- Minimal regeneration rate */
1044                         if (!frac) if (one_in_(2)) frac = 1;
1045
1046                         /* Hack -- Some monsters regenerate quickly */
1047                         if (r_ptr->flags2 & RF2_REGENERATE) frac *= 2;
1048
1049                         /* Hack -- Regenerate */
1050                         o_ptr->xtra4 += frac;
1051
1052                         /* Do not over-regenerate */
1053                         if (o_ptr->xtra4 > o_ptr->xtra5) o_ptr->xtra4 = o_ptr->xtra5;
1054                 }
1055         }
1056
1057         if (heal)
1058         {
1059                 /* Combine pack */
1060                 p_ptr->notice |= (PN_COMBINE);
1061
1062                 /* Window stuff */
1063                 p_ptr->window |= (PW_INVEN);
1064                 p_ptr->window |= (PW_EQUIP);
1065                 wild_regen = 20;
1066         }
1067 }
1068
1069
1070 /*
1071  * Process the counters of monsters (once per 10 game turns)
1072  *
1073  * This function is to process monsters' counters same as player's.
1074  */
1075 static void process_monsters_counters(void)
1076 {
1077         int          m_idx;
1078         monster_type *m_ptr;
1079         monster_race *r_ptr;
1080
1081         u32b noise; /* Hack -- local "player stealth" value */
1082
1083         /* Handle "leaving" */
1084         if (p_ptr->leaving) return;
1085
1086         /* Hack -- calculate the "player noise" */
1087         noise = (1L << (30 - p_ptr->skill_stl));
1088
1089         /* Process the monsters (backwards) */
1090         for (m_idx = m_max - 1; m_idx >= 1; m_idx--)
1091         {
1092                 /* Access the monster */
1093                 m_ptr = &m_list[m_idx];
1094                 r_ptr = &r_info[m_ptr->r_idx];
1095
1096                 /* Ignore "dead" monsters */
1097                 if (!m_ptr->r_idx) continue;
1098
1099                 /* Handle Invulnerability */
1100                 if (m_ptr->invulner)
1101                 {
1102                         /* Reduce by one, note if expires */
1103                         m_ptr->invulner--;
1104
1105                         if (!m_ptr->invulner)
1106                         {
1107                                 if (m_ptr->ml)
1108                                 {
1109                                         char m_name[80];
1110
1111                                         /* Acquire the monster name */
1112                                         monster_desc(m_name, m_ptr, 0);
1113
1114                                         /* Dump a message */
1115 #ifdef JP
1116                                         msg_format("%^s¤Ï¤â¤¦ÌµÅ¨¤Ç¤Ê¤¤¡£", m_name);
1117 #else
1118                                         msg_format("%^s is no longer invulnerable.", m_name);
1119 #endif
1120
1121                                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1122                                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1123                                 }
1124                                 if (!p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
1125                         }
1126                 }
1127
1128                 /* Handle fast */
1129                 if (m_ptr->fast)
1130                 {
1131                         /* Reduce by one, note if expires */
1132                         m_ptr->fast--;
1133
1134                         if (!m_ptr->fast && m_ptr->ml)
1135                         {
1136                                 char m_name[80];
1137
1138                                 /* Acquire the monster name */
1139                                 monster_desc(m_name, m_ptr, 0);
1140
1141                                 /* Dump a message */
1142 #ifdef JP
1143                                 msg_format("%^s¤Ï¤â¤¦²Ã®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
1144 #else
1145                                 msg_format("%^s is no longer fast.", m_name);
1146 #endif
1147
1148                                 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1149                                 if (p_ptr->riding == m_idx)
1150                                 {
1151                                         p_ptr->redraw |= (PR_UHEALTH);
1152                                         p_ptr->update |= (PU_BONUS);
1153                                 }
1154                         }
1155                 }
1156
1157                 /* Handle slow */
1158                 if (m_ptr->slow)
1159                 {
1160                         /* Reduce by one, note if expires */
1161                         m_ptr->slow--;
1162
1163                         if (!m_ptr->slow && m_ptr->ml)
1164                         {
1165                                 char m_name[80];
1166
1167                                 /* Acquire the monster name */
1168                                 monster_desc(m_name, m_ptr, 0);
1169
1170                                 /* Dump a message */
1171 #ifdef JP
1172                                 msg_format("%^s¤Ï¤â¤¦¸ºÂ®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
1173 #else
1174                                 msg_format("%^s is no longer slow.", m_name);
1175 #endif
1176
1177                                 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1178                                 if (p_ptr->riding == m_idx)
1179                                 {
1180                                         p_ptr->redraw |= (PR_UHEALTH);
1181                                         p_ptr->update |= (PU_BONUS);
1182                                 }
1183                         }
1184                 }
1185
1186                 /* Handle "sleep" */
1187                 if (m_ptr->csleep)
1188                 {
1189                         /* Assume does not wake up */
1190                         bool test = FALSE;
1191
1192                         /* Hack -- Require proximity */
1193                         if (m_ptr->cdis < AAF_LIMIT)
1194                         {
1195                                 /* Handle "sensing radius" */
1196                                 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
1197                                 {
1198                                         /* We may wake up */
1199                                         test = TRUE;
1200                                 }
1201
1202                                 /* Handle "sight" and "aggravation" */
1203                                 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
1204                                 {
1205                                         /* We may wake up */
1206                                         test = TRUE;
1207                                 }
1208                         }
1209
1210                         if (test)
1211                         {
1212                                 u32b notice = randint0(1024);
1213
1214                                 /* Nightmare monsters are more alert */
1215                                 if (ironman_nightmare) notice /= 2;
1216
1217                                 /* Hack -- See if monster "notices" player */
1218                                 if ((notice * notice * notice) <= noise)
1219                                 {
1220                                         /* Hack -- amount of "waking" */
1221                                         /* Wake up faster near the player */
1222                                         int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
1223
1224                                         /* Hack -- amount of "waking" is affected by speed of player */
1225                                         d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
1226                                         if (d < 0) d = 1;
1227
1228                                         /* Still asleep */
1229                                         if (m_ptr->csleep > d)
1230                                         {
1231                                                 /* Monster wakes up "a little bit" */
1232                                                 m_ptr->csleep -= d;
1233
1234                                                 /* Notice the "not waking up" */
1235                                                 if (m_ptr->ml)
1236                                                 {
1237                                                         /* Hack -- Count the ignores */
1238                                                         if (r_ptr->r_ignore < MAX_UCHAR)
1239                                                         {
1240                                                                 r_ptr->r_ignore++;
1241                                                         }
1242                                                 }
1243                                         }
1244
1245                                         /* Just woke up */
1246                                         else
1247                                         {
1248                                                 /* Reset sleep counter */
1249                                                 m_ptr->csleep = 0;
1250
1251                                                 if (r_ptr->flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
1252
1253                                                 /* Notice the "waking up" */
1254                                                 if (m_ptr->ml)
1255                                                 {
1256                                                         char m_name[80];
1257
1258                                                         /* Acquire the monster name */
1259                                                         monster_desc(m_name, m_ptr, 0);
1260
1261                                                         /* Dump a message */
1262 #ifdef JP
1263                                                         msg_format("%^s¤¬Ìܤò³Ð¤Þ¤·¤¿¡£", m_name);
1264 #else
1265                                                         msg_format("%^s wakes up.", m_name);
1266 #endif
1267
1268                                                         /* Redraw the health bar */
1269                                                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1270                                                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1271
1272                                                         /* Hack -- Count the wakings */
1273                                                         if (r_ptr->r_wake < MAX_UCHAR)
1274                                                         {
1275                                                                 r_ptr->r_wake++;
1276                                                         }
1277                                                 }
1278                                         }
1279                                 }
1280                         }
1281                 }
1282
1283                 /* Handle "stun" */
1284                 if (m_ptr->stunned)
1285                 {
1286                         int d = 1;
1287
1288                         /* Make a "saving throw" against stun */
1289                         if (randint0(10000) <= r_ptr->level * r_ptr->level)
1290                         {
1291                                 /* Recover fully */
1292                                 d = m_ptr->stunned;
1293                         }
1294
1295                         /* Hack -- Recover from stun */
1296                         if (m_ptr->stunned > d)
1297                         {
1298                                 /* Recover somewhat */
1299                                 m_ptr->stunned -= d;
1300                         }
1301
1302                         /* Fully recover */
1303                         else
1304                         {
1305                                 /* Recover fully */
1306                                 m_ptr->stunned = 0;
1307
1308                                 /* Message if visible */
1309                                 if (m_ptr->ml)
1310                                 {
1311                                         char m_name[80];
1312
1313                                         /* Acquire the monster name */
1314                                         monster_desc(m_name, m_ptr, 0);
1315
1316                                         /* Dump a message */
1317 #ifdef JP
1318                                         msg_format("%^s¤ÏÛ¯Û°¾õÂÖ¤«¤éΩ¤Áľ¤Ã¤¿¡£", m_name);
1319 #else
1320                                         msg_format("%^s is no longer stunned.", m_name);
1321 #endif
1322
1323                                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1324                                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1325                                 }
1326                         }
1327                 }
1328
1329                 /* Handle confusion */
1330                 if (m_ptr->confused)
1331                 {
1332                         /* Amount of "boldness" */
1333                         int d = randint1(r_ptr->level / 20 + 1);
1334
1335                         /* Still confused */
1336                         if (m_ptr->confused > d)
1337                         {
1338                                 /* Reduce the confusion */
1339                                 m_ptr->confused -= d;
1340                         }
1341
1342                         /* Recovered */
1343                         else
1344                         {
1345                                 /* No longer confused */
1346                                 m_ptr->confused = 0;
1347
1348                                 /* Message if visible */
1349                                 if (m_ptr->ml)
1350                                 {
1351                                         char m_name[80];
1352
1353                                         /* Acquire the monster name */
1354                                         monster_desc(m_name, m_ptr, 0);
1355
1356                                         /* Dump a message */
1357 #ifdef JP
1358                                         msg_format("%^s¤Ïº®Í𤫤éΩ¤Áľ¤Ã¤¿¡£", m_name);
1359 #else
1360                                         msg_format("%^s is no longer confused.", m_name);
1361 #endif
1362
1363                                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1364                                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1365                                 }
1366                         }
1367                 }
1368
1369                 /* Handle "fear" */
1370                 if (m_ptr->monfear)
1371                 {
1372                         /* Amount of "boldness" */
1373                         int d = randint1(r_ptr->level / 20 + 1);
1374
1375                         /* Still afraid */
1376                         if (m_ptr->monfear > d)
1377                         {
1378                                 /* Reduce the fear */
1379                                 m_ptr->monfear -= d;
1380                         }
1381
1382                         /* Recover from fear, take note if seen */
1383                         else
1384                         {
1385                                 /* No longer afraid */
1386                                 m_ptr->monfear = 0;
1387
1388                                 /* Visual note */
1389                                 if (m_ptr->ml)
1390                                 {
1391                                         char m_name[80];
1392 #ifndef JP
1393                                         char m_poss[80];
1394
1395                                         /* Acquire the monster possessive */
1396                                         monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
1397 #endif
1398
1399                                         /* Acquire the monster name */
1400                                         monster_desc(m_name, m_ptr, 0);
1401
1402                                         /* Dump a message */
1403 #ifdef JP
1404                                         msg_format("%^s¤Ïͦµ¤¤ò¼è¤êÌᤷ¤¿¡£", m_name);
1405 #else
1406                                         msg_format("%^s recovers %s courage.", m_name, m_poss);
1407 #endif
1408
1409                                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1410                                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1411                                 }
1412                         }
1413                 }
1414         }
1415 }
1416
1417
1418 static void notice_lite_change(object_type *o_ptr)
1419 {
1420         /* Hack -- notice interesting fuel steps */
1421         if ((o_ptr->xtra4 < 100) || (!(o_ptr->xtra4 % 100)))
1422         {
1423                 /* Window stuff */
1424                 p_ptr->window |= (PW_EQUIP);
1425         }
1426
1427         /* Hack -- Special treatment when blind */
1428         if (p_ptr->blind)
1429         {
1430                 /* Hack -- save some light for later */
1431                 if (o_ptr->xtra4 == 0) o_ptr->xtra4++;
1432         }
1433
1434         /* The light is now out */
1435         else if (o_ptr->xtra4 == 0)
1436         {
1437                 disturb(0, 0);
1438 #ifdef JP
1439 msg_print("ÌÀ¤«¤ê¤¬¾Ã¤¨¤Æ¤·¤Þ¤Ã¤¿¡ª");
1440 #else
1441                 msg_print("Your light has gone out!");
1442 #endif
1443                 p_ptr->update |= (PU_BONUS);
1444         }
1445
1446         /* The light is getting dim */
1447         else if (o_ptr->name2 == EGO_LITE_LONG)
1448         {
1449                 if ((o_ptr->xtra4 < 50) && (!(o_ptr->xtra4 % 5))
1450                     && (turn % (TURNS_PER_TICK*2)))
1451                 {
1452                         if (disturb_minor) disturb(0, 0);
1453 #ifdef JP
1454 msg_print("ÌÀ¤«¤ê¤¬Èù¤«¤Ë¤Ê¤Ã¤Æ¤­¤Æ¤¤¤ë¡£");
1455 #else
1456                         msg_print("Your light is growing faint.");
1457 #endif
1458
1459                 }
1460         }
1461
1462         /* The light is getting dim */
1463         else if ((o_ptr->xtra4 < 100) && (!(o_ptr->xtra4 % 10)))
1464         {
1465                 if (disturb_minor) disturb(0, 0);
1466 #ifdef JP
1467 msg_print("ÌÀ¤«¤ê¤¬Èù¤«¤Ë¤Ê¤Ã¤Æ¤­¤Æ¤¤¤ë¡£");
1468 #else
1469                 msg_print("Your light is growing faint.");
1470 #endif
1471
1472         }
1473 }
1474
1475
1476 void leave_quest_check(void)
1477 {
1478         /* Save quest number for dungeon pref file ($LEAVING_QUEST) */
1479         leaving_quest = p_ptr->inside_quest;
1480
1481         /* Leaving an 'only once' quest marks it as failed */
1482         if (leaving_quest &&
1483             ((quest[leaving_quest].flags & QUEST_FLAG_ONCE)  || (quest[leaving_quest].type == QUEST_TYPE_RANDOM)) &&
1484             (quest[leaving_quest].status == QUEST_STATUS_TAKEN))
1485         {
1486                 quest[leaving_quest].status = QUEST_STATUS_FAILED;
1487                 quest[leaving_quest].complev = (byte)p_ptr->lev;
1488                 if (quest[leaving_quest].type == QUEST_TYPE_RANDOM)
1489                 {
1490                         r_info[quest[leaving_quest].r_idx].flags1 &= ~(RF1_QUESTOR);
1491                         if (record_rand_quest)
1492                                 do_cmd_write_nikki(NIKKI_RAND_QUEST_F, leaving_quest, NULL);
1493
1494                         /* Floor of random quest will be blocked */
1495                         prepare_change_floor_mode(CFM_NO_RETURN);
1496                 }
1497                 else if (record_fix_quest)
1498                         do_cmd_write_nikki(NIKKI_FIX_QUEST_F, leaving_quest, NULL);
1499         }
1500 }
1501
1502
1503 /*
1504  * Forcibly pseudo-identify an object in the inventory
1505  * (or on the floor)
1506  *
1507  * note: currently this function allows pseudo-id of any object,
1508  * including silly ones like potions & scrolls, which always
1509  * get '{average}'. This should be changed, either to stop such
1510  * items from being pseudo-id'd, or to allow psychometry to
1511  * detect whether the unidentified potion/scroll/etc is
1512  * good (Cure Light Wounds, Restore Strength, etc) or
1513  * bad (Poison, Weakness etc) or 'useless' (Slime Mold Juice, etc).
1514  */
1515 bool psychometry(void)
1516 {
1517         int             item;
1518         object_type     *o_ptr;
1519         char            o_name[MAX_NLEN];
1520         byte            feel;
1521         cptr            q, s;
1522         bool okay = FALSE;
1523
1524         item_tester_no_ryoute = TRUE;
1525         /* Get an item */
1526 #ifdef JP
1527 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÄ´¤Ù¤Þ¤¹¤«¡©";
1528 s = "Ä´¤Ù¤ë¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
1529 #else
1530         q = "Meditate on which item? ";
1531         s = "You have nothing appropriate.";
1532 #endif
1533
1534         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
1535
1536         /* Get the item (in the pack) */
1537         if (item >= 0)
1538         {
1539                 o_ptr = &inventory[item];
1540         }
1541
1542         /* Get the item (on the floor) */
1543         else
1544         {
1545                 o_ptr = &o_list[0 - item];
1546         }
1547
1548         /* It is fully known, no information needed */
1549         if (object_known_p(o_ptr))
1550         {
1551 #ifdef JP
1552 msg_print("²¿¤â¿·¤·¤¤¤³¤È¤ÏȽ¤é¤Ê¤«¤Ã¤¿¡£");
1553 #else
1554                 msg_print("You cannot find out anything more about that.");
1555 #endif
1556
1557                 return TRUE;
1558         }
1559
1560         /* Check for a feeling */
1561         feel = value_check_aux1(o_ptr);
1562
1563         /* Get an object description */
1564         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1565
1566         /* Skip non-feelings */
1567         if (!feel)
1568         {
1569 #ifdef JP
1570 msg_format("%s¤«¤é¤ÏÆäËÊѤï¤Ã¤¿»ö¤Ï´¶¤¸¤È¤ì¤Ê¤«¤Ã¤¿¡£", o_name);
1571 #else
1572                 msg_format("You do not perceive anything unusual about the %s.", o_name);
1573 #endif
1574
1575                 return TRUE;
1576         }
1577
1578 #ifdef JP
1579 msg_format("%s¤Ï%s¤È¤¤¤¦´¶¤¸¤¬¤¹¤ë...",
1580     o_name,  game_inscriptions[feel]);
1581 #else
1582         msg_format("You feel that the %s %s %s...",
1583                            o_name, ((o_ptr->number == 1) ? "is" : "are"),
1584                            game_inscriptions[feel]);
1585 #endif
1586
1587
1588         /* We have "felt" it */
1589         o_ptr->ident |= (IDENT_SENSE);
1590
1591         /* "Inscribe" it */
1592         o_ptr->feeling = feel;
1593
1594         /* Combine / Reorder the pack (later) */
1595         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
1596
1597         /* Window stuff */
1598         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1599
1600         /* Valid "tval" codes */
1601         switch (o_ptr->tval)
1602         {
1603         case TV_SHOT:
1604         case TV_ARROW:
1605         case TV_BOLT:
1606         case TV_BOW:
1607         case TV_DIGGING:
1608         case TV_HAFTED:
1609         case TV_POLEARM:
1610         case TV_SWORD:
1611         case TV_BOOTS:
1612         case TV_GLOVES:
1613         case TV_HELM:
1614         case TV_CROWN:
1615         case TV_SHIELD:
1616         case TV_CLOAK:
1617         case TV_SOFT_ARMOR:
1618         case TV_HARD_ARMOR:
1619         case TV_DRAG_ARMOR:
1620         case TV_CARD:
1621         case TV_RING:
1622         case TV_AMULET:
1623         case TV_LITE:
1624         case TV_FIGURINE:
1625                 okay = TRUE;
1626                 break;
1627         }
1628
1629         /* Auto-inscription/destroy */
1630         autopick_alter_item(item, (bool)(okay && destroy_feeling));
1631
1632         /* Something happened */
1633         return (TRUE);
1634 }
1635
1636
1637 static void gere_music(s32b music)
1638 {
1639         switch(music)
1640         {
1641                 case MUSIC_SLOW:
1642                         slow_monsters();
1643                         break;
1644                 case MUSIC_STUN:
1645                         stun_monsters(damroll(p_ptr->lev/10,2));
1646                         break;
1647                 case MUSIC_L_LIFE:
1648                         hp_player(damroll(2,6));
1649                         break;
1650                 case MUSIC_FEAR:
1651                         project_hack(GF_TURN_ALL, p_ptr->lev);
1652                         break;
1653                 case MUSIC_PSI:
1654                         project_hack(GF_PSI, randint1(p_ptr->lev * 3 / 2));
1655                         break;
1656                 case MUSIC_ID:
1657                         project(0, 1, py, px, 0, GF_IDENTIFY, PROJECT_ITEM, -1);
1658                         break;
1659                 case MUSIC_CONF:
1660                         confuse_monsters(p_ptr->lev * 2);
1661                         break;
1662                 case MUSIC_SOUND:
1663                         project_hack(GF_SOUND, damroll(10 + p_ptr->lev/5,7));
1664                         break;
1665                 case MUSIC_CHARM:
1666                         charm_monsters(damroll(10 + p_ptr->lev/15,6));
1667                         break;
1668                 case MUSIC_WALL:
1669                         project(0, 0, py, px,
1670                                 0, GF_DISINTEGRATE, PROJECT_KILL | PROJECT_ITEM | PROJECT_HIDE, -1);
1671                         break;
1672                 case MUSIC_DISPEL:
1673                         dispel_monsters(randint1(p_ptr->lev * 3));
1674                         dispel_evil(randint1(p_ptr->lev * 3));
1675                         break;
1676                 case MUSIC_SARUMAN:
1677                         slow_monsters();
1678                         sleep_monsters();
1679                         break;
1680                 case MUSIC_QUAKE:
1681                         earthquake(py, px, 10);
1682                         break;
1683                 case MUSIC_STASIS:
1684                         stasis_monsters(p_ptr->lev * 4);
1685                         break;
1686                 case MUSIC_SHERO:
1687                         dispel_monsters(randint1(p_ptr->lev * 3));
1688                         break;
1689                 case MUSIC_H_LIFE:
1690                         hp_player(damroll(15,10));
1691                         set_stun(0);
1692                         set_cut(0);
1693                         break;
1694                 case MUSIC_DETECT+19:
1695                         wiz_lite(FALSE);
1696                 case MUSIC_DETECT+11:
1697                 case MUSIC_DETECT+12:
1698                 case MUSIC_DETECT+13:
1699                 case MUSIC_DETECT+14:
1700                 case MUSIC_DETECT+15:
1701                 case MUSIC_DETECT+16:
1702                 case MUSIC_DETECT+17:
1703                 case MUSIC_DETECT+18:
1704                         map_area(DETECT_RAD_MAP);
1705                         if ((p_ptr->lev > 39) && (music < MUSIC_DETECT+19)) p_ptr->magic_num1[0] = music+1;
1706                 case MUSIC_DETECT+6:
1707                 case MUSIC_DETECT+7:
1708                 case MUSIC_DETECT+8:
1709                 case MUSIC_DETECT+9:
1710                 case MUSIC_DETECT+10:
1711                         /* There are too many hidden treasure.  So... */
1712                         /* detect_treasure(DETECT_RAD_DEFAULT); */
1713                         detect_objects_gold(DETECT_RAD_DEFAULT);
1714                         detect_objects_normal(DETECT_RAD_DEFAULT);
1715                         if ((p_ptr->lev > 24) && (music < MUSIC_DETECT+11)) p_ptr->magic_num1[0] = music+1;
1716                 case MUSIC_DETECT+3:
1717                 case MUSIC_DETECT+4:
1718                 case MUSIC_DETECT+5:
1719                         detect_monsters_invis(DETECT_RAD_DEFAULT);
1720                         detect_monsters_normal(DETECT_RAD_DEFAULT);
1721                         if ((p_ptr->lev > 19) && (music < MUSIC_DETECT+6)) p_ptr->magic_num1[0] = music+1;
1722                 case MUSIC_DETECT:
1723                 case MUSIC_DETECT+1:
1724                 case MUSIC_DETECT+2:
1725                         detect_traps(DETECT_RAD_DEFAULT, TRUE);
1726                         detect_doors(DETECT_RAD_DEFAULT);
1727                         detect_stairs(DETECT_RAD_DEFAULT);
1728                         if ((p_ptr->lev > 14)  && (music  < MUSIC_DETECT+3)) p_ptr->magic_num1[0] = music+1;
1729                         break;
1730         }
1731 }
1732
1733 /*
1734  * If player has inscribed the object with "!!", let him know when it's
1735  * recharged. -LM-
1736  */
1737 static void recharged_notice(object_type *o_ptr)
1738 {
1739         char o_name[MAX_NLEN];
1740
1741         cptr s;
1742
1743         /* No inscription */
1744         if (!o_ptr->inscription) return;
1745
1746         /* Find a '!' */
1747         s = my_strchr(quark_str(o_ptr->inscription), '!');
1748
1749         /* Process notification request. */
1750         while (s)
1751         {
1752                 /* Find another '!' */
1753                 if (s[1] == '!')
1754                 {
1755                         /* Describe (briefly) */
1756                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1757
1758                         /* Notify the player */
1759 #ifdef JP
1760                         msg_format("%s¤ÏºÆ½¼Å¶¤µ¤ì¤¿¡£", o_name);
1761 #else
1762                         if (o_ptr->number > 1)
1763                                 msg_format("Your %s are recharged.", o_name);
1764                         else
1765                                 msg_format("Your %s is recharged.", o_name);
1766 #endif
1767
1768                         disturb(0, 0);
1769
1770                         /* Done. */
1771                         return;
1772                 }
1773
1774                 /* Keep looking for '!'s */
1775                 s = my_strchr(s + 1, '!');
1776         }
1777 }
1778
1779
1780 static void check_music(void)
1781 {
1782         magic_type *s_ptr;
1783         int spell;
1784         u32b need_mana;
1785
1786         /* Music singed by player */
1787         if (p_ptr->pclass != CLASS_BARD) return;
1788         if (!p_ptr->magic_num1[0] && !p_ptr->magic_num1[1]) return;
1789
1790         spell = p_ptr->magic_num2[0];
1791         s_ptr = &technic_info[REALM_MUSIC - MIN_TECHNIC][spell];
1792
1793         need_mana = mod_need_mana(s_ptr->smana, spell, REALM_MUSIC);
1794         need_mana *= 0x8000;
1795         if (((u32b)p_ptr->csp < (need_mana / 0x10000)) || (p_ptr->anti_magic))
1796         {
1797                 stop_singing();
1798                 return;
1799         }
1800         else
1801         {
1802                 p_ptr->csp -= (u16b) (need_mana / 0x10000);
1803                 need_mana = (need_mana & 0xffff);
1804                 if ((u32b)p_ptr->csp_frac < need_mana)
1805                 {
1806                         p_ptr->csp--;
1807                         p_ptr->csp_frac += (u16b)(0x10000L - need_mana);
1808                 }
1809                 else
1810                 {
1811                         p_ptr->csp_frac -= (u16b)need_mana;
1812                 }
1813
1814                 p_ptr->redraw |= PR_MANA;
1815                 if (p_ptr->magic_num1[1])
1816                 {
1817                         p_ptr->magic_num1[0] = p_ptr->magic_num1[1];
1818                         p_ptr->magic_num1[1] = 0;
1819 #ifdef JP
1820                         msg_print("²Î¤òºÆ³«¤·¤¿¡£");
1821 #else
1822                         msg_print("You restart singing.");
1823 #endif
1824                         p_ptr->action = ACTION_SING;
1825
1826                         /* Recalculate bonuses */
1827                         p_ptr->update |= (PU_BONUS | PU_HP);
1828
1829                         /* Redraw map and status bar */
1830                         p_ptr->redraw |= (PR_MAP | PR_STATUS | PR_STATE);
1831
1832                         /* Update monsters */
1833                         p_ptr->update |= (PU_MONSTERS);
1834
1835                         /* Window stuff */
1836                         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1837                 }
1838         }
1839         if (p_ptr->spell_exp[spell] < SPELL_EXP_BEGINNER)
1840                 p_ptr->spell_exp[spell] += 5;
1841         else if(p_ptr->spell_exp[spell] < SPELL_EXP_SKILLED)
1842         { if (one_in_(2) && (dun_level > 4) && ((dun_level + 10) > p_ptr->lev)) p_ptr->spell_exp[spell] += 1; }
1843         else if(p_ptr->spell_exp[spell] < SPELL_EXP_EXPERT)
1844         { if (one_in_(5) && ((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel)) p_ptr->spell_exp[spell] += 1; }
1845         else if(p_ptr->spell_exp[spell] < SPELL_EXP_MASTER)
1846         { if (one_in_(5) && ((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel)) p_ptr->spell_exp[spell] += 1; }
1847
1848         gere_music(p_ptr->magic_num1[0]);
1849 }
1850
1851 /* Choose one of items that have cursed flag */
1852 static object_type *choose_cursed_obj_name(u32b flag)
1853 {
1854         int i;
1855         int choices[INVEN_TOTAL-INVEN_RARM];
1856         int number = 0;
1857
1858         /* Paranoia -- Player has no warning-item */
1859         if (!(p_ptr->cursed & flag)) return NULL;
1860
1861         /* Search Inventry */
1862         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
1863         {
1864                 object_type *o_ptr = &inventory[i];
1865
1866                 if (o_ptr->curse_flags & flag)
1867                 {
1868                         choices[number] = i;
1869                         number++;
1870                 }
1871         }
1872
1873         /* Choice one of them */
1874         return (&inventory[choices[randint0(number)]]);
1875 }
1876
1877
1878 /*
1879  * Handle certain things once every 10 game turns
1880  */
1881 static void process_world(void)
1882 {
1883         int x, y, i, j;
1884         int regen_amount;
1885         bool cave_no_regen = FALSE;
1886         int upkeep_factor = 0;
1887         cave_type *c_ptr;
1888         object_type *o_ptr;
1889         int temp;
1890         object_kind *k_ptr;
1891         const int dec_count = (easy_band ? 2 : 1);
1892
1893         int day, hour, min, prev_min;
1894
1895         s32b len = TURNS_PER_TICK * TOWN_DAWN;
1896         s32b tick = turn % len + len / 4;
1897
1898         int quest_num = quest_number(dun_level);
1899
1900         extract_day_hour_min(&day, &hour, &min);
1901         prev_min = (1440 * (tick - TURNS_PER_TICK) / len) % 60;
1902
1903         if ((turn - old_turn == (150 - dun_level) * TURNS_PER_TICK)
1904             && dun_level &&
1905             !(quest_num && (is_fixed_quest_idx(quest_num) &&
1906             !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) ||
1907               !(quest[quest_num].flags & QUEST_FLAG_PRESET)))) &&
1908             !p_ptr->inside_battle)
1909         {
1910                 /* Announce feeling */
1911                 do_cmd_feeling();
1912
1913                 /* Update the level indicator */
1914                 p_ptr->redraw |= (PR_DEPTH);
1915
1916                 /* Disturb */
1917                 if (disturb_minor) disturb(0, 0);
1918         }
1919
1920         if (p_ptr->inside_battle && !p_ptr->leaving)
1921         {
1922
1923                 int i2, j2;
1924                 int win_m_idx = 0;
1925                 int number_mon = 0;
1926
1927                 /* Count all hostile monsters */
1928                 for (i2 = 0; i2 < cur_wid; ++i2)
1929                         for (j2 = 0; j2 < cur_hgt; j2++)
1930                                 if ((cave[j2][i2].m_idx > 0) && (cave[j2][i2].m_idx != p_ptr->riding))
1931                                 {
1932                                         number_mon++;
1933                                         win_m_idx = cave[j2][i2].m_idx;
1934                                 }
1935
1936                 if (number_mon == 0)
1937                 {
1938 #ifdef JP
1939 msg_print("ÁêÂǤÁ¤Ë½ª¤ï¤ê¤Þ¤·¤¿¡£");
1940 #else
1941                         msg_print("They have kill each other at the same time.");
1942 #endif
1943                         msg_print(NULL);
1944                         p_ptr->energy_need = 0;
1945                         battle_monsters();
1946                 }
1947                 else if ((number_mon-1) == 0)
1948                 {
1949                         char m_name[80];
1950                         monster_type *wm_ptr;
1951
1952                         wm_ptr = &m_list[win_m_idx];
1953
1954                         monster_desc(m_name, wm_ptr, 0);
1955 #ifdef JP
1956 msg_format("%s¤¬¾¡Íø¤·¤¿¡ª", m_name);
1957 #else
1958                         msg_format("%s is winner!", m_name);
1959 #endif
1960                         msg_print(NULL);
1961
1962                         if (win_m_idx == (sel_monster+1))
1963                         {
1964 #ifdef JP
1965 msg_print("¤ª¤á¤Ç¤È¤¦¤´¤¶¤¤¤Þ¤¹¡£");
1966 #else
1967                                 msg_print("Congratulations.");
1968 #endif
1969 #ifdef JP
1970 msg_format("%d¡ð¤ò¼õ¤±¼è¤Ã¤¿¡£", battle_odds);
1971 #else
1972                                 msg_format("You received %d gold.", battle_odds);
1973 #endif
1974                         p_ptr->au += battle_odds;
1975                         }
1976                         else
1977                         {
1978 #ifdef JP
1979 msg_print("»ÄÇ°¤Ç¤·¤¿¡£");
1980 #else
1981                                 msg_print("You lost gold.");
1982 #endif
1983                         }
1984                         msg_print(NULL);
1985                         p_ptr->energy_need = 0;
1986                         battle_monsters();
1987                 }
1988                 else if(turn - old_turn == 150*TURNS_PER_TICK)
1989                 {
1990 #ifdef JP
1991 msg_print("¿½¤·Ê¬¤±¤¢¤ê¤Þ¤»¤ó¤¬¡¢¤³¤Î¾¡Éé¤Ï°ú¤­Ê¬¤±¤È¤µ¤»¤Æ¤¤¤¿¤À¤­¤Þ¤¹¡£");
1992 #else
1993                         msg_format("This battle have ended in a draw.");
1994 #endif
1995                         p_ptr->au += kakekin;
1996                         msg_print(NULL);
1997                         p_ptr->energy_need = 0;
1998                         battle_monsters();
1999                 }
2000         }
2001
2002         /* Every 10 game turns */
2003         if (turn % TURNS_PER_TICK) return;
2004
2005         /*** Check the Time and Load ***/
2006
2007         if (!(turn % (50*TURNS_PER_TICK)))
2008         {
2009                 /* Check time and load */
2010                 if ((0 != check_time()) || (0 != check_load()))
2011                 {
2012                         /* Warning */
2013                         if (closing_flag <= 2)
2014                         {
2015                                 /* Disturb */
2016                                 disturb(0, 0);
2017
2018                                 /* Count warnings */
2019                                 closing_flag++;
2020
2021                                 /* Message */
2022 #ifdef JP
2023 msg_print("¥¢¥ó¥°¥Ð¥ó¥É¤Ø¤ÎÌ礬ÊĤ¸¤«¤«¤Ã¤Æ¤¤¤Þ¤¹...");
2024 msg_print("¥²¡¼¥à¤ò½ªÎ»¤¹¤ë¤«¥»¡¼¥Ö¤¹¤ë¤«¤·¤Æ²¼¤µ¤¤¡£");
2025 #else
2026                                 msg_print("The gates to ANGBAND are closing...");
2027                                 msg_print("Please finish up and/or save your game.");
2028 #endif
2029
2030                         }
2031
2032                         /* Slam the gate */
2033                         else
2034                         {
2035                                 /* Message */
2036 #ifdef JP
2037 msg_print("º£¡¢¥¢¥ó¥°¥Ð¥ó¥É¤Ø¤ÎÌ礬ÊĤ¶¤µ¤ì¤Þ¤·¤¿¡£");
2038 #else
2039                                 msg_print("The gates to ANGBAND are now closed.");
2040 #endif
2041
2042
2043                                 /* Stop playing */
2044                                 p_ptr->playing = FALSE;
2045
2046                                 /* Leaving */
2047                                 p_ptr->leaving = TRUE;
2048                         }
2049                 }
2050         }
2051
2052         /*** Attempt timed autosave ***/
2053         if (autosave_t && autosave_freq && !p_ptr->inside_battle)
2054         {
2055                 if (!(turn % ((s32b)autosave_freq * TURNS_PER_TICK)))
2056                         do_cmd_save_game(TRUE);
2057         }
2058
2059         if (mon_fight)
2060         {
2061 #ifdef JP
2062                 msg_print("²¿¤«¤¬Ê¹¤³¤¨¤¿¡£");
2063 #else
2064                 msg_print("You hear noise.");
2065 #endif
2066         }
2067
2068         /*** Handle the wilderness/town (sunshine) ***/
2069
2070         /* While in town/wilderness */
2071         if (!dun_level && !p_ptr->inside_quest && !p_ptr->inside_battle && !p_ptr->inside_arena && !p_ptr->wild_mode)
2072         {
2073                 /* Hack -- Daybreak/Nighfall in town */
2074                 if (!(turn % ((TURNS_PER_TICK * TOWN_DAWN) / 2)))
2075                 {
2076                         bool dawn;
2077
2078                         /* Check for dawn */
2079                         dawn = (!(turn % (TURNS_PER_TICK * TOWN_DAWN)));
2080
2081                         /* Day breaks */
2082                         if (dawn)
2083                         {
2084                                 /* Message */
2085 #ifdef JP
2086                                 msg_print("Ì뤬ÌÀ¤±¤¿¡£");
2087 #else
2088                                 msg_print("The sun has risen.");
2089 #endif
2090
2091                                 /* Hack -- Scan the town */
2092                                 for (y = 0; y < cur_hgt; y++)
2093                                 {
2094                                         for (x = 0; x < cur_wid; x++)
2095                                         {
2096                                                 /* Get the cave grid */
2097                                                 c_ptr = &cave[y][x];
2098
2099                                                 /* Assume lit */
2100                                                 c_ptr->info |= (CAVE_GLOW);
2101
2102                                                 /* Hack -- Memorize lit grids if allowed */
2103                                                 if (view_perma_grids) c_ptr->info |= (CAVE_MARK);
2104
2105                                                 /* Hack -- Notice spot */
2106                                                 note_spot(y, x);
2107                                         }
2108                                 }
2109                         }
2110
2111                         /* Night falls */
2112                         else
2113                         {
2114                                 byte feat;
2115
2116                                 /* Message */
2117 #ifdef JP
2118                                 msg_print("Æü¤¬ÄÀ¤ó¤À¡£");
2119 #else
2120                                 msg_print("The sun has fallen.");
2121 #endif
2122
2123                                 /* Hack -- Scan the town */
2124                                 for (y = 0; y < cur_hgt; y++)
2125                                 {
2126                                         for (x = 0; x < cur_wid; x++)
2127                                         {
2128                                                 /* Get the cave grid */
2129                                                 c_ptr = &cave[y][x];
2130
2131                                                 /* Feature code (applying "mimic" field) */
2132                                                 feat = get_feat_mimic(c_ptr);
2133
2134                                                 if (!is_mirror_grid(c_ptr) && (feat != FEAT_QUEST_ENTER) && (feat != FEAT_ENTRANCE))
2135                                                 {
2136                                                         /* Assume dark */
2137                                                         c_ptr->info &= ~(CAVE_GLOW);
2138
2139                                                         if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
2140                                                         {
2141                                                                 /* Forget the normal floor grid */
2142                                                                 c_ptr->info &= ~(CAVE_MARK);
2143
2144                                                                 /* Hack -- Notice spot */
2145                                                                 note_spot(y, x);
2146                                                         }
2147                                                 }
2148                                         }
2149
2150                                         /* Glow deep lava and building entrances */
2151                                         glow_deep_lava_and_bldg();
2152                                 }
2153                         }
2154
2155                         /* Update the monsters */
2156                         p_ptr->update |= (PU_MONSTERS | PU_MON_LITE);
2157
2158                         /* Redraw map */
2159                         p_ptr->redraw |= (PR_MAP);
2160
2161                         /* Window stuff */
2162                         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2163                 }
2164         }
2165
2166         /* While in the dungeon (vanilla_town or lite_town mode only) */
2167         else if ((vanilla_town || (lite_town && !p_ptr->inside_quest && !p_ptr->inside_battle && !p_ptr->inside_arena)) && dun_level)
2168         {
2169                 /*** Shuffle the Storekeepers ***/
2170
2171                 /* Chance is only once a day (while in dungeon) */
2172                 if (!(turn % (TURNS_PER_TICK * STORE_TICKS)))
2173                 {
2174                         /* Sometimes, shuffle the shop-keepers */
2175                         if (one_in_(STORE_SHUFFLE))
2176                         {
2177                                 int n;
2178
2179                                 /* Pick a random shop (except home) */
2180                                 do
2181                                 {
2182                                         n = randint0(MAX_STORES);
2183                                 }
2184                                 while ((n == STORE_HOME) || (n == STORE_MUSEUM));
2185
2186                                 /* Message */
2187 #ifdef JP
2188                                 if (cheat_xtra) msg_format("%s¤ÎŹ¼ç¤ò¥·¥ã¥Ã¥Õ¥ë¤·¤Þ¤¹¡£", f_name + f_info[FEAT_SHOP_HEAD + n].name);
2189 #else
2190                                 if (cheat_xtra) msg_format("Shuffle a Shopkeeper of %s.", f_name + f_info[FEAT_SHOP_HEAD + n].name);
2191 #endif
2192
2193                                 /* Shuffle it */
2194                                 store_shuffle(n);
2195                         }
2196                 }
2197         }
2198
2199
2200         /*** Process the monsters ***/
2201
2202         /* Check for creature generation. */
2203         if (one_in_(d_info[dungeon_type].max_m_alloc_chance) &&
2204             !p_ptr->inside_arena && !p_ptr->inside_quest && !p_ptr->inside_battle)
2205         {
2206                 /* Make a new monster */
2207                 (void)alloc_monster(MAX_SIGHT + 5, 0);
2208         }
2209
2210         /* Hack -- Check for creature regeneration */
2211         if (!(turn % (TURNS_PER_TICK*10)) && !p_ptr->inside_battle) regen_monsters();
2212         if (!(turn % (TURNS_PER_TICK*3))) regen_captured_monsters();
2213
2214         /* Hack -- Process the counters of all monsters */
2215         process_monsters_counters();
2216
2217
2218         /*** Damage over Time ***/
2219
2220         /* Take damage from poison */
2221         if (p_ptr->poisoned && !IS_INVULN())
2222         {
2223                 /* Take damage */
2224 #ifdef JP
2225                 take_hit(DAMAGE_NOESCAPE, 1, "ÆÇ", -1);
2226 #else
2227                 take_hit(DAMAGE_NOESCAPE, 1, "poison", -1);
2228 #endif
2229
2230         }
2231
2232
2233         /* (Vampires) Take damage from sunlight */
2234         if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE))
2235         {
2236                 if (!dun_level && !p_ptr->resist_lite && !IS_INVULN() && is_daytime())
2237                 {
2238                         if ((cave[py][px].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
2239                         {
2240                                 /* Take damage */
2241 #ifdef JP
2242 msg_print("Æü¸÷¤¬¤¢¤Ê¤¿¤Î¥¢¥ó¥Ç¥Ã¥É¤ÎÆùÂΤò¾Æ¤­¾Ç¤¬¤·¤¿¡ª");
2243 take_hit(DAMAGE_NOESCAPE, 1, "Æü¸÷", -1);
2244 #else
2245                                 msg_print("The sun's rays scorch your undead flesh!");
2246                                 take_hit(DAMAGE_NOESCAPE, 1, "sunlight", -1);
2247 #endif
2248
2249                                 cave_no_regen = TRUE;
2250                         }
2251                 }
2252
2253                 if (inventory[INVEN_LITE].tval && (inventory[INVEN_LITE].name2 != EGO_LITE_DARKNESS) &&
2254                     !p_ptr->resist_lite)
2255                 {
2256                         object_type * o_ptr = &inventory[INVEN_LITE];
2257                         char o_name [MAX_NLEN];
2258                         char ouch [MAX_NLEN+40];
2259
2260                         /* Get an object description */
2261                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2262
2263 #ifdef JP
2264 msg_format("%s¤¬¤¢¤Ê¤¿¤Î¥¢¥ó¥Ç¥Ã¥É¤ÎÆùÂΤò¾Æ¤­¾Ç¤¬¤·¤¿¡ª", o_name);
2265 #else
2266                         msg_format("The %s scorches your undead flesh!", o_name);
2267 #endif
2268
2269
2270                         cave_no_regen = TRUE;
2271
2272                         /* Get an object description */
2273                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2274
2275 #ifdef JP
2276 sprintf(ouch, "%s¤òÁõÈ÷¤·¤¿¥À¥á¡¼¥¸", o_name);
2277 #else
2278                         sprintf(ouch, "wielding %s", o_name);
2279 #endif
2280
2281                         if (!IS_INVULN()) take_hit(DAMAGE_NOESCAPE, 1, ouch, -1);
2282                 }
2283         }
2284
2285         if ((cave[py][px].feat == FEAT_SHAL_LAVA) &&
2286                 !IS_INVULN() && !p_ptr->immune_fire && !p_ptr->ffall)
2287         {
2288                 int damage = 3000 + randint0(2000);
2289
2290                 if (prace_is_(RACE_ENT)) damage += damage/3;
2291                 if (p_ptr->resist_fire) damage = damage / 3;
2292                 if (IS_OPPOSE_FIRE()) damage = damage / 3;
2293                 damage = damage / 100 + (randint0(100) < (damage % 100));
2294
2295                 if (damage)
2296                 {
2297                         /* Take damage */
2298 #ifdef JP
2299 msg_print("ÍÏ´ä¤Ç²Ð½ý¤·¤¿¡ª");
2300 take_hit(DAMAGE_NOESCAPE, damage, "Àõ¤¤ÍÏ´äή", -1);
2301 #else
2302                         msg_print("The lava burns you!");
2303                         take_hit(DAMAGE_NOESCAPE, damage, "shallow lava", -1);
2304 #endif
2305
2306                         cave_no_regen = TRUE;
2307                 }
2308         }
2309
2310         else if ((cave[py][px].feat == FEAT_DEEP_LAVA) &&
2311                 !IS_INVULN() && !p_ptr->immune_fire)
2312         {
2313                 int damage = 6000 + randint0(4000);
2314
2315                 cptr message;
2316                 cptr hit_from;
2317
2318                 if (p_ptr->resist_fire) damage = damage / 3;
2319                 if (IS_OPPOSE_FIRE()) damage = damage / 3;
2320
2321                 if (p_ptr->ffall)
2322                 {
2323                         damage = damage / 5;
2324
2325 #ifdef JP
2326 message = "Ç®¤Ç²Ð½ý¤·¤¿¡ª";
2327 hit_from = "¿¼¤¤ÍÏ´äή¤Î¾å¤ËÉâÍ·¤·¤¿¥À¥á¡¼¥¸";
2328 #else
2329                         message = "The heat burns you!";
2330                         hit_from = "flying over deep lava";
2331 #endif
2332
2333                 }
2334                 else
2335                 {
2336 #ifdef JP
2337 message = "ÍÏ´ä¤Ç²Ð½ý¤·¤¿¡ª";
2338 hit_from = "¿¼¤¤ÍÏ´äή";
2339 #else
2340                         message = "The lava burns you!";
2341                         hit_from = "deep lava";
2342 #endif
2343
2344                 }
2345
2346                 damage = damage / 100 + (randint0(100) < (damage % 100));
2347                 if (damage)
2348                 {
2349                         /* Take damage */
2350                         msg_print(message);
2351                         take_hit(DAMAGE_NOESCAPE, damage, hit_from, -1);
2352
2353                         cave_no_regen = TRUE;
2354                 }
2355         }
2356
2357         else if ((cave[py][px].feat == FEAT_DEEP_WATER) && !p_ptr->ffall && !p_ptr->can_swim)
2358         {
2359                 if (p_ptr->total_weight > (((u32b)adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) / 2))
2360                 {
2361                         /* Take damage */
2362 #ifdef JP
2363 msg_print("Å®¤ì¤Æ¤¤¤ë¡ª");
2364 take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->lev), "Å®¤ì", -1);
2365 #else
2366                         msg_print("You are drowning!");
2367                         take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->lev), "drowning", -1);
2368 #endif
2369
2370                         cave_no_regen = TRUE;
2371                 }
2372         }
2373
2374         if (p_ptr->riding)
2375         {
2376                 int damage;
2377                 if ((r_info[m_list[p_ptr->riding].r_idx].flags2 & RF2_AURA_FIRE) && !p_ptr->immune_fire)
2378                 {
2379                         damage = r_info[m_list[p_ptr->riding].r_idx].level / 2;
2380                         if (prace_is_(RACE_ENT)) damage += damage / 3;
2381                         if (p_ptr->resist_fire) damage = damage / 3;
2382                         if (IS_OPPOSE_FIRE()) damage = damage / 3;
2383 #ifdef JP
2384 msg_print("Ç®¤¤¡ª");
2385 take_hit(DAMAGE_NOESCAPE, damage, "±ê¤Î¥ª¡¼¥é", -1);
2386 #else
2387                         msg_print("It's hot!");
2388                         take_hit(DAMAGE_NOESCAPE, damage, "Fire aura", -1);
2389 #endif
2390                 }
2391                 if ((r_info[m_list[p_ptr->riding].r_idx].flags2 & RF2_AURA_ELEC) && !p_ptr->immune_elec)
2392                 {
2393                         damage = r_info[m_list[p_ptr->riding].r_idx].level / 2;
2394                         if (prace_is_(RACE_ANDROID)) damage += damage / 3;
2395                         if (p_ptr->resist_elec) damage = damage / 3;
2396                         if (IS_OPPOSE_ELEC()) damage = damage / 3;
2397 #ifdef JP
2398 msg_print("Äˤ¤¡ª");
2399 take_hit(DAMAGE_NOESCAPE, damage, "Åŵ¤¤Î¥ª¡¼¥é", -1);
2400 #else
2401                         msg_print("It hurts!");
2402                         take_hit(DAMAGE_NOESCAPE, damage, "Elec aura", -1);
2403 #endif
2404                 }
2405                 if ((r_info[m_list[p_ptr->riding].r_idx].flags3 & RF3_AURA_COLD) && !p_ptr->immune_cold)
2406                 {
2407                         damage = r_info[m_list[p_ptr->riding].r_idx].level / 2;
2408                         if (p_ptr->resist_cold) damage = damage / 3;
2409                         if (IS_OPPOSE_COLD()) damage = damage / 3;
2410 #ifdef JP
2411 msg_print("Î䤿¤¤¡ª");
2412 take_hit(DAMAGE_NOESCAPE, damage, "Î䵤¤Î¥ª¡¼¥é", -1);
2413 #else
2414                         msg_print("It's cold!");
2415                         take_hit(DAMAGE_NOESCAPE, damage, "Cold aura", -1);
2416 #endif
2417                 }
2418         }
2419
2420         /* Spectres -- take damage when moving through walls */
2421         /*
2422          * Added: ANYBODY takes damage if inside through walls
2423          * without wraith form -- NOTE: Spectres will never be
2424          * reduced below 0 hp by being inside a stone wall; others
2425          * WILL BE!
2426          */
2427         if (!cave_floor_bold(py, px))
2428         {
2429                 /* Player can walk through trees */
2430                 if ((cave[py][px].feat == FEAT_TREES) || ((cave[py][px].feat == FEAT_MOUNTAIN) && !dun_level && p_ptr->ffall))
2431                 {
2432                         /* Do nothing */
2433                 }
2434                 else if (!IS_INVULN() && !p_ptr->wraith_form && !p_ptr->kabenuke &&
2435                     ((p_ptr->chp > (p_ptr->lev / 5)) || !p_ptr->pass_wall))
2436                 {
2437                         cptr dam_desc;
2438
2439                         cave_no_regen = TRUE;
2440
2441                         if (p_ptr->pass_wall)
2442                         {
2443 #ifdef JP
2444 msg_print("ÂΤÎʬ»Ò¤¬Ê¬²ò¤·¤¿µ¤¤¬¤¹¤ë¡ª");
2445 dam_desc = "Ì©ÅÙ";
2446 #else
2447                                 msg_print("Your molecules feel disrupted!");
2448                                 dam_desc = "density";
2449 #endif
2450
2451                         }
2452                         else
2453                         {
2454 #ifdef JP
2455 msg_print("Êø¤ì¤¿´ä¤Ë²¡¤·ÄÙ¤µ¤ì¤¿¡ª");
2456 dam_desc = "¹Å¤¤´ä";
2457 #else
2458                                 msg_print("You are being crushed!");
2459                                 dam_desc = "solid rock";
2460 #endif
2461
2462                         }
2463
2464                         take_hit(DAMAGE_NOESCAPE, 1 + (p_ptr->lev / 5), dam_desc, -1);
2465                 }
2466         }
2467
2468         if (!hour && !min)
2469         {
2470                 if (min != prev_min)
2471                 {
2472                         do_cmd_write_nikki(NIKKI_HIGAWARI, 0, NULL);
2473                         determine_today_mon(FALSE);
2474                 }
2475         }
2476
2477         /* Nightmare mode activates the TY_CURSE at midnight */
2478         if (ironman_nightmare)
2479         {
2480                 /* Require exact minute */
2481                 if (min != prev_min)
2482                 {
2483                         /* Every 15 minutes after 11:00 pm */
2484                         if ((hour == 23) && !(min % 15))
2485                         {
2486                                 /* Disturbing */
2487                                 disturb(0, 0);
2488
2489                                 switch (min / 15)
2490                                 {
2491                                         case 0:
2492                                         {
2493 #ifdef JP
2494 msg_print("±ó¤¯¤ÇÉÔµ¤Ì£¤Ê¾â¤Î²»¤¬ÌĤä¿¡£");
2495 #else
2496                                                 msg_print("You hear a distant bell toll ominously.");
2497 #endif
2498
2499                                                 break;
2500                                         }
2501                                         case 1:
2502                                         {
2503 #ifdef JP
2504 msg_print("±ó¤¯¤Ç¾â¤¬Æó²óÌĤä¿¡£");
2505 #else
2506                                                 msg_print("A distant bell sounds twice.");
2507 #endif
2508
2509                                                 break;
2510                                         }
2511                                         case 2:
2512         {
2513 #ifdef JP
2514 msg_print("±ó¤¯¤Ç¾â¤¬»°²óÌĤä¿¡£");
2515 #else
2516                                                 msg_print("A distant bell sounds three times.");
2517 #endif
2518
2519                                                 break;
2520                                         }
2521                                         case 3:
2522                                         {
2523 #ifdef JP
2524 msg_print("±ó¤¯¤Ç¾â¤¬»Í²óÌĤä¿¡£");
2525 #else
2526                                                 msg_print("A distant bell tolls four times.");
2527 #endif
2528
2529                                                 break;
2530                                         }
2531                                 }
2532                         }
2533
2534                         /* TY_CURSE activates at mignight! */
2535                         if (!hour && !min)
2536                         {
2537                                 int count = 0;
2538
2539                                 disturb(1, 0);
2540 #ifdef JP
2541 msg_print("±ó¤¯¤Ç¾â¤¬²¿²ó¤âÌĤꡢ»à¤ó¤À¤è¤¦¤ÊÀŤ±¤µ¤ÎÃæ¤Ø¾Ã¤¨¤Æ¤¤¤Ã¤¿¡£");
2542 #else
2543                                 msg_print("A distant bell tolls many times, fading into an deathly silence.");
2544 #endif
2545
2546                 activate_ty_curse(FALSE, &count);
2547         }
2548                 }
2549         }
2550
2551         /* Take damage from cuts */
2552         if (p_ptr->cut && !IS_INVULN())
2553         {
2554                 /* Mortal wound or Deep Gash */
2555                 if (p_ptr->cut > 1000)
2556                 {
2557                         i = 200;
2558                 }
2559
2560                 else if (p_ptr->cut > 200)
2561                 {
2562                         i = 80;
2563                 }
2564
2565                 /* Severe cut */
2566                 else if (p_ptr->cut > 100)
2567                 {
2568                         i = 32;
2569                 }
2570
2571                 else if (p_ptr->cut > 50)
2572                 {
2573                         i = 16;
2574                 }
2575
2576                 else if (p_ptr->cut > 25)
2577                 {
2578                         i = 7;
2579                 }
2580
2581                 else if (p_ptr->cut > 10)
2582                 {
2583                         i = 3;
2584                 }
2585
2586                 /* Other cuts */
2587                 else
2588                 {
2589                         i = 1;
2590                 }
2591
2592                 /* Take damage */
2593 #ifdef JP
2594 take_hit(DAMAGE_NOESCAPE, i, "Ã×Ì¿½ý", -1);
2595 #else
2596                 take_hit(DAMAGE_NOESCAPE, i, "a fatal wound", -1);
2597 #endif
2598
2599         }
2600
2601
2602         /*** Check the Food, and Regenerate ***/
2603
2604         if (!p_ptr->inside_battle)
2605         {
2606                 /* Digest normally */
2607                 if (p_ptr->food < PY_FOOD_MAX)
2608                 {
2609                         /* Every 50 game turns */
2610                         if (!(turn % (TURNS_PER_TICK*5)))
2611                         {
2612                                 /* Basic digestion rate based on speed */
2613                                 i = SPEED_TO_ENERGY(p_ptr->pspeed);
2614
2615                                 /* Regeneration takes more food */
2616                                 if (p_ptr->regenerate) i += 20;
2617                                 if (p_ptr->special_defense & (KAMAE_MASK | KATA_MASK)) i+= 20;
2618                                 if (p_ptr->cursed & TRC_FAST_DIGEST) i += 30;
2619
2620                                 /* Slow digestion takes less food */
2621                                 if (p_ptr->slow_digest) i -= 5;
2622
2623                                 /* Minimal digestion */
2624                                 if (i < 1) i = 1;
2625                                 /* Maximal digestion */
2626                                 if (i > 100) i = 100;
2627
2628                                 /* Digest some food */
2629                                 (void)set_food(p_ptr->food - i);
2630                         }
2631                 }
2632
2633                 /* Digest quickly when gorged */
2634                 else
2635                 {
2636                         /* Digest a lot of food */
2637                         (void)set_food(p_ptr->food - 100);
2638                 }
2639         }
2640
2641         /* Starve to death (slowly) */
2642         if (p_ptr->food < PY_FOOD_STARVE)
2643         {
2644                 /* Calculate damage */
2645                 i = (PY_FOOD_STARVE - p_ptr->food) / 10;
2646
2647                 /* Take damage */
2648 #ifdef JP
2649                 if (!IS_INVULN()) take_hit(DAMAGE_LOSELIFE, i, "¶õÊ¢", -1);
2650 #else
2651                 if (!IS_INVULN()) take_hit(DAMAGE_LOSELIFE, i, "starvation", -1);
2652 #endif
2653
2654         }
2655
2656         /* Default regeneration */
2657         regen_amount = PY_REGEN_NORMAL;
2658
2659         /* Getting Weak */
2660         if (p_ptr->food < PY_FOOD_WEAK)
2661         {
2662                 /* Lower regeneration */
2663                 if (p_ptr->food < PY_FOOD_STARVE)
2664                 {
2665                         regen_amount = 0;
2666                 }
2667                 else if (p_ptr->food < PY_FOOD_FAINT)
2668                 {
2669                         regen_amount = PY_REGEN_FAINT;
2670                 }
2671                 else
2672                 {
2673                         regen_amount = PY_REGEN_WEAK;
2674                 }
2675
2676                 /* Getting Faint */
2677                 if ((p_ptr->food < PY_FOOD_FAINT) && !p_ptr->inside_battle)
2678                 {
2679                         /* Faint occasionally */
2680                         if (!p_ptr->paralyzed && (randint0(100) < 10))
2681                         {
2682                                 /* Message */
2683 #ifdef JP
2684 msg_print("¤¢¤Þ¤ê¤Ë¤â¶õÊ¢¤Çµ¤À䤷¤Æ¤·¤Þ¤Ã¤¿¡£");
2685 #else
2686                                 msg_print("You faint from the lack of food.");
2687 #endif
2688
2689                                 disturb(1, 0);
2690
2691                                 /* Hack -- faint (bypass free action) */
2692                                 (void)set_paralyzed(p_ptr->paralyzed + 1 + randint0(5));
2693                         }
2694                 }
2695         }
2696
2697
2698         /* Are we walking the pattern? */
2699         if (pattern_effect())
2700         {
2701                 cave_no_regen = TRUE;
2702         }
2703         else
2704         {
2705                 /* Regeneration ability */
2706                 if (p_ptr->regenerate)
2707                 {
2708                         regen_amount = regen_amount * 2;
2709                 }
2710                 if (p_ptr->special_defense & (KAMAE_MASK | KATA_MASK))
2711                 {
2712                         regen_amount /= 2;
2713                 }
2714                 if (p_ptr->cursed & TRC_SLOW_REGEN)
2715                 {
2716                         regen_amount /= 5;
2717                 }
2718         }
2719
2720
2721         /* Searching or Resting */
2722         if ((p_ptr->action == ACTION_SEARCH) || (p_ptr->action == ACTION_REST))
2723         {
2724                 regen_amount = regen_amount * 2;
2725         }
2726
2727         upkeep_factor = calculate_upkeep();
2728
2729         /* Regenerate the mana */
2730 /*      if (p_ptr->csp < p_ptr->msp) */
2731         {
2732                 if (upkeep_factor)
2733                 {
2734                         s32b upkeep_regen = ((100 - upkeep_factor) * regen_amount);
2735                         if ((p_ptr->action == ACTION_LEARN) || (p_ptr->action == ACTION_HAYAGAKE)) upkeep_regen -= regen_amount;
2736                         regenmana(upkeep_regen/100);
2737
2738 #ifdef TRACK_FRIENDS
2739                         if (p_ptr->wizard)
2740                         {
2741 #ifdef JP
2742 msg_format("£Í£Ð²óÉü: %d/%d", upkeep_regen, regen_amount);
2743 #else
2744                                 msg_format("Regen: %d/%d", upkeep_regen, regen_amount);
2745 #endif
2746
2747                         }
2748 #endif /* TRACK_FRIENDS */
2749
2750                 }
2751                 else if (p_ptr->action != ACTION_LEARN)
2752                 {
2753                         regenmana(regen_amount);
2754                 }
2755         }
2756         if (p_ptr->pclass == CLASS_MAGIC_EATER)
2757         {
2758                 regenmagic(regen_amount);
2759         }
2760
2761         if ((p_ptr->csp == 0) && (p_ptr->csp_frac == 0))
2762         {
2763                 while (upkeep_factor > 100)
2764                 {
2765 #ifdef JP
2766 msg_print("¤³¤ó¤Ê¤Ë¿¤¯¤Î¥Ú¥Ã¥È¤òÀ©¸æ¤Ç¤­¤Ê¤¤¡ª");
2767 #else
2768                         msg_print("Such much pets cannot be controled at once!");
2769 #endif
2770                         msg_print(NULL);
2771                         do_cmd_pet_dismiss();
2772
2773                         upkeep_factor = calculate_upkeep();
2774
2775 #ifdef JP
2776                         msg_format("°Ý»ý£Í£Ð¤Ï %d%%", upkeep_factor);
2777 #else
2778                         msg_format("Upkeep: %d%% mana.", upkeep_factor);
2779 #endif
2780                         msg_print(NULL);
2781                 }
2782         }
2783
2784         /* Poisoned or cut yields no healing */
2785         if (p_ptr->poisoned) regen_amount = 0;
2786         if (p_ptr->cut) regen_amount = 0;
2787
2788         /* Special floor -- Pattern, in a wall -- yields no healing */
2789         if (cave_no_regen) regen_amount = 0;
2790
2791         regen_amount = (regen_amount * mutant_regenerate_mod) / 100;
2792
2793         /* Regenerate Hit Points if needed */
2794         if ((p_ptr->chp < p_ptr->mhp) && !cave_no_regen)
2795         {
2796                 if ((cave[py][px].feat < FEAT_PATTERN_END) &&
2797                     (cave[py][px].feat >= FEAT_PATTERN_START))
2798                 {
2799                         regenhp(regen_amount / 5); /* Hmmm. this should never happen? */
2800                 }
2801                 else
2802                 {
2803                         regenhp(regen_amount);
2804                 }
2805         }
2806
2807
2808         /*** Timeout Various Things ***/
2809
2810         /* Mimic */
2811         if (p_ptr->tim_mimic)
2812         {
2813                 (void)set_mimic(p_ptr->tim_mimic - 1, p_ptr->mimic_form, TRUE);
2814         }
2815
2816         /* Hack -- Hallucinating */
2817         if (p_ptr->image)
2818         {
2819                 (void)set_image(p_ptr->image - dec_count);
2820         }
2821
2822         /* Blindness */
2823         if (p_ptr->blind)
2824         {
2825                 (void)set_blind(p_ptr->blind - dec_count);
2826         }
2827
2828         /* Times see-invisible */
2829         if (p_ptr->tim_invis)
2830         {
2831                 (void)set_tim_invis(p_ptr->tim_invis - 1, TRUE);
2832         }
2833
2834         if (multi_rew)
2835         {
2836                 multi_rew = FALSE;
2837         }
2838
2839         /* Timed esp */
2840         if (p_ptr->tim_esp)
2841         {
2842                 (void)set_tim_esp(p_ptr->tim_esp - 1, TRUE);
2843         }
2844
2845         /* Timed temporary elemental brands. -LM- */
2846         if (p_ptr->ele_attack)
2847         {
2848                 p_ptr->ele_attack--;
2849
2850                 /* Clear all temporary elemental brands. */
2851                 if (!p_ptr->ele_attack) set_ele_attack(0, 0);
2852         }
2853
2854         /* Timed temporary elemental immune. -LM- */
2855         if (p_ptr->ele_immune)
2856         {
2857                 p_ptr->ele_immune--;
2858
2859                 /* Clear all temporary elemental brands. */
2860                 if (!p_ptr->ele_immune) set_ele_immune(0, 0);
2861         }
2862
2863         /* Timed infra-vision */
2864         if (p_ptr->tim_infra)
2865         {
2866                 (void)set_tim_infra(p_ptr->tim_infra - 1, TRUE);
2867         }
2868
2869         /* Timed stealth */
2870         if (p_ptr->tim_stealth)
2871         {
2872                 (void)set_tim_stealth(p_ptr->tim_stealth - 1, TRUE);
2873         }
2874
2875         /* Timed levitation */
2876         if (p_ptr->tim_ffall)
2877         {
2878                 (void)set_tim_ffall(p_ptr->tim_ffall - 1, TRUE);
2879         }
2880
2881         /* Timed sh_touki */
2882         if (p_ptr->tim_sh_touki)
2883         {
2884                 (void)set_tim_sh_touki(p_ptr->tim_sh_touki - 1, TRUE);
2885         }
2886
2887         /* Timed sh_fire */
2888         if (p_ptr->tim_sh_fire)
2889         {
2890                 (void)set_tim_sh_fire(p_ptr->tim_sh_fire - 1, TRUE);
2891         }
2892
2893         /* Timed sh_holy */
2894         if (p_ptr->tim_sh_holy)
2895         {
2896                 (void)set_tim_sh_holy(p_ptr->tim_sh_holy - 1, TRUE);
2897         }
2898
2899         /* Timed eyeeye */
2900         if (p_ptr->tim_eyeeye)
2901         {
2902                 (void)set_tim_eyeeye(p_ptr->tim_eyeeye - 1, TRUE);
2903         }
2904
2905         /* Timed resist-magic */
2906         if (p_ptr->resist_magic)
2907         {
2908                 (void)set_resist_magic(p_ptr->resist_magic - 1, TRUE);
2909         }
2910
2911         /* Timed regeneration */
2912         if (p_ptr->tim_regen)
2913         {
2914                 (void)set_tim_regen(p_ptr->tim_regen - 1, TRUE);
2915         }
2916
2917         /* Timed resist nether */
2918         if (p_ptr->tim_res_nether)
2919         {
2920                 (void)set_tim_res_nether(p_ptr->tim_res_nether - 1, TRUE);
2921         }
2922
2923         /* Timed resist time */
2924         if (p_ptr->tim_res_time)
2925         {
2926                 (void)set_tim_res_time(p_ptr->tim_res_time - 1, TRUE);
2927         }
2928
2929         /* Timed reflect */
2930         if (p_ptr->tim_reflect)
2931         {
2932                 (void)set_tim_reflect(p_ptr->tim_reflect - 1, TRUE);
2933         }
2934
2935         /* Multi-shadow */
2936         if (p_ptr->multishadow)
2937         {
2938                 (void)set_multishadow(p_ptr->multishadow - 1, TRUE);
2939         }
2940
2941         /* Timed Robe of dust */
2942         if (p_ptr->dustrobe)
2943         {
2944                 (void)set_dustrobe(p_ptr->dustrobe - 1, TRUE);
2945         }
2946
2947         /* Timed infra-vision */
2948         if (p_ptr->kabenuke)
2949         {
2950                 (void)set_kabenuke(p_ptr->kabenuke - 1, TRUE);
2951         }
2952
2953         /* Paralysis */
2954         if (p_ptr->paralyzed)
2955         {
2956                 (void)set_paralyzed(p_ptr->paralyzed - dec_count);
2957         }
2958
2959         /* Confusion */
2960         if (p_ptr->confused)
2961         {
2962                 (void)set_confused(p_ptr->confused - dec_count);
2963         }
2964
2965         /* Afraid */
2966         if (p_ptr->afraid)
2967         {
2968                 (void)set_afraid(p_ptr->afraid - dec_count);
2969         }
2970
2971         /* Fast */
2972         if (p_ptr->fast)
2973         {
2974                 (void)set_fast(p_ptr->fast - 1, TRUE);
2975         }
2976
2977         /* Slow */
2978         if (p_ptr->slow)
2979         {
2980                 (void)set_slow(p_ptr->slow - dec_count, TRUE);
2981         }
2982
2983         /* Protection from evil */
2984         if (p_ptr->protevil)
2985         {
2986                 (void)set_protevil(p_ptr->protevil - 1, TRUE);
2987         }
2988
2989         /* Invulnerability */
2990         if (p_ptr->invuln)
2991         {
2992                 (void)set_invuln(p_ptr->invuln - 1, TRUE);
2993         }
2994
2995         /* Wraith form */
2996         if (p_ptr->wraith_form)
2997         {
2998                 (void)set_wraith_form(p_ptr->wraith_form - 1, TRUE);
2999         }
3000
3001         /* Heroism */
3002         if (p_ptr->hero)
3003         {
3004                 (void)set_hero(p_ptr->hero - 1, TRUE);
3005         }
3006
3007         /* Super Heroism */
3008         if (p_ptr->shero)
3009         {
3010                 (void)set_shero(p_ptr->shero - 1, TRUE);
3011         }
3012
3013         /* Blessed */
3014         if (p_ptr->blessed)
3015         {
3016                 (void)set_blessed(p_ptr->blessed - 1, TRUE);
3017         }
3018
3019         /* Shield */
3020         if (p_ptr->shield)
3021         {
3022                 (void)set_shield(p_ptr->shield - 1, TRUE);
3023         }
3024
3025         /* Tsubureru */
3026         if (p_ptr->tsubureru)
3027         {
3028                 (void)set_tsubureru(p_ptr->tsubureru - 1, TRUE);
3029         }
3030
3031         /* Magicdef */
3032         if (p_ptr->magicdef)
3033         {
3034                 (void)set_magicdef(p_ptr->magicdef - 1, TRUE);
3035         }
3036
3037         /* Tsuyoshi */
3038         if (p_ptr->tsuyoshi)
3039         {
3040                 (void)set_tsuyoshi(p_ptr->tsuyoshi - 1, TRUE);
3041         }
3042
3043         /* Oppose Acid */
3044         if (p_ptr->oppose_acid)
3045         {
3046                 (void)set_oppose_acid(p_ptr->oppose_acid - 1, TRUE);
3047         }
3048
3049         /* Oppose Lightning */
3050         if (p_ptr->oppose_elec)
3051         {
3052                 (void)set_oppose_elec(p_ptr->oppose_elec - 1, TRUE);
3053         }
3054
3055         /* Oppose Fire */
3056         if (p_ptr->oppose_fire)
3057         {
3058                 (void)set_oppose_fire(p_ptr->oppose_fire - 1, TRUE);
3059         }
3060
3061         /* Oppose Cold */
3062         if (p_ptr->oppose_cold)
3063         {
3064                 (void)set_oppose_cold(p_ptr->oppose_cold - 1, TRUE);
3065         }
3066
3067         /* Oppose Poison */
3068         if (p_ptr->oppose_pois)
3069         {
3070                 (void)set_oppose_pois(p_ptr->oppose_pois - 1, TRUE);
3071         }
3072
3073         if (p_ptr->ult_res)
3074         {
3075                 (void)set_ultimate_res(p_ptr->ult_res - 1, TRUE);
3076         }
3077
3078         /*** Poison and Stun and Cut ***/
3079
3080         /* Poison */
3081         if (p_ptr->poisoned)
3082         {
3083                 int adjust = adj_con_fix[p_ptr->stat_ind[A_CON]] + 1;
3084
3085                 /* Apply some healing */
3086                 (void)set_poisoned(p_ptr->poisoned - adjust);
3087         }
3088
3089         /* Stun */
3090         if (p_ptr->stun)
3091         {
3092                 int adjust = adj_con_fix[p_ptr->stat_ind[A_CON]] + 1;
3093
3094                 /* Apply some healing */
3095                 (void)set_stun(p_ptr->stun - adjust);
3096         }
3097
3098         /* Cut */
3099         if (p_ptr->cut)
3100         {
3101                 int adjust = adj_con_fix[p_ptr->stat_ind[A_CON]] + 1;
3102
3103                 /* Hack -- Truly "mortal" wound */
3104                 if (p_ptr->cut > 1000) adjust = 0;
3105
3106                 /* Apply some healing */
3107                 (void)set_cut(p_ptr->cut - adjust);
3108         }
3109
3110
3111
3112         /*** Process Light ***/
3113
3114         /* Check for light being wielded */
3115         o_ptr = &inventory[INVEN_LITE];
3116
3117         /* Burn some fuel in the current lite */
3118         if (o_ptr->tval == TV_LITE)
3119         {
3120                 /* Hack -- Use some fuel (except on artifacts) */
3121                 if (!(artifact_p(o_ptr) || o_ptr->sval == SV_LITE_FEANOR) && (o_ptr->xtra4 > 0))
3122                 {
3123                         /* Decrease life-span */
3124                         if (o_ptr->name2 == EGO_LITE_LONG)
3125                         {
3126                                 if (turn % (TURNS_PER_TICK*2)) o_ptr->xtra4--;
3127                         }
3128                         else o_ptr->xtra4--;
3129
3130                         /* Notice interesting fuel steps */
3131                         notice_lite_change(o_ptr);
3132                 }
3133         }
3134
3135         /* Calculate torch radius */
3136         p_ptr->update |= (PU_TORCH);
3137
3138
3139         /*** Process mutation effects ***/
3140         if (p_ptr->muta2 && !p_ptr->inside_battle && !p_ptr->wild_mode)
3141         {
3142                 if ((p_ptr->muta2 & MUT2_BERS_RAGE) && one_in_(3000))
3143                 {
3144                         disturb(0, 0);
3145 #ifdef JP
3146 msg_print("¥¦¥¬¥¡¥¡¥¢¡ª");
3147 msg_print("·ãÅܤÎȯºî¤Ë½±¤ï¤ì¤¿¡ª");
3148 #else
3149                         msg_print("RAAAAGHH!");
3150                         msg_print("You feel a fit of rage coming over you!");
3151 #endif
3152
3153                         (void)set_shero(10 + randint1(p_ptr->lev), FALSE);
3154                 }
3155
3156                 if ((p_ptr->muta2 & MUT2_COWARDICE) && (randint1(3000) == 13))
3157                 {
3158                         if (!p_ptr->resist_fear)
3159                         {
3160                                 disturb(0, 0);
3161 #ifdef JP
3162 msg_print("¤È¤Æ¤â°Å¤¤... ¤È¤Æ¤â¶²¤¤¡ª");
3163 #else
3164                                 msg_print("It's so dark... so scary!");
3165 #endif
3166
3167                                 set_afraid(p_ptr->afraid + 13 + randint1(26));
3168                         }
3169                 }
3170
3171                 if ((p_ptr->muta2 & MUT2_RTELEPORT) && (randint1(5000) == 88))
3172                 {
3173                         if (!p_ptr->resist_nexus && !(p_ptr->muta1 & MUT1_VTELEPORT) &&
3174                             !p_ptr->anti_tele)
3175                         {
3176                                 disturb(0, 0);
3177
3178                                 /* Teleport player */
3179 #ifdef JP
3180 msg_print("¤¢¤Ê¤¿¤Î°ÌÃÖ¤ÏÆÍÁ³¤Ò¤¸¤ç¤¦¤ËÉÔ³ÎÄê¤Ë¤Ê¤Ã¤¿...");
3181 #else
3182                                 msg_print("Your position suddenly seems very uncertain...");
3183 #endif
3184
3185                                 msg_print(NULL);
3186                                 teleport_player(40);
3187                         }
3188                 }
3189
3190                 if ((p_ptr->muta2 & MUT2_ALCOHOL) && (randint1(6400) == 321))
3191                 {
3192                         if (!p_ptr->resist_conf && !p_ptr->resist_chaos)
3193                         {
3194                                 disturb(0, 0);
3195                                 p_ptr->redraw |= PR_EXTRA;
3196 #ifdef JP
3197 msg_print("¤¤¤Ò¤­¤¬¤â¡¼¤í¡¼¤È¤Ò¤Æ¤­¤¿¤­¤¬¤Õ¤ë...¥Ò¥Ã¥¯¡ª");
3198 #else
3199                                 msg_print("You feel a SSSCHtupor cOmINg over yOu... *HIC*!");
3200 #endif
3201
3202                         }
3203
3204                         if (!p_ptr->resist_conf)
3205                         {
3206                                 (void)set_confused(p_ptr->confused + randint0(20) + 15);
3207                         }
3208
3209                         if (!p_ptr->resist_chaos)
3210                         {
3211                                 if (one_in_(20))
3212                                 {
3213                                         msg_print(NULL);
3214                                         if (one_in_(3)) lose_all_info();
3215                                         else wiz_dark();
3216                                         teleport_player(100);
3217                                         wiz_dark();
3218 #ifdef JP
3219 msg_print("¤¢¤Ê¤¿¤Ï¸«ÃΤé¤Ì¾ì½ê¤ÇÌܤ¬Àä᤿...Ƭ¤¬Äˤ¤¡£");
3220 msg_print("²¿¤â³Ð¤¨¤Æ¤¤¤Ê¤¤¡£¤É¤¦¤ä¤Ã¤Æ¤³¤³¤ËÍ褿¤«¤âʬ¤«¤é¤Ê¤¤¡ª");
3221 #else
3222                                         msg_print("You wake up somewhere with a sore head...");
3223                                         msg_print("You can't remember a thing, or how you got here!");
3224 #endif
3225
3226                                 }
3227                                 else
3228                                 {
3229                                         if (one_in_(3))
3230                                         {
3231 #ifdef JP
3232 msg_print("¤­¡Á¤ì¤¤¤Ê¤Á¤ç¤ª¤Á¤ç¤é¤È¤ó¤ì¤¤¤ë¡Á");
3233 #else
3234                                                 msg_print("Thishcischs GooDSChtuff!");
3235 #endif
3236
3237                                                 (void)set_image(p_ptr->image + randint0(150) + 150);
3238                                         }
3239                                 }
3240                         }
3241                 }
3242
3243                 if ((p_ptr->muta2 & MUT2_HALLU) && (randint1(6400) == 42))
3244                 {
3245                         if (!p_ptr->resist_chaos)
3246                         {
3247                                 disturb(0, 0);
3248                                 p_ptr->redraw |= PR_EXTRA;
3249                                 (void)set_image(p_ptr->image + randint0(50) + 20);
3250                         }
3251                 }
3252
3253                 if ((p_ptr->muta2 & MUT2_FLATULENT) && (randint1(3000) == 13))
3254                 {
3255                         disturb(0, 0);
3256
3257 #ifdef JP
3258 msg_print("¥Ö¥¥¡¼¡¼¥Ã¡ª¤ª¤Ã¤È¡£");
3259 #else
3260                         msg_print("BRRAAAP! Oops.");
3261 #endif
3262
3263                         msg_print(NULL);
3264                         fire_ball(GF_POIS, 0, p_ptr->lev, 3);
3265                 }
3266
3267                 if ((p_ptr->muta2 & MUT2_PROD_MANA) &&
3268                     !p_ptr->anti_magic && one_in_(9000))
3269                 {
3270                         int dire = 0;
3271                         disturb(0, 0);
3272 #ifdef JP
3273 msg_print("ËâË¡¤Î¥¨¥Í¥ë¥®¡¼¤¬ÆÍÁ³¤¢¤Ê¤¿¤ÎÃæ¤Ëή¤ì¹þ¤ó¤Ç¤­¤¿¡ª¥¨¥Í¥ë¥®¡¼¤ò²òÊü¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡ª");
3274 #else
3275                         msg_print("Magical energy flows through you! You must release it!");
3276 #endif
3277
3278                         flush();
3279                         msg_print(NULL);
3280                         (void)get_hack_dir(&dire);
3281                         fire_ball(GF_MANA, dire, p_ptr->lev * 2, 3);
3282                 }
3283
3284                 if ((p_ptr->muta2 & MUT2_ATT_DEMON) &&
3285                     !p_ptr->anti_magic && (randint1(6666) == 666))
3286                 {
3287                         bool pet = one_in_(6);
3288                         u32b mode = PM_ALLOW_GROUP;
3289
3290                         if (pet) mode |= PM_FORCE_PET;
3291                         else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
3292
3293                         if (summon_specific((pet ? -1 : 0), py, px,
3294                                     dun_level, SUMMON_DEMON, mode))
3295                         {
3296 #ifdef JP
3297 msg_print("¤¢¤Ê¤¿¤Ï¥Ç¡¼¥â¥ó¤ò°ú¤­´ó¤»¤¿¡ª");
3298 #else
3299                                 msg_print("You have attracted a demon!");
3300 #endif
3301
3302                                 disturb(0, 0);
3303                         }
3304                 }
3305
3306                 if ((p_ptr->muta2 & MUT2_SPEED_FLUX) && one_in_(6000))
3307                 {
3308                         disturb(0, 0);
3309                         if (one_in_(2))
3310                         {
3311 #ifdef JP
3312 msg_print("ÀºÎÏŪ¤Ç¤Ê¤¯¤Ê¤Ã¤¿µ¤¤¬¤¹¤ë¡£");
3313 #else
3314                                 msg_print("You feel less energetic.");
3315 #endif
3316
3317                                 if (p_ptr->fast > 0)
3318                                 {
3319                                         set_fast(0, TRUE);
3320                                 }
3321                                 else
3322                                 {
3323                                         set_slow(randint1(30) + 10, FALSE);
3324                                 }
3325                         }
3326                         else
3327                         {
3328 #ifdef JP
3329 msg_print("ÀºÎÏŪ¤Ë¤Ê¤Ã¤¿µ¤¤¬¤¹¤ë¡£");
3330 #else
3331                                 msg_print("You feel more energetic.");
3332 #endif
3333
3334                                 if (p_ptr->slow > 0)
3335                                 {
3336                                         set_slow(0, TRUE);
3337                                 }
3338                                 else
3339                                 {
3340                                         set_fast(randint1(30) + 10, FALSE);
3341                                 }
3342                         }
3343                         msg_print(NULL);
3344                 }
3345                 if ((p_ptr->muta2 & MUT2_BANISH_ALL) && one_in_(9000))
3346                 {
3347                         disturb(0, 0);
3348 #ifdef JP
3349 msg_print("ÆÍÁ³¤Û¤È¤ó¤É¸ÉÆȤˤʤ俵¤¤¬¤¹¤ë¡£");
3350 #else
3351                         msg_print("You suddenly feel almost lonely.");
3352 #endif
3353
3354                         banish_monsters(100);
3355                         if (!dun_level && p_ptr->town_num)
3356                         {
3357                                 int n;
3358
3359                                 /* Pick a random shop (except home) */
3360                                 do
3361                                 {
3362                                         n = randint0(MAX_STORES);
3363                                 }
3364                                 while ((n == STORE_HOME) || (n == STORE_MUSEUM));
3365
3366 #ifdef JP
3367                                 msg_print("Ź¤Î¼ç¿Í¤¬µÖ¤Ë¸þ¤«¤Ã¤ÆÁö¤Ã¤Æ¤¤¤ë¡ª");
3368 #else
3369                                 msg_print("You see one of the shopkeepers running for the hills!");
3370 #endif
3371
3372                                 store_shuffle(n);
3373                         }
3374                         msg_print(NULL);
3375                 }
3376
3377                 if ((p_ptr->muta2 & MUT2_EAT_LIGHT) && one_in_(3000))
3378                 {
3379                         object_type *o_ptr;
3380
3381 #ifdef JP
3382 msg_print("±Æ¤Ë¤Ä¤Ä¤Þ¤ì¤¿¡£");
3383 #else
3384                         msg_print("A shadow passes over you.");
3385 #endif
3386
3387                         msg_print(NULL);
3388
3389                         /* Absorb light from the current possition */
3390                         if ((cave[py][px].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
3391                         {
3392                                 hp_player(10);
3393                         }
3394
3395                         o_ptr = &inventory[INVEN_LITE];
3396
3397                         /* Absorb some fuel in the current lite */
3398                         if (o_ptr->tval == TV_LITE)
3399                         {
3400                                 /* Use some fuel (except on artifacts) */
3401                                 if (!artifact_p(o_ptr) && (o_ptr->xtra4 > 0))
3402                                 {
3403                                         /* Heal the player a bit */
3404                                         hp_player(o_ptr->xtra4 / 20);
3405
3406                                         /* Decrease life-span of lite */
3407                                         o_ptr->xtra4 /= 2;
3408
3409 #ifdef JP
3410 msg_print("¸÷¸»¤«¤é¥¨¥Í¥ë¥®¡¼¤òµÛ¼ý¤·¤¿¡ª");
3411 #else
3412                                         msg_print("You absorb energy from your light!");
3413 #endif
3414
3415
3416                                         /* Notice interesting fuel steps */
3417                                         notice_lite_change(o_ptr);
3418                                 }
3419                         }
3420
3421                         /*
3422                          * Unlite the area (radius 10) around player and
3423                          * do 50 points damage to every affected monster
3424                          */
3425                         unlite_area(50, 10);
3426                 }
3427
3428                 if ((p_ptr->muta2 & MUT2_ATT_ANIMAL) &&
3429                    !p_ptr->anti_magic && one_in_(7000))
3430                 {
3431                         bool pet = one_in_(3);
3432                         u32b mode = PM_ALLOW_GROUP;
3433
3434                         if (pet) mode |= PM_FORCE_PET;
3435                         else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
3436
3437                         if (summon_specific((pet ? -1 : 0), py, px, dun_level, SUMMON_ANIMAL, mode))
3438                         {
3439 #ifdef JP
3440 msg_print("ưʪ¤ò°ú¤­´ó¤»¤¿¡ª");
3441 #else
3442                                 msg_print("You have attracted an animal!");
3443 #endif
3444
3445                                 disturb(0, 0);
3446                         }
3447                 }
3448
3449                 if ((p_ptr->muta2 & MUT2_RAW_CHAOS) &&
3450                     !p_ptr->anti_magic && one_in_(8000))
3451                 {
3452                         disturb(0, 0);
3453 #ifdef JP
3454 msg_print("¼þ¤ê¤Î¶õ´Ö¤¬ÏĤó¤Ç¤¤¤ëµ¤¤¬¤¹¤ë¡ª");
3455 #else
3456                         msg_print("You feel the world warping around you!");
3457 #endif
3458
3459                         msg_print(NULL);
3460                         fire_ball(GF_CHAOS, 0, p_ptr->lev, 8);
3461                 }
3462                 if ((p_ptr->muta2 & MUT2_NORMALITY) && one_in_(5000))
3463                 {
3464                         if (!lose_mutation(0))
3465 #ifdef JP
3466 msg_print("´ñ̯¤Ê¤¯¤é¤¤ÉáÄ̤ˤʤ俵¤¤¬¤¹¤ë¡£");
3467 #else
3468                                 msg_print("You feel oddly normal.");
3469 #endif
3470
3471                 }
3472                 if ((p_ptr->muta2 & MUT2_WRAITH) && !p_ptr->anti_magic && one_in_(3000))
3473                 {
3474                         disturb(0, 0);
3475 #ifdef JP
3476 msg_print("Èóʪ¼Á²½¤·¤¿¡ª");
3477 #else
3478                         msg_print("You feel insubstantial!");
3479 #endif
3480
3481                         msg_print(NULL);
3482                         set_wraith_form(randint1(p_ptr->lev / 2) + (p_ptr->lev / 2), FALSE);
3483                 }
3484                 if ((p_ptr->muta2 & MUT2_POLY_WOUND) && one_in_(3000))
3485                 {
3486                         do_poly_wounds();
3487                 }
3488                 if ((p_ptr->muta2 & MUT2_WASTING) && one_in_(3000))
3489                 {
3490                         int which_stat = randint0(6);
3491                         int sustained = FALSE;
3492
3493                         switch (which_stat)
3494                         {
3495                         case A_STR:
3496                                 if (p_ptr->sustain_str) sustained = TRUE;
3497                                 break;
3498                         case A_INT:
3499                                 if (p_ptr->sustain_int) sustained = TRUE;
3500                                 break;
3501                         case A_WIS:
3502                                 if (p_ptr->sustain_wis) sustained = TRUE;
3503                                 break;
3504                         case A_DEX:
3505                                 if (p_ptr->sustain_dex) sustained = TRUE;
3506                                 break;
3507                         case A_CON:
3508                                 if (p_ptr->sustain_con) sustained = TRUE;
3509                                 break;
3510                         case A_CHR:
3511                                 if (p_ptr->sustain_chr) sustained = TRUE;
3512                                 break;
3513                         default:
3514 #ifdef JP
3515 msg_print("ÉÔÀµ¤Ê¾õÂÖ¡ª");
3516 #else
3517                                 msg_print("Invalid stat chosen!");
3518 #endif
3519
3520                                 sustained = TRUE;
3521                         }
3522
3523                         if (!sustained)
3524                         {
3525                                 disturb(0, 0);
3526 #ifdef JP
3527 msg_print("¼«Ê¬¤¬¿ê¼å¤·¤Æ¤¤¤¯¤Î¤¬Ê¬¤«¤ë¡ª");
3528 #else
3529                                 msg_print("You can feel yourself wasting away!");
3530 #endif
3531
3532                                 msg_print(NULL);
3533                                 (void)dec_stat(which_stat, randint1(6) + 6, one_in_(3));
3534                         }
3535                 }
3536                 if ((p_ptr->muta2 & MUT2_ATT_DRAGON) &&
3537                    !p_ptr->anti_magic && one_in_(3000))
3538                 {
3539                         bool pet = one_in_(5);
3540                         u32b mode = PM_ALLOW_GROUP;
3541
3542                         if (pet) mode |= PM_FORCE_PET;
3543                         else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
3544
3545                         if (summon_specific((pet ? -1 : 0), py, px, dun_level, SUMMON_DRAGON, mode))
3546                         {
3547 #ifdef JP
3548 msg_print("¥É¥é¥´¥ó¤ò°ú¤­´ó¤»¤¿¡ª");
3549 #else
3550                                 msg_print("You have attracted a dragon!");
3551 #endif
3552
3553                                 disturb(0, 0);
3554                         }
3555                 }
3556                 if ((p_ptr->muta2 & MUT2_WEIRD_MIND) && !p_ptr->anti_magic &&
3557                         one_in_(3000))
3558                 {
3559                         if (p_ptr->tim_esp > 0)
3560                         {
3561 #ifdef JP
3562 msg_print("Àº¿À¤Ë¤â¤ä¤¬¤«¤«¤Ã¤¿¡ª");
3563 #else
3564                                 msg_print("Your mind feels cloudy!");
3565 #endif
3566
3567                                 set_tim_esp(0, TRUE);
3568                         }
3569                         else
3570                         {
3571 #ifdef JP
3572 msg_print("Àº¿À¤¬¹­¤¬¤Ã¤¿¡ª");
3573 #else
3574                                 msg_print("Your mind expands!");
3575 #endif
3576
3577                                 set_tim_esp(p_ptr->lev, FALSE);
3578                         }
3579                 }
3580                 if ((p_ptr->muta2 & MUT2_NAUSEA) && !p_ptr->slow_digest &&
3581                         one_in_(9000))
3582                 {
3583                         disturb(0, 0);
3584 #ifdef JP
3585 msg_print("°ß¤¬áÛÚ»¤·¡¢¿©»ö¤ò¼º¤Ã¤¿¡ª");
3586 #else
3587                         msg_print("Your stomach roils, and you lose your lunch!");
3588 #endif
3589
3590                         msg_print(NULL);
3591                         set_food(PY_FOOD_WEAK);
3592                 }
3593
3594                 if ((p_ptr->muta2 & MUT2_WALK_SHAD) &&
3595                    !p_ptr->anti_magic && one_in_(12000) && !p_ptr->inside_arena)
3596                 {
3597                         alter_reality();
3598                 }
3599
3600                 if ((p_ptr->muta2 & MUT2_WARNING) && one_in_(1000))
3601                 {
3602                         int danger_amount = 0;
3603                         int monster;
3604
3605                         for (monster = 0; monster < m_max; monster++)
3606                         {
3607                                 monster_type    *m_ptr = &m_list[monster];
3608                                 monster_race    *r_ptr = &r_info[m_ptr->r_idx];
3609
3610                                 /* Paranoia -- Skip dead monsters */
3611                                 if (!m_ptr->r_idx) continue;
3612
3613                                 if (r_ptr->level >= p_ptr->lev)
3614                                 {
3615                                         danger_amount += r_ptr->level - p_ptr->lev + 1;
3616                                 }
3617                         }
3618
3619                         if (danger_amount > 100)
3620 #ifdef JP
3621 msg_print("Èó¾ï¤Ë¶²¤í¤·¤¤µ¤¤¬¤¹¤ë¡ª");
3622 #else
3623                                 msg_print("You feel utterly terrified!");
3624 #endif
3625
3626                         else if (danger_amount > 50)
3627 #ifdef JP
3628 msg_print("¶²¤í¤·¤¤µ¤¤¬¤¹¤ë¡ª");
3629 #else
3630                                 msg_print("You feel terrified!");
3631 #endif
3632
3633                         else if (danger_amount > 20)
3634 #ifdef JP
3635 msg_print("Èó¾ï¤Ë¿´Çۤʵ¤¤¬¤¹¤ë¡ª");
3636 #else
3637                                 msg_print("You feel very worried!");
3638 #endif
3639
3640                         else if (danger_amount > 10)
3641 #ifdef JP
3642 msg_print("¿´Çۤʵ¤¤¬¤¹¤ë¡ª");
3643 #else
3644                                 msg_print("You feel paranoid!");
3645 #endif
3646
3647                         else if (danger_amount > 5)
3648 #ifdef JP
3649 msg_print("¤Û¤È¤ó¤É°ÂÁ´¤Êµ¤¤¬¤¹¤ë¡£");
3650 #else
3651                                 msg_print("You feel almost safe.");
3652 #endif
3653
3654                         else
3655 #ifdef JP
3656 msg_print("¼ä¤·¤¤µ¤¤¬¤¹¤ë¡£");
3657 #else
3658                                 msg_print("You feel lonely.");
3659 #endif
3660
3661                 }
3662                 if ((p_ptr->muta2 & MUT2_INVULN) && !p_ptr->anti_magic &&
3663                         one_in_(5000))
3664                 {
3665                         disturb(0, 0);
3666 #ifdef JP
3667 msg_print("̵Ũ¤Êµ¤¤¬¤¹¤ë¡ª");
3668 #else
3669                         msg_print("You feel invincible!");
3670 #endif
3671
3672                         msg_print(NULL);
3673                         (void)set_invuln(randint1(8) + 8, FALSE);
3674                 }
3675                 if ((p_ptr->muta2 & MUT2_SP_TO_HP) && one_in_(2000))
3676                 {
3677                         int wounds = p_ptr->mhp - p_ptr->chp;
3678
3679                         if (wounds > 0)
3680                         {
3681                                 int healing = p_ptr->csp;
3682
3683                                 if (healing > wounds)
3684                                 {
3685                                         healing = wounds;
3686                                 }
3687
3688                                 hp_player(healing);
3689                                 p_ptr->csp -= healing;
3690
3691                                 /* Redraw mana */
3692                                 p_ptr->redraw |= (PR_MANA);
3693                         }
3694                 }
3695                 if ((p_ptr->muta2 & MUT2_HP_TO_SP) && !p_ptr->anti_magic &&
3696                         one_in_(4000))
3697                 {
3698                         int wounds = p_ptr->msp - p_ptr->csp;
3699
3700                         if (wounds > 0)
3701                         {
3702                                 int healing = p_ptr->chp;
3703
3704                                 if (healing > wounds)
3705                                 {
3706                                         healing = wounds;
3707                                 }
3708
3709                                 p_ptr->csp += healing;
3710
3711                                 /* Redraw mana */
3712                                 p_ptr->redraw |= (PR_MANA);
3713 #ifdef JP
3714 take_hit(DAMAGE_LOSELIFE, healing, "Ƭ¤Ë¾º¤Ã¤¿·ì", -1);
3715 #else
3716                                 take_hit(DAMAGE_LOSELIFE, healing, "blood rushing to the head", -1);
3717 #endif
3718
3719                         }
3720                 }
3721                 if ((p_ptr->muta2 & MUT2_DISARM) && one_in_(10000))
3722                 {
3723                         object_type *o_ptr;
3724
3725                         disturb(0, 0);
3726 #ifdef JP
3727 msg_print("­¤¬¤â¤Ä¤ì¤Æž¤ó¤À¡ª");
3728 take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->wt / 6), "žÅÝ", -1);
3729 #else
3730                         msg_print("You trip over your own feet!");
3731                         take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->wt / 6), "tripping", -1);
3732 #endif
3733
3734
3735                         msg_print(NULL);
3736                         if (buki_motteruka(INVEN_RARM))
3737                         {
3738                                 int slot = INVEN_RARM;
3739                                 o_ptr = &inventory[INVEN_RARM];
3740                                 if (buki_motteruka(INVEN_LARM) && one_in_(2))
3741                                 {
3742                                         o_ptr = &inventory[INVEN_LARM];
3743                                         slot = INVEN_LARM;
3744                                 }
3745                                 if (!cursed_p(o_ptr))
3746                                 {
3747 #ifdef JP
3748 msg_print("Éð´ï¤òÍ¤Æ¤·¤Þ¤Ã¤¿¡ª");
3749 #else
3750                                         msg_print("You drop your weapon!");
3751 #endif
3752
3753                                         inven_drop(slot, 1);
3754                                 }
3755                         }
3756                 }
3757         }
3758
3759
3760         /*** Process Inventory ***/
3761
3762         if ((p_ptr->cursed & TRC_P_FLAG_MASK) && !p_ptr->inside_battle && !p_ptr->wild_mode)
3763         {
3764                 /*
3765                  * Hack: Uncursed teleporting items (e.g. Trump Weapons)
3766                  * can actually be useful!
3767                  */
3768                 if ((p_ptr->cursed & TRC_TELEPORT_SELF) && one_in_(200))
3769                 {
3770                         char o_name[MAX_NLEN];
3771                         object_type *o_ptr;
3772                         int i;
3773
3774                         /* Scan the equipment with random teleport ability */
3775                         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
3776                         {
3777                                 u32b flgs[TR_FLAG_SIZE];
3778                                 o_ptr = &inventory[i];
3779                                 
3780                                 /* Skip non-objects */
3781                                 if (!o_ptr->k_idx) continue;
3782                                 
3783                                 /* Extract the item flags */
3784                                 object_flags(o_ptr, flgs);
3785                                 
3786                                 if (have_flag(flgs, TR_TELEPORT)) break;
3787                         }
3788
3789                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3790
3791 #ifdef JP
3792                         msg_format("%s¤¬¥Æ¥ì¥Ý¡¼¥È¤ÎǽÎϤòȯư¤µ¤»¤è¤¦¤È¤·¤Æ¤¤¤ë¡£", o_name);
3793 #else
3794                         msg_format("Your %s is activating teleportation.", o_name);
3795 #endif
3796
3797 #ifdef JP
3798                         if (get_check_strict("¥Æ¥ì¥Ý¡¼¥È¤·¤Þ¤¹¤«¡©", CHECK_OKAY_CANCEL))
3799 #else
3800                         if (get_check_strict("Teleport? ", CHECK_OKAY_CANCEL))
3801 #endif
3802                         {
3803                                 disturb(0, 0);
3804                                 teleport_player(50);
3805                         }
3806                         else
3807                         {
3808 #ifdef JP
3809                                 msg_format("%s¤Ë{.}(¥Ô¥ê¥ª¥É)¤ÈÌäò¹ï¤à¤Èȯư¤òÍÞÀ©¤Ç¤­¤Þ¤¹¡£", o_name);
3810 #else
3811                                 msg_format("You can inscribe {.} on your %s to disable random teleportation. ", o_name);
3812 #endif
3813                                 disturb(1, 0);
3814                         }
3815                 }
3816                 /* Make a chainsword noise */
3817                 if ((p_ptr->cursed & TRC_CHAINSWORD) && one_in_(CHAINSWORD_NOISE))
3818                 {
3819                         char noise[1024];
3820 #ifdef JP
3821                         if (!get_rnd_line("chainswd_j.txt", 0, noise))
3822 #else
3823                         if (!get_rnd_line("chainswd.txt", 0, noise))
3824 #endif
3825                                 msg_print(noise);
3826                         disturb(FALSE, FALSE);
3827                 }
3828                 /* TY Curse */
3829                 if ((p_ptr->cursed & TRC_TY_CURSE) && one_in_(TY_CURSE_CHANCE))
3830                 {
3831                         int count = 0;
3832                         (void)activate_ty_curse(FALSE, &count);
3833                 }
3834                 /* Handle experience draining */
3835                 if (p_ptr->prace != RACE_ANDROID && 
3836                         ((p_ptr->cursed & TRC_DRAIN_EXP) && one_in_(4)))
3837                 {
3838                         p_ptr->exp -= (p_ptr->lev+1)/2;
3839                         if (p_ptr->exp < 0) p_ptr->exp = 0;
3840                         p_ptr->max_exp -= (p_ptr->lev+1)/2;
3841                         if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
3842                         check_experience();
3843                 }
3844                 /* Add light curse (Later) */
3845                 if ((p_ptr->cursed & TRC_ADD_L_CURSE) && one_in_(2000))
3846                 {
3847                         u32b new_curse;
3848                         object_type *o_ptr;
3849
3850                         o_ptr = choose_cursed_obj_name(TRC_ADD_L_CURSE);
3851
3852                         new_curse = get_curse(0, o_ptr);
3853                         if (!(o_ptr->curse_flags & new_curse))
3854                         {
3855                                 char o_name[MAX_NLEN];
3856
3857                                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3858
3859                                 o_ptr->curse_flags |= new_curse;
3860 #ifdef JP
3861                                 msg_format("°­°Õ¤ËËþ¤Á¤¿¹õ¤¤¥ª¡¼¥é¤¬%s¤ò¤È¤ê¤Þ¤¤¤¿...", o_name);
3862 #else
3863                                 msg_format("There is a malignant black aura surrounding your %s...", o_name);
3864 #endif
3865
3866                                 o_ptr->feeling = FEEL_NONE;
3867
3868                                 p_ptr->update |= (PU_BONUS);
3869                         }
3870                 }
3871                 /* Add heavy curse (Later) */
3872                 if ((p_ptr->cursed & TRC_ADD_H_CURSE) && one_in_(2000))
3873                 {
3874                         u32b new_curse;
3875                         object_type *o_ptr;
3876
3877                         o_ptr = choose_cursed_obj_name(TRC_ADD_H_CURSE);
3878
3879                         new_curse = get_curse(1, o_ptr);
3880                         if (!(o_ptr->curse_flags & new_curse))
3881                         {
3882                                 char o_name[MAX_NLEN];
3883
3884                                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3885
3886                                 o_ptr->curse_flags |= new_curse;
3887 #ifdef JP
3888                                 msg_format("°­°Õ¤ËËþ¤Á¤¿¹õ¤¤¥ª¡¼¥é¤¬%s¤ò¤È¤ê¤Þ¤¤¤¿...", o_name);
3889 #else
3890                                 msg_format("There is a malignant black aura surrounding your %s...", o_name);
3891 #endif
3892
3893                                 o_ptr->feeling = FEEL_NONE;
3894
3895                                 p_ptr->update |= (PU_BONUS);
3896                         }
3897                 }
3898                 /* Call animal */
3899                 if ((p_ptr->cursed & TRC_CALL_ANIMAL) && one_in_(2500))
3900                 {
3901                         if (summon_specific(0, py, px, dun_level, SUMMON_ANIMAL,
3902                             (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
3903                         {
3904                                 char o_name[MAX_NLEN];
3905
3906                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_ANIMAL), (OD_OMIT_PREFIX | OD_NAME_ONLY));
3907 #ifdef JP
3908                                 msg_format("%s¤¬Æ°Êª¤ò°ú¤­´ó¤»¤¿¡ª", o_name);
3909 #else
3910                                 msg_format("Your %s have attracted an animal!", o_name);
3911 #endif
3912
3913                                 disturb(0, 0);
3914                         }
3915                 }
3916                 /* Call demon */
3917                 if ((p_ptr->cursed & TRC_CALL_DEMON) && one_in_(1111))
3918                 {
3919                         if (summon_specific(0, py, px, dun_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
3920                         {
3921                                 char o_name[MAX_NLEN];
3922
3923                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_DEMON), (OD_OMIT_PREFIX | OD_NAME_ONLY));
3924 #ifdef JP
3925                                 msg_format("%s¤¬°­Ëâ¤ò°ú¤­´ó¤»¤¿¡ª", o_name);
3926 #else
3927                                 msg_format("Your %s have attracted a demon!", o_name);
3928 #endif
3929
3930                                 disturb(0, 0);
3931                         }
3932                 }
3933                 /* Call dragon */
3934                 if ((p_ptr->cursed & TRC_CALL_DRAGON) && one_in_(800))
3935                 {
3936                         if (summon_specific(0, py, px, dun_level, SUMMON_DRAGON,
3937                             (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
3938                         {
3939                                 char o_name[MAX_NLEN];
3940
3941                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_DRAGON), (OD_OMIT_PREFIX | OD_NAME_ONLY));
3942 #ifdef JP
3943                                 msg_format("%s¤¬¥É¥é¥´¥ó¤ò°ú¤­´ó¤»¤¿¡ª", o_name);
3944 #else
3945                                 msg_format("Your %s have attracted an animal!", o_name);
3946 #endif
3947
3948                                 disturb(0, 0);
3949                         }
3950                 }
3951                 if ((p_ptr->cursed & TRC_COWARDICE) && one_in_(1500))
3952                 {
3953                         if (!p_ptr->resist_fear)
3954                         {
3955                                 disturb(0, 0);
3956 #ifdef JP
3957                                 msg_print("¤È¤Æ¤â°Å¤¤... ¤È¤Æ¤â¶²¤¤¡ª");
3958 #else
3959                                 msg_print("It's so dark... so scary!");
3960 #endif
3961
3962                                 set_afraid(p_ptr->afraid + 13 + randint1(26));
3963                         }
3964                 }
3965                 /* Teleport player */
3966                 if ((p_ptr->cursed & TRC_TELEPORT) && one_in_(200) && !p_ptr->anti_tele)
3967                 {
3968                         disturb(0, 0);
3969
3970                         /* Teleport player */
3971                         teleport_player(40);
3972                 }
3973                 /* Handle HP draining */
3974                 if ((p_ptr->cursed & TRC_DRAIN_HP) && one_in_(666))
3975                 {
3976                         char o_name[MAX_NLEN];
3977
3978                         object_desc(o_name, choose_cursed_obj_name(TRC_DRAIN_HP), (OD_OMIT_PREFIX | OD_NAME_ONLY));
3979 #ifdef JP
3980                         msg_format("%s¤Ï¤¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª", o_name);
3981 #else
3982                         msg_format("Your %s drains HP from you!", o_name);
3983 #endif
3984                         take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev*2, 100), o_name, -1);
3985                 }
3986                 /* Handle mana draining */
3987                 if ((p_ptr->cursed & TRC_DRAIN_MANA) && one_in_(666))
3988                 {
3989                         char o_name[MAX_NLEN];
3990
3991                         object_desc(o_name, choose_cursed_obj_name(TRC_DRAIN_MANA), (OD_OMIT_PREFIX | OD_NAME_ONLY));
3992 #ifdef JP
3993                         msg_format("%s¤Ï¤¢¤Ê¤¿¤ÎËâÎϤòµÛ¼ý¤·¤¿¡ª", o_name);
3994 #else
3995                         msg_format("Your %s drains mana from you!", o_name);
3996 #endif
3997                         p_ptr->csp -= MIN(p_ptr->lev, 50);
3998                         if (p_ptr->csp < 0)
3999                         {
4000                                 p_ptr->csp = 0;
4001                                 p_ptr->csp_frac = 0;
4002                         }
4003                         p_ptr->redraw |= PR_MANA;
4004                 }
4005         }
4006
4007         /* Rarely, take damage from the Jewel of Judgement */
4008         if (one_in_(999) && !p_ptr->anti_magic)
4009         {
4010                 object_type *o_ptr = &inventory[INVEN_LITE];
4011
4012                 if (o_ptr->name1 == ART_JUDGE)
4013                 {
4014 #ifdef JP
4015                         if (object_known_p(o_ptr))
4016                                 msg_print("¡Ø¿³È½¤ÎÊõÀС٤Ϥ¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª");
4017                         else
4018                                 msg_print("¤Ê¤Ë¤«¤¬¤¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª");
4019                         take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "¿³È½¤ÎÊõÀÐ", -1);
4020 #else
4021                         if (object_known_p(o_ptr))
4022                                 msg_print("The Jewel of Judgement drains life from you!");
4023                         else
4024                                 msg_print("Something drains life from you!");
4025                         take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "the Jewel of Judgement", -1);
4026 #endif
4027                 }
4028         }
4029
4030
4031         /* Process equipment */
4032         for (j = 0, i = INVEN_RARM; i < INVEN_TOTAL; i++)
4033         {
4034                 /* Get the object */
4035                 o_ptr = &inventory[i];
4036
4037                 /* Skip non-objects */
4038                 if (!o_ptr->k_idx) continue;
4039
4040                 /* Recharge activatable objects */
4041                 if (o_ptr->timeout > 0)
4042                 {
4043                         /* Recharge */
4044                         o_ptr->timeout--;
4045
4046                         /* Notice changes */
4047                         if (!o_ptr->timeout)
4048                         {
4049                                 recharged_notice(o_ptr);
4050                                 j++;
4051                         }
4052                 }
4053         }
4054
4055         /* Notice changes */
4056         if (j)
4057         {
4058                 /* Window stuff */
4059                 p_ptr->window |= (PW_EQUIP);
4060                 wild_regen = 20;
4061         }
4062
4063         /*
4064          * Recharge rods.  Rods now use timeout to control charging status,
4065          * and each charging rod in a stack decreases the stack's timeout by
4066          * one per turn. -LM-
4067          */
4068         for (j = 0, i = 0; i < INVEN_PACK; i++)
4069         {
4070                 o_ptr = &inventory[i];
4071                 k_ptr = &k_info[o_ptr->k_idx];
4072
4073                 /* Skip non-objects */
4074                 if (!o_ptr->k_idx) continue;
4075
4076                 /* Examine all charging rods or stacks of charging rods. */
4077                 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
4078                 {
4079                         /* Determine how many rods are charging. */
4080                         temp = (o_ptr->timeout + (k_ptr->pval - 1)) / k_ptr->pval;
4081                         if (temp > o_ptr->number) temp = o_ptr->number;
4082
4083                         /* Decrease timeout by that number. */
4084                         o_ptr->timeout -= temp;
4085
4086                         /* Boundary control. */
4087                         if (o_ptr->timeout < 0) o_ptr->timeout = 0;
4088
4089                         /* Notice changes, provide message if object is inscribed. */
4090                         if (!(o_ptr->timeout))
4091                         {
4092                                 recharged_notice(o_ptr);
4093                                 j++;
4094                         }
4095                 }
4096         }
4097
4098         /* Notice changes */
4099         if (j)
4100         {
4101                 /* Combine pack */
4102                 p_ptr->notice |= (PN_COMBINE);
4103
4104                 /* Window stuff */
4105                 p_ptr->window |= (PW_INVEN);
4106                 wild_regen = 20;
4107         }
4108
4109         /* Feel the inventory */
4110         sense_inventory1();
4111         sense_inventory2();
4112
4113
4114         /*** Process Objects ***/
4115
4116         /* Process objects */
4117         for (i = 1; i < o_max; i++)
4118         {
4119                 /* Access object */
4120                 o_ptr = &o_list[i];
4121
4122                 /* Skip dead objects */
4123                 if (!o_ptr->k_idx) continue;
4124
4125                 /* Recharge rods on the ground.  No messages. */
4126                 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
4127                 {
4128                         /* Charge it */
4129                         o_ptr->timeout -= o_ptr->number;
4130
4131                         /* Boundary control. */
4132                         if (o_ptr->timeout < 0) o_ptr->timeout = 0;
4133                 }
4134         }
4135
4136
4137         /*** Involuntary Movement ***/
4138
4139         /* Delayed Word-of-Recall */
4140         if (p_ptr->word_recall)
4141         {
4142                 /*
4143                  * HACK: Autosave BEFORE resetting the recall counter (rr9)
4144                  * The player is yanked up/down as soon as
4145                  * he loads the autosaved game.
4146                  */
4147                 if (autosave_l && (p_ptr->word_recall == 1) && !p_ptr->inside_battle)
4148                         do_cmd_save_game(TRUE);
4149
4150                 /* Count down towards recall */
4151                 p_ptr->word_recall--;
4152
4153                 p_ptr->redraw |= (PR_STATUS);
4154
4155                 /* Activate the recall */
4156                 if (!p_ptr->word_recall)
4157                 {
4158                         /* Disturbing! */
4159                         disturb(0, 0);
4160
4161                         /* Determine the level */
4162                         if (dun_level || p_ptr->inside_quest)
4163                         {
4164 #ifdef JP
4165 msg_print("¾å¤Ë°ú¤ÃÄ¥¤ê¤¢¤²¤é¤ì¤ë´¶¤¸¤¬¤¹¤ë¡ª");
4166 #else
4167                                 msg_print("You feel yourself yanked upwards!");
4168 #endif
4169
4170                                 p_ptr->recall_dungeon = dungeon_type;
4171                                 if (record_stair)
4172                                         do_cmd_write_nikki(NIKKI_RECALL, dun_level, NULL);
4173
4174                                 dun_level = 0;
4175                                 dungeon_type = 0;
4176
4177                                 leave_quest_check();
4178
4179                                 p_ptr->inside_quest = 0;
4180
4181                                 p_ptr->leaving = TRUE;
4182                         }
4183                         else
4184                         {
4185 #ifdef JP
4186 msg_print("²¼¤Ë°ú¤­¤º¤ê¹ß¤í¤µ¤ì¤ë´¶¤¸¤¬¤¹¤ë¡ª");
4187 #else
4188                                 msg_print("You feel yourself yanked downwards!");
4189 #endif
4190
4191                                 dungeon_type = p_ptr->recall_dungeon;
4192
4193                                 if (record_stair)
4194                                         do_cmd_write_nikki(NIKKI_RECALL, dun_level, NULL);
4195
4196                                 /* New depth */
4197                                 dun_level = max_dlv[dungeon_type];
4198                                 if (dun_level < 1) dun_level = 1;
4199
4200                                 /* Nightmare mode makes recall more dangerous */
4201                                 if (ironman_nightmare && !randint0(666) && (dungeon_type == DUNGEON_ANGBAND))
4202                                 {
4203                                         if (dun_level < 50)
4204                                         {
4205                                                 dun_level *= 2;
4206                                         }
4207                                         else if (dun_level < 99)
4208                                         {
4209                                                 dun_level = (dun_level + 99) / 2;
4210                                         }
4211                                         else if (dun_level > 100)
4212                                         {
4213                                                 dun_level = d_info[dungeon_type].maxdepth - 1;
4214                                         }
4215                                 }
4216
4217                                 if (p_ptr->wild_mode)
4218                                 {
4219                                         p_ptr->wilderness_y = py;
4220                                         p_ptr->wilderness_x = px;
4221                                 }
4222                                 else
4223                                 {
4224                                         /* Save player position */
4225                                         p_ptr->oldpx = px;
4226                                         p_ptr->oldpy = py;
4227                                 }
4228                                 p_ptr->wild_mode = FALSE;
4229
4230                                 /* Leaving */
4231                                 p_ptr->leaving = TRUE;
4232
4233                                 if (dungeon_type == DUNGEON_ANGBAND)
4234                                 {
4235                                         for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
4236                                         {
4237                                                 if ((quest[i].type == QUEST_TYPE_RANDOM) &&
4238                                                     (quest[i].status == QUEST_STATUS_TAKEN) &&
4239                                                     (quest[i].level < dun_level))
4240                                                 {
4241                                                         quest[i].status = QUEST_STATUS_FAILED;
4242                                                         quest[i].complev = (byte)p_ptr->lev;
4243                                                         r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
4244                                                 }
4245                                         }
4246                                 }
4247                         }
4248
4249                         /* Sound */
4250                         sound(SOUND_TPLEVEL);
4251                 }
4252         }
4253
4254
4255         /* Delayed Alter reality */
4256         if (p_ptr->alter_reality)
4257         {
4258                 if (autosave_l && (p_ptr->alter_reality == 1) && !p_ptr->inside_battle)
4259                         do_cmd_save_game(TRUE);
4260
4261                 /* Count down towards alter */
4262                 p_ptr->alter_reality--;
4263
4264                 p_ptr->redraw |= (PR_STATUS);
4265
4266                 /* Activate the alter reality */
4267                 if (!p_ptr->alter_reality)
4268                 {
4269                         /* Disturbing! */
4270                         disturb(0, 0);
4271
4272                         /* Determine the level */
4273                         if (!quest_number(dun_level) && dun_level)
4274                         {
4275 #ifdef JP
4276                                 msg_print("À¤³¦¤¬ÊѤï¤Ã¤¿¡ª");
4277 #else
4278                                 msg_print("The world changes!");
4279 #endif
4280
4281                                 /* Leaving */
4282                                 p_ptr->leaving = TRUE;
4283                         }
4284                         else
4285                         {
4286 #ifdef JP
4287                                 msg_print("À¤³¦¤¬¾¯¤·¤Î´ÖÊѲ½¤·¤¿¤è¤¦¤À¡£");
4288 #else
4289                                 msg_print("The world seems to change for a moment!");
4290 #endif
4291                         }
4292
4293                         /* Sound */
4294                         sound(SOUND_TPLEVEL);
4295                 }
4296         }
4297 }
4298
4299
4300
4301 /*
4302  * Verify use of "wizard" mode
4303  */
4304 static bool enter_wizard_mode(void)
4305 {
4306         /* Ask first time */
4307         if (!p_ptr->noscore)
4308         {
4309                 /* Wizard mode is not permitted */
4310                 if (!allow_debug_opts)
4311                 {
4312 #ifdef JP
4313                         msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£ ");
4314 #else
4315                         msg_print("Wizard mode is not permitted.");
4316 #endif
4317                         return FALSE;
4318                 }
4319
4320                 /* Mention effects */
4321 #ifdef JP
4322                 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤Ï¥Ç¥Ð¥Ã¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥â¡¼¥É¤Ç¤¹¡£ ");
4323                 msg_print("°ìÅÙ¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆþ¤ë¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
4324 #else
4325                 msg_print("Wizard mode is for debugging and experimenting.");
4326                 msg_print("The game will not be scored if you enter wizard mode.");
4327 #endif
4328
4329                 msg_print(NULL);
4330
4331                 /* Verify request */
4332 #ifdef JP
4333                 if (!get_check("ËÜÅö¤Ë¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆþ¤ê¤¿¤¤¤Î¤Ç¤¹¤«? "))
4334 #else
4335                 if (!get_check("Are you sure you want to enter wizard mode? "))
4336 #endif
4337                 {
4338                         return (FALSE);
4339                 }
4340
4341 #ifdef JP
4342                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆÍÆþ¤·¤Æ¥¹¥³¥¢¤ò»Ä¤»¤Ê¤¯¤Ê¤Ã¤¿¡£");
4343 #else
4344                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up recording score to enter wizard mode.");
4345 #endif
4346                 /* Mark savefile */
4347                 p_ptr->noscore |= 0x0002;
4348         }
4349
4350         /* Success */
4351         return (TRUE);
4352 }
4353
4354
4355 #ifdef ALLOW_WIZARD
4356
4357 /*
4358  * Verify use of "debug" commands
4359  */
4360 static bool enter_debug_mode(void)
4361 {
4362         /* Ask first time */
4363         if (!p_ptr->noscore)
4364         {
4365                 /* Debug mode is not permitted */
4366                 if (!allow_debug_opts)
4367                 {
4368 #ifdef JP
4369                         msg_print("¥Ç¥Ð¥Ã¥°¥³¥Þ¥ó¥É¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£ ");
4370 #else
4371                         msg_print("Use of debug command is not permitted.");
4372 #endif
4373                         return FALSE;
4374                 }
4375
4376                 /* Mention effects */
4377 #ifdef JP
4378                 msg_print("¥Ç¥Ð¥Ã¥°¡¦¥³¥Þ¥ó¥É¤Ï¥Ç¥Ð¥Ã¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥³¥Þ¥ó¥É¤Ç¤¹¡£ ");
4379                 msg_print("¥Ç¥Ð¥Ã¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¦¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
4380 #else
4381                 msg_print("The debug commands are for debugging and experimenting.");
4382                 msg_print("The game will not be scored if you use debug commands.");
4383 #endif
4384
4385                 msg_print(NULL);
4386
4387                 /* Verify request */
4388 #ifdef JP
4389                 if (!get_check("ËÜÅö¤Ë¥Ç¥Ð¥Ã¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¤¤Þ¤¹¤«? "))
4390 #else
4391                 if (!get_check("Are you sure you want to use debug commands? "))
4392 #endif
4393                 {
4394                         return (FALSE);
4395                 }
4396
4397 #ifdef JP
4398                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥Ç¥Ð¥Ã¥°¥â¡¼¥É¤ËÆÍÆþ¤·¤Æ¥¹¥³¥¢¤ò»Ä¤»¤Ê¤¯¤Ê¤Ã¤¿¡£");
4399 #else
4400                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up sending score to use debug commands.");
4401 #endif
4402                 /* Mark savefile */
4403                 p_ptr->noscore |= 0x0008;
4404         }
4405
4406         /* Success */
4407         return (TRUE);
4408 }
4409
4410 /*
4411  * Hack -- Declare the Debug Routines
4412  */
4413 extern void do_cmd_debug(void);
4414
4415 #endif /* ALLOW_WIZARD */
4416
4417
4418 #ifdef ALLOW_BORG
4419
4420 /*
4421  * Verify use of "borg" commands
4422  */
4423 static bool enter_borg_mode(void)
4424 {
4425         /* Ask first time */
4426         if (!(p_ptr->noscore & 0x0010))
4427         {
4428                 /* Mention effects */
4429 #ifdef JP
4430                 msg_print("¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤Ï¥Ç¥Ð¥Ã¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥³¥Þ¥ó¥É¤Ç¤¹¡£ ");
4431                 msg_print("¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¦¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
4432 #else
4433                 msg_print("The borg commands are for debugging and experimenting.");
4434                 msg_print("The game will not be scored if you use borg commands.");
4435 #endif
4436
4437                 msg_print(NULL);
4438
4439                 /* Verify request */
4440 #ifdef JP
4441                 if (!get_check("ËÜÅö¤Ë¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¤¤Þ¤¹¤«? "))
4442 #else
4443                 if (!get_check("Are you sure you want to use borg commands? "))
4444 #endif
4445                 {
4446                         return (FALSE);
4447                 }
4448
4449 #ifdef JP
4450                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»ÈÍѤ·¤Æ¥¹¥³¥¢¤ò»Ä¤»¤Ê¤¯¤Ê¤Ã¤¿¡£");
4451 #else
4452                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up recording score to use borg commands.");
4453 #endif
4454                 /* Mark savefile */
4455                 p_ptr->noscore |= 0x0010;
4456         }
4457
4458         /* Success */
4459         return (TRUE);
4460 }
4461
4462 /*
4463  * Hack -- Declare the Ben Borg
4464  */
4465 extern void do_cmd_borg(void);
4466
4467 #endif /* ALLOW_BORG */
4468
4469
4470
4471 /*
4472  * Parse and execute the current command
4473  * Give "Warning" on illegal commands.
4474  *
4475  * XXX XXX XXX Make some "blocks"
4476  */
4477 static void process_command(void)
4478 {
4479         int old_now_message = now_message;
4480
4481 #ifdef ALLOW_REPEAT /* TNB */
4482
4483         /* Handle repeating the last command */
4484         repeat_check();
4485
4486 #endif /* ALLOW_REPEAT -- TNB */
4487
4488         now_message = 0;
4489
4490         /* Parse the command */
4491         switch (command_cmd)
4492         {
4493                 /* Ignore */
4494                 case ESCAPE:
4495                 case ' ':
4496                 {
4497                         break;
4498                 }
4499
4500                 /* Ignore return */
4501                 case '\r':
4502                 case '\n':
4503                 {
4504                         break;
4505                 }
4506
4507                 /*** Wizard Commands ***/
4508
4509                 /* Toggle Wizard Mode */
4510                 case KTRL('W'):
4511                 {
4512                         if (p_ptr->wizard)
4513                         {
4514                                 p_ptr->wizard = FALSE;
4515 #ifdef JP
4516 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É²ò½ü¡£");
4517 #else
4518                                 msg_print("Wizard mode off.");
4519 #endif
4520
4521                         }
4522                         else if (enter_wizard_mode())
4523                         {
4524                                 p_ptr->wizard = TRUE;
4525 #ifdef JP
4526 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥ÉÆÍÆþ¡£");
4527 #else
4528                                 msg_print("Wizard mode on.");
4529 #endif
4530
4531                         }
4532
4533                         /* Update monsters */
4534                         p_ptr->update |= (PU_MONSTERS);
4535
4536                         /* Redraw "title" */
4537                         p_ptr->redraw |= (PR_TITLE);
4538
4539                         break;
4540                 }
4541
4542
4543 #ifdef ALLOW_WIZARD
4544
4545                 /* Special "debug" commands */
4546                 case KTRL('A'):
4547                 {
4548                         /* Enter debug mode */
4549                         if (enter_debug_mode())
4550                         {
4551                                 do_cmd_debug();
4552                         }
4553                         break;
4554                 }
4555
4556 #endif /* ALLOW_WIZARD */
4557
4558
4559 #ifdef ALLOW_BORG
4560
4561                 /* Special "borg" commands */
4562                 case KTRL('Z'):
4563                 {
4564                         /* Enter borg mode */
4565                         if (enter_borg_mode())
4566                         {
4567                                 if (!p_ptr->wild_mode) do_cmd_borg();
4568                         }
4569
4570                         break;
4571                 }
4572
4573 #endif /* ALLOW_BORG */
4574
4575
4576
4577                 /*** Inventory Commands ***/
4578
4579                 /* Wear/wield equipment */
4580                 case 'w':
4581                 {
4582                         if (!p_ptr->wild_mode) do_cmd_wield();
4583                         break;
4584                 }
4585
4586                 /* Take off equipment */
4587                 case 't':
4588                 {
4589                         if (!p_ptr->wild_mode) do_cmd_takeoff();
4590                         break;
4591                 }
4592
4593                 /* Drop an item */
4594                 case 'd':
4595                 {
4596                         if (!p_ptr->wild_mode) do_cmd_drop();
4597                         break;
4598                 }
4599
4600                 /* Destroy an item */
4601                 case 'k':
4602                 {
4603                         do_cmd_destroy();
4604                         break;
4605                 }
4606
4607                 /* Equipment list */
4608                 case 'e':
4609                 {
4610                         do_cmd_equip();
4611                         break;
4612                 }
4613
4614                 /* Inventory list */
4615                 case 'i':
4616                 {
4617                         do_cmd_inven();
4618                         break;
4619                 }
4620
4621
4622                 /*** Various commands ***/
4623
4624                 /* Identify an object */
4625                 case 'I':
4626                 {
4627                         do_cmd_observe();
4628                         break;
4629                 }
4630
4631                 /* Hack -- toggle windows */
4632                 case KTRL('I'):
4633                 {
4634                         toggle_inven_equip();
4635                         break;
4636                 }
4637
4638
4639                 /*** Standard "Movement" Commands ***/
4640
4641                 /* Alter a grid */
4642                 case '+':
4643                 {
4644                         if (!p_ptr->wild_mode) do_cmd_alter();
4645                         break;
4646                 }
4647
4648                 /* Dig a tunnel */
4649                 case 'T':
4650                 {
4651                         if (!p_ptr->wild_mode) do_cmd_tunnel();
4652                         break;
4653                 }
4654
4655                 /* Move (usually pick up things) */
4656                 case ';':
4657                 {
4658 #ifdef ALLOW_EASY_DISARM /* TNB */
4659
4660                         do_cmd_walk(FALSE);
4661
4662 #else /* ALLOW_EASY_DISARM -- TNB */
4663
4664                         do_cmd_walk(always_pickup);
4665
4666 #endif /* ALLOW_EASY_DISARM -- TNB */
4667
4668                         break;
4669                 }
4670
4671                 /* Move (usually do not pick up) */
4672                 case '-':
4673                 {
4674 #ifdef ALLOW_EASY_DISARM /* TNB */
4675
4676                         do_cmd_walk(TRUE);
4677
4678 #else /* ALLOW_EASY_DISARM -- TNB */
4679
4680                         do_cmd_walk(!always_pickup);
4681
4682 #endif /* ALLOW_EASY_DISARM -- TNB */
4683
4684                         break;
4685                 }
4686
4687
4688                 /*** Running, Resting, Searching, Staying */
4689
4690                 /* Begin Running -- Arg is Max Distance */
4691                 case '.':
4692                 {
4693                         if (!p_ptr->wild_mode) do_cmd_run();
4694                         break;
4695                 }
4696
4697                 /* Stay still (usually pick things up) */
4698                 case ',':
4699                 {
4700                         do_cmd_stay(always_pickup);
4701                         break;
4702                 }
4703
4704                 /* Stay still (usually do not pick up) */
4705                 case 'g':
4706                 {
4707                         do_cmd_stay(!always_pickup);
4708                         break;
4709                 }
4710
4711                 /* Rest -- Arg is time */
4712                 case 'R':
4713                 {
4714                         do_cmd_rest();
4715                         break;
4716                 }
4717
4718                 /* Search for traps/doors */
4719                 case 's':
4720                 {
4721                         do_cmd_search();
4722                         break;
4723                 }
4724
4725                 /* Toggle search mode */
4726                 case 'S':
4727                 {
4728                         if (p_ptr->action == ACTION_SEARCH) set_action(ACTION_NONE);
4729                         else set_action(ACTION_SEARCH);
4730                         break;
4731                 }
4732
4733
4734                 /*** Stairs and Doors and Chests and Traps ***/
4735
4736                 /* Enter store */
4737                 case SPECIAL_KEY_STORE:
4738                 {
4739                         if (!p_ptr->wild_mode) do_cmd_store();
4740                         break;
4741                 }
4742
4743                 /* Enter building -KMW- */
4744                 case SPECIAL_KEY_BUILDING:
4745                 {
4746                         if (!p_ptr->wild_mode) do_cmd_bldg();
4747                         break;
4748                 }
4749
4750                 /* Enter quest level -KMW- */
4751                 case SPECIAL_KEY_QUEST:
4752                 {
4753                         if (!p_ptr->wild_mode) do_cmd_quest();
4754                         break;
4755                 }
4756
4757                 /* Go up staircase */
4758                 case '<':
4759                 {
4760                         if(!p_ptr->wild_mode && !dun_level && !p_ptr->inside_arena && !p_ptr->inside_quest)
4761                         {
4762                                 if (!vanilla_town)
4763                                 {
4764                                         if(ambush_flag)
4765                                         {
4766 #ifdef JP
4767                                                 msg_print("½±·â¤«¤éƨ¤²¤ë¤Ë¤Ï¥Þ¥Ã¥×¤Îü¤Þ¤Ç°ÜÆ°¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£");
4768 #else
4769                                                 msg_print("To flee the ambush you have to reach the edge of the map.");
4770 #endif
4771                                         }
4772                                         else if (p_ptr->food < PY_FOOD_WEAK)
4773                                         {
4774 #ifdef JP
4775                                                 msg_print("¤½¤ÎÁ°¤Ë¿©»ö¤ò¤È¤é¤Ê¤¤¤È¡£");
4776 #else
4777                                                 msg_print("You must eat something here.");
4778 #endif
4779                                         }
4780                                         else
4781                                         {
4782                                                 if (change_wild_mode())
4783                                                 {
4784                                                         p_ptr->oldpx = px;
4785                                                         p_ptr->oldpy = py;
4786                                                 }
4787                                         }
4788                                 }
4789                         }
4790                         else
4791                                 do_cmd_go_up();
4792                         break;
4793                 }
4794
4795                 /* Go down staircase */
4796                 case '>':
4797                 {
4798                         if(!p_ptr->wild_mode) do_cmd_go_down();
4799                         else
4800                         {
4801                                 p_ptr->wilderness_x = px;
4802                                 p_ptr->wilderness_y = py;
4803                                 change_wild_mode();
4804                         }
4805                         break;
4806                 }
4807
4808                 /* Open a door or chest */
4809                 case 'o':
4810                 {
4811                         if (!p_ptr->wild_mode) do_cmd_open();
4812                         break;
4813                 }
4814
4815                 /* Close a door */
4816                 case 'c':
4817                 {
4818                         if (!p_ptr->wild_mode) do_cmd_close();
4819                         break;
4820                 }
4821
4822                 /* Jam a door with spikes */
4823                 case 'j':
4824                 {
4825                         if (!p_ptr->wild_mode) do_cmd_spike();
4826                         break;
4827                 }
4828
4829                 /* Bash a door */
4830                 case 'B':
4831                 {
4832                         if (!p_ptr->wild_mode) do_cmd_bash();
4833                         break;
4834                 }
4835
4836                 /* Disarm a trap or chest */
4837                 case 'D':
4838                 {
4839                         if (!p_ptr->wild_mode) do_cmd_disarm();
4840                         break;
4841                 }
4842
4843
4844                 /*** Magic and Prayers ***/
4845
4846                 /* Gain new spells/prayers */
4847                 case 'G':
4848                 {
4849                         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
4850 #ifdef JP
4851                                 msg_print("¼öʸ¤ò³Ø½¬¤¹¤ëɬÍפϤʤ¤¡ª");
4852 #else
4853                                 msg_print("You don't have to learn spells!");
4854 #endif
4855                         else if (p_ptr->pclass == CLASS_SAMURAI)
4856                                 do_cmd_gain_hissatsu();
4857                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4858                                 gain_magic();
4859                         else
4860                                 do_cmd_study();
4861                         break;
4862                 }
4863
4864                 /* Browse a book */
4865                 case 'b':
4866                 {
4867                         if ( (p_ptr->pclass == CLASS_MINDCRAFTER) ||
4868                              (p_ptr->pclass == CLASS_BERSERKER) ||
4869                              (p_ptr->pclass == CLASS_NINJA) ||
4870                              (p_ptr->pclass == CLASS_MIRROR_MASTER) 
4871                              ) do_cmd_mind_browse();
4872                         else if (p_ptr->pclass == CLASS_SMITH)
4873                                 do_cmd_kaji(TRUE);
4874                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4875                                 do_cmd_magic_eater(TRUE);
4876                         else do_cmd_browse();
4877                         break;
4878                 }
4879
4880                 /* Cast a spell */
4881                 case 'm':
4882                 {
4883                         /* -KMW- */
4884                         if (!p_ptr->wild_mode)
4885                         {
4886                                 if ((p_ptr->pclass == CLASS_WARRIOR) || (p_ptr->pclass == CLASS_ARCHER) || (p_ptr->pclass == CLASS_CAVALRY))
4887                                 {
4888 #ifdef JP
4889                                         msg_print("¼öʸ¤ò¾§¤¨¤é¤ì¤Ê¤¤¡ª");
4890 #else
4891                                         msg_print("You cannot cast spells!");
4892 #endif
4893                                 }
4894                                 else if (dun_level && (d_info[dungeon_type].flags1 & DF1_NO_MAGIC) && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
4895                                 {
4896 #ifdef JP
4897                                         msg_print("¥À¥ó¥¸¥ç¥ó¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
4898 #else
4899                                         msg_print("The dungeon absorbs all attempted magic!");
4900 #endif
4901                                         msg_print(NULL);
4902                                 }
4903                                 else if (p_ptr->anti_magic && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
4904                                 {
4905 #ifdef JP
4906
4907                                         cptr which_power = "ËâË¡";
4908 #else
4909                                         cptr which_power = "magic";
4910 #endif
4911                                         if (p_ptr->pclass == CLASS_MINDCRAFTER)
4912 #ifdef JP
4913                                                 which_power = "ĶǽÎÏ";
4914 #else
4915                                                 which_power = "psionic powers";
4916 #endif
4917                                         else if (p_ptr->pclass == CLASS_IMITATOR)
4918 #ifdef JP
4919                                                 which_power = "¤â¤Î¤Þ¤Í";
4920 #else
4921                                                 which_power = "imitation";
4922 #endif
4923                                         else if (p_ptr->pclass == CLASS_SAMURAI)
4924 #ifdef JP
4925                                                 which_power = "ɬ»¦·õ";
4926 #else
4927                                                 which_power = "hissatsu";
4928 #endif
4929                                         else if (p_ptr->pclass == CLASS_MIRROR_MASTER)
4930 #ifdef JP
4931                                                 which_power = "¶ÀËâË¡";
4932 #else
4933                                                 which_power = "mirror magic";
4934 #endif
4935                                         else if (p_ptr->pclass == CLASS_NINJA)
4936 #ifdef JP
4937                                                 which_power = "Ǧ½Ñ";
4938 #else
4939                                                 which_power = "ninjutsu";
4940 #endif
4941                                         else if (mp_ptr->spell_book == TV_LIFE_BOOK)
4942 #ifdef JP
4943                                                 which_power = "µ§¤ê";
4944 #else
4945                                                 which_power = "prayer";
4946 #endif
4947
4948 #ifdef JP
4949                                         msg_format("È¿ËâË¡¥Ð¥ê¥¢¤¬%s¤ò¼ÙË⤷¤¿¡ª", which_power);
4950 #else
4951                                         msg_format("An anti-magic shell disrupts your %s!", which_power);
4952 #endif
4953                                         energy_use = 0;
4954                                 }
4955                                 else if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER))
4956                                 {
4957 #ifdef JP
4958                                         msg_format("¶¸Àï»Î²½¤·¤Æ¤¤¤ÆƬ¤¬²ó¤é¤Ê¤¤¡ª");
4959 #else
4960                                         msg_format("You cannot think directly!");
4961 #endif
4962                                         energy_use = 0;
4963                                 }
4964                                 else
4965                                 {
4966                                         if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
4967                                             (p_ptr->pclass == CLASS_BERSERKER) ||
4968                                             (p_ptr->pclass == CLASS_NINJA) ||
4969                                             (p_ptr->pclass == CLASS_MIRROR_MASTER)
4970                                             )
4971                                                 do_cmd_mind();
4972                                         else if (p_ptr->pclass == CLASS_IMITATOR)
4973                                                 do_cmd_mane(FALSE);
4974                                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4975                                                 do_cmd_magic_eater(FALSE);
4976                                         else if (p_ptr->pclass == CLASS_SAMURAI)
4977                                                 do_cmd_hissatsu();
4978                                         else if (p_ptr->pclass == CLASS_BLUE_MAGE)
4979                                                 do_cmd_cast_learned();
4980                                         else if (p_ptr->pclass == CLASS_SMITH)
4981                                                 do_cmd_kaji(FALSE);
4982                                         else
4983                                                 do_cmd_cast();
4984                                 }
4985                         }
4986                         break;
4987                 }
4988
4989                 /* Issue a pet command */
4990                 case 'p':
4991                 {
4992                         if (!p_ptr->wild_mode) do_cmd_pet();
4993                         break;
4994                 }
4995
4996                 /*** Use various objects ***/
4997
4998                 /* Inscribe an object */
4999                 case '{':
5000                 {
5001                         do_cmd_inscribe();
5002                         break;
5003                 }
5004
5005                 /* Uninscribe an object */
5006                 case '}':
5007                 {
5008                         do_cmd_uninscribe();
5009                         break;
5010                 }
5011
5012                 /* Activate an artifact */
5013                 case 'A':
5014                 {
5015                         if (!p_ptr->wild_mode)
5016                         {
5017                         if (!p_ptr->inside_arena)
5018                                 do_cmd_activate();
5019                         else
5020                         {
5021 #ifdef JP
5022 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
5023 #else
5024                                 msg_print("The arena absorbs all attempted magic!");
5025 #endif
5026
5027                                 msg_print(NULL);
5028                         }
5029                         }
5030                         break;
5031                 }
5032
5033                 /* Eat some food */
5034                 case 'E':
5035                 {
5036                         do_cmd_eat_food();
5037                         break;
5038                 }
5039
5040                 /* Fuel your lantern/torch */
5041                 case 'F':
5042                 {
5043                         do_cmd_refill();
5044                         break;
5045                 }
5046
5047                 /* Fire an item */
5048                 case 'f':
5049                 {
5050                         if (!p_ptr->wild_mode) do_cmd_fire();
5051                         break;
5052                 }
5053
5054                 /* Throw an item */
5055                 case 'v':
5056                 {
5057                         if (!p_ptr->wild_mode)
5058                         {
5059                                 do_cmd_throw();
5060                         }
5061                         break;
5062                 }
5063
5064                 /* Aim a wand */
5065                 case 'a':
5066                 {
5067                         if (!p_ptr->wild_mode)
5068                         {
5069                         if (!p_ptr->inside_arena)
5070                                 do_cmd_aim_wand();
5071                         else
5072                         {
5073 #ifdef JP
5074 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
5075 #else
5076                                 msg_print("The arena absorbs all attempted magic!");
5077 #endif
5078
5079                                 msg_print(NULL);
5080                         }
5081                         }
5082                         break;
5083                 }
5084
5085                 /* Zap a rod */
5086                 case 'z':
5087                 {
5088                         if (!p_ptr->wild_mode)
5089                         {
5090                         if (p_ptr->inside_arena)
5091                         {
5092 #ifdef JP
5093 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
5094 #else
5095                                 msg_print("The arena absorbs all attempted magic!");
5096 #endif
5097
5098                                 msg_print(NULL);
5099                         }
5100                         else if (use_command && rogue_like_commands)
5101                         {
5102                                 do_cmd_use();
5103                         }
5104                         else
5105                         {
5106                                 do_cmd_zap_rod();
5107                         }
5108                         }
5109                         break;
5110                 }
5111
5112                 /* Quaff a potion */
5113                 case 'q':
5114                 {
5115                         if (!p_ptr->wild_mode)
5116                         {
5117                         if (!p_ptr->inside_arena)
5118                                 do_cmd_quaff_potion();
5119                         else
5120                         {
5121 #ifdef JP
5122 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
5123 #else
5124                                 msg_print("The arena absorbs all attempted magic!");
5125 #endif
5126
5127                                 msg_print(NULL);
5128                         }
5129                         }
5130                         break;
5131                 }
5132
5133                 /* Read a scroll */
5134                 case 'r':
5135                 {
5136                         if (!p_ptr->wild_mode)
5137                         {
5138                         if (!p_ptr->inside_arena)
5139                                 do_cmd_read_scroll();
5140                         else
5141                         {
5142 #ifdef JP
5143 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
5144 #else
5145                                 msg_print("The arena absorbs all attempted magic!");
5146 #endif
5147
5148                                 msg_print(NULL);
5149                         }
5150                         }
5151                         break;
5152                 }
5153
5154                 /* Use a staff */
5155                 case 'u':
5156                 {
5157                         if (!p_ptr->wild_mode)
5158                         {
5159                         if (p_ptr->inside_arena)
5160                         {
5161 #ifdef JP
5162 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
5163 #else
5164                                 msg_print("The arena absorbs all attempted magic!");
5165 #endif
5166
5167                                 msg_print(NULL);
5168                         }
5169                         else if (use_command && !rogue_like_commands)
5170                         {
5171                                 do_cmd_use();
5172                         }
5173                         else
5174                                 do_cmd_use_staff();
5175                         }
5176                         break;
5177                 }
5178
5179                 /* Use racial power */
5180                 case 'U':
5181                 {
5182                         if (!p_ptr->wild_mode) do_cmd_racial_power();
5183                         break;
5184                 }
5185
5186
5187                 /*** Looking at Things (nearby or on map) ***/
5188
5189                 /* Full dungeon map */
5190                 case 'M':
5191                 {
5192                         do_cmd_view_map();
5193                         break;
5194                 }
5195
5196                 /* Locate player on map */
5197                 case 'L':
5198                 {
5199                         do_cmd_locate();
5200                         break;
5201                 }
5202
5203                 /* Look around */
5204                 case 'l':
5205                 {
5206                         do_cmd_look();
5207                         break;
5208                 }
5209
5210                 /* Target monster or location */
5211                 case '*':
5212                 {
5213                         if (!p_ptr->wild_mode) do_cmd_target();
5214                         break;
5215                 }
5216
5217
5218
5219                 /*** Help and Such ***/
5220
5221                 /* Help */
5222                 case '?':
5223                 {
5224                         do_cmd_help();
5225                         break;
5226                 }
5227
5228                 /* Identify symbol */
5229                 case '/':
5230                 {
5231                         do_cmd_query_symbol();
5232                         break;
5233                 }
5234
5235                 /* Character description */
5236                 case 'C':
5237                 {
5238                         do_cmd_change_name();
5239                         break;
5240                 }
5241
5242
5243                 /*** System Commands ***/
5244
5245                 /* Hack -- User interface */
5246                 case '!':
5247                 {
5248                         (void)Term_user(0);
5249                         break;
5250                 }
5251
5252                 /* Single line from a pref file */
5253                 case '"':
5254                 {
5255                         do_cmd_pref();
5256                         break;
5257                 }
5258
5259                 case '$':
5260                 {
5261                         do_cmd_reload_autopick();
5262                         break;
5263                 }
5264
5265                 case '_':
5266                 {
5267                         do_cmd_edit_autopick();
5268                         break;
5269                 }
5270
5271                 /* Interact with macros */
5272                 case '@':
5273                 {
5274                         do_cmd_macros();
5275                         break;
5276                 }
5277
5278                 /* Interact with visuals */
5279                 case '%':
5280                 {
5281                         do_cmd_visuals();
5282                         do_cmd_redraw();
5283                         break;
5284                 }
5285
5286                 /* Interact with colors */
5287                 case '&':
5288                 {
5289                         do_cmd_colors();
5290                         do_cmd_redraw();
5291                         break;
5292                 }
5293
5294                 /* Interact with options */
5295                 case '=':
5296                 {
5297                         do_cmd_options();
5298                         do_cmd_redraw();
5299                         break;
5300                 }
5301
5302                 /*** Misc Commands ***/
5303
5304                 /* Take notes */
5305                 case ':':
5306                 {
5307                         do_cmd_note();
5308                         break;
5309                 }
5310
5311                 /* Version info */
5312                 case 'V':
5313                 {
5314                         do_cmd_version();
5315                         break;
5316                 }
5317
5318                 /* Repeat level feeling */
5319                 case KTRL('F'):
5320                 {
5321                         if (!p_ptr->wild_mode) do_cmd_feeling();
5322                         break;
5323                 }
5324
5325                 /* Show previous message */
5326                 case KTRL('O'):
5327                 {
5328                         do_cmd_message_one();
5329                         break;
5330                 }
5331
5332                 /* Show previous messages */
5333                 case KTRL('P'):
5334                 {
5335                         do_cmd_messages(old_now_message);
5336                         break;
5337                 }
5338
5339                 /* Show quest status -KMW- */
5340                 case KTRL('Q'):
5341                 {
5342                         do_cmd_checkquest();
5343                         break;
5344                 }
5345
5346                 /* Redraw the screen */
5347                 case KTRL('R'):
5348                 {
5349                         now_message = old_now_message;
5350                         do_cmd_redraw();
5351                         break;
5352                 }
5353
5354 #ifndef VERIFY_SAVEFILE
5355
5356                 /* Hack -- Save and don't quit */
5357                 case KTRL('S'):
5358                 {
5359                         do_cmd_save_game(FALSE);
5360                         break;
5361                 }
5362
5363 #endif /* VERIFY_SAVEFILE */
5364
5365                 case KTRL('T'):
5366                 {
5367                         do_cmd_time();
5368                         break;
5369                 }
5370
5371                 /* Save and quit */
5372                 case KTRL('X'):
5373                 case SPECIAL_KEY_QUIT:
5374                 {
5375                         do_cmd_save_and_exit();
5376                         break;
5377                 }
5378
5379                 /* Quit (commit suicide) */
5380                 case 'Q':
5381                 {
5382                         do_cmd_suicide();
5383                         break;
5384                 }
5385
5386                 case '|':
5387                 {
5388                         do_cmd_nikki();
5389                         break;
5390                 }
5391
5392                 /* Check artifacts, uniques, objects */
5393                 case '~':
5394                 {
5395                         do_cmd_knowledge();
5396                         break;
5397                 }
5398
5399                 /* Load "screen dump" */
5400                 case '(':
5401                 {
5402                         do_cmd_load_screen();
5403                         break;
5404                 }
5405
5406                 /* Save "screen dump" */
5407                 case ')':
5408                 {
5409                         do_cmd_save_screen();
5410                         break;
5411                 }
5412
5413                 /* Make random artifact list */
5414                 case KTRL('V'):
5415                 {
5416                         spoil_random_artifact("randifact.txt");
5417                         break;
5418                 }
5419
5420                 /* Hack -- Unknown command */
5421                 default:
5422                 {
5423                         if (flush_failure) flush();
5424                         if (one_in_(2))
5425                         {
5426                                 char error_m[1024];
5427                                 sound(SOUND_ILLEGAL);
5428 #ifdef JP
5429                                 if (!get_rnd_line("error_j.txt", 0, error_m))
5430 #else
5431                                 if (!get_rnd_line("error.txt", 0, error_m))
5432 #endif
5433
5434                                         msg_print(error_m);
5435                         }
5436                         else
5437 #ifdef JP
5438 prt(" '?' ¤Ç¥Ø¥ë¥×¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£", 0, 0);
5439 #else
5440                                 prt("Type '?' for help.", 0, 0);
5441 #endif
5442
5443                         break;
5444                 }
5445         }
5446         if (!energy_use && !now_message)
5447                 now_message = old_now_message;
5448 }
5449
5450
5451
5452
5453 static bool monster_tsuri(int r_idx)
5454 {
5455         monster_race *r_ptr = &r_info[r_idx];
5456
5457         if ((r_ptr->flags7 & RF7_AQUATIC) && !(r_ptr->flags1 & RF1_UNIQUE) && my_strchr("Jjlw", r_ptr->d_char))
5458                 return TRUE;
5459         else
5460                 return FALSE;
5461 }
5462
5463
5464 /*
5465  * Process the player
5466  *
5467  * Notice the annoying code to handle "pack overflow", which
5468  * must come first just in case somebody manages to corrupt
5469  * the savefiles by clever use of menu commands or something.
5470  */
5471 static void process_player(void)
5472 {
5473         int i;
5474
5475         /*** Apply energy ***/
5476
5477         if (hack_mutation)
5478         {
5479 #ifdef JP
5480 msg_print("²¿¤«ÊѤï¤Ã¤¿µ¤¤¬¤¹¤ë¡ª");
5481 #else
5482                 msg_print("You feel different!");
5483 #endif
5484
5485                 (void)gain_random_mutation(0);
5486                 hack_mutation = FALSE;
5487         }
5488
5489         if (p_ptr->inside_battle)
5490         {
5491                 for(i = 1; i < m_max; i++)
5492                 {
5493                         monster_type *m_ptr = &m_list[i];
5494
5495                         if (!m_ptr->r_idx) continue;
5496
5497                         /* Hack -- Detect monster */
5498                         m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
5499
5500                         /* Update the monster */
5501                         update_mon(i, FALSE);
5502                 }
5503                 prt_time();
5504         }
5505
5506         /* Give the player some energy */
5507         else if (!(load && p_ptr->energy_need <= 0))
5508         {
5509                 p_ptr->energy_need -= SPEED_TO_ENERGY(p_ptr->pspeed);
5510         }
5511
5512         /* No turn yet */
5513         if (p_ptr->energy_need > 0) return;
5514         if (!command_rep) prt_time();
5515
5516         /*** Check for interupts ***/
5517
5518         /* Complete resting */
5519         if (resting < 0)
5520         {
5521                 /* Basic resting */
5522                 if (resting == -1)
5523                 {
5524                         /* Stop resting */
5525                         if ((p_ptr->chp == p_ptr->mhp) &&
5526                             (p_ptr->csp >= p_ptr->msp))
5527                         {
5528                                 set_action(ACTION_NONE);
5529                         }
5530                 }
5531
5532                 /* Complete resting */
5533                 else if (resting == -2)
5534                 {
5535                         /* Stop resting */
5536                         if ((p_ptr->chp == p_ptr->mhp) &&
5537                             (p_ptr->csp >= p_ptr->msp) &&
5538                             !p_ptr->blind && !p_ptr->confused &&
5539                             !p_ptr->poisoned && !p_ptr->afraid &&
5540                             !p_ptr->stun && !p_ptr->cut &&
5541                             !p_ptr->slow && !p_ptr->paralyzed &&
5542                             !p_ptr->image && !p_ptr->word_recall &&
5543                             !p_ptr->alter_reality)
5544                         {
5545                                 set_action(ACTION_NONE);
5546                         }
5547                 }
5548         }
5549
5550         if (p_ptr->action == ACTION_FISH)
5551         {
5552                 /* Delay */
5553                 Term_xtra(TERM_XTRA_DELAY, 10);
5554                 if (one_in_(1000))
5555                 {
5556                         int r_idx;
5557                         bool success = FALSE;
5558                         get_mon_num_prep(monster_tsuri,NULL);
5559                         r_idx = get_mon_num(dun_level ? dun_level : wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level);
5560                         msg_print(NULL);
5561                         if (r_idx && one_in_(2))
5562                         {
5563                                 int y, x;
5564                                 y = py+ddy[tsuri_dir];
5565                                 x = px+ddx[tsuri_dir];
5566                                 if (place_monster_aux(0, y, x, r_idx, PM_NO_KAGE))
5567                                 {
5568                                         char m_name[80];
5569                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
5570 #ifdef JP
5571                                         msg_format("%s¤¬Äà¤ì¤¿¡ª", m_name);
5572 #else
5573                                         msg_format("You have a good catch!", m_name);
5574 #endif
5575                                         success = TRUE;
5576                                 }
5577                         }
5578                         if (!success)
5579                         {
5580 #ifdef JP
5581                                 msg_print("±Â¤À¤±¿©¤ï¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª¤¯¤Ã¤½¡Á¡ª");
5582 #else
5583                                 msg_print("Damn!  The fish stole your bait!");
5584 #endif
5585                         }
5586                         disturb(0, 0);
5587                 }
5588         }
5589
5590         /* Handle "abort" */
5591         if (check_abort)
5592         {
5593                 /* Check for "player abort" (semi-efficiently for resting) */
5594                 if (running || command_rep || (p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH))
5595                 {
5596                         /* Do not wait */
5597                         inkey_scan = TRUE;
5598
5599                         /* Check for a key */
5600                         if (inkey())
5601                         {
5602                                 /* Flush input */
5603                                 flush();
5604
5605                                 /* Disturb */
5606                                 disturb(0, 0);
5607
5608                                 /* Hack -- Show a Message */
5609 #ifdef JP
5610 msg_print("ÃæÃǤ·¤Þ¤·¤¿¡£");
5611 #else
5612                                 msg_print("Canceled.");
5613 #endif
5614
5615                         }
5616                 }
5617         }
5618
5619         if (p_ptr->riding && !p_ptr->confused && !p_ptr->blind)
5620         {
5621                 monster_type *m_ptr = &m_list[p_ptr->riding];
5622                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
5623
5624                 if (m_ptr->csleep)
5625                 {
5626                         char m_name[80];
5627
5628                         /* Recover fully */
5629                         m_ptr->csleep = 0;
5630
5631                         if (r_ptr->flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
5632
5633                         /* Acquire the monster name */
5634                         monster_desc(m_name, m_ptr, 0);
5635 #ifdef JP
5636 msg_format("%^s¤òµ¯¤³¤·¤¿¡£", m_name);
5637 #else
5638                         msg_format("You have waked %s up.", m_name);
5639 #endif
5640                         if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= (PR_HEALTH);
5641                         p_ptr->redraw |= (PR_UHEALTH);
5642                 }
5643
5644                 if (m_ptr->stunned)
5645                 {
5646                         int d = 1;
5647
5648                         /* Make a "saving throw" against stun */
5649                         if (randint0(r_ptr->level) < p_ptr->skill_exp[GINOU_RIDING])
5650                         {
5651                                 /* Recover fully */
5652                                 d = m_ptr->stunned;
5653                         }
5654
5655                         /* Hack -- Recover from stun */
5656                         if (m_ptr->stunned > d)
5657                         {
5658                                 /* Recover somewhat */
5659                                 m_ptr->stunned -= d;
5660                         }
5661
5662                         /* Fully recover */
5663                         else
5664                         {
5665                                 char m_name[80];
5666
5667                                 /* Recover fully */
5668                                 m_ptr->stunned = 0;
5669
5670                                 /* Acquire the monster name */
5671                                 monster_desc(m_name, m_ptr, 0);
5672
5673                                 /* Dump a message */
5674 #ifdef JP
5675 msg_format("%^s¤òÛ¯Û°¾õÂÖ¤«¤éΩ¤Áľ¤é¤»¤¿¡£", m_name);
5676 #else
5677                                 msg_format("%^s is no longer stunned.", m_name);
5678 #endif
5679                                 if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= (PR_HEALTH);
5680                                 p_ptr->redraw |= (PR_UHEALTH);
5681                         }
5682                 }
5683
5684                 if (m_ptr->confused)
5685                 {
5686                         int d = 1;
5687
5688                         /* Make a "saving throw" against stun */
5689                         if (randint0(r_ptr->level) < p_ptr->skill_exp[GINOU_RIDING])
5690                         {
5691                                 /* Recover fully */
5692                                 d = m_ptr->confused;
5693                         }
5694
5695                         /* Hack -- Recover from stun */
5696                         if (m_ptr->confused > d)
5697                         {
5698                                 /* Recover somewhat */
5699                                 m_ptr->confused -= d;
5700                         }
5701
5702                         /* Fully recover */
5703                         else
5704                         {
5705                                 char m_name[80];
5706
5707                                 /* Recover fully */
5708                                 m_ptr->confused = 0;
5709
5710                                 /* Acquire the monster name */
5711                                 monster_desc(m_name, m_ptr, 0);
5712
5713                                 /* Dump a message */
5714 #ifdef JP
5715 msg_format("%^s¤òº®Íð¾õÂÖ¤«¤éΩ¤Áľ¤é¤»¤¿¡£", m_name);
5716 #else
5717                                 msg_format("%^s is no longer confused.", m_name);
5718 #endif
5719                                 if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= (PR_HEALTH);
5720                                 p_ptr->redraw |= (PR_UHEALTH);
5721                         }
5722                 }
5723
5724                 if (m_ptr->monfear)
5725                 {
5726                         int d = 1;
5727
5728                         /* Make a "saving throw" against stun */
5729                         if (randint0(r_ptr->level) < p_ptr->skill_exp[GINOU_RIDING])
5730                         {
5731                                 /* Recover fully */
5732                                 d = m_ptr->monfear;
5733                         }
5734
5735                         /* Hack -- Recover from stun */
5736                         if (m_ptr->monfear > d)
5737                         {
5738                                 /* Recover somewhat */
5739                                 m_ptr->monfear -= d;
5740                         }
5741
5742                         /* Fully recover */
5743                         else
5744                         {
5745                                 char m_name[80];
5746
5747                                 /* Recover fully */
5748                                 m_ptr->monfear = 0;
5749
5750                                 /* Acquire the monster name */
5751                                 monster_desc(m_name, m_ptr, 0);
5752
5753                                 /* Dump a message */
5754 #ifdef JP
5755 msg_format("%^s¤ò¶²Éݤ«¤éΩ¤Áľ¤é¤»¤¿¡£", m_name);
5756 #else
5757                                 msg_format("%^s is no longer fear.", m_name);
5758 #endif
5759                                 if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= (PR_HEALTH);
5760                                 p_ptr->redraw |= (PR_UHEALTH);
5761                         }
5762                 }
5763
5764                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5765                 handle_stuff();
5766         }
5767
5768         /* Handle the player song */
5769         if (!load) check_music();
5770
5771         load = FALSE;
5772
5773         /* Fast */
5774         if (p_ptr->lightspeed)
5775         {
5776                 (void)set_lightspeed(p_ptr->lightspeed - 1, TRUE);
5777         }
5778         if ((p_ptr->pclass == CLASS_FORCETRAINER) && (p_ptr->magic_num1[0]))
5779         {
5780                 if (p_ptr->magic_num1[0] < 40)
5781                 {
5782                         p_ptr->magic_num1[0] = 0;
5783                 }
5784                 else p_ptr->magic_num1[0] -= 40;
5785                 p_ptr->update |= (PU_BONUS);
5786         }
5787         if (p_ptr->action == ACTION_LEARN)
5788         {
5789                 int hoge = ((p_ptr->msp * 0x10000L) / 256L)+7680L;
5790                 if ((p_ptr->csp * 0x10000L + p_ptr->csp_frac) < hoge)
5791                 {
5792                         p_ptr->csp = 0;
5793                         p_ptr->csp_frac = 0;
5794                         set_action(ACTION_NONE);
5795                 }
5796                 else
5797                 {
5798                         p_ptr->csp -= (s16b)(hoge >> 16);
5799                         hoge &= 0xFFFFL;
5800                         if (p_ptr->csp_frac < hoge)
5801                         {
5802                                 p_ptr->csp_frac += 0x10000L - hoge;
5803                                 p_ptr->csp--;
5804                         }
5805                         else
5806                                 p_ptr->csp_frac -= hoge;
5807                 }
5808                 p_ptr->redraw |= PR_MANA;
5809         }
5810
5811         if (p_ptr->special_defense & KATA_MASK)
5812         {
5813                 if (p_ptr->special_defense & KATA_MUSOU)
5814                 {
5815                         if (p_ptr->csp < 3)
5816                         {
5817                                 set_action(ACTION_NONE);
5818                         }
5819                         else
5820                         {
5821                                 p_ptr->csp -= 2;
5822                                 p_ptr->redraw |= (PR_MANA);
5823                         }
5824                 }
5825         }
5826
5827         /*** Handle actual user input ***/
5828
5829         /* Repeat until out of energy */
5830         while (p_ptr->energy_need <= 0)
5831         {
5832                 p_ptr->window |= PW_PLAYER;
5833                 p_ptr->sutemi = FALSE;
5834                 p_ptr->counter = FALSE;
5835                 now_damaged = FALSE;
5836
5837                 /* Handle "p_ptr->notice" */
5838                 notice_stuff();
5839
5840                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5841                 handle_stuff();
5842
5843                 /* Place the cursor on the player */
5844                 move_cursor_relative(py, px);
5845
5846                 /* Refresh (optional) */
5847                 if (fresh_before) Term_fresh();
5848
5849
5850                 /* Hack -- Pack Overflow */
5851                 if (inventory[INVEN_PACK].k_idx)
5852                 {
5853                         int item = INVEN_PACK;
5854
5855                         char o_name[MAX_NLEN];
5856
5857                         object_type *o_ptr;
5858
5859                         /* Access the slot to be dropped */
5860                         o_ptr = &inventory[item];
5861
5862                         /* Disturbing */
5863                         disturb(0, 0);
5864
5865                         /* Warning */
5866 #ifdef JP
5867 msg_print("¥¶¥Ã¥¯¤«¤é¥¢¥¤¥Æ¥à¤¬¤¢¤Õ¤ì¤¿¡ª");
5868 #else
5869                         msg_print("Your pack overflows!");
5870 #endif
5871
5872
5873                         /* Describe */
5874                         object_desc(o_name, o_ptr, 0);
5875
5876                         /* Message */
5877 #ifdef JP
5878 msg_format("%s(%c)¤òÍî¤È¤·¤¿¡£", o_name, index_to_label(item));
5879 #else
5880                         msg_format("You drop %s (%c).", o_name, index_to_label(item));
5881 #endif
5882
5883
5884                         /* Drop it (carefully) near the player */
5885                         (void)drop_near(o_ptr, 0, py, px);
5886
5887                         /* Modify, Describe, Optimize */
5888                         inven_item_increase(item, -255);
5889                         inven_item_describe(item);
5890                         inven_item_optimize(item);
5891
5892                         /* Handle "p_ptr->notice" */
5893                         notice_stuff();
5894
5895                         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5896                         handle_stuff();
5897                 }
5898
5899
5900                 /* Hack -- cancel "lurking browse mode" */
5901                 if (!command_new) command_see = FALSE;
5902
5903
5904                 /* Assume free turn */
5905                 energy_use = 0;
5906
5907
5908                 if (p_ptr->inside_battle)
5909                 {
5910                         /* Place the cursor on the player */
5911                         move_cursor_relative(py, px);
5912
5913                         command_cmd = SPECIAL_KEY_BUILDING;
5914
5915                         /* Process the command */
5916                         process_command();
5917                 }
5918
5919                 /* Paralyzed or Knocked Out */
5920                 else if (p_ptr->paralyzed || (p_ptr->stun >= 100))
5921                 {
5922                         /* Take a turn */
5923                         energy_use = 100;
5924                 }
5925
5926                 /* Resting */
5927                 else if (p_ptr->action == ACTION_REST)
5928                 {
5929                         /* Timed rest */
5930                         if (resting > 0)
5931                         {
5932                                 /* Reduce rest count */
5933                                 resting--;
5934
5935                                 if (!resting) set_action(ACTION_NONE);
5936
5937                                 /* Redraw the state */
5938                                 p_ptr->redraw |= (PR_STATE);
5939                         }
5940
5941                         /* Take a turn */
5942                         energy_use = 100;
5943                 }
5944
5945                 /* Fishing */
5946                 else if (p_ptr->action == ACTION_FISH)
5947                 {
5948                         /* Take a turn */
5949                         energy_use = 100;
5950                 }
5951
5952                 /* Running */
5953                 else if (running)
5954                 {
5955                         /* Take a step */
5956                         run_step(0);
5957                 }
5958
5959                 /* Repeated command */
5960                 else if (command_rep)
5961                 {
5962                         /* Count this execution */
5963                         command_rep--;
5964
5965                         /* Redraw the state */
5966                         p_ptr->redraw |= (PR_STATE);
5967
5968                         /* Redraw stuff */
5969                         redraw_stuff();
5970
5971                         /* Hack -- Assume messages were seen */
5972                         msg_flag = FALSE;
5973
5974                         /* Clear the top line */
5975                         prt("", 0, 0);
5976
5977                         /* Process the command */
5978                         process_command();
5979                 }
5980
5981                 /* Normal command */
5982                 else
5983                 {
5984                         /* Place the cursor on the player */
5985                         move_cursor_relative(py, px);
5986
5987                         can_save = TRUE;
5988                         /* Get a command (normal) */
5989                         request_command(FALSE);
5990                         can_save = FALSE;
5991
5992                         /* Process the command */
5993                         process_command();
5994                 }
5995
5996
5997                 /*** Clean up ***/
5998
5999                 /* Significant */
6000                 if (energy_use)
6001                 {
6002                         /* Use some energy */
6003                         if (world_player || energy_use > 400)
6004                         {
6005                                 /* The Randomness is irrelevant */
6006                                 p_ptr->energy_need += energy_use * TURNS_PER_TICK / 10;
6007                         }
6008                         else
6009                         {
6010                                 /* There is some randomness of needed energy */
6011                                 p_ptr->energy_need += (s16b)((s32b)energy_use * ENERGY_NEED() / 100L);
6012                         }
6013
6014                         /* Hack -- constant hallucination */
6015                         if (p_ptr->image) p_ptr->redraw |= (PR_MAP);
6016
6017
6018                         /* Shimmer monsters if needed */
6019                         if (shimmer_monsters)
6020                         {
6021                                 /* Clear the flag */
6022                                 shimmer_monsters = FALSE;
6023
6024                                 /* Shimmer multi-hued monsters */
6025                                 for (i = 1; i < m_max; i++)
6026                                 {
6027                                         monster_type *m_ptr;
6028                                         monster_race *r_ptr;
6029
6030                                         /* Access monster */
6031                                         m_ptr = &m_list[i];
6032
6033                                         /* Skip dead monsters */
6034                                         if (!m_ptr->r_idx) continue;
6035
6036                                         /* Skip unseen monsters */
6037                                         if (!m_ptr->ml) continue;
6038
6039                                         /* Access the monster race */
6040                                         r_ptr = &r_info[m_ptr->ap_r_idx];
6041
6042                                         /* Skip non-multi-hued monsters */
6043                                         if (!(r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER)))
6044                                                 continue;
6045
6046                                         /* Reset the flag */
6047                                         shimmer_monsters = TRUE;
6048
6049                                         /* Redraw regardless */
6050                                         lite_spot(m_ptr->fy, m_ptr->fx);
6051                                 }
6052                         }
6053
6054
6055                         /* Handle monster detection */
6056                         if (repair_monsters)
6057                         {
6058                                 /* Reset the flag */
6059                                 repair_monsters = FALSE;
6060
6061                                 /* Rotate detection flags */
6062                                 for (i = 1; i < m_max; i++)
6063                                 {
6064                                         monster_type *m_ptr;
6065
6066                                         /* Access monster */
6067                                         m_ptr = &m_list[i];
6068
6069                                         /* Skip dead monsters */
6070                                         if (!m_ptr->r_idx) continue;
6071
6072                                         /* Nice monsters get mean */
6073                                         if (m_ptr->mflag & MFLAG_NICE)
6074                                         {
6075                                                 /* Nice monsters get mean */
6076                                                 m_ptr->mflag &= ~(MFLAG_NICE);
6077                                         }
6078
6079                                         /* Handle memorized monsters */
6080                                         if (m_ptr->mflag2 & MFLAG2_MARK)
6081                                         {
6082                                                 /* Maintain detection */
6083                                                 if (m_ptr->mflag2 & MFLAG2_SHOW)
6084                                                 {
6085                                                         /* Forget flag */
6086                                                         m_ptr->mflag2 &= ~(MFLAG2_SHOW);
6087
6088                                                         /* Still need repairs */
6089                                                         repair_monsters = TRUE;
6090                                                 }
6091
6092                                                 /* Remove detection */
6093                                                 else
6094                                                 {
6095                                                         /* Forget flag */
6096                                                         m_ptr->mflag2 &= ~(MFLAG2_MARK);
6097
6098                                                         /* Assume invisible */
6099                                                         m_ptr->ml = FALSE;
6100
6101                                                         /* Update the monster */
6102                                                         update_mon(i, FALSE);
6103
6104                                                         if (p_ptr->health_who == i) p_ptr->redraw |= (PR_HEALTH);
6105                                                         if (p_ptr->riding == i) p_ptr->redraw |= (PR_UHEALTH);
6106
6107                                                         /* Redraw regardless */
6108                                                         lite_spot(m_ptr->fy, m_ptr->fx);
6109                                                 }
6110                                         }
6111                                 }
6112                         }
6113                         if (p_ptr->pclass == CLASS_IMITATOR)
6114                         {
6115                                 if (p_ptr->mane_num > (p_ptr->lev > 44 ? 3 : p_ptr->lev > 29 ? 2 : 1))
6116                                 {
6117                                         p_ptr->mane_num--;
6118                                         for (i = 0; i < p_ptr->mane_num; i++)
6119                                         {
6120                                                 p_ptr->mane_spell[i] = p_ptr->mane_spell[i+1];
6121                                                 p_ptr->mane_dam[i] = p_ptr->mane_dam[i+1];
6122                                         }
6123                                 }
6124                                 new_mane = FALSE;
6125                                 p_ptr->redraw |= (PR_MANE);
6126                         }
6127                         if (p_ptr->action == ACTION_LEARN)
6128                         {
6129                                 new_mane = FALSE;
6130                                 p_ptr->redraw |= (PR_STATE);
6131                         }
6132
6133                         if (world_player && (p_ptr->energy_need > - 1000))
6134                         {
6135                                 /* Redraw map */
6136                                 p_ptr->redraw |= (PR_MAP);
6137
6138                                 /* Update monsters */
6139                                 p_ptr->update |= (PU_MONSTERS);
6140
6141                                 /* Window stuff */
6142                                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
6143
6144 #ifdef JP
6145                                 msg_print("¡Ö»þ¤ÏÆ°¤­¤À¤¹¡Ä¡×");
6146 #else
6147                                 msg_print("You feel time flowing around you once more.");
6148 #endif
6149                                 msg_print(NULL);
6150                                 world_player = FALSE;
6151                                 p_ptr->energy_need = ENERGY_NEED();
6152
6153                                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6154                                 handle_stuff();
6155                         }
6156                 }
6157
6158                 /* Hack -- notice death */
6159                 if (!p_ptr->playing || p_ptr->is_dead)
6160                 {
6161                         world_player = FALSE;
6162                         break;
6163                 }
6164
6165                 /* Handle "leaving" */
6166                 if (p_ptr->leaving) break;
6167         }
6168
6169         /* Update scent trail */
6170         update_smell();
6171 }
6172
6173
6174 /*
6175  * Interact with the current dungeon level.
6176  *
6177  * This function will not exit until the level is completed,
6178  * the user dies, or the game is terminated.
6179  */
6180 static void dungeon(bool load_game)
6181 {
6182         int quest_num = 0;
6183
6184         /* Set the base level */
6185         base_level = dun_level;
6186
6187         /* Reset various flags */
6188         hack_mind = FALSE;
6189
6190         /* Not leaving */
6191         p_ptr->leaving = FALSE;
6192
6193         /* Reset the "command" vars */
6194         command_cmd = 0;
6195
6196 #if 0 /* Don't reset here --- It's used for Arena */
6197         command_new = 0;
6198 #endif
6199
6200         command_rep = 0;
6201         command_arg = 0;
6202         command_dir = 0;
6203
6204
6205         /* Cancel the target */
6206         target_who = 0;
6207         pet_t_m_idx = 0;
6208         riding_t_m_idx = 0;
6209         ambush_flag = FALSE;
6210
6211         /* Cancel the health bar */
6212         health_track(0);
6213
6214         /* Check visual effects */
6215         shimmer_monsters = TRUE;
6216         shimmer_objects = TRUE;
6217         repair_monsters = TRUE;
6218         repair_objects = TRUE;
6219
6220
6221         /* Disturb */
6222         disturb(1, 0);
6223
6224         /* Get index of current quest (if any) */
6225         quest_num = quest_number(dun_level);
6226
6227         /* Inside a quest? */
6228         if (quest_num)
6229         {
6230                 /* Mark the quest monster */
6231                 r_info[quest[quest_num].r_idx].flags1 |= RF1_QUESTOR;
6232         }
6233
6234         /* Track maximum player level */
6235         if (p_ptr->max_plv < p_ptr->lev)
6236         {
6237                 p_ptr->max_plv = p_ptr->lev;
6238         }
6239
6240
6241         /* Track maximum dungeon level (if not in quest -KMW-) */
6242         if ((max_dlv[dungeon_type] < dun_level) && !p_ptr->inside_quest)
6243         {
6244                 max_dlv[dungeon_type] = dun_level;
6245                 if (record_maxdeapth) do_cmd_write_nikki(NIKKI_MAXDEAPTH, dun_level, NULL);
6246         }
6247
6248         /* Validate the panel */
6249         panel_bounds_center();
6250
6251         /* Verify the panel */
6252         verify_panel();
6253
6254         /* Flush messages */
6255         msg_print(NULL);
6256
6257
6258         /* Enter "xtra" mode */
6259         character_xtra = TRUE;
6260
6261         /* Window stuff */
6262         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_MONSTER | PW_OVERHEAD | PW_DUNGEON);
6263
6264         /* Redraw dungeon */
6265         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_EQUIPPY);
6266
6267         /* Redraw map */
6268         p_ptr->redraw |= (PR_MAP);
6269
6270         /* Update stuff */
6271         p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
6272
6273         /* Update lite/view */
6274         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_TORCH);
6275
6276         /* Update monsters */
6277         p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
6278
6279         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6280         handle_stuff();
6281
6282         /* Leave "xtra" mode */
6283         character_xtra = FALSE;
6284
6285         /* Update stuff */
6286         p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
6287
6288         /* Combine / Reorder the pack */
6289         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
6290
6291         /* Handle "p_ptr->notice" */
6292         notice_stuff();
6293
6294         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6295         handle_stuff();
6296
6297         /* Refresh */
6298         Term_fresh();
6299
6300         if (quest_num && (is_fixed_quest_idx(quest_num) &&
6301             !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) ||
6302             !(quest[quest_num].flags & QUEST_FLAG_PRESET)))) do_cmd_feeling();
6303
6304         if (p_ptr->inside_battle)
6305         {
6306                 if (load_game)
6307                 {
6308                         p_ptr->energy_need = 0;
6309                         battle_monsters();
6310                 }
6311                 else
6312                 {
6313 #ifdef JP
6314 msg_print("»î¹ç³«»Ï¡ª");
6315 #else
6316                         msg_format("Ready..Fight!");
6317 #endif
6318                         msg_print(NULL);
6319                 }
6320         }
6321
6322         if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] > MUSIC_DETECT))
6323                 p_ptr->magic_num1[0] = MUSIC_DETECT;
6324
6325         /* Hack -- notice death or departure */
6326         if (!p_ptr->playing || p_ptr->is_dead) return;
6327
6328         /* Print quest message if appropriate */
6329         if (!p_ptr->inside_quest && (dungeon_type == DUNGEON_ANGBAND))
6330         {
6331                 quest_discovery(random_quest_number(dun_level));
6332                 p_ptr->inside_quest = random_quest_number(dun_level);
6333         }
6334         if ((dun_level == d_info[dungeon_type].maxdepth) && d_info[dungeon_type].final_guardian)
6335         {
6336                 if (r_info[d_info[dungeon_type].final_guardian].max_num)
6337 #ifdef JP
6338                         msg_format("¤³¤Î³¬¤Ë¤Ï%s¤Î¼ç¤Ç¤¢¤ë%s¤¬À³¤ó¤Ç¤¤¤ë¡£",
6339                                    d_name+d_info[dungeon_type].name, 
6340                                    r_name+r_info[d_info[dungeon_type].final_guardian].name);
6341 #else
6342                         msg_format("%^s lives in this level as the keeper of %s.",
6343                                            r_name+r_info[d_info[dungeon_type].final_guardian].name, 
6344                                            d_name+d_info[dungeon_type].name);
6345 #endif
6346         }
6347
6348         /*** Process this dungeon level ***/
6349
6350         /* Reset the monster generation level */
6351         monster_level = base_level;
6352
6353         /* Reset the object generation level */
6354         object_level = base_level;
6355
6356         hack_mind = TRUE;
6357
6358         if (p_ptr->energy_need > 0 && !p_ptr->inside_battle &&
6359             (dun_level || p_ptr->leaving_dungeon || p_ptr->inside_arena))
6360                 p_ptr->energy_need = 0;
6361
6362         /* Not leaving dungeon */
6363         p_ptr->leaving_dungeon = FALSE;
6364
6365         /* Main loop */
6366         while (TRUE)
6367         {
6368                 /* Hack -- Compact the monster list occasionally */
6369                 if ((m_cnt + 32 > max_m_idx) && !p_ptr->inside_battle) compact_monsters(64);
6370
6371                 /* Hack -- Compress the monster list occasionally */
6372                 if ((m_cnt + 32 < m_max) && !p_ptr->inside_battle) compact_monsters(0);
6373
6374
6375                 /* Hack -- Compact the object list occasionally */
6376                 if (o_cnt + 32 > max_o_idx) compact_objects(64);
6377
6378                 /* Hack -- Compress the object list occasionally */
6379                 if (o_cnt + 32 < o_max) compact_objects(0);
6380
6381
6382                 /* Process the player */
6383                 process_player();
6384
6385                 /* Handle "p_ptr->notice" */
6386                 notice_stuff();
6387
6388                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6389                 handle_stuff();
6390
6391                 /* Hack -- Hilite the player */
6392                 move_cursor_relative(py, px);
6393
6394                 /* Optional fresh */
6395                 if (fresh_after) Term_fresh();
6396
6397                 /* Hack -- Notice death or departure */
6398                 if (!p_ptr->playing || p_ptr->is_dead) break;
6399
6400                 /* Process all of the monsters */
6401                 process_monsters();
6402
6403                 /* Handle "p_ptr->notice" */
6404                 notice_stuff();
6405
6406                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6407                 handle_stuff();
6408
6409                 /* Hack -- Hilite the player */
6410                 move_cursor_relative(py, px);
6411
6412                 /* Optional fresh */
6413                 if (fresh_after) Term_fresh();
6414
6415                 /* Hack -- Notice death or departure */
6416                 if (!p_ptr->playing || p_ptr->is_dead) break;
6417
6418
6419                 /* Process the world */
6420                 process_world();
6421
6422                 /* Handle "p_ptr->notice" */
6423                 notice_stuff();
6424
6425                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6426                 handle_stuff();
6427
6428                 /* Hack -- Hilite the player */
6429                 move_cursor_relative(py, px);
6430
6431                 /* Optional fresh */
6432                 if (fresh_after) Term_fresh();
6433
6434                 /* Hack -- Notice death or departure */
6435                 if (!p_ptr->playing || p_ptr->is_dead) break;
6436
6437                 /* Handle "leaving" */
6438                 if (p_ptr->leaving) break;
6439
6440                 /* Count game turns */
6441                 turn++;
6442                 if (!p_ptr->wild_mode || wild_regen) dungeon_turn++;
6443                 else if (p_ptr->wild_mode && !(turn % ((MAX_HGT + MAX_WID) / 2))) dungeon_turn++;
6444                 if (wild_regen) wild_regen--;
6445         }
6446
6447         /* Inside a quest and non-unique questor? */
6448         if (quest_num && !(r_info[quest[quest_num].r_idx].flags1 & RF1_UNIQUE))
6449         {
6450                 /* Un-mark the quest monster */
6451                 r_info[quest[quest_num].r_idx].flags1 &= ~RF1_QUESTOR;
6452         }
6453
6454         /* Not save-and-quit and not dead? */
6455         if (p_ptr->playing && !p_ptr->is_dead)
6456         {
6457                 /*
6458                  * Maintain Unique monsters and artifact, save current
6459                  * floor, then prepare next floor
6460                  */
6461                 leave_floor();
6462
6463                 /* Forget the flag */
6464                 reinit_wilderness = FALSE;
6465         }
6466
6467         /* Write about current level on the play record once per level */
6468         write_level = TRUE;
6469 }
6470
6471
6472 /*
6473  * Load some "user pref files"
6474  *
6475  * Modified by Arcum Dagsson to support
6476  * separate macro files for different realms.
6477  */
6478 static void load_all_pref_files(void)
6479 {
6480         char buf[1024];
6481
6482         /* Access the "user" pref file */
6483         sprintf(buf, "user.prf");
6484
6485         /* Process that file */
6486         process_pref_file(buf);
6487
6488         /* Access the "user" system pref file */
6489         sprintf(buf, "user-%s.prf", ANGBAND_SYS);
6490
6491         /* Process that file */
6492         process_pref_file(buf);
6493
6494         /* Access the "race" pref file */
6495         sprintf(buf, "%s.prf", rp_ptr->title);
6496
6497         /* Process that file */
6498         process_pref_file(buf);
6499
6500         /* Access the "class" pref file */
6501         sprintf(buf, "%s.prf", cp_ptr->title);
6502
6503         /* Process that file */
6504         process_pref_file(buf);
6505
6506         /* Access the "character" pref file */
6507         sprintf(buf, "%s.prf", player_base);
6508
6509         /* Process that file */
6510         process_pref_file(buf);
6511
6512         /* Access the "realm 1" pref file */
6513         if (p_ptr->realm1 != REALM_NONE)
6514         {
6515                 sprintf(buf, "%s.prf", realm_names[p_ptr->realm1]);
6516
6517                 /* Process that file */
6518                 process_pref_file(buf);
6519         }
6520
6521         /* Access the "realm 2" pref file */
6522         if (p_ptr->realm2 != REALM_NONE)
6523         {
6524                 sprintf(buf, "%s.prf", realm_names[p_ptr->realm2]);
6525
6526                 /* Process that file */
6527                 process_pref_file(buf);
6528         }
6529
6530
6531         /* Load an autopick preference file */
6532         autopick_load_pref(FALSE);
6533 }
6534
6535
6536 /*
6537  * Extract option variables from bit sets
6538  */
6539 void extract_option_vars(void)
6540 {
6541         int i;
6542
6543         for (i = 0; option_info[i].o_desc; i++)
6544         {
6545                 int os = option_info[i].o_set;
6546                 int ob = option_info[i].o_bit;
6547
6548                 /* Set the "default" options */
6549                 if (option_info[i].o_var)
6550                 {
6551                         /* Set */
6552                         if (option_flag[os] & (1L << ob))
6553                         {
6554                                 /* Set */
6555                                 (*option_info[i].o_var) = TRUE;
6556                         }
6557
6558                         /* Clear */
6559                         else
6560                         {
6561                                 /* Clear */
6562                                 (*option_info[i].o_var) = FALSE;
6563                         }
6564                 }
6565         }
6566 }
6567
6568
6569 /*
6570  * Determine bounty uniques
6571  */
6572 void determine_bounty_uniques(void)
6573 {
6574         int          i, j, tmp;
6575         monster_race *r_ptr;
6576
6577         get_mon_num_prep(NULL, NULL);
6578         for (i = 0; i < MAX_KUBI; i++)
6579         {
6580                 while (1)
6581                 {
6582                         kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
6583                         r_ptr = &r_info[kubi_r_idx[i]];
6584
6585                         if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
6586
6587                         if (!(r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON))) continue;
6588
6589                         if (r_ptr->rarity > 100) continue;
6590
6591                         if (no_questor_or_bounty_uniques(kubi_r_idx[i])) continue;
6592
6593                         for (j = 0; j < i; j++)
6594                                 if (kubi_r_idx[i] == kubi_r_idx[j]) break;
6595
6596                         if (j == i) break;
6597                 }
6598         }
6599
6600         /* Sort them */
6601         for (i = 0; i < MAX_KUBI - 1; i++)
6602         {
6603                 for (j = i; j < MAX_KUBI; j++)
6604                 {
6605                         if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
6606                         {
6607                                 tmp = kubi_r_idx[i];
6608                                 kubi_r_idx[i] = kubi_r_idx[j];
6609                                 kubi_r_idx[j] = tmp;
6610                         }
6611                 }
6612         }
6613 }
6614
6615
6616 /*
6617  * Determine today's bounty monster
6618  * Note: conv_old is used if loaded 0.0.3 or older save file
6619  */
6620 void determine_today_mon(bool conv_old)
6621 {
6622         int max_dl = 3, i;
6623         bool old_inside_battle = p_ptr->inside_battle;
6624         monster_race *r_ptr;
6625
6626         if (!conv_old)
6627         {
6628                 for (i = 0; i < max_d_idx; i++)
6629                 {
6630                         if (max_dlv[i] < d_info[i].mindepth) continue;
6631                         if (max_dl < max_dlv[i]) max_dl = max_dlv[i];
6632                 }
6633         }
6634         else max_dl = MAX(max_dlv[DUNGEON_ANGBAND], 3);
6635
6636         p_ptr->inside_battle = TRUE;
6637         get_mon_num_prep(NULL, NULL);
6638
6639         while (1)
6640         {
6641                 today_mon = get_mon_num(max_dl);
6642                 r_ptr = &r_info[today_mon];
6643
6644                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
6645                 if (r_ptr->flags7 & (RF7_NAZGUL | RF7_UNIQUE2)) continue;
6646                 if (r_ptr->flags2 & RF2_MULTIPLY) continue;
6647                 if ((r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) != (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) continue;
6648                 if (r_ptr->level < MIN(max_dl / 2, 40)) continue;
6649                 if (r_ptr->rarity > 10) continue;
6650                 break;
6651         }
6652
6653         p_ptr->today_mon = 0;
6654         p_ptr->inside_battle = old_inside_battle;
6655 }
6656
6657
6658 /*
6659  * Actually play a game
6660  *
6661  * If the "new_game" parameter is true, then, after loading the
6662  * savefile, we will commit suicide, if necessary, to allow the
6663  * player to start a new game.
6664  */
6665 void play_game(bool new_game)
6666 {
6667         int i;
6668         bool load_game = TRUE;
6669
6670 #ifdef CHUUKEI
6671         if(chuukei_client){
6672           reset_visuals();
6673           browse_chuukei();
6674           return;
6675         }
6676 #endif
6677
6678         hack_mutation = FALSE;
6679
6680         /* Hack -- Character is "icky" */
6681         character_icky = TRUE;
6682
6683         /* Make sure main term is active */
6684         Term_activate(angband_term[0]);
6685
6686         /* Initialise the resize hooks */
6687         angband_term[0]->resize_hook = resize_map;
6688
6689         for (i = 1; i < 8; i++)
6690         {
6691                 /* Does the term exist? */
6692                 if (angband_term[i])
6693                 {
6694                         /* Add the redraw on resize hook */
6695                         angband_term[i]->resize_hook = redraw_window;
6696                 }
6697         }
6698
6699         /* Hack -- turn off the cursor */
6700         (void)Term_set_cursor(0);
6701
6702
6703         /* Attempt to load */
6704         if (!load_player())
6705         {
6706                 /* Oops */
6707 #ifdef JP
6708 quit("¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤¬²õ¤ì¤Æ¤¤¤Þ¤¹");
6709 #else
6710                 quit("broken savefile");
6711 #endif
6712
6713         }
6714
6715         /* Extract the options */
6716         extract_option_vars();
6717
6718         /* Report waited score */
6719         if (p_ptr->wait_report_score)
6720         {
6721                 char buf[1024];
6722                 bool success;
6723
6724 #ifdef JP
6725                 if (!get_check_strict("ÂÔµ¡¤·¤Æ¤¤¤¿¥¹¥³¥¢ÅÐÏ¿¤òº£¹Ô¤Ê¤¤¤Þ¤¹¤«¡©", CHECK_NO_HISTORY))
6726 #else
6727                 if (!get_check_strict("Do you register score now? ", CHECK_NO_HISTORY))
6728 #endif
6729                         quit(0);
6730
6731                 /* Update stuff */
6732                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
6733
6734                 /* Update stuff */
6735                 update_stuff();
6736
6737                 p_ptr->is_dead = TRUE;
6738
6739                 start_time = time(NULL);
6740
6741                 /* No suspending now */
6742                 signals_ignore_tstp();
6743                 
6744                 /* Hack -- Character is now "icky" */
6745                 character_icky = TRUE;
6746
6747                 /* Build the filename */
6748                 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
6749
6750                 /* Open the high score file, for reading/writing */
6751                 highscore_fd = fd_open(buf, O_RDWR);
6752
6753                 /* Handle score, show Top scores */
6754                 success = send_world_score(TRUE);
6755
6756 #ifdef JP
6757                 if (!success && !get_check_strict("¥¹¥³¥¢ÅÐÏ¿¤òÄü¤á¤Þ¤¹¤«¡©", CHECK_NO_HISTORY))
6758 #else
6759                 if (!success && !get_check_strict("Do you give up score registration? ", CHECK_NO_HISTORY))
6760 #endif
6761                 {
6762 #ifdef JP
6763                         prt("°ú¤­Â³¤­ÂÔµ¡¤·¤Þ¤¹¡£", 0, 0);
6764 #else
6765                         prt("standing by for future registration...", 0, 0);
6766 #endif
6767                         (void)inkey();
6768                 }
6769                 else
6770                 {
6771                         p_ptr->wait_report_score = FALSE;
6772                         top_twenty();
6773 #ifdef JP
6774                         if (!save_player()) msg_print("¥»¡¼¥Ö¼ºÇÔ¡ª");
6775 #else
6776                         if (!save_player()) msg_print("death save failed!");
6777 #endif
6778                 }
6779                 /* Shut the high score file */
6780                 (void)fd_close(highscore_fd);
6781
6782                 /* Forget the high score fd */
6783                 highscore_fd = -1;
6784                 
6785                 /* Allow suspending now */
6786                 signals_handle_tstp();
6787
6788                 quit(0);
6789         }
6790
6791         /* Nothing loaded */
6792         if (!character_loaded)
6793         {
6794                 /* Make new player */
6795                 new_game = TRUE;
6796
6797                 /* The dungeon is not ready */
6798                 character_dungeon = FALSE;
6799
6800                 /* Prepare to init the RNG */
6801                 Rand_quick = TRUE;
6802
6803                 /* Initialize the saved floors data */
6804                 init_saved_floors(FALSE);
6805         }
6806
6807         /* Old game is loaded.  But new game is requested. */
6808         else if (new_game)
6809         {
6810                 /* Initialize the saved floors data */
6811                 init_saved_floors(TRUE);
6812         }
6813
6814         /* Process old character */
6815         if (!new_game)
6816         {
6817                 /* Process the player name */
6818                 process_player_name(FALSE);
6819         }
6820
6821         /* Init the RNG */
6822         if (Rand_quick)
6823         {
6824                 u32b seed;
6825
6826                 /* Basic seed */
6827                 seed = (time(NULL));
6828
6829 #ifdef SET_UID
6830
6831                 /* Mutate the seed on Unix machines */
6832                 seed = ((seed >> 3) * (getpid() << 1));
6833
6834 #endif
6835
6836                 /* Use the complex RNG */
6837                 Rand_quick = FALSE;
6838
6839                 /* Seed the "complex" RNG */
6840                 Rand_state_init(seed);
6841         }
6842
6843         /* Roll new character */
6844         if (new_game)
6845         {
6846                 /* The dungeon is not ready */
6847                 character_dungeon = FALSE;
6848
6849                 /* Start in town */
6850                 dun_level = 0;
6851                 p_ptr->inside_quest = 0;
6852                 p_ptr->inside_arena = FALSE;
6853                 p_ptr->inside_battle = FALSE;
6854
6855                 write_level = TRUE;
6856
6857                 /* Hack -- seed for flavors */
6858                 seed_flavor = randint0(0x10000000);
6859
6860                 /* Hack -- seed for town layout */
6861                 seed_town = randint0(0x10000000);
6862
6863                 /* Roll up a new character */
6864                 player_birth();
6865
6866                 counts_write(2,0);
6867                 p_ptr->count = 0;
6868
6869                 load = FALSE;
6870
6871                 determine_bounty_uniques();
6872                 determine_today_mon(FALSE);
6873         }
6874         else
6875         {
6876                 write_level = FALSE;
6877
6878 #ifdef JP
6879                 do_cmd_write_nikki(NIKKI_GAMESTART, 1, "                            ----¥²¡¼¥àºÆ³«----");
6880 #else
6881                 do_cmd_write_nikki(NIKKI_GAMESTART, 1, "                            ---- Restart Game ----");
6882 #endif
6883
6884 /*
6885  * 1.0.9 °ÊÁ°¤Ï¥»¡¼¥ÖÁ°¤Ë p_ptr->riding = -1 ¤È¤·¤Æ¤¤¤¿¤Î¤Ç¡¢ºÆÀßÄ꤬ɬÍפÀ¤Ã¤¿¡£
6886  * ¤â¤¦ÉÔÍפÀ¤¬¡¢°ÊÁ°¤Î¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤È¤Î¸ß´¹¤Î¤¿¤á¤Ë»Ä¤·¤Æ¤ª¤¯¡£
6887  */
6888                 if (p_ptr->riding == -1)
6889                 {
6890                         p_ptr->riding = 0;
6891                         for (i = m_max; i > 0; i--)
6892                         {
6893                                 if (player_bold(m_list[i].fy, m_list[i].fx))
6894                                 {
6895                                         p_ptr->riding = i;
6896                                         break;
6897                                 }
6898                         }
6899                 }
6900         }
6901
6902         p_ptr->teleport_town = FALSE;
6903         p_ptr->sutemi = FALSE;
6904         world_monster = FALSE;
6905         now_damaged = FALSE;
6906         now_message = 0;
6907         start_time = time(NULL) - 1;
6908         record_o_name[0] = '\0';
6909
6910         /* Reset map panel */
6911         panel_row_min = cur_hgt;
6912         panel_col_min = cur_wid;
6913
6914         /* Sexy gal gets bonus to maximum weapon skill of whip */
6915         if (p_ptr->pseikaku == SEIKAKU_SEXY)
6916                 s_info[p_ptr->pclass].w_max[TV_HAFTED-TV_WEAPON_BEGIN][SV_WHIP] = WEAPON_EXP_MASTER;
6917
6918         /* Fill the arrays of floors and walls in the good proportions */
6919         set_floor_and_wall(dungeon_type);
6920
6921         /* Flavor the objects */
6922         flavor_init();
6923         if (new_game)
6924         {
6925                 wipe_o_list();
6926                 player_outfit();
6927         }
6928
6929         /* Flash a message */
6930 #ifdef JP
6931 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
6932 #else
6933         prt("Please wait...", 0, 0);
6934 #endif
6935
6936
6937         /* Flush the message */
6938         Term_fresh();
6939
6940
6941         /* Hack -- Enter wizard mode */
6942         if (arg_wizard)
6943         {
6944                 if (enter_wizard_mode()) p_ptr->wizard = TRUE;
6945                 else if (p_ptr->is_dead) quit("Already dead.");
6946         }
6947
6948         /* Initialize the town-buildings if necessary */
6949         if (!dun_level && !p_ptr->inside_quest)
6950         {
6951                 /* Init the wilderness */
6952
6953                 process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
6954
6955                 /* Init the town */
6956                 init_flags = INIT_ONLY_BUILDINGS;
6957
6958                 process_dungeon_file("t_info.txt", 0, 0, MAX_HGT, MAX_WID);
6959
6960         }
6961
6962
6963         /* Generate a dungeon level if needed */
6964         if (!character_dungeon)
6965         {
6966                 change_floor();
6967         }
6968
6969
6970         /* Character is now "complete" */
6971         character_generated = TRUE;
6972
6973
6974         /* Hack -- Character is no longer "icky" */
6975         character_icky = FALSE;
6976
6977
6978         if (new_game)
6979         {
6980                 char buf[80];
6981
6982 #ifdef JP
6983                 sprintf(buf, "%s¤Ë¹ß¤êΩ¤Ã¤¿¡£", map_name());
6984 #else
6985                 sprintf(buf, "You are standing in the %s.", map_name());
6986 #endif
6987                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, buf);
6988         }
6989
6990
6991         /* Start game */
6992         p_ptr->playing = TRUE;
6993
6994         /* Reset the visual mappings */
6995         reset_visuals();
6996
6997         /* Load the "pref" files */
6998         load_all_pref_files();
6999
7000         /* React to changes */
7001         Term_xtra(TERM_XTRA_REACT, 0);
7002
7003         /* Window stuff */
7004         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
7005
7006         /* Window stuff */
7007         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
7008
7009         /* Window stuff */
7010         window_stuff();
7011
7012
7013         /* Set or clear "rogue_like_commands" if requested */
7014         if (arg_force_original) rogue_like_commands = FALSE;
7015         if (arg_force_roguelike) rogue_like_commands = TRUE;
7016
7017         /* Hack -- Enforce "delayed death" */
7018         if (p_ptr->chp < 0) p_ptr->is_dead = TRUE;
7019
7020         if (p_ptr->prace == RACE_ANDROID) calc_android_exp();
7021
7022         if (new_game && ((p_ptr->pclass == CLASS_CAVALRY) || (p_ptr->pclass == CLASS_BEASTMASTER)))
7023         {
7024                 monster_type *m_ptr;
7025                 int pet_r_idx = ((p_ptr->pclass == CLASS_CAVALRY) ? MON_HORSE : MON_YASE_HORSE);
7026                 monster_race *r_ptr = &r_info[pet_r_idx];
7027                 place_monster_aux(0, py, px - 1, pet_r_idx,
7028                                   (PM_FORCE_PET | PM_NO_KAGE));
7029                 m_ptr = &m_list[hack_m_idx_ii];
7030                 m_ptr->mspeed = r_ptr->speed;
7031                 m_ptr->maxhp = r_ptr->hdice*(r_ptr->hside+1)/2;
7032                 m_ptr->max_maxhp = m_ptr->maxhp;
7033                 m_ptr->hp = r_ptr->hdice*(r_ptr->hside+1)/2;
7034                 m_ptr->energy_need = ENERGY_NEED() + ENERGY_NEED();
7035         }
7036
7037         /* Process */
7038         while (TRUE)
7039         {
7040                 /* Process the level */
7041                 dungeon(load_game);
7042
7043                 /* Handle "p_ptr->notice" */
7044                 notice_stuff();
7045
7046                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
7047                 handle_stuff();
7048
7049                 /* Cancel the target */
7050                 target_who = 0;
7051
7052                 /* Cancel the health bar */
7053                 health_track(0);
7054
7055
7056                 /* Forget the lite */
7057                 forget_lite();
7058
7059                 /* Forget the view */
7060                 forget_view();
7061
7062                 /* Forget the view */
7063                 clear_mon_lite();
7064
7065                 /* Handle "quit and save" */
7066                 if (!p_ptr->playing && !p_ptr->is_dead) break;
7067
7068                 /* Erase the old cave */
7069                 wipe_o_list();
7070                 if (!p_ptr->is_dead) wipe_m_list();
7071
7072
7073                 /* XXX XXX XXX */
7074                 msg_print(NULL);
7075
7076                 load_game = FALSE;
7077
7078                 /* Accidental Death */
7079                 if (p_ptr->playing && p_ptr->is_dead)
7080                 {
7081                         if (p_ptr->inside_arena)
7082                         {
7083                                 p_ptr->inside_arena = FALSE;
7084                                 if (p_ptr->arena_number > MAX_ARENA_MONS)
7085                                         p_ptr->arena_number++;
7086                                 else
7087                                         p_ptr->arena_number = -1 - p_ptr->arena_number;
7088                                 p_ptr->is_dead = FALSE;
7089                                 p_ptr->chp = 0;
7090                                 p_ptr->chp_frac = 0;
7091                                 p_ptr->exit_bldg = TRUE;
7092                                 reset_tim_flags();
7093
7094                                 /* Leave through the exit */
7095                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_RAND_CONNECT);
7096
7097                                 /* prepare next floor */
7098                                 leave_floor();
7099                         }
7100                         else
7101                         {
7102                                 /* Mega-Hack -- Allow player to cheat death */
7103 #ifdef JP
7104 if ((p_ptr->wizard || cheat_live) && !get_check("»à¤Ë¤Þ¤¹¤«? "))
7105 #else
7106                                 if ((p_ptr->wizard || cheat_live) && !get_check("Die? "))
7107 #endif
7108
7109                                 {
7110                                         /* Mark social class, reset age, if needed */
7111                                         if (p_ptr->sc) p_ptr->sc = p_ptr->age = 0;
7112
7113                                         /* Increase age */
7114                                         p_ptr->age++;
7115
7116                                         /* Mark savefile */
7117                                         p_ptr->noscore |= 0x0001;
7118
7119                                         /* Message */
7120 #ifdef JP
7121 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÇ°¤òÁ÷¤ê¡¢»à¤òµ½¤¤¤¿¡£");
7122 #else
7123                                         msg_print("You invoke wizard mode and cheat death.");
7124 #endif
7125                                         wipe_m_list();
7126
7127                                         msg_print(NULL);
7128
7129                                         /* Restore hit points */
7130                                         p_ptr->chp = p_ptr->mhp;
7131                                         p_ptr->chp_frac = 0;
7132
7133                                         if (p_ptr->pclass == CLASS_MAGIC_EATER)
7134                                         {
7135                                                 for (i = 0; i < EATER_EXT*2; i++)
7136                                                 {
7137                                                         p_ptr->magic_num1[i] = p_ptr->magic_num2[i]*EATER_CHARGE;
7138                                                 }
7139                                                 for (; i < EATER_EXT*3; i++)
7140                                                 {
7141                                                         p_ptr->magic_num1[i] = 0;
7142                                                 }
7143                                         }
7144                                         /* Restore spell points */
7145                                         p_ptr->csp = p_ptr->msp;
7146                                         p_ptr->csp_frac = 0;
7147
7148                                         /* Hack -- Healing */
7149                                         (void)set_blind(0);
7150                                         (void)set_confused(0);
7151                                         (void)set_poisoned(0);
7152                                         (void)set_afraid(0);
7153                                         (void)set_paralyzed(0);
7154                                         (void)set_image(0);
7155                                         (void)set_stun(0);
7156                                         (void)set_cut(0);
7157
7158                                         /* Hack -- Prevent starvation */
7159                                         (void)set_food(PY_FOOD_MAX - 1);
7160
7161                                         /* Hack -- cancel recall */
7162                                         if (p_ptr->word_recall)
7163                                         {
7164                                                 /* Message */
7165 #ifdef JP
7166 msg_print("Ä¥¤ê¤Ä¤á¤¿Â絤¤¬Î®¤ìµî¤Ã¤¿...");
7167 #else
7168                                                 msg_print("A tension leaves the air around you...");
7169 #endif
7170
7171                                                 msg_print(NULL);
7172
7173                                                 /* Hack -- Prevent recall */
7174                                                 p_ptr->word_recall = 0;
7175                                                 p_ptr->redraw |= (PR_STATUS);
7176                                         }
7177
7178                                         /* Hack -- cancel alter */
7179                                         if (p_ptr->alter_reality)
7180                                         {
7181                                                 /* Hack -- Prevent alter */
7182                                                 p_ptr->alter_reality = 0;
7183                                                 p_ptr->redraw |= (PR_STATUS);
7184                                         }
7185
7186                                         /* Note cause of death XXX XXX XXX */
7187 #ifdef JP
7188 (void)strcpy(p_ptr->died_from, "»à¤Îµ½¤­");
7189 #else
7190                                         (void)strcpy(p_ptr->died_from, "Cheating death");
7191 #endif
7192
7193
7194                                         /* Do not die */
7195                                         p_ptr->is_dead = FALSE;
7196
7197                                         dun_level = 0;
7198                                         p_ptr->inside_arena = FALSE;
7199                                         p_ptr->inside_battle = FALSE;
7200                                         leaving_quest = 0;
7201                                         p_ptr->inside_quest = 0;
7202                                         p_ptr->recall_dungeon = dungeon_type;
7203                                         dungeon_type = 0;
7204                                         if (lite_town || vanilla_town)
7205                                         {
7206                                                 p_ptr->wilderness_y = 1;
7207                                                 p_ptr->wilderness_x = 1;
7208                                                 if (vanilla_town)
7209                                                 {
7210                                                         p_ptr->oldpy = 10;
7211                                                         p_ptr->oldpx = 34;
7212                                                 }
7213                                                 else
7214                                                 {
7215                                                         p_ptr->oldpy = 33;
7216                                                         p_ptr->oldpx = 131;
7217                                                 }
7218                                         }
7219                                         else
7220                                         {
7221                                                 p_ptr->wilderness_y = 48;
7222                                                 p_ptr->wilderness_x = 5;
7223                                                 p_ptr->oldpy = 33;
7224                                                 p_ptr->oldpx = 131;
7225                                         }
7226
7227                                         /* Leaving */
7228                                         p_ptr->wild_mode = FALSE;
7229
7230                                         p_ptr->leaving = TRUE;
7231
7232 #ifdef JP
7233                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "                            ¤·¤«¤·¡¢À¸¤­Ê֤ä¿¡£");
7234 #else
7235                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "                            but revived.");
7236 #endif
7237                                 }
7238                         }
7239                 }
7240
7241                 /* Handle "death" */
7242                 if (p_ptr->is_dead) break;
7243
7244                 /* Make a new level */
7245                 change_floor();
7246         }
7247
7248         /* Close stuff */
7249         close_game();
7250
7251         /* Quit */
7252         quit(NULL);
7253 }
7254
7255 s32b turn_real(s32b hoge)
7256 {
7257         switch (p_ptr->start_race)
7258         {
7259         case RACE_VAMPIRE:
7260         case RACE_SKELETON:
7261         case RACE_ZOMBIE:
7262         case RACE_SPECTRE:
7263                 return hoge - (TURNS_PER_TICK * TOWN_DAWN * 3 / 4);
7264         default:
7265                 return hoge;
7266         }
7267 }