OSDN Git Service

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