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