OSDN Git Service

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