OSDN Git Service

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