OSDN Git Service

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