OSDN Git Service

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