OSDN Git Service

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