OSDN Git Service

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