OSDN Git Service

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