OSDN Git Service

MP操作が行われた後に再描画が必要な部分の修正.
[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                                 /* Redraw mana */
3686                                 p_ptr->redraw |= (PR_MANA);
3687                         }
3688                 }
3689                 if ((p_ptr->muta2 & MUT2_HP_TO_SP) && !p_ptr->anti_magic &&
3690                         one_in_(4000))
3691                 {
3692                         int wounds = p_ptr->msp - p_ptr->csp;
3693
3694                         if (wounds > 0)
3695                         {
3696                                 int healing = p_ptr->chp;
3697
3698                                 if (healing > wounds)
3699                                 {
3700                                         healing = wounds;
3701                                 }
3702
3703                                 p_ptr->csp += healing;
3704
3705                                 /* Redraw mana */
3706                                 p_ptr->redraw |= (PR_MANA);
3707 #ifdef JP
3708 take_hit(DAMAGE_LOSELIFE, healing, "Ƭ¤Ë¾º¤Ã¤¿·ì", -1);
3709 #else
3710                                 take_hit(DAMAGE_LOSELIFE, healing, "blood rushing to the head", -1);
3711 #endif
3712
3713                         }
3714                 }
3715                 if ((p_ptr->muta2 & MUT2_DISARM) && one_in_(10000))
3716                 {
3717                         object_type *o_ptr;
3718
3719                         disturb(0, 0);
3720 #ifdef JP
3721 msg_print("­¤¬¤â¤Ä¤ì¤Æž¤ó¤À¡ª");
3722 take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->wt / 6), "žÅÝ", -1);
3723 #else
3724                         msg_print("You trip over your own feet!");
3725                         take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->wt / 6), "tripping", -1);
3726 #endif
3727
3728
3729                         msg_print(NULL);
3730                         if (buki_motteruka(INVEN_RARM))
3731                         {
3732                                 int slot = INVEN_RARM;
3733                                 o_ptr = &inventory[INVEN_RARM];
3734                                 if (buki_motteruka(INVEN_LARM) && one_in_(2))
3735                                 {
3736                                         o_ptr = &inventory[INVEN_LARM];
3737                                         slot = INVEN_LARM;
3738                                 }
3739                                 if (!cursed_p(o_ptr))
3740                                 {
3741 #ifdef JP
3742 msg_print("Éð´ï¤òÍ¤Æ¤·¤Þ¤Ã¤¿¡ª");
3743 #else
3744                                         msg_print("You drop your weapon!");
3745 #endif
3746
3747                                         inven_drop(slot, 1);
3748                                 }
3749                         }
3750                 }
3751         }
3752
3753
3754         /*** Process Inventory ***/
3755
3756         if ((p_ptr->cursed & TRC_P_FLAG_MASK) && !p_ptr->inside_battle && !p_ptr->wild_mode)
3757         {
3758                 /*
3759                  * Hack: Uncursed teleporting items (e.g. Trump Weapons)
3760                  * can actually be useful!
3761                  */
3762                 if ((p_ptr->cursed & TRC_TELEPORT_SELF) && one_in_(200))
3763                 {
3764 #ifdef JP
3765 if (get_check_strict("¥Æ¥ì¥Ý¡¼¥È¤·¤Þ¤¹¤«¡©", CHECK_OKAY_CANCEL))
3766 #else
3767                         if (get_check_strict("Teleport? ", CHECK_OKAY_CANCEL))
3768 #endif
3769                         {
3770                                 disturb(0, 0);
3771                                 teleport_player(50);
3772                         }
3773                 }
3774                 /* Make a chainsword noise */
3775                 if ((p_ptr->cursed & TRC_CHAINSWORD) && one_in_(CHAINSWORD_NOISE))
3776                 {
3777                         char noise[1024];
3778 #ifdef JP
3779 if (!get_rnd_line("chainswd_j.txt", 0, noise))
3780 #else
3781                         if (!get_rnd_line("chainswd.txt", 0, noise))
3782 #endif
3783                                 msg_print(noise);
3784                         disturb(FALSE, FALSE);
3785                 }
3786                 /* TY Curse */
3787                 if ((p_ptr->cursed & TRC_TY_CURSE) && one_in_(TY_CURSE_CHANCE))
3788                 {
3789                         int count = 0;
3790                         (void)activate_ty_curse(FALSE, &count);
3791                 }
3792                 /* Handle experience draining */
3793                 if (p_ptr->prace != RACE_ANDROID && 
3794                         ((p_ptr->cursed & TRC_DRAIN_EXP) && one_in_(4)))
3795                 {
3796                         p_ptr->exp -= (p_ptr->lev+1)/2;
3797                         if (p_ptr->exp < 0) p_ptr->exp = 0;
3798                         p_ptr->max_exp -= (p_ptr->lev+1)/2;
3799                         if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
3800                         check_experience();
3801                 }
3802                 /* Add light curse (Later) */
3803                 if ((p_ptr->cursed & TRC_ADD_L_CURSE) && one_in_(2000))
3804                 {
3805                         u32b new_curse;
3806                         object_type *o_ptr;
3807
3808                         o_ptr = choose_cursed_obj_name(TRC_ADD_L_CURSE);
3809
3810                         new_curse = get_curse(0, o_ptr);
3811                         if (!(o_ptr->curse_flags & new_curse))
3812                         {
3813                                 char o_name[MAX_NLEN];
3814
3815                                 object_desc(o_name, o_ptr, FALSE, 0);
3816
3817                                 o_ptr->curse_flags |= new_curse;
3818 #ifdef JP
3819 msg_format("°­°Õ¤ËËþ¤Á¤¿¹õ¤¤¥ª¡¼¥é¤¬%s¤ò¤È¤ê¤Þ¤¤¤¿...", o_name);
3820 #else
3821                                 msg_format("There is a malignant black aura surrounding %s...", o_name);
3822 #endif
3823
3824                                 o_ptr->feeling = FEEL_NONE;
3825
3826                                 p_ptr->update |= (PU_BONUS);
3827                         }
3828                 }
3829                 /* Add heavy curse (Later) */
3830                 if ((p_ptr->cursed & TRC_ADD_H_CURSE) && one_in_(2000))
3831                 {
3832                         u32b new_curse;
3833                         object_type *o_ptr;
3834
3835                         o_ptr = choose_cursed_obj_name(TRC_ADD_H_CURSE);
3836
3837                         new_curse = get_curse(1, o_ptr);
3838                         if (!(o_ptr->curse_flags & new_curse))
3839                         {
3840                                 char o_name[MAX_NLEN];
3841
3842                                 object_desc(o_name, o_ptr, FALSE, 0);
3843
3844                                 o_ptr->curse_flags |= new_curse;
3845 #ifdef JP
3846 msg_format("°­°Õ¤ËËþ¤Á¤¿¹õ¤¤¥ª¡¼¥é¤¬%s¤ò¤È¤ê¤Þ¤¤¤¿...", o_name);
3847 #else
3848                                 msg_format("There is a malignant black aura surrounding %s...", o_name);
3849 #endif
3850
3851                                 o_ptr->feeling = FEEL_NONE;
3852
3853                                 p_ptr->update |= (PU_BONUS);
3854                         }
3855                 }
3856                 /* Call animal */
3857                 if ((p_ptr->cursed & TRC_CALL_ANIMAL) && one_in_(2500))
3858                 {
3859                         if (summon_specific(0, py, px, dun_level, SUMMON_ANIMAL,
3860                             (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
3861                         {
3862                                 char o_name[MAX_NLEN];
3863
3864                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_ANIMAL), FALSE, 0);
3865 #ifdef JP
3866 msg_format("%s¤¬Æ°Êª¤ò°ú¤­´ó¤»¤¿¡ª", o_name);
3867 #else
3868                                 msg_format("%s have attracted an animal!", o_name);
3869 #endif
3870
3871                                 disturb(0, 0);
3872                         }
3873                 }
3874                 /* Call demon */
3875                 if ((p_ptr->cursed & TRC_CALL_DEMON) && one_in_(1111))
3876                 {
3877                         if (summon_specific(0, py, px, dun_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
3878                         {
3879                                 char o_name[MAX_NLEN];
3880
3881                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_DEMON), FALSE, 0);
3882 #ifdef JP
3883 msg_format("%s¤¬°­Ëâ¤ò°ú¤­´ó¤»¤¿¡ª", o_name);
3884 #else
3885                                 msg_format("%s have attracted a demon!", o_name);
3886 #endif
3887
3888                                 disturb(0, 0);
3889                         }
3890                 }
3891                 /* Call dragon */
3892                 if ((p_ptr->cursed & TRC_CALL_DRAGON) && one_in_(800))
3893                 {
3894                         if (summon_specific(0, py, px, dun_level, SUMMON_DRAGON,
3895                             (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
3896                         {
3897                                 char o_name[MAX_NLEN];
3898
3899                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_DRAGON), FALSE, 0);
3900 #ifdef JP
3901 msg_format("%s¤¬¥É¥é¥´¥ó¤ò°ú¤­´ó¤»¤¿¡ª", o_name);
3902 #else
3903                                 msg_format("%s have attracted an animal!", o_name);
3904 #endif
3905
3906                                 disturb(0, 0);
3907                         }
3908                 }
3909                 if ((p_ptr->cursed & TRC_COWARDICE) && one_in_(1500))
3910                 {
3911                         if (!p_ptr->resist_fear)
3912                         {
3913                                 disturb(0, 0);
3914 #ifdef JP
3915 msg_print("¤È¤Æ¤â°Å¤¤... ¤È¤Æ¤â¶²¤¤¡ª");
3916 #else
3917                                 msg_print("It's so dark... so scary!");
3918 #endif
3919
3920                                 set_afraid(p_ptr->afraid + 13 + randint1(26));
3921                         }
3922                 }
3923                 /* Teleport player */
3924                 if ((p_ptr->cursed & TRC_TELEPORT) && one_in_(200) && !p_ptr->anti_tele)
3925                 {
3926                         disturb(0, 0);
3927
3928                         /* Teleport player */
3929                         teleport_player(40);
3930                 }
3931                 /* Handle HP draining */
3932                 if ((p_ptr->cursed & TRC_DRAIN_HP) && one_in_(666))
3933                 {
3934                         char o_name[MAX_NLEN];
3935
3936                         object_desc(o_name, choose_cursed_obj_name(TRC_DRAIN_HP), FALSE, 0);
3937 #ifdef JP
3938 msg_format("%s¤Ï¤¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª", o_name);
3939 #else
3940                         msg_format("%s drains HP from you!", o_name);
3941 #endif
3942                         take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev*2, 100), o_name, -1);
3943                 }
3944                 /* Handle mana draining */
3945                 if ((p_ptr->cursed & TRC_DRAIN_MANA) && one_in_(666))
3946                 {
3947                         char o_name[MAX_NLEN];
3948
3949                         object_desc(o_name, choose_cursed_obj_name(TRC_DRAIN_MANA), FALSE, 0);
3950 #ifdef JP
3951 msg_format("%s¤Ï¤¢¤Ê¤¿¤ÎËâÎϤòµÛ¼ý¤·¤¿¡ª", o_name);
3952 #else
3953                         msg_format("%s drains mana from you!", o_name);
3954 #endif
3955                         p_ptr->csp -= MIN(p_ptr->lev, 50);
3956                         if (p_ptr->csp < 0)
3957                         {
3958                                 p_ptr->csp = 0;
3959                                 p_ptr->csp_frac = 0;
3960                         }
3961                         p_ptr->redraw |= PR_MANA;
3962                 }
3963         }
3964
3965         /* Rarely, take damage from the Jewel of Judgement */
3966         if (one_in_(999) && !p_ptr->anti_magic)
3967         {
3968                 object_type *o_ptr = &inventory[INVEN_LITE];
3969
3970                 if (o_ptr->name1 == ART_JUDGE)
3971                 {
3972 #ifdef JP
3973                         if (object_known_p(o_ptr))
3974                                 msg_print("¡Ø¿³È½¤ÎÊõÀС٤Ϥ¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª");
3975                         else
3976                                 msg_print("¤Ê¤Ë¤«¤¬¤¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª");
3977                         take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "¿³È½¤ÎÊõÀÐ", -1);
3978 #else
3979                         if (object_known_p(o_ptr))
3980                                 msg_print("The Jewel of Judgement drains life from you!");
3981                         else
3982                                 msg_print("Something drains life from you!");
3983                         take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "the Jewel of Judgement", -1);
3984 #endif
3985                 }
3986         }
3987
3988
3989         /* Process equipment */
3990         for (j = 0, i = INVEN_RARM; i < INVEN_TOTAL; i++)
3991         {
3992                 /* Get the object */
3993                 o_ptr = &inventory[i];
3994
3995                 /* Skip non-objects */
3996                 if (!o_ptr->k_idx) continue;
3997
3998                 /* Recharge activatable objects */
3999                 if (o_ptr->timeout > 0)
4000                 {
4001                         /* Recharge */
4002                         o_ptr->timeout--;
4003
4004                         /* Notice changes */
4005                         if (!o_ptr->timeout)
4006                         {
4007                                 recharged_notice(o_ptr);
4008                                 j++;
4009                         }
4010                 }
4011         }
4012
4013         /* Notice changes */
4014         if (j)
4015         {
4016                 /* Window stuff */
4017                 p_ptr->window |= (PW_EQUIP);
4018                 wild_regen = 20;
4019         }
4020
4021         /*
4022          * Recharge rods.  Rods now use timeout to control charging status,
4023          * and each charging rod in a stack decreases the stack's timeout by
4024          * one per turn. -LM-
4025          */
4026         for (j = 0, i = 0; i < INVEN_PACK; i++)
4027         {
4028                 o_ptr = &inventory[i];
4029                 k_ptr = &k_info[o_ptr->k_idx];
4030
4031                 /* Skip non-objects */
4032                 if (!o_ptr->k_idx) continue;
4033
4034                 /* Examine all charging rods or stacks of charging rods. */
4035                 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
4036                 {
4037                         /* Determine how many rods are charging. */
4038                         temp = (o_ptr->timeout + (k_ptr->pval - 1)) / k_ptr->pval;
4039                         if (temp > o_ptr->number) temp = o_ptr->number;
4040
4041                         /* Decrease timeout by that number. */
4042                         o_ptr->timeout -= temp;
4043
4044                         /* Boundary control. */
4045                         if (o_ptr->timeout < 0) o_ptr->timeout = 0;
4046
4047                         /* Notice changes, provide message if object is inscribed. */
4048                         if (!(o_ptr->timeout))
4049                         {
4050                                 recharged_notice(o_ptr);
4051                                 j++;
4052                         }
4053                 }
4054         }
4055
4056         /* Notice changes */
4057         if (j)
4058         {
4059                 /* Combine pack */
4060                 p_ptr->notice |= (PN_COMBINE);
4061
4062                 /* Window stuff */
4063                 p_ptr->window |= (PW_INVEN);
4064                 wild_regen = 20;
4065         }
4066
4067         /* Feel the inventory */
4068         sense_inventory1();
4069         sense_inventory2();
4070
4071
4072         /*** Process Objects ***/
4073
4074         /* Process objects */
4075         for (i = 1; i < o_max; i++)
4076         {
4077                 /* Access object */
4078                 o_ptr = &o_list[i];
4079
4080                 /* Skip dead objects */
4081                 if (!o_ptr->k_idx) continue;
4082
4083                 /* Recharge rods on the ground.  No messages. */
4084                 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
4085                 {
4086                         /* Charge it */
4087                         o_ptr->timeout -= o_ptr->number;
4088
4089                         /* Boundary control. */
4090                         if (o_ptr->timeout < 0) o_ptr->timeout = 0;
4091                 }
4092         }
4093
4094
4095         /*** Involuntary Movement ***/
4096
4097         /* Delayed Word-of-Recall */
4098         if (p_ptr->word_recall)
4099         {
4100                 /*
4101                  * HACK: Autosave BEFORE resetting the recall counter (rr9)
4102                  * The player is yanked up/down as soon as
4103                  * he loads the autosaved game.
4104                  */
4105                 if (autosave_l && (p_ptr->word_recall == 1) && !p_ptr->inside_battle)
4106                         do_cmd_save_game(TRUE);
4107
4108                 /* Count down towards recall */
4109                 p_ptr->word_recall--;
4110
4111                 p_ptr->redraw |= (PR_STATUS);
4112
4113                 /* Activate the recall */
4114                 if (!p_ptr->word_recall)
4115                 {
4116                         /* Disturbing! */
4117                         disturb(0, 0);
4118
4119                         /* Determine the level */
4120                         if (dun_level || p_ptr->inside_quest)
4121                         {
4122 #ifdef JP
4123 msg_print("¾å¤Ë°ú¤ÃÄ¥¤ê¤¢¤²¤é¤ì¤ë´¶¤¸¤¬¤¹¤ë¡ª");
4124 #else
4125                                 msg_print("You feel yourself yanked upwards!");
4126 #endif
4127
4128                                 p_ptr->recall_dungeon = dungeon_type;
4129                                 if (record_stair)
4130                                         do_cmd_write_nikki(NIKKI_RECALL, dun_level, NULL);
4131
4132                                 dun_level = 0;
4133                                 dungeon_type = 0;
4134                                 prepare_change_floor_mode(CFM_CLEAR_ALL);
4135
4136                                 leave_quest_check();
4137
4138                                 p_ptr->inside_quest = 0;
4139                                 p_ptr->leaving = TRUE;
4140                         }
4141                         else
4142                         {
4143 #ifdef JP
4144 msg_print("²¼¤Ë°ú¤­¤º¤ê¹ß¤í¤µ¤ì¤ë´¶¤¸¤¬¤¹¤ë¡ª");
4145 #else
4146                                 msg_print("You feel yourself yanked downwards!");
4147 #endif
4148
4149                                 dungeon_type = p_ptr->recall_dungeon;
4150
4151                                 if (record_stair)
4152                                         do_cmd_write_nikki(NIKKI_RECALL, dun_level, NULL);
4153
4154                                 /* New depth */
4155                                 dun_level = max_dlv[dungeon_type];
4156                                 if (dun_level < 1) dun_level = 1;
4157
4158                                 /* Nightmare mode makes recall more dangerous */
4159                                 if (ironman_nightmare && !randint0(666) && (dungeon_type == DUNGEON_ANGBAND))
4160                                 {
4161                                         if (dun_level < 50)
4162                                         {
4163                                                 dun_level *= 2;
4164                                         }
4165                                         else if (dun_level < 99)
4166                                         {
4167                                                 dun_level = (dun_level + 99) / 2;
4168                                         }
4169                                         else if (dun_level > 100)
4170                                         {
4171                                                 dun_level = d_info[dungeon_type].maxdepth - 1;
4172                                         }
4173                                 }
4174
4175                                 if (p_ptr->wild_mode)
4176                                 {
4177                                         p_ptr->wilderness_y = py;
4178                                         p_ptr->wilderness_x = px;
4179                                 }
4180                                 else
4181                                 {
4182                                         /* Save player position */
4183                                         p_ptr->oldpx = px;
4184                                         p_ptr->oldpy = py;
4185                                 }
4186                                 p_ptr->wild_mode = FALSE;
4187
4188                                 prepare_change_floor_mode(CFM_CLEAR_ALL);
4189
4190                                 /* Leaving */
4191                                 p_ptr->leaving = TRUE;
4192
4193                                 if (dungeon_type == DUNGEON_ANGBAND)
4194                                 {
4195                                         for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
4196                                         {
4197                                                 if ((quest[i].type == QUEST_TYPE_RANDOM) &&
4198                                                     (quest[i].status == QUEST_STATUS_TAKEN) &&
4199                                                     (quest[i].level < dun_level))
4200                                                 {
4201                                                         quest[i].status = QUEST_STATUS_FAILED;
4202                                                         quest[i].complev = (byte)p_ptr->lev;
4203                                                         r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
4204                                                 }
4205                                         }
4206                                 }
4207                         }
4208
4209                         /* Sound */
4210                         sound(SOUND_TPLEVEL);
4211                 }
4212         }
4213
4214
4215         /* Delayed Alter reality */
4216         if (p_ptr->alter_reality)
4217         {
4218                 if (autosave_l && (p_ptr->alter_reality == 1) && !p_ptr->inside_battle)
4219                         do_cmd_save_game(TRUE);
4220
4221                 /* Count down towards alter */
4222                 p_ptr->alter_reality--;
4223
4224                 p_ptr->redraw |= (PR_STATUS);
4225
4226                 /* Activate the alter reality */
4227                 if (!p_ptr->alter_reality)
4228                 {
4229                         /* Disturbing! */
4230                         disturb(0, 0);
4231
4232                         /* Determine the level */
4233                         if (!quest_number(dun_level) && dun_level)
4234                         {
4235 #ifdef JP
4236                                 msg_print("À¤³¦¤¬ÊѤï¤Ã¤¿¡ª");
4237 #else
4238                                 msg_print("The world changes!");
4239 #endif
4240
4241                                 prepare_change_floor_mode(CFM_CLEAR_ALL);
4242
4243                                 /* Leaving */
4244                                 p_ptr->leaving = TRUE;
4245                         }
4246                         else
4247                         {
4248 #ifdef JP
4249                                 msg_print("À¤³¦¤¬¾¯¤·¤Î´ÖÊѲ½¤·¤¿¤è¤¦¤À¡£");
4250 #else
4251                                 msg_print("The world seems to change for a moment!");
4252 #endif
4253                         }
4254
4255                         /* Sound */
4256                         sound(SOUND_TPLEVEL);
4257                 }
4258         }
4259 }
4260
4261
4262
4263 /*
4264  * Verify use of "wizard" mode
4265  */
4266 static bool enter_wizard_mode(void)
4267 {
4268         /* Ask first time */
4269         if (!p_ptr->noscore)
4270         {
4271                 /* Wizard mode is not permitted */
4272                 if (!allow_debug_opts)
4273                 {
4274 #ifdef JP
4275                         msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£ ");
4276 #else
4277                         msg_print("Wizard mode is not permitted.");
4278 #endif
4279                         return FALSE;
4280                 }
4281
4282                 /* Mention effects */
4283 #ifdef JP
4284                 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤Ï¥Ç¥Ð¥Ã¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥â¡¼¥É¤Ç¤¹¡£ ");
4285                 msg_print("°ìÅÙ¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆþ¤ë¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
4286 #else
4287                 msg_print("Wizard mode is for debugging and experimenting.");
4288                 msg_print("The game will not be scored if you enter wizard mode.");
4289 #endif
4290
4291                 msg_print(NULL);
4292
4293                 /* Verify request */
4294 #ifdef JP
4295                 if (!get_check("ËÜÅö¤Ë¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆþ¤ê¤¿¤¤¤Î¤Ç¤¹¤«? "))
4296 #else
4297                 if (!get_check("Are you sure you want to enter wizard mode? "))
4298 #endif
4299                 {
4300                         return (FALSE);
4301                 }
4302
4303 #ifdef JP
4304                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆÍÆþ¤·¤Æ¥¹¥³¥¢¤ò»Ä¤»¤Ê¤¯¤Ê¤Ã¤¿¡£");
4305 #else
4306                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up recording score to enter wizard mode.");
4307 #endif
4308                 /* Mark savefile */
4309                 p_ptr->noscore |= 0x0002;
4310         }
4311
4312         /* Success */
4313         return (TRUE);
4314 }
4315
4316
4317 #ifdef ALLOW_WIZARD
4318
4319 /*
4320  * Verify use of "debug" commands
4321  */
4322 static bool enter_debug_mode(void)
4323 {
4324         /* Ask first time */
4325         if (!p_ptr->noscore)
4326         {
4327                 /* Debug mode is not permitted */
4328                 if (!allow_debug_opts)
4329                 {
4330 #ifdef JP
4331                         msg_print("¥Ç¥Ð¥Ã¥°¥³¥Þ¥ó¥É¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£ ");
4332 #else
4333                         msg_print("Use of debug command is not permitted.");
4334 #endif
4335                         return FALSE;
4336                 }
4337
4338                 /* Mention effects */
4339 #ifdef JP
4340                 msg_print("¥Ç¥Ð¥Ã¥°¡¦¥³¥Þ¥ó¥É¤Ï¥Ç¥Ð¥Ã¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥³¥Þ¥ó¥É¤Ç¤¹¡£ ");
4341                 msg_print("¥Ç¥Ð¥Ã¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¦¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
4342 #else
4343                 msg_print("The debug commands are for debugging and experimenting.");
4344                 msg_print("The game will not be scored if you use debug commands.");
4345 #endif
4346
4347                 msg_print(NULL);
4348
4349                 /* Verify request */
4350 #ifdef JP
4351                 if (!get_check("ËÜÅö¤Ë¥Ç¥Ð¥Ã¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¤¤Þ¤¹¤«? "))
4352 #else
4353                 if (!get_check("Are you sure you want to use debug commands? "))
4354 #endif
4355                 {
4356                         return (FALSE);
4357                 }
4358
4359 #ifdef JP
4360                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥Ç¥Ð¥Ã¥°¥â¡¼¥É¤ËÆÍÆþ¤·¤Æ¥¹¥³¥¢¤ò»Ä¤»¤Ê¤¯¤Ê¤Ã¤¿¡£");
4361 #else
4362                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up sending score to use debug commands.");
4363 #endif
4364                 /* Mark savefile */
4365                 p_ptr->noscore |= 0x0008;
4366         }
4367
4368         /* Success */
4369         return (TRUE);
4370 }
4371
4372 /*
4373  * Hack -- Declare the Debug Routines
4374  */
4375 extern void do_cmd_debug(void);
4376
4377 #endif /* ALLOW_WIZARD */
4378
4379
4380 #ifdef ALLOW_BORG
4381
4382 /*
4383  * Verify use of "borg" commands
4384  */
4385 static bool enter_borg_mode(void)
4386 {
4387         /* Ask first time */
4388         if (!(p_ptr->noscore & 0x0010))
4389         {
4390                 /* Mention effects */
4391 #ifdef JP
4392                 msg_print("¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤Ï¥Ç¥Ð¥Ã¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥³¥Þ¥ó¥É¤Ç¤¹¡£ ");
4393                 msg_print("¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¦¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
4394 #else
4395                 msg_print("The borg commands are for debugging and experimenting.");
4396                 msg_print("The game will not be scored if you use borg commands.");
4397 #endif
4398
4399                 msg_print(NULL);
4400
4401                 /* Verify request */
4402 #ifdef JP
4403                 if (!get_check("ËÜÅö¤Ë¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¤¤Þ¤¹¤«? "))
4404 #else
4405                 if (!get_check("Are you sure you want to use borg commands? "))
4406 #endif
4407                 {
4408                         return (FALSE);
4409                 }
4410
4411 #ifdef JP
4412                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»ÈÍѤ·¤Æ¥¹¥³¥¢¤ò»Ä¤»¤Ê¤¯¤Ê¤Ã¤¿¡£");
4413 #else
4414                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up recording score to use borg commands.");
4415 #endif
4416                 /* Mark savefile */
4417                 p_ptr->noscore |= 0x0010;
4418         }
4419
4420         /* Success */
4421         return (TRUE);
4422 }
4423
4424 /*
4425  * Hack -- Declare the Ben Borg
4426  */
4427 extern void do_cmd_borg(void);
4428
4429 #endif /* ALLOW_BORG */
4430
4431
4432
4433 /*
4434  * Parse and execute the current command
4435  * Give "Warning" on illegal commands.
4436  *
4437  * XXX XXX XXX Make some "blocks"
4438  */
4439 static void process_command(void)
4440 {
4441         int old_now_message = now_message;
4442
4443 #ifdef ALLOW_REPEAT /* TNB */
4444
4445         /* Handle repeating the last command */
4446         repeat_check();
4447
4448 #endif /* ALLOW_REPEAT -- TNB */
4449
4450         now_message = 0;
4451
4452         /* Parse the command */
4453         switch (command_cmd)
4454         {
4455                 /* Ignore */
4456                 case ESCAPE:
4457                 case ' ':
4458                 {
4459                         break;
4460                 }
4461
4462                 /* Ignore return */
4463                 case '\r':
4464                 case '\n':
4465                 {
4466                         break;
4467                 }
4468
4469                 /*** Wizard Commands ***/
4470
4471                 /* Toggle Wizard Mode */
4472                 case KTRL('W'):
4473                 {
4474                         if (p_ptr->wizard)
4475                         {
4476                                 p_ptr->wizard = FALSE;
4477 #ifdef JP
4478 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É²ò½ü¡£");
4479 #else
4480                                 msg_print("Wizard mode off.");
4481 #endif
4482
4483                         }
4484                         else if (enter_wizard_mode())
4485                         {
4486                                 p_ptr->wizard = TRUE;
4487 #ifdef JP
4488 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥ÉÆÍÆþ¡£");
4489 #else
4490                                 msg_print("Wizard mode on.");
4491 #endif
4492
4493                         }
4494
4495                         /* Update monsters */
4496                         p_ptr->update |= (PU_MONSTERS);
4497
4498                         /* Redraw "title" */
4499                         p_ptr->redraw |= (PR_TITLE);
4500
4501                         break;
4502                 }
4503
4504
4505 #ifdef ALLOW_WIZARD
4506
4507                 /* Special "debug" commands */
4508                 case KTRL('A'):
4509                 {
4510                         /* Enter debug mode */
4511                         if (enter_debug_mode())
4512                         {
4513                                 do_cmd_debug();
4514                         }
4515                         break;
4516                 }
4517
4518 #endif /* ALLOW_WIZARD */
4519
4520
4521 #ifdef ALLOW_BORG
4522
4523                 /* Special "borg" commands */
4524                 case KTRL('Z'):
4525                 {
4526                         /* Enter borg mode */
4527                         if (enter_borg_mode())
4528                         {
4529                                 if (!p_ptr->wild_mode) do_cmd_borg();
4530                         }
4531
4532                         break;
4533                 }
4534
4535 #endif /* ALLOW_BORG */
4536
4537
4538
4539                 /*** Inventory Commands ***/
4540
4541                 /* Wear/wield equipment */
4542                 case 'w':
4543                 {
4544                         if (!p_ptr->wild_mode) do_cmd_wield();
4545                         break;
4546                 }
4547
4548                 /* Take off equipment */
4549                 case 't':
4550                 {
4551                         if (!p_ptr->wild_mode) do_cmd_takeoff();
4552                         break;
4553                 }
4554
4555                 /* Drop an item */
4556                 case 'd':
4557                 {
4558                         if (!p_ptr->wild_mode) do_cmd_drop();
4559                         break;
4560                 }
4561
4562                 /* Destroy an item */
4563                 case 'k':
4564                 {
4565                         do_cmd_destroy();
4566                         break;
4567                 }
4568
4569                 /* Equipment list */
4570                 case 'e':
4571                 {
4572                         do_cmd_equip();
4573                         break;
4574                 }
4575
4576                 /* Inventory list */
4577                 case 'i':
4578                 {
4579                         do_cmd_inven();
4580                         break;
4581                 }
4582
4583
4584                 /*** Various commands ***/
4585
4586                 /* Identify an object */
4587                 case 'I':
4588                 {
4589                         do_cmd_observe();
4590                         break;
4591                 }
4592
4593                 /* Hack -- toggle windows */
4594                 case KTRL('I'):
4595                 {
4596                         toggle_inven_equip();
4597                         break;
4598                 }
4599
4600
4601                 /*** Standard "Movement" Commands ***/
4602
4603                 /* Alter a grid */
4604                 case '+':
4605                 {
4606                         if (!p_ptr->wild_mode) do_cmd_alter();
4607                         break;
4608                 }
4609
4610                 /* Dig a tunnel */
4611                 case 'T':
4612                 {
4613                         if (!p_ptr->wild_mode) do_cmd_tunnel();
4614                         break;
4615                 }
4616
4617                 /* Move (usually pick up things) */
4618                 case ';':
4619                 {
4620 #ifdef ALLOW_EASY_DISARM /* TNB */
4621
4622                         do_cmd_walk(FALSE);
4623
4624 #else /* ALLOW_EASY_DISARM -- TNB */
4625
4626                         do_cmd_walk(always_pickup);
4627
4628 #endif /* ALLOW_EASY_DISARM -- TNB */
4629
4630                         break;
4631                 }
4632
4633                 /* Move (usually do not pick up) */
4634                 case '-':
4635                 {
4636 #ifdef ALLOW_EASY_DISARM /* TNB */
4637
4638                         do_cmd_walk(TRUE);
4639
4640 #else /* ALLOW_EASY_DISARM -- TNB */
4641
4642                         do_cmd_walk(!always_pickup);
4643
4644 #endif /* ALLOW_EASY_DISARM -- TNB */
4645
4646                         break;
4647                 }
4648
4649
4650                 /*** Running, Resting, Searching, Staying */
4651
4652                 /* Begin Running -- Arg is Max Distance */
4653                 case '.':
4654                 {
4655                         if (!p_ptr->wild_mode) do_cmd_run();
4656                         break;
4657                 }
4658
4659                 /* Stay still (usually pick things up) */
4660                 case ',':
4661                 {
4662                         do_cmd_stay(always_pickup);
4663                         break;
4664                 }
4665
4666                 /* Stay still (usually do not pick up) */
4667                 case 'g':
4668                 {
4669                         do_cmd_stay(!always_pickup);
4670                         break;
4671                 }
4672
4673                 /* Rest -- Arg is time */
4674                 case 'R':
4675                 {
4676                         do_cmd_rest();
4677                         break;
4678                 }
4679
4680                 /* Search for traps/doors */
4681                 case 's':
4682                 {
4683                         do_cmd_search();
4684                         break;
4685                 }
4686
4687                 /* Toggle search mode */
4688                 case 'S':
4689                 {
4690                         if (p_ptr->action == ACTION_SEARCH) set_action(ACTION_NONE);
4691                         else set_action(ACTION_SEARCH);
4692                         break;
4693                 }
4694
4695
4696                 /*** Stairs and Doors and Chests and Traps ***/
4697
4698                 /* Enter store */
4699                 case SPECIAL_KEY_STORE:
4700                 {
4701                         if (!p_ptr->wild_mode) do_cmd_store();
4702                         break;
4703                 }
4704
4705                 /* Enter building -KMW- */
4706                 case SPECIAL_KEY_BUILDING:
4707                 {
4708                         if (!p_ptr->wild_mode) do_cmd_bldg();
4709                         break;
4710                 }
4711
4712                 /* Enter quest level -KMW- */
4713                 case SPECIAL_KEY_QUEST:
4714                 {
4715                         if (!p_ptr->wild_mode) do_cmd_quest();
4716                         break;
4717                 }
4718
4719                 /* Go up staircase */
4720                 case '<':
4721                 {
4722                         if(!p_ptr->wild_mode && !dun_level && !p_ptr->inside_arena && !p_ptr->inside_quest)
4723                         {
4724                                 if (!vanilla_town)
4725                                 {
4726                                         if(ambush_flag)
4727                                         {
4728 #ifdef JP
4729                                                 msg_print("½±·â¤«¤éƨ¤²¤ë¤Ë¤Ï¥Þ¥Ã¥×¤Îü¤Þ¤Ç°ÜÆ°¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£");
4730 #else
4731                                                 msg_print("To flee the ambush you have to reach the edge of the map.");
4732 #endif
4733                                         }
4734                                         else if (p_ptr->food < PY_FOOD_WEAK)
4735                                         {
4736 #ifdef JP
4737                                                 msg_print("¤½¤ÎÁ°¤Ë¿©»ö¤ò¤È¤é¤Ê¤¤¤È¡£");
4738 #else
4739                                                 msg_print("You must eat something here.");
4740 #endif
4741                                         }
4742                                         else
4743                                         {
4744                                                 if (change_wild_mode())
4745                                                 {
4746                                                         p_ptr->oldpx = px;
4747                                                         p_ptr->oldpy = py;
4748                                                 }
4749                                         }
4750                                 }
4751                         }
4752                         else
4753                                 do_cmd_go_up();
4754                         break;
4755                 }
4756
4757                 /* Go down staircase */
4758                 case '>':
4759                 {
4760                         if(!p_ptr->wild_mode) do_cmd_go_down();
4761                         else
4762                         {
4763                                 p_ptr->wilderness_x = px;
4764                                 p_ptr->wilderness_y = py;
4765                                 change_wild_mode();
4766                         }
4767                         break;
4768                 }
4769
4770                 /* Open a door or chest */
4771                 case 'o':
4772                 {
4773                         if (!p_ptr->wild_mode) do_cmd_open();
4774                         break;
4775                 }
4776
4777                 /* Close a door */
4778                 case 'c':
4779                 {
4780                         if (!p_ptr->wild_mode) do_cmd_close();
4781                         break;
4782                 }
4783
4784                 /* Jam a door with spikes */
4785                 case 'j':
4786                 {
4787                         if (!p_ptr->wild_mode) do_cmd_spike();
4788                         break;
4789                 }
4790
4791                 /* Bash a door */
4792                 case 'B':
4793                 {
4794                         if (!p_ptr->wild_mode) do_cmd_bash();
4795                         break;
4796                 }
4797
4798                 /* Disarm a trap or chest */
4799                 case 'D':
4800                 {
4801                         if (!p_ptr->wild_mode) do_cmd_disarm();
4802                         break;
4803                 }
4804
4805
4806                 /*** Magic and Prayers ***/
4807
4808                 /* Gain new spells/prayers */
4809                 case 'G':
4810                 {
4811                         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
4812 #ifdef JP
4813                                 msg_print("¼öʸ¤ò³Ø½¬¤¹¤ëɬÍפϤʤ¤¡ª");
4814 #else
4815                                 msg_print("You don't have to learn spells!");
4816 #endif
4817                         else if (p_ptr->pclass == CLASS_SAMURAI)
4818                                 do_cmd_gain_hissatsu();
4819                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4820                                 gain_magic();
4821                         else
4822                                 do_cmd_study();
4823                         break;
4824                 }
4825
4826                 /* Browse a book */
4827                 case 'b':
4828                 {
4829                         if ( (p_ptr->pclass == CLASS_MINDCRAFTER) ||
4830                              (p_ptr->pclass == CLASS_BERSERKER) ||
4831                              (p_ptr->pclass == CLASS_NINJA) ||
4832                              (p_ptr->pclass == CLASS_MIRROR_MASTER) 
4833                              ) do_cmd_mind_browse();
4834                         else if (p_ptr->pclass == CLASS_SMITH)
4835                                 do_cmd_kaji(TRUE);
4836                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4837                                 do_cmd_magic_eater(TRUE);
4838                         else do_cmd_browse();
4839                         break;
4840                 }
4841
4842                 /* Cast a spell */
4843                 case 'm':
4844                 {
4845                         /* -KMW- */
4846                         if (!p_ptr->wild_mode)
4847                         {
4848                                 if ((p_ptr->pclass == CLASS_WARRIOR) || (p_ptr->pclass == CLASS_ARCHER) || (p_ptr->pclass == CLASS_CAVALRY))
4849                                 {
4850 #ifdef JP
4851                                         msg_print("¼öʸ¤ò¾§¤¨¤é¤ì¤Ê¤¤¡ª");
4852 #else
4853                                         msg_print("You cannot cast spells!");
4854 #endif
4855                                 }
4856                                 else if (dun_level && (d_info[dungeon_type].flags1 & DF1_NO_MAGIC) && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
4857                                 {
4858 #ifdef JP
4859                                         msg_print("¥À¥ó¥¸¥ç¥ó¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
4860 #else
4861                                         msg_print("The dungeon absorbs all attempted magic!");
4862 #endif
4863                                         msg_print(NULL);
4864                                 }
4865                                 else if (p_ptr->anti_magic && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
4866                                 {
4867 #ifdef JP
4868
4869                                         cptr which_power = "ËâË¡";
4870 #else
4871                                         cptr which_power = "magic";
4872 #endif
4873                                         if (p_ptr->pclass == CLASS_MINDCRAFTER)
4874 #ifdef JP
4875                                                 which_power = "ĶǽÎÏ";
4876 #else
4877                                                 which_power = "psionic powers";
4878 #endif
4879                                         else if (p_ptr->pclass == CLASS_IMITATOR)
4880 #ifdef JP
4881                                                 which_power = "¤â¤Î¤Þ¤Í";
4882 #else
4883                                                 which_power = "imitation";
4884 #endif
4885                                         else if (p_ptr->pclass == CLASS_SAMURAI)
4886 #ifdef JP
4887                                                 which_power = "ɬ»¦·õ";
4888 #else
4889                                                 which_power = "hissatsu";
4890 #endif
4891                                         else if (p_ptr->pclass == CLASS_MIRROR_MASTER)
4892 #ifdef JP
4893                                                 which_power = "¶ÀËâË¡";
4894 #else
4895                                                 which_power = "mirror magic";
4896 #endif
4897                                         else if (p_ptr->pclass == CLASS_NINJA)
4898 #ifdef JP
4899                                                 which_power = "Ǧ½Ñ";
4900 #else
4901                                                 which_power = "ninjutsu";
4902 #endif
4903                                         else if (mp_ptr->spell_book == TV_LIFE_BOOK)
4904 #ifdef JP
4905                                                 which_power = "µ§¤ê";
4906 #else
4907                                                 which_power = "prayer";
4908 #endif
4909
4910 #ifdef JP
4911                                         msg_format("È¿ËâË¡¥Ð¥ê¥¢¤¬%s¤ò¼ÙË⤷¤¿¡ª", which_power);
4912 #else
4913                                         msg_format("An anti-magic shell disrupts your %s!", which_power);
4914 #endif
4915                                         energy_use = 0;
4916                                 }
4917                                 else if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER))
4918                                 {
4919 #ifdef JP
4920                                         msg_format("¶¸Àï»Î²½¤·¤Æ¤¤¤ÆƬ¤¬²ó¤é¤Ê¤¤¡ª");
4921 #else
4922                                         msg_format("You cannot think directly!");
4923 #endif
4924                                         energy_use = 0;
4925                                 }
4926                                 else
4927                                 {
4928                                         if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
4929                                             (p_ptr->pclass == CLASS_BERSERKER) ||
4930                                             (p_ptr->pclass == CLASS_NINJA) ||
4931                                             (p_ptr->pclass == CLASS_MIRROR_MASTER)
4932                                             )
4933                                                 do_cmd_mind();
4934                                         else if (p_ptr->pclass == CLASS_IMITATOR)
4935                                                 do_cmd_mane(FALSE);
4936                                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4937                                                 do_cmd_magic_eater(FALSE);
4938                                         else if (p_ptr->pclass == CLASS_SAMURAI)
4939                                                 do_cmd_hissatsu();
4940                                         else if (p_ptr->pclass == CLASS_BLUE_MAGE)
4941                                                 do_cmd_cast_learned();
4942                                         else if (p_ptr->pclass == CLASS_SMITH)
4943                                                 do_cmd_kaji(FALSE);
4944                                         else
4945                                                 do_cmd_cast();
4946                                 }
4947                         }
4948                         break;
4949                 }
4950
4951                 /* Issue a pet command */
4952                 case 'p':
4953                 {
4954                         if (!p_ptr->wild_mode) do_cmd_pet();
4955                         break;
4956                 }
4957
4958                 /*** Use various objects ***/
4959
4960                 /* Inscribe an object */
4961                 case '{':
4962                 {
4963                         do_cmd_inscribe();
4964                         break;
4965                 }
4966
4967                 /* Uninscribe an object */
4968                 case '}':
4969                 {
4970                         do_cmd_uninscribe();
4971                         break;
4972                 }
4973
4974                 /* Activate an artifact */
4975                 case 'A':
4976                 {
4977                         if (!p_ptr->wild_mode)
4978                         {
4979                         if (!p_ptr->inside_arena)
4980                                 do_cmd_activate();
4981                         else
4982                         {
4983 #ifdef JP
4984 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
4985 #else
4986                                 msg_print("The arena absorbs all attempted magic!");
4987 #endif
4988
4989                                 msg_print(NULL);
4990                         }
4991                         }
4992                         break;
4993                 }
4994
4995                 /* Eat some food */
4996                 case 'E':
4997                 {
4998                         do_cmd_eat_food();
4999                         break;
5000                 }
5001
5002                 /* Fuel your lantern/torch */
5003                 case 'F':
5004                 {
5005                         do_cmd_refill();
5006                         break;
5007                 }
5008
5009                 /* Fire an item */
5010                 case 'f':
5011                 {
5012                         if (!p_ptr->wild_mode) do_cmd_fire();
5013                         break;
5014                 }
5015
5016                 /* Throw an item */
5017                 case 'v':
5018                 {
5019                         if (!p_ptr->wild_mode)
5020                         {
5021                                 do_cmd_throw();
5022                         }
5023                         break;
5024                 }
5025
5026                 /* Aim a wand */
5027                 case 'a':
5028                 {
5029                         if (!p_ptr->wild_mode)
5030                         {
5031                         if (!p_ptr->inside_arena)
5032                                 do_cmd_aim_wand();
5033                         else
5034                         {
5035 #ifdef JP
5036 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
5037 #else
5038                                 msg_print("The arena absorbs all attempted magic!");
5039 #endif
5040
5041                                 msg_print(NULL);
5042                         }
5043                         }
5044                         break;
5045                 }
5046
5047                 /* Zap a rod */
5048                 case 'z':
5049                 {
5050                         if (!p_ptr->wild_mode)
5051                         {
5052                         if (p_ptr->inside_arena)
5053                         {
5054 #ifdef JP
5055 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
5056 #else
5057                                 msg_print("The arena absorbs all attempted magic!");
5058 #endif
5059
5060                                 msg_print(NULL);
5061                         }
5062                         else if (use_command && rogue_like_commands)
5063                         {
5064                                 do_cmd_use();
5065                         }
5066                         else
5067                         {
5068                                 do_cmd_zap_rod();
5069                         }
5070                         }
5071                         break;
5072                 }
5073
5074                 /* Quaff a potion */
5075                 case 'q':
5076                 {
5077                         if (!p_ptr->wild_mode)
5078                         {
5079                         if (!p_ptr->inside_arena)
5080                                 do_cmd_quaff_potion();
5081                         else
5082                         {
5083 #ifdef JP
5084 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
5085 #else
5086                                 msg_print("The arena absorbs all attempted magic!");
5087 #endif
5088
5089                                 msg_print(NULL);
5090                         }
5091                         }
5092                         break;
5093                 }
5094
5095                 /* Read a scroll */
5096                 case 'r':
5097                 {
5098                         if (!p_ptr->wild_mode)
5099                         {
5100                         if (!p_ptr->inside_arena)
5101                                 do_cmd_read_scroll();
5102                         else
5103                         {
5104 #ifdef JP
5105 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
5106 #else
5107                                 msg_print("The arena absorbs all attempted magic!");
5108 #endif
5109
5110                                 msg_print(NULL);
5111                         }
5112                         }
5113                         break;
5114                 }
5115
5116                 /* Use a staff */
5117                 case 'u':
5118                 {
5119                         if (!p_ptr->wild_mode)
5120                         {
5121                         if (p_ptr->inside_arena)
5122                         {
5123 #ifdef JP
5124 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
5125 #else
5126                                 msg_print("The arena absorbs all attempted magic!");
5127 #endif
5128
5129                                 msg_print(NULL);
5130                         }
5131                         else if (use_command && !rogue_like_commands)
5132                         {
5133                                 do_cmd_use();
5134                         }
5135                         else
5136                                 do_cmd_use_staff();
5137                         }
5138                         break;
5139                 }
5140
5141                 /* Use racial power */
5142                 case 'U':
5143                 {
5144                         if (!p_ptr->wild_mode) do_cmd_racial_power();
5145                         break;
5146                 }
5147
5148
5149                 /*** Looking at Things (nearby or on map) ***/
5150
5151                 /* Full dungeon map */
5152                 case 'M':
5153                 {
5154                         do_cmd_view_map();
5155                         break;
5156                 }
5157
5158                 /* Locate player on map */
5159                 case 'L':
5160                 {
5161                         do_cmd_locate();
5162                         break;
5163                 }
5164
5165                 /* Look around */
5166                 case 'l':
5167                 {
5168                         do_cmd_look();
5169                         break;
5170                 }
5171
5172                 /* Target monster or location */
5173                 case '*':
5174                 {
5175                         if (!p_ptr->wild_mode) do_cmd_target();
5176                         break;
5177                 }
5178
5179
5180
5181                 /*** Help and Such ***/
5182
5183                 /* Help */
5184                 case '?':
5185                 {
5186                         do_cmd_help();
5187                         break;
5188                 }
5189
5190                 /* Identify symbol */
5191                 case '/':
5192                 {
5193                         do_cmd_query_symbol();
5194                         break;
5195                 }
5196
5197                 /* Character description */
5198                 case 'C':
5199                 {
5200                         do_cmd_change_name();
5201                         break;
5202                 }
5203
5204
5205                 /*** System Commands ***/
5206
5207                 /* Hack -- User interface */
5208                 case '!':
5209                 {
5210                         (void)Term_user(0);
5211                         break;
5212                 }
5213
5214                 /* Single line from a pref file */
5215                 case '"':
5216                 {
5217                         do_cmd_pref();
5218                         break;
5219                 }
5220
5221                 case '$':
5222                 {
5223                         do_cmd_pickpref();
5224                         break;
5225                 }
5226
5227                 case '_':
5228                 {
5229                         do_cmd_edit_autopick();
5230                         break;
5231                 }
5232
5233                 /* Interact with macros */
5234                 case '@':
5235                 {
5236                         do_cmd_macros();
5237                         break;
5238                 }
5239
5240                 /* Interact with visuals */
5241                 case '%':
5242                 {
5243                         do_cmd_visuals();
5244                         do_cmd_redraw();
5245                         break;
5246                 }
5247
5248                 /* Interact with colors */
5249                 case '&':
5250                 {
5251                         do_cmd_colors();
5252                         do_cmd_redraw();
5253                         break;
5254                 }
5255
5256                 /* Interact with options */
5257                 case '=':
5258                 {
5259                         do_cmd_options();
5260                         do_cmd_redraw();
5261                         break;
5262                 }
5263
5264                 /*** Misc Commands ***/
5265
5266                 /* Take notes */
5267                 case ':':
5268                 {
5269                         do_cmd_note();
5270                         break;
5271                 }
5272
5273                 /* Version info */
5274                 case 'V':
5275                 {
5276                         do_cmd_version();
5277                         break;
5278                 }
5279
5280                 /* Repeat level feeling */
5281                 case KTRL('F'):
5282                 {
5283                         if (!p_ptr->wild_mode) do_cmd_feeling();
5284                         break;
5285                 }
5286
5287                 /* Show previous message */
5288                 case KTRL('O'):
5289                 {
5290                         do_cmd_message_one();
5291                         break;
5292                 }
5293
5294                 /* Show previous messages */
5295                 case KTRL('P'):
5296                 {
5297                         do_cmd_messages(old_now_message);
5298                         break;
5299                 }
5300
5301                 /* Show quest status -KMW- */
5302                 case KTRL('Q'):
5303                 {
5304                         do_cmd_checkquest();
5305                         break;
5306                 }
5307
5308                 /* Redraw the screen */
5309                 case KTRL('R'):
5310                 {
5311                         now_message = old_now_message;
5312                         do_cmd_redraw();
5313                         break;
5314                 }
5315
5316 #ifndef VERIFY_SAVEFILE
5317
5318                 /* Hack -- Save and don't quit */
5319                 case KTRL('S'):
5320                 {
5321                         do_cmd_save_game(FALSE);
5322                         break;
5323                 }
5324
5325 #endif /* VERIFY_SAVEFILE */
5326
5327                 case KTRL('T'):
5328                 {
5329                         do_cmd_time();
5330                         break;
5331                 }
5332
5333                 /* Save and quit */
5334                 case KTRL('X'):
5335                 case SPECIAL_KEY_QUIT:
5336                 {
5337                         do_cmd_save_and_exit();
5338                         break;
5339                 }
5340
5341                 /* Quit (commit suicide) */
5342                 case 'Q':
5343                 {
5344                         do_cmd_suicide();
5345                         break;
5346                 }
5347
5348                 case '|':
5349                 {
5350                         do_cmd_nikki();
5351                         break;
5352                 }
5353
5354                 /* Check artifacts, uniques, objects */
5355                 case '~':
5356                 {
5357                         do_cmd_knowledge();
5358                         break;
5359                 }
5360
5361                 /* Load "screen dump" */
5362                 case '(':
5363                 {
5364                         do_cmd_load_screen();
5365                         break;
5366                 }
5367
5368                 /* Save "screen dump" */
5369                 case ')':
5370                 {
5371                         do_cmd_save_screen();
5372                         break;
5373                 }
5374
5375                 /* Make random artifact list */
5376                 case KTRL('V'):
5377                 {
5378                         spoil_random_artifact("randifact.txt");
5379                         break;
5380                 }
5381
5382                 /* Hack -- Unknown command */
5383                 default:
5384                 {
5385                         if (flush_failure) flush();
5386                         if (one_in_(2))
5387                         {
5388                                 char error_m[1024];
5389                                 sound(SOUND_ILLEGAL);
5390 #ifdef JP
5391                                 if (!get_rnd_line("error_j.txt", 0, error_m))
5392 #else
5393                                 if (!get_rnd_line("error.txt", 0, error_m))
5394 #endif
5395
5396                                         msg_print(error_m);
5397                         }
5398                         else
5399 #ifdef JP
5400 prt(" '?' ¤Ç¥Ø¥ë¥×¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£", 0, 0);
5401 #else
5402                                 prt("Type '?' for help.", 0, 0);
5403 #endif
5404
5405                         break;
5406                 }
5407         }
5408         if (!energy_use && !now_message)
5409                 now_message = old_now_message;
5410 }
5411
5412
5413
5414
5415 static bool monster_tsuri(int r_idx)
5416 {
5417         monster_race *r_ptr = &r_info[r_idx];
5418
5419         if ((r_ptr->flags7 & RF7_AQUATIC) && !(r_ptr->flags1 & RF1_UNIQUE) && strchr("Jjlw", r_ptr->d_char))
5420                 return TRUE;
5421         else
5422                 return FALSE;
5423 }
5424
5425
5426 /*
5427  * Process the player
5428  *
5429  * Notice the annoying code to handle "pack overflow", which
5430  * must come first just in case somebody manages to corrupt
5431  * the savefiles by clever use of menu commands or something.
5432  */
5433 static void process_player(void)
5434 {
5435         int i;
5436
5437         /*** Apply energy ***/
5438
5439         if (hack_mutation)
5440         {
5441 #ifdef JP
5442 msg_print("²¿¤«ÊѤï¤Ã¤¿µ¤¤¬¤¹¤ë¡ª");
5443 #else
5444                 msg_print("You feel different!");
5445 #endif
5446
5447                 (void)gain_random_mutation(0);
5448                 hack_mutation = FALSE;
5449         }
5450
5451         if (p_ptr->inside_battle)
5452         {
5453                 for(i = 1; i < m_max; i++)
5454                 {
5455                         monster_type *m_ptr = &m_list[i];
5456
5457                         if (!m_ptr->r_idx) continue;
5458
5459                         /* Hack -- Detect monster */
5460                         m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
5461
5462                         /* Update the monster */
5463                         update_mon(i, FALSE);
5464                 }
5465                 prt_time();
5466         }
5467
5468         /* Give the player some energy */
5469         else if (!(load && p_ptr->energy_need <= 0))
5470         {
5471                 p_ptr->energy_need -= SPEED_TO_ENERGY(p_ptr->pspeed);
5472         }
5473
5474         /* No turn yet */
5475         if (p_ptr->energy_need > 0) return;
5476         if (!command_rep) prt_time();
5477
5478         /*** Check for interupts ***/
5479
5480         /* Complete resting */
5481         if (resting < 0)
5482         {
5483                 /* Basic resting */
5484                 if (resting == -1)
5485                 {
5486                         /* Stop resting */
5487                         if ((p_ptr->chp == p_ptr->mhp) &&
5488                             (p_ptr->csp >= p_ptr->msp))
5489                         {
5490                                 set_action(ACTION_NONE);
5491                         }
5492                 }
5493
5494                 /* Complete resting */
5495                 else if (resting == -2)
5496                 {
5497                         /* Stop resting */
5498                         if ((p_ptr->chp == p_ptr->mhp) &&
5499                             (p_ptr->csp >= p_ptr->msp) &&
5500                             !p_ptr->blind && !p_ptr->confused &&
5501                             !p_ptr->poisoned && !p_ptr->afraid &&
5502                             !p_ptr->stun && !p_ptr->cut &&
5503                             !p_ptr->slow && !p_ptr->paralyzed &&
5504                             !p_ptr->image && !p_ptr->word_recall &&
5505                             !p_ptr->alter_reality)
5506                         {
5507                                 set_action(ACTION_NONE);
5508                         }
5509                 }
5510         }
5511
5512         if (p_ptr->action == ACTION_FISH)
5513         {
5514                 /* Delay */
5515                 Term_xtra(TERM_XTRA_DELAY, 10);
5516                 if (one_in_(1000))
5517                 {
5518                         int r_idx;
5519                         bool success = FALSE;
5520                         get_mon_num_prep(monster_tsuri,NULL);
5521                         r_idx = get_mon_num(dun_level ? dun_level : wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level);
5522                         msg_print(NULL);
5523                         if (r_idx && one_in_(2))
5524                         {
5525                                 int y, x;
5526                                 y = py+ddy[tsuri_dir];
5527                                 x = px+ddx[tsuri_dir];
5528                                 if (place_monster_aux(0, y, x, r_idx, PM_NO_KAGE))
5529                                 {
5530                                         char m_name[80];
5531                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
5532 #ifdef JP
5533                                         msg_format("%s¤¬Äà¤ì¤¿¡ª", m_name);
5534 #else
5535                                         msg_format("You have a good catch!", m_name);
5536 #endif
5537                                         success = TRUE;
5538                                 }
5539                         }
5540                         if (!success)
5541                         {
5542 #ifdef JP
5543                                 msg_print("±Â¤À¤±¿©¤ï¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª¤¯¤Ã¤½¡Á¡ª");
5544 #else
5545                                 msg_print("Damn!  The fish stole your bait!");
5546 #endif
5547                         }
5548                         disturb(0, 0);
5549                 }
5550         }
5551
5552         /* Handle "abort" */
5553         if (check_abort)
5554         {
5555                 /* Check for "player abort" (semi-efficiently for resting) */
5556                 if (running || command_rep || (p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH))
5557                 {
5558                         /* Do not wait */
5559                         inkey_scan = TRUE;
5560
5561                         /* Check for a key */
5562                         if (inkey())
5563                         {
5564                                 /* Flush input */
5565                                 flush();
5566
5567                                 /* Disturb */
5568                                 disturb(0, 0);
5569
5570                                 /* Hack -- Show a Message */
5571 #ifdef JP
5572 msg_print("ÃæÃǤ·¤Þ¤·¤¿¡£");
5573 #else
5574                                 msg_print("Canceled.");
5575 #endif
5576
5577                         }
5578                 }
5579         }
5580
5581         if (p_ptr->riding && !p_ptr->confused && !p_ptr->blind)
5582         {
5583                 monster_type *m_ptr = &m_list[p_ptr->riding];
5584
5585                 if (m_ptr->csleep)
5586                 {
5587                         char m_name[80];
5588
5589                         /* Recover fully */
5590                         m_ptr->csleep = 0;
5591
5592                         if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
5593
5594                         /* Acquire the monster name */
5595                         monster_desc(m_name, m_ptr, 0);
5596 #ifdef JP
5597 msg_format("%^s¤òµ¯¤³¤·¤¿¡£", m_name);
5598 #else
5599                         msg_format("You have waked %s up.", m_name);
5600 #endif
5601                         if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= (PR_HEALTH);
5602                         p_ptr->redraw |= (PR_UHEALTH);
5603                 }
5604
5605                 if (m_ptr->stunned)
5606                 {
5607                         int d = 1;
5608
5609                         /* Make a "saving throw" against stun */
5610                         if (randint0(r_info[m_ptr->r_idx].level) < p_ptr->skill_exp[GINOU_RIDING])
5611                         {
5612                                 /* Recover fully */
5613                                 d = m_ptr->stunned;
5614                         }
5615
5616                         /* Hack -- Recover from stun */
5617                         if (m_ptr->stunned > d)
5618                         {
5619                                 /* Recover somewhat */
5620                                 m_ptr->stunned -= d;
5621                         }
5622
5623                         /* Fully recover */
5624                         else
5625                         {
5626                                 char m_name[80];
5627
5628                                 /* Recover fully */
5629                                 m_ptr->stunned = 0;
5630
5631                                 /* Acquire the monster name */
5632                                 monster_desc(m_name, m_ptr, 0);
5633
5634                                 /* Dump a message */
5635 #ifdef JP
5636 msg_format("%^s¤òÛ¯Û°¾õÂÖ¤«¤éΩ¤Áľ¤é¤»¤¿¡£", m_name);
5637 #else
5638                                 msg_format("%^s is no longer stunned.", m_name);
5639 #endif
5640                                 if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= (PR_HEALTH);
5641                                 p_ptr->redraw |= (PR_UHEALTH);
5642                         }
5643                 }
5644
5645                 if (m_ptr->confused)
5646                 {
5647                         int d = 1;
5648
5649                         /* Make a "saving throw" against stun */
5650                         if (randint0(r_info[m_ptr->r_idx].level) < p_ptr->skill_exp[GINOU_RIDING])
5651                         {
5652                                 /* Recover fully */
5653                                 d = m_ptr->confused;
5654                         }
5655
5656                         /* Hack -- Recover from stun */
5657                         if (m_ptr->confused > d)
5658                         {
5659                                 /* Recover somewhat */
5660                                 m_ptr->confused -= d;
5661                         }
5662
5663                         /* Fully recover */
5664                         else
5665                         {
5666                                 char m_name[80];
5667
5668                                 /* Recover fully */
5669                                 m_ptr->confused = 0;
5670
5671                                 /* Acquire the monster name */
5672                                 monster_desc(m_name, m_ptr, 0);
5673
5674                                 /* Dump a message */
5675 #ifdef JP
5676 msg_format("%^s¤òº®Íð¾õÂÖ¤«¤éΩ¤Áľ¤é¤»¤¿¡£", m_name);
5677 #else
5678                                 msg_format("%^s is no longer confused.", m_name);
5679 #endif
5680                                 if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= (PR_HEALTH);
5681                                 p_ptr->redraw |= (PR_UHEALTH);
5682                         }
5683                 }
5684
5685                 if (m_ptr->monfear)
5686                 {
5687                         int d = 1;
5688
5689                         /* Make a "saving throw" against stun */
5690                         if (randint0(r_info[m_ptr->r_idx].level) < p_ptr->skill_exp[GINOU_RIDING])
5691                         {
5692                                 /* Recover fully */
5693                                 d = m_ptr->monfear;
5694                         }
5695
5696                         /* Hack -- Recover from stun */
5697                         if (m_ptr->monfear > d)
5698                         {
5699                                 /* Recover somewhat */
5700                                 m_ptr->monfear -= d;
5701                         }
5702
5703                         /* Fully recover */
5704                         else
5705                         {
5706                                 char m_name[80];
5707
5708                                 /* Recover fully */
5709                                 m_ptr->monfear = 0;
5710
5711                                 /* Acquire the monster name */
5712                                 monster_desc(m_name, m_ptr, 0);
5713
5714                                 /* Dump a message */
5715 #ifdef JP
5716 msg_format("%^s¤ò¶²Éݤ«¤éΩ¤Áľ¤é¤»¤¿¡£", m_name);
5717 #else
5718                                 msg_format("%^s is no longer fear.", m_name);
5719 #endif
5720                                 if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= (PR_HEALTH);
5721                                 p_ptr->redraw |= (PR_UHEALTH);
5722                         }
5723                 }
5724
5725                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5726                 handle_stuff();
5727         }
5728
5729         /* Handle the player song */
5730         if (!load) check_music();
5731
5732         load = FALSE;
5733
5734         /* Fast */
5735         if (p_ptr->lightspeed)
5736         {
5737                 (void)set_lightspeed(p_ptr->lightspeed - 1, TRUE);
5738         }
5739         if ((p_ptr->pclass == CLASS_FORCETRAINER) && (p_ptr->magic_num1[0]))
5740         {
5741                 if (p_ptr->magic_num1[0] < 40)
5742                 {
5743                         p_ptr->magic_num1[0] = 0;
5744                 }
5745                 else p_ptr->magic_num1[0] -= 40;
5746                 p_ptr->update |= (PU_BONUS);
5747         }
5748         if (p_ptr->action == ACTION_LEARN)
5749         {
5750                 int hoge = ((p_ptr->msp * 0x10000L) / 256L)+7680L;
5751                 if ((p_ptr->csp * 0x10000L + p_ptr->csp_frac) < hoge)
5752                 {
5753                         p_ptr->csp = 0;
5754                         p_ptr->csp_frac = 0;
5755                         set_action(ACTION_NONE);
5756                 }
5757                 else
5758                 {
5759                         p_ptr->csp -= (s16b)(hoge >> 16);
5760                         hoge &= 0xFFFFL;
5761                         if (p_ptr->csp_frac < hoge)
5762                         {
5763                                 p_ptr->csp_frac += 0x10000L - hoge;
5764                                 p_ptr->csp--;
5765                         }
5766                         else
5767                                 p_ptr->csp_frac -= hoge;
5768                 }
5769                 p_ptr->redraw |= PR_MANA;
5770         }
5771
5772         if (p_ptr->special_defense & KATA_MASK)
5773         {
5774                 if (p_ptr->special_defense & KATA_MUSOU)
5775                 {
5776                         if (p_ptr->csp < 3)
5777                         {
5778                                 set_action(ACTION_NONE);
5779                         }
5780                         else
5781                         {
5782                                 p_ptr->csp -= 2;
5783                                 p_ptr->redraw |= (PR_MANA);
5784                         }
5785                 }
5786         }
5787
5788         /*** Handle actual user input ***/
5789
5790         /* Repeat until out of energy */
5791         while (p_ptr->energy_need <= 0)
5792         {
5793                 p_ptr->window |= PW_PLAYER;
5794                 p_ptr->sutemi = FALSE;
5795                 p_ptr->counter = FALSE;
5796                 now_damaged = FALSE;
5797
5798                 /* Handle "p_ptr->notice" */
5799                 notice_stuff();
5800
5801                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5802                 handle_stuff();
5803
5804                 /* Place the cursor on the player */
5805                 move_cursor_relative(py, px);
5806
5807                 /* Refresh (optional) */
5808                 if (fresh_before) Term_fresh();
5809
5810
5811                 /* Hack -- Pack Overflow */
5812                 if (inventory[INVEN_PACK].k_idx)
5813                 {
5814                         int item = INVEN_PACK;
5815
5816                         char o_name[MAX_NLEN];
5817
5818                         object_type *o_ptr;
5819
5820                         /* Access the slot to be dropped */
5821                         o_ptr = &inventory[item];
5822
5823                         /* Disturbing */
5824                         disturb(0, 0);
5825
5826                         /* Warning */
5827 #ifdef JP
5828 msg_print("¥¶¥Ã¥¯¤«¤é¥¢¥¤¥Æ¥à¤¬¤¢¤Õ¤ì¤¿¡ª");
5829 #else
5830                         msg_print("Your pack overflows!");
5831 #endif
5832
5833
5834                         /* Describe */
5835                         object_desc(o_name, o_ptr, TRUE, 3);
5836
5837                         /* Message */
5838 #ifdef JP
5839 msg_format("%s(%c)¤òÍî¤È¤·¤¿¡£", o_name, index_to_label(item));
5840 #else
5841                         msg_format("You drop %s (%c).", o_name, index_to_label(item));
5842 #endif
5843
5844
5845                         /* Drop it (carefully) near the player */
5846                         (void)drop_near(o_ptr, 0, py, px);
5847
5848                         /* Modify, Describe, Optimize */
5849                         inven_item_increase(item, -255);
5850                         inven_item_describe(item);
5851                         inven_item_optimize(item);
5852
5853                         /* Handle "p_ptr->notice" */
5854                         notice_stuff();
5855
5856                         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5857                         handle_stuff();
5858                 }
5859
5860
5861                 /* Hack -- cancel "lurking browse mode" */
5862                 if (!command_new) command_see = FALSE;
5863
5864
5865                 /* Assume free turn */
5866                 energy_use = 0;
5867
5868
5869                 if (p_ptr->inside_battle)
5870                 {
5871                         /* Place the cursor on the player */
5872                         move_cursor_relative(py, px);
5873
5874                         command_cmd = SPECIAL_KEY_BUILDING;
5875
5876                         /* Process the command */
5877                         process_command();
5878                 }
5879
5880                 /* Paralyzed or Knocked Out */
5881                 else if (p_ptr->paralyzed || (p_ptr->stun >= 100))
5882                 {
5883                         /* Take a turn */
5884                         energy_use = 100;
5885                 }
5886
5887                 /* Resting */
5888                 else if (p_ptr->action == ACTION_REST)
5889                 {
5890                         /* Timed rest */
5891                         if (resting > 0)
5892                         {
5893                                 /* Reduce rest count */
5894                                 resting--;
5895
5896                                 if (!resting) set_action(ACTION_NONE);
5897
5898                                 /* Redraw the state */
5899                                 p_ptr->redraw |= (PR_STATE);
5900                         }
5901
5902                         /* Take a turn */
5903                         energy_use = 100;
5904                 }
5905
5906                 /* Fishing */
5907                 else if (p_ptr->action == ACTION_FISH)
5908                 {
5909                         /* Take a turn */
5910                         energy_use = 100;
5911                 }
5912
5913                 /* Running */
5914                 else if (running)
5915                 {
5916                         /* Take a step */
5917                         run_step(0);
5918                 }
5919
5920                 /* Repeated command */
5921                 else if (command_rep)
5922                 {
5923                         /* Count this execution */
5924                         command_rep--;
5925
5926                         /* Redraw the state */
5927                         p_ptr->redraw |= (PR_STATE);
5928
5929                         /* Redraw stuff */
5930                         redraw_stuff();
5931
5932                         /* Hack -- Assume messages were seen */
5933                         msg_flag = FALSE;
5934
5935                         /* Clear the top line */
5936                         prt("", 0, 0);
5937
5938                         /* Process the command */
5939                         process_command();
5940                 }
5941
5942                 /* Normal command */
5943                 else
5944                 {
5945                         /* Place the cursor on the player */
5946                         move_cursor_relative(py, px);
5947
5948                         can_save = TRUE;
5949                         /* Get a command (normal) */
5950                         request_command(FALSE);
5951                         can_save = FALSE;
5952
5953                         /* Process the command */
5954                         process_command();
5955                 }
5956
5957
5958                 /*** Clean up ***/
5959
5960                 /* Significant */
5961                 if (energy_use)
5962                 {
5963                         /* Use some energy */
5964                         if (world_player || energy_use > 400)
5965                         {
5966                                 /* The Randomness is irrelevant */
5967                                 p_ptr->energy_need += energy_use * TURNS_PER_TICK / 10;
5968                         }
5969                         else
5970                         {
5971                                 /* There is some randomness of needed energy */
5972                                 p_ptr->energy_need += (s16b)((s32b)energy_use * ENERGY_NEED() / 100L);
5973                         }
5974
5975                         /* Hack -- constant hallucination */
5976                         if (p_ptr->image) p_ptr->redraw |= (PR_MAP);
5977
5978
5979                         /* Shimmer monsters if needed */
5980                         if (shimmer_monsters)
5981                         {
5982                                 /* Clear the flag */
5983                                 shimmer_monsters = FALSE;
5984
5985                                 /* Shimmer multi-hued monsters */
5986                                 for (i = 1; i < m_max; i++)
5987                                 {
5988                                         monster_type *m_ptr;
5989                                         monster_race *r_ptr;
5990
5991                                         /* Access monster */
5992                                         m_ptr = &m_list[i];
5993
5994                                         /* Skip dead monsters */
5995                                         if (!m_ptr->r_idx) continue;
5996
5997                                         /* Skip unseen monsters */
5998                                         if (!m_ptr->ml) continue;
5999
6000                                         /* Access the monster race */
6001                                         r_ptr = &r_info[m_ptr->ap_r_idx];
6002
6003                                         /* Skip non-multi-hued monsters */
6004                                         if (!(r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER)))
6005                                                 continue;
6006
6007                                         /* Reset the flag */
6008                                         shimmer_monsters = TRUE;
6009
6010                                         /* Redraw regardless */
6011                                         lite_spot(m_ptr->fy, m_ptr->fx);
6012                                 }
6013                         }
6014
6015
6016                         /* Handle monster detection */
6017                         if (repair_monsters)
6018                         {
6019                                 /* Reset the flag */
6020                                 repair_monsters = FALSE;
6021
6022                                 /* Rotate detection flags */
6023                                 for (i = 1; i < m_max; i++)
6024                                 {
6025                                         monster_type *m_ptr;
6026
6027                                         /* Access monster */
6028                                         m_ptr = &m_list[i];
6029
6030                                         /* Skip dead monsters */
6031                                         if (!m_ptr->r_idx) continue;
6032
6033                                         /* Nice monsters get mean */
6034                                         if (m_ptr->mflag & MFLAG_NICE)
6035                                         {
6036                                                 /* Nice monsters get mean */
6037                                                 m_ptr->mflag &= ~(MFLAG_NICE);
6038                                         }
6039
6040                                         /* Handle memorized monsters */
6041                                         if (m_ptr->mflag2 & MFLAG2_MARK)
6042                                         {
6043                                                 /* Maintain detection */
6044                                                 if (m_ptr->mflag2 & MFLAG2_SHOW)
6045                                                 {
6046                                                         /* Forget flag */
6047                                                         m_ptr->mflag2 &= ~(MFLAG2_SHOW);
6048
6049                                                         /* Still need repairs */
6050                                                         repair_monsters = TRUE;
6051                                                 }
6052
6053                                                 /* Remove detection */
6054                                                 else
6055                                                 {
6056                                                         /* Forget flag */
6057                                                         m_ptr->mflag2 &= ~(MFLAG2_MARK);
6058
6059                                                         /* Assume invisible */
6060                                                         m_ptr->ml = FALSE;
6061
6062                                                         /* Update the monster */
6063                                                         update_mon(i, FALSE);
6064
6065                                                         if (p_ptr->health_who == i) p_ptr->redraw |= (PR_HEALTH);
6066                                                         if (p_ptr->riding == i) p_ptr->redraw |= (PR_UHEALTH);
6067
6068                                                         /* Redraw regardless */
6069                                                         lite_spot(m_ptr->fy, m_ptr->fx);
6070                                                 }
6071                                         }
6072                                 }
6073                         }
6074                         if (p_ptr->pclass == CLASS_IMITATOR)
6075                         {
6076                                 if (p_ptr->mane_num > (p_ptr->lev > 44 ? 3 : p_ptr->lev > 29 ? 2 : 1))
6077                                 {
6078                                         p_ptr->mane_num--;
6079                                         for (i = 0; i < p_ptr->mane_num; i++)
6080                                         {
6081                                                 p_ptr->mane_spell[i] = p_ptr->mane_spell[i+1];
6082                                                 p_ptr->mane_dam[i] = p_ptr->mane_dam[i+1];
6083                                         }
6084                                 }
6085                                 new_mane = FALSE;
6086                                 p_ptr->redraw |= (PR_MANE);
6087                         }
6088                         if (p_ptr->action == ACTION_LEARN)
6089                         {
6090                                 new_mane = FALSE;
6091                                 p_ptr->redraw |= (PR_STATE);
6092                         }
6093
6094                         if (world_player && (p_ptr->energy_need > - 1000))
6095                         {
6096                                 /* Redraw map */
6097                                 p_ptr->redraw |= (PR_MAP);
6098
6099                                 /* Update monsters */
6100                                 p_ptr->update |= (PU_MONSTERS);
6101
6102                                 /* Window stuff */
6103                                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
6104
6105 #ifdef JP
6106                                 msg_print("¡Ö»þ¤ÏÆ°¤­¤À¤¹¡Ä¡×");
6107 #else
6108                                 msg_print("You feel time flowing around you once more.");
6109 #endif
6110                                 msg_print(NULL);
6111                                 world_player = FALSE;
6112                                 p_ptr->energy_need = ENERGY_NEED();
6113
6114                                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6115                                 handle_stuff();
6116                         }
6117                 }
6118
6119                 /* Hack -- notice death */
6120                 if (!p_ptr->playing || p_ptr->is_dead)
6121                 {
6122                         world_player = FALSE;
6123                         break;
6124                 }
6125
6126                 /* Handle "leaving" */
6127                 if (p_ptr->leaving) break;
6128         }
6129
6130         /* Update scent trail */
6131         update_smell();
6132 }
6133
6134
6135 /*
6136  * Interact with the current dungeon level.
6137  *
6138  * This function will not exit until the level is completed,
6139  * the user dies, or the game is terminated.
6140  */
6141 static void dungeon(bool load_game)
6142 {
6143         int quest_num = 0;
6144
6145         /* Set the base level */
6146         base_level = dun_level;
6147
6148         /* Reset various flags */
6149         hack_mind = FALSE;
6150
6151         /* Not leaving */
6152         p_ptr->leaving = FALSE;
6153
6154         /* Reset the "command" vars */
6155         command_cmd = 0;
6156         command_new = 0;
6157         command_rep = 0;
6158         command_arg = 0;
6159         command_dir = 0;
6160
6161
6162         /* Cancel the target */
6163         target_who = 0;
6164         pet_t_m_idx = 0;
6165         riding_t_m_idx = 0;
6166         ambush_flag = FALSE;
6167
6168         /* Cancel the health bar */
6169         health_track(0);
6170
6171         /* Check visual effects */
6172         shimmer_monsters = TRUE;
6173         shimmer_objects = TRUE;
6174         repair_monsters = TRUE;
6175         repair_objects = TRUE;
6176
6177
6178         /* Disturb */
6179         disturb(1, 0);
6180
6181         /* Get index of current quest (if any) */
6182         quest_num = quest_number(dun_level);
6183
6184         /* Inside a quest? */
6185         if (quest_num)
6186         {
6187                 /* Mark the quest monster */
6188                 r_info[quest[quest_num].r_idx].flags1 |= RF1_QUESTOR;
6189         }
6190
6191         /* Track maximum player level */
6192         if (p_ptr->max_plv < p_ptr->lev)
6193         {
6194                 p_ptr->max_plv = p_ptr->lev;
6195         }
6196
6197
6198         /* Track maximum dungeon level (if not in quest -KMW-) */
6199         if ((max_dlv[dungeon_type] < dun_level) && !p_ptr->inside_quest)
6200         {
6201                 max_dlv[dungeon_type] = dun_level;
6202                 if (record_maxdeapth) do_cmd_write_nikki(NIKKI_MAXDEAPTH, dun_level, NULL);
6203         }
6204
6205         /* Validate the panel */
6206         panel_bounds_center();
6207
6208         /* Verify the panel */
6209         verify_panel();
6210
6211         /* Flush messages */
6212         msg_print(NULL);
6213
6214
6215         /* Enter "xtra" mode */
6216         character_xtra = TRUE;
6217
6218         /* Window stuff */
6219         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_MONSTER | PW_OVERHEAD | PW_DUNGEON);
6220
6221         /* Redraw dungeon */
6222         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_EQUIPPY);
6223
6224         /* Redraw map */
6225         p_ptr->redraw |= (PR_MAP);
6226
6227         /* Update stuff */
6228         p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
6229
6230         /* Update lite/view */
6231         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_TORCH);
6232
6233         /* Update monsters */
6234         p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
6235
6236         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6237         handle_stuff();
6238
6239         /* Leave "xtra" mode */
6240         character_xtra = FALSE;
6241
6242         /* Update stuff */
6243         p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
6244
6245         /* Combine / Reorder the pack */
6246         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
6247
6248         /* Handle "p_ptr->notice" */
6249         notice_stuff();
6250
6251         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6252         handle_stuff();
6253
6254         /* Refresh */
6255         Term_fresh();
6256
6257         if (quest_num && (is_fixed_quest_idx(quest_num) &&
6258             !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) ||
6259             !(quest[quest_num].flags & QUEST_FLAG_PRESET)))) do_cmd_feeling();
6260
6261         if (p_ptr->inside_battle)
6262         {
6263                 if (load_game)
6264                 {
6265                         p_ptr->energy_need = 0;
6266                         battle_monsters();
6267                 }
6268                 else
6269                 {
6270 #ifdef JP
6271 msg_print("»î¹ç³«»Ï¡ª");
6272 #else
6273                         msg_format("Ready..Fight!");
6274 #endif
6275                         msg_print(NULL);
6276                 }
6277         }
6278
6279         if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] > MUSIC_DETECT))
6280                 p_ptr->magic_num1[0] = MUSIC_DETECT;
6281
6282         /* Hack -- notice death or departure */
6283         if (!p_ptr->playing || p_ptr->is_dead) return;
6284
6285         /* Print quest message if appropriate */
6286         if (!p_ptr->inside_quest && (dungeon_type == DUNGEON_ANGBAND))
6287         {
6288                 quest_discovery(random_quest_number(dun_level));
6289                 p_ptr->inside_quest = random_quest_number(dun_level);
6290         }
6291         if ((dun_level == d_info[dungeon_type].maxdepth) && d_info[dungeon_type].final_guardian)
6292         {
6293                 if (r_info[d_info[dungeon_type].final_guardian].max_num)
6294 #ifdef JP
6295                         msg_format("¤³¤Î³¬¤Ë¤Ï%s¤Î¼ç¤Ç¤¢¤ë%s¤¬À³¤ó¤Ç¤¤¤ë¡£",
6296                                    d_name+d_info[dungeon_type].name, 
6297                                    r_name+r_info[d_info[dungeon_type].final_guardian].name);
6298 #else
6299                         msg_format("%^s lives in this level as the keeper of %s.",
6300                                            r_name+r_info[d_info[dungeon_type].final_guardian].name, 
6301                                            d_name+d_info[dungeon_type].name);
6302 #endif
6303         }
6304
6305         /*** Process this dungeon level ***/
6306
6307         /* Reset the monster generation level */
6308         monster_level = base_level;
6309
6310         /* Reset the object generation level */
6311         object_level = base_level;
6312
6313         hack_mind = TRUE;
6314
6315         if (p_ptr->energy_need > 0 && !p_ptr->inside_battle &&
6316             (dun_level || p_ptr->leaving_dungeon || p_ptr->inside_arena))
6317                 p_ptr->energy_need = 0;
6318
6319         /* Not leaving dungeon */
6320         p_ptr->leaving_dungeon = FALSE;
6321
6322         /* Main loop */
6323         while (TRUE)
6324         {
6325                 /* Hack -- Compact the monster list occasionally */
6326                 if ((m_cnt + 32 > max_m_idx) && !p_ptr->inside_battle) compact_monsters(64);
6327
6328                 /* Hack -- Compress the monster list occasionally */
6329                 if ((m_cnt + 32 < m_max) && !p_ptr->inside_battle) compact_monsters(0);
6330
6331
6332                 /* Hack -- Compact the object list occasionally */
6333                 if (o_cnt + 32 > max_o_idx) compact_objects(64);
6334
6335                 /* Hack -- Compress the object list occasionally */
6336                 if (o_cnt + 32 < o_max) compact_objects(0);
6337
6338
6339                 /* Process the player */
6340                 process_player();
6341
6342                 /* Handle "p_ptr->notice" */
6343                 notice_stuff();
6344
6345                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6346                 handle_stuff();
6347
6348                 /* Hack -- Hilite the player */
6349                 move_cursor_relative(py, px);
6350
6351                 /* Optional fresh */
6352                 if (fresh_after) Term_fresh();
6353
6354                 /* Hack -- Notice death or departure */
6355                 if (!p_ptr->playing || p_ptr->is_dead) break;
6356
6357                 /* Process all of the monsters */
6358                 process_monsters();
6359
6360                 /* Handle "p_ptr->notice" */
6361                 notice_stuff();
6362
6363                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6364                 handle_stuff();
6365
6366                 /* Hack -- Hilite the player */
6367                 move_cursor_relative(py, px);
6368
6369                 /* Optional fresh */
6370                 if (fresh_after) Term_fresh();
6371
6372                 /* Hack -- Notice death or departure */
6373                 if (!p_ptr->playing || p_ptr->is_dead) break;
6374
6375
6376                 /* Process the world */
6377                 process_world();
6378
6379                 /* Handle "p_ptr->notice" */
6380                 notice_stuff();
6381
6382                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6383                 handle_stuff();
6384
6385                 /* Hack -- Hilite the player */
6386                 move_cursor_relative(py, px);
6387
6388                 /* Optional fresh */
6389                 if (fresh_after) Term_fresh();
6390
6391                 /* Hack -- Notice death or departure */
6392                 if (!p_ptr->playing || p_ptr->is_dead) break;
6393
6394                 /* Handle "leaving" */
6395                 if (p_ptr->leaving) break;
6396
6397                 /* Count game turns */
6398                 turn++;
6399                 if (!p_ptr->wild_mode || wild_regen) dungeon_turn++;
6400                 else if (p_ptr->wild_mode && !(turn % ((MAX_HGT + MAX_WID) / 2))) dungeon_turn++;
6401                 if (wild_regen) wild_regen--;
6402         }
6403
6404         /* Inside a quest and non-unique questor? */
6405         if (quest_num && !(r_info[quest[quest_num].r_idx].flags1 & RF1_UNIQUE))
6406         {
6407                 /* Un-mark the quest monster */
6408                 r_info[quest[quest_num].r_idx].flags1 &= ~RF1_QUESTOR;
6409         }
6410
6411         /* Not save-and-quit and not dead? */
6412         if (p_ptr->playing && !p_ptr->is_dead)
6413         {
6414                 /*
6415                  * Maintain Unique monsters and artifact, save current
6416                  * floor, then prepare next floor
6417                  */
6418                 leave_floor();
6419
6420                 /* Forget the flag */
6421                 reinit_wilderness = FALSE;
6422         }
6423
6424         /* Write about current level on the play record once per level */
6425         write_level = TRUE;
6426 }
6427
6428
6429 /*
6430  * Load some "user pref files"
6431  *
6432  * Modified by Arcum Dagsson to support
6433  * separate macro files for different realms.
6434  */
6435 static void load_all_pref_files(void)
6436 {
6437         char buf[1024];
6438         errr err;
6439
6440         /* Access the "user" pref file */
6441         sprintf(buf, "user.prf");
6442
6443         /* Process that file */
6444         process_pref_file(buf);
6445
6446         /* Access the "user" system pref file */
6447         sprintf(buf, "user-%s.prf", ANGBAND_SYS);
6448
6449         /* Process that file */
6450         process_pref_file(buf);
6451
6452         /* Access the "race" pref file */
6453         sprintf(buf, "%s.prf", rp_ptr->title);
6454
6455         /* Process that file */
6456         process_pref_file(buf);
6457
6458         /* Access the "class" pref file */
6459         sprintf(buf, "%s.prf", cp_ptr->title);
6460
6461         /* Process that file */
6462         process_pref_file(buf);
6463
6464         /* Access the "character" pref file */
6465         sprintf(buf, "%s.prf", player_base);
6466
6467         /* Process that file */
6468         process_pref_file(buf);
6469
6470         /* Free old entries */
6471         init_autopicker();
6472
6473 #ifdef JP
6474         sprintf(buf, "picktype-%s.prf", player_base);
6475 #else
6476         sprintf(buf, "pickpref-%s.prf", player_base);
6477 #endif
6478
6479         err = process_pickpref_file(buf);
6480
6481         /* Process 'pick????.prf' if 'pick????-<name>.prf' doesn't exist */
6482         if (0 > err)
6483         {
6484 #ifdef JP
6485                 process_pickpref_file("picktype.prf");
6486 #else
6487                 process_pickpref_file("pickpref.prf");
6488 #endif
6489         }
6490
6491         /* Access the "realm 1" pref file */
6492         if (p_ptr->realm1 != REALM_NONE)
6493         {
6494                 sprintf(buf, "%s.prf", realm_names[p_ptr->realm1]);
6495
6496                 /* Process that file */
6497                 process_pref_file(buf);
6498         }
6499
6500         /* Access the "realm 2" pref file */
6501         if (p_ptr->realm2 != REALM_NONE)
6502         {
6503                 sprintf(buf, "%s.prf", realm_names[p_ptr->realm2]);
6504
6505                 /* Process that file */
6506                 process_pref_file(buf);
6507         }
6508 }
6509
6510
6511 /*
6512  * Extract option variables from bit sets
6513  */
6514 void extract_option_vars(void)
6515 {
6516         int i;
6517
6518         for (i = 0; option_info[i].o_desc; i++)
6519         {
6520                 int os = option_info[i].o_set;
6521                 int ob = option_info[i].o_bit;
6522
6523                 /* Set the "default" options */
6524                 if (option_info[i].o_var)
6525                 {
6526                         /* Set */
6527                         if (option_flag[os] & (1L << ob))
6528                         {
6529                                 /* Set */
6530                                 (*option_info[i].o_var) = TRUE;
6531                         }
6532
6533                         /* Clear */
6534                         else
6535                         {
6536                                 /* Clear */
6537                                 (*option_info[i].o_var) = FALSE;
6538                         }
6539                 }
6540         }
6541 }
6542
6543
6544 /*
6545  * Determine bounty uniques
6546  */
6547 void determine_bounty_uniques(void)
6548 {
6549         int          i, j, tmp;
6550         monster_race *r_ptr;
6551
6552         get_mon_num_prep(NULL, NULL);
6553         for (i = 0; i < MAX_KUBI; i++)
6554         {
6555                 while (1)
6556                 {
6557                         kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
6558                         r_ptr = &r_info[kubi_r_idx[i]];
6559
6560                         if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
6561
6562                         if (!(r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON))) continue;
6563
6564                         if (r_ptr->rarity > 100) continue;
6565
6566                         if (no_questor_or_bounty_uniques(kubi_r_idx[i])) continue;
6567
6568                         for (j = 0; j < i; j++)
6569                                 if (kubi_r_idx[i] == kubi_r_idx[j]) break;
6570
6571                         if (j == i) break;
6572                 }
6573         }
6574
6575         /* Sort them */
6576         for (i = 0; i < MAX_KUBI - 1; i++)
6577         {
6578                 for (j = i; j < MAX_KUBI; j++)
6579                 {
6580                         if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
6581                         {
6582                                 tmp = kubi_r_idx[i];
6583                                 kubi_r_idx[i] = kubi_r_idx[j];
6584                                 kubi_r_idx[j] = tmp;
6585                         }
6586                 }
6587         }
6588 }
6589
6590
6591 /*
6592  * Determine today's bounty monster
6593  * Note: conv_old is used if loaded 0.0.3 or older save file
6594  */
6595 void determine_today_mon(bool conv_old)
6596 {
6597         int max_dl = 3, i;
6598         bool old_inside_battle = p_ptr->inside_battle;
6599         monster_race *r_ptr;
6600
6601         if (!conv_old)
6602         {
6603                 for (i = 0; i < max_d_idx; i++)
6604                 {
6605                         if (max_dlv[i] < d_info[i].mindepth) continue;
6606                         if (max_dl < max_dlv[i]) max_dl = max_dlv[i];
6607                 }
6608         }
6609         else max_dl = MAX(max_dlv[DUNGEON_ANGBAND], 3);
6610
6611         p_ptr->inside_battle = TRUE;
6612         get_mon_num_prep(NULL, NULL);
6613
6614         while (1)
6615         {
6616                 today_mon = get_mon_num(max_dl);
6617                 r_ptr = &r_info[today_mon];
6618
6619                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
6620                 if (r_ptr->flags7 & (RF7_UNIQUE_7 | RF7_UNIQUE2)) continue;
6621                 if (r_ptr->flags2 & RF2_MULTIPLY) continue;
6622                 if ((r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) != (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) continue;
6623                 if (r_ptr->level < MIN(max_dl / 2, 40)) continue;
6624                 if (r_ptr->rarity > 10) continue;
6625                 break;
6626         }
6627
6628         p_ptr->today_mon = 0;
6629         p_ptr->inside_battle = old_inside_battle;
6630 }
6631
6632
6633 /*
6634  * Actually play a game
6635  *
6636  * If the "new_game" parameter is true, then, after loading the
6637  * savefile, we will commit suicide, if necessary, to allow the
6638  * player to start a new game.
6639  */
6640 void play_game(bool new_game)
6641 {
6642         int i;
6643         bool load_game = TRUE;
6644
6645 #ifdef CHUUKEI
6646         if(chuukei_client){
6647           reset_visuals();
6648           browse_chuukei();
6649           return;
6650         }
6651 #endif
6652
6653         hack_mutation = FALSE;
6654
6655         /* Hack -- Character is "icky" */
6656         character_icky = TRUE;
6657
6658         /* Make sure main term is active */
6659         Term_activate(angband_term[0]);
6660
6661         /* Initialise the resize hooks */
6662         angband_term[0]->resize_hook = resize_map;
6663
6664         for (i = 1; i < 8; i++)
6665         {
6666                 /* Does the term exist? */
6667                 if (angband_term[i])
6668                 {
6669                         /* Add the redraw on resize hook */
6670                         angband_term[i]->resize_hook = redraw_window;
6671                 }
6672         }
6673
6674         /* Hack -- turn off the cursor */
6675         (void)Term_set_cursor(0);
6676
6677
6678         /* Attempt to load */
6679         if (!load_player())
6680         {
6681                 /* Oops */
6682 #ifdef JP
6683 quit("¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤¬²õ¤ì¤Æ¤¤¤Þ¤¹");
6684 #else
6685                 quit("broken savefile");
6686 #endif
6687
6688         }
6689
6690         /* Extract the options */
6691         extract_option_vars();
6692
6693         /* Report waited score */
6694         if (p_ptr->wait_report_score)
6695         {
6696                 char buf[1024];
6697                 bool success;
6698
6699 #ifdef JP
6700                 if (!get_check_strict("ÂÔµ¡¤·¤Æ¤¤¤¿¥¹¥³¥¢ÅÐÏ¿¤òº£¹Ô¤Ê¤¤¤Þ¤¹¤«¡©", CHECK_NO_HISTORY))
6701 #else
6702                 if (!get_check_strict("Do you register score now? ", CHECK_NO_HISTORY))
6703 #endif
6704                         quit(0);
6705
6706                 /* Update stuff */
6707                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
6708
6709                 /* Update stuff */
6710                 update_stuff();
6711
6712                 p_ptr->is_dead = TRUE;
6713
6714                 start_time = time(NULL);
6715
6716                 /* No suspending now */
6717                 signals_ignore_tstp();
6718                 
6719                 /* Hack -- Character is now "icky" */
6720                 character_icky = TRUE;
6721
6722                 /* Build the filename */
6723                 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
6724
6725                 /* Open the high score file, for reading/writing */
6726                 highscore_fd = fd_open(buf, O_RDWR);
6727
6728                 /* Handle score, show Top scores */
6729                 success = send_world_score(TRUE);
6730
6731 #ifdef JP
6732                 if (!success && !get_check_strict("¥¹¥³¥¢ÅÐÏ¿¤òÄü¤á¤Þ¤¹¤«¡©", CHECK_NO_HISTORY))
6733 #else
6734                 if (!success && !get_check_strict("Do you give up score registration? ", CHECK_NO_HISTORY))
6735 #endif
6736                 {
6737 #ifdef JP
6738                         prt("°ú¤­Â³¤­ÂÔµ¡¤·¤Þ¤¹¡£", 0, 0);
6739 #else
6740                         prt("standing by for future registration...", 0, 0);
6741 #endif
6742                         (void)inkey();
6743                 }
6744                 else
6745                 {
6746                         p_ptr->wait_report_score = FALSE;
6747                         top_twenty();
6748 #ifdef JP
6749                         if (!save_player()) msg_print("¥»¡¼¥Ö¼ºÇÔ¡ª");
6750 #else
6751                         if (!save_player()) msg_print("death save failed!");
6752 #endif
6753                 }
6754                 /* Shut the high score file */
6755                 (void)fd_close(highscore_fd);
6756
6757                 /* Forget the high score fd */
6758                 highscore_fd = -1;
6759                 
6760                 /* Allow suspending now */
6761                 signals_handle_tstp();
6762
6763                 quit(0);
6764         }
6765
6766         /* Nothing loaded */
6767         if (!character_loaded)
6768         {
6769                 /* Make new player */
6770                 new_game = TRUE;
6771
6772                 /* The dungeon is not ready */
6773                 character_dungeon = FALSE;
6774
6775                 /* Prepare to init the RNG */
6776                 Rand_quick = TRUE;
6777
6778                 /* Initialize the saved floors data */
6779                 init_saved_floors();
6780         }
6781
6782         /* Old game is loaded.  But new game is requested. */
6783         else if (new_game)
6784         {
6785                 /* Delete expanded temporal files */
6786                 clear_saved_floor_files();
6787         }
6788
6789         /* Process old character */
6790         if (!new_game)
6791         {
6792                 /* Process the player name */
6793                 process_player_name(FALSE);
6794         }
6795
6796         /* Init the RNG */
6797         if (Rand_quick)
6798         {
6799                 u32b seed;
6800
6801                 /* Basic seed */
6802                 seed = (time(NULL));
6803
6804 #ifdef SET_UID
6805
6806                 /* Mutate the seed on Unix machines */
6807                 seed = ((seed >> 3) * (getpid() << 1));
6808
6809 #endif
6810
6811                 /* Use the complex RNG */
6812                 Rand_quick = FALSE;
6813
6814                 /* Seed the "complex" RNG */
6815                 Rand_state_init(seed);
6816         }
6817
6818         /* Roll new character */
6819         if (new_game)
6820         {
6821                 /* The dungeon is not ready */
6822                 character_dungeon = FALSE;
6823
6824                 /* Start in town */
6825                 dun_level = 0;
6826                 p_ptr->inside_quest = 0;
6827                 p_ptr->inside_arena = FALSE;
6828                 p_ptr->inside_battle = FALSE;
6829
6830                 write_level = TRUE;
6831
6832                 /* Hack -- seed for flavors */
6833                 seed_flavor = randint0(0x10000000);
6834
6835                 /* Hack -- seed for town layout */
6836                 seed_town = randint0(0x10000000);
6837
6838                 /* Roll up a new character */
6839                 player_birth();
6840
6841                 counts_write(2,0);
6842                 p_ptr->count = 0;
6843
6844 #ifdef JP
6845                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "ÊÕ¶­¤ÎÃϤ˹ߤêΩ¤Ã¤¿¡£");
6846 #else
6847                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "You are standing in the Outpost.");
6848 #endif
6849
6850                 load = FALSE;
6851
6852                 determine_bounty_uniques();
6853                 determine_today_mon(FALSE);
6854         }
6855         else
6856         {
6857                 write_level = FALSE;
6858
6859 #ifdef JP
6860                 do_cmd_write_nikki(NIKKI_GAMESTART, 1, "                            ----¥²¡¼¥àºÆ³«----");
6861 #else
6862                 do_cmd_write_nikki(NIKKI_GAMESTART, 1, "                            ---- Restart Game ----");
6863 #endif
6864
6865 /*
6866  * 1.0.9 °ÊÁ°¤Ï¥»¡¼¥ÖÁ°¤Ë p_ptr->riding = -1 ¤È¤·¤Æ¤¤¤¿¤Î¤Ç¡¢ºÆÀßÄ꤬ɬÍפÀ¤Ã¤¿¡£
6867  * ¤â¤¦ÉÔÍפÀ¤¬¡¢°ÊÁ°¤Î¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤È¤Î¸ß´¹¤Î¤¿¤á¤Ë»Ä¤·¤Æ¤ª¤¯¡£
6868  */
6869                 if (p_ptr->riding == -1)
6870                 {
6871                         p_ptr->riding = 0;
6872                         for (i = m_max; i > 0; i--)
6873                         {
6874                                 if (player_bold(m_list[i].fy, m_list[i].fx))
6875                                 {
6876                                         p_ptr->riding = i;
6877                                         break;
6878                                 }
6879                         }
6880                 }
6881         }
6882
6883         p_ptr->teleport_town = FALSE;
6884         p_ptr->sutemi = FALSE;
6885         world_monster = FALSE;
6886         now_damaged = FALSE;
6887         now_message = 0;
6888         start_time = time(NULL) - 1;
6889         record_o_name[0] = '\0';
6890
6891         /* Reset map panel */
6892         panel_row_min = cur_hgt;
6893         panel_col_min = cur_wid;
6894
6895         /* Sexy gal gets bonus to maximum weapon skill of whip */
6896         if (p_ptr->pseikaku == SEIKAKU_SEXY)
6897                 s_info[p_ptr->pclass].w_max[TV_HAFTED-TV_BOW][SV_WHIP] = WEAPON_EXP_MASTER;
6898
6899         /* Fill the arrays of floors and walls in the good proportions */
6900         set_floor_and_wall(dungeon_type);
6901
6902         /* Flavor the objects */
6903         flavor_init();
6904         if (new_game)
6905         {
6906                 wipe_o_list();
6907                 player_outfit();
6908         }
6909
6910         /* Flash a message */
6911 #ifdef JP
6912 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
6913 #else
6914         prt("Please wait...", 0, 0);
6915 #endif
6916
6917
6918         /* Flush the message */
6919         Term_fresh();
6920
6921
6922         /* Hack -- Enter wizard mode */
6923         if (arg_wizard)
6924         {
6925                 if (enter_wizard_mode()) p_ptr->wizard = TRUE;
6926                 else if (p_ptr->is_dead) quit("Already dead.");
6927         }
6928
6929         /* Initialize the town-buildings if necessary */
6930         if (!dun_level && !p_ptr->inside_quest)
6931         {
6932                 /* Init the wilderness */
6933
6934                 process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
6935
6936                 /* Init the town */
6937                 init_flags = INIT_ONLY_BUILDINGS;
6938
6939                 process_dungeon_file("t_info.txt", 0, 0, MAX_HGT, MAX_WID);
6940
6941         }
6942
6943
6944         /* Generate a dungeon level if needed */
6945         if (!character_dungeon) change_floor();
6946
6947
6948         /* Character is now "complete" */
6949         character_generated = TRUE;
6950
6951
6952         /* Hack -- Character is no longer "icky" */
6953         character_icky = FALSE;
6954
6955
6956         /* Start game */
6957         p_ptr->playing = TRUE;
6958
6959         /* Reset the visual mappings */
6960         reset_visuals();
6961
6962         /* Load the "pref" files */
6963         load_all_pref_files();
6964
6965         /* React to changes */
6966         Term_xtra(TERM_XTRA_REACT, 0);
6967
6968         /* Window stuff */
6969         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
6970
6971         /* Window stuff */
6972         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
6973
6974         /* Window stuff */
6975         window_stuff();
6976
6977
6978         /* Set or clear "rogue_like_commands" if requested */
6979         if (arg_force_original) rogue_like_commands = FALSE;
6980         if (arg_force_roguelike) rogue_like_commands = TRUE;
6981
6982         /* Hack -- Enforce "delayed death" */
6983         if (p_ptr->chp < 0) p_ptr->is_dead = TRUE;
6984
6985         if (p_ptr->prace == RACE_ANDROID) calc_android_exp();
6986
6987         if (new_game && ((p_ptr->pclass == CLASS_CAVALRY) || (p_ptr->pclass == CLASS_BEASTMASTER)))
6988         {
6989                 monster_type *m_ptr;
6990                 int pet_r_idx = ((p_ptr->pclass == CLASS_CAVALRY) ? MON_HORSE : MON_YASE_HORSE);
6991                 monster_race *r_ptr = &r_info[pet_r_idx];
6992                 place_monster_aux(0, py, px - 1, pet_r_idx,
6993                                   (PM_FORCE_PET | PM_NO_KAGE));
6994                 m_ptr = &m_list[hack_m_idx_ii];
6995                 m_ptr->mspeed = r_ptr->speed;
6996                 m_ptr->maxhp = r_ptr->hdice*(r_ptr->hside+1)/2;
6997                 m_ptr->max_maxhp = m_ptr->maxhp;
6998                 m_ptr->hp = r_ptr->hdice*(r_ptr->hside+1)/2;
6999                 m_ptr->energy_need = ENERGY_NEED() + ENERGY_NEED();
7000         }
7001
7002         /* Process */
7003         while (TRUE)
7004         {
7005                 /* Process the level */
7006                 dungeon(load_game);
7007
7008                 /* Handle "p_ptr->notice" */
7009                 notice_stuff();
7010
7011                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
7012                 handle_stuff();
7013
7014                 /* Cancel the target */
7015                 target_who = 0;
7016
7017                 /* Cancel the health bar */
7018                 health_track(0);
7019
7020
7021                 /* Forget the lite */
7022                 forget_lite();
7023
7024                 /* Forget the view */
7025                 forget_view();
7026
7027                 /* Forget the view */
7028                 clear_mon_lite();
7029
7030                 /* Handle "quit and save" */
7031                 if (!p_ptr->playing && !p_ptr->is_dead) break;
7032
7033                 /* Erase the old cave */
7034                 wipe_o_list();
7035                 if (!p_ptr->is_dead) wipe_m_list();
7036
7037
7038                 /* XXX XXX XXX */
7039                 msg_print(NULL);
7040
7041                 load_game = FALSE;
7042
7043                 /* Accidental Death */
7044                 if (p_ptr->playing && p_ptr->is_dead)
7045                 {
7046                         if (p_ptr->inside_arena)
7047                         {
7048                                 p_ptr->inside_arena = FALSE;
7049                                 if (p_ptr->arena_number > MAX_ARENA_MONS)
7050                                         p_ptr->arena_number++;
7051                                 else
7052                                         p_ptr->arena_number = -1 - p_ptr->arena_number;
7053                                 p_ptr->is_dead = FALSE;
7054                                 p_ptr->chp = 0;
7055                                 p_ptr->chp_frac = 0;
7056                                 p_ptr->exit_bldg = TRUE;
7057                                 reset_tim_flags();
7058                         }
7059                         else
7060                         {
7061                                 /* Mega-Hack -- Allow player to cheat death */
7062 #ifdef JP
7063 if ((p_ptr->wizard || cheat_live) && !get_check("»à¤Ë¤Þ¤¹¤«? "))
7064 #else
7065                                 if ((p_ptr->wizard || cheat_live) && !get_check("Die? "))
7066 #endif
7067
7068                                 {
7069                                         /* Mark social class, reset age, if needed */
7070                                         if (p_ptr->sc) p_ptr->sc = p_ptr->age = 0;
7071
7072                                         /* Increase age */
7073                                         p_ptr->age++;
7074
7075                                         /* Mark savefile */
7076                                         p_ptr->noscore |= 0x0001;
7077
7078                                         /* Message */
7079 #ifdef JP
7080 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÇ°¤òÁ÷¤ê¡¢»à¤òµ½¤¤¤¿¡£");
7081 #else
7082                                         msg_print("You invoke wizard mode and cheat death.");
7083 #endif
7084                                         wipe_m_list();
7085
7086                                         msg_print(NULL);
7087
7088                                         /* Restore hit points */
7089                                         p_ptr->chp = p_ptr->mhp;
7090                                         p_ptr->chp_frac = 0;
7091
7092                                         if (p_ptr->pclass == CLASS_MAGIC_EATER)
7093                                         {
7094                                                 for (i = 0; i < EATER_EXT*2; i++)
7095                                                 {
7096                                                         p_ptr->magic_num1[i] = p_ptr->magic_num2[i]*EATER_CHARGE;
7097                                                 }
7098                                                 for (; i < EATER_EXT*3; i++)
7099                                                 {
7100                                                         p_ptr->magic_num1[i] = 0;
7101                                                 }
7102                                         }
7103                                         /* Restore spell points */
7104                                         p_ptr->csp = p_ptr->msp;
7105                                         p_ptr->csp_frac = 0;
7106
7107                                         /* Hack -- Healing */
7108                                         (void)set_blind(0);
7109                                         (void)set_confused(0);
7110                                         (void)set_poisoned(0);
7111                                         (void)set_afraid(0);
7112                                         (void)set_paralyzed(0);
7113                                         (void)set_image(0);
7114                                         (void)set_stun(0);
7115                                         (void)set_cut(0);
7116
7117                                         /* Hack -- Prevent starvation */
7118                                         (void)set_food(PY_FOOD_MAX - 1);
7119
7120                                         /* Hack -- cancel recall */
7121                                         if (p_ptr->word_recall)
7122                                         {
7123                                                 /* Message */
7124 #ifdef JP
7125 msg_print("Ä¥¤ê¤Ä¤á¤¿Â絤¤¬Î®¤ìµî¤Ã¤¿...");
7126 #else
7127                                                 msg_print("A tension leaves the air around you...");
7128 #endif
7129
7130                                                 msg_print(NULL);
7131
7132                                                 /* Hack -- Prevent recall */
7133                                                 p_ptr->word_recall = 0;
7134                                                 p_ptr->redraw |= (PR_STATUS);
7135                                         }
7136
7137                                         /* Hack -- cancel alter */
7138                                         if (p_ptr->alter_reality)
7139                                         {
7140                                                 /* Hack -- Prevent alter */
7141                                                 p_ptr->alter_reality = 0;
7142                                                 p_ptr->redraw |= (PR_STATUS);
7143                                         }
7144
7145                                         /* Note cause of death XXX XXX XXX */
7146 #ifdef JP
7147 (void)strcpy(p_ptr->died_from, "»à¤Îµ½¤­");
7148 #else
7149                                         (void)strcpy(p_ptr->died_from, "Cheating death");
7150 #endif
7151
7152
7153                                         /* Do not die */
7154                                         p_ptr->is_dead = FALSE;
7155
7156                                         dun_level = 0;
7157                                         p_ptr->inside_arena = FALSE;
7158                                         p_ptr->inside_battle = FALSE;
7159                                         leaving_quest = 0;
7160                                         p_ptr->inside_quest = 0;
7161                                         p_ptr->recall_dungeon = dungeon_type;
7162                                         dungeon_type = 0;
7163                                         if (lite_town || vanilla_town)
7164                                         {
7165                                                 p_ptr->wilderness_y = 1;
7166                                                 p_ptr->wilderness_x = 1;
7167                                                 if (vanilla_town)
7168                                                 {
7169                                                         p_ptr->oldpy = 10;
7170                                                         p_ptr->oldpx = 34;
7171                                                 }
7172                                                 else
7173                                                 {
7174                                                         p_ptr->oldpy = 33;
7175                                                         p_ptr->oldpx = 131;
7176                                                 }
7177                                         }
7178                                         else
7179                                         {
7180                                                 p_ptr->wilderness_y = 48;
7181                                                 p_ptr->wilderness_x = 5;
7182                                                 p_ptr->oldpy = 33;
7183                                                 p_ptr->oldpx = 131;
7184                                         }
7185
7186                                         /* Leaving */
7187                                         p_ptr->wild_mode = FALSE;
7188                                         p_ptr->leaving = TRUE;
7189
7190 #ifdef JP
7191                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "                            ¤·¤«¤·¡¢À¸¤­Ê֤ä¿¡£");
7192 #else
7193                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "                            but revived.");
7194 #endif
7195                                 }
7196                         }
7197                 }
7198
7199                 /* Handle "death" */
7200                 if (p_ptr->is_dead) break;
7201
7202                 /* Make a new level */
7203                 change_floor();
7204         }
7205
7206         /* Close stuff */
7207         close_game();
7208
7209         /* Quit */
7210         quit(NULL);
7211 }
7212
7213 s32b turn_real(s32b hoge)
7214 {
7215         switch (p_ptr->start_race)
7216         {
7217         case RACE_VAMPIRE:
7218         case RACE_SKELETON:
7219         case RACE_ZOMBIE:
7220         case RACE_SPECTRE:
7221                 return hoge - (TURNS_PER_TICK * TOWN_DAWN * 3 / 4);
7222         default:
7223                 return hoge;
7224         }
7225 }