OSDN Git Service

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