OSDN Git Service

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